Index: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp |
diff --git a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp |
index db5216fa3ecb5d55548c2f258e795b169a6c2503..01141e5be87a6d36335777e5e7577648fa1d4628 100644 |
--- a/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp |
+++ b/third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp |
@@ -34,29 +34,45 @@ |
namespace blink { |
-CanvasRenderingContext* WebGL2RenderingContext::Factory::create( |
- HTMLCanvasElement* canvas, |
- const CanvasContextCreationAttributes& attrs, |
- Document&) { |
- std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( |
- createWebGraphicsContext3DProvider(canvas, attrs, 2)); |
+// An helper function for the two create() methods. The return value is an |
+// indicate of whether the create() should return nullptr or not. |
+static bool shouldCreateContext(WebGraphicsContext3DProvider* contextProvider, |
+ HTMLCanvasElement* canvas, |
+ OffscreenCanvas* offscreenCanvas) { |
if (!contextProvider) { |
- canvas->dispatchEvent(WebGLContextEvent::create( |
- EventTypeNames::webglcontextcreationerror, false, true, |
- "Failed to create a WebGL2 context.")); |
- return nullptr; |
+ if (canvas) { |
+ canvas->dispatchEvent(WebGLContextEvent::create( |
+ EventTypeNames::webglcontextcreationerror, false, true, |
+ "Failed to create a WebGL2 context.")); |
+ } else { |
+ offscreenCanvas->dispatchEvent(WebGLContextEvent::create( |
+ EventTypeNames::webglcontextcreationerror, false, true, |
+ "Failed to create a WebGL2 context.")); |
+ } |
+ return false; |
} |
+ |
gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
std::unique_ptr<Extensions3DUtil> extensionsUtil = |
Extensions3DUtil::create(gl); |
if (!extensionsUtil) |
- return nullptr; |
+ return false; |
if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) { |
String contextLabel( |
- String::format("WebGL2RenderingContext-%p", contextProvider.get())); |
+ String::format("WebGL2RenderingContext-%p", contextProvider)); |
gl->PushGroupMarkerEXT(0, contextLabel.ascii().data()); |
} |
+ return true; |
+} |
+CanvasRenderingContext* WebGL2RenderingContext::Factory::create( |
+ HTMLCanvasElement* canvas, |
+ const CanvasContextCreationAttributes& attrs, |
+ Document&) { |
+ std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( |
+ createWebGraphicsContext3DProvider(canvas, attrs, 2)); |
+ if (!shouldCreateContext(contextProvider.get(), canvas, nullptr)) |
+ return nullptr; |
WebGL2RenderingContext* renderingContext = |
new WebGL2RenderingContext(canvas, std::move(contextProvider), attrs); |
@@ -73,6 +89,30 @@ CanvasRenderingContext* WebGL2RenderingContext::Factory::create( |
return renderingContext; |
} |
+CanvasRenderingContext* WebGL2RenderingContext::Factory::create( |
+ ScriptState* scriptState, |
+ OffscreenCanvas* offscreenCanvas, |
+ const CanvasContextCreationAttributes& attrs) { |
+ std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( |
+ createWebGraphicsContext3DProvider(scriptState, attrs, 2)); |
+ if (!shouldCreateContext(contextProvider.get(), nullptr, offscreenCanvas)) |
+ return nullptr; |
+ WebGL2RenderingContext* renderingContext = new WebGL2RenderingContext( |
+ offscreenCanvas, std::move(contextProvider), attrs); |
+ |
+ if (!renderingContext->drawingBuffer()) { |
+ offscreenCanvas->dispatchEvent(WebGLContextEvent::create( |
+ EventTypeNames::webglcontextcreationerror, false, true, |
+ "Could not create a WebGL2 context.")); |
+ return nullptr; |
+ } |
+ |
+ renderingContext->initializeNewContext(); |
+ renderingContext->registerContextExtensions(); |
+ |
+ return renderingContext; |
+} |
+ |
void WebGL2RenderingContext::Factory::onError(HTMLCanvasElement* canvas, |
const String& error) { |
canvas->dispatchEvent(WebGLContextEvent::create( |
@@ -87,6 +127,14 @@ WebGL2RenderingContext::WebGL2RenderingContext( |
std::move(contextProvider), |
requestedAttributes) {} |
+WebGL2RenderingContext::WebGL2RenderingContext( |
+ OffscreenCanvas* passedOffscreenCanvas, |
+ std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, |
+ const CanvasContextCreationAttributes& requestedAttributes) |
+ : WebGL2RenderingContextBase(passedOffscreenCanvas, |
+ std::move(contextProvider), |
+ requestedAttributes) {} |
+ |
WebGL2RenderingContext::~WebGL2RenderingContext() {} |
void WebGL2RenderingContext::setCanvasGetContextResult( |