<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[151262] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/151262">151262</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2013-06-06 02:43:20 -0700 (Thu, 06 Jun 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
https://bugs.webkit.org/show_bug.cgi?id=108899

Patch by Jae Hyun Park &lt;jae.park@company100.net&gt; on 2013-06-06
Reviewed by Noam Rosenthal.

This is a preparation patch for Threaded Coordinated Graphics.

This patch changes CoordinatedSurface to be responsible for the
lifecycle of GraphicsContext used in Coordinated Graphics System.
CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
of GraphicsContext anymore. Instead, those classes use client pattern to
ask the CoordiantedSurface to paint to the GraphicsContext.

This refactoring is needed to implement CoordinatedSurface for Threaded
Coordinated Graphics.

Source/WebCore:

No new tests, covered by existing tests.

* platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::paintToSurface):
* platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
* platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
(WebCore::ImageBackingSurfaceClient::ImageBackingSurfaceClient):
(WebCore::CoordinatedImageBacking::update):
* platform/graphics/texmap/coordinated/CoordinatedSurface.h:
(WebCore::CoordinatedSurface::Client::~Client):
* platform/graphics/texmap/coordinated/CoordinatedTile.cpp:
(WebCore::CoordinatedTile::updateBackBuffer):
(WebCore::CoordinatedTile::paintToSurfaceContext):
* platform/graphics/texmap/coordinated/CoordinatedTile.h:
* platform/graphics/texmap/coordinated/UpdateAtlas.cpp:
(WebCore::UpdateAtlasSurfaceClient::UpdateAtlasSurfaceClient):
(WebCore::UpdateAtlas::paintOnAvailableBuffer):
* platform/graphics/texmap/coordinated/UpdateAtlas.h:

Source/WebKit2:

* Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp:
(WebKit::WebCoordinatedSurface::paintToSurface):
* Shared/CoordinatedGraphics/WebCoordinatedSurface.h:
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
(WebKit::CoordinatedLayerTreeHost::paintToSurface):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedGraphicsLayercpp">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedGraphicsLayerh">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedImageBackingcpp">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedSurfaceh">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedSurface.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedTilecpp">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedTileh">trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedUpdateAtlascpp">trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicstexmapcoordinatedUpdateAtlash">trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsWebCoordinatedSurfacecpp">trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsWebCoordinatedSurfaceh">trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCoordinatedLayerTreeHostcpp">trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCoordinatedLayerTreeHosth">trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/ChangeLog        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2013-06-06  Jae Hyun Park  &lt;jae.park@company100.net&gt;
+
+        Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
+        https://bugs.webkit.org/show_bug.cgi?id=108899
+
+        Reviewed by Noam Rosenthal.
+
+        This is a preparation patch for Threaded Coordinated Graphics.
+
+        This patch changes CoordinatedSurface to be responsible for the
+        lifecycle of GraphicsContext used in Coordinated Graphics System.
+        CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
+        of GraphicsContext anymore. Instead, those classes use client pattern to
+        ask the CoordiantedSurface to paint to the GraphicsContext.
+
+        This refactoring is needed to implement CoordinatedSurface for Threaded
+        Coordinated Graphics.
+
+        No new tests, covered by existing tests.
+
+        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
+        (WebCore::CoordinatedGraphicsLayer::paintToSurface):
+        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
+        * platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
+        (WebCore::ImageBackingSurfaceClient::ImageBackingSurfaceClient):
+        (WebCore::CoordinatedImageBacking::update):
+        * platform/graphics/texmap/coordinated/CoordinatedSurface.h:
+        (WebCore::CoordinatedSurface::Client::~Client):
+        * platform/graphics/texmap/coordinated/CoordinatedTile.cpp:
+        (WebCore::CoordinatedTile::updateBackBuffer):
+        (WebCore::CoordinatedTile::paintToSurfaceContext):
+        * platform/graphics/texmap/coordinated/CoordinatedTile.h:
+        * platform/graphics/texmap/coordinated/UpdateAtlas.cpp:
+        (WebCore::UpdateAtlasSurfaceClient::UpdateAtlasSurfaceClient):
+        (WebCore::UpdateAtlas::paintOnAvailableBuffer):
+        * platform/graphics/texmap/coordinated/UpdateAtlas.h:
+
</ins><span class="cx"> 2013-06-05  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Revert the second half of r151257. WebGLRenderingContext::create can return null.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedGraphicsLayercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -959,11 +959,11 @@
</span><span class="cx">     return contentsOpaque() ? Color::white : Color::transparent;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;GraphicsContext&gt; CoordinatedGraphicsLayer::beginContentUpdate(const IntSize&amp; size, uint32_t&amp; atlas, IntPoint&amp; offset)
</del><ins>+bool CoordinatedGraphicsLayer::paintToSurface(const IntSize&amp; size, uint32_t&amp; atlas, IntPoint&amp; offset, CoordinatedSurface::Client* client)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_coordinator);
</span><span class="cx">     ASSERT(m_coordinator-&gt;isFlushingLayerChanges());
</span><del>-    return m_coordinator-&gt;beginContentUpdate(size, contentsOpaque() ? CoordinatedSurface::NoFlags : CoordinatedSurface::SupportsAlpha, atlas, offset);
</del><ins>+    return m_coordinator-&gt;paintToSurface(size, contentsOpaque() ? CoordinatedSurface::NoFlags : CoordinatedSurface::SupportsAlpha, atlas, offset, client);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CoordinatedGraphicsLayer::createTile(uint32_t tileID, const SurfaceUpdateInfo&amp; updateInfo, const IntRect&amp; tileRect)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedGraphicsLayerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">     virtual FloatRect visibleContentsRect() const = 0;
</span><span class="cx">     virtual PassRefPtr&lt;CoordinatedImageBacking&gt; createImageBackingIfNeeded(Image*) = 0;
</span><span class="cx">     virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
</span><del>-    virtual PassOwnPtr&lt;GraphicsContext&gt; beginContentUpdate(const IntSize&amp;, CoordinatedSurface::Flags, uint32_t&amp; atlasID, IntPoint&amp;) = 0;
</del><ins>+    virtual bool paintToSurface(const IntSize&amp;, CoordinatedSurface::Flags, uint32_t&amp; atlasID, IntPoint&amp;, CoordinatedSurface::Client*) = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&amp;) = 0;
</span><span class="cx"> };
</span><span class="lines">@@ -142,7 +142,7 @@
</span><span class="cx">     virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&amp;, const IntRect&amp;) OVERRIDE;
</span><span class="cx">     virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&amp;, const IntRect&amp;) OVERRIDE;
</span><span class="cx">     virtual void removeTile(uint32_t tileID) OVERRIDE;
</span><del>-    virtual PassOwnPtr&lt;GraphicsContext&gt; beginContentUpdate(const IntSize&amp;, uint32_t&amp; atlasID, IntPoint&amp;) OVERRIDE;
</del><ins>+    virtual bool paintToSurface(const IntSize&amp;, uint32_t&amp; /* atlasID */, IntPoint&amp;, CoordinatedSurface::Client*) OVERRIDE;
</ins><span class="cx"> 
</span><span class="cx">     void setCoordinator(CoordinatedGraphicsLayerClient*);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedImageBackingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -33,6 +33,24 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class ImageBackingSurfaceClient : public CoordinatedSurface::Client {
+public:
+    ImageBackingSurfaceClient(Image* image, const IntRect&amp; rect)
+        : m_image(image)
+        , m_rect(rect)
+    {
+    }
+
+    virtual void paintToSurfaceContext(GraphicsContext* context) OVERRIDE
+    {
+        context-&gt;drawImage(m_image, ColorSpaceDeviceRGB, m_rect, m_rect);
+    }
+
+private:
+    Image* m_image;
+    IntRect m_rect;
+};
+
</ins><span class="cx"> CoordinatedImageBackingID CoordinatedImageBacking::getCoordinatedImageBackingID(Image* image)
</span><span class="cx"> {
</span><span class="cx">     // CoordinatedImageBacking keeps a RefPtr&lt;Image&gt; member, so the same Image pointer can not refer two different instances until CoordinatedImageBacking releases the member.
</span><span class="lines">@@ -109,9 +127,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     IntRect rect(IntPoint::zero(), m_image-&gt;size());
</span><del>-    OwnPtr&lt;GraphicsContext&gt; context = m_surface-&gt;createGraphicsContext(rect);
-    context-&gt;drawImage(m_image.get(), ColorSpaceDeviceRGB, rect, rect);
</del><span class="cx"> 
</span><ins>+    ImageBackingSurfaceClient surfaceClient(m_image.get(), rect);
+    m_surface-&gt;paintToSurface(rect, &amp;surfaceClient);
+
</ins><span class="cx">     m_nativeImagePtr = m_image-&gt;nativeImageForCurrentFrame();
</span><span class="cx"> 
</span><span class="cx">     m_client-&gt;updateImageBacking(id(), m_surface);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedSurfaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedSurface.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedSurface.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedSurface.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -39,6 +39,12 @@
</span><span class="cx">     };
</span><span class="cx">     typedef unsigned Flags;
</span><span class="cx"> 
</span><ins>+    class Client {
+    public:
+        virtual ~Client() { }
+        virtual void paintToSurfaceContext(GraphicsContext*) = 0;
+    };
+
</ins><span class="cx">     typedef PassRefPtr&lt;CoordinatedSurface&gt; Factory(const IntSize&amp;, Flags);
</span><span class="cx">     static void setFactory(Factory);
</span><span class="cx">     static PassRefPtr&lt;CoordinatedSurface&gt; create(const IntSize&amp;, Flags);
</span><span class="lines">@@ -48,8 +54,7 @@
</span><span class="cx">     bool supportsAlpha() const { return flags() &amp; SupportsAlpha; }
</span><span class="cx">     virtual IntSize size() const = 0;
</span><span class="cx"> 
</span><del>-    // Create a graphics context that can be used to paint into the backing store.
-    virtual PassOwnPtr&lt;GraphicsContext&gt; createGraphicsContext(const IntRect&amp;) = 0;
</del><ins>+    virtual void paintToSurface(const IntRect&amp;, Client*) = 0;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(TEXTURE_MAPPER)
</span><span class="cx">     virtual void copyToTexture(PassRefPtr&lt;BitmapTexture&gt;, const IntRect&amp; target, const IntPoint&amp; sourceOffset) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedTilecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -73,17 +73,13 @@
</span><span class="cx">         return Vector&lt;IntRect&gt;();
</span><span class="cx"> 
</span><span class="cx">     SurfaceUpdateInfo updateInfo;
</span><del>-    OwnPtr&lt;GraphicsContext&gt; graphicsContext = m_client-&gt;beginContentUpdate(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset);
-    if (!graphicsContext)
</del><ins>+
+    if (!m_client-&gt;paintToSurface(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset, this))
</ins><span class="cx">         return Vector&lt;IntRect&gt;();
</span><del>-    graphicsContext-&gt;translate(-m_dirtyRect.x(), -m_dirtyRect.y());
-    graphicsContext-&gt;scale(FloatSize(m_tiledBackingStore-&gt;contentsScale(), m_tiledBackingStore-&gt;contentsScale()));
-    m_tiledBackingStore-&gt;client()-&gt;tiledBackingStorePaint(graphicsContext.get(), m_tiledBackingStore-&gt;mapToContents(m_dirtyRect));
</del><span class="cx"> 
</span><span class="cx">     updateInfo.updateRect = m_dirtyRect;
</span><span class="cx">     updateInfo.updateRect.move(-m_rect.x(), -m_rect.y());
</span><span class="cx">     updateInfo.scaleFactor = m_tiledBackingStore-&gt;contentsScale();
</span><del>-    graphicsContext.release();
</del><span class="cx"> 
</span><span class="cx">     static uint32_t id = 1;
</span><span class="cx">     if (m_ID == InvalidCoordinatedTileID) {
</span><span class="lines">@@ -101,6 +97,13 @@
</span><span class="cx">     return updatedRects;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void CoordinatedTile::paintToSurfaceContext(GraphicsContext* context)
+{
+    context-&gt;translate(-m_dirtyRect.x(), -m_dirtyRect.y());
+    context-&gt;scale(FloatSize(m_tiledBackingStore-&gt;contentsScale(), m_tiledBackingStore-&gt;contentsScale()));
+    m_tiledBackingStore-&gt;client()-&gt;tiledBackingStorePaint(context, m_tiledBackingStore-&gt;mapToContents(m_dirtyRect));
+}
+
</ins><span class="cx"> void CoordinatedTile::swapBackBufferToFront()
</span><span class="cx"> {
</span><span class="cx">     // Handled by tiledBackingStorePaintEnd.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedCoordinatedTileh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedTile.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(TILED_BACKING_STORE)
</span><span class="cx"> 
</span><ins>+#include &quot;CoordinatedSurface.h&quot;
</ins><span class="cx"> #include &quot;IntRect.h&quot;
</span><span class="cx"> #include &quot;Tile.h&quot;
</span><span class="cx"> #include &quot;TiledBackingStore.h&quot;
</span><span class="lines">@@ -39,7 +40,7 @@
</span><span class="cx"> class SurfaceUpdateInfo;
</span><span class="cx"> class TiledBackingStore;
</span><span class="cx"> 
</span><del>-class CoordinatedTile : public Tile {
</del><ins>+class CoordinatedTile : public Tile, public CoordinatedSurface::Client {
</ins><span class="cx"> public:
</span><span class="cx">     static PassRefPtr&lt;Tile&gt; create(CoordinatedTileClient* client, TiledBackingStore* tiledBackingStore, const Coordinate&amp; tileCoordinate) { return adoptRef(new CoordinatedTile(client, tiledBackingStore, tileCoordinate)); }
</span><span class="cx">     ~CoordinatedTile();
</span><span class="lines">@@ -55,6 +56,8 @@
</span><span class="cx">     const IntRect&amp; rect() const { return m_rect; }
</span><span class="cx">     void resize(const IntSize&amp;);
</span><span class="cx"> 
</span><ins>+    virtual void paintToSurfaceContext(GraphicsContext*) OVERRIDE;
+
</ins><span class="cx"> private:
</span><span class="cx">     CoordinatedTile(CoordinatedTileClient*, TiledBackingStore*, const Coordinate&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -75,7 +78,7 @@
</span><span class="cx">     virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&amp;, const IntRect&amp;) = 0;
</span><span class="cx">     virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&amp;, const IntRect&amp;) = 0;
</span><span class="cx">     virtual void removeTile(uint32_t tileID) = 0;
</span><del>-    virtual PassOwnPtr&lt;GraphicsContext&gt; beginContentUpdate(const IntSize&amp;, uint32_t&amp; atlasID, IntPoint&amp;) = 0;
</del><ins>+    virtual bool paintToSurface(const IntSize&amp;, uint32_t&amp; atlasID, IntPoint&amp;, CoordinatedSurface::Client*) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class CoordinatedTileBackend : public TiledBackingStoreBackend {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedUpdateAtlascpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -30,6 +30,32 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class UpdateAtlasSurfaceClient : public CoordinatedSurface::Client {
+public:
+    UpdateAtlasSurfaceClient(CoordinatedSurface::Client* client, const IntSize&amp; size, bool supportsAlpha)
+        : m_client(client)
+        , m_size(size)
+        , m_supportsAlpha(supportsAlpha)
+    {
+    }
+
+    virtual void paintToSurfaceContext(GraphicsContext* context) OVERRIDE
+    {
+        if (m_supportsAlpha) {
+            context-&gt;setCompositeOperation(CompositeCopy);
+            context-&gt;fillRect(IntRect(IntPoint::zero(), m_size), Color::transparent, ColorSpaceDeviceRGB);
+            context-&gt;setCompositeOperation(CompositeSourceOver);
+        }
+
+        m_client-&gt;paintToSurfaceContext(context);
+    }
+
+private:
+    CoordinatedSurface::Client* m_client;
+    IntSize m_size;
+    bool m_supportsAlpha;
+};
+
</ins><span class="cx"> UpdateAtlas::UpdateAtlas(Client* client, int dimension, CoordinatedSurface::Flags flags)
</span><span class="cx">     : m_client(client)
</span><span class="cx">     , m_inactivityInSeconds(0)
</span><span class="lines">@@ -61,32 +87,29 @@
</span><span class="cx">     m_areaAllocator.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;GraphicsContext&gt; UpdateAtlas::beginPaintingOnAvailableBuffer(uint32_t&amp; atlasID, const IntSize&amp; size, IntPoint&amp; offset)
</del><ins>+
+bool UpdateAtlas::paintOnAvailableBuffer(const IntSize&amp; size, uint32_t&amp; atlasID, IntPoint&amp; offset, CoordinatedSurface::Client* client)
</ins><span class="cx"> {
</span><span class="cx">     m_inactivityInSeconds = 0;
</span><span class="cx">     buildLayoutIfNeeded();
</span><span class="cx">     IntRect rect = m_areaAllocator-&gt;allocate(size);
</span><span class="cx"> 
</span><del>-    // No available buffer was found, returning null.
</del><ins>+    // No available buffer was found.
</ins><span class="cx">     if (rect.isEmpty())
</span><del>-        return PassOwnPtr&lt;GraphicsContext&gt;();
</del><ins>+        return false;
</ins><span class="cx"> 
</span><span class="cx">     if (!m_surface)
</span><del>-        return PassOwnPtr&lt;GraphicsContext&gt;();
</del><ins>+        return false;
</ins><span class="cx"> 
</span><span class="cx">     atlasID = m_ID;
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Use tri-state buffers, to allow faster updates.
</span><span class="cx">     offset = rect.location();
</span><del>-    OwnPtr&lt;GraphicsContext&gt; graphicsContext = m_surface-&gt;createGraphicsContext(rect);
</del><span class="cx"> 
</span><del>-    if (supportsAlpha()) {
-        graphicsContext-&gt;setCompositeOperation(CompositeCopy);
-        graphicsContext-&gt;fillRect(IntRect(IntPoint::zero(), size), Color::transparent, ColorSpaceDeviceRGB);
-        graphicsContext-&gt;setCompositeOperation(CompositeSourceOver);
-    }
</del><ins>+    UpdateAtlasSurfaceClient surfaceClient(client, size, supportsAlpha());
+    m_surface-&gt;paintToSurface(rect, &amp;surfaceClient);
</ins><span class="cx"> 
</span><del>-    return graphicsContext.release();
</del><ins>+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicstexmapcoordinatedUpdateAtlash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -45,8 +45,8 @@
</span><span class="cx"> 
</span><span class="cx">     inline IntSize size() const { return m_surface-&gt;size(); }
</span><span class="cx"> 
</span><del>-    // Returns a null pointer of there is no available buffer.
-    PassOwnPtr&lt;GraphicsContext&gt; beginPaintingOnAvailableBuffer(uint32_t&amp; atlasID, const IntSize&amp;, IntPoint&amp; offset);
</del><ins>+    // Returns false if there is no available buffer.
+    bool paintOnAvailableBuffer(const IntSize&amp;, uint32_t&amp; atlasID, IntPoint&amp; offset, CoordinatedSurface::Client*);
</ins><span class="cx">     void didSwapBuffers();
</span><span class="cx">     bool supportsAlpha() const { return m_surface-&gt;supportsAlpha(); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebKit2/ChangeLog        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2013-06-06  Jae Hyun Park  &lt;jae.park@company100.net&gt;
+
+        Coordinated Graphics : Refactor CoordinatedSurface to manage the lifecycle of GraphicsContext
+        https://bugs.webkit.org/show_bug.cgi?id=108899
+
+        Reviewed by Noam Rosenthal.
+
+        This is a preparation patch for Threaded Coordinated Graphics.
+
+        This patch changes CoordinatedSurface to be responsible for the
+        lifecycle of GraphicsContext used in Coordinated Graphics System.
+        CoordinatedImageBacking and UpdateAtlas do not ask for the ownership
+        of GraphicsContext anymore. Instead, those classes use client pattern to
+        ask the CoordiantedSurface to paint to the GraphicsContext.
+
+        This refactoring is needed to implement CoordinatedSurface for Threaded
+        Coordinated Graphics.
+
+        * Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp:
+        (WebKit::WebCoordinatedSurface::paintToSurface):
+        * Shared/CoordinatedGraphics/WebCoordinatedSurface.h:
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
+        (WebKit::CoordinatedLayerTreeHost::paintToSurface):
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
+
</ins><span class="cx"> 2013-06-05  Kangil Han  &lt;kangil.han@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL][WK2] Fix test_ewk2_view unit test timed out issue
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsWebCoordinatedSurfacecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -183,6 +183,14 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebCoordinatedSurface::paintToSurface(const IntRect&amp; rect, CoordinatedSurface::Client* client)
+{
+    ASSERT(client);
+
+    OwnPtr&lt;GraphicsContext&gt; context = createGraphicsContext(rect);
+    client-&gt;paintToSurfaceContext(context.get());
+}
+
</ins><span class="cx"> #if USE(TEXTURE_MAPPER)
</span><span class="cx"> void WebCoordinatedSurface::copyToTexture(PassRefPtr&lt;WebCore::BitmapTexture&gt; passTexture, const IntRect&amp; target, const IntPoint&amp; sourceOffset)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsWebCoordinatedSurfaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/WebCoordinatedSurface.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual WebCore::IntSize size() const OVERRIDE { return m_size; }
</span><span class="cx"> 
</span><del>-    virtual PassOwnPtr&lt;WebCore::GraphicsContext&gt; createGraphicsContext(const WebCore::IntRect&amp;) OVERRIDE;
</del><ins>+    virtual void paintToSurface(const WebCore::IntRect&amp;, WebCore::CoordinatedSurface::Client*) OVERRIDE;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(TEXTURE_MAPPER)
</span><span class="cx">     virtual void copyToTexture(PassRefPtr&lt;WebCore::BitmapTexture&gt;, const WebCore::IntRect&amp; target, const WebCore::IntPoint&amp; sourceOffset) OVERRIDE;
</span><span class="lines">@@ -87,6 +87,7 @@
</span><span class="cx">     // Create a WebCoordinatedSurface referencing an existing ShareableBitmap.
</span><span class="cx">     static PassRefPtr&lt;WebCoordinatedSurface&gt; create(const WebCore::IntSize&amp;, Flags, PassRefPtr&lt;ShareableBitmap&gt;);
</span><span class="cx"> 
</span><ins>+    PassOwnPtr&lt;WebCore::GraphicsContext&gt; createGraphicsContext(const WebCore::IntRect&amp;);
</ins><span class="cx"> #if USE(GRAPHICS_SURFACE)
</span><span class="cx">     WebCoordinatedSurface(const WebCore::IntSize&amp;, Flags, PassRefPtr&lt;WebCore::GraphicsSurface&gt;);
</span><span class="cx">     // Create a shareable bitmap backed by a graphics surface.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCoordinatedLayerTreeHostcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -670,23 +670,21 @@
</span><span class="cx">     m_updateAtlases.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;GraphicsContext&gt; CoordinatedLayerTreeHost::beginContentUpdate(const IntSize&amp; size, CoordinatedSurface::Flags flags, uint32_t&amp; atlasID, IntPoint&amp; offset)
</del><ins>+bool CoordinatedLayerTreeHost::paintToSurface(const IntSize&amp; size, CoordinatedSurface::Flags flags, uint32_t&amp; atlasID, IntPoint&amp; offset, CoordinatedSurface::Client* client)
</ins><span class="cx"> {
</span><del>-    OwnPtr&lt;GraphicsContext&gt; graphicsContext;
</del><span class="cx">     for (unsigned i = 0; i &lt; m_updateAtlases.size(); ++i) {
</span><span class="cx">         UpdateAtlas* atlas = m_updateAtlases[i].get();
</span><span class="cx">         if (atlas-&gt;supportsAlpha() == (flags &amp; CoordinatedSurface::SupportsAlpha)) {
</span><del>-            // This will return null if there is no available buffer space.
-            graphicsContext = atlas-&gt;beginPaintingOnAvailableBuffer(atlasID, size, offset);
-            if (graphicsContext)
-                return graphicsContext.release();
</del><ins>+            // This will false if there is no available buffer space.
+            if (atlas-&gt;paintOnAvailableBuffer(size, atlasID, offset, client))
+                return true;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     static const int ScratchBufferDimension = 1024; // Should be a power of two.
</span><span class="cx">     m_updateAtlases.append(adoptPtr(new UpdateAtlas(this, ScratchBufferDimension, flags)));
</span><span class="cx">     scheduleReleaseInactiveAtlases();
</span><del>-    return m_updateAtlases.last()-&gt;beginPaintingOnAvailableBuffer(atlasID, size, offset);
</del><ins>+    return m_updateAtlases.last()-&gt;paintOnAvailableBuffer(size, atlasID, offset, client);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> const double ReleaseInactiveAtlasesTimerInterval = 0.5;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageCoordinatedGraphicsCoordinatedLayerTreeHosth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h (151261 => 151262)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h        2013-06-06 09:19:57 UTC (rev 151261)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h        2013-06-06 09:43:20 UTC (rev 151262)
</span><span class="lines">@@ -124,7 +124,7 @@
</span><span class="cx">     virtual WebCore::FloatRect visibleContentsRect() const;
</span><span class="cx">     virtual PassRefPtr&lt;WebCore::CoordinatedImageBacking&gt; createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
</span><span class="cx">     virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
</span><del>-    virtual PassOwnPtr&lt;WebCore::GraphicsContext&gt; beginContentUpdate(const WebCore::IntSize&amp;, WebCore::CoordinatedSurface::Flags, uint32_t&amp; atlasID, WebCore::IntPoint&amp;);
</del><ins>+    virtual bool paintToSurface(const WebCore::IntSize&amp;, WebCore::CoordinatedSurface::Flags, uint32_t&amp; /* atlasID */, WebCore::IntPoint&amp;, WebCore::CoordinatedSurface::Client*) OVERRIDE;
</ins><span class="cx">     virtual void syncLayerState(WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayerState&amp;);
</span><span class="cx"> 
</span><span class="cx">     // UpdateAtlas::Client
</span></span></pre>
</div>
</div>

</body>
</html>