Chromium Code Reviews| Index: Source/core/html/canvas/WebGLRenderingContext.cpp |
| diff --git a/Source/core/html/canvas/WebGLRenderingContext.cpp b/Source/core/html/canvas/WebGLRenderingContext.cpp |
| index 34cf1793dff9881e7320d7f5595e53d10af9f036..ac6bb169b128d454589d9590806968f72f1bb0c7 100644 |
| --- a/Source/core/html/canvas/WebGLRenderingContext.cpp |
| +++ b/Source/core/html/canvas/WebGLRenderingContext.cpp |
| @@ -450,6 +450,15 @@ namespace { |
| break; |
| } |
| } |
| + |
| + GraphicsContext3D::Attributes adjustAttributes(GraphicsContext3D::Attributes attributes, Settings* settings) { |
| + if (attributes.antialias) { |
| + if (settings && !settings->openGLMultisamplingEnabled()) |
| + attributes.antialias = false; |
| + } |
| + |
| + return attributes; |
| + } |
| } // namespace anonymous |
| class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostCallback { |
| @@ -492,17 +501,13 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen |
| } |
| HostWindow* hostWindow = document->view()->root()->hostWindow(); |
| - GraphicsContext3D::Attributes attributes = attrs ? attrs->attributes() : GraphicsContext3D::Attributes(); |
| - |
| - if (attributes.antialias) { |
| - if (settings && !settings->openGLMultisamplingEnabled()) |
| - attributes.antialias = false; |
| - } |
| + GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attributes() : GraphicsContext3D::Attributes(); |
| + requestedAttributes.noExtensions = true; |
| + requestedAttributes.shareResources = true; |
| + requestedAttributes.preferDiscreteGPU = true; |
| + requestedAttributes.topDocumentURL = document->topDocument()->url(); |
| - attributes.noExtensions = true; |
| - attributes.shareResources = true; |
| - attributes.preferDiscreteGPU = true; |
| - attributes.topDocumentURL = document->topDocument()->url(); |
| + GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttributes, settings); |
| RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes, hostWindow)); |
| @@ -515,7 +520,7 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen |
| if (extensions->supports("GL_EXT_debug_marker")) |
| extensions->pushGroupMarkerEXT("WebGLRenderingContext"); |
| - OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRenderingContext(canvas, context, attributes)); |
| + OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRenderingContext(canvas, context, attributes, requestedAttributes)); |
| renderingContext->suspendIfNeeded(); |
| if (renderingContext->m_drawingBuffer->isZeroSized()) { |
| @@ -527,7 +532,8 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen |
| } |
| WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassRefPtr<GraphicsContext3D> context, |
| - GraphicsContext3D::Attributes attributes) |
| + GraphicsContext3D::Attributes attributes, |
| + GraphicsContext3D::Attributes requestedAttributes) |
| : CanvasRenderingContext(passedCanvas) |
| , ActiveDOMObject(passedCanvas->document()) |
| , m_context(context) |
| @@ -539,6 +545,7 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa |
| , m_contextLost(false) |
| , m_contextLostMode(SyntheticLostContext) |
| , m_attributes(attributes) |
| + , m_requestedAttributes(requestedAttributes) |
| , m_synthesizedErrorsToConsole(true) |
| , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) |
| { |
| @@ -646,9 +653,15 @@ void WebGLRenderingContext::setupFlags() |
| ASSERT(m_context); |
| Page* p = canvas()->document()->page(); |
| - if (p) |
| + if (p) { |
| m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnabled(); |
| + if (m_settingsChangedObserver == 0) { |
| + m_settingsChangedObserver = adoptRef(new WebGLSettingsChangedObserver(this, p)); |
| + p->addSettingsChangedObserver(m_settingsChangedObserver.get()); |
| + } |
| + } |
| + |
| m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture_npot"); |
| m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_packed_depth_stencil"); |
| m_isRobustnessEXTSupported = m_context->getExtensions()->isEnabled("GL_EXT_robustness"); |
| @@ -5244,7 +5257,7 @@ void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext |
| canvas()->dispatchEvent(event); |
| m_restoreAllowed = event->defaultPrevented(); |
| deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAllowed); |
| - if (m_contextLostMode == RealLostContext && m_restoreAllowed) |
| + if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecoverSyntheticLostContext) && m_restoreAllowed) |
| m_restoreTimer.startOneShot(0); |
| } |
| @@ -5268,7 +5281,9 @@ void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
| if (!frame) |
| return; |
| - if (!frame->loader()->client()->allowWebGL(frame->settings() && frame->settings()->webGLEnabled())) |
| + Settings* settings = frame->settings(); |
| + |
| + if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnabled())) |
| return; |
| FrameView* view = frame->view(); |
| @@ -5281,6 +5296,9 @@ void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
| if (!hostWindow) |
| return; |
| + // Reset the context attributes back to the requested attributes and re-apply restrictions |
| + m_attributes = adjustAttributes(m_requestedAttributes, settings); |
| + |
| RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(m_attributes, hostWindow)); |
| if (!context) { |
| if (m_contextLostMode == RealLostContext) |
| @@ -5471,4 +5489,25 @@ void WebGLRenderingContext::restoreCurrentTexture2D() |
| bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(), ec); |
| } |
| +WebGLRenderingContext::WebGLSettingsChangedObserver::WebGLSettingsChangedObserver(WebGLRenderingContext* context, Page* page) |
| + : m_context(context) |
| + , m_page(page) |
| +{ |
| + m_multisamplingAllowed = m_context->getContextAttributes()->antialias(); |
| +} |
| + |
| +void WebGLRenderingContext::WebGLSettingsChangedObserver::settingsChanged(Settings* settings) |
| +{ |
| + bool enabled = settings->openGLMultisamplingEnabled(); |
| + if(m_multisamplingAllowed != enabled) { |
|
abarth-chromium
2013/05/06 21:58:30
nit: missing a space after "if"
Ken Russell (switch to Gerrit)
2013/05/06 22:12:22
The logic here doesn't seem right. If the app didn
bajones
2013/05/06 22:44:14
Good point. I should be able to do that without to
|
| + m_multisamplingAllowed = enabled; |
| + m_context->forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext); |
| + } |
| +} |
| + |
| +WebGLRenderingContext::WebGLSettingsChangedObserver::~WebGLSettingsChangedObserver() |
| +{ |
| + m_page->removeSettingsChangedObserver(this); |
| +} |
| + |
| } // namespace WebCore |