| Index: Source/core/html/canvas/WebGLRenderingContextBase.cpp
|
| diff --git a/Source/core/html/canvas/WebGLRenderingContextBase.cpp b/Source/core/html/canvas/WebGLRenderingContextBase.cpp
|
| index b814a1b920247f8d51f2315cac8877997d5b7951..41d867f23882fae8122affe01e34789b92363459 100644
|
| --- a/Source/core/html/canvas/WebGLRenderingContextBase.cpp
|
| +++ b/Source/core/html/canvas/WebGLRenderingContextBase.cpp
|
| @@ -42,6 +42,7 @@
|
| #include "core/html/canvas/ANGLEInstancedArrays.h"
|
| #include "core/html/canvas/CHROMIUMSubscribeUniform.h"
|
| #include "core/html/canvas/CHROMIUMValuebuffer.h"
|
| +#include "core/html/canvas/ContextAttributeHelpers.h"
|
| #include "core/html/canvas/EXTBlendMinMax.h"
|
| #include "core/html/canvas/EXTFragDepth.h"
|
| #include "core/html/canvas/EXTShaderTextureLOD.h"
|
| @@ -558,7 +559,7 @@ private:
|
| RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
|
| };
|
|
|
| -WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCanvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requestedAttributes)
|
| +WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCanvas, PassOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttributes& requestedAttributes)
|
| : CanvasRenderingContext(passedCanvas)
|
| , ActiveDOMObject(&passedCanvas->document())
|
| , m_contextLostMode(NotLostContext)
|
| @@ -567,7 +568,7 @@ WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
|
| , m_restoreAllowed(false)
|
| , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
|
| , m_generatedImageCache(4)
|
| - , m_requestedAttributes(requestedAttributes->clone())
|
| + , m_requestedAttributes(requestedAttributes)
|
| , m_synthesizedErrorsToConsole(true)
|
| , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
|
| , m_multisamplingAllowed(false)
|
| @@ -602,12 +603,12 @@ PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn
|
| RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptRef(new WebGLRenderingContextEvictionManager());
|
|
|
| blink::WebGraphicsContext3D::Attributes attrs;
|
| - attrs.alpha = m_requestedAttributes->alpha();
|
| - attrs.depth = m_requestedAttributes->depth();
|
| - attrs.stencil = m_requestedAttributes->stencil();
|
| - attrs.antialias = m_requestedAttributes->antialias();
|
| - attrs.premultipliedAlpha = m_requestedAttributes->premultipliedAlpha();
|
| - DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->preserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
|
| + attrs.alpha = m_requestedAttributes.alpha();
|
| + attrs.depth = m_requestedAttributes.depth();
|
| + attrs.stencil = m_requestedAttributes.stencil();
|
| + attrs.antialias = m_requestedAttributes.antialias();
|
| + attrs.premultipliedAlpha = m_requestedAttributes.premultipliedAlpha();
|
| + DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
|
| return DrawingBuffer::create(context, clampedCanvasSize(), preserve, attrs, contextEvictionManager.release());
|
| }
|
|
|
| @@ -698,7 +699,7 @@ void WebGLRenderingContextBase::setupFlags()
|
| if (Page* p = canvas()->document().page()) {
|
| m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled();
|
|
|
| - if (!m_multisamplingObserverRegistered && m_requestedAttributes->antialias()) {
|
| + if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialias()) {
|
| m_multisamplingAllowed = drawingBuffer()->multisample();
|
| p->addMultisamplingChangedObserver(this);
|
| m_multisamplingObserverRegistered = true;
|
| @@ -823,7 +824,12 @@ WebGLRenderingContextBase::HowToClear WebGLRenderingContextBase::clearIfComposit
|
| if (!drawingBuffer()->bufferClearNeeded() || (mask && m_framebufferBinding))
|
| return Skipped;
|
|
|
| - RefPtrWillBeRawPtr<WebGLContextAttributes> contextAttributes = getContextAttributes();
|
| + Nullable<WebGLContextAttributes> contextAttributes;
|
| + getContextAttributes(contextAttributes);
|
| + if (contextAttributes.isNull()) {
|
| + // Unlikely, but context was lost.
|
| + return Skipped;
|
| + }
|
|
|
| // Determine if it's possible to combine the clear the user asked for and this clear.
|
| bool combinedClear = mask && !m_scissorEnabled;
|
| @@ -839,13 +845,13 @@ WebGLRenderingContextBase::HowToClear WebGLRenderingContextBase::clearIfComposit
|
| }
|
| webContext()->colorMask(true, true, true, true);
|
| GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
|
| - if (contextAttributes->depth()) {
|
| + if (contextAttributes.get().depth()) {
|
| if (!combinedClear || !m_depthMask || !(mask & GL_DEPTH_BUFFER_BIT))
|
| webContext()->clearDepth(1.0f);
|
| clearMask |= GL_DEPTH_BUFFER_BIT;
|
| webContext()->depthMask(true);
|
| }
|
| - if (contextAttributes->stencil()) {
|
| + if (contextAttributes.get().stencil()) {
|
| if (combinedClear && (mask & GL_STENCIL_BUFFER_BIT))
|
| webContext()->clearStencil(m_clearStencil & m_stencilMask);
|
| else
|
| @@ -2109,22 +2115,19 @@ ScriptValue WebGLRenderingContextBase::getBufferParameter(ScriptState* scriptSta
|
| return WebGLAny(scriptState, static_cast<unsigned>(value));
|
| }
|
|
|
| -PassRefPtrWillBeRawPtr<WebGLContextAttributes> WebGLRenderingContextBase::getContextAttributes()
|
| +void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttributes>& result)
|
| {
|
| if (isContextLost())
|
| - return nullptr;
|
| - // We always need to return a new WebGLContextAttributes object to
|
| - // prevent the user from mutating any cached version.
|
| - blink::WebGraphicsContext3D::Attributes attrs = drawingBuffer()->getActualAttributes();
|
| - RefPtrWillBeRawPtr<WebGLContextAttributes> attributes = m_requestedAttributes->clone();
|
| + return;
|
| + result.set(m_requestedAttributes);
|
| // Some requested attributes may not be honored, so we need to query the underlying
|
| // context/drawing buffer and adjust accordingly.
|
| - if (m_requestedAttributes->depth() && !attrs.depth)
|
| - attributes->setDepth(false);
|
| - if (m_requestedAttributes->stencil() && !attrs.stencil)
|
| - attributes->setStencil(false);
|
| - attributes->setAntialias(drawingBuffer()->multisample());
|
| - return attributes.release();
|
| + blink::WebGraphicsContext3D::Attributes attrs = drawingBuffer()->getActualAttributes();
|
| + if (m_requestedAttributes.depth() && !attrs.depth)
|
| + result.get().setDepth(false);
|
| + if (m_requestedAttributes.stencil() && !attrs.stencil)
|
| + result.get().setStencil(false);
|
| + result.get().setAntialias(drawingBuffer()->multisample());
|
| }
|
|
|
| GLenum WebGLRenderingContextBase::getError()
|
| @@ -2304,7 +2307,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* scriptState, GL
|
| case GL_CURRENT_PROGRAM:
|
| return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(m_currentProgram.get()));
|
| case GL_DEPTH_BITS:
|
| - if (!m_framebufferBinding && !m_requestedAttributes->depth())
|
| + if (!m_framebufferBinding && !m_requestedAttributes.depth())
|
| return WebGLAny(scriptState, intZero);
|
| return getIntParameter(scriptState, pname);
|
| case GL_DEPTH_CLEAR_VALUE:
|
| @@ -2403,7 +2406,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* scriptState, GL
|
| case GL_STENCIL_BACK_WRITEMASK:
|
| return getUnsignedIntParameter(scriptState, pname);
|
| case GL_STENCIL_BITS:
|
| - if (!m_framebufferBinding && !m_requestedAttributes->stencil())
|
| + if (!m_framebufferBinding && !m_requestedAttributes.stencil())
|
| return WebGLAny(scriptState, intZero);
|
| return getIntParameter(scriptState, pname);
|
| case GL_STENCIL_CLEAR_VALUE:
|
| @@ -4596,7 +4599,7 @@ GLenum WebGLRenderingContextBase::boundFramebufferColorFormat()
|
| {
|
| if (m_framebufferBinding && m_framebufferBinding->object())
|
| return m_framebufferBinding->colorBufferFormat();
|
| - if (m_requestedAttributes->alpha())
|
| + if (m_requestedAttributes.alpha())
|
| return GL_RGBA;
|
| return GL_RGB;
|
| }
|
| @@ -5603,7 +5606,7 @@ void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB
|
| #endif
|
| }
|
|
|
| - blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes->attributes(canvas()->document().topDocument().url().string(), settings, version());
|
| + blink::WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttributes(m_requestedAttributes, canvas()->document().topDocument().url().string(), settings, version());
|
| OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::current()->createOffscreenGraphicsContext3D(attributes, 0));
|
| RefPtr<DrawingBuffer> buffer;
|
| if (context) {
|
| @@ -5742,8 +5745,9 @@ void WebGLRenderingContextBase::applyStencilTest()
|
| if (m_framebufferBinding)
|
| haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
|
| else {
|
| - RefPtrWillBeRawPtr<WebGLContextAttributes> attributes = getContextAttributes();
|
| - haveStencilBuffer = attributes->stencil();
|
| + Nullable<WebGLContextAttributes> attributes;
|
| + getContextAttributes(attributes);
|
| + haveStencilBuffer = !attributes.isNull() && attributes.get().stencil();
|
| }
|
| enableOrDisable(GL_STENCIL_TEST,
|
| m_stencilEnabled && haveStencilBuffer);
|
|
|