<!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>[177276] trunk/Source/WebKit2</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/177276">177276</a></dd>
<dt>Author</dt> <dd>yoon@igalia.com</dd>
<dt>Date</dt> <dd>2014-12-15 02:39:49 -0800 (Mon, 15 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add initial implementation of ThreadSafeCoordinatedSurface, ThreadedCompositor, and SimpleViewportController
https://bugs.webkit.org/show_bug.cgi?id=118383

Reviewed by Martin Robinson.

Implements an initial version of the Threaded Compositor.

Threaded Compositor is a variant of Coordinated Graphics implementation.
Basic structure of the implementaion is simliar, thus, Threaded
Compositor reuses lots of classes from Coordinated Graphics. However,
instead of compositing on UI Process, Threaded Compositor performs
compositing on a dedicate thread of Web Process.

No new test, because it is in experimental stage.

* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::CoordinatedGraphicsScene):
Removed a assertion not to force its creation in the main thread. In
the Threaded Compositor, it can be created in the dedicated thread.

* Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp: Added.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h: Added.
Implements a surface using ImageBuffer as a backend to use in the Web
Process.

* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h: Added.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: Added.
Implements a compositor which runs on the created thread. It owns
SimpleViewportController and CoordinatedGraphicsScene to render scene on the
actual surface.

