Title: [113618] trunk/Source
Revision
113618
Author
[email protected]
Date
2012-04-09 14:24:59 -0700 (Mon, 09 Apr 2012)

Log Message

[chromium] Texture copies should happen after incremental updates to preserve commit atomicity
https://bugs.webkit.org/show_bug.cgi?id=83392

Reviewed by Adrienne Walker.

Source/WebCore:

This enqueues texture copy operations in the CCTextureUpdater's list instead of evaluating them immediately so
if the update is spread over multiple frames we can properly defer the texture copy until the end. Otherwise,
the texture copy for WebGL / Canvas 2D content happens before the commit completes and the compositor might pick
up a frame for the canvas that's "ahead" of the content around it.

* platform/graphics/chromium/Canvas2DLayerChromium.cpp:
(WebCore::Canvas2DLayerChromium::updateCompositorResources):
* platform/graphics/chromium/TiledLayerChromium.cpp:
(WebCore::TiledLayerChromium::updateCompositorResources):
* platform/graphics/chromium/WebGLLayerChromium.cpp:
(WebCore::WebGLLayerChromium::updateCompositorResources):
* platform/graphics/chromium/cc/CCTextureUpdater.cpp:
(WebCore::CCTextureUpdater::appendUpdate):
(WebCore::CCTextureUpdater::appendPartialUpdate):
(WebCore):
(WebCore::CCTextureUpdater::appendCopy):
(WebCore::CCTextureUpdater::hasMoreUpdates):
(WebCore::CCTextureUpdater::update):
(WebCore::CCTextureUpdater::clear):
* platform/graphics/chromium/cc/CCTextureUpdater.h:
(CCTextureUpdater):
(UpdateEntry):
(CopyEntry):

Source/WebKit/chromium:

* tests/Canvas2DLayerChromiumTest.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (113617 => 113618)


--- trunk/Source/WebCore/ChangeLog	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/ChangeLog	2012-04-09 21:24:59 UTC (rev 113618)
@@ -1,3 +1,34 @@
+2012-04-06  James Robinson  <[email protected]>
+
+        [chromium] Texture copies should happen after incremental updates to preserve commit atomicity
+        https://bugs.webkit.org/show_bug.cgi?id=83392
+
+        Reviewed by Adrienne Walker.
+
+        This enqueues texture copy operations in the CCTextureUpdater's list instead of evaluating them immediately so
+        if the update is spread over multiple frames we can properly defer the texture copy until the end. Otherwise,
+        the texture copy for WebGL / Canvas 2D content happens before the commit completes and the compositor might pick
+        up a frame for the canvas that's "ahead" of the content around it.
+
+        * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
+        (WebCore::Canvas2DLayerChromium::updateCompositorResources):
+        * platform/graphics/chromium/TiledLayerChromium.cpp:
+        (WebCore::TiledLayerChromium::updateCompositorResources):
+        * platform/graphics/chromium/WebGLLayerChromium.cpp:
+        (WebCore::WebGLLayerChromium::updateCompositorResources):
+        * platform/graphics/chromium/cc/CCTextureUpdater.cpp:
+        (WebCore::CCTextureUpdater::appendUpdate):
+        (WebCore::CCTextureUpdater::appendPartialUpdate):
+        (WebCore):
+        (WebCore::CCTextureUpdater::appendCopy):
+        (WebCore::CCTextureUpdater::hasMoreUpdates):
+        (WebCore::CCTextureUpdater::update):
+        (WebCore::CCTextureUpdater::clear):
+        * platform/graphics/chromium/cc/CCTextureUpdater.h:
+        (CCTextureUpdater):
+        (UpdateEntry):
+        (CopyEntry):
+
 2012-04-09  Sadrul Habib Chowdhury  <[email protected]>
 
         [chromium] Add Battery Status API support.

Modified: trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp (113617 => 113618)


--- trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp	2012-04-09 21:24:59 UTC (rev 113618)
@@ -135,8 +135,7 @@
         return;
 
     m_frontTexture->allocate(updater.allocator());
