2011-05-17 Nat Duca <nduca@chromium.org>
authornduca@chromium.org <nduca@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jun 2011 19:29:16 +0000 (19:29 +0000)
committernduca@chromium.org <nduca@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jun 2011 19:29:16 +0000 (19:29 +0000)
        Reviewed by James Robinson.

        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
        https://bugs.webkit.org/show_bug.cgi?id=58408

        Create CCLayerTreeHost and CCLayerTreeHostImpl, which are the main
        thread and compositor thread halves of a composited view. Communication
        between the two is based on the design used in FileStreamProxy.

        * WebCore.gypi:
        * platform/chromium/TraceEvent.h:
        * platform/graphics/chromium/LayerRendererChromium.cpp:
        (WebCore::LayerRendererChromium::create):
        (WebCore::LayerRendererChromium::LayerRendererChromium):
        (WebCore::LayerRendererChromium::setViewport):
        (WebCore::LayerRendererChromium::updateLayers):
        (WebCore::LayerRendererChromium::drawLayers):
        (WebCore::LayerRendererChromiumImpl::create):
        (WebCore::LayerRendererChromiumImpl::drawLayersAndPresent):
        (WebCore::LayerRendererChromiumImpl::LayerRendererChromiumImpl):
        (WebCore::LayerRendererChromiumImpl::drawLayersOnMainThread):
        (WebCore::LayerRendererChromiumImplProxy::create):
        (WebCore::LayerRendererChromiumImplProxy::createLayerTreeHostImpl):
        (WebCore::LayerRendererChromiumImplProxy::LayerRendererChromiumImplProxy):
        (WebCore::LayerRendererChromium::createLayerTreeHostImplProxy):
        * platform/graphics/chromium/LayerRendererChromium.h:
        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
        (WebCore::CCHeadsUpDisplay::setShowFPSCounter):
        (WebCore::CCHeadsUpDisplay::setShowPlatformLayerTree):
        * platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
        (WebCore::CCHeadsUpDisplay::currentFrameNumber):
        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
        (WebCore::CCLayerTreeHost::CCLayerTreeHost):
        (WebCore::CCLayerTreeHost::init):
        (WebCore::CCLayerTreeHost::~CCLayerTreeHost):
        (WebCore::CCLayerTreeHost::beginCommit):
        (WebCore::CCLayerTreeHost::commitComplete):
        (WebCore::CCLayerTreeHost::animateAndLayout):
        (WebCore::CCLayerTreeHost::createLayerTreeHostCommitter):
        (WebCore::CCLayerTreeHost::setNeedsCommitAndRedraw):
        (WebCore::CCLayerTreeHost::setNeedsRedraw):
        (WebCore::CCLayerTreeHost::updateLayers):
        * platform/graphics/chromium/cc/CCLayerTreeHost.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
        (WebCore::CCLayerTreeHost::frameNumber):
        * platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
        (WebCore::CCLayerTreeHostCommitter::create):
        (WebCore::CCLayerTreeHostCommitter::commit):
        * platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
        (WebCore::CCLayerTreeHostCommitter::CCLayerTreeHostCommitter):
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp: Added.
        (WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
        (WebCore::CCLayerTreeHostImpl::~CCLayerTreeHostImpl):
        (WebCore::CCLayerTreeHostImpl::beginCommit):
        (WebCore::CCLayerTreeHostImpl::commitComplete):
        (WebCore::CCLayerTreeHostImpl::drawLayers):
        (WebCore::CCLayerTreeHostImpl::setNeedsCommitAndRedraw):
        (WebCore::CCLayerTreeHostImpl::setNeedsRedraw):
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
        (WebCore::CCLayerTreeHostImplClient::~CCLayerTreeHostImplClient):
        (WebCore::CCLayerTreeHostImpl::frameNumber):
        (WebCore::CCLayerTreeHostImpl::sourceFrameNumber):
        (WebCore::CCLayerTreeHostImpl::setSourceFrameNumber):
        * platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp: Added.
        (WebCore::CCLayerTreeHostImplProxy::CCLayerTreeHostImplProxy):
        (WebCore::CCLayerTreeHostImplProxy::start):
        (WebCore::CCLayerTreeHostImplProxy::~CCLayerTreeHostImplProxy):
        (WebCore::CCLayerTreeHostImplProxy::isStarted):
        (WebCore::CCLayerTreeHostImplProxy::setNeedsCommitAndRedraw):
        (WebCore::CCLayerTreeHostImplProxy::setNeedsRedraw):
        (WebCore::CCLayerTreeHostImplProxy::stop):
        (WebCore::CCLayerTreeHostImplProxy::postDrawLayersTaskOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::requestFrameAndCommitOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::isMainThread):
        (WebCore::CCLayerTreeHostImplProxy::isCCThread):
        (WebCore::CCLayerTreeHostImplProxy::requestFrameAndCommit):
        (WebCore::CCLayerTreeHostImplProxy::commitOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::drawLayersOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::setNeedsCommitAndRedrawOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::setNeedsRedrawOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::initImplOnCCThread):
        (WebCore::CCLayerTreeHostImplProxy::layerTreeHostClosedOnCCThread):
        * platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h: Added.
        (WebCore::CCLayerTreeHostImplProxy::host):
        * platform/graphics/chromium/cc/CCMainThreadTask.h:
        * platform/graphics/chromium/cc/CCThread.cpp:
        (WebCore::CCThread::runLoop):
        * platform/graphics/chromium/cc/CCThreadTask.h:
2011-05-17  Nat Duca  <nduca@chromium.org>

        Reviewed by James Robinson.

        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
        https://bugs.webkit.org/show_bug.cgi?id=58408

        Redirect invalidates and scheduling into compositor when in
        threaded compositing mode. Add stress tests for CCLayerTreeHost.

        * WebKit.gypi:
        * public/WebWidget.h:
        * src/WebPopupMenuImpl.cpp:
        (WebKit::WebPopupMenuImpl::animate):
        * src/WebPopupMenuImpl.h:
        * src/WebViewImpl.cpp:
        (WebKit::WebViewImpl::animate):
        (WebKit::WebViewImpl::paint):
        (WebKit::WebViewImpl::animateAndLayout):
        (WebKit::WebViewImpl::updateLayers):
        (WebKit::WebViewImpl::composite):
        (WebKit::WebViewImpl::setRootLayerNeedsDisplay):
        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
        (WebKit::WebViewImpl::doComposite):
        (WebKit::WebViewImpl::createLayerTreeHostContext3D):
        (WebKit::WebViewImpl::reallocateRenderer):
        (WebKit::WebViewImpl::updateLayerRendererSettings):
        (WebKit::WebViewImpl::updateLayerRendererViewport):
        * src/WebViewImpl.h:
        * tests/CCLayerTreeHostTest.cpp: Added.
        (WTF::CCLayerTreeHostTest::CCLayerTreeHostTest):
        (WTF::CCLayerTreeHostTest::animateAndLayout):
        (WTF::CCLayerTreeHostTest::beginCommitOnCCThread):
        (WTF::CCLayerTreeHostTest::beginCommitOnMainThread):
        (WTF::CCLayerTreeHostTest::commitOnCCThread):
        (WTF::CCLayerTreeHostTest::commitCompleteOnCCThread):
        (WTF::CCLayerTreeHostTest::commitCompleteOnMainThread):
        (WTF::CCLayerTreeHostTest::drawLayersAndPresentOnCCThread):
        (WTF::CCLayerTreeHostTest::updateLayers):
        (WTF::CCLayerTreeHostTest::onBeginTest):
        (WTF::CCLayerTreeHostTest::doEndTest):
        (WTF::CCLayerTreeHostTest::onEndTest):
        (WTF::CCLayerTreeHostTest::runTest):
        (WTF::CCLayerTreeHostTest::testTimeout):
        (WTF::MockLayerTreeHostClient::MockLayerTreeHostClient):
        (WTF::MockLayerTreeHostClient::createLayerTreeHostContext3D):
        (WTF::MockLayerTreeHostClient::animateAndLayout):
        (WTF::MockLayerTreeHostClient::updateLayers):
        (WTF::MockLayerTreeHostCommitter::create):
        (WTF::MockLayerTreeHostCommitter::commit):
        (WTF::MockLayerTreeHostCommitter::MockLayerTreeHostCommitter):
        (WTF::MockLayerTreeHostImpl::create):
        (WTF::MockLayerTreeHostImpl::beginCommit):
        (WTF::MockLayerTreeHostImpl::commitComplete):
        (WTF::MockLayerTreeHostImpl::drawLayersAndPresent):
        (WTF::MockLayerTreeHostImpl::MockLayerTreeHostImpl):
        (WTF::MockLayerTreeHostImplProxy::create):
        (WTF::MockLayerTreeHostImplProxy::createLayerTreeHostImpl):
        (WTF::MockLayerTreeHostImplProxy::MockLayerTreeHostImplProxy):
        (WTF::MockLayerTreeHost::MockLayerTreeHost):
        (WTF::MockLayerTreeHost::createLayerTreeHostImplProxy):
        (WTF::MockLayerTreeHost::updateLayers):
        (WTF::MockLayerTreeHost::createLayerTreeHostCommitter):
        (WTF::MockLayerTreeHost::beginCommit):
        (WTF::MockLayerTreeHost::commitComplete):
        (WTF::CCLayerTreeHostTest::doBeginTest):
        (WTF::CCLayerTreeHostTest::endTest):
        (WTF::CCLayerTreeHostTestShortlived1::CCLayerTreeHostTestShortlived1):
        (WTF::CCLayerTreeHostTestShortlived1::beginTest):
        (WTF::CCLayerTreeHostTestShortlived1::afterTest):
        (WTF::TEST_F):
        (WTF::CCLayerTreeHostTestShortlived2::CCLayerTreeHostTestShortlived2):
        (WTF::CCLayerTreeHostTestShortlived2::beginTest):
        (WTF::CCLayerTreeHostTestShortlived2::afterTest):
        (WTF::CCLayerTreeHostTestShortlived3::CCLayerTreeHostTestShortlived3):
        (WTF::CCLayerTreeHostTestShortlived3::beginTest):
        (WTF::CCLayerTreeHostTestShortlived3::afterTest):
        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::CCLayerTreeHostTestCommitingWithContinuousRedraw):
        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest):
        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread):
        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersAndPresentOnCCThread):
        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::afterTest):
        (WTF::CCLayerTreeHostTestSetNeedsCommit1::CCLayerTreeHostTestSetNeedsCommit1):
        (WTF::CCLayerTreeHostTestSetNeedsCommit1::beginTest):
        (WTF::CCLayerTreeHostTestSetNeedsCommit1::drawLayersAndPresentOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsCommit1::commitOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsCommit1::afterTest):
        (WTF::CCLayerTreeHostTestSetNeedsCommit2::CCLayerTreeHostTestSetNeedsCommit2):
        (WTF::CCLayerTreeHostTestSetNeedsCommit2::beginTest):
        (WTF::CCLayerTreeHostTestSetNeedsCommit2::drawLayersAndPresentOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsCommit2::commitOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsCommit2::afterTest):
        (WTF::CCLayerTreeHostTestSetNeedsRedraw::CCLayerTreeHostTestSetNeedsRedraw):
        (WTF::CCLayerTreeHostTestSetNeedsRedraw::beginTest):
        (WTF::CCLayerTreeHostTestSetNeedsRedraw::drawLayersAndPresentOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsRedraw::commitOnCCThread):
        (WTF::CCLayerTreeHostTestSetNeedsRedraw::afterTest):
        * tests/CCThreadTest.cpp:
        (WebCore::TEST):
