Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Unified Diff: Source/core/html/canvas/WebGLRenderingContext.cpp

Issue 14840015: Lose/restore WebGL contexts if multisampling blackist status changes at runtime. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Forgot to remove DrawingBuffer change Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ed1f58ab12235f70711ea5cc9e176dd95d0c40ce 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) {
Ken Russell (switch to Gerrit) 2013/05/08 02:17:02 Passing the GraphicsContext3D::Attributes by value
+ 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();
+ GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attributes() : GraphicsContext3D::Attributes();
+ requestedAttributes.noExtensions = true;
+ requestedAttributes.shareResources = true;
+ requestedAttributes.preferDiscreteGPU = true;
+ requestedAttributes.topDocumentURL = document->topDocument()->url();
- if (attributes.antialias) {
- if (settings && !settings->openGLMultisamplingEnabled())
- attributes.antialias = false;
- }
-
- 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,13 @@ void WebGLRenderingContext::setupFlags()
ASSERT(m_context);
Page* p = canvas()->document()->page();
- if (p)
+ if (p) {
m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnabled();
+ if (m_multisamplingChangedObserver == 0 && m_requestedAttributes.antialias)
Ken Russell (switch to Gerrit) 2013/05/08 02:17:02 Nit: style guide would say "if (!m_multisamplingCh
+ m_multisamplingChangedObserver = adoptRef(new WebGLMultisamplingChangedObserver(this, p));
+ }
+
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 +5255,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 +5279,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 +5294,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 +5487,19 @@ void WebGLRenderingContext::restoreCurrentTexture2D()
bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(), ec);
}
+WebGLRenderingContext::WebGLMultisamplingChangedObserver::WebGLMultisamplingChangedObserver(WebGLRenderingContext* context, Page* page)
+ : m_context(context)
+ , Page::MultisamplingChangedObserver(page)
+{
+ m_multisamplingAllowed = m_context->getContextAttributes()->antialias();
+}
+
+void WebGLRenderingContext::WebGLMultisamplingChangedObserver::multisamplingChanged(bool enabled)
+{
+ if (m_multisamplingAllowed != enabled) {
+ m_multisamplingAllowed = enabled;
+ m_context->forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext);
+ }
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698