| Index: Source/platform/graphics/gpu/DrawingBuffer.cpp
|
| diff --git a/Source/platform/graphics/gpu/DrawingBuffer.cpp b/Source/platform/graphics/gpu/DrawingBuffer.cpp
|
| index a38cb2b2cac0860b50ab7694fe8406265a334b56..607a68216facf6a5eb479a95ecc0656f587caf7c 100644
|
| --- a/Source/platform/graphics/gpu/DrawingBuffer.cpp
|
| +++ b/Source/platform/graphics/gpu/DrawingBuffer.cpp
|
| @@ -78,9 +78,10 @@ private:
|
| Platform3DObject m_oldTextureUnitZeroId;
|
| };
|
|
|
| -PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
|
| +PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsContext3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
|
| {
|
| - Extensions3DUtil extensionsUtil(context);
|
| + ASSERT(context);
|
| + Extensions3DUtil extensionsUtil(context.get());
|
| bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_framebuffer_multisample")
|
| && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8");
|
| if (multisampleSupported) {
|
| @@ -91,12 +92,13 @@ PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* con
|
| if (packedDepthStencilSupported)
|
| extensionsUtil.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, multisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManager));
|
| + if (!drawingBuffer->initialize(size))
|
| + return PassRefPtr<DrawingBuffer>();
|
| return drawingBuffer.release();
|
| }
|
|
|
| -DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context,
|
| - const IntSize& size,
|
| +DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context,
|
| bool multisampleExtensionSupported,
|
| bool packedDepthStencilExtensionSupported,
|
| PreserveDrawingBuffer preserve,
|
| @@ -121,16 +123,17 @@ DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context,
|
| , m_contentsChanged(true)
|
| , m_contentsChangeCommitted(false)
|
| , m_layerComposited(false)
|
| + , m_multisampleMode(None)
|
| , m_internalColorFormat(0)
|
| , m_colorFormat(0)
|
| , m_internalRenderbufferFormat(0)
|
| , m_maxTextureSize(0)
|
| + , m_sampleCount(0)
|
| , m_packAlignment(4)
|
| , m_contextEvictionManager(contextEvictionManager)
|
| {
|
| // Used by browser tests to detect the use of a DrawingBuffer.
|
| TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation");
|
| - initialize(size);
|
| }
|
|
|
| DrawingBuffer::~DrawingBuffer()
|
| @@ -157,12 +160,12 @@ void DrawingBuffer::markLayerComposited()
|
|
|
| blink::WebGraphicsContext3D* DrawingBuffer::context()
|
| {
|
| - return m_context;
|
| + return m_context.get();
|
| }
|
|
|
| bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap)
|
| {
|
| - if (!m_context || !m_contentsChanged)
|
| + if (!m_contentsChanged)
|
| return false;
|
|
|
| m_context->makeContextCurrent();
|
| @@ -183,7 +186,7 @@ bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
|
|
|
| // We must restore the texture binding since creating new textures,
|
| // consuming and producing mailboxes changes it.
|
| - ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m_texture2DBinding);
|
| + ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureUnit, m_texture2DBinding);
|
|
|
| // First try to recycle an old buffer.
|
| RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox();
|
| @@ -246,7 +249,7 @@ void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail
|
|
|
| PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox()
|
| {
|
| - if (!m_context || m_recycledMailboxes.isEmpty())
|
| + if (m_recycledMailboxes.isEmpty())
|
| return PassRefPtr<MailboxInfo>();
|
|
|
| RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release();
|
| @@ -276,11 +279,10 @@ PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
|
| return returnMailbox.release();
|
| }
|
|
|
| -void DrawingBuffer::initialize(const IntSize& size)
|
| +bool DrawingBuffer::initialize(const IntSize& size)
|
| {
|
| - ASSERT(m_context);
|
| m_attributes = m_context->getContextAttributes();
|
| - Extensions3DUtil extensionsUtil(m_context);
|
| + Extensions3DUtil extensionsUtil(m_context.get());
|
|
|
| if (m_attributes.alpha) {
|
| m_internalColorFormat = GL_RGBA;
|
| @@ -313,12 +315,12 @@ void DrawingBuffer::initialize(const IntSize& size)
|
| else
|
| m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0);
|
| createSecondaryBuffers();
|
| - reset(size);
|
| + return reset(size);
|
| }
|
|
|
| bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context, Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY)
|
| {
|
| - if (!m_context || !m_context->makeContextCurrent())
|
| + if (!m_context->makeContextCurrent())
|
| return false;
|
| if (m_contentsChanged) {
|
| if (m_multisampleMode != None) {
|
| @@ -388,9 +390,6 @@ Platform3DObject DrawingBuffer::framebuffer() const
|
|
|
| blink::WebLayer* DrawingBuffer::platformLayer()
|
| {
|
| - if (!m_context)
|
| - return 0;
|
| -
|
| if (!m_layer) {
|
| m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->createExternalTextureLayer(this));
|
|
|
| @@ -405,7 +404,7 @@ blink::WebLayer* DrawingBuffer::platformLayer()
|
|
|
| void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer)
|
| {
|
| - if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB() != GL_NO_ERROR)
|
| + if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB() != GL_NO_ERROR)
|
| return;
|
|
|
| if (!imageBuffer)
|
| @@ -471,43 +470,40 @@ void DrawingBuffer::clearPlatformLayer()
|
| if (m_layer)
|
| m_layer->clearTexture();
|
|
|
| - if (m_context)
|
| - m_context->flush();
|
| + m_context->flush();
|
| }
|
|
|
| void DrawingBuffer::releaseResources()
|
| {
|
| - if (m_context) {
|
| - m_context->makeContextCurrent();
|
| + m_context->makeContextCurrent();
|
|
|
| - clearPlatformLayer();
|
| + clearPlatformLayer();
|
|
|
| - for (size_t i = 0; i < m_textureMailboxes.size(); i++)
|
| - m_context->deleteTexture(m_textureMailboxes[i]->textureId);
|
| + for (size_t i = 0; i < m_textureMailboxes.size(); i++)
|
| + m_context->deleteTexture(m_textureMailboxes[i]->textureId);
|
|
|
| - if (m_multisampleFBO)
|
| - m_context->deleteFramebuffer(m_multisampleFBO);
|
| + if (m_multisampleFBO)
|
| + m_context->deleteFramebuffer(m_multisampleFBO);
|
|
|
| - if (m_fbo)
|
| - m_context->deleteFramebuffer(m_fbo);
|
| + if (m_fbo)
|
| + m_context->deleteFramebuffer(m_fbo);
|
|
|
| - if (m_multisampleColorBuffer)
|
| - m_context->deleteRenderbuffer(m_multisampleColorBuffer);
|
| + if (m_multisampleColorBuffer)
|
| + m_context->deleteRenderbuffer(m_multisampleColorBuffer);
|
|
|
| - if (m_depthStencilBuffer)
|
| - m_context->deleteRenderbuffer(m_depthStencilBuffer);
|
| + if (m_depthStencilBuffer)
|
| + m_context->deleteRenderbuffer(m_depthStencilBuffer);
|
|
|
| - if (m_depthBuffer)
|
| - m_context->deleteRenderbuffer(m_depthBuffer);
|
| + if (m_depthBuffer)
|
| + m_context->deleteRenderbuffer(m_depthBuffer);
|
|
|
| - if (m_stencilBuffer)
|
| - m_context->deleteRenderbuffer(m_stencilBuffer);
|
| + if (m_stencilBuffer)
|
| + m_context->deleteRenderbuffer(m_stencilBuffer);
|
|
|
| - if (m_colorBuffer)
|
| - m_context->deleteTexture(m_colorBuffer);
|
| + if (m_colorBuffer)
|
| + m_context->deleteTexture(m_colorBuffer);
|
|
|
| - m_context = 0;
|
| - }
|
| + m_context.clear();
|
|
|
| setSize(IntSize());
|
|
|
| @@ -532,9 +528,6 @@ void DrawingBuffer::releaseResources()
|
|
|
| unsigned DrawingBuffer::createColorTexture(const IntSize& size)
|
| {
|
| - if (!m_context)
|
| - return 0;
|
| -
|
| unsigned offscreenColorTexture = m_context->createTexture();
|
| if (!offscreenColorTexture)
|
| return 0;
|
| @@ -651,9 +644,6 @@ void DrawingBuffer::resizeDepthStencil(const IntSize& size)
|
|
|
| void DrawingBuffer::clearFramebuffers(GLbitfield clearMask)
|
| {
|
| - if (!m_context)
|
| - return;
|
| -
|
| // We will clear the multisample FBO, but we also need to clear the non-multisampled buffer.
|
| if (m_multisampleFBO) {
|
| m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
| @@ -721,11 +711,9 @@ IntSize DrawingBuffer::adjustSizeWithContextEviction(const IntSize& size, bool&
|
| return adjustedSize;
|
| }
|
|
|
| -void DrawingBuffer::reset(const IntSize& newSize)
|
| +bool DrawingBuffer::reset(const IntSize& newSize)
|
| {
|
| - if (!m_context)
|
| - return;
|
| -
|
| + ASSERT(!newSize.isEmpty());
|
| IntSize adjustedSize;
|
| bool evictContext = false;
|
| bool isNewContext = m_size.isEmpty();
|
| @@ -735,7 +723,7 @@ void DrawingBuffer::reset(const IntSize& newSize)
|
| adjustedSize = adjustSize(newSize);
|
|
|
| if (adjustedSize.isEmpty())
|
| - return;
|
| + return false;
|
|
|
| if (evictContext)
|
| m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL contexts have exceeded the maximum allowed backbuffer area. Oldest context will be lost.");
|
| @@ -753,7 +741,7 @@ void DrawingBuffer::reset(const IntSize& newSize)
|
| setSize(adjustedSize);
|
|
|
| if (adjustedSize.isEmpty())
|
| - return;
|
| + return false;
|
| }
|
|
|
| m_context->disable(GL_SCISSOR_TEST);
|
| @@ -773,13 +761,11 @@ void DrawingBuffer::reset(const IntSize& newSize)
|
| }
|
|
|
| clearFramebuffers(clearMask);
|
| + return true;
|
| }
|
|
|
| void DrawingBuffer::commit(long x, long y, long width, long height)
|
| {
|
| - if (!m_context)
|
| - return;
|
| -
|
| if (width < 0)
|
| width = m_size.width();
|
| if (height < 0)
|
| @@ -807,7 +793,7 @@ void DrawingBuffer::commit(long x, long y, long width, long height)
|
|
|
| void DrawingBuffer::restoreFramebufferBinding()
|
| {
|
| - if (!m_context || !m_framebufferBinding)
|
| + if (!m_framebufferBinding)
|
| return;
|
|
|
| m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding);
|
| @@ -820,9 +806,6 @@ bool DrawingBuffer::multisample() const
|
|
|
| void DrawingBuffer::bind()
|
| {
|
| - if (!m_context)
|
| - return;
|
| -
|
| m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo);
|
| }
|
|
|
|
|