Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| index 0d5e2ba07c88b4dc68f8a5b672c199098c6258eb..783bae88118e322ffb0d4686066e3228cca8e052 100644 |
| --- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| +++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
| @@ -506,6 +506,34 @@ static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf |
| return statusMessage; |
| } |
| +static PassOwnPtr<WebGraphicsContext3DProvider> createWebGraphicsContext3DProviderHelper(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttributes attributes, unsigned webGLVersion) |
| +{ |
| + Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(attributes, webGLVersion); |
| + Platform::GraphicsInfo glInfo; |
| + OwnPtr<WebGraphicsContext3DProvider> contextProvider; |
| + if (canvas) { |
| + contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| + contextAttributes, canvas->document().topDocument().url(), 0, &glInfo)); |
| + } else { |
| + contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| + contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo)); |
|
xidachen
2016/04/20 19:31:09
Doing offscreenCanvas.getContext('webgl') works fi
|
| + } |
| + if (!contextProvider || shouldFailContextCreationForTesting) { |
| + shouldFailContextCreationForTesting = false; |
| + if (canvas) |
| + canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| + return nullptr; |
| + } |
| + gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
| + if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_stencil")) { |
| + if (canvas) |
| + canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "OES_packed_depth_stencil support is required.")); |
| + return nullptr; |
| + } |
| + |
| + return contextProvider.release(); |
| +} |
| + |
| PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGraphicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attributes, unsigned webGLVersion) |
| { |
| Document& document = canvas->document(); |
| @@ -523,22 +551,12 @@ PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra |
| return nullptr; |
| } |
| - Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(attributes, webGLVersion); |
| - Platform::GraphicsInfo glInfo; |
| - OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsContext3DProvider( |
| - contextAttributes, document.topDocument().url(), 0, &glInfo)); |
| - if (!contextProvider || shouldFailContextCreationForTesting) { |
| - shouldFailContextCreationForTesting = false; |
| - canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| - return nullptr; |
| - } |
| - gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
| - if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_stencil")) { |
| - canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "OES_packed_depth_stencil support is required.")); |
| - return nullptr; |
| - } |
| + return createWebGraphicsContext3DProviderHelper(canvas, static_cast<ScriptState*>(nullptr), attributes, webGLVersion); |
| +} |
| - return contextProvider.release(); |
| +PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGraphicsContext3DProvider(ScriptState* scriptState, WebGLContextAttributes attributes, unsigned webGLVersion) |
| +{ |
| + return createWebGraphicsContext3DProviderHelper(static_cast<HTMLCanvasElement*>(nullptr), scriptState, attributes, webGLVersion); |
| } |
| void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() |
| @@ -783,8 +801,17 @@ bool isSRGBFormat(GLenum internalformat) |
| } // namespace |
| +WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContextAttributes& requestedAttributes) |
| + : WebGLRenderingContextBase(static_cast<HTMLCanvasElement*>(nullptr), passedOffscreenCanvas, contextProvider, requestedAttributes) |
| +{ } |
| + |
| WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContextAttributes& requestedAttributes) |
| + : WebGLRenderingContextBase(passedCanvas, static_cast<OffscreenCanvas*>(nullptr), contextProvider, requestedAttributes) |
| +{ } |
| + |
| +WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCanvas, OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContextAttributes& requestedAttributes) |
| : CanvasRenderingContext(passedCanvas) |
| + , OffscreenCanvasRenderingContext(passedOffscreenCanvas) |
| , m_isHidden(false) |
| , m_contextLostMode(NotLostContext) |
| , m_autoRecoveryMethod(Manual) |
| @@ -980,8 +1007,10 @@ void WebGLRenderingContextBase::initializeNewContext() |
| void WebGLRenderingContextBase::setupFlags() |
| { |
| ASSERT(drawingBuffer()); |
| - if (Page* p = canvas()->document().page()) { |
| - m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled(); |
| + if (canvas()) { |
| + if (Page* p = canvas()->document().page()) { |
| + m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled(); |
| + } |
| } |
| m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_packed_depth_stencil"); |
| @@ -6111,8 +6140,16 @@ void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable) |
| IntSize WebGLRenderingContextBase::clampedCanvasSize() |
| { |
| - return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), |
| - clamp(canvas()->height(), 1, m_maxViewportDims[1])); |
| + int width, height; |
| + if (canvas()) { |
| + width = canvas()->width(); |
| + height = canvas()->height(); |
| + } else { |
| + width = getOffscreenCanvas()->width(); |
| + height = getOffscreenCanvas()->height(); |
| + } |
| + return IntSize(clamp(width, 1, m_maxViewportDims[0]), |
| + clamp(height, 1, m_maxViewportDims[1])); |
| } |
| GLint WebGLRenderingContextBase::maxDrawBuffers() |
| @@ -6251,6 +6288,7 @@ DEFINE_TRACE(WebGLRenderingContextBase) |
| visitor->trace(m_textureUnits); |
| visitor->trace(m_extensions); |
| CanvasRenderingContext::trace(visitor); |
| + OffscreenCanvasRenderingContext::trace(visitor); |
| } |
| int WebGLRenderingContextBase::externallyAllocatedBytesPerPixel() |