Index: Source/core/html/canvas/WebGLRenderingContext.cpp |
diff --git a/Source/core/html/canvas/WebGLRenderingContext.cpp b/Source/core/html/canvas/WebGLRenderingContext.cpp |
index 467b55837a80dd8135b6354d1758556c22343e67..dbd071a5ae2741c378b8ad83776656b81219fab4 100644 |
--- a/Source/core/html/canvas/WebGLRenderingContext.cpp |
+++ b/Source/core/html/canvas/WebGLRenderingContext.cpp |
@@ -526,7 +526,7 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen |
WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requestedAttributes) |
: CanvasRenderingContext(passedCanvas) |
, ActiveDOMObject(&passedCanvas->document()) |
- , m_context(context) |
+ , m_context(context.get()) |
, m_drawingBuffer(0) |
, m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchContextLostEvent) |
, m_restoreAllowed(false) |
@@ -555,7 +555,7 @@ WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa |
// Create the DrawingBuffer and initialize the platform layer. |
DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; |
- m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize(), preserve, contextEvictionManager.release()); |
+ m_drawingBuffer = DrawingBuffer::create(context, clampedCanvasSize(), preserve, contextEvictionManager.release()); |
if (!m_drawingBuffer) |
return; |
@@ -760,16 +760,16 @@ void WebGLRenderingContext::destroyContext() |
ASSERT(!m_drawingBuffer); |
return; |
} |
- // The drawing buffer holds a context reference. It must also be destroyed |
- // in order for the context to be released. |
- ASSERT(m_drawingBuffer); |
- m_drawingBuffer.clear(); |
m_extensionsUtil.clear(); |
m_context->setContextLostCallback(0); |
m_context->setErrorMessageCallback(0); |
- m_context.clear(); |
+ m_context = 0; |
+ |
+ ASSERT(m_drawingBuffer); |
+ m_drawingBuffer->releaseResources(); |
+ m_drawingBuffer.clear(); |
} |
void WebGLRenderingContext::markContextChanged() |
@@ -1314,7 +1314,7 @@ void WebGLRenderingContext::clear(GLbitfield mask) |
return; |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); |
return; |
} |
@@ -1468,7 +1468,7 @@ void WebGLRenderingContext::copyTexImage2D(GLenum target, GLint level, GLenum in |
return; |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", reason); |
return; |
} |
@@ -1511,7 +1511,7 @@ void WebGLRenderingContext::copyTexSubImage2D(GLenum target, GLint level, GLint |
return; |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); |
return; |
} |
@@ -1618,7 +1618,7 @@ bool WebGLRenderingContext::deleteObject(WebGLObject* object) |
if (object->object()) { |
// We need to pass in context here because we want |
// things in this context unbound. |
- object->deleteObject(m_context.get()); |
+ object->deleteObject(m_context); |
} |
return true; |
} |
@@ -1731,7 +1731,7 @@ void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha |
return; |
} |
m_context->detachShader(objectOrZero(program), objectOrZero(shader)); |
- shader->onDetached(m_context.get()); |
+ shader->onDetached(m_context); |
} |
void WebGLRenderingContext::disable(GLenum cap) |
@@ -3072,7 +3072,7 @@ void WebGLRenderingContext::readPixels(GLint x, GLint y, GLsizei width, GLsizei |
return; |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "readPixels", reason); |
return; |
} |
@@ -3136,7 +3136,7 @@ void WebGLRenderingContext::renderbufferStorage(GLenum target, GLenum internalfo |
m_context->renderbufferStorage(target, internalformat, width, height); |
m_renderbufferBinding->setInternalFormat(internalformat); |
m_renderbufferBinding->setSize(width, height); |
- m_renderbufferBinding->deleteEmulatedStencilBuffer(m_context.get()); |
+ m_renderbufferBinding->deleteEmulatedStencilBuffer(m_context); |
break; |
case GL_DEPTH_STENCIL_OES: |
if (isDepthStencilSupported()) { |
@@ -3465,14 +3465,14 @@ void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern |
if (GL_TEXTURE_2D == target && texture) { |
if (!canvas->is3D()) { |
ImageBuffer* buffer = canvas->buffer(); |
- if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture->object(), internalformat, type, |
+ if (buffer && buffer->copyToPlatformTexture(m_context, texture->object(), internalformat, type, |
level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas->height(), type); |
return; |
} |
} else { |
WebGLRenderingContext* gl = toWebGLRenderingContext(canvas->renderingContext()); |
- if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get(), texture->object(), internalformat, type, |
+ if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context, texture->object(), internalformat, type, |
level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas->height(), type); |
return; |
@@ -3512,7 +3512,7 @@ void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern |
// Otherwise, it will fall back to the normal SW path. |
WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
if (GL_TEXTURE_2D == target && texture) { |
- if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->object(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
+ if (video->copyVideoTextureToPlatformTexture(m_context, texture->object(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
texture->setLevelInfo(target, level, internalformat, video->videoWidth(), video->videoHeight(), type); |
return; |
} |
@@ -4006,7 +4006,7 @@ void WebGLRenderingContext::useProgram(WebGLProgram* program) |
} |
if (m_currentProgram != program) { |
if (m_currentProgram) |
- m_currentProgram->onDetached(m_context.get()); |
+ m_currentProgram->onDetached(m_context); |
m_currentProgram = program; |
m_context->useProgram(objectOrZero(program)); |
if (program) |
@@ -4226,7 +4226,7 @@ blink::WebLayer* WebGLRenderingContext::platformLayer() const |
Extensions3DUtil* WebGLRenderingContext::extensionsUtil() |
{ |
if (!m_extensionsUtil) |
- m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context.get())); |
+ m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context)); |
return m_extensionsUtil.get(); |
} |
@@ -5215,7 +5215,7 @@ bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GLenum |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); |
return false; |
} |
@@ -5265,7 +5265,7 @@ bool WebGLRenderingContext::validateDrawElements(const char* functionName, GLenu |
} |
const char* reason = "framebuffer incomplete"; |
- if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { |
+ if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reason)) { |
synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason); |
return false; |
} |
@@ -5405,13 +5405,14 @@ void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes->attributes(canvas()->document().topDocument()->url().string(), settings); |
OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::current()->createOffscreenGraphicsContext3D(attributes)); |
+ ASSERT(!m_drawingBuffer); |
if (context) { |
RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptRef(new WebGLRenderingContextEvictionManager()); |
DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->preserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; |
- m_drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize(), preserve, contextEvictionManager.release()); |
+ m_drawingBuffer = DrawingBuffer::create(context.release(), clampedCanvasSize(), preserve, contextEvictionManager.release()); |
} |
- bool failToRestore = !context || !m_drawingBuffer; |
+ bool failToRestore = !m_drawingBuffer; |
if (failToRestore) { |
if (m_contextLostMode == RealLostContext) { |
m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts); |
@@ -5426,7 +5427,7 @@ void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
m_lostContextErrors.clear(); |
- m_context = context.release(); |
+ m_context = m_drawingBuffer->context(); |
m_contextLost = false; |
setupFlags(); |