| Index: trunk/Source/platform/graphics/gpu/DrawingBuffer.cpp
|
| ===================================================================
|
| --- trunk/Source/platform/graphics/gpu/DrawingBuffer.cpp (revision 168480)
|
| +++ trunk/Source/platform/graphics/gpu/DrawingBuffer.cpp (working copy)
|
| @@ -77,10 +77,9 @@
|
| Platform3DObject m_oldTextureUnitZeroId;
|
| };
|
|
|
| -PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsContext3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
|
| +PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManager> contextEvictionManager)
|
| {
|
| - ASSERT(context);
|
| - Extensions3DUtil extensionsUtil(context.get());
|
| + Extensions3DUtil extensionsUtil(context);
|
| bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_framebuffer_multisample")
|
| && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8");
|
| if (multisampleSupported) {
|
| @@ -91,13 +90,12 @@
|
| if (packedDepthStencilSupported)
|
| extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil");
|
|
|
| - RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, multisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManager));
|
| - if (!drawingBuffer->initialize(size))
|
| - return PassRefPtr<DrawingBuffer>();
|
| + RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManager));
|
| return drawingBuffer.release();
|
| }
|
|
|
| -DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context,
|
| +DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context,
|
| + const IntSize& size,
|
| bool multisampleExtensionSupported,
|
| bool packedDepthStencilExtensionSupported,
|
| PreserveDrawingBuffer preserve,
|
| @@ -126,12 +124,12 @@
|
| , 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()
|
| @@ -158,12 +156,12 @@
|
|
|
| blink::WebGraphicsContext3D* DrawingBuffer::context()
|
| {
|
| - return m_context.get();
|
| + return m_context;
|
| }
|
|
|
| bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap)
|
| {
|
| - if (!m_contentsChanged)
|
| + if (!m_context || !m_contentsChanged)
|
| return false;
|
|
|
| m_context->makeContextCurrent();
|
| @@ -184,7 +182,7 @@
|
|
|
| // 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> frontColorBufferMailbox = recycledMailbox();
|
| @@ -247,7 +245,7 @@
|
|
|
| PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox()
|
| {
|
| - if (m_recycledMailboxes.isEmpty())
|
| + if (!m_context || m_recycledMailboxes.isEmpty())
|
| return PassRefPtr<MailboxInfo>();
|
|
|
| RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release();
|
| @@ -277,10 +275,11 @@
|
| return returnMailbox.release();
|
| }
|
|
|
| -bool DrawingBuffer::initialize(const IntSize& size)
|
| +void DrawingBuffer::initialize(const IntSize& size)
|
| {
|
| + ASSERT(m_context);
|
| m_attributes = m_context->getContextAttributes();
|
| - Extensions3DUtil extensionsUtil(m_context.get());
|
| + Extensions3DUtil extensionsUtil(m_context);
|
|
|
| if (m_attributes.alpha) {
|
| m_internalColorFormat = GL_RGBA;
|
| @@ -313,12 +312,12 @@
|
| else
|
| m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0);
|
| createSecondaryBuffers();
|
| - return reset(size);
|
| + reset(size);
|
| }
|
|
|
| bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context, Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY)
|
| {
|
| - if (!m_context->makeContextCurrent())
|
| + if (!m_context || !m_context->makeContextCurrent())
|
| return false;
|
| if (m_contentsChanged) {
|
| if (m_multisampleMode != None) {
|
| @@ -364,6 +363,9 @@
|
|
|
| blink::WebLayer* DrawingBuffer::platformLayer()
|
| {
|
| + if (!m_context)
|
| + return 0;
|
| +
|
| if (!m_layer) {
|
| m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->createExternalTextureLayer(this));
|
|
|
| @@ -378,7 +380,7 @@
|
|
|
| void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer)
|
| {
|
| - if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB() != GL_NO_ERROR)
|
| + if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB() != GL_NO_ERROR)
|
| return;
|
|
|
| if (!imageBuffer)
|
| @@ -419,37 +421,40 @@
|
| if (m_layer)
|
| m_layer->clearTexture();
|
|
|
| - m_context->flush();
|
| + if (m_context)
|
| + m_context->flush();
|
| }
|
|
|
| void DrawingBuffer::releaseResources()
|
| {
|
| - m_context->makeContextCurrent();
|
| + if (m_context) {
|
| + 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_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_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);
|
|
|
| - m_context.clear();
|
| + m_context = 0;
|
| + }
|
|
|
| setSize(IntSize());
|
|
|
| @@ -474,6 +479,9 @@
|
|
|
| unsigned DrawingBuffer::createColorTexture(const IntSize& size)
|
| {
|
| + if (!m_context)
|
| + return 0;
|
| +
|
| unsigned offscreenColorTexture = m_context->createTexture();
|
| if (!offscreenColorTexture)
|
| return 0;
|
| @@ -590,6 +598,9 @@
|
|
|
| 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);
|
| @@ -657,9 +668,11 @@
|
| return adjustedSize;
|
| }
|
|
|
| -bool DrawingBuffer::reset(const IntSize& newSize)
|
| +void DrawingBuffer::reset(const IntSize& newSize)
|
| {
|
| - ASSERT(!newSize.isEmpty());
|
| + if (!m_context)
|
| + return;
|
| +
|
| IntSize adjustedSize;
|
| bool evictContext = false;
|
| bool isNewContext = m_size.isEmpty();
|
| @@ -669,7 +682,7 @@
|
| adjustedSize = adjustSize(newSize);
|
|
|
| if (adjustedSize.isEmpty())
|
| - return false;
|
| + return;
|
|
|
| if (evictContext)
|
| m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL contexts have exceeded the maximum allowed backbuffer area. Oldest context will be lost.");
|
| @@ -687,7 +700,7 @@
|
| setSize(adjustedSize);
|
|
|
| if (adjustedSize.isEmpty())
|
| - return false;
|
| + return;
|
| }
|
|
|
| m_context->disable(GL_SCISSOR_TEST);
|
| @@ -707,11 +720,13 @@
|
| }
|
|
|
| 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)
|
| @@ -739,7 +754,7 @@
|
|
|
| void DrawingBuffer::restoreFramebufferBinding()
|
| {
|
| - if (!m_framebufferBinding)
|
| + if (!m_context || !m_framebufferBinding)
|
| return;
|
|
|
| m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding);
|
| @@ -752,6 +767,9 @@
|
|
|
| void DrawingBuffer::bind()
|
| {
|
| + if (!m_context)
|
| + return;
|
| +
|
| m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo);
|
| }
|
|
|
|
|