* Shared/CoordinatedGraphics/SimpleViewportController.cpp: Added.
* Shared/CoordinatedGraphics/SimpleViewportController.h: Added.
This class is responsible to handle scale factor and scrolling position
with a simplifed logic in the compositing thread.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsCoordinatedGraphicsScenecpp">trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsSimpleViewportControllercpp">trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsSimpleViewportControllerh">trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.h</a></li>
<li>trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/</li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadSafeCoordinatedSurfacecpp">trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadSafeCoordinatedSurfaceh">trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadedCompositorcpp">trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadedCompositorh">trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (177275 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-12-15 09:58:39 UTC (rev 177275)
+++ trunk/Source/WebKit2/ChangeLog        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2014-12-15  Gwang Yoon Hwang  &lt;yoon@igalia.com&gt;
+
+        Add initial implementation of ThreadSafeCoordinatedSurface, ThreadedCompositor, and SimpleViewportController
+        https://bugs.webkit.org/show_bug.cgi?id=118383
+
+        Reviewed by Martin Robinson.
+
+        Implements an initial version of the Threaded Compositor.
+
+        Threaded Compositor is a variant of Coordinated Graphics implementation.
+        Basic structure of the implementaion is simliar, thus, Threaded
+        Compositor reuses lots of classes from Coordinated Graphics. However,
+        instead of compositing on UI Process, Threaded Compositor performs
+        compositing on a dedicate thread of Web Process.
+
+        No new test, because it is in experimental stage.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
+        (WebKit::CoordinatedGraphicsScene::CoordinatedGraphicsScene):
+        Removed a assertion not to force its creation in the main thread. In
+        the Threaded Compositor, it can be created in the dedicated thread.
+
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp: Added.
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h: Added.
+        Implements a surface using ImageBuffer as a backend to use in the Web
+        Process.
+
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h: Added.
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: Added.
+        Implements a compositor which runs on the created thread. It owns
+        SimpleViewportController and CoordinatedGraphicsScene to render scene on the
+        actual surface.
+
+        * Shared/CoordinatedGraphics/SimpleViewportController.cpp: Added.
+        * Shared/CoordinatedGraphics/SimpleViewportController.h: Added.
+        This class is responsible to handle scale factor and scrolling position
+        with a simplifed logic in the compositing thread.
+
</ins><span class="cx"> 2014-12-14  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Replace PassRef with Ref/Ref&amp;&amp; across the board.
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsCoordinatedGraphicsScenecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp (177275 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp        2014-12-15 09:58:39 UTC (rev 177275)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -54,7 +54,6 @@
</span><span class="cx">     , m_rootLayerID(InvalidCoordinatedLayerID)
</span><span class="cx">     , m_viewBackgroundColor(Color::white)
</span><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CoordinatedGraphicsScene::~CoordinatedGraphicsScene()
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsSimpleViewportControllercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.cpp (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.cpp                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.cpp        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,201 @@
</span><ins>+/*
+ * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2011 Benjamin Poulain &lt;benjamin@webkit.org&gt;
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include &quot;config.h&quot;
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include &quot;SimpleViewportController.h&quot;
+
+using namespace WebCore;
+
+namespace WebKit {
+
+SimpleViewportController::SimpleViewportController(Client* client)
+    : m_client(client)
+    , m_contentsPosition(FloatPoint())
+    , m_contentsSize(FloatSize())
+    , m_viewportSize(FloatSize())
+    , m_allowsUserScaling(false)
+    , m_initiallyFitToViewport(true)
+    , m_hasViewportAttribute(false)
+{
+    resetViewportToDefaultState();
+}
+
+void SimpleViewportController::didChangeViewportSize(const FloatSize&amp; newSize)
+{
+    if (newSize.isEmpty())
+        return;
+
+    m_viewportSize = newSize;
+    updateMinimumScaleToFit();
+    syncVisibleContents();
+}
+
+void SimpleViewportController::didChangeContentsSize(const IntSize&amp; newSize)
+{
+    m_contentsSize = newSize;
+
+    updateMinimumScaleToFit();
+
+    if (m_initiallyFitToViewport) {
+        // Restrict scale factors to m_minimumScaleToFit.
+        ASSERT(m_minimumScaleToFit &gt; 0);
+        m_rawAttributes.initialScale = m_minimumScaleToFit;
+        restrictScaleFactorToInitialScaleIfNotUserScalable(m_rawAttributes);
+    }
+
+    syncVisibleContents();
+}
+
+void SimpleViewportController::didChangeViewportAttribute(const ViewportAttributes&amp; newAttributes)
+{
+    if (newAttributes.layoutSize.isEmpty()) {
+        resetViewportToDefaultState();
+        return;
+    }
+
+    m_hasViewportAttribute = true;
+
+    m_rawAttributes = newAttributes;
+    m_allowsUserScaling = m_rawAttributes.userScalable;
+    m_initiallyFitToViewport = m_rawAttributes.initialScale &lt; 0;
+
+    if (!m_initiallyFitToViewport)
+        restrictScaleFactorToInitialScaleIfNotUserScalable(m_rawAttributes);
+
+    updateMinimumScaleToFit();
+
+    syncVisibleContents();
+}
+
+void SimpleViewportController::scrollBy(const IntSize&amp; scrollOffset)
+{
+    m_contentsPosition.move(scrollOffset);
+    m_contentsPosition = boundContentsPosition(m_contentsPosition);
+
+    syncVisibleContents();
+}
+
+void SimpleViewportController::scrollTo(const IntPoint&amp; position)
+{
+    if (m_contentsPosition == boundContentsPosition(position))
+        return;
+
+    m_contentsPosition = boundContentsPosition(position);
+    syncVisibleContents();
+}
+
+void SimpleViewportController::syncVisibleContents()
+{
+    if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty())
+        return;
+
+    m_client-&gt;didChangeVisibleRect();
+}
+
+FloatRect SimpleViewportController::visibleContentsRect() const
+{
+    FloatRect visibleContentsRect(boundContentsPosition(m_contentsPosition), visibleContentsSize());
+    visibleContentsRect.intersect(FloatRect(FloatPoint::zero(), m_contentsSize));
+
+    return visibleContentsRect;
+}
+
+FloatSize SimpleViewportController::visibleContentsSize() const
+{
+    return FloatSize(m_viewportSize.width() / m_pageScaleFactor, m_viewportSize.height() / m_pageScaleFactor);
+}
+
+FloatPoint SimpleViewportController::boundContentsPositionAtScale(const FloatPoint&amp; framePosition, float scale) const
+{
+    // We need to floor the viewport here as to allow aligning the content in device units. If not,
+    // it might not be possible to scroll the last pixel and that affects fixed position elements.
+    return FloatPoint(
+        clampTo(framePosition.x(), .0f, std::max(.0f, m_contentsSize.width() - floorf(m_viewportSize.width() / scale))),
+        clampTo(framePosition.y(), .0f, std::max(.0f, m_contentsSize.height() - floorf(m_viewportSize.height() / scale))));
+}
+
+FloatPoint SimpleViewportController::boundContentsPosition(const FloatPoint&amp; framePosition) const
+{
+    return boundContentsPositionAtScale(framePosition, m_pageScaleFactor);
+}
+
+bool fuzzyCompare(float a, float b, float epsilon)
+{
+    return std::abs(a - b) &lt; epsilon;
+}
+
+bool SimpleViewportController::updateMinimumScaleToFit()
+{
+    if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty() || !m_hasViewportAttribute)
+        return false;
+
+    bool currentlyScaledToFit = fuzzyCompare(m_pageScaleFactor, m_minimumScaleToFit, 0.0001);
+
+    float minimumScale = computeMinimumScaleFactorForContentContained(m_rawAttributes, roundedIntSize(m_viewportSize), roundedIntSize(m_contentsSize));
+
+    if (minimumScale &lt;= 0)
+        return false;
+
+    if (!fuzzyCompare(minimumScale, m_minimumScaleToFit, 0.0001)) {
+        m_minimumScaleToFit = minimumScale;
+
+        if (currentlyScaledToFit)
+            m_pageScaleFactor = m_minimumScaleToFit;
+        else {
+            // Ensure the effective scale stays within bounds.
+            float boundedScale = innerBoundedViewportScale(m_pageScaleFactor);
+            if (!fuzzyCompare(boundedScale, m_pageScaleFactor, 0.0001))
+                m_pageScaleFactor = boundedScale;
+        }
+
+        return true;
+    }
+    return false;
+}
+
+float SimpleViewportController::innerBoundedViewportScale(float viewportScale) const
+{
+    return clampTo(viewportScale, m_minimumScaleToFit, m_rawAttributes.maximumScale);
+}
+
+void SimpleViewportController::resetViewportToDefaultState()
+{
+    m_hasViewportAttribute = false;
+    m_pageScaleFactor = 1;
+    m_minimumScaleToFit = 1;
+
+    // Initializing Viewport Raw Attributes to avoid random negative or infinity scale factors
+    // if there is a race condition between the first layout and setting the viewport attributes for the first time.
+    m_rawAttributes.minimumScale = 1;
+    m_rawAttributes.maximumScale = 1;
+    m_rawAttributes.userScalable = m_allowsUserScaling;
+
+    // The initial scale might be implicit and set to -1, in this case we have to infer it
+    // using the viewport size and the final layout size.
+    // To be able to assert for valid scale we initialize it to -1.
+    m_rawAttributes.initialScale = -1;
+}
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS_THREADED)
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsSimpleViewportControllerh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.h (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.h                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.h        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,93 @@
</span><ins>+/*
+ * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2011 Benjamin Poulain &lt;benjamin@webkit.org&gt;
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SimpleViewportController_h
+#define SimpleViewportController_h
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+
+#include &lt;WebCore/FloatPoint.h&gt;
+#include &lt;WebCore/FloatRect.h&gt;
+#include &lt;WebCore/FloatSize.h&gt;
+#include &lt;WebCore/IntRect.h&gt;
+#include &lt;WebCore/IntSize.h&gt;
+#include &lt;WebCore/ViewportArguments.h&gt;
+#include &lt;wtf/Noncopyable.h&gt;
+
+namespace WebKit {
+
+class SimpleViewportController {
+    WTF_MAKE_NONCOPYABLE(SimpleViewportController);
+public:
+    class Client {
+    public:
+        virtual void didChangeVisibleRect() = 0;
+    };
+
+    explicit SimpleViewportController(Client*);
+
+    void didChangeViewportSize(const WebCore::FloatSize&amp;);
+    void didChangeContentsSize(const WebCore::IntSize&amp;);
+    void didChangeViewportAttribute(const WebCore::ViewportAttributes&amp;);
+
+    void scrollBy(const WebCore::IntSize&amp;);
+    void scrollTo(const WebCore::IntPoint&amp;);
+
+    WebCore::FloatRect visibleContentsRect() const;
+    float pageScaleFactor() const { return m_pageScaleFactor; }
+
+private:
+
+    WebCore::FloatSize visibleContentsSize() const;
+
+    void syncVisibleContents();
+
+    void applyScaleAfterRenderingContents(float scale);
+    void applyPositionAfterRenderingContents(const WebCore::FloatPoint&amp; pos);
+
+    WebCore::FloatPoint boundContentsPosition(const WebCore::FloatPoint&amp;) const;
+    WebCore::FloatPoint boundContentsPositionAtScale(const WebCore::FloatPoint&amp;, float scale) const;
+
+    bool updateMinimumScaleToFit();
+    float innerBoundedViewportScale(float) const;
+
+    void resetViewportToDefaultState();
+
+    Client* m_client;
+
+    WebCore::FloatPoint m_contentsPosition;
+    WebCore::FloatSize m_contentsSize;
+    WebCore::FloatSize m_viewportSize;
+    float m_pageScaleFactor;
+
+    bool m_allowsUserScaling;
+    float m_minimumScaleToFit;
+    bool m_initiallyFitToViewport;
+
+    bool m_hasViewportAttribute;
+    WebCore::ViewportAttributes m_rawAttributes;
+};
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS_THREADED)
+
+#endif // SimpleViewportController_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadSafeCoordinatedSurfacecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,94 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+
+#if USE(COORDINATED_GRAPHICS)
+#include &quot;ThreadSafeCoordinatedSurface.h&quot;
+
+#include &lt;WebCore/TextureMapperGL.h&gt;
+#include &lt;wtf/StdLibExtras.h&gt;
+
+using namespace WebCore;
+
+namespace WebKit {
+
+PassRefPtr&lt;ThreadSafeCoordinatedSurface&gt; ThreadSafeCoordinatedSurface::create(const IntSize&amp; size, CoordinatedSurface::Flags flags)
+{
+    return adoptRef(new ThreadSafeCoordinatedSurface(size, flags, ImageBuffer::create(size)));
+}
+
+PassRefPtr&lt;ThreadSafeCoordinatedSurface&gt; ThreadSafeCoordinatedSurface::create(const IntSize&amp; size, CoordinatedSurface::Flags flags, std::unique_ptr&lt;ImageBuffer&gt; buffer)
+{
+    return adoptRef(new ThreadSafeCoordinatedSurface(size, flags, WTF::move(buffer)));
+}
+
+ThreadSafeCoordinatedSurface::ThreadSafeCoordinatedSurface(const IntSize&amp; size, CoordinatedSurface::Flags flags, std::unique_ptr&lt;ImageBuffer&gt; buffer)
+    : CoordinatedSurface(size, flags)
+    , m_imageBuffer(WTF::move(buffer))
+{
+}
+
+ThreadSafeCoordinatedSurface::~ThreadSafeCoordinatedSurface()
+{
+}
+
+void ThreadSafeCoordinatedSurface::paintToSurface(const IntRect&amp; rect, CoordinatedSurface::Client* client)
+{
+    ASSERT(client);
+
+    GraphicsContext* context = beginPaint(rect);
+    client-&gt;paintToSurfaceContext(context);
+    endPaint();
+}
+
+GraphicsContext* ThreadSafeCoordinatedSurface::beginPaint(const IntRect&amp; rect)
+{
+    ASSERT(m_imageBuffer);
+    GraphicsContext* graphicsContext = m_imageBuffer-&gt;context();
+    graphicsContext-&gt;save();
+    graphicsContext-&gt;clip(rect);
+    graphicsContext-&gt;translate(rect.x(), rect.y());
+    return graphicsContext;
+}
+
+void ThreadSafeCoordinatedSurface::endPaint()
+{
+    ASSERT(m_imageBuffer);
+    m_imageBuffer-&gt;context()-&gt;restore();
+}
+
+void ThreadSafeCoordinatedSurface::copyToTexture(PassRefPtr&lt;BitmapTexture&gt; passTexture, const IntRect&amp; target, const IntPoint&amp; sourceOffset)
+{
+    RefPtr&lt;BitmapTexture&gt; texture(passTexture);
+
+    ASSERT(m_imageBuffer);
+    RefPtr&lt;Image&gt; image = m_imageBuffer-&gt;copyImage(DontCopyBackingStore);
+    texture-&gt;updateContents(image.get(), target, sourceOffset, BitmapTexture::UpdateCanModifyOriginalImageData);
+}
+
+} // namespace WebCore
+
+#endif // USE(COORDINATED_GRAPHICS)
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadSafeCoordinatedSurfaceh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.h        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,61 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadSafeCoordinatedSurface_h
+#define ThreadSafeCoordinatedSurface_h
+
+#if USE(COORDINATED_GRAPHICS)
+#include &lt;WebCore/CoordinatedSurface.h&gt;
+#include &lt;WebCore/ImageBuffer.h&gt;
+
+namespace WebKit {
+
+class ThreadSafeCoordinatedSurface : public WebCore::CoordinatedSurface {
+public:
+    virtual ~ThreadSafeCoordinatedSurface();
+
+    // Create a new ThreadSafeCoordinatedSurface and allocate either a GraphicsSurface or a ImageBuffer as backing.
+    static PassRefPtr&lt;ThreadSafeCoordinatedSurface&gt; create(const WebCore::IntSize&amp;, WebCore::CoordinatedSurface::Flags);
+
+    virtual void paintToSurface(const WebCore::IntRect&amp;, WebCore::CoordinatedSurface::Client*) override;
+    virtual void copyToTexture(PassRefPtr&lt;WebCore::BitmapTexture&gt;, const WebCore::IntRect&amp; target, const WebCore::IntPoint&amp; sourceOffset) override;
+
+private:
+    ThreadSafeCoordinatedSurface(const WebCore::IntSize&amp;, WebCore::CoordinatedSurface::Flags, std::unique_ptr&lt;WebCore::ImageBuffer&gt;);
+
+    WebCore::GraphicsContext* beginPaint(const WebCore::IntRect&amp;);
+    void endPaint();
+
+    // Create a ThreadSafeCoordinatedSurface referencing an exisiting ImageBuffer
+    static PassRefPtr&lt;ThreadSafeCoordinatedSurface&gt; create(const WebCore::IntSize&amp;, WebCore::CoordinatedSurface::Flags, std::unique_ptr&lt;WebCore::ImageBuffer&gt;);
+
+    std::unique_ptr&lt;WebCore::ImageBuffer&gt; m_imageBuffer;
+};
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)
+
+#endif // ThreadSafeCoordinatedSurface_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadedCompositorcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,326 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include &quot;ThreadedCompositor.h&quot;
+
+#include &lt;WebCore/TransformationMatrix.h&gt;
+#include &lt;wtf/CurrentTime.h&gt;
+#include &lt;wtf/RunLoop.h&gt;
+#include &lt;wtf/StdLibExtras.h&gt;
+
+#if USE(OPENGL_ES_2)
+#include &lt;GLES2/gl2.h&gt;
+#else
+#include &lt;GL/gl.h&gt;
+#endif
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class CompositingRunLoop {
+    WTF_MAKE_NONCOPYABLE(CompositingRunLoop);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    CompositingRunLoop(std::function&lt;void()&gt; updateFunction)
+        : m_runLoop(RunLoop::current())
+        , m_updateTimer(m_runLoop, this, &amp;CompositingRunLoop::updateTimerFired)
+        , m_updateFunction(WTF::move(updateFunction))
+    {
+    }
+
+    void callOnCompositingRunLoop(std::function&lt;void()&gt; function)
+    {
+        if (&amp;m_runLoop == &amp;RunLoop::current()) {
+            function();
+            return;
+        }
+
+        m_runLoop.dispatch(WTF::move(function));
+    }
+
+    void setUpdateTimer(double interval = 0)
+    {
+        if (m_updateTimer.isActive())
+            return;
+
+        m_updateTimer.startOneShot(interval);
+    }
+
+    void stopUpdateTimer()
+    {
+        if (m_updateTimer.isActive())
+            m_updateTimer.stop();
+    }
+
+    RunLoop&amp; runLoop()
+    {
+        return m_runLoop;
+    }
+
+private:
+
+    void updateTimerFired()
+    {
+        m_updateFunction();
+    }
+
+    RunLoop&amp; m_runLoop;
+    RunLoop::Timer&lt;CompositingRunLoop&gt; m_updateTimer;
+    std::function&lt;void()&gt; m_updateFunction;
+};
+
+PassRefPtr&lt;ThreadedCompositor&gt; ThreadedCompositor::create(Client* client)
+{
+    return adoptRef(new ThreadedCompositor(client));
+}
+
+ThreadedCompositor::ThreadedCompositor(Client* client)
+    : m_client(client)
+    , m_scene(adoptRef(new CoordinatedGraphicsScene(this)))
+    , m_viewportController(std::make_unique&lt;SimpleViewportController&gt;(this))
+    , m_threadIdentifier(0)
+{
+    createCompositingThread();
+}
+
+ThreadedCompositor::~ThreadedCompositor()
+{
+    terminateCompositingThread();
+}
+
+void ThreadedCompositor::setNeedsDisplay()
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;scheduleDisplayIfNeeded();
+    });
+}
+
+void ThreadedCompositor::setNativeSurfaceHandleForCompositing(uint64_t handle)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;m_nativeSurfaceHandle = handle;
+        protector-&gt;m_scene-&gt;setActive(true);
+    });
+}
+
+
+void ThreadedCompositor::didChangeViewportSize(const IntSize&amp; newSize)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;viewportController()-&gt;didChangeViewportSize(newSize);
+    });
+}
+
+void ThreadedCompositor::didChangeViewportAttribute(const ViewportAttributes&amp; attr)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;viewportController()-&gt;didChangeViewportAttribute(attr);
+    });
+}
+
+void ThreadedCompositor::didChangeContentsSize(const IntSize&amp; size)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;viewportController()-&gt;didChangeContentsSize(size);
+    });
+}
+
+void ThreadedCompositor::scrollTo(const IntPoint&amp; position)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;viewportController()-&gt;scrollTo(position);
+    });
+}
+
+void ThreadedCompositor::scrollBy(const IntSize&amp; delta)
+{
+    RefPtr&lt;ThreadedCompositor&gt; protector(this);
+    callOnCompositingThread([=] {
+        protector-&gt;viewportController()-&gt;scrollBy(delta);
+    });
+}
+
+void ThreadedCompositor::purgeBackingStores()
+{
+    m_client-&gt;purgeBackingStores();
+}
+
+void ThreadedCompositor::renderNextFrame()
+{
+    m_client-&gt;renderNextFrame();
+}
+
+void ThreadedCompositor::updateViewport()
+{
+    setNeedsDisplay();
+}
+
+void ThreadedCompositor::commitScrollOffset(uint32_t layerID, const IntSize&amp; offset)
+{
+    m_client-&gt;commitScrollOffset(layerID, offset);
+}
+
+bool ThreadedCompositor::ensureGLContext()
+{
+    if (!glContext())
+        return false;
+
+    glContext()-&gt;makeContextCurrent();
+    // The window size may be out of sync with the page size at this point, and getting
+    // the viewport parameters incorrect, means that the content will be misplaced. Thus
+    // we set the viewport parameters directly from the window size.
+    IntSize contextSize = glContext()-&gt;defaultFrameBufferSize();
+    if (m_viewportSize != contextSize) {
+        glViewport(0, 0, contextSize.width(), contextSize.height());
+        m_viewportSize = contextSize;
+    }
+
+    return true;
+}
+
+GLContext* ThreadedCompositor::glContext()
+{
+    if (m_context)
+        return m_context.get();
+
+    if (!m_nativeSurfaceHandle)
+        return 0;
+
+    m_context = GLContext::createContextForWindow(m_nativeSurfaceHandle, GLContext::sharingContext());
+    return m_context.get();
+}
+
+void ThreadedCompositor::scheduleDisplayIfNeeded(double interval)
+{
+    m_compositingRunLoop-&gt;setUpdateTimer(interval);
+}
+
+void ThreadedCompositor::didChangeVisibleRect()
+{
+    FloatRect visibleRect = viewportController()-&gt;visibleContentsRect();
+    float scale = viewportController()-&gt;pageScaleFactor();
+    callOnMainThread([=] {
+        m_client-&gt;setVisibleContentsRect(visibleRect, FloatPoint::zero(), scale);
+    });
+
+    setNeedsDisplay();
+}
+
+void ThreadedCompositor::renderLayerTree()
+{
+    if (!m_scene)
+        return;
+
+    if (!ensureGLContext())
+        return;
+
+    FloatRect clipRect(0, 0, m_viewportSize.width(), m_viewportSize.height());
+
+    TransformationMatrix viewportTransform;
+    FloatPoint scrollPostion = viewportController()-&gt;visibleContentsRect().location();
+    viewportTransform.scale(viewportController()-&gt;pageScaleFactor());
+    viewportTransform.translate(-scrollPostion.x(), -scrollPostion.y());
+
+    m_scene-&gt;paintToCurrentGLContext(viewportTransform, 1, clipRect, Color::white, false, scrollPostion);
+
+    glContext()-&gt;swapBuffers();
+}
+
+void ThreadedCompositor::updateSceneState(const CoordinatedGraphicsState&amp; state)
+{
+    m_scene-&gt;appendUpdate(bind(&amp;CoordinatedGraphicsScene::commitSceneState, m_scene.get(), state));
+    setNeedsDisplay();
+}
+
+void ThreadedCompositor::callOnCompositingThread(std::function&lt;void()&gt; function)
+{
+    m_compositingRunLoop-&gt;callOnCompositingRunLoop(WTF::move(function));
+}
+
+void ThreadedCompositor::compositingThreadEntry(void* coordinatedCompositor)
+{
+    static_cast&lt;ThreadedCompositor*&gt;(coordinatedCompositor)-&gt;runCompositingThread();
+}
+
+void ThreadedCompositor::createCompositingThread()
+{
+    if (m_threadIdentifier)
+        return;
+
+    MutexLocker locker(m_initializeRunLoopConditionMutex);
+    m_threadIdentifier = createThread(compositingThreadEntry, this, &quot;WebCore: ThreadedCompositor&quot;);
+
+    m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex);
+}
+
+void ThreadedCompositor::runCompositingThread()
+{
+    {
+        MutexLocker locker(m_initializeRunLoopConditionMutex);
+
+        m_compositingRunLoop = std::make_unique&lt;CompositingRunLoop&gt;([&amp;] {
+            renderLayerTree();
+        });
+
+        m_initializeRunLoopCondition.signal();
+    }
+
+    m_compositingRunLoop-&gt;runLoop().run();
+
+    m_compositingRunLoop-&gt;stopUpdateTimer();
+    m_scene-&gt;purgeGLResources();
+
+    {
+        MutexLocker locker(m_terminateRunLoopConditionMutex);
+        m_compositingRunLoop = nullptr;
+        m_context.clear();
+        m_terminateRunLoopCondition.signal();
+    }
+
+    detachThread(m_threadIdentifier);
+}
+
+void ThreadedCompositor::terminateCompositingThread()
+{
+    MutexLocker locker(m_terminateRunLoopConditionMutex);
+
+    m_scene-&gt;detach();
+    m_compositingRunLoop-&gt;runLoop().stop();
+
+    m_terminateRunLoopCondition.wait(m_terminateRunLoopConditionMutex);
+}
+
+}
+#endif // USE(COORDINATED_GRAPHICS_THREADED)
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedCoordinatedGraphicsthreadedcompositorThreadedCompositorh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h (0 => 177276)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h                                (rev 0)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h        2014-12-15 10:39:49 UTC (rev 177276)
</span><span class="lines">@@ -0,0 +1,123 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadedCompositor_h
+#define ThreadedCompositor_h
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+
+#include &quot;CoordinatedGraphicsScene.h&quot;
+#include &quot;SimpleViewportController.h&quot;
+#include &lt;WebCore/GLContext.h&gt;
+#include &lt;WebCore/IntSize.h&gt;
+#include &lt;WebCore/TransformationMatrix.h&gt;
+#include &lt;wtf/FastMalloc.h&gt;
+#include &lt;wtf/Noncopyable.h&gt;
+#include &lt;wtf/ThreadSafeRefCounted.h&gt;
+#include &lt;wtf/Threading.h&gt;
+
+namespace WebCore {
+class CoordinatedGraphicsState;
+}
+
+namespace WebKit {
+class CoordinatedGraphicsScene;
+class CoordinatedGraphicsSceneClient;
+
+class CompositingRunLoop;
+
+class ThreadedCompositor : public SimpleViewportController::Client, public CoordinatedGraphicsSceneClient, public ThreadSafeRefCounted&lt;ThreadedCompositor&gt; {
+    WTF_MAKE_NONCOPYABLE(ThreadedCompositor);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    class Client {
+    public:
+        virtual void setVisibleContentsRect(const WebCore::FloatRect&amp;, const WebCore::FloatPoint&amp;, float) = 0;
+        virtual void purgeBackingStores() = 0;
+        virtual void renderNextFrame() = 0;
+        virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize&amp; offset) = 0;
+    };
+
+    static PassRefPtr&lt;ThreadedCompositor&gt; create(Client*);
+    virtual ~ThreadedCompositor();
+
+    void setNeedsDisplay();
+
+    void setNativeSurfaceHandleForCompositing(uint64_t);
+
+    void updateSceneState(const WebCore::CoordinatedGraphicsState&amp;);
+
+    void didChangeViewportSize(const WebCore::IntSize&amp;);
+    void didChangeViewportAttribute(const WebCore::ViewportAttributes&amp;);
+    void didChangeContentsSize(const WebCore::IntSize&amp;);
+    void scrollTo(const WebCore::IntPoint&amp;);
+    void scrollBy(const WebCore::IntSize&amp;);
+
+private:
+    ThreadedCompositor(Client*);
+
+    // CoordinatedGraphicsSceneClient
+    virtual void purgeBackingStores() override;
+    virtual void renderNextFrame() override;
+    virtual void updateViewport() override;
+    virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize&amp; offset) override;
+
+    void renderLayerTree();
+    void scheduleDisplayIfNeeded(double interval = 0);
+    virtual void didChangeVisibleRect() override;
+
+    bool ensureGLContext();
+    WebCore::GLContext* glContext();
+    SimpleViewportController* viewportController() { return m_viewportController.get(); }
+
+    void callOnCompositingThread(std::function&lt;void()&gt;);
+    void createCompositingThread();
+    void runCompositingThread();
+    void terminateCompositingThread();
+    static void compositingThreadEntry(void*);
+
+    Client* m_client;
+    RefPtr&lt;CoordinatedGraphicsScene&gt; m_scene;
+    std::unique_ptr&lt;SimpleViewportController&gt; m_viewportController;
+
+    OwnPtr&lt;WebCore::GLContext&gt; m_context;
+
+    WebCore::IntSize m_viewportSize;
+    uint64_t m_nativeSurfaceHandle;
+
+    std::unique_ptr&lt;CompositingRunLoop&gt; m_compositingRunLoop;
+
+    ThreadIdentifier m_threadIdentifier;
+    ThreadCondition m_initializeRunLoopCondition;
+    Mutex m_initializeRunLoopConditionMutex;
+    ThreadCondition m_terminateRunLoopCondition;
+    Mutex m_terminateRunLoopConditionMutex;
+};
+
+} // namespace WebKit
+
+#endif
+
+#endif // ThreadedCompositor_h
</ins></span></pre>
</div>
</div>

</body>
</html>