-    updater.copier()->copyTexture(context, m_backTextureId, m_frontTexture->textureId(), m_size);
-    GLC(context, context->flush());
+    updater.appendCopy(m_backTextureId, m_frontTexture->textureId(), m_size);
 }
 
 void Canvas2DLayerChromium::pushPropertiesTo(CCLayerImpl* layer)

Modified: trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp (113617 => 113618)


--- trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp	2012-04-09 21:24:59 UTC (rev 113618)
@@ -232,9 +232,9 @@
                 CRASH();
 
             if (tile->m_partialUpdate)
-                updater.appendPartial(tile->texture(), sourceRect, destRect);
+                updater.appendPartialUpdate(tile->texture(), sourceRect, destRect);
             else
-                updater.append(tile->texture(), sourceRect, destRect);
+                updater.appendUpdate(tile->texture(), sourceRect, destRect);
         }
     }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp (113617 => 113618)


--- trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp	2012-04-09 21:24:59 UTC (rev 113618)
@@ -84,14 +84,14 @@
     m_contextLost = context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
 }
 
-void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D* context, CCTextureUpdater& updater)
+void WebGLLayerChromium::updateCompositorResources(GraphicsContext3D*, CCTextureUpdater& updater)
 {
     if (!m_drawingBuffer)
         return;
 
     m_textureId = m_drawingBuffer->frontColorBuffer();
     if (m_drawingBuffer->requiresCopyFromBackToFrontBuffer())
-        updater.copier()->copyTexture(context, m_drawingBuffer->colorBuffer(), m_textureId, bounds());
+        updater.appendCopy(m_drawingBuffer->colorBuffer(), m_textureId, bounds());
 }
 
 void WebGLLayerChromium::pushPropertiesTo(CCLayerImpl* layer)

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.cpp (113617 => 113618)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.cpp	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.cpp	2012-04-09 21:24:59 UTC (rev 113618)
@@ -32,6 +32,7 @@
 #include "GraphicsContext3D.h"
 #include "LayerTextureUpdater.h"
 #include "ManagedTexture.h"
+#include "TextureCopier.h"
 
 using namespace std;
 
@@ -49,30 +50,39 @@
 {
 }
 
-void CCTextureUpdater::append(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>& entries)
+void CCTextureUpdater::appendUpdate(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>& entries)
 {
     ASSERT(texture);
 
     UpdateEntry entry;
-    entry.m_texture = texture;
-    entry.m_sourceRect = sourceRect;
-    entry.m_destRect = destRect;
+    entry.texture = texture;
+    entry.sourceRect = sourceRect;
+    entry.destRect = destRect;
     entries.append(entry);
 }
 
