Changeset 103264 in webkit


Ignore:
Timestamp:
Dec 19, 2011, 1:45:43 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Accelerated canvas broken in threaded compositing mode
https://bugs.webkit.org/show_bug.cgi?id=72738

We were flushing the Skia canvas in updateCompositorResources, which
is illegal as it runs on the wrong thread. Moved to paintContentsIfDirty
instead. For correct rendering on the compositor thread, we make a copy
of the canvas texture in updateCompositorResources.

Removed m_textureId and pushPropertiesTo from CanvasLayerChromium, as
it's no longer common between Canvas2DLayerChromium and
WebGLLayerChromium. WebGL changes do not change functionality.

Patch by Iain Merrick <husky@google.com> on 2011-12-19
Reviewed by James Robinson.

Source/WebCore:

  • platform/graphics/chromium/Canvas2DLayerChromium.cpp:

(WebCore::Canvas2DLayerChromium::create):
(WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
(WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
(WebCore::Canvas2DLayerChromium::setTextureId):
(WebCore::Canvas2DLayerChromium::contentChanged):
(WebCore::Canvas2DLayerChromium::drawsContent):
(WebCore::Canvas2DLayerChromium::paintContentsIfDirty):
(WebCore::Canvas2DLayerChromium::setLayerTreeHost):
(WebCore::Canvas2DLayerChromium::setTextureManager):
(WebCore::Canvas2DLayerChromium::updateCompositorResources):
(WebCore::Canvas2DLayerChromium::pushPropertiesTo):
(WebCore::Canvas2DLayerChromium::unreserveContentsTexture):
(WebCore::Canvas2DLayerChromium::cleanupResources):

  • platform/graphics/chromium/Canvas2DLayerChromium.h:
  • platform/graphics/chromium/CanvasLayerChromium.cpp:

(WebCore::CanvasLayerChromium::CanvasLayerChromium):

  • platform/graphics/chromium/CanvasLayerChromium.h:
  • platform/graphics/chromium/WebGLLayerChromium.cpp:

(WebCore::WebGLLayerChromium::WebGLLayerChromium):
(WebCore::WebGLLayerChromium::pushPropertiesTo):

  • platform/graphics/chromium/WebGLLayerChromium.h:

(WebCore::WebGLLayerChromium::textureId):
(WebCore::WebGLLayerChromium::setTextureId):

  • platform/graphics/chromium/cc/CCCanvasLayerImpl.h:

(WebCore::CCCanvasLayerImpl::textureId):

  • platform/graphics/skia/ImageBufferSkia.cpp:

(WebCore::createAcceleratedCanvas):

Source/WebKit/chromium:

  • WebKit.gypi:
  • tests/Canvas2DLayerChromiumTest.cpp: Added.

(WebCore::Canvas2DLayerChromiumTest::setTextureManager):

Location:
trunk/Source
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r103262 r103264  
     12011-12-19  Iain Merrick  <husky@google.com>
     2
     3        [chromium] Accelerated canvas broken in threaded compositing mode
     4        https://bugs.webkit.org/show_bug.cgi?id=72738
     5
     6        We were flushing the Skia canvas in updateCompositorResources, which
     7        is illegal as it runs on the wrong thread. Moved to paintContentsIfDirty
     8        instead. For correct rendering on the compositor thread, we make a copy
     9        of the canvas texture in updateCompositorResources.
     10
     11        Removed m_textureId and pushPropertiesTo from CanvasLayerChromium, as
     12        it's no longer common between Canvas2DLayerChromium and
     13        WebGLLayerChromium. WebGL changes do not change functionality.
     14
     15        Reviewed by James Robinson.
     16
     17        * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
     18        (WebCore::Canvas2DLayerChromium::create):
     19        (WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
     20        (WebCore::Canvas2DLayerChromium::~Canvas2DLayerChromium):
     21        (WebCore::Canvas2DLayerChromium::setTextureId):
     22        (WebCore::Canvas2DLayerChromium::contentChanged):
     23        (WebCore::Canvas2DLayerChromium::drawsContent):
     24        (WebCore::Canvas2DLayerChromium::paintContentsIfDirty):
     25        (WebCore::Canvas2DLayerChromium::setLayerTreeHost):
     26        (WebCore::Canvas2DLayerChromium::setTextureManager):
     27        (WebCore::Canvas2DLayerChromium::updateCompositorResources):
     28        (WebCore::Canvas2DLayerChromium::pushPropertiesTo):
     29        (WebCore::Canvas2DLayerChromium::unreserveContentsTexture):
     30        (WebCore::Canvas2DLayerChromium::cleanupResources):
     31        * platform/graphics/chromium/Canvas2DLayerChromium.h:
     32        * platform/graphics/chromium/CanvasLayerChromium.cpp:
     33        (WebCore::CanvasLayerChromium::CanvasLayerChromium):
     34        * platform/graphics/chromium/CanvasLayerChromium.h:
     35        * platform/graphics/chromium/WebGLLayerChromium.cpp:
     36        (WebCore::WebGLLayerChromium::WebGLLayerChromium):
     37        (WebCore::WebGLLayerChromium::pushPropertiesTo):
     38        * platform/graphics/chromium/WebGLLayerChromium.h:
     39        (WebCore::WebGLLayerChromium::textureId):
     40        (WebCore::WebGLLayerChromium::setTextureId):
     41        * platform/graphics/chromium/cc/CCCanvasLayerImpl.h:
     42        (WebCore::CCCanvasLayerImpl::textureId):
     43        * platform/graphics/skia/ImageBufferSkia.cpp:
     44        (WebCore::createAcceleratedCanvas):
     45
    1462011-12-19  Mike Reed  <reed@google.com>
    247
  • trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp

    r101623 r103264  
    3535#include "Canvas2DLayerChromium.h"
    3636
     37#include "cc/CCCanvasLayerImpl.h"
     38#include "cc/CCLayerTreeHost.h"
     39#include "cc/CCTextureUpdater.h"
    3740#include "Extensions3DChromium.h"
    3841#include "GraphicsContext3D.h"
    39 #include "cc/CCLayerTreeHost.h"
     42#include "LayerRendererChromium.h" // For the GLC() macro
    4043
    4144#if USE(SKIA)
     
    4548namespace WebCore {
    4649
    47 PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(GraphicsContext3D* context)
     50PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(GraphicsContext3D* context, const IntSize& size)
    4851{
    49     return adoptRef(new Canvas2DLayerChromium(context));
     52    return adoptRef(new Canvas2DLayerChromium(context, size));
    5053}
    5154
    52 Canvas2DLayerChromium::Canvas2DLayerChromium(GraphicsContext3D* context)
     55Canvas2DLayerChromium::Canvas2DLayerChromium(GraphicsContext3D* context, const IntSize& size)
    5356    : CanvasLayerChromium(0)
    5457    , m_context(context)
     58    , m_size(size)
     59    , m_backTextureId(0)
     60    , m_fbo(0)
    5561{
     62    GLC(m_context, m_fbo = m_context->createFramebuffer());
    5663}
    5764
    5865Canvas2DLayerChromium::~Canvas2DLayerChromium()
    5966{
     67    GLC(m_context, m_context->deleteFramebuffer(m_fbo));
    6068}
    6169
    62 bool Canvas2DLayerChromium::drawsContent() const
     70void Canvas2DLayerChromium::setTextureId(unsigned textureId)
    6371{
    64     return m_textureId && (m_context
    65             && (m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR));
    66 }
    67 
    68 void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&)
    69 {
    70     if (!m_needsDisplay || !drawsContent())
    71         return;
    72 
    73     if (m_context) {
    74 #if USE(SKIA)
    75         GrContext* grContext = m_context->grContext();
    76         if (grContext) {
    77             m_context->makeContextCurrent();
    78             grContext->flush();
    79         }
    80 #endif
    81         m_context->flush();
    82     }
    83 
    84     m_updateRect = FloatRect(FloatPoint(), bounds());
    85     m_needsDisplay = false;
     72    m_backTextureId = textureId;
     73    setNeedsCommit();
    8674}
    8775
     
    9078    if (layerTreeHost())
    9179        layerTreeHost()->startRateLimiter(m_context);
     80
     81    setNeedsDisplay();
     82}
     83
     84bool Canvas2DLayerChromium::drawsContent() const
     85{
     86    return m_backTextureId && !m_size.isEmpty()
     87        && m_context && (m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
     88}
     89
     90void Canvas2DLayerChromium::paintContentsIfDirty()
     91{
     92    if (!drawsContent())
     93        return;
     94
     95    m_frontTexture->reserve(m_size, GraphicsContext3D::RGBA);
     96
     97    if (!needsDisplay())
     98        return;
     99
     100    m_needsDisplay = false;
     101
     102    bool success = m_context->makeContextCurrent();
     103    ASSERT_UNUSED(success, success);
     104
     105#if USE(SKIA)
     106    GrContext* grContext = m_context->grContext();
     107    if (grContext)
     108        grContext->flush();
     109#endif
     110
     111    m_context->flush();
     112}
     113
     114void Canvas2DLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
     115{
     116    if (layerTreeHost() != host)
     117        setTextureManager(host ? host->contentsTextureManager() : 0);
     118
     119    CanvasLayerChromium::setLayerTreeHost(host);
     120}
     121
     122void Canvas2DLayerChromium::setTextureManager(TextureManager* textureManager)
     123{
     124    if (textureManager)
     125        m_frontTexture = ManagedTexture::create(textureManager);
     126    else
     127        m_frontTexture.clear();
     128}
     129
     130void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D* context, CCTextureUpdater& updater)
     131{
     132    if (!m_backTextureId || !m_frontTexture->isValid(m_size, GraphicsContext3D::RGBA))
     133        return;
     134
     135    m_frontTexture->bindTexture(context, updater.allocator());
     136
     137    GLC(context, context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo));
     138    GLC(context, context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_backTextureId, 0));
     139    GLC(context, context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, 0, 0, m_size.width(), m_size.height(), 0));
     140    GLC(context, context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0));
     141    GLC(context, context->flush());
     142}
     143
     144void Canvas2DLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
     145{
     146    CanvasLayerChromium::pushPropertiesTo(layer);
     147
     148    CCCanvasLayerImpl* canvasLayer = static_cast<CCCanvasLayerImpl*>(layer);
     149    canvasLayer->setTextureId(m_frontTexture->textureId());
     150}
     151
     152void Canvas2DLayerChromium::unreserveContentsTexture()
     153{
     154    m_frontTexture->unreserve();
     155}
     156
     157void Canvas2DLayerChromium::cleanupResources()
     158{
     159    m_frontTexture.clear();
    92160}
    93161
    94162}
     163
    95164#endif // USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h

    r98471 r103264  
    3636
    3737#include "CanvasLayerChromium.h"
     38#include "ManagedTexture.h"
    3839
    3940namespace WebCore {
     
    4445class Canvas2DLayerChromium : public CanvasLayerChromium {
    4546public:
    46     static PassRefPtr<Canvas2DLayerChromium> create(GraphicsContext3D*);
     47    static PassRefPtr<Canvas2DLayerChromium> create(GraphicsContext3D*, const IntSize&);
    4748    virtual ~Canvas2DLayerChromium();
    48     virtual bool drawsContent() const;
    49     virtual void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
     49
     50    void setTextureId(unsigned);
    5051
    5152    virtual void contentChanged();
    5253
     54    virtual bool drawsContent() const;
     55    virtual void paintContentsIfDirty();
     56
     57    virtual void setLayerTreeHost(CCLayerTreeHost*);
     58    virtual void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
     59    virtual void pushPropertiesTo(CCLayerImpl*);
     60    virtual void unreserveContentsTexture();
     61    virtual void cleanupResources();
     62
    5363private:
    54     explicit Canvas2DLayerChromium(GraphicsContext3D*);
     64    Canvas2DLayerChromium(GraphicsContext3D*, const IntSize&);
     65
     66    // Visible for testing so we can bypass setLayerTreeHost.
     67    friend class Canvas2DLayerChromiumTest;
     68    void setTextureManager(TextureManager*);
     69
    5570    GraphicsContext3D* m_context;
     71    IntSize m_size;
     72    unsigned m_backTextureId;
     73    Platform3DObject m_fbo;
     74    OwnPtr<ManagedTexture> m_frontTexture;
    5675};
    5776
  • trunk/Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp

    r95901 r103264  
    4343CanvasLayerChromium::CanvasLayerChromium(CCLayerDelegate* delegate)
    4444    : LayerChromium(delegate)
    45     , m_hasAlpha(true)
    46     , m_premultipliedAlpha(true)
    47     , m_textureId(0)
    48 {
    49 }
    50 
    51 CanvasLayerChromium::~CanvasLayerChromium()
    5245{
    5346}
     
    5851}
    5952
    60 void CanvasLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
    61 {
    62     LayerChromium::pushPropertiesTo(layer);
    63 
    64     CCCanvasLayerImpl* canvasLayer = static_cast<CCCanvasLayerImpl*>(layer);
    65     canvasLayer->setTextureId(textureId());
    66     canvasLayer->setHasAlpha(m_hasAlpha);
    67     canvasLayer->setPremultipliedAlpha(m_premultipliedAlpha);
    68 }
    69 
    7053}
    7154#endif // USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.h

    r95901 r103264  
    4242class CanvasLayerChromium : public LayerChromium {
    4343public:
    44     virtual ~CanvasLayerChromium();
    45 
    4644    virtual PassRefPtr<CCLayerImpl> createCCLayerImpl();
    47 
    48     virtual void pushPropertiesTo(CCLayerImpl*);
    49     unsigned textureId() const { return m_textureId; }
    50     void setTextureId(unsigned textureId) { m_textureId = textureId; }
    5145
    5246protected:
    5347    explicit CanvasLayerChromium(CCLayerDelegate*);
    54 
    55     bool m_hasAlpha;
    56     bool m_premultipliedAlpha;
    57     unsigned m_textureId;
    5848};
    5949
  • trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp

    r101623 r103264  
    5050WebGLLayerChromium::WebGLLayerChromium(CCLayerDelegate* delegate)
    5151    : CanvasLayerChromium(delegate)
     52    , m_hasAlpha(true)
     53    , m_premultipliedAlpha(true)
     54    , m_textureId(0)
    5255    , m_textureChanged(true)
    5356    , m_textureUpdated(false)
     
    9497        m_textureUpdated = false;
    9598    }
     99}
     100
     101void WebGLLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
     102{
     103    CanvasLayerChromium::pushPropertiesTo(layer);
     104
     105    CCCanvasLayerImpl* canvasLayer = static_cast<CCCanvasLayerImpl*>(layer);
     106    canvasLayer->setTextureId(m_textureId);
     107    canvasLayer->setHasAlpha(m_hasAlpha);
     108    canvasLayer->setPremultipliedAlpha(m_premultipliedAlpha);
    96109}
    97110
  • trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h

    r100032 r103264  
    5050    virtual ~WebGLLayerChromium();
    5151
     52    unsigned textureId() const { return m_textureId; }
     53    void setTextureId(unsigned textureId) { m_textureId = textureId; }
     54
    5255    virtual bool drawsContent() const;
    5356    virtual void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
     57    virtual void pushPropertiesTo(CCLayerImpl*);
    5458    virtual void contentChanged();
    5559    bool paintRenderedResultsToCanvas(ImageBuffer*);
     
    6569    GraphicsContext3D* layerRendererContext();
    6670
     71    bool m_hasAlpha;
     72    bool m_premultipliedAlpha;
     73    unsigned m_textureId;
    6774    bool m_textureChanged;
    6875    bool m_textureUpdated;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h

    r95901 r103264  
    4747    virtual void dumpLayerProperties(TextStream&, int indent) const;
    4848
     49    unsigned textureId() const { return m_textureId; }
    4950    void setTextureId(unsigned id) { m_textureId = id; }
    5051    void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; }
  • trunk/Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

    r102782 r103264  
    8888    data->m_platformContext.setGraphicsContext3D(context3D);
    8989#if USE(ACCELERATED_COMPOSITING)
    90     data->m_platformLayer = Canvas2DLayerChromium::create(context3D);
     90    data->m_platformLayer = Canvas2DLayerChromium::create(context3D, size);
    9191    data->m_platformLayer->setTextureId(texture.get()->getTextureHandle());
    9292#endif
  • trunk/Source/WebKit/chromium/ChangeLog

    r103263 r103264  
     12011-12-19  Iain Merrick  <husky@google.com>
     2
     3        [chromium] Accelerated canvas broken in threaded compositing mode
     4        https://bugs.webkit.org/show_bug.cgi?id=72738
     5
     6        We were flushing the Skia canvas in updateCompositorResources, which
     7        is illegal as it runs on the wrong thread. Moved to paintContentsIfDirty
     8        instead. For correct rendering on the compositor thread, we make a copy
     9        of the canvas texture in updateCompositorResources.
     10
     11        Removed m_textureId and pushPropertiesTo from CanvasLayerChromium, as
     12        it's no longer common between Canvas2DLayerChromium and
     13        WebGLLayerChromium. WebGL changes do not change functionality.
     14
     15        Reviewed by James Robinson.
     16
     17        * WebKit.gypi:
     18        * tests/Canvas2DLayerChromiumTest.cpp: Added.
     19        (WebCore::Canvas2DLayerChromiumTest::setTextureManager):
     20
    1212011-12-19  Ryosuke Niwa  <rniwa@webkit.org>
    222
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r103150 r103264  
    5555            'tests/ArenaTestHelpers.h',
    5656            'tests/AssociatedURLLoaderTest.cpp',
     57            'tests/Canvas2DLayerChromiumTest.cpp',
    5758            'tests/CCDamageTrackerTest.cpp',
    5859            'tests/CCDelayBasedTimeSourceTest.cpp',
Note: See TracChangeset for help on using the changeset viewer.