Changeset 100032 in webkit


Ignore:
Timestamp:
Nov 11, 2011 2:55:11 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Patch that implementing the changes required to allow WebGL
to share its backing store directly with the compositor.
WebGL rendering contexts create and render to FBOs managed by a
DrawingBuffer instance. All PlatformLayer lifetime management is
performed by the DrawingBuffer.
Changes are only relevant to Chromium ports. Functionality is
unchanged for other ports.
https://bugs.webkit.org/show_bug.cgi?id=53201

Patch by Jeff Timanus <twiz@chromium.org> on 2011-11-11
Reviewed by Stephen White.

Source/WebCore:

  • html/canvas/WebGLRenderingContext.cpp: Construct a DrawingBuffer

during initialization, and forward all framebuffer management calls to
it.
(WebCore::WebGLRenderingContext::create):
(WebCore::WebGLRenderingContext::WebGLRenderingContext):
(WebCore::WebGLRenderingContext::initializeNewContext):
(WebCore::WebGLRenderingContext::markContextChanged):
(WebCore::WebGLRenderingContext::clearIfComposited):
(WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
(WebCore::WebGLRenderingContext::paintRenderingResultsToImageData):
(WebCore::WebGLRenderingContext::reshape):
(WebCore::WebGLRenderingContext::drawingBufferWidth):
(WebCore::WebGLRenderingContext::drawingBufferHeight):
(WebCore::WebGLRenderingContext::bindFramebuffer):
(WebCore::WebGLRenderingContext::copyTexImage2D):
(WebCore::WebGLRenderingContext::copyTexSubImage2D):
(WebCore::WebGLRenderingContext::deleteFramebuffer):
(WebCore::WebGLRenderingContext::disable):
(WebCore::WebGLRenderingContext::enable):
(WebCore::WebGLRenderingContext::readPixels):
(WebCore::WebGLRenderingContext::platformLayer):
(WebCore::WebGLRenderingContext::getBoundFramebufferWidth):
(WebCore::WebGLRenderingContext::getBoundFramebufferHeight):
(WebCore::WebGLRenderingContext::maybeRestoreContext):

  • html/canvas/WebGLRenderingContext.h:
  • platform/graphics/GraphicsContext3D.cpp:
  • platform/graphics/GraphicsContext3D.h: WebGLLayerChromium instances

are no longer tracked by GraphicsContext3D. Callers can now pass a
DrawingBuffer instance to provide access to the WebGLLayerChromium data.

  • platform/graphics/chromium/DrawingBufferChromium.cpp:

(WebCore::generateColorTexture):
(WebCore::DrawingBuffer::DrawingBuffer):
(WebCore::DrawingBuffer::initialize):
(WebCore::DrawingBuffer::publishToPlatformLayer):
(WebCore::DrawingBuffer::platformLayer):
(WebCore::DrawingBuffer::platformColorBuffer):
(WebCore::DrawingBuffer::framebuffer):
(WebCore::DrawingBuffer::markContextChanged):
(WebCore::DrawingBuffer::paintCompositedResultsToCanvas):

  • platform/graphics/chromium/WebGLLayerChromium.cpp:

(WebCore::WebGLLayerChromium::WebGLLayerChromium):
(WebCore::WebGLLayerChromium::~WebGLLayerChromium):
(WebCore::WebGLLayerChromium::drawsContent):
(WebCore::WebGLLayerChromium::updateCompositorResources):
(WebCore::WebGLLayerChromium::paintRenderedResultsToCanvas):
(WebCore::WebGLLayerChromium::contentChanged):
(WebCore::WebGLLayerChromium::setDrawingBuffer):
(WebCore::WebGLLayerChromium::context):

  • platform/graphics/chromium/WebGLLayerChromium.h: WebGLLayerChromium instances

have a raw reference to their owning DrawingBuffer. This reference is set to NULL on
destruction of the DrawingBuffer. This follows the old code, which had the WebGLLayerChromium
refer rawly to a GraphicsContext3D instance, which was also revoked during tear-down of the
GraphicsContext3D.
(WebCore::WebGLLayerChromium::drawingBuffer):

  • platform/graphics/efl/GraphicsContext3DEfl.cpp:

(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::paintRenderingResultsToImageData):

  • platform/graphics/gpu/DrawingBuffer.cpp: The DrawingBuffer is now the

central point between the GraphicsContext3D, WebGLRenderingContext, and
WebGLLayerChromium classes. GraphicsContext3D, and WebGLLayerChromium only
depend on the DrawingBuffer interface.
(WebCore::DrawingBuffer::create):
(WebCore::DrawingBuffer::clear):
(WebCore::DrawingBuffer::clearFramebuffer):
(WebCore::DrawingBuffer::reset):
(WebCore::DrawingBuffer::commit):
(WebCore::DrawingBuffer::multisample):
(WebCore::DrawingBuffer::paintRenderingResultsToImageData):
(WebCore::DrawingBuffer::discardResources):

  • platform/graphics/gpu/DrawingBuffer.h:

(WebCore::DrawingBuffer::setScissorEnabled):

  • platform/graphics/gpu/mac/DrawingBufferMac.mm:

(WebCore::DrawingBuffer::DrawingBuffer):

  • platform/graphics/gpu/qt/DrawingBufferQt.cpp:

(WebCore::DrawingBuffer::DrawingBuffer):

  • platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:

(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::paintRenderingResultsToImageData):

  • platform/graphics/qt/GraphicsContext3DQt.cpp:

(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::paintRenderingResultsToImageData):

Source/WebKit/chromium:

  • src/GraphicsContext3DChromium.cpp: GraphicsContext3DPrivate no longer caches

the WebGLLayerChromium instance. Instead, it is accessed via DrawingBuffer instances
passed as arguments to the necessary routines.
(WebCore::GraphicsContext3DPrivate::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3DPrivate::paintCompositedResultsToCanvas):
(WebCore::GraphicsContext3DPrivate::paintRenderingResultsToImageData):
(WebCore::GraphicsContext3D::~GraphicsContext3D):
(WebCore::GraphicsContext3D::platformLayer):
(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::paintRenderingResultsToImageData):

  • src/GraphicsContext3DPrivate.h:
Location:
trunk/Source
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r100030 r100032  
     12011-11-11  Jeff Timanus  <twiz@chromium.org>
     2
     3        [chromium] Patch that implementing the changes required to allow WebGL
     4        to share its backing store directly with the compositor.
     5        WebGL rendering contexts create and render to FBOs managed by a
     6        DrawingBuffer instance. All PlatformLayer lifetime management is
     7        performed by the DrawingBuffer.
     8        Changes are only relevant to Chromium ports. Functionality is
     9        unchanged for other ports.
     10        https://bugs.webkit.org/show_bug.cgi?id=53201
     11
     12        Reviewed by Stephen White.
     13
     14        * html/canvas/WebGLRenderingContext.cpp: Construct a DrawingBuffer
     15        during initialization, and forward all framebuffer management calls to
     16        it.
     17        (WebCore::WebGLRenderingContext::create):
     18        (WebCore::WebGLRenderingContext::WebGLRenderingContext):
     19        (WebCore::WebGLRenderingContext::initializeNewContext):
     20        (WebCore::WebGLRenderingContext::markContextChanged):
     21        (WebCore::WebGLRenderingContext::clearIfComposited):
     22        (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
     23        (WebCore::WebGLRenderingContext::paintRenderingResultsToImageData):
     24        (WebCore::WebGLRenderingContext::reshape):
     25        (WebCore::WebGLRenderingContext::drawingBufferWidth):
     26        (WebCore::WebGLRenderingContext::drawingBufferHeight):
     27        (WebCore::WebGLRenderingContext::bindFramebuffer):
     28        (WebCore::WebGLRenderingContext::copyTexImage2D):
     29        (WebCore::WebGLRenderingContext::copyTexSubImage2D):
     30        (WebCore::WebGLRenderingContext::deleteFramebuffer):
     31        (WebCore::WebGLRenderingContext::disable):
     32        (WebCore::WebGLRenderingContext::enable):
     33        (WebCore::WebGLRenderingContext::readPixels):
     34        (WebCore::WebGLRenderingContext::platformLayer):
     35        (WebCore::WebGLRenderingContext::getBoundFramebufferWidth):
     36        (WebCore::WebGLRenderingContext::getBoundFramebufferHeight):
     37        (WebCore::WebGLRenderingContext::maybeRestoreContext):
     38        * html/canvas/WebGLRenderingContext.h:
     39        * platform/graphics/GraphicsContext3D.cpp:
     40        * platform/graphics/GraphicsContext3D.h:  WebGLLayerChromium instances
     41        are no longer tracked by GraphicsContext3D. Callers can now pass a
     42        DrawingBuffer instance to provide access to the WebGLLayerChromium data.
     43        * platform/graphics/chromium/DrawingBufferChromium.cpp:
     44        (WebCore::generateColorTexture):
     45        (WebCore::DrawingBuffer::DrawingBuffer):
     46        (WebCore::DrawingBuffer::initialize):
     47        (WebCore::DrawingBuffer::publishToPlatformLayer):
     48        (WebCore::DrawingBuffer::platformLayer):
     49        (WebCore::DrawingBuffer::platformColorBuffer):
     50        (WebCore::DrawingBuffer::framebuffer):
     51        (WebCore::DrawingBuffer::markContextChanged):
     52        (WebCore::DrawingBuffer::paintCompositedResultsToCanvas):
     53        * platform/graphics/chromium/WebGLLayerChromium.cpp:
     54        (WebCore::WebGLLayerChromium::WebGLLayerChromium):
     55        (WebCore::WebGLLayerChromium::~WebGLLayerChromium):
     56        (WebCore::WebGLLayerChromium::drawsContent):
     57        (WebCore::WebGLLayerChromium::updateCompositorResources):
     58        (WebCore::WebGLLayerChromium::paintRenderedResultsToCanvas):
     59        (WebCore::WebGLLayerChromium::contentChanged):
     60        (WebCore::WebGLLayerChromium::setDrawingBuffer):
     61        (WebCore::WebGLLayerChromium::context):
     62        * platform/graphics/chromium/WebGLLayerChromium.h: WebGLLayerChromium instances
     63        have a raw reference to their owning DrawingBuffer.  This reference is set to NULL on
     64        destruction of the DrawingBuffer.  This follows the old code, which had the WebGLLayerChromium
     65        refer rawly to a GraphicsContext3D instance, which was also revoked during tear-down of the
     66        GraphicsContext3D.
     67        (WebCore::WebGLLayerChromium::drawingBuffer):
     68        * platform/graphics/efl/GraphicsContext3DEfl.cpp:
     69        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
     70        (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
     71        * platform/graphics/gpu/DrawingBuffer.cpp: The DrawingBuffer is now the
     72        central point between the GraphicsContext3D, WebGLRenderingContext, and
     73        WebGLLayerChromium classes.  GraphicsContext3D, and WebGLLayerChromium only
     74        depend on the DrawingBuffer interface.
     75        (WebCore::DrawingBuffer::create):
     76        (WebCore::DrawingBuffer::clear):
     77        (WebCore::DrawingBuffer::clearFramebuffer):
     78        (WebCore::DrawingBuffer::reset):
     79        (WebCore::DrawingBuffer::commit):
     80        (WebCore::DrawingBuffer::multisample):
     81        (WebCore::DrawingBuffer::paintRenderingResultsToImageData):
     82        (WebCore::DrawingBuffer::discardResources):
     83        * platform/graphics/gpu/DrawingBuffer.h:
     84        (WebCore::DrawingBuffer::setScissorEnabled):
     85        * platform/graphics/gpu/mac/DrawingBufferMac.mm:
     86        (WebCore::DrawingBuffer::DrawingBuffer):
     87        * platform/graphics/gpu/qt/DrawingBufferQt.cpp:
     88        (WebCore::DrawingBuffer::DrawingBuffer):
     89        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
     90        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
     91        (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
     92        * platform/graphics/qt/GraphicsContext3DQt.cpp:
     93        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
     94        (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
     95
    1962011-11-11  Darin Adler  <darin@apple.com>
    297
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r99645 r100032  
    367367
    368368    attributes.noExtensions = true;
     369#if PLATFORM(CHROMIUM)
     370    attributes.shareResources = true;
     371#else
    369372    attributes.shareResources = false;
     373#endif
     374
    370375
    371376    RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes, hostWindow));
     
    383388    : CanvasRenderingContext(passedCanvas)
    384389    , m_context(context)
     390    , m_drawingBuffer(0)
    385391    , m_restoreAllowed(false)
    386392    , m_restoreTimer(this)
     
    390396{
    391397    ASSERT(m_context);
     398
     399#if PLATFORM(CHROMIUM)
     400    // Create the DrawingBuffer and initialize the platform layer.
     401    m_drawingBuffer = DrawingBuffer::create(m_context.get(), IntSize(canvas()->width(), canvas()->height()), !m_attributes.preserveDrawingBuffer);
     402#endif
     403
     404    if (m_drawingBuffer)
     405        m_drawingBuffer->bind();
     406
    392407    setupFlags();
    393408    initializeNewContext();
     
    455470        initVertexAttrib0();
    456471
     472    if (m_drawingBuffer)
     473        m_drawingBuffer->reset(IntSize(canvas()->width(), canvas()->height()));
     474
    457475    m_context->reshape(canvas()->width(), canvas()->height());
    458476    m_context->viewport(0, 0, canvas()->width(), canvas()->height());
     
    495513    if (m_framebufferBinding)
    496514        return;
     515
    497516    m_context->markContextChanged();
     517
    498518    m_layerCleared = false;
    499519#if USE(ACCELERATED_COMPOSITING)
     
    525545    bool combinedClear = mask && !m_scissorEnabled;
    526546
    527     if (m_framebufferBinding)
    528         m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
     547    if (m_framebufferBinding) {
     548        if (m_drawingBuffer)
     549            m_drawingBuffer->bind();
     550        else
     551            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
     552    }
    529553    m_context->disable(GraphicsContext3D::SCISSOR_TEST);
    530554    if (combinedClear && (mask & GraphicsContext3D::COLOR_BUFFER_BIT))
     
    582606    if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) {
    583607        m_context->paintCompositedResultsToCanvas(this);
     608
     609#if USE(ACCELERATED_COMPOSITING) && PLATFORM(CHROMIUM)
     610        if (m_drawingBuffer)
     611            m_drawingBuffer->paintCompositedResultsToCanvas(this);
     612#endif
     613
    584614        canvas()->makePresentationCopy();
    585615    } else
    586616        canvas()->clearPresentationCopy();
    587617    clearIfComposited();
     618
    588619    if (!m_markedCanvasDirty && !m_layerCleared)
    589620        return;
     621
    590622    canvas()->clearCopiedImage();
    591623    m_markedCanvasDirty = false;
    592     m_context->paintRenderingResultsToCanvas(this);
     624
     625    if (m_drawingBuffer)
     626        m_drawingBuffer->commit();
     627    m_context->paintRenderingResultsToCanvas(this, m_drawingBuffer.get());
     628
     629    if (m_drawingBuffer) {
     630        if (m_framebufferBinding)
     631            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero(m_framebufferBinding.get()));
     632        else
     633            m_drawingBuffer->bind();
     634    }
    593635}
    594636
     
    596638{
    597639    clearIfComposited();
    598     return m_context->paintRenderingResultsToImageData();
     640    if (m_drawingBuffer)
     641        m_drawingBuffer->commit();
     642    RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer.get());
     643
     644    if (m_drawingBuffer) {
     645        if (m_framebufferBinding)
     646            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero(m_framebufferBinding.get()));
     647        else
     648            m_drawingBuffer->bind();
     649    }
     650
     651    return imageData;
    599652}
    600653
     
    628681    // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
    629682    // clear (and this matches what reshape will do).
    630     m_context->reshape(width, height);
     683    if (m_drawingBuffer)
     684        m_drawingBuffer->reset(IntSize(width, height));
     685    else
     686        m_context->reshape(width, height);
    631687}
    632688
    633689int WebGLRenderingContext::drawingBufferWidth() const
    634690{
     691    if (m_drawingBuffer)
     692        return m_drawingBuffer->size().width();
     693
    635694    return m_context->getInternalFramebufferSize().width();
    636695}
     
    638697int WebGLRenderingContext::drawingBufferHeight() const
    639698{
     699    if (m_drawingBuffer)
     700        return m_drawingBuffer->size().height();
     701
    640702    return m_context->getInternalFramebufferSize().height();
    641703}
     
    759821    }
    760822    m_framebufferBinding = buffer;
    761     m_context->bindFramebuffer(target, objectOrZero(buffer));
     823    if (!m_framebufferBinding && m_drawingBuffer) {
     824        // Instead of binding fb 0, bind the drawing buffer.
     825        m_drawingBuffer->bind();
     826    } else
     827        m_context->bindFramebuffer(target, objectOrZero(buffer));
    762828    if (buffer)
    763829        buffer->setHasEverBeenBound();
     
    10981164    }
    10991165    clearIfComposited();
    1100     if (isResourceSafe())
     1166    if (isResourceSafe()) {
     1167        // Commit DrawingBuffer if needed (e.g., for multisampling)
     1168        if (!m_framebufferBinding && m_drawingBuffer)
     1169            m_drawingBuffer->commit();
     1170
    11011171        m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
    1102     else {
     1172
     1173        // Restore DrawingBuffer if needed
     1174        if (!m_framebufferBinding && m_drawingBuffer)
     1175            m_drawingBuffer->bind();
     1176    } else {
     1177        // Commit DrawingBuffer if needed (e.g., for multisampling)
     1178        if (!m_framebufferBinding && m_drawingBuffer)
     1179            m_drawingBuffer->commit();
     1180
    11031181        GC3Dint clippedX, clippedY;
    11041182        GC3Dsizei clippedWidth, clippedHeight;
     
    11121190        } else
    11131191            m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
     1192
     1193        // Restore DrawingBuffer if needed
     1194        if (!m_framebufferBinding && m_drawingBuffer)
     1195            m_drawingBuffer->bind();
    11141196    }
    11151197    // FIXME: if the framebuffer is not complete, none of the below should be executed.
     
    11431225    clearIfComposited();
    11441226    if (isResourceSafe())
     1227        // Commit DrawingBuffer if needed (e.g., for multisampling)
     1228        if (!m_framebufferBinding && m_drawingBuffer)
     1229            m_drawingBuffer->commit();
     1230
    11451231        m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
     1232
     1233        // Restore DrawingBuffer if needed
     1234        if (!m_framebufferBinding && m_drawingBuffer)
     1235            m_drawingBuffer->bind();
    11461236    else {
    11471237        GC3Dint clippedX, clippedY;
     
    11671257            m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, zero.get());
    11681258            if (clippedWidth > 0 && clippedHeight > 0) {
     1259                // Commit DrawingBuffer if needed (e.g., for multisampling)
     1260                if (!m_framebufferBinding && m_drawingBuffer)
     1261                    m_drawingBuffer->commit();
     1262
    11691263                m_context->copyTexSubImage2D(target, level, xoffset + clippedX - x, yoffset + clippedY - y,
    11701264                                             clippedX, clippedY, clippedWidth, clippedHeight);
     1265
     1266               // Restore DrawingBuffer if needed
     1267               if (!m_framebufferBinding && m_drawingBuffer)
     1268                  m_drawingBuffer->bind();
    11711269            }
    1172         } else
     1270        } else {
     1271            // Commit DrawingBuffer if needed (e.g., for multisampling)
     1272            if (!m_framebufferBinding && m_drawingBuffer)
     1273                m_drawingBuffer->commit();
     1274
    11731275            m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
     1276
     1277            // Restore DrawingBuffer if needed
     1278            if (!m_framebufferBinding && m_drawingBuffer)
     1279                m_drawingBuffer->bind();
     1280        }
    11741281    }
    11751282    cleanupAfterGraphicsCall(false);
     
    12881395        m_framebufferBinding = 0;
    12891396        // Have to call bindFramebuffer here to bind back to internal fbo.
    1290         m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
     1397        if (m_drawingBuffer)
     1398            m_drawingBuffer->bind();
     1399        else
     1400            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
    12911401    }
    12921402}
     
    13751485    if (isContextLost() || !validateCapability(cap))
    13761486        return;
    1377     if (cap == GraphicsContext3D::SCISSOR_TEST)
     1487    if (cap == GraphicsContext3D::SCISSOR_TEST) {
    13781488        m_scissorEnabled = false;
     1489        if (m_drawingBuffer)
     1490            m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
     1491    }
    13791492    m_context->disable(cap);
    13801493    cleanupAfterGraphicsCall(false);
     
    17171830    if (isContextLost() || !validateCapability(cap))
    17181831        return;
    1719     if (cap == GraphicsContext3D::SCISSOR_TEST)
     1832    if (cap == GraphicsContext3D::SCISSOR_TEST) {
    17201833        m_scissorEnabled = true;
     1834        if (m_drawingBuffer)
     1835            m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
     1836    }
    17211837    m_context->enable(cap);
    17221838    cleanupAfterGraphicsCall(false);
     
    29253041    clearIfComposited();
    29263042    void* data = pixels->baseAddress();
     3043
     3044    // Commit DrawingBuffer if needed (e.g., for multisampling)
     3045    if (!m_framebufferBinding && m_drawingBuffer)
     3046        m_drawingBuffer->commit();
     3047
    29273048    m_context->readPixels(x, y, width, height, format, type, data);
     3049
     3050    // Restore DrawingBuffer if needed
     3051    if (!m_framebufferBinding && m_drawingBuffer)
     3052        m_drawingBuffer->bind();
     3053
    29283054#if OS(DARWIN)
    29293055    // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,
     
    39764102    maybeRestoreContext(SyntheticLostContext);
    39774103}
     4104
     4105#if USE(ACCELERATED_COMPOSITING)
     4106PlatformLayer* WebGLRenderingContext::platformLayer() const
     4107{
     4108#if PLATFORM(CHROMIUM)
     4109    if (m_drawingBuffer)
     4110        return m_drawingBuffer->platformLayer();
     4111#endif
     4112
     4113    return m_context->platformLayer();
     4114}
     4115#endif
    39784116
    39794117void WebGLRenderingContext::removeObject(WebGLObject* object)
     
    41684306    if (m_framebufferBinding && m_framebufferBinding->object())
    41694307        return m_framebufferBinding->getWidth();
    4170     return m_context->getInternalFramebufferSize().width();
     4308    return m_drawingBuffer ? m_drawingBuffer->size().width() : m_context->getInternalFramebufferSize().width();
    41714309}
    41724310
     
    41754313    if (m_framebufferBinding && m_framebufferBinding->object())
    41764314        return m_framebufferBinding->getHeight();
    4177     return m_context->getInternalFramebufferSize().height();
     4315    return m_drawingBuffer ? m_drawingBuffer->size().height() : m_context->getInternalFramebufferSize().height();
    41784316}
    41794317
     
    48815019    }
    48825020
     5021    // Construct a new drawing buffer with the new GraphicsContext3D.
     5022    if (m_drawingBuffer) {
     5023        m_drawingBuffer->discardResources();
     5024        m_drawingBuffer = DrawingBuffer::create(m_context.get(), m_drawingBuffer->size(), !m_attributes.preserveDrawingBuffer);
     5025    }
     5026
    48835027    m_context = context;
    48845028    m_contextLost = false;
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r99645 r100032  
    2828
    2929#include "CanvasRenderingContext.h"
     30#include "DrawingBuffer.h"
    3031#include "Float32Array.h"
    3132#include "GraphicsContext3D.h"
     
    294295    GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
    295296#if USE(ACCELERATED_COMPOSITING)
    296     virtual PlatformLayer* platformLayer() const { return m_context->platformLayer(); }
     297    virtual PlatformLayer* platformLayer() const;
    297298#endif
    298299
     
    359360
    360361    RefPtr<GraphicsContext3D> m_context;
     362
     363    // Optional structure for rendering to a DrawingBuffer, instead of directly
     364    // to the back-buffer of m_context.
     365    RefPtr<DrawingBuffer> m_drawingBuffer;
    361366
    362367    class WebGLRenderingContextRestoreTimer : public TimerBase {
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp

    r95901 r100032  
    5757
    5858} // anonymous namespace
    59 
    60 
    61 PassRefPtr<DrawingBuffer> GraphicsContext3D::createDrawingBuffer(const IntSize& size)
    62 {
    63     return DrawingBuffer::create(this, size);
    64 }
    6559
    6660bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint unpackAlignment)
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r95901 r100032  
    501501    void makeContextCurrent();
    502502
    503     PassRefPtr<DrawingBuffer> createDrawingBuffer(const IntSize& = IntSize());
    504    
    505503#if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT)
    506504    // With multisampling on, blit from multisampleFBO to regular FBO.
     
    792790    bool layerComposited() const;
    793791
    794     void paintRenderingResultsToCanvas(CanvasRenderingContext*);
    795     PassRefPtr<ImageData> paintRenderingResultsToImageData();
     792    void paintRenderingResultsToCanvas(CanvasRenderingContext*, DrawingBuffer*);
     793    PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
    796794    bool paintCompositedResultsToCanvas(CanvasRenderingContext*);
    797795
  • trunk/Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp

    r95901 r100032  
    3333#include "DrawingBuffer.h"
    3434
     35#include "CanvasRenderingContext.h"
     36#include "Extensions3DChromium.h"
    3537#include "GraphicsContext3D.h"
     38#include "WebGLLayerChromium.h"
    3639
    3740namespace WebCore {
     
    4952    context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
    5053    context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE);
    51     context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0);
    5254
    5355    return offscreenColorTexture;
     
    5759                             const IntSize& size,
    5860                             bool multisampleExtensionSupported,
    59                              bool packedDepthStencilExtensionSupported)
    60     : m_context(context)
     61                             bool packedDepthStencilExtensionSupported,
     62                             bool separateBackingTexture)
     63    : m_separateBackingTexture(separateBackingTexture)
     64    , m_scissorEnabled(false)
     65    , m_context(context)
    6166    , m_size(-1, -1)
    6267    , m_multisampleExtensionSupported(multisampleExtensionSupported)
     
    6469    , m_fbo(0)
    6570    , m_colorBuffer(0)
     71    , m_backingColorBuffer(0)
    6672    , m_depthStencilBuffer(0)
    6773    , m_depthBuffer(0)
     
    7076    , m_multisampleColorBuffer(0)
    7177{
    72     m_fbo = context->createFramebuffer();
    73     context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    74     m_colorBuffer = generateColorTexture(context, size);
     78    initialize(size);
     79}
     80
     81DrawingBuffer::~DrawingBuffer()
     82{
     83    if (m_platformLayer)
     84        m_platformLayer->setDrawingBuffer(0);
     85
     86    if (!m_context)
     87        return;
     88
     89    clear();
     90}
     91
     92void DrawingBuffer::initialize(const IntSize& size)
     93{
     94    m_fbo = m_context->createFramebuffer();
     95
     96    if (m_separateBackingTexture)
     97        m_backingColorBuffer = generateColorTexture(m_context.get(), size);
     98
     99    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     100    m_colorBuffer = generateColorTexture(m_context.get(), size);
     101    m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
    75102    createSecondaryBuffers();
    76103    if (!reset(size)) {
     
    78105        return;
    79106    }
    80 }
    81 
    82 DrawingBuffer::~DrawingBuffer()
    83 {
    84     if (!m_context)
    85         return;
    86 
    87     clear();
    88107}
    89108
     
    94113        return;
    95114
     115    m_context->makeContextCurrent();
    96116    if (multisample())
    97117        commit();
    98     m_context->makeContextCurrent();
     118
     119    if (m_separateBackingTexture) {
     120        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     121        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
     122        unsigned colorFormat = m_context->getContextAttributes().alpha ? GraphicsContext3D::RGBA : GraphicsContext3D::RGB;
     123        m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, colorFormat, 0, 0, size().width(), size().height(), 0);
     124    }
     125
     126    if (multisample())
     127        bind();
     128
    99129    m_context->flush();
    100130}
     
    104134PlatformLayer* DrawingBuffer::platformLayer()
    105135{
    106     return 0;
     136    if (!m_platformLayer) {
     137        m_platformLayer = WebGLLayerChromium::create(0);
     138        m_platformLayer->setDrawingBuffer(this);
     139    }
     140
     141    return m_platformLayer.get();
    107142}
    108143#endif
     
    110145Platform3DObject DrawingBuffer::platformColorBuffer() const
    111146{
    112     return m_colorBuffer;
     147    return m_separateBackingTexture ? m_backingColorBuffer : m_colorBuffer;
    113148}
    114149
     150Platform3DObject DrawingBuffer::framebuffer() const
     151{
     152    return m_fbo;
    115153}
     154
     155#if USE(ACCELERATED_COMPOSITING)
     156void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
     157{
     158    if (m_platformLayer)
     159        m_platformLayer->paintRenderedResultsToCanvas(context->canvas()->buffer());
     160}
     161#endif
     162
     163}
  • trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp

    r98471 r100032  
    3535#include "WebGLLayerChromium.h"
    3636
     37#include "DrawingBuffer.h"
    3738#include "Extensions3DChromium.h"
    3839#include "GraphicsContext3D.h"
     
    4950WebGLLayerChromium::WebGLLayerChromium(CCLayerDelegate* delegate)
    5051    : CanvasLayerChromium(delegate)
    51     , m_context(0)
    5252    , m_textureChanged(true)
    5353    , m_textureUpdated(false)
     
    5757WebGLLayerChromium::~WebGLLayerChromium()
    5858{
    59     if (m_context && layerTreeHost())
    60         layerTreeHost()->stopRateLimiter(m_context);
     59    if (context() && layerTreeHost())
     60        layerTreeHost()->stopRateLimiter(context());
    6161}
    6262
    6363bool WebGLLayerChromium::drawsContent() const
    6464{
    65     return (m_context && m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
     65    return (context() && context()->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
    6666}
    6767
     
    8686    // Update the contents of the texture used by the compositor.
    8787    if (!m_dirtyRect.isEmpty() && m_textureUpdated) {
    88         // prepareTexture copies the contents of the off-screen render target into the texture
    89         // used by the compositor.
    90         //
    91         m_context->prepareTexture();
    92         m_context->markLayerComposited();
     88        // publishToPlatformLayer prepares the contents of the off-screen render target for use by the compositor.
     89        drawingBuffer()->publishToPlatformLayer();
     90        context()->markLayerComposited();
    9391        m_updateRect = FloatRect(FloatPoint(), bounds());
    9492        resetNeedsDisplay();
     
    102100        return false;
    103101
    104     IntSize framebufferSize = m_context->getInternalFramebufferSize();
     102    IntSize framebufferSize = context()->getInternalFramebufferSize();
    105103    ASSERT(layerRendererContext());
    106104
     
    111109
    112110    Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(layerRendererContext()->getExtensions());
    113     extensions->paintFramebufferToCanvas(framebuffer, framebufferSize.width(), framebufferSize.height(), !m_context->getContextAttributes().premultipliedAlpha, imageBuffer);
     111    extensions->paintFramebufferToCanvas(framebuffer, framebufferSize.width(), framebufferSize.height(), !context()->getContextAttributes().premultipliedAlpha, imageBuffer);
    114112    layerRendererContext()->deleteFramebuffer(framebuffer);
    115113    return true;
     
    122120    // call rateLimitOffscreenContextCHROMIUM() to keep the context from getting too far ahead.
    123121    if (layerTreeHost())
    124         layerTreeHost()->startRateLimiter(m_context);
     122        layerTreeHost()->startRateLimiter(context());
    125123}
    126124
    127 void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
     125void WebGLLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer)
    128126{
    129     bool contextChanged = (m_context != context);
     127    bool drawingBufferChanged = (m_drawingBuffer != drawingBuffer);
     128    m_drawingBuffer = drawingBuffer;
    130129
    131     if (layerTreeHost() && contextChanged)
    132         layerTreeHost()->stopRateLimiter(m_context);
     130    if (layerTreeHost() && drawingBufferChanged)
     131        layerTreeHost()->stopRateLimiter(context());
    133132
    134     m_context = const_cast<GraphicsContext3D*>(context);
    135 
    136     if (!m_context)
     133    if (!m_drawingBuffer)
    137134        return;
    138135
    139     unsigned int textureId = m_context->platformTexture();
    140     if (textureId != m_textureId || contextChanged) {
     136    unsigned int textureId = m_drawingBuffer->platformColorBuffer();
     137    if (textureId != m_textureId || drawingBufferChanged) {
    141138        m_textureChanged = true;
    142139        m_textureUpdated = true;
    143140    }
    144141    m_textureId = textureId;
    145     GraphicsContext3D::Attributes attributes = m_context->getContextAttributes();
     142    GraphicsContext3D::Attributes attributes = context()->getContextAttributes();
    146143    m_hasAlpha = attributes.alpha;
    147144    m_premultipliedAlpha = attributes.premultipliedAlpha;
     145}
     146
     147GraphicsContext3D* WebGLLayerChromium::context() const
     148{
     149    if (drawingBuffer())
     150        return drawingBuffer()->graphicsContext3D().get();
     151
     152    return 0;
    148153}
    149154
     
    158163
    159164}
     165
    160166#endif // USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h

    r98471 r100032  
    3636
    3737#include "CanvasLayerChromium.h"
     38#include "DrawingBuffer.h"
    3839
    3940namespace WebCore {
     
    5455    bool paintRenderedResultsToCanvas(ImageBuffer*);
    5556
    56     void setContext(const GraphicsContext3D* context);
    57     GraphicsContext3D* context() { return m_context; }
     57    GraphicsContext3D* context() const;
    5858
     59    void setDrawingBuffer(DrawingBuffer*);
     60    DrawingBuffer* drawingBuffer() const { return m_drawingBuffer; }
    5961private:
    6062    explicit WebGLLayerChromium(CCLayerDelegate*);
     
    6365    GraphicsContext3D* layerRendererContext();
    6466
    65     // GraphicsContext3D::platformLayer has a side-effect of assigning itself
    66     // to the layer. Because of that GraphicsContext3D's destructor will reset
    67     // layer's context to 0.
    68     GraphicsContext3D* m_context;
    6967    bool m_textureChanged;
    7068    bool m_textureUpdated;
     69
     70    // The DrawingBuffer holding the WebGL contents for this layer.
     71    // A reference is not held here, because the DrawingBuffer already holds
     72    // a reference to the WebGLLayerChromium.
     73    DrawingBuffer* m_drawingBuffer;
    7174};
    7275
  • trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp

    r95901 r100032  
    727727}
    728728
    729 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
    730 {
    731     notImplemented();
    732 }
    733 
    734 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
    735 {
     729void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
     730{
     731    // DrawingBuffer support only implemented in Chromium ports.
     732    ASSERT(!drawingBuffer);
     733    notImplemented();
     734}
     735
     736PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
     737{
     738    // DrawingBuffer support only implemented in Chromium ports.
     739    ASSERT(!drawingBuffer);
    736740    notImplemented();
    737741    RefPtr<ImageData> imageData = ImageData::create(IntSize(1, 1));
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

    r95901 r100032  
    3636
    3737#include "Extensions3D.h"
     38#include "GraphicsContext3D.h"
     39#include "ImageData.h"
    3840
    3941namespace WebCore {
     
    4951static int s_currentResourceUsePixels = 0;
    5052
    51 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size)
     53PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, bool separateBackingTexture)
    5254{
    5355    Extensions3D* extensions = context->getExtensions();
     
    6163    if (packedDepthStencilSupported)
    6264        extensions->ensureEnabled("GL_OES_packed_depth_stencil");
    63     RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported));
     65    RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported, separateBackingTexture));
    6466    return (drawingBuffer->m_context) ? drawingBuffer.release() : 0;
    6567}
     
    7779        m_context->deleteTexture(m_colorBuffer);
    7880        m_colorBuffer = 0;
     81    }
     82
     83    if (m_backingColorBuffer) {
     84        m_context->deleteTexture(m_backingColorBuffer);
     85        m_backingColorBuffer = 0;
    7986    }
    8087
     
    167174    unsigned int stencilMask = 0xffffffff;
    168175    unsigned char isScissorEnabled = false;
    169     unsigned long clearMask = GraphicsContext3D::COLOR_BUFFER_BIT;
     176    unsigned clearMask = GraphicsContext3D::COLOR_BUFFER_BIT;
    170177    if (attributes.depth) {
    171178        m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth);
     
    189196    m_context->clearColor(0, 0, 0, 0);
    190197    m_context->clear(clearMask);
     198
     199    // The multisample fbo was just cleared, but we also need to clear the non-multisampled buffer too.
     200    if (m_multisampleFBO) {
     201        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     202        m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
     203        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     204    }
     205
    191206    m_context->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    192207
     
    234249        m_size = newSize;
    235250
    236         unsigned long internalColorFormat, colorFormat, internalRenderbufferFormat;
     251        unsigned internalColorFormat, colorFormat, internalRenderbufferFormat;
    237252        if (attributes.alpha) {
    238253            internalColorFormat = GraphicsContext3D::RGBA;
     
    251266           
    252267            m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
    253             int sampleCount = std::min(8, maxSampleCount);
     268            int sampleCount = std::min(4, maxSampleCount);
    254269
    255270            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     
    270285
    271286        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
    272        
    273287        m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
    274288
    275289        m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
     290
     291        // resize the backing color buffer
     292        if (m_separateBackingTexture) {
     293            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
     294            m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
     295        }
     296
    276297        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
    277298
     
    294315    if (!m_context)
    295316        return;
    296        
     317
    297318    if (width < 0)
    298319        width = m_size.width();
    299320    if (height < 0)
    300321        height = m_size.height();
    301        
     322
    302323    m_context->makeContextCurrent();
    303    
     324
    304325    if (m_multisampleFBO) {
    305326        m_context->bindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_multisampleFBO);
    306327        m_context->bindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_fbo);
    307         m_context->getExtensions()->blitFramebuffer(x, y, width, height, x, y, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::LINEAR);
    308     }
    309    
     328
     329        if (m_scissorEnabled)
     330            m_context->disable(GraphicsContext3D::SCISSOR_TEST);
     331
     332        // Use NEAREST, because there is no scale performed during the blit.
     333        m_context->getExtensions()->blitFramebuffer(x, y, width, height, x, y, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST);
     334
     335        if (m_scissorEnabled)
     336            m_context->enable(GraphicsContext3D::SCISSOR_TEST);
     337    }
     338
    310339    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     340}
     341
     342bool DrawingBuffer::multisample() const
     343{
     344    return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported;
     345}
     346
     347PassRefPtr<ImageData> DrawingBuffer::paintRenderingResultsToImageData()
     348{
     349    return m_context->paintRenderingResultsToImageData(this);
     350}
     351
     352void DrawingBuffer::discardResources()
     353{
     354    m_colorBuffer = 0;
     355    m_backingColorBuffer = 0;
     356    m_multisampleColorBuffer = 0;
     357
     358    m_depthStencilBuffer = 0;
     359    m_depthBuffer = 0;
     360
     361    m_stencilBuffer = 0;
     362
     363    m_multisampleFBO = 0;
     364    m_fbo = 0;
    311365}
    312366
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h

    r95901 r100032  
    3434#include "GraphicsContext3D.h"
    3535#include "GraphicsLayer.h"
     36#include "GraphicsTypes3D.h"
    3637#include "IntSize.h"
    3738
     
    4445
    4546namespace WebCore {
    46 
    47 #if PLATFORM(CHROMIUM) && USE(ACCELERATED_COMPOSITING)
    48 class Canvas2DLayerChromium;
     47class CanvasRenderingContext;
     48class GraphicsContext3D;
     49class ImageData;
     50#if PLATFORM(CHROMIUM)
     51class WebGLLayerChromium;
    4952#endif
    5053
     
    5356class DrawingBuffer : public RefCounted<DrawingBuffer> {
    5457public:
     58    static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&, bool);
    5559    friend class GraphicsContext3D;
    5660
     
    7680    // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound
    7781    void commit(long x = 0, long y = 0, long width = -1, long height = -1);
    78    
    79     bool multisample() const { return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported; }
    80    
     82
     83    // commit should copy the full multisample buffer, and not respect the
     84    // current scissor bounds. Track the state of the scissor test so that it
     85    // can be disabled during calls to commit.
     86    void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnabled; }
     87
     88    bool multisample() const;
     89
    8190    Platform3DObject platformColorBuffer() const;
     91    Platform3DObject framebuffer() const;
     92
     93    PassRefPtr<ImageData> paintRenderingResultsToImageData();
     94
     95    // Immediately releases ownership of all resources. Call upon loss of the
     96    // graphics context to prevent freeing invalid resources.
     97    void discardResources();
    8298
    8399#if USE(ACCELERATED_COMPOSITING)
    84100    PlatformLayer* platformLayer();
    85101    void publishToPlatformLayer();
     102    void paintCompositedResultsToCanvas(CanvasRenderingContext*);
    86103#endif
    87104
     
    89106
    90107private:
    91     static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&);
    92    
    93     DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported, bool packedDepthStencilExtensionSupported);
     108    DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported,
     109                  bool packedDepthStencilExtensionSupported, bool separateBackingTexture);
     110
     111    void initialize(const IntSize&);
     112
     113    bool m_separateBackingTexture;
     114    bool m_scissorEnabled;
    94115
    95116    RefPtr<GraphicsContext3D> m_context;
     
    99120    Platform3DObject m_fbo;
    100121    Platform3DObject m_colorBuffer;
     122    Platform3DObject m_backingColorBuffer;
    101123
    102124    // This is used when we have OES_packed_depth_stencil.
     
    111133    Platform3DObject m_multisampleColorBuffer;
    112134
     135#if PLATFORM(CHROMIUM)
     136    RefPtr<WebGLLayerChromium> m_platformLayer;
     137#endif
     138
    113139#if PLATFORM(MAC)
    114140    RetainPtr<WebGLLayer> m_platformLayer;
  • trunk/Source/WebCore/platform/graphics/gpu/mac/DrawingBufferMac.mm

    r95901 r100032  
    4040                             const IntSize& size,
    4141                             bool multisampleExtensionSupported,
    42                              bool packedDepthStencilExtensionSupported)
    43     : m_context(context)
     42                             bool packedDepthStencilExtensionSupported,
     43                             bool separateBackingTexture)
     44    : m_separateBackingTexture(separateBackingTexture)
     45    , m_scissorEnabled(false)
     46    , m_context(context)
    4447    , m_size(-1, -1)
    4548    , m_multisampleExtensionSupported(multisampleExtensionSupported)
     
    5356    , m_multisampleColorBuffer(0)
    5457{
     58    // Support for a separate backing texture has only been enabled for
     59    // the chromium port.
     60    ASSERT(!m_separateBackingTexture);
    5561    ASSERT(m_fbo);
    5662    if (!m_fbo) {
  • trunk/Source/WebCore/platform/graphics/gpu/qt/DrawingBufferQt.cpp

    r95901 r100032  
    3535                             const IntSize& size,
    3636                             bool multisampleExtensionSupported,
    37                              bool packedDepthStencilExtensionSupported)
    38     : m_context(context)
     37                             bool packedDepthStencilExtensionSupported,
     38                             bool separateBackingTexture)
     39    : m_separateBackingTexture(separateBackingTexture)
     40    , m_scissorEnabled(false)
     41    , m_context(context)
    3942    , m_size(-1, -1)
    4043    , m_multisampleExtensionSupported(multisampleExtensionSupported)
     
    4851    , m_multisampleColorBuffer(0)
    4952{
     53    // Support for a separate backing texture has only been enabled for
     54    // the chromium port.
     55    ASSERT(!m_separateBackingTexture);
    5056    ASSERT(m_fbo);
    5157    if (!m_fbo) {
     
    8490}
    8591
     92#if USE(ACCELERATED_COMPOSITING)
     93void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
     94{
     95}
     96#endif
     97
    8698}
    8799
  • trunk/Source/WebCore/platform/graphics/gtk/DrawingBufferGtk.cpp

    r95901 r100032  
    7777}
    7878
     79#if USE(ACCELERATED_COMPOSITING)
     80void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
     81{
     82}
     83#endif
     84
    7985}
    8086
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r95901 r100032  
    129129
    130130#if !PLATFORM(QT)
    131 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
     131void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*)
    132132{
    133133    HTMLCanvasElement* canvas = context->canvas();
     
    163163}
    164164
    165 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
     165PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer*)
    166166{
    167167    // Reading premultiplied alpha would involve unpremultiplying, which is
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r95901 r100032  
    421421}
    422422
    423 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
     423void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*)
    424424{
    425425    m_private->m_glWidget->makeCurrent();
     
    431431
    432432#if defined(QT_OPENGL_ES_2)
    433 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
     433PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer*)
    434434{
    435435    // FIXME: This needs to be implemented for proper non-premultiplied-alpha
  • trunk/Source/WebKit/chromium/ChangeLog

    r100011 r100032  
     12011-11-11  Jeff Timanus  <twiz@chromium.org>
     2
     3        [chromium] Patch that implementing the changes required to allow WebGL
     4        to share its backing store directly with the compositor.
     5        WebGL rendering contexts create and render to FBOs managed by a
     6        DrawingBuffer instance. All PlatformLayer lifetime management is
     7        performed by the DrawingBuffer.
     8        Changes are only relevant to Chromium ports. Functionality is
     9        unchanged for other ports.
     10        https://bugs.webkit.org/show_bug.cgi?id=53201
     11
     12        Reviewed by Stephen White.
     13
     14        * src/GraphicsContext3DChromium.cpp: GraphicsContext3DPrivate no longer caches
     15        the WebGLLayerChromium instance.  Instead, it is accessed via DrawingBuffer instances
     16        passed as arguments to the necessary routines.
     17        (WebCore::GraphicsContext3DPrivate::paintRenderingResultsToCanvas):
     18        (WebCore::GraphicsContext3DPrivate::paintCompositedResultsToCanvas):
     19        (WebCore::GraphicsContext3DPrivate::paintRenderingResultsToImageData):
     20        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     21        (WebCore::GraphicsContext3D::platformLayer):
     22        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
     23        (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
     24        * src/GraphicsContext3DPrivate.h:
     25
    1262011-11-11  Sheriff Bot  <webkit.review.bot@gmail.com>
    227
  • trunk/Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp

    r99648 r100032  
    3636
    3737#include "CachedImage.h"
    38 #include "WebGLLayerChromium.h"
    3938#include "CanvasRenderingContext.h"
    4039#include "Chrome.h"
    4140#include "ChromeClientImpl.h"
     41#include "DrawingBuffer.h"
    4242#include "Extensions3DChromium.h"
    4343#include "GraphicsContext3DPrivate.h"
     
    164164}
    165165
     166void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsContext3D* graphicsContext3D,
     167                          Platform3DObject* frameBufferId, int* width, int* height)
     168{
     169    if (drawingBuffer) {
     170        *frameBufferId = drawingBuffer->framebuffer();
     171        *width = drawingBuffer->size().width();
     172        *height = drawingBuffer->size().height();
     173    } else {
     174        *frameBufferId = 0;
     175        *width = graphicsContext3D->width();
     176        *height = graphicsContext3D->height();
     177    }
     178}
     179
    166180} // anonymous namespace
    167181
     
    212226    m_impl->prepareTexture();
    213227}
    214 
    215 #if USE(ACCELERATED_COMPOSITING)
    216 WebGLLayerChromium* GraphicsContext3DPrivate::platformLayer()
    217 {
    218 #if USE(ACCELERATED_COMPOSITING)
    219     if (!m_compositingLayer)
    220         m_compositingLayer = WebGLLayerChromium::create(0);
    221 #endif
    222     return m_compositingLayer.get();
    223 }
    224 #endif
    225228
    226229void GraphicsContext3DPrivate::markContextChanged()
     
    306309}
    307310
    308 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
     311void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
    309312{
    310313    ImageBuffer* imageBuffer = context->canvas()->buffer();
    311     paintFramebufferToCanvas(0, m_impl->width(), m_impl->height(), !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer);
     314    Platform3DObject framebufferId;
     315    int width, height;
     316    getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
     317    paintFramebufferToCanvas(framebufferId, width, height, !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer);
    312318}
    313319
    314320bool GraphicsContext3DPrivate::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
    315321{
    316 #if USE(ACCELERATED_COMPOSITING)
    317     if (platformLayer())
    318         return platformLayer()->paintRenderedResultsToCanvas(context->canvas()->buffer());
    319 #endif
    320322    return false;
    321323}
    322324
    323 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData()
     325PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
    324326{
    325327    if (m_impl->getContextAttributes().premultipliedAlpha)
    326328        return 0;
    327    
    328     RefPtr<ImageData> imageData = ImageData::create(IntSize(m_impl->width(), m_impl->height()));
     329
     330    Platform3DObject framebufferId;
     331    int width, height;
     332    getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height);
     333
     334    RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
    329335    unsigned char* pixels = imageData->data()->data()->data();
    330     size_t bufferSize = 4 * m_impl->width() * m_impl->height();
    331 
    332     m_impl->readBackFramebuffer(pixels, bufferSize, 0, m_impl->width(), m_impl->height());
     336    size_t bufferSize = 4 * width * height;
     337
     338    m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height);
    333339
    334340    for (size_t i = 0; i < bufferSize; i += 4)
     
    10131019GraphicsContext3D::~GraphicsContext3D()
    10141020{
    1015     WebGLLayerChromium* canvasLayer = m_private->platformLayer();
    1016     if (canvasLayer)
    1017         canvasLayer->setContext(0);
    10181021    m_private->setContextLostCallback(nullptr);
    10191022    m_private->setSwapBuffersCompleteCallbackCHROMIUM(nullptr);
     
    10601063PlatformLayer* GraphicsContext3D::platformLayer() const
    10611064{
    1062     WebGLLayerChromium* canvasLayer = m_private->platformLayer();
    1063     canvasLayer->setContext(this);
    1064     return canvasLayer;
     1065    return 0;
    10651066}
    10661067#endif
     
    12181219}
    12191220
    1220 DELEGATE_TO_INTERNAL_1(paintRenderingResultsToCanvas, CanvasRenderingContext*)
    1221 DELEGATE_TO_INTERNAL_R(paintRenderingResultsToImageData, PassRefPtr<ImageData>)
     1221void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer)
     1222{
     1223    return m_private->paintRenderingResultsToCanvas(context, drawingBuffer);
     1224}
     1225
     1226PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer)
     1227{
     1228    return m_private->paintRenderingResultsToImageData(drawingBuffer);
     1229}
     1230
    12221231DELEGATE_TO_INTERNAL_1R(paintCompositedResultsToCanvas, CanvasRenderingContext*, bool)
    12231232
  • trunk/Source/WebKit/chromium/src/GraphicsContext3DPrivate.h

    r98185 r100032  
    4747namespace WebCore {
    4848
     49class DrawingBuffer;
    4950class Extensions3DChromium;
    50 #if USE(ACCELERATED_COMPOSITING)
    51 class WebGLLayerChromium;
    52 #endif
    5351class GraphicsContextLostCallbackAdapter;
    5452class GraphicsContext3DSwapBuffersCompleteCallbackAdapter;
     
    9694    void markLayerComposited();
    9795
    98     void paintRenderingResultsToCanvas(CanvasRenderingContext*);
     96    void paintRenderingResultsToCanvas(CanvasRenderingContext*, DrawingBuffer*);
    9997    void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*);
    100     PassRefPtr<ImageData> paintRenderingResultsToImageData();
     98    PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
    10199    bool paintsIntoCanvasBuffer() const;
    102100    bool paintCompositedResultsToCanvas(CanvasRenderingContext*);
     
    104102    void prepareTexture();
    105103
    106 #if USE(ACCELERATED_COMPOSITING)
    107     WebGLLayerChromium* platformLayer();
    108 #endif
    109104    bool isGLES2Compliant() const;
    110105
     
    331326    ResourceSafety m_resourceSafety;
    332327
    333 #if USE(ACCELERATED_COMPOSITING)
    334     RefPtr<WebGLLayerChromium> m_compositingLayer;
    335 #endif
    336328#if USE(SKIA)
    337329    // If the width and height of the Canvas's backing store don't
Note: See TracChangeset for help on using the changeset viewer.