-void CCTextureUpdater::append(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
+void CCTextureUpdater::appendUpdate(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
 {
-    append(texture, sourceRect, destRect, m_entries);
+    appendUpdate(texture, sourceRect, destRect, m_entries);
 }
 
-void CCTextureUpdater::appendPartial(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
+void CCTextureUpdater::appendPartialUpdate(LayerTextureUpdater::Texture* texture, const IntRect& sourceRect, const IntRect& destRect)
 {
-    append(texture, sourceRect, destRect, m_partialEntries);
+    appendUpdate(texture, sourceRect, destRect, m_partialEntries);
 }
 
+void CCTextureUpdater::appendCopy(unsigned sourceTexture, unsigned destTexture, const IntSize& size)
+{
+    CopyEntry copy;
+    copy.sourceTexture = sourceTexture;
+    copy.destTexture = destTexture;
+    copy.size = size;
+    m_copyEntries.append(copy);
+}
+
 bool CCTextureUpdater::hasMoreUpdates() const
 {
-    return m_entries.size() || m_partialEntries.size();
+    return m_entries.size() || m_partialEntries.size() || m_copyEntries.size();
 }
 
 bool CCTextureUpdater::update(GraphicsContext3D* context, size_t count)
@@ -81,7 +91,7 @@
     size_t maxIndex = min(m_entryIndex + count, m_entries.size());
     for (index = m_entryIndex; index < maxIndex; ++index) {
         UpdateEntry& entry = m_entries[index];
-        entry.m_texture->updateRect(context, m_allocator, entry.m_sourceRect, entry.m_destRect);
+        entry.texture->updateRect(context, m_allocator, entry.sourceRect, entry.destRect);
     }
 
     bool moreUpdates = maxIndex < m_entries.size();
@@ -99,9 +109,19 @@
 
     for (index = 0; index < m_partialEntries.size(); ++index) {
         UpdateEntry& entry = m_partialEntries[index];
-        entry.m_texture->updateRect(context, m_allocator, entry.m_sourceRect, entry.m_destRect);
+        entry.texture->updateRect(context, m_allocator, entry.sourceRect, entry.destRect);
     }
 
+    for (index = 0; index < m_copyEntries.size(); ++index) {
+        CopyEntry& copyEntry = m_copyEntries[index];
+        m_copier->copyTexture(context, copyEntry.sourceTexture, copyEntry.destTexture, copyEntry.size);
+    }
+    // If we've performed any texture copies, we need to insert a flush here into the compositor context
+    // before letting the main thread proceed as it may make draw calls to the source texture of one of
+    // our copy operations.
+    if (m_copyEntries.size())
+        context->flush();
+
     // If no entries left to process, auto-clear.
     clear();
     return false;
@@ -112,6 +132,7 @@
     m_entryIndex = 0;
     m_entries.clear();
     m_partialEntries.clear();
+    m_copyEntries.clear();
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.h (113617 => 113618)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.h	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.h	2012-04-09 21:24:59 UTC (rev 113618)
@@ -41,8 +41,9 @@
     CCTextureUpdater(TextureAllocator*, TextureCopier*);
     ~CCTextureUpdater();
 
-    void append(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
-    void appendPartial(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
+    void appendUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
+    void appendPartialUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
+    void appendCopy(unsigned sourceTexture, unsigned destTexture, const IntSize&);
 
     bool hasMoreUpdates() const;
 
@@ -52,22 +53,28 @@
     void clear();
 
     TextureAllocator* allocator() { return m_allocator; }
-    TextureCopier* copier() { return m_copier; }
 
 private:
     struct UpdateEntry {
-        LayerTextureUpdater::Texture* m_texture;
-        IntRect m_sourceRect;
-        IntRect m_destRect;
+        LayerTextureUpdater::Texture* texture;
+        IntRect sourceRect;
+        IntRect destRect;
     };
 
-    static void append(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>&);
+    struct CopyEntry {
+        IntSize size;
+        unsigned sourceTexture;
+        unsigned destTexture;
+    };
 
+    static void appendUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>&);
+
     TextureAllocator* m_allocator;
     TextureCopier* m_copier;
     size_t m_entryIndex;
     Vector<UpdateEntry> m_entries;
     Vector<UpdateEntry> m_partialEntries;
+    Vector<CopyEntry> m_copyEntries;
 };
 
 }

Modified: trunk/Source/WebKit/chromium/ChangeLog (113617 => 113618)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-04-09 21:24:59 UTC (rev 113618)
@@ -1,3 +1,12 @@
+2012-04-06  James Robinson  <[email protected]>
+
+        [chromium] Texture copies should happen after incremental updates to preserve commit atomicity
+        https://bugs.webkit.org/show_bug.cgi?id=83392
+
+        Reviewed by Adrienne Walker.
+
+        * tests/Canvas2DLayerChromiumTest.cpp:
+
 2012-04-09  Sadrul Habib Chowdhury  <[email protected]>
 
         [chromium] Add Battery Status API support.

Modified: trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp (113617 => 113618)


--- trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp	2012-04-09 21:07:42 UTC (rev 113617)
+++ trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp	2012-04-09 21:24:59 UTC (rev 113618)
@@ -97,8 +97,8 @@
         RefPtr<GraphicsContext3D> mainContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
         RefPtr<GraphicsContext3D> implContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
 
+        MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(mainContext.get()));
         MockCanvasContext& implMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(implContext.get()));
-        MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(mainContext.get()));
 
         MockTextureAllocator allocatorMock;
         MockTextureCopier copierMock;
@@ -156,6 +156,8 @@
             canvas->updateCompositorResources(implContext.get(), updater);
             canvas->pushPropertiesTo(layerImpl.get());
 
+            updater.update(implContext.get(), 1);
+
             if (threaded)
                 EXPECT_EQ(frontTextureId, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId());
             else
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to