Index: Source/platform/graphics/gpu/DrawingBuffer.cpp |
diff --git a/Source/platform/graphics/gpu/DrawingBuffer.cpp b/Source/platform/graphics/gpu/DrawingBuffer.cpp |
index c02d95270d991a66d230631ed60e330f79ac6948..0f2e25d7551f5c50ac2062eb12ddc2cbe309a2ef 100644 |
--- a/Source/platform/graphics/gpu/DrawingBuffer.cpp |
+++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp |
@@ -57,7 +57,7 @@ static const int s_maxScaleAttempts = 3; |
class ScopedTextureUnit0BindingRestorer { |
public: |
- ScopedTextureUnit0BindingRestorer(GraphicsContext3D* context, GLenum activeTextureUnit, Platform3DObject textureUnitZeroId) |
+ ScopedTextureUnit0BindingRestorer(blink::WebGraphicsContext3D* context, GLenum activeTextureUnit, Platform3DObject textureUnitZeroId) |
: m_context(context) |
, m_oldActiveTextureUnit(activeTextureUnit) |
, m_oldTextureUnitZeroId(textureUnitZeroId) |
@@ -71,41 +71,45 @@ public: |
} |
private: |
- GraphicsContext3D* m_context; |
+ blink::WebGraphicsContext3D* m_context; |
GLenum m_oldActiveTextureUnit; |
Platform3DObject m_oldTextureUnitZeroId; |
}; |
-PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager) |
+PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager) |
{ |
- bool multisampleSupported = context->supportsExtension("GL_ANGLE_framebuffer_blit") |
- && context->supportsExtension("GL_ANGLE_framebuffer_multisample") |
- && context->supportsExtension("GL_OES_rgb8_rgba8"); |
+ RefPtr<GraphicsContext3D> contextSupport(GraphicsContext3D::createContextSupport(context)); |
bajones
2014/01/08 03:13:08
Rather than require that both the context and cont
|
+ |
+ bool multisampleSupported = contextSupport->supportsExtension("GL_ANGLE_framebuffer_blit") |
+ && contextSupport->supportsExtension("GL_ANGLE_framebuffer_multisample") |
+ && contextSupport->supportsExtension("GL_OES_rgb8_rgba8"); |
if (multisampleSupported) { |
- context->ensureExtensionEnabled("GL_ANGLE_framebuffer_blit"); |
- context->ensureExtensionEnabled("GL_ANGLE_framebuffer_multisample"); |
- context->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
+ contextSupport->ensureExtensionEnabled("GL_ANGLE_framebuffer_blit"); |
+ contextSupport->ensureExtensionEnabled("GL_ANGLE_framebuffer_multisample"); |
+ contextSupport->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
} |
- bool packedDepthStencilSupported = context->supportsExtension("GL_OES_packed_depth_stencil"); |
+ bool packedDepthStencilSupported = contextSupport->supportsExtension("GL_OES_packed_depth_stencil"); |
if (packedDepthStencilSupported) |
- context->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
+ contextSupport->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
- RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManager)); |
+ RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, contextSupport.get(), size, multisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManager)); |
return drawingBuffer.release(); |
} |
-DrawingBuffer::DrawingBuffer(GraphicsContext3D* context, |
- const IntSize& size, |
- bool multisampleExtensionSupported, |
- bool packedDepthStencilExtensionSupported, |
- PreserveDrawingBuffer preserve, |
- PassRefPtr<ContextEvictionManager> contextEvictionManager) |
+DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context, |
+ GraphicsContext3D* contextSupport, |
+ const IntSize& size, |
+ bool multisampleExtensionSupported, |
+ bool packedDepthStencilExtensionSupported, |
+ PreserveDrawingBuffer preserve, |
+ PassRefPtr<ContextEvictionManager> contextEvictionManager) |
: m_preserveDrawingBuffer(preserve) |
, m_scissorEnabled(false) |
, m_texture2DBinding(0) |
, m_framebufferBinding(0) |
, m_activeTextureUnit(GL_TEXTURE0) |
, m_context(context) |
+ , m_contextSupport(contextSupport) |
, m_size(-1, -1) |
, m_multisampleExtensionSupported(multisampleExtensionSupported) |
, m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupported) |
@@ -143,9 +147,7 @@ void DrawingBuffer::markContentsChanged() |
blink::WebGraphicsContext3D* DrawingBuffer::context() |
{ |
- if (!m_context) |
- return 0; |
- return m_context->webContext(); |
+ return m_context; |
} |
bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap) |
@@ -166,12 +168,12 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, |
bool needPremultiply = m_attributes.alpha && !m_attributes.premultipliedAlpha; |
GraphicsContext3D::AlphaOp op = needPremultiply ? GraphicsContext3D::AlphaDoPremultiply : GraphicsContext3D::AlphaDoNothing; |
if (pixels) |
- m_context->readBackFramebuffer(pixels, size().width(), size().height(), GraphicsContext3D::ReadbackSkia, op); |
+ m_contextSupport->readBackFramebuffer(pixels, size().width(), size().height(), GraphicsContext3D::ReadbackSkia, op); |
} |
// We must restore the texture binding since creating new textures, |
// consuming and producing mailboxes changes it. |
- ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureUnit, m_texture2DBinding); |
+ ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m_texture2DBinding); |
// First try to recycle an old buffer. |
RefPtr<MailboxInfo> nextFrontColorBuffer = recycledMailbox(); |
@@ -196,7 +198,7 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, |
m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0); |
} else { |
- m_context->webContext()->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer, nextFrontColorBuffer->textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
+ m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer, nextFrontColorBuffer->textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
} |
if (multisample() && !m_framebufferBinding) |
@@ -206,10 +208,10 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, |
m_contentsChanged = false; |
- context()->bindTexture(GL_TEXTURE_2D, nextFrontColorBuffer->textureId); |
- context()->produceTextureCHROMIUM(GL_TEXTURE_2D, nextFrontColorBuffer->mailbox.name); |
- context()->flush(); |
- m_context->markLayerComposited(); |
+ m_context->bindTexture(GL_TEXTURE_2D, nextFrontColorBuffer->textureId); |
+ m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, nextFrontColorBuffer->mailbox.name); |
+ m_context->flush(); |
+ m_contextSupport->markLayerComposited(); |
*outMailbox = nextFrontColorBuffer->mailbox; |
m_frontColorBuffer = nextFrontColorBuffer->textureId; |
@@ -238,15 +240,15 @@ PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
m_recycledMailboxes.removeLast(); |
if (mailboxInfo->mailbox.syncPoint) { |
- context()->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
+ m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
mailboxInfo->mailbox.syncPoint = 0; |
} |
- context()->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
- context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->mailbox.name); |
+ m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
+ m_context->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->mailbox.name); |
if (mailboxInfo->size != m_size) { |
- m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
+ m_contextSupport->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
mailboxInfo->size = m_size; |
} |
@@ -256,7 +258,7 @@ PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned textureId) |
{ |
RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
- context()->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
+ m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
returnMailbox->textureId = textureId; |
returnMailbox->size = m_size; |
m_textureMailboxes.append(returnMailbox); |
@@ -300,7 +302,7 @@ unsigned DrawingBuffer::frontColorBuffer() const |
return m_frontColorBuffer; |
} |
-bool DrawingBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY) |
+bool DrawingBuffer::copyToPlatformTexture(GraphicsContext3D& contextSupport, Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY) |
{ |
if (!m_context || !m_context->makeContextCurrent()) |
return false; |
@@ -316,10 +318,12 @@ bool DrawingBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3D |
} |
Platform3DObject sourceTexture = colorBuffer(); |
- if (!context.makeContextCurrent()) |
+ blink::WebGraphicsContext3D* context = contextSupport.webContext(); |
+ |
+ if (!context->makeContextCurrent()) |
return false; |
- if (!context.supportsExtension("GL_CHROMIUM_copy_texture") || !context.supportsExtension("GL_CHROMIUM_flipy") |
- || !context.canUseCopyTextureCHROMIUM(internalFormat, destType, level)) |
+ if (!contextSupport.supportsExtension("GL_CHROMIUM_copy_texture") || !contextSupport.supportsExtension("GL_CHROMIUM_flipy") |
+ || !contextSupport.canUseCopyTextureCHROMIUM(internalFormat, destType, level)) |
return false; |
bool unpackPremultiplyAlphaNeeded = false; |
@@ -329,14 +333,14 @@ bool DrawingBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3D |
else if (m_attributes.alpha && !m_attributes.premultipliedAlpha && premultiplyAlpha) |
unpackPremultiplyAlphaNeeded = true; |
- context.pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpackUnpremultiplyAlphaNeeded); |
- context.pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackPremultiplyAlphaNeeded); |
- context.pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, flipY); |
- context.webContext()->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, level, internalFormat, destType); |
- context.pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false); |
- context.pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false); |
- context.pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false); |
- context.flush(); |
+ context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpackUnpremultiplyAlphaNeeded); |
+ context->pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackPremultiplyAlphaNeeded); |
+ context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, flipY); |
+ context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, level, internalFormat, destType); |
+ context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false); |
+ context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false); |
+ context->pixelStorei(GC3D_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false); |
+ context->flush(); |
return true; |
} |
@@ -365,14 +369,14 @@ blink::WebLayer* DrawingBuffer::platformLayer() |
void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
{ |
- if (!m_context || !m_context->makeContextCurrent() || m_context->webContext()->getGraphicsResetStatusARB() != GL_NO_ERROR) |
+ if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB() != GL_NO_ERROR) |
return; |
if (!imageBuffer) |
return; |
Platform3DObject tex = imageBuffer->getBackingTexture(); |
if (tex) { |
- m_context->webContext()->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, |
+ m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, |
tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
return; |
} |
@@ -382,7 +386,7 @@ void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
// FIXME: That's not true any more, provided we don't change texture |
// parameters. |
unsigned sourceTexture = createColorTexture(m_size); |
- m_context->webContext()->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, sourceTexture, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
+ m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, sourceTexture, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
// Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding). |
// FIXME: The WebGLRenderingContext tracks the current framebuffer binding, it would be slightly more efficient to use this value |
@@ -394,7 +398,7 @@ void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sourceTexture, 0); |
- m_context->paintFramebufferToCanvas(framebuffer, size().width(), size().height(), !m_attributes.premultipliedAlpha, imageBuffer); |
+ m_contextSupport->paintFramebufferToCanvas(framebuffer, size().width(), size().height(), !m_attributes.premultipliedAlpha, imageBuffer); |
m_context->deleteFramebuffer(framebuffer); |
m_context->deleteTexture(sourceTexture); |
@@ -438,7 +442,8 @@ void DrawingBuffer::releaseResources() |
if (m_fbo) |
m_context->deleteFramebuffer(m_fbo); |
- m_context.clear(); |
+ m_contextSupport.clear(); |
+ m_context = 0; |
} |
setSize(IntSize()); |
@@ -478,7 +483,7 @@ unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
if (!size.isEmpty()) |
- m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
+ m_contextSupport->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
return offscreenColorTexture; |
} |
@@ -499,7 +504,7 @@ bool DrawingBuffer::resizeFramebuffer(const IntSize& size) |
m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer); |
- m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
+ m_contextSupport->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
if (m_lastColorBuffer) |
m_lastColorBuffer->size = size; |
@@ -521,7 +526,7 @@ bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) |
m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
m_context->bindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); |
- m_context->webContext()->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, m_internalRenderbufferFormat, size.width(), size.height()); |
+ m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, m_internalRenderbufferFormat, size.width(), size.height()); |
if (m_context->getError() == GL_OUT_OF_MEMORY) |
return false; |
@@ -542,7 +547,7 @@ void DrawingBuffer::resizeDepthStencil(const IntSize& size) |
m_depthStencilBuffer = m_context->createRenderbuffer(); |
m_context->bindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); |
if (multisample()) |
- m_context->webContext()->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
+ m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
else |
m_context->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |
m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer); |
@@ -553,7 +558,7 @@ void DrawingBuffer::resizeDepthStencil(const IntSize& size) |
m_depthBuffer = m_context->createRenderbuffer(); |
m_context->bindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer); |
if (multisample()) |
- m_context->webContext()->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH_COMPONENT16, size.width(), size.height()); |
+ m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_DEPTH_COMPONENT16, size.width(), size.height()); |
else |
m_context->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.width(), size.height()); |
m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer); |
@@ -563,7 +568,7 @@ void DrawingBuffer::resizeDepthStencil(const IntSize& size) |
m_stencilBuffer = m_context->createRenderbuffer(); |
m_context->bindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer); |
if (multisample()) |
- m_context->webContext()->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_STENCIL_INDEX8, size.width(), size.height()); |
+ m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount, GL_STENCIL_INDEX8, size.width(), size.height()); |
else |
m_context->renderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, size.width(), size.height()); |
m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilBuffer); |
@@ -720,7 +725,7 @@ void DrawingBuffer::commit(long x, long y, long width, long height) |
m_context->disable(GL_SCISSOR_TEST); |
// Use NEAREST, because there is no scale performed during the blit. |
- m_context->webContext()->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
+ m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
if (m_scissorEnabled) |
m_context->enable(GL_SCISSOR_TEST); |