Title: [123751] trunk/Source/WebKit/blackberry
Revision
123751
Author
[email protected]
Date
2012-07-26 09:00:16 -0700 (Thu, 26 Jul 2012)

Log Message

[BlackBerry] Refactor BackingStorePrivate::render() to avoid touching tile frontbuffer
https://bugs.webkit.org/show_bug.cgi?id=91989

Patch by Arvid Nilsson <[email protected]> on 2012-07-26
Reviewed by George Staikos.

PR: 141439
Specifically, we want to avoid changing the rendered region of the
front buffer. The code only touched the front buffer rendered region
if the tile was not committed.

Instead of immediately marking the tile as committed, and clearing the
front buffer's rendered region to make it appear as checkerboard, we
leave the front buffer alone and only mark the tile as committed once
the front buffer has valid content. Un-committed tiles will also be
rendered as checkerboard, so leaving it uncommitted is equivalent to
clearing the front buffer rendered region here.

In addition to the main change, some related changes follow naturally.

The copyPreviousContentsToBackSurfaceOfTile() call only makes sense if
the tile is committed, and the front buffer has valid content.
Otherwise, clearing the back buffer is equivalent. The code has been
updated to this effect.

Since copyPreviousContentsToBackSurfaceOfTile() always sets the
rendered region to the union of the front and back buffer regions,
there is no point in the "backBufferIsValid" check. It has been turned
into an ASSERT instead, just to make sure.

Internally reviewed by Jakob Petsovits.

* Api/BackingStore.cpp:
(BlackBerry::WebKit::BackingStorePrivate::render):

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/Api/BackingStore.cpp (123750 => 123751)


--- trunk/Source/WebKit/blackberry/Api/BackingStore.cpp	2012-07-26 15:51:45 UTC (rev 123750)
+++ trunk/Source/WebKit/blackberry/Api/BackingStore.cpp	2012-07-26 16:00:16 UTC (rev 123751)
@@ -1090,15 +1090,6 @@
         // transformed contents coordinates.
         Platform::IntRect dirtyRect = mapFromTilesToTransformedContents(tileRect);
 
-        // If we're not yet committed, then commit now by clearing the rendered region
-        // and setting the committed flag as well as clearing the shift.
-        if (!tile->isCommitted()) {
-            tile->setCommitted(true);
-            tile->frontBuffer()->clearRenderedRegion();
-            tile->backBuffer()->clearRenderedRegion();
-            tile->clearShift();
-        }
-
         // If the tile has been created, but this is the first time we are painting on it
         // then it hasn't been given a default background yet so that we can save time during
         // startup. That's why we are doing it here instead...
@@ -1144,7 +1135,14 @@
 
         // Modify the buffer only after we've waited for the buffer to become available above.
 
-        copyPreviousContentsToBackSurfaceOfTile(dirtyTileRect, tile);
+        // If we're not yet committed, then commit only after the tile has back buffer has been
+        // swapped in so it has some valid content.
+        // Otherwise the compositing thread could pick up the tile while its front buffer is still invalid.
+        bool wasCommitted = tile->isCommitted();
+        if (wasCommitted)
+            copyPreviousContentsToBackSurfaceOfTile(dirtyTileRect, tile);
+        else
+            tile->backBuffer()->clearRenderedRegion();
 
         // FIXME: modify render to take a Vector<IntRect> parameter so we're not recreating
         // GraphicsContext on the stack each time.
@@ -1153,22 +1151,26 @@
         // Add the newly rendered region to the tile so it can keep track for blits.
         tile->backBuffer()->addRenderedRegion(dirtyTileRect);
 
-        // Check if the contents for this tile's backbuffer are valid when
-        // compared to the front buffer.
-        bool backBufferIsValid = tile->backBuffer()->isRendered(tile->frontBuffer()->renderedRegion());
+        // Thanks to the copyPreviousContentsToBackSurfaceOfTile() call above, we know that
+        // the rendered region of the back buffer contains the rendered region of the front buffer.
+        // Assert this just to make sure.
+        // For previously uncommitted tiles, the front buffer's rendered region is not relevant.
+        ASSERT(!wasCommitted || tile->backBuffer()->isRendered(tile->frontBuffer()->renderedRegion()));
 
-        // Our current design demands that the backbuffer is valid after any
-        // rendering operation so assert that here. If we hit this assert we
-        // know that we're doing something bad that will result in artifacts.
-        ASSERT(backBufferIsValid);
+        // We will need a swap here because of the shared back buffer.
+        tile->swapBuffers();
 
-        // We will need a swap here because of the shared back buffer.
-        if (backBufferIsValid) {
-            tile->swapBuffers();
-            BlackBerry::Platform::userInterfaceThreadMessageClient()->syncToCurrentMessage();
-            tile->backBuffer()->clearRenderedRegion();
+        if (!wasCommitted) {
+            // Commit the tile only after it has valid front buffer contents. Now, the compositing thread
+            // can finally start blitting this tile.
+            tile->clearShift();
+            tile->setCommitted(true);
         }
 
+        // Before clearing the render region, wait for the compositing thread to stop using the
+        // buffer, in order to avoid a race on its rendered region.
+        BlackBerry::Platform::userInterfaceThreadMessageClient()->syncToCurrentMessage();
+        tile->backBuffer()->clearRenderedRegion();
     }
 
     return true;

Modified: trunk/Source/WebKit/blackberry/ChangeLog (123750 => 123751)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-07-26 15:51:45 UTC (rev 123750)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-07-26 16:00:16 UTC (rev 123751)
@@ -1,3 +1,39 @@
+2012-07-26  Arvid Nilsson  <[email protected]>
+
+        [BlackBerry] Refactor BackingStorePrivate::render() to avoid touching tile frontbuffer
+        https://bugs.webkit.org/show_bug.cgi?id=91989
+
+        Reviewed by George Staikos.
+
+        PR: 141439
+        Specifically, we want to avoid changing the rendered region of the
+        front buffer. The code only touched the front buffer rendered region
+        if the tile was not committed.
+
+        Instead of immediately marking the tile as committed, and clearing the
+        front buffer's rendered region to make it appear as checkerboard, we
+        leave the front buffer alone and only mark the tile as committed once
+        the front buffer has valid content. Un-committed tiles will also be
+        rendered as checkerboard, so leaving it uncommitted is equivalent to
+        clearing the front buffer rendered region here.
+
+        In addition to the main change, some related changes follow naturally.
+
+        The copyPreviousContentsToBackSurfaceOfTile() call only makes sense if
+        the tile is committed, and the front buffer has valid content.
+        Otherwise, clearing the back buffer is equivalent. The code has been
+        updated to this effect.
+
+        Since copyPreviousContentsToBackSurfaceOfTile() always sets the
+        rendered region to the union of the front and back buffer regions,
+        there is no point in the "backBufferIsValid" check. It has been turned
+        into an ASSERT instead, just to make sure.
+
+        Internally reviewed by Jakob Petsovits.
+
+        * Api/BackingStore.cpp:
+        (BlackBerry::WebKit::BackingStorePrivate::render):
+
 2012-07-25  Jonathan Dong  <[email protected]>
 
         [BlackBerry] Support RTSP in browser
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to