Commit b6d95d9d authored by Corentin Wallez's avatar Corentin Wallez Committed by Commit Bot

Add stubs for WebGPU's CanvasRenderingContext

This makes canvas.getContext("gpupresent") return a GPUCanvasContext
when the --enable-unsafe-webgpu flag is present.

BUG=chromium:877147

Change-Id: I74b35cf117aadcc00a979189b8364798b353ac66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559181Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650595}
parent 5174884f
...@@ -445,9 +445,9 @@ def shorten_union_name(union_type): ...@@ -445,9 +445,9 @@ def shorten_union_name(union_type):
'CSSImageValueOrHTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmapOrOffscreenCanvas': 'CanvasImageSource', 'CSSImageValueOrHTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmapOrOffscreenCanvas': 'CanvasImageSource',
# modules/canvas/htmlcanvas/html_canvas_element_module_support_webgl2_compute.idl # modules/canvas/htmlcanvas/html_canvas_element_module_support_webgl2_compute.idl
# Due to html_canvas_element_module_support_webgl2_compute.idl and html_canvas_element_module.idl are exclusive in modules_idl_files.gni, they have same shorten name. # Due to html_canvas_element_module_support_webgl2_compute.idl and html_canvas_element_module.idl are exclusive in modules_idl_files.gni, they have same shorten name.
'CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContext': 'RenderingContext', 'CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext': 'RenderingContext',
# modules/canvas/htmlcanvas/html_canvas_element_module.idl # modules/canvas/htmlcanvas/html_canvas_element_module.idl
'CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContext': 'RenderingContext', 'CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext': 'RenderingContext',
# core/frame/window_or_worker_global_scope.idl # core/frame/window_or_worker_global_scope.idl
'HTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrImageBitmapOrOffscreenCanvas': 'ImageBitmapSource', 'HTMLImageElementOrSVGImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrImageBitmapOrOffscreenCanvas': 'ImageBitmapSource',
# bindings/tests/idls/core/TestTypedefs.idl # bindings/tests/idls/core/TestTypedefs.idl
......
...@@ -148,6 +148,8 @@ CanvasRenderingContext::ContextType CanvasRenderingContext::ContextTypeFromId( ...@@ -148,6 +148,8 @@ CanvasRenderingContext::ContextType CanvasRenderingContext::ContextTypeFromId(
return kContextImageBitmap; return kContextImageBitmap;
if (id == "xrpresent") if (id == "xrpresent")
return kContextXRPresent; return kContextXRPresent;
if (id == "gpupresent" && RuntimeEnabledFeatures::WebGPUEnabled())
return kContextGPUPresent;
return kContextTypeUnknown; return kContextTypeUnknown;
} }
......
...@@ -71,7 +71,8 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable, ...@@ -71,7 +71,8 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable,
kContextImageBitmap = 5, kContextImageBitmap = 5,
kContextXRPresent = 6, kContextXRPresent = 6,
kContextWebgl2Compute = 7, kContextWebgl2Compute = 7,
kContextTypeUnknown = 8, kContextGPUPresent = 8,
kContextTypeUnknown = 9,
kMaxValue = kContextTypeUnknown, kMaxValue = kContextTypeUnknown,
}; };
......
...@@ -75,13 +75,13 @@ class IntSize; ...@@ -75,13 +75,13 @@ class IntSize;
#if defined(SUPPORT_WEBGL2_COMPUTE_CONTEXT) #if defined(SUPPORT_WEBGL2_COMPUTE_CONTEXT)
class class
CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContext; CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext;
typedef CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContext typedef CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrWebGL2ComputeRenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext
RenderingContext; RenderingContext;
#else #else
class class
CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContext; CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext;
typedef CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContext typedef CanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContextOrImageBitmapRenderingContextOrXRPresentationContextOrGPUCanvasContext
RenderingContext; RenderingContext;
#endif #endif
......
...@@ -8,7 +8,8 @@ typedef (CanvasRenderingContext2D or ...@@ -8,7 +8,8 @@ typedef (CanvasRenderingContext2D or
WebGLRenderingContext or WebGLRenderingContext or
WebGL2RenderingContext or WebGL2RenderingContext or
ImageBitmapRenderingContext or ImageBitmapRenderingContext or
XRPresentationContext) RenderingContext; XRPresentationContext or
GPUCanvasContext) RenderingContext;
[ [
ImplementedAs=HTMLCanvasElementModule ImplementedAs=HTMLCanvasElementModule
......
...@@ -9,7 +9,8 @@ typedef (CanvasRenderingContext2D or ...@@ -9,7 +9,8 @@ typedef (CanvasRenderingContext2D or
WebGL2RenderingContext or WebGL2RenderingContext or
WebGL2ComputeRenderingContext or WebGL2ComputeRenderingContext or
ImageBitmapRenderingContext or ImageBitmapRenderingContext or
XRPresentationContext) RenderingContext; XRPresentationContext or
GPUCanvasContext) RenderingContext;
[ [
ImplementedAs=HTMLCanvasElementModule ImplementedAs=HTMLCanvasElementModule
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
#include "third_party/blink/renderer/modules/accessibility/inspector_accessibility_agent.h" #include "third_party/blink/renderer/modules/accessibility/inspector_accessibility_agent.h"
#include "third_party/blink/renderer/modules/webgl/webgl2_rendering_context.h" #include "third_party/blink/renderer/modules/webgl/webgl2_rendering_context.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context.h" #include "third_party/blink/renderer/modules/webgl/webgl_rendering_context.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_canvas_context.h"
#include "third_party/blink/renderer/modules/xr/xr_presentation_context.h" #include "third_party/blink/renderer/modules/xr/xr_presentation_context.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/mojo/mojo_helper.h" #include "third_party/blink/renderer/platform/mojo/mojo_helper.h"
...@@ -140,6 +141,8 @@ void ModulesInitializer::Initialize() { ...@@ -140,6 +141,8 @@ void ModulesInitializer::Initialize() {
std::make_unique<ImageBitmapRenderingContext::Factory>()); std::make_unique<ImageBitmapRenderingContext::Factory>());
HTMLCanvasElement::RegisterRenderingContextFactory( HTMLCanvasElement::RegisterRenderingContextFactory(
std::make_unique<XRPresentationContext::Factory>()); std::make_unique<XRPresentationContext::Factory>());
HTMLCanvasElement::RegisterRenderingContextFactory(
std::make_unique<GPUCanvasContext::Factory>());
// OffscreenCanvas context types must be registered with the OffscreenCanvas. // OffscreenCanvas context types must be registered with the OffscreenCanvas.
OffscreenCanvas::RegisterRenderingContextFactory( OffscreenCanvas::RegisterRenderingContextFactory(
......
...@@ -4,4 +4,37 @@ ...@@ -4,4 +4,37 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_canvas_context.h" #include "third_party/blink/renderer/modules/webgpu/gpu_canvas_context.h"
namespace blink {} // namespace blink #include "third_party/blink/renderer/bindings/modules/v8/rendering_context.h"
namespace blink {
GPUCanvasContext::Factory::Factory() {}
GPUCanvasContext::Factory::~Factory() {}
CanvasRenderingContext* GPUCanvasContext::Factory::Create(
CanvasRenderingContextHost* host,
const CanvasContextCreationAttributesCore& attrs) {
return MakeGarbageCollected<GPUCanvasContext>(host, attrs);
}
CanvasRenderingContext::ContextType GPUCanvasContext::Factory::GetContextType()
const {
return CanvasRenderingContext::kContextGPUPresent;
}
GPUCanvasContext::GPUCanvasContext(
CanvasRenderingContextHost* host,
const CanvasContextCreationAttributesCore& attrs)
: CanvasRenderingContext(host, attrs) {}
GPUCanvasContext::~GPUCanvasContext() {}
CanvasRenderingContext::ContextType GPUCanvasContext::GetContextType() const {
return CanvasRenderingContext::kContextGPUPresent;
}
void GPUCanvasContext::SetCanvasGetContextResult(RenderingContext& result) {
result.SetGPUCanvasContext(this);
}
} // namespace blink
...@@ -5,14 +5,55 @@ ...@@ -5,14 +5,55 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
namespace blink { namespace blink {
class GPUCanvasContext : public ScriptWrappable { // A GPUCanvasContext does little by itself and basically just binds a canvas
// and a GPUSwapChain together and forwards calls from one to the other. The
// logic that are in other CanvasRenderingContext is in GPUSwapChain instead.
class GPUCanvasContext : public CanvasRenderingContext {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
class Factory : public CanvasRenderingContextFactory {
DISALLOW_COPY_AND_ASSIGN(Factory);
public:
Factory();
~Factory() override;
CanvasRenderingContext* Create(
CanvasRenderingContextHost*,
const CanvasContextCreationAttributesCore&) override;
CanvasRenderingContext::ContextType GetContextType() const override;
};
GPUCanvasContext(CanvasRenderingContextHost*,
const CanvasContextCreationAttributesCore&);
~GPUCanvasContext() override;
// CanvasRenderingContext implementation
ContextType GetContextType() const override;
void SetCanvasGetContextResult(RenderingContext&) final;
scoped_refptr<StaticBitmapImage> GetImage(AccelerationHint) const final {
return nullptr;
}
void SetIsHidden(bool) override {}
bool isContextLost() const override { return false; }
bool IsComposited() const final { return true; }
bool IsAccelerated() const final { return true; }
bool IsOriginTopLeft() const final { return true; }
bool Is3d() const final { return true; }
void SetFilterQuality(SkFilterQuality) final {}
bool IsPaintable() const final { return true; }
int ExternallyAllocatedBufferCountPerPixel() final { return 1; }
void Stop() override {}
cc::Layer* CcLayer() const final { return nullptr; }
// gpu_canvas_context.idl // gpu_canvas_context.idl
// TODO(crbug.com/877147): implement GPUCanvasContext. // TODO(crbug.com/877147): implement GPUCanvasContext.
...@@ -20,6 +61,14 @@ class GPUCanvasContext : public ScriptWrappable { ...@@ -20,6 +61,14 @@ class GPUCanvasContext : public ScriptWrappable {
DISALLOW_COPY_AND_ASSIGN(GPUCanvasContext); DISALLOW_COPY_AND_ASSIGN(GPUCanvasContext);
}; };
DEFINE_TYPE_CASTS(GPUCanvasContext,
CanvasRenderingContext,
context,
context->GetContextType() ==
CanvasRenderingContext::kContextGPUPresent,
context.GetContextType() ==
CanvasRenderingContext::kContextGPUPresent);
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_CANVAS_CONTEXT_H_
# WebGPU tests are only run with --enable-unsafe-webgpu # WebGPU tests are only run with --enable-unsafe-webgpu
Bug(none) webgpu/canvas_context.html [ Pass ]
Bug(none) webgpu/fence.html [ Pass ] Bug(none) webgpu/fence.html [ Pass ]
...@@ -12,6 +12,7 @@ Bug(intentional) external/wpt/infrastructure/reftest/reftest_timeout.html [ Time ...@@ -12,6 +12,7 @@ Bug(intentional) external/wpt/infrastructure/reftest/reftest_timeout.html [ Time
Bug(intentional) external/wpt/infrastructure/expected-fail/timeout.html [ Timeout ] Bug(intentional) external/wpt/infrastructure/expected-fail/timeout.html [ Timeout ]
# WebGPU tests are only run with --enable-unsafe-webgpu # WebGPU tests are only run with --enable-unsafe-webgpu
Bug(none) webgpu/canvas_context.html [ Skip ]
Bug(none) webgpu/fence.html [ Skip ] Bug(none) webgpu/fence.html [ Skip ]
crbug.com/807686 crbug.com/24182 jquery/manipulation.html [ Timeout Pass ] crbug.com/807686 crbug.com/24182 jquery/manipulation.html [ Timeout Pass ]
......
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
let width = 10;
let height = 10;
test(function() {
let canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('gpupresent');
assert_true(ctx instanceof GPUCanvasContext);
}, "Test that canvas.getContext('gpupresent') returns an instance of GPUCanvasContext");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment