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

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: Missed one of kbr's suggestions in previous patch 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
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContext.h ('k') | Source/core/page/Page.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/canvas/WebGLRenderingContext.cpp
diff --git a/Source/core/html/canvas/WebGLRenderingContext.cpp b/Source/core/html/canvas/WebGLRenderingContext.cpp
index d29ad0b56d217e10a761f87e3998ae77746ea20b..0cb52ca58a012e1454c37cf57560def828e8097f 100644
--- a/Source/core/html/canvas/WebGLRenderingContext.cpp
+++ b/Source/core/html/canvas/WebGLRenderingContext.cpp
@@ -450,6 +450,17 @@ namespace {
break;
}
}
+
+ GraphicsContext3D::Attributes adjustAttributes(const GraphicsContext3D::Attributes attributes, Settings* settings)
+ {
+ GraphicsContext3D::Attributes adjustedAttributes = attributes;
+ if (adjustedAttributes.antialias) {
+ if (settings && !settings->openGLMultisamplingEnabled())
+ adjustedAttributes.antialias = false;
+ }
+
+ return adjustedAttributes;
+ }
} // namespace anonymous
class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostCallback {
@@ -491,17 +502,8 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
return nullptr;
}
- GraphicsContext3D::Attributes attributes = attrs ? attrs->attributes() : GraphicsContext3D::Attributes();
-
- 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 requestedAttributes = attrs ? attrs->attributes() : GraphicsContext3D::Attributes();
+ GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttributes, settings);
RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes));
@@ -514,7 +516,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()) {
@@ -525,8 +527,7 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
return renderingContext.release();
}
-WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassRefPtr<GraphicsContext3D> context,
- GraphicsContext3D::Attributes attributes)
+WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, GraphicsContext3D::Attributes requestedAttributes)
: CanvasRenderingContext(passedCanvas)
, ActiveDOMObject(passedCanvas->document())
, m_context(context)
@@ -538,8 +539,11 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa
, m_contextLost(false)
, m_contextLostMode(SyntheticLostContext)
, m_attributes(attributes)
+ , m_requestedAttributes(requestedAttributes)
, m_synthesizedErrorsToConsole(true)
, m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
+ , m_multisamplingAllowed(false)
+ , m_multisamplingObserverHost(0)
{
ASSERT(m_context);
ScriptWrappable::init(this);
@@ -645,9 +649,16 @@ void WebGLRenderingContext::setupFlags()
ASSERT(m_context);
Page* p = canvas()->document()->page();
- if (p)
+ if (p) {
m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnabled();
+ if (!m_multisamplingObserverHost && m_requestedAttributes.antialias) {
+ m_multisamplingAllowed = m_drawingBuffer->multisample();
+ m_multisamplingObserverHost = p;
Ken Russell (switch to Gerrit) 2013/05/09 00:17:13 Is it necessary to cache the Page like this? Would
+ m_multisamplingObserverHost->addMultisamplingChangedObserver(this);
+ }
+ }
+
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");
@@ -691,6 +702,9 @@ WebGLRenderingContext::~WebGLRenderingContext()
destroyGraphicsContext3D();
m_contextGroup->removeContext(this);
+ if (m_multisamplingObserverHost)
+ m_multisamplingObserverHost->removeMultisamplingChangedObserver(this);
+
willDestroyContext(this);
}
@@ -5233,7 +5247,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);
}
@@ -5257,10 +5271,16 @@ 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;
+ // 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));
+
if (!context) {
if (m_contextLostMode == RealLostContext)
m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts);
@@ -5450,4 +5470,12 @@ void WebGLRenderingContext::restoreCurrentTexture2D()
bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(), ec);
}
+void WebGLRenderingContext::multisamplingChanged(bool enabled)
+{
+ if (m_multisamplingAllowed != enabled) {
+ m_multisamplingAllowed = enabled;
+ forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext);
+ }
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContext.h ('k') | Source/core/page/Page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698