2011-05-17  Nat Duca  <nduca@chromium.org>

        Reviewed by James Robinson.

        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
        https://bugs.webkit.org/show_bug.cgi?id=58408

        * DumpRenderTree/chromium/WebViewHost.cpp:
        (WebViewHost::paintInvalidatedRegion):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@89694 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp
Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCMainThreadTask.h
Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp
Source/WebCore/platform/graphics/chromium/cc/CCThreadTask.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/public/WebWidget.h
Source/WebKit/chromium/src/WebPopupMenuImpl.cpp
Source/WebKit/chromium/src/WebPopupMenuImpl.h
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/src/WebViewImpl.h
Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/CCThreadTest.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/WebViewHost.cpp

index ef1945c..09c4637 100644 (file)
@@ -1,3 +1,93 @@
+2011-05-17  Nat Duca  <nduca@chromium.org>
+
+        Reviewed by James Robinson.
+
+        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
+        https://bugs.webkit.org/show_bug.cgi?id=58408
+
+        Create CCLayerTreeHost and CCLayerTreeHostImpl, which are the main
+        thread and compositor thread halves of a composited view. Communication
+        between the two is based on the design used in FileStreamProxy.
+
+        * WebCore.gypi:
+        * platform/chromium/TraceEvent.h:
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::create):
+        (WebCore::LayerRendererChromium::LayerRendererChromium):
+        (WebCore::LayerRendererChromium::setViewport):
+        (WebCore::LayerRendererChromium::updateLayers):
+        (WebCore::LayerRendererChromium::drawLayers):
+        (WebCore::LayerRendererChromiumImpl::create):
+        (WebCore::LayerRendererChromiumImpl::drawLayersAndPresent):
+        (WebCore::LayerRendererChromiumImpl::LayerRendererChromiumImpl):
+        (WebCore::LayerRendererChromiumImpl::drawLayersOnMainThread):
+        (WebCore::LayerRendererChromiumImplProxy::create):
+        (WebCore::LayerRendererChromiumImplProxy::createLayerTreeHostImpl):
+        (WebCore::LayerRendererChromiumImplProxy::LayerRendererChromiumImplProxy):
+        (WebCore::LayerRendererChromium::createLayerTreeHostImplProxy):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
+        (WebCore::CCHeadsUpDisplay::setShowFPSCounter):
+        (WebCore::CCHeadsUpDisplay::setShowPlatformLayerTree):
+        * platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
+        (WebCore::CCHeadsUpDisplay::currentFrameNumber):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
+        (WebCore::CCLayerTreeHost::CCLayerTreeHost):
+        (WebCore::CCLayerTreeHost::init):
+        (WebCore::CCLayerTreeHost::~CCLayerTreeHost):
+        (WebCore::CCLayerTreeHost::beginCommit):
+        (WebCore::CCLayerTreeHost::commitComplete):
+        (WebCore::CCLayerTreeHost::animateAndLayout):
+        (WebCore::CCLayerTreeHost::createLayerTreeHostCommitter):
+        (WebCore::CCLayerTreeHost::setNeedsCommitAndRedraw):
+        (WebCore::CCLayerTreeHost::setNeedsRedraw):
+        (WebCore::CCLayerTreeHost::updateLayers):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
+        (WebCore::CCLayerTreeHost::frameNumber):
+        * platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
+        (WebCore::CCLayerTreeHostCommitter::create):
+        (WebCore::CCLayerTreeHostCommitter::commit):
+        * platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
+        (WebCore::CCLayerTreeHostCommitter::CCLayerTreeHostCommitter):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp: Added.
+        (WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
+        (WebCore::CCLayerTreeHostImpl::~CCLayerTreeHostImpl):
+        (WebCore::CCLayerTreeHostImpl::beginCommit):
+        (WebCore::CCLayerTreeHostImpl::commitComplete):
+        (WebCore::CCLayerTreeHostImpl::drawLayers):
+        (WebCore::CCLayerTreeHostImpl::setNeedsCommitAndRedraw):
+        (WebCore::CCLayerTreeHostImpl::setNeedsRedraw):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCThread.cpp.
+        (WebCore::CCLayerTreeHostImplClient::~CCLayerTreeHostImplClient):
+        (WebCore::CCLayerTreeHostImpl::frameNumber):
+        (WebCore::CCLayerTreeHostImpl::sourceFrameNumber):
+        (WebCore::CCLayerTreeHostImpl::setSourceFrameNumber):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp: Added.
+        (WebCore::CCLayerTreeHostImplProxy::CCLayerTreeHostImplProxy):
+        (WebCore::CCLayerTreeHostImplProxy::start):
+        (WebCore::CCLayerTreeHostImplProxy::~CCLayerTreeHostImplProxy):
+        (WebCore::CCLayerTreeHostImplProxy::isStarted):
+        (WebCore::CCLayerTreeHostImplProxy::setNeedsCommitAndRedraw):
+        (WebCore::CCLayerTreeHostImplProxy::setNeedsRedraw):
+        (WebCore::CCLayerTreeHostImplProxy::stop):
+        (WebCore::CCLayerTreeHostImplProxy::postDrawLayersTaskOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::requestFrameAndCommitOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::isMainThread):
+        (WebCore::CCLayerTreeHostImplProxy::isCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::requestFrameAndCommit):
+        (WebCore::CCLayerTreeHostImplProxy::commitOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::drawLayersOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::setNeedsCommitAndRedrawOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::setNeedsRedrawOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::initImplOnCCThread):
+        (WebCore::CCLayerTreeHostImplProxy::layerTreeHostClosedOnCCThread):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h: Added.
+        (WebCore::CCLayerTreeHostImplProxy::host):
+        * platform/graphics/chromium/cc/CCMainThreadTask.h:
+        * platform/graphics/chromium/cc/CCThread.cpp:
+        (WebCore::CCThread::runLoop):
+        * platform/graphics/chromium/cc/CCThreadTask.h:
+
 2011-06-24  Adrienne Walker  <enne@google.com>
 
         Unreviewed, remove assertion about root layers in RenderLayerBacking.
index 8f99bac..7f8def1 100644 (file)
             'platform/graphics/chromium/cc/CCLayerImpl.h',
             'platform/graphics/chromium/cc/CCLayerSorter.cpp',
             'platform/graphics/chromium/cc/CCLayerSorter.h',
+            'platform/graphics/chromium/cc/CCLayerTreeHost.cpp',
+            'platform/graphics/chromium/cc/CCLayerTreeHost.h',
+            'platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp',
+            'platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h',
+            'platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp',
+            'platform/graphics/chromium/cc/CCLayerTreeHostImpl.h',
+            'platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp',
+            'platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h',
             'platform/graphics/chromium/cc/CCMainThread.cpp',
             'platform/graphics/chromium/cc/CCMainThread.h',
             'platform/graphics/chromium/cc/CCMainThreadTask.h',
index 9656ad3..fd3de6b 100644 (file)
@@ -50,6 +50,8 @@
 #include "TraceEvent.h"
 #include "WebGLLayerChromium.h"
 #include "cc/CCLayerImpl.h"
+#include "cc/CCLayerTreeHostImpl.h"
+#include "cc/CCMainThreadTask.h"
 #if USE(SKIA)
 #include "Extensions3D.h"
 #include "GrContext.h"
@@ -98,22 +100,26 @@ static bool isScaleOrTranslation(const TransformationMatrix& m)
 
 }
 
-PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing)
+PassRefPtr<LayerRendererChromium> LayerRendererChromium::create(CCLayerTreeHostClient* client, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing)
 {
+    RefPtr<GraphicsContext3D> context = client->createLayerTreeHostContext3D();
     if (!context)
         return 0;
 
-    RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(context, contentPaint, accelerateDrawing)));
+    RefPtr<LayerRendererChromium> layerRenderer(adoptRef(new LayerRendererChromium(client, context, contentPaint, accelerateDrawing)));
+    layerRenderer->init();
     if (!layerRenderer->hardwareCompositing())
         return 0;
 
     return layerRenderer.release();
 }
 
-LayerRendererChromium::LayerRendererChromium(PassRefPtr<GraphicsContext3D> context,
+LayerRendererChromium::LayerRendererChromium(CCLayerTreeHostClient* client,
+                                             PassRefPtr<GraphicsContext3D> context,
                                              PassOwnPtr<LayerPainterChromium> contentPaint,
                                              bool accelerateDrawing)
-    : m_viewportScrollPosition(IntPoint(-1, -1))
+    : CCLayerTreeHost(client)
+    , m_viewportScrollPosition(IntPoint(-1, -1))
     , m_rootLayer(0)
     , m_accelerateDrawing(false)
     , m_currentRenderSurface(0)
@@ -223,10 +229,12 @@ void LayerRendererChromium::setViewport(const IntRect& visibleRect, const IntRec
         m_currentRenderSurface = 0;
         m_rootLayerContentTiler->invalidateEntireLayer();
     }
+    setNeedsCommitAndRedraw();
 }
 
-void LayerRendererChromium::updateAndDrawLayers()
+void LayerRendererChromium::updateLayers()
 {
+    CCLayerTreeHost::updateLayers();
     if (m_viewportVisibleRect.isEmpty())
         return;
 
@@ -251,9 +259,14 @@ void LayerRendererChromium::updateAndDrawLayers()
         m_rootCCLayerImpl = TreeSynchronizer::synchronizeTrees(m_rootLayer.get(), m_rootCCLayerImpl.get());
     }
 
-    LayerList renderSurfaceLayerList;
-    updateLayers(renderSurfaceLayerList);
+    m_computedRenderSurfaceLayerList = adoptPtr(new LayerList());
+    updateLayers(*m_computedRenderSurfaceLayerList);
+}
 
+void LayerRendererChromium::drawLayers()
+{
+    ASSERT(m_hardwareCompositing);
+    ASSERT(m_computedRenderSurfaceLayerList);
     // Before drawLayers:
     if (hardwareCompositing() && m_contextSupportsLatch) {
         // FIXME: The multithreaded compositor case will not work as long as
@@ -276,7 +289,7 @@ void LayerRendererChromium::updateAndDrawLayers()
         }
     }
 
-    drawLayers(renderSurfaceLayerList);
+    drawLayers(*m_computedRenderSurfaceLayerList);
 
     m_textureManager->unprotectAllTextures();
 
@@ -1265,6 +1278,74 @@ void LayerRendererChromium::dumpRenderSurfaces(TextStream& ts, int indent, Layer
         dumpRenderSurfaces(ts, indent, layer->children()[i].get());
 }
 
+class LayerRendererChromiumImpl : public CCLayerTreeHostImpl {
+public:
+    static PassOwnPtr<LayerRendererChromiumImpl> create(CCLayerTreeHostImplClient* client, LayerRendererChromium* layerRenderer)
+    {
+        return adoptPtr(new LayerRendererChromiumImpl(client, layerRenderer));
+    }
+
+    virtual void drawLayersAndPresent()
+    {
+        CCCompletionEvent completion;
+        bool contextLost;
+        CCMainThread::postTask(createMainThreadTask(this, &LayerRendererChromiumImpl::drawLayersOnMainThread, AllowCrossThreadAccess(&completion), AllowCrossThreadAccess(&contextLost)));
+        completion.wait();
+
+        // FIXME: Send the "UpdateRect" message up to the RenderWidget [or moveplugin equivalents...]
+
+        // FIXME: handle context lost
+        if (contextLost)
+            FATAL("LayerRendererChromiumImpl does not handle context lost yet.");
+    }
+
+private:
+    LayerRendererChromiumImpl(CCLayerTreeHostImplClient* client, LayerRendererChromium* layerRenderer)
+        : CCLayerTreeHostImpl(client)
+        , m_layerRenderer(layerRenderer) { }
+
+    void drawLayersOnMainThread(CCCompletionEvent* completion, bool* contextLost)
+    {
+        ASSERT(isMainThread());
+
+        if (m_layerRenderer->rootLayer()) {
+            m_layerRenderer->drawLayers();
+            m_layerRenderer->present();
+
+            GraphicsContext3D* context = m_layerRenderer->context();
+            *contextLost = context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
+        } else
+            *contextLost = false;
+        completion->signal();
+    }
+
+    LayerRendererChromium* m_layerRenderer;
+};
+
+class LayerRendererChromiumImplProxy : public CCLayerTreeHostImplProxy {
+public:
+    static PassOwnPtr<LayerRendererChromiumImplProxy> create(LayerRendererChromium* layerRenderer)
+    {
+        return adoptPtr(new LayerRendererChromiumImplProxy(layerRenderer));
+    }
+
+    virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
+    {
+        return LayerRendererChromiumImpl::create(this, static_cast<LayerRendererChromium*>(host()));
+    }
+
+private:
+    LayerRendererChromiumImplProxy(LayerRendererChromium* layerRenderer)
+        : CCLayerTreeHostImplProxy(layerRenderer) { }
+};
+
+PassOwnPtr<CCLayerTreeHostImplProxy> LayerRendererChromium::createLayerTreeHostImplProxy()
+{
+    OwnPtr<CCLayerTreeHostImplProxy> proxy = LayerRendererChromiumImplProxy::create(this);
+    proxy->start();
+    return proxy.release();
+}
+
 } // namespace WebCore
 
 #endif // USE(ACCELERATED_COMPOSITING)
index f5f2f3c..c9485c8 100644 (file)
 #include "cc/CCCanvasLayerImpl.h"
 #include "cc/CCHeadsUpDisplay.h"
 #include "cc/CCLayerSorter.h"
+#include "cc/CCLayerTreeHost.h"
 #include "cc/CCPluginLayerImpl.h"
 #include "cc/CCVideoLayerImpl.h"
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
 #if USE(CG)
@@ -66,14 +66,16 @@ namespace WebCore {
 
 class CCHeadsUpDisplay;
 class CCLayerImpl;
+class CCLayerTreeHostCommitter;
+class CCLayerTreeHostImpl;
 class GeometryBinding;
 class GraphicsContext3D;
 class LayerPainterChromium;
 
 // Class that handles drawing of composited render layers using GL.
-class LayerRendererChromium : public RefCounted<LayerRendererChromium> {
+class LayerRendererChromium : public CCLayerTreeHost {
 public:
-    static PassRefPtr<LayerRendererChromium> create(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing);
+    static PassRefPtr<LayerRendererChromium> create(CCLayerTreeHostClient*, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing);
 
     ~LayerRendererChromium();
 
@@ -88,7 +90,8 @@ public:
     void setViewport(const IntRect& visibleRect, const IntRect& contentRect, const IntPoint& scrollPosition);
 
     // updates and draws the current layers onto the backbuffer
-    void updateAndDrawLayers();
+    virtual void updateLayers();
+    void drawLayers();
 
     // Set by WebViewImpl when animation callbacks are running.
     // FIXME: When we move scheduling into the compositor, we can remove this flag.
@@ -156,14 +159,17 @@ public:
 #ifndef NDEBUG
     static bool s_inPaintLayerContents;
 #endif
+protected:
+    virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy();
+
 private:
     typedef Vector<RefPtr<CCLayerImpl> > LayerList;
     typedef HashMap<GraphicsContext3D*, int> ChildContextMap;
 
-    // FIXME: This needs to be moved to the CCViewImpl when that class exists.
+    // FIXME: This needs to be moved to the CCLayerTreeHostImpl when that class exists.
     RefPtr<CCLayerImpl> m_rootCCLayerImpl;
 
-    LayerRendererChromium(PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing);
+    LayerRendererChromium(CCLayerTreeHostClient*, PassRefPtr<GraphicsContext3D>, PassOwnPtr<LayerPainterChromium> contentPaint, bool accelerateDrawing);
 
     void updateLayers(LayerList& renderSurfaceLayerList);
     void updateRootLayerContents();
@@ -210,6 +216,8 @@ private:
     bool m_hardwareCompositing;
     bool m_accelerateDrawing;
 
+    OwnPtr<LayerList> m_computedRenderSurfaceLayerList;
+
     RenderSurfaceChromium* m_currentRenderSurface;
     unsigned m_offscreenFramebufferId;
     bool m_compositeOffscreen;
index f2a72a1..295d310 100644 (file)
@@ -247,6 +247,18 @@ void CCHeadsUpDisplay::onPresent()
     m_currentFrameNumber += 1;
 }
 
+void CCHeadsUpDisplay::setShowFPSCounter(bool show)
+{
+    m_showFPSCounter = show;
+    m_layerRenderer->setNeedsRedraw();
+}
+
+void CCHeadsUpDisplay::setShowPlatformLayerTree(bool show)
+{
+    m_showPlatformLayerTree = show;
+    m_layerRenderer->setNeedsRedraw();
+}
+
 }
 
 #endif // USE(ACCELERATED_COMPOSITING)
index 9057534..f043317 100644 (file)
@@ -49,13 +49,15 @@ public:
 
     ~CCHeadsUpDisplay();
 
+    int currentFrameNumber() const { return m_currentFrameNumber; }
+
     void onFrameBegin(double timestamp);
     void onPresent();
 
-    void setShowFPSCounter(bool enable) { m_showFPSCounter = enable; }
+    void setShowFPSCounter(bool enable);
     bool showFPSCounter() const { return m_showFPSCounter; }
 
-    void setShowPlatformLayerTree(bool enable) { m_showPlatformLayerTree = enable; }
+    void setShowPlatformLayerTree(bool enable);
     bool showPlatformLayerTree() const { return m_showPlatformLayerTree; }
 
     bool enabled() const { return m_showPlatformLayerTree || m_showFPSCounter; }
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
new file mode 100644 (file)
index 0000000..518a91e
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 "config.h"
+
+#include "cc/CCLayerTreeHost.h"
+
+#include "TraceEvent.h"
+#include "cc/CCLayerTreeHostCommitter.h"
+#include "cc/CCLayerTreeHostImpl.h"
+
+
+namespace WebCore {
+
+CCLayerTreeHost::CCLayerTreeHost(CCLayerTreeHostClient* client)
+    : m_client(client)
+    , m_frameNumber(0)
+{
+}
+
+void CCLayerTreeHost::init()
+{
+#if USE(THREADED_COMPOSITING)
+    m_proxy = createLayerTreeHostImplProxy();
+    ASSERT(m_proxy->isStarted());
+    m_proxy->setNeedsCommitAndRedraw();
+#endif
+}
+
+CCLayerTreeHost::~CCLayerTreeHost()
+{
+    TRACE_EVENT("CCLayerTreeHost::~CCLayerTreeHost", this, 0);
+#if USE(THREADED_COMPOSITING)
+    m_proxy->stop();
+    m_proxy.clear();
+#endif
+}
+
+void CCLayerTreeHost::beginCommit()
+{
+}
+
+void CCLayerTreeHost::commitComplete()
+{
+    m_frameNumber++;
+}
+
+void CCLayerTreeHost::animateAndLayout(double frameBeginTime)
+{
+    m_client->animateAndLayout(frameBeginTime);
+}
+
+PassOwnPtr<CCLayerTreeHostCommitter> CCLayerTreeHost::createLayerTreeHostCommitter()
+{
+    return CCLayerTreeHostCommitter::create();
+}
+
+void CCLayerTreeHost::setNeedsCommitAndRedraw()
+{
+#if USE(THREADED_COMPOSITING)
+    m_proxy->setNeedsCommitAndRedraw();
+#endif
+}
+
+void CCLayerTreeHost::setNeedsRedraw()
+{
+    TRACE_EVENT("CCLayerTreeHost::setNeedsRedraw", this, 0);
+#if USE(THREADED_COMPOSITING)
+    m_proxy->setNeedsRedraw();
+#endif
+}
+
+void CCLayerTreeHost::updateLayers()
+{
+    m_client->updateLayers();
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
new file mode 100644 (file)
index 0000000..668e8bf
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 CCLayerTreeHost_h
+#define CCLayerTreeHost_h
+
+#include "cc/CCLayerTreeHostCommitter.h"
+#include "cc/CCLayerTreeHostImplProxy.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class CCLayerTreeHostImpl;
+class CCLayerTreeHostImplClient;
+class GraphicsContext3D;
+
+class CCLayerTreeHostClient {
+public:
+    virtual void animateAndLayout(double frameBeginTime) = 0;
+    virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D() = 0;
+    virtual void updateLayers() = 0;
+
+protected:
+    virtual ~CCLayerTreeHostClient() { }
+};
+
+class CCLayerTreeHost : public RefCounted<CCLayerTreeHost> {
+public:
+    explicit CCLayerTreeHost(CCLayerTreeHostClient*);
+    void init();
+    virtual ~CCLayerTreeHost();
+
+    virtual void animateAndLayout(double frameBeginTime);
+    virtual void beginCommit();
+    virtual void commitComplete();
+    virtual PassOwnPtr<CCLayerTreeHostCommitter> createLayerTreeHostCommitter();
+
+    int frameNumber() const { return m_frameNumber; }
+
+    void setNeedsCommitAndRedraw();
+    void setNeedsRedraw();
+
+    virtual void updateLayers();
+
+protected:
+    virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy() = 0;
+
+private:
+    CCLayerTreeHostClient* m_client;
+    int m_frameNumber;
+    OwnPtr<CCLayerTreeHostImplProxy> m_proxy;
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.cpp
new file mode 100644 (file)
index 0000000..72dd714
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 "config.h"
+
+#include "cc/CCLayerTreeHostCommitter.h"
+
+#include "cc/CCLayerTreeHost.h"
+#include "cc/CCLayerTreeHostImpl.h"
+
+namespace WebCore {
+
+PassOwnPtr<CCLayerTreeHostCommitter> CCLayerTreeHostCommitter::create()
+{
+    return adoptPtr(new CCLayerTreeHostCommitter());
+}
+
+void CCLayerTreeHostCommitter::commit(CCLayerTreeHost* host, CCLayerTreeHostImpl* hostImpl)
+{
+    hostImpl->setSourceFrameNumber(host->frameNumber());
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommitter.h
new file mode 100644 (file)
index 0000000..dd8e918
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 CCLayerTreeHostCommitter_h
+#define CCLayerTreeHostCommitter_h
+
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class CCLayerTreeHost;
+class CCLayerTreeHostImpl;
+
+// FIXME: merge in TreeSynchronizer code into here
+class CCLayerTreeHostCommitter {
+    WTF_MAKE_NONCOPYABLE(CCLayerTreeHostCommitter);
+public:
+    static PassOwnPtr<CCLayerTreeHostCommitter> create();
+    virtual void commit(CCLayerTreeHost*, CCLayerTreeHostImpl*);
+
+protected:
+    CCLayerTreeHostCommitter() { }
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp
new file mode 100644 (file)
index 0000000..a3aa2ba
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 "config.h"
+
+#include "cc/CCLayerTreeHostImpl.h"
+
+#include "TraceEvent.h"
+#include "cc/CCLayerTreeHost.h"
+#include "cc/CCThreadTask.h"
+#include <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+CCLayerTreeHostImpl::CCLayerTreeHostImpl(CCLayerTreeHostImplClient* client)
+    : m_sourceFrameNumber(-1)
+    , m_frameNumber(0)
+    , m_client(client)
+    , m_commitPending(false)
+    , m_redrawPending(false)
+{
+}
+
+CCLayerTreeHostImpl::~CCLayerTreeHostImpl()
+{
+    TRACE_EVENT("CCLayerTreeHostImpl::~CCLayerTreeHostImpl()", this, 0);
+}
+
+void CCLayerTreeHostImpl::beginCommit()
+{
+}
+
+void CCLayerTreeHostImpl::commitComplete()
+{
+    m_commitPending = false;
+    setNeedsRedraw();
+}
+
+void CCLayerTreeHostImpl::drawLayers()
+{
+    // If a commit is pending, do not draw. This is a temporary restriction that
+    // is necessary because drawLayers is currently a blocking operation on the main thread.
+    if (m_commitPending)
+        return;
+
+    TRACE_EVENT("CCLayerTreeHostImpl::drawLayers", this, 0);
+    ASSERT(m_redrawPending);
+    m_redrawPending = false;
+
+    {
+        TRACE_EVENT("CCLayerTreeHostImpl::drawLayersAndPresent", this, 0);
+        drawLayersAndPresent();
+    }
+
+    ++m_frameNumber;
+}
+
+void CCLayerTreeHostImpl::setNeedsCommitAndRedraw()
+{
+    TRACE_EVENT("CCLayerTreeHostImpl::setNeedsCommitAndRedraw", this, 0);
+
+    // FIXME: move the requestFrameAndCommit out from here once we add framerate throttling/animation
+    double frameBeginTime = currentTime();
+    m_commitPending = true;
+    m_client->requestFrameAndCommitOnCCThread(frameBeginTime);
+}
+
+void CCLayerTreeHostImpl::setNeedsRedraw()
+{
+    if (m_redrawPending || m_commitPending)
+        return;
+
+    TRACE_EVENT("CCLayerTreeHostImpl::setNeedsRedraw", this, 0);
+    m_redrawPending = true;
+    m_client->postDrawLayersTaskOnCCThread();
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h
new file mode 100644 (file)
index 0000000..0805c7a
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 CCLayerTreeHostImpl_h
+#define CCLayerTreeHostImpl_h
+
+#include "cc/CCThread.h"
+#include <wtf/RefPtr.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+// Provides scheduling infrastructure for a CCLayerTreeHostImpl
+class CCLayerTreeHostImplClient  {
+public:
+    virtual void postDrawLayersTaskOnCCThread() = 0;
+    virtual void requestFrameAndCommitOnCCThread(double frameBeginTime) = 0;
+
+protected:
+    virtual ~CCLayerTreeHostImplClient() { }
+};
+
+// CCLayerTreeHostImpl owns the CCLayerImpl tree as well as associated rendering state
+class CCLayerTreeHostImpl {
+    WTF_MAKE_NONCOPYABLE(CCLayerTreeHostImpl);
+public:
+    explicit CCLayerTreeHostImpl(CCLayerTreeHostImplClient*);
+    virtual ~CCLayerTreeHostImpl();
+
+    virtual void beginCommit();
+    virtual void commitComplete();
+
+    void drawLayers();
+    virtual void drawLayersAndPresent() = 0;
+
+    int frameNumber() const { return m_frameNumber; }
+
+    void setNeedsRedraw();
+    void setNeedsCommitAndRedraw();
+
+    int sourceFrameNumber() const { return m_sourceFrameNumber; }
+    void setSourceFrameNumber(int frameNumber) { m_sourceFrameNumber = frameNumber; }
+
+protected:
+    int m_sourceFrameNumber;
+    int m_frameNumber;
+
+private:
+    CCLayerTreeHostImplClient* m_client;
+    bool m_commitPending;
+    bool m_redrawPending;
+};
+
+};
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.cpp
new file mode 100644 (file)
index 0000000..fc172f2
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 "config.h"
+
+#include "cc/CCLayerTreeHostImplProxy.h"
+
+#include "TraceEvent.h"
+#include "cc/CCLayerTreeHost.h"
+#include "cc/CCMainThreadTask.h"
+#include "cc/CCThreadTask.h"
+
+
+using namespace WTF;
+
+namespace WebCore {
+
+namespace {
+CCThread* ccThread;
+int numProxies = 0;
+}
+
+CCLayerTreeHostImplProxy::CCLayerTreeHostImplProxy(CCLayerTreeHost* layerTreeHost)
+    : m_commitPending(false)
+    , m_layerTreeHost(layerTreeHost)
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::CCLayerTreeHostImplProxy", this, 0);
+    ASSERT(isMainThread());
+    numProxies++;
+    if (!ccThread)
+        ccThread = CCThread::create().leakPtr();
+}
+
+
+void CCLayerTreeHostImplProxy::start()
+{
+    // Create LayerTreeHostImpl.
+    CCCompletionEvent completion;
+    ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::initImplOnCCThread, AllowCrossThreadAccess(&completion)));
+    completion.wait();
+}
+
+CCLayerTreeHostImplProxy::~CCLayerTreeHostImplProxy()
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::~CCLayerTreeHostImplProxy", this, 0);
+    ASSERT(isMainThread());
+    ASSERT(!m_layerTreeHostImpl && !m_layerTreeHost); // make sure stop() got called.
+
+    numProxies--;
+    if (!numProxies) {
+        delete ccThread;
+        ccThread = 0;
+    }
+}
+
+bool CCLayerTreeHostImplProxy::isStarted() const
+{
+    return m_layerTreeHostImpl;
+}
+
+void CCLayerTreeHostImplProxy::setNeedsCommitAndRedraw()
+{
+    ASSERT(isMainThread());
+    if (m_commitPending)
+        return;
+
+    TRACE_EVENT("CCLayerTreeHostImplProxy::setNeedsCommitAndRedraw", this, 0);
+    m_commitPending = true;
+    ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::setNeedsCommitAndRedrawOnCCThread));
+}
+
+void CCLayerTreeHostImplProxy::setNeedsRedraw()
+{
+    ASSERT(isMainThread());
+    ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::setNeedsRedrawOnCCThread));
+}
+
+void CCLayerTreeHostImplProxy::stop()
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::stop", this, 0);
+    ASSERT(isMainThread());
+    // Synchronously deletes the impl.
+    CCCompletionEvent completion;
+    ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::layerTreeHostClosedOnCCThread, AllowCrossThreadAccess(&completion)));
+    completion.wait();
+
+    ASSERT(!m_layerTreeHostImpl); // verify that the impl deleted.
+    m_layerTreeHost = 0;
+}
+
+void CCLayerTreeHostImplProxy::postDrawLayersTaskOnCCThread()
+{
+    ASSERT(isCCThread());
+    if (m_layerTreeHostImpl)
+        ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::drawLayersOnCCThread));
+}
+
+void CCLayerTreeHostImplProxy::requestFrameAndCommitOnCCThread(double frameBeginTime)
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::requestFrameAndCommitOnCCThread", this, 0);
+    ASSERT(isCCThread());
+    if (m_layerTreeHostImpl)
+        CCMainThread::postTask(createMainThreadTask(this, &CCLayerTreeHostImplProxy::requestFrameAndCommit, frameBeginTime));
+}
+
+bool CCLayerTreeHostImplProxy::isMainThread() const
+{
+    return ::isMainThread();
+}
+
+bool CCLayerTreeHostImplProxy::isCCThread() const
+{
+    return currentThread() == ccThread->threadID();
+}
+
+void CCLayerTreeHostImplProxy::requestFrameAndCommit(double frameBeginTime)
+{
+    ASSERT(isMainThread());
+    if (!m_layerTreeHost)
+        return;
+
+    TRACE_EVENT("CCLayerTreeHostImplProxy::requestFrameAndCommit", this, 0);
+    {
+        TRACE_EVENT("CCLayerTreeHost::animateAndLayout", this, 0);
+        m_layerTreeHost->animateAndLayout(frameBeginTime);
+    }
+
+    m_commitPending = false;
+    {
+        TRACE_EVENT("CCLayerTreeHost::updateLayers", this, 0);
+        m_layerTreeHost->updateLayers();
+    }
+
+    OwnPtr<CCLayerTreeHostCommitter> committer = m_layerTreeHost->createLayerTreeHostCommitter();
+    m_layerTreeHost->beginCommit();
+
+    // Blocking call to CCLayerTreeHostImplProxy::performCommit
+    CCCompletionEvent completion;
+    ccThread->postTask(createCCThreadTask(this, &CCLayerTreeHostImplProxy::commitOnCCThread, AllowCrossThreadAccess(committer.get()), AllowCrossThreadAccess(&completion)));
+    completion.wait();
+
+    committer.clear();
+
+    m_layerTreeHost->commitComplete();
+}
+
+void CCLayerTreeHostImplProxy::commitOnCCThread(CCLayerTreeHostCommitter* committer, CCCompletionEvent* completion)
+{
+    ASSERT(isCCThread());
+    TRACE_EVENT("CCLayerTreeHostImplProxy::commitOnCCThread", this, 0);
+    m_layerTreeHostImpl->beginCommit();
+    {
+        TRACE_EVENT("CCLayerTreeHost::commit", this, 0);
+        committer->commit(m_layerTreeHost, m_layerTreeHostImpl.get());
+    }
+    completion->signal();
+
+    m_layerTreeHostImpl->commitComplete();
+}
+
+void CCLayerTreeHostImplProxy::drawLayersOnCCThread()
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::drawLayersOnCCThread", this, 0);
+    ASSERT(isCCThread());
+    if (m_layerTreeHostImpl)
+        m_layerTreeHostImpl->drawLayers();
+}
+
+void CCLayerTreeHostImplProxy::setNeedsCommitAndRedrawOnCCThread()
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::setNeedsCommitAndRedrawOnCCThread", this, 0);
+    ASSERT(isCCThread() && m_layerTreeHostImpl);
+    m_layerTreeHostImpl->setNeedsCommitAndRedraw();
+}
+
+void CCLayerTreeHostImplProxy::setNeedsRedrawOnCCThread()
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::setNeedsRedrawOnCCThread", this, 0);
+    ASSERT(isCCThread() && m_layerTreeHostImpl);
+    m_layerTreeHostImpl->setNeedsRedraw();
+}
+
+void CCLayerTreeHostImplProxy::initImplOnCCThread(CCCompletionEvent* completion)
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::initImplOnCCThread", this, 0);
+    ASSERT(isCCThread());
+    m_layerTreeHostImpl = createLayerTreeHostImpl();
+    completion->signal();
+}
+
+void CCLayerTreeHostImplProxy::layerTreeHostClosedOnCCThread(CCCompletionEvent* completion)
+{
+    TRACE_EVENT("CCLayerTreeHostImplProxy::layerTreeHostClosedOnCCThread", this, 0);
+    ASSERT(isCCThread());
+    m_layerTreeHostImpl.clear();
+    completion->signal();
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImplProxy.h
new file mode 100644 (file)
index 0000000..295be3c
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 CCLayerTreeHostImplProxy_h
+#define CCLayerTreeHostImplProxy_h
+
+#include "cc/CCCompletionEvent.h"
+#include "cc/CCLayerTreeHostImpl.h"
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+class CCLayerTreeHost;
+class CCLayerTreeHostCommitter;
+
+class CCLayerTreeHostImplProxy : public CCLayerTreeHostImplClient {
+    WTF_MAKE_NONCOPYABLE(CCLayerTreeHostImplProxy);
+public:
+    virtual ~CCLayerTreeHostImplProxy();
+
+    bool isStarted() const;
+
+    void setNeedsCommitAndRedraw();
+    void setNeedsRedraw();
+
+    void start(); // Must be called before using the proxy.
+    void stop(); // Must be called before deleting the proxy.
+
+    // CCLayerTreeHostImplCient -- called on CCThread
+    virtual void postDrawLayersTaskOnCCThread();
+    virtual void requestFrameAndCommitOnCCThread(double frameBeginTime);
+
+protected:
+    explicit CCLayerTreeHostImplProxy(CCLayerTreeHost*);
+    virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl() = 0;
+    CCLayerTreeHost* host() const { return m_layerTreeHost; }
+
+private:
+    bool isMainThread() const;
+    bool isCCThread() const;
+
+    // Called on CCMainThread
+    void requestFrameAndCommit(double frameBeginTime);
+
+    // Called on CCThread
+    void commitOnCCThread(CCLayerTreeHostCommitter*, CCCompletionEvent*);
+    void drawLayersOnCCThread();
+    void initImplOnCCThread(CCCompletionEvent*);
+    void setNeedsCommitAndRedrawOnCCThread();
+    void setNeedsRedrawOnCCThread();
+    void layerTreeHostClosedOnCCThread(CCCompletionEvent*);
+
+    // Used on main-thread only.
+    bool m_commitPending;
+
+    // Accessed on main thread only.
+    CCLayerTreeHost* m_layerTreeHost;
+
+    // Used on the CCThread, but checked on main thread during initialization/shutdown.
+    OwnPtr<CCLayerTreeHostImpl> m_layerTreeHostImpl;
+};
+
+}
+
+#endif
index 7de8d71..fac6e64 100644 (file)
@@ -24,9 +24,9 @@
 #ifndef CCMainThreadTask_h
 #define CCMainThreadTask_h
 
-#include "CCMainThread.h"
 #include "CrossThreadCopier.h"
 #include "CrossThreadTask.h"
+#include "cc/CCMainThread.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 
index 9566584..de173a1 100644 (file)
@@ -27,6 +27,7 @@
 #include "CCThread.h"
 
 #include "LayerRendererChromium.h"
+#include "TraceEvent.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/ThreadingPrimitives.h>
@@ -64,6 +65,7 @@ void* CCThread::compositorThreadStart(void* userdata)
 
 void* CCThread::runLoop()
 {
+    TRACE_EVENT("CCThread::runLoop", this, 0);
     {
         // Wait for CCThread::start() to complete to have m_threadID
         // established before starting the main loop.
index 71245d3..91c58e5 100644 (file)
@@ -24,9 +24,9 @@
 #ifndef CCThreadTask_h
 #define CCThreadTask_h
 
-#include "CCThread.h"
 #include "CrossThreadCopier.h"
 #include "CrossThreadTask.h"
+#include "cc/CCThread.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 
index a56e04e..13fd9d6 100644 (file)
@@ -1,3 +1,103 @@
+2011-05-17  Nat Duca  <nduca@chromium.org>
+
+        Reviewed by James Robinson.
+
+        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
+        https://bugs.webkit.org/show_bug.cgi?id=58408
+
+        Redirect invalidates and scheduling into compositor when in
+        threaded compositing mode. Add stress tests for CCLayerTreeHost.
+
+        * WebKit.gypi:
+        * public/WebWidget.h:
+        * src/WebPopupMenuImpl.cpp:
+        (WebKit::WebPopupMenuImpl::animate):
+        * src/WebPopupMenuImpl.h:
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::animate):
+        (WebKit::WebViewImpl::paint):
+        (WebKit::WebViewImpl::animateAndLayout):
+        (WebKit::WebViewImpl::updateLayers):
+        (WebKit::WebViewImpl::composite):
+        (WebKit::WebViewImpl::setRootLayerNeedsDisplay):
+        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
+        (WebKit::WebViewImpl::doComposite):
+        (WebKit::WebViewImpl::createLayerTreeHostContext3D):
+        (WebKit::WebViewImpl::reallocateRenderer):
+        (WebKit::WebViewImpl::updateLayerRendererSettings):
+        (WebKit::WebViewImpl::updateLayerRendererViewport):
+        * src/WebViewImpl.h:
+        * tests/CCLayerTreeHostTest.cpp: Added.
+        (WTF::CCLayerTreeHostTest::CCLayerTreeHostTest):
+        (WTF::CCLayerTreeHostTest::animateAndLayout):
+        (WTF::CCLayerTreeHostTest::beginCommitOnCCThread):
+        (WTF::CCLayerTreeHostTest::beginCommitOnMainThread):
+        (WTF::CCLayerTreeHostTest::commitOnCCThread):
+        (WTF::CCLayerTreeHostTest::commitCompleteOnCCThread):
+        (WTF::CCLayerTreeHostTest::commitCompleteOnMainThread):
+        (WTF::CCLayerTreeHostTest::drawLayersAndPresentOnCCThread):
+        (WTF::CCLayerTreeHostTest::updateLayers):
+        (WTF::CCLayerTreeHostTest::onBeginTest):
+        (WTF::CCLayerTreeHostTest::doEndTest):
+        (WTF::CCLayerTreeHostTest::onEndTest):
+        (WTF::CCLayerTreeHostTest::runTest):
+        (WTF::CCLayerTreeHostTest::testTimeout):
+        (WTF::MockLayerTreeHostClient::MockLayerTreeHostClient):
+        (WTF::MockLayerTreeHostClient::createLayerTreeHostContext3D):
+        (WTF::MockLayerTreeHostClient::animateAndLayout):
+        (WTF::MockLayerTreeHostClient::updateLayers):
+        (WTF::MockLayerTreeHostCommitter::create):
+        (WTF::MockLayerTreeHostCommitter::commit):
+        (WTF::MockLayerTreeHostCommitter::MockLayerTreeHostCommitter):
+        (WTF::MockLayerTreeHostImpl::create):
+        (WTF::MockLayerTreeHostImpl::beginCommit):
+        (WTF::MockLayerTreeHostImpl::commitComplete):
+        (WTF::MockLayerTreeHostImpl::drawLayersAndPresent):
+        (WTF::MockLayerTreeHostImpl::MockLayerTreeHostImpl):
+        (WTF::MockLayerTreeHostImplProxy::create):
+        (WTF::MockLayerTreeHostImplProxy::createLayerTreeHostImpl):
+        (WTF::MockLayerTreeHostImplProxy::MockLayerTreeHostImplProxy):
+        (WTF::MockLayerTreeHost::MockLayerTreeHost):
+        (WTF::MockLayerTreeHost::createLayerTreeHostImplProxy):
+        (WTF::MockLayerTreeHost::updateLayers):
+        (WTF::MockLayerTreeHost::createLayerTreeHostCommitter):
+        (WTF::MockLayerTreeHost::beginCommit):
+        (WTF::MockLayerTreeHost::commitComplete):
+        (WTF::CCLayerTreeHostTest::doBeginTest):
+        (WTF::CCLayerTreeHostTest::endTest):
+        (WTF::CCLayerTreeHostTestShortlived1::CCLayerTreeHostTestShortlived1):
+        (WTF::CCLayerTreeHostTestShortlived1::beginTest):
+        (WTF::CCLayerTreeHostTestShortlived1::afterTest):
+        (WTF::TEST_F):
+        (WTF::CCLayerTreeHostTestShortlived2::CCLayerTreeHostTestShortlived2):
+        (WTF::CCLayerTreeHostTestShortlived2::beginTest):
+        (WTF::CCLayerTreeHostTestShortlived2::afterTest):
+        (WTF::CCLayerTreeHostTestShortlived3::CCLayerTreeHostTestShortlived3):
+        (WTF::CCLayerTreeHostTestShortlived3::beginTest):
+        (WTF::CCLayerTreeHostTestShortlived3::afterTest):
+        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::CCLayerTreeHostTestCommitingWithContinuousRedraw):
+        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest):
+        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread):
+        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersAndPresentOnCCThread):
+        (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::afterTest):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit1::CCLayerTreeHostTestSetNeedsCommit1):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit1::beginTest):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit1::drawLayersAndPresentOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit1::commitOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit1::afterTest):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit2::CCLayerTreeHostTestSetNeedsCommit2):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit2::beginTest):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit2::drawLayersAndPresentOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit2::commitOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsCommit2::afterTest):
+        (WTF::CCLayerTreeHostTestSetNeedsRedraw::CCLayerTreeHostTestSetNeedsRedraw):
+        (WTF::CCLayerTreeHostTestSetNeedsRedraw::beginTest):
+        (WTF::CCLayerTreeHostTestSetNeedsRedraw::drawLayersAndPresentOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsRedraw::commitOnCCThread):
+        (WTF::CCLayerTreeHostTestSetNeedsRedraw::afterTest):
+        * tests/CCThreadTest.cpp:
+        (WebCore::TEST):
+
 2011-06-24  Chris Rogers  <crogers@google.com>
 
         Reviewed by Kenneth Russell.
index f2a0dc7..c4ca90d 100644 (file)
         'webkit_unittest_files': [
             'tests/ArenaTestHelpers.h',
             'tests/AssociatedURLLoaderTest.cpp',
-            'tests/InnerGestureRecognizerTest.cpp',
+            'tests/CCLayerTreeHostTest.cpp',
             'tests/CCThreadTaskTest.cpp',
             'tests/CCThreadTest.cpp',
             'tests/IDBBindingUtilitiesTest.cpp',
             'tests/IDBKeyPathTest.cpp',
             'tests/IDBLevelDBCodingTest.cpp',
+            'tests/InnerGestureRecognizerTest.cpp',
             'tests/KeyboardTest.cpp',
             'tests/KURLTest.cpp',
             'tests/PODArenaTest.cpp',
index 7434412..f6e73f1 100644 (file)
@@ -47,6 +47,9 @@ class WebString;
 struct WebPoint;
 template <typename T> class WebVector;
 
+// FIXME: remove this define once render_widget has been changed to issue threaded compositor calls
+#define WEBWIDGET_HAS_ANIMATE_CHANGES 1
+
 class WebWidget {
 public:
     // This method closes and deletes the WebWidget.
@@ -68,15 +71,17 @@ public:
     // willStartLiveResize.
     virtual void willEndLiveResize() { }
 
-    // Called to update imperative animation state.  This should be called before
-    // paint, although the client can rate-limit these calls.
-    virtual void animate() { }
+    // Called to update imperative animation state. This should be called before
+    // paint, although the client can rate-limit these calls. When
+    // frameBeginTime is 0.0, the WebWidget will determine the frame begin time
+    // itself.
+    virtual void animate(double frameBeginTime) { }
 
     // Called to layout the WebWidget.  This MUST be called before Paint,
     // and it may result in calls to WebWidgetClient::didInvalidateRect.
     virtual void layout() { }
 
-    // Called to paint the rectangular region within the WebWidget 
+    // Called to paint the rectangular region within the WebWidget
     // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
     // Layout before calling this method.  It is okay to call paint
     // multiple times once layout has been called, assuming no other
@@ -85,12 +90,15 @@ public:
     // warranted before painting again).
     virtual void paint(WebCanvas*, const WebRect& viewPort) { }
 
-    // Triggers compositing of the current layers onto the screen.
-    // The finish argument controls whether the compositor will wait for the
-    // GPU to finish rendering before returning. You MUST call Layout
-    // before calling this method, for the same reasons described in
-    // the paint method above.
-    virtual void composite(bool finish) { }
+    // In non-threaded compositing mode, triggers compositing of the current
+    // layers onto the screen. You MUST call Layout before calling this method, for the same
+    // reasons described in the paint method above
+    //
+    // In threaded compositing mode, indicates that the widget should update
+    // itself, for example due to window damage. The redraw will begin
+    // asynchronously and perform layout and animation internally. Do not call
+    // animate or layout in this case.
+    virtual void composite(bool finish) = 0;
 
     // Called to inform the WebWidget of a change in theme.
     // Implementors that cache rendered copies of widgets need to re-render
index 5cbf5ff..409e6f7 100644 (file)
@@ -167,7 +167,7 @@ void WebPopupMenuImpl::willEndLiveResize()
 {
 }
 
-void WebPopupMenuImpl::animate()
+void WebPopupMenuImpl::animate(double)
 {
 }
 
index a91faf1..45e8897 100644 (file)
@@ -65,7 +65,7 @@ public:
     virtual void willStartLiveResize();
     virtual void resize(const WebSize&);
     virtual void willEndLiveResize();
-    virtual void animate();
+    virtual void animate(double frameBeginTime);
     virtual void layout();
     virtual void paint(WebCanvas* canvas, const WebRect& rect);
     virtual void themeChanged();
index 022a2e1..b850270 100644 (file)
 #include <cmath> // for std::pow
 
 using namespace WebCore;
+using namespace std;
 
 namespace {
 
@@ -1004,8 +1005,8 @@ void WebViewImpl::resize(const WebSize& newSize)
 
 #if USE(ACCELERATED_COMPOSITING)
     if (m_layerRenderer && isAcceleratedCompositingActive()) {
-        m_layerRenderer->resizeOnscreenContent(IntSize(std::max(1, m_size.width),
-                                                       std::max(1, m_size.height)));
+        m_layerRenderer->resizeOnscreenContent(IntSize(max(1, m_size.width),
+                                                       max(1, m_size.height)));
     }
 #endif
 }
@@ -1016,17 +1017,21 @@ void WebViewImpl::willEndLiveResize()
         mainFrameImpl()->frameView()->willEndLiveResize();
 }
 
-void WebViewImpl::animate()
+void WebViewImpl::animate(double frameBeginTime)
 {
-    TRACE_EVENT("WebViewImpl::animate", this, 0);
 #if ENABLE(REQUEST_ANIMATION_FRAME)
+    TRACE_EVENT("WebViewImpl::animate", this, 0);
+    // FIXME: remove this zero-check once render_widget has been modified to
+    // pass in a frameBeginTime.
+    if (!frameBeginTime)
+        frameBeginTime = currentTime();
     WebFrameImpl* webframe = mainFrameImpl();
     if (webframe) {
         FrameView* view = webframe->frameView();
         if (view) {
             if (m_layerRenderer)
                 m_layerRenderer->setIsAnimating(true);
-            view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(currentTime()));
+            view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(frameBeginTime));
             if (m_layerRenderer)
                 m_layerRenderer->setIsAnimating(false);
         }
@@ -1095,6 +1100,10 @@ void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect)
 {
     if (isAcceleratedCompositingActive()) {
 #if USE(ACCELERATED_COMPOSITING)
+#if USE(THREADED_COMPOSITING)
+        // FIXME: do readback in threaded compositing mode rather than returning nothing
+        return;
+#endif
         doComposite();
 
         // If a canvas was passed in, we use it to grab a copy of the
@@ -1128,16 +1137,29 @@ void WebViewImpl::themeChanged()
     view->invalidateRect(damagedRect);
 }
 
-void WebViewImpl::composite(bool finish)
+void WebViewImpl::animateAndLayout(double frameBeginTime)
+{
+    animate(frameBeginTime);
+    layout();
+}
+
+void WebViewImpl::updateLayers()
 {
-#if USE(ACCELERATED_COMPOSITING)
     // Update the compositing requirements for all frame in the tree before doing any painting
     // as the compositing requirements for a RenderLayer within a subframe might change.
     for (Frame* frame = page()->mainFrame(); frame; frame = frame->tree()->traverseNext())
         frame->view()->updateCompositingLayers();
     page()->mainFrame()->view()->syncCompositingStateIncludingSubframes();
+}
 
+void WebViewImpl::composite(bool finish)
+{
+#if USE(ACCELERATED_COMPOSITING)
+#if USE(THREADED_COMPOSITING)
+    m_layerRenderer->setNeedsRedraw();
+#else
     TRACE_EVENT("WebViewImpl::composite", this, 0);
+
     if (m_recreatingGraphicsContext) {
         // reallocateRenderer will request a repaint whether or not it succeeded
         // in creating a new context.
@@ -1147,10 +1169,6 @@ void WebViewImpl::composite(bool finish)
     }
     doComposite();
 
-    // Finish if requested.
-    if (finish)
-        m_layerRenderer->finish();
-
     // Put result onscreen.
     m_layerRenderer->present();
 
@@ -1165,6 +1183,7 @@ void WebViewImpl::composite(bool finish)
         setRootLayerNeedsDisplay();
     }
 #endif
+#endif
 }
 
 const WebInputEvent* WebViewImpl::m_currentInputEvent = 0;
@@ -1778,13 +1797,13 @@ void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel)
     if (zoomLevel == m_zoomLevel)
         return;
 
-    m_zoomLevel = std::max(std::min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel);
+    m_zoomLevel = max(min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel);
     m_client->zoomLevelChanged();
 }
 
 double WebView::zoomLevelToZoomFactor(double zoomLevel)
 {
-    return std::pow(textSizeMultiplierRatio, zoomLevel);
+    return pow(textSizeMultiplierRatio, zoomLevel);
 }
 
 double WebView::zoomFactorToZoomLevel(double factor)
@@ -2418,7 +2437,12 @@ void WebViewImpl::setRootPlatformLayer(WebCore::PlatformLayer* layer)
 
 void WebViewImpl::setRootLayerNeedsDisplay()
 {
+#if USE(THREADED_COMPOSITING)
+    if (m_layerRenderer)
+        m_layerRenderer->setNeedsCommitAndRedraw();
+#else
     m_client->scheduleComposite();
+#endif
 }
 
 
@@ -2490,22 +2514,16 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
         m_client->didActivateAcceleratedCompositing(false);
     } else if (m_layerRenderer) {
         m_isAcceleratedCompositingActive = true;
-        m_layerRenderer->resizeOnscreenContent(WebCore::IntSize(std::max(1, m_size.width),
-                                                                std::max(1, m_size.height)));
+        m_layerRenderer->resizeOnscreenContent(WebCore::IntSize(max(1, m_size.width),
+                                                                max(1, m_size.height)));
 
         m_client->didActivateAcceleratedCompositing(true);
     } else {
         TRACE_EVENT("WebViewImpl::setIsAcceleratedCompositingActive(true)", this, 0);
-        RefPtr<GraphicsContext3D> context = m_temporaryOnscreenGraphicsContext3D.release();
-        if (!context) {
-            context = GraphicsContext3D::create(getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow);
-            if (context)
-                context->reshape(std::max(1, m_size.width), std::max(1, m_size.height));
-        }
-
 
-        m_layerRenderer = LayerRendererChromium::create(context.release(), WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled());
+        m_layerRenderer = LayerRendererChromium::create(this, WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled());
         if (m_layerRenderer) {
+            updateLayerRendererSettings();
             m_client->didActivateAcceleratedCompositing(true);
             m_isAcceleratedCompositingActive = true;
             m_compositorCreationFailed = false;
@@ -2533,39 +2551,43 @@ void WebViewImpl::doComposite()
     if (!page())
         return;
 
-    m_layerRenderer->setCompositeOffscreen(settings()->compositeToTextureEnabled());
-
-    CCHeadsUpDisplay* hud = m_layerRenderer->headsUpDisplay();
-    hud->setShowFPSCounter(settings()->showFPSCounter());
-    hud->setShowPlatformLayerTree(settings()->showPlatformLayerTree());
-
     if (m_pageOverlay)
         m_pageOverlay->update();
 
-    m_layerRenderer->updateAndDrawLayers();
+    m_layerRenderer->updateLayers();
+    m_layerRenderer->drawLayers();
+}
+
+PassRefPtr<GraphicsContext3D> WebViewImpl::createLayerTreeHostContext3D()
+{
+    RefPtr<GraphicsContext3D> context = m_temporaryOnscreenGraphicsContext3D.release();
+    if (!context) {
+        context = GraphicsContext3D::create(getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow);
+        if (context)
+            context->reshape(max(1, m_size.width), max(1, m_size.height));
+    }
+    return context;
 }
 
 void WebViewImpl::reallocateRenderer()
 {
-    RefPtr<GraphicsContext3D> newContext = m_temporaryOnscreenGraphicsContext3D.get();
-    WebGraphicsContext3D* webContext = GraphicsContext3DInternal::extractWebGraphicsContext3D(newContext.get());
-    if (!newContext || !webContext || webContext->isContextLost())
-        newContext = GraphicsContext3D::create(
-            getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow);
     // GraphicsContext3D::create might fail and return 0, in that case LayerRendererChromium::create will also return 0.
-    RefPtr<LayerRendererChromium> layerRenderer = LayerRendererChromium::create(newContext, WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled());
+    RefPtr<LayerRendererChromium> layerRenderer = LayerRendererChromium::create(this, WebViewImplContentPainter::create(this), m_page->settings()->acceleratedDrawingEnabled());
 
     // Reattach the root layer.  Child layers will get reattached as a side effect of updateLayersRecursive.
     if (layerRenderer) {
         m_layerRenderer->transferRootLayer(layerRenderer.get());
         m_layerRenderer = layerRenderer;
+        updateLayerRendererSettings();
+
         // FIXME: In MacOS newContext->reshape method needs to be called to
         // allocate IOSurfaces. All calls to create a context followed by
         // reshape should really be extracted into one function; it is not
         // immediately obvious that GraphicsContext3D object will not
         // function properly until its reshape method is called.
-        newContext->reshape(std::max(1, m_size.width), std::max(1, m_size.height));
+        layerRenderer->context()->reshape(max(1, m_size.width), max(1, m_size.height));
         setRootPlatformLayer(m_layerRenderer->rootLayer());
+
         // Forces ViewHostMsg_DidActivateAcceleratedCompositing to be sent so
         // that the browser process can reacquire surfaces.
         m_client->didActivateAcceleratedCompositing(true);
@@ -2576,10 +2598,18 @@ void WebViewImpl::reallocateRenderer()
 }
 #endif
 
-void WebViewImpl::updateLayerRendererViewport()
+void WebViewImpl::updateLayerRendererSettings()
 {
     ASSERT(m_layerRenderer);
+    m_layerRenderer->setCompositeOffscreen(settings()->compositeToTextureEnabled());
+
+    CCHeadsUpDisplay* hud = m_layerRenderer->headsUpDisplay();
+    hud->setShowFPSCounter(settings()->showFPSCounter());
+    hud->setShowPlatformLayerTree(settings()->showPlatformLayerTree());
+}
 
+void WebViewImpl::updateLayerRendererViewport()
+{
     if (!page())
         return;
 
@@ -2607,7 +2637,7 @@ WebGraphicsContext3D* WebViewImpl::graphicsContext3D()
         }
         m_temporaryOnscreenGraphicsContext3D = GraphicsContext3D::create(getCompositorContextAttributes(), m_page->chrome(), GraphicsContext3D::RenderDirectlyToHostWindow);
         if (m_temporaryOnscreenGraphicsContext3D)
-            m_temporaryOnscreenGraphicsContext3D->reshape(std::max(1, m_size.width), std::max(1, m_size.height));
+            m_temporaryOnscreenGraphicsContext3D->reshape(max(1, m_size.width), max(1, m_size.height));
         return GraphicsContext3DInternal::extractWebGraphicsContext3D(m_temporaryOnscreenGraphicsContext3D.get());
     }
 #endif
index 6d897df..6553b58 100644 (file)
@@ -56,6 +56,7 @@ namespace WebCore {
 class ChromiumDataObject;
 class DocumentLoader;
 class Frame;
+class GraphicsContext3D;
 class HistoryItem;
 class HitTestResult;
 class KeyboardEvent;
@@ -87,7 +88,7 @@ class WebMouseWheelEvent;
 class WebSettingsImpl;
 class WebTouchEvent;
 
-class WebViewImpl : public WebView, public RefCounted<WebViewImpl> {
+class WebViewImpl : public WebView, public WebCore::CCLayerTreeHostClient, public RefCounted<WebViewImpl> {
 public:
     // WebWidget methods:
     virtual void close();
@@ -95,7 +96,7 @@ public:
     virtual void willStartLiveResize();
     virtual void resize(const WebSize&);
     virtual void willEndLiveResize();
-    virtual void animate();
+    virtual void animate(double frameBeginTime);
     virtual void layout();
     virtual void paint(WebCanvas*, const WebRect&);
     virtual void themeChanged();
@@ -202,6 +203,11 @@ public:
                                     unsigned inactiveForegroundColor);
     virtual void performCustomContextMenuAction(unsigned action);
 
+    // CCLayerTreeHostClient
+    virtual void animateAndLayout(double frameBeginTime);
+    virtual PassRefPtr<WebCore::GraphicsContext3D> createLayerTreeHostContext3D();
+    virtual void updateLayers();
+
     // WebViewImpl
 
     void setIgnoreInputEvents(bool newValue);
@@ -356,6 +362,7 @@ public:
     void setRootLayerNeedsDisplay();
     void scrollRootLayerRect(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& clipRect);
     void invalidateRootLayerRect(const WebCore::IntRect&);
+    void doUpdateAndComposite();
 #endif
 
     // Returns the onscreen 3D context used by the compositor. This is
@@ -423,6 +430,7 @@ private:
     void doComposite();
     void doPixelReadbackToCanvas(WebCanvas*, const WebCore::IntRect&);
     void reallocateRenderer();
+    void updateLayerRendererSettings();
     void updateLayerRendererViewport();
 #endif
 
diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp
new file mode 100644 (file)
index 0000000..d854806
--- /dev/null
@@ -0,0 +1,538 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * 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 "config.h"
+
+#if USE(THREADED_COMPOSITING)
+
+#include "cc/CCLayerTreeHost.h"
+
+#include "GraphicsContext3D.h"
+#include "cc/CCLayerTreeHostImpl.h"
+#include "cc/CCMainThreadTask.h"
+#include "cc/CCThreadTask.h"
+#include <gtest/gtest.h>
+#include <webkit/support/webkit_support.h>
+#include <wtf/MainThread.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+
+
+using namespace WebCore;
+using namespace WTF;
+
+namespace {
+
+class MockLayerTreeHost;
+class MockLayerTreeHostClient;
+class MockLayerTreeHostImpl;
+
+// The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated
+// MockLayerTreeHostImpl/MockLayerTreeHostClient.
+//
+// beginTest() is called once the main message loop is running and the layer tree host is initialized.
+//
+// Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCLayerTreeHostTest methods of similar names.
+// To track the commit process, override these functions.
+//
+// The test continues until someone calls endTest. endTest can be called on any thread, but be aware that
+// ending the test is an asynchronous process.
+class CCLayerTreeHostTest : public testing::Test {
+public:
+    CCLayerTreeHostTest()
+        : m_beginning(false)
+        , m_endWhenBeginReturns(false)
+        , m_running(false)
+        , m_timedOut(false) { }
+
+    virtual void afterTest() = 0;
+
+    virtual void beginTest() = 0;
+    virtual void animateAndLayout(MockLayerTreeHostClient* layerTreeHost, double frameBeginTime) { }
+    virtual void beginCommitOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
+    virtual void beginCommitOnMainThread(MockLayerTreeHost* layerTreeHost) { }
+    virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* layerTreeHostImpl) { }
+    virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
+    virtual void commitCompleteOnMainThread(MockLayerTreeHost* layerTreeHost) { }
+    virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
+    virtual void updateLayers(MockLayerTreeHost* layerTreeHost) { }
+
+    void endTest();
+
+protected:
+    void doBeginTest();
+
+    static void onBeginTest(void* self)
+    {
+        static_cast<CCLayerTreeHostTest*>(self)->doBeginTest();
+    }
+
+    void doEndTest()
+    {
+    }
+
+    static void onEndTest(void* self)
+    {
+        ASSERT(isMainThread());
+        CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
+        test->m_layerTreeHost.clear();
+        test->m_client.clear();
+        webkit_support::QuitMessageLoop();
+    }
+
+    void runTest()
+    {
+        webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
+        webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast<void*>(this), 5000);
+        webkit_support::RunMessageLoop();
+        m_running = false;
+        bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout.
+        webkit_support::RunAllPendingMessages();
+        if (timedOut) {
+            printf("Test timed out");
+            FAIL() << "Test timed out";
+            return;
+        }
+        afterTest();
+    }
+
+    static void testTimeout(void* self)
+    {
+        CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
+        if (!test->m_running)
+            return;
+        test->m_timedOut = true;
+        test->endTest();
+    }
+
+    Mutex m_tracesLock;
+    Vector<std::string> m_traces;
+
+    OwnPtr<MockLayerTreeHostClient> m_client;
+    RefPtr<MockLayerTreeHost> m_layerTreeHost;
+
+private:
+    bool m_beginning;
+    bool m_endWhenBeginReturns;
+    bool m_running;
+    bool m_timedOut;
+};
+
+class MockLayerTreeHostClient : public CCLayerTreeHostClient {
+public:
+    MockLayerTreeHostClient(CCLayerTreeHostTest* test) : m_test(test) { }
+
+    virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
+    {
+        return adoptRef<GraphicsContext3D>(0);
+    }
+
+    virtual void animateAndLayout(double frameBeginTime)
+    {
+        m_test->animateAndLayout(this, frameBeginTime);
+    }
+
+    virtual void updateLayers()
+    {
+    }
+
+private:
+    CCLayerTreeHostTest* m_test;
+};
+
+class MockLayerTreeHostCommitter : public CCLayerTreeHostCommitter {
+public:
+    static PassOwnPtr<MockLayerTreeHostCommitter> create(CCLayerTreeHostTest* test)
+    {
+        return adoptPtr(new MockLayerTreeHostCommitter(test));
+    }
+
+    virtual void commit(CCLayerTreeHost* host, CCLayerTreeHostImpl* hostImpl)
+    {
+        CCLayerTreeHostCommitter::commit(host, hostImpl);
+        m_test->commitOnCCThread(reinterpret_cast<MockLayerTreeHost*>(host), reinterpret_cast<MockLayerTreeHostImpl*>(hostImpl));
+    }
+
+private:
+    MockLayerTreeHostCommitter(CCLayerTreeHostTest* test) : m_test(test) { }
+    CCLayerTreeHostTest* m_test;
+};
+
+class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
+public:
+    static PassOwnPtr<MockLayerTreeHostImpl> create(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
+    {
+        return adoptPtr(new MockLayerTreeHostImpl(client, test));
+    }
+
+    virtual void beginCommit()
+    {
+        CCLayerTreeHostImpl::beginCommit();
+        m_test->beginCommitOnCCThread(this);
+    }
+
+    virtual void commitComplete()
+    {
+        CCLayerTreeHostImpl::commitComplete();
+        m_test->commitCompleteOnCCThread(this);
+    }
+
+    virtual void drawLayersAndPresent()
+    {
+        m_test->drawLayersAndPresentOnCCThread(this);
+    }
+
+private:
+    MockLayerTreeHostImpl(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
+            : CCLayerTreeHostImpl(client)
+            , m_test(test)
+    {
+    }
+
+    CCLayerTreeHostTest* m_test;
+};
+
+class MockLayerTreeHostImplProxy : public CCLayerTreeHostImplProxy {
+public:
+    static PassOwnPtr<MockLayerTreeHostImplProxy> create(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
+    {
+        return adoptPtr(new MockLayerTreeHostImplProxy(host, test));
+    }
+
+    PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
+    {
+        return MockLayerTreeHostImpl::create(this, m_test);
+    }
+
+private:
+    MockLayerTreeHostImplProxy(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
+        : CCLayerTreeHostImplProxy(host)
+        , m_test(test) { }
+
+    CCLayerTreeHostTest* m_test;
+};
+
+class MockLayerTreeHost : public CCLayerTreeHost {
+public:
+    MockLayerTreeHost(CCLayerTreeHostClient* client, CCLayerTreeHostTest* test)
+        : CCLayerTreeHost(client)
+        , m_test(test) { }
+
+    virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy()
+    {
+        OwnPtr<CCLayerTreeHostImplProxy> proxy = MockLayerTreeHostImplProxy::create(this, m_test);
+        proxy->start();
+        return proxy.release();
+    }
+
+    virtual void updateLayers()
+    {
+        m_test->updateLayers(this);
+    }
+
+    virtual PassOwnPtr<CCLayerTreeHostCommitter> createLayerTreeHostCommitter()
+    {
+        return MockLayerTreeHostCommitter::create(m_test);
+    }
+
+    virtual void beginCommit()
+    {
+        CCLayerTreeHost::beginCommit();
+        m_test->beginCommitOnMainThread(this);
+    }
+
+    virtual void commitComplete()
+    {
+        m_test->commitCompleteOnMainThread(this);
+        CCLayerTreeHost::commitComplete();
+    }
+
+private:
+    CCLayerTreeHostTest* m_test;
+};
+
+void CCLayerTreeHostTest::doBeginTest()
+{
+    ASSERT(!m_running);
+    m_running = true;
+    m_client = adoptPtr(new MockLayerTreeHostClient(this));
+    m_layerTreeHost = adoptRef(new MockLayerTreeHost(m_client.get(), this));
+    m_layerTreeHost->init();
+    m_beginning = true;
+    beginTest();
+    m_beginning = false;
+    if (m_endWhenBeginReturns)
+        onEndTest(static_cast<void*>(this));
+}
+
+void CCLayerTreeHostTest::endTest()
+{
+    // If we are called from the CCThread, re-call endTest on the main thread.
+    if (!isMainThread())
+        CCMainThread::postTask(createMainThreadTask(this, &CCLayerTreeHostTest::endTest));
+    else {
+        // For the case where we endTest during beginTest(), set a flag to indicate that
+        // the test should end the second beginTest regains control.
+        if (m_beginning)
+            m_endWhenBeginReturns = true;
+        else
+            onEndTest(static_cast<void*>(this));
+    }
+}
+
+// Shortlived layerTreeHosts shouldn't die.
+class CCLayerTreeHostTestShortlived1 : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestShortlived1() { }
+
+    virtual void beginTest()
+    {
+        endTest();
+    }
+
+    virtual void afterTest()
+    {
+    }
+};
+TEST_F(CCLayerTreeHostTestShortlived1, run)
+{
+    runTest();
+}
+
+// Shortlived layerTreeHosts shouldn't die with a commit in flight.
+class CCLayerTreeHostTestShortlived2 : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestShortlived2() { }
+
+    virtual void beginTest()
+    {
+        m_layerTreeHost->setNeedsCommitAndRedraw();
+        endTest();
+    }
+
+    virtual void afterTest()
+    {
+    }
+};
+TEST_F(CCLayerTreeHostTestShortlived2, run)
+{
+    runTest();
+}
+
+// Shortlived layerTreeHosts shouldn't die with a redraw in flight.
+class CCLayerTreeHostTestShortlived3 : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestShortlived3() { }
+
+    virtual void beginTest()
+    {
+        m_layerTreeHost->setNeedsRedraw();
+        endTest();
+    }
+
+    virtual void afterTest()
+    {
+    }
+};
+TEST_F(CCLayerTreeHostTestShortlived3, run)
+{
+    runTest();
+}
+
+// Constantly redrawing layerTreeHosts shouldn't die when they commit
+class CCLayerTreeHostTestCommitingWithContinuousRedraw : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestCommitingWithContinuousRedraw()
+        : m_numCompleteCommits(0)
+        , m_numDraws(0)
+    {
+    }
+
+    virtual void beginTest()
+    {
+        m_layerTreeHost->setNeedsCommitAndRedraw();
+        endTest();
+    }
+
+    virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
+    {
+        m_numCompleteCommits++;
+        if (m_numCompleteCommits == 2)
+            endTest();
+    }
+
+    virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
+    {
+        if (m_numDraws == 1)
+            layerTreeHostImpl->setNeedsCommitAndRedraw();
+        m_numDraws++;
+        layerTreeHostImpl->setNeedsRedraw();
+    }
+
+    virtual void afterTest()
+    {
+    }
+
+private:
+    int m_numCompleteCommits;
+    int m_numDraws;
+};
+TEST_F(CCLayerTreeHostTestCommitingWithContinuousRedraw, run)
+{
+    runTest();
+}
+
+// Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
+// draw with frame 0.
+class CCLayerTreeHostTestSetNeedsCommit1 : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestSetNeedsCommit1()
+        : m_numCommits(0)
+        , m_numDraws(0)
+    {
+    }
+
+    virtual void beginTest()
+    {
+        m_layerTreeHost->setNeedsCommitAndRedraw();
+        m_layerTreeHost->setNeedsCommitAndRedraw();
+    }
+
+    virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
+    {
+        m_numDraws++;
+        if (!layerTreeHostImpl->sourceFrameNumber())
+            endTest();
+    }
+
+    virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
+    {
+        m_numCommits++;
+    }
+
+    virtual void afterTest()
+    {
+        EXPECT_GE(1, m_numCommits);
+        EXPECT_GE(1, m_numDraws);
+    }
+
+private:
+    int m_numCommits;
+    int m_numDraws;
+};
+TEST_F(CCLayerTreeHostTestSetNeedsCommit1, run)
+{
+    runTest();
+}
+
+// A setNeedsCommit should lead to 1 commit. Issuing a second commit after that
+// first committed frame draws should lead to another commit.
+class CCLayerTreeHostTestSetNeedsCommit2 : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestSetNeedsCommit2()
+        : m_numCommits(0)
+        , m_numDraws(0)
+    {
+    }
+
+    virtual void beginTest()
+    {
+        m_layerTreeHost->setNeedsCommitAndRedraw();
+    }
+
+    virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
+    {
+        if (!layerTreeHostImpl->sourceFrameNumber())
+            layerTreeHostImpl->setNeedsCommitAndRedraw();
+        else if (layerTreeHostImpl->sourceFrameNumber() == 1)
+            endTest();
+    }
+
+    virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
+    {
+        m_numCommits++;
+    }
+
+    virtual void afterTest()
+    {
+        EXPECT_EQ(2, m_numCommits);
+        EXPECT_GE(2, m_numDraws);
+    }
+
+private:
+    int m_numCommits;
+    int m_numDraws;
+};
+TEST_F(CCLayerTreeHostTestSetNeedsCommit2, run)
+{
+    runTest();
+}
+
+// 1 setNeedsRedraw after the first commit has completed should lead to 1
+// additional draw.
+class CCLayerTreeHostTestSetNeedsRedraw : public CCLayerTreeHostTest {
+public:
+    CCLayerTreeHostTestSetNeedsRedraw()
+        : m_numCommits(0)
+        , m_numDraws(0)
+    {
+    }
+
+    virtual void beginTest()
+    {
+    }
+
+    virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* impl)
+    {
+        EXPECT_EQ(0, impl->sourceFrameNumber());
+        if (!m_numDraws)
+            impl->setNeedsRedraw(); // redraw again to verify that the second redraw doesnt commit.
+        else
+            endTest();
+        m_numDraws++;
+    }
+
+    virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
+    {
+        m_numCommits++;
+    }
+
+    virtual void afterTest()
+    {
+        EXPECT_GE(2, m_numDraws);
+        EXPECT_EQ(1, m_numCommits);
+    }
+
+private:
+    int m_numCommits;
+    int m_numDraws;
+};
+TEST_F(CCLayerTreeHostTestSetNeedsRedraw, run)
+{
+    runTest();
+}
+
+} // namespace
+
+#endif // USE(THREADED_COMPOSITING)
index 09c4193..e0218ce 100644 (file)
@@ -53,7 +53,7 @@ TEST(CCThreadTest, pingPongUsingCondition)
     OwnPtr<CCThread> thread = CCThread::create();
     PingPongUsingCondition target;
     CCCompletionEvent completion;
-    thread->postTask(createCCThreadTask(&target, &PingPongUsingCondition::ping, 
+    thread->postTask(createCCThreadTask(&target, &PingPongUsingCondition::ping,
                                         AllowCrossThreadAccess(&completion)));
     completion.wait();
 
index a57cfd7..ed30d72 100644 (file)
@@ -1,3 +1,13 @@
+2011-05-17  Nat Duca  <nduca@chromium.org>
+
+        Reviewed by James Robinson.
+
+        [chromium] Implement CCLayerTreeHost and CCLayerTreeHostImpl portions of threaded compositor
+        https://bugs.webkit.org/show_bug.cgi?id=58408
+
+        * DumpRenderTree/chromium/WebViewHost.cpp:
+        (WebViewHost::paintInvalidatedRegion):
+
 2011-06-24  Dominic Cooney   <dominicc@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 7ef47b3..33d5893 100644 (file)
@@ -1486,7 +1486,7 @@ void WebViewHost::paintRect(const WebRect& rect)
 void WebViewHost::paintInvalidatedRegion()
 {
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-    webWidget()->animate();
+    webWidget()->animate(0.0);
 #endif
     webWidget()->layout();
     WebSize widgetSize = webWidget()->size();