Changeset 95309 in webkit


Ignore:
Timestamp:
Sep 16, 2011 11:43:37 AM (13 years ago)
Author:
jamesr@google.com
Message:

[chromium] Fix CCLayerTreeHostTest
https://bugs.webkit.org/show_bug.cgi?id=67418

Source/WebCore:

This is a minimal set of changes to get CCLayerTreeHostTest
compiling, running and passing with USE_THREADED_COMPOSITING
enabled.

Patch by Iain Merrick <husky@google.com> on 2011-09-16
Reviewed by James Robinson.

  • platform/graphics/chromium/ContentLayerChromium.cpp:

(WebCore::ContentLayerChromium::createTextureUpdater):

  • platform/graphics/chromium/LayerRendererChromium.cpp:

(WebCore::LayerRendererChromium::LayerRendererChromium):

  • platform/graphics/chromium/cc/CCLayerTreeHost.cpp:

(WebCore::CCLayerTreeHost::createLayerTreeHostImpl):

  • platform/graphics/chromium/cc/CCLayerTreeHost.h:
  • platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
  • platform/graphics/chromium/cc/CCThreadProxy.cpp:

(WebCore::CCThreadProxy::context):
(WebCore::CCThreadProxy::beginFrameAndCommitOnCCThread):
(WebCore::CCThreadProxy::setNeedsCommitAndRedrawOnCCThread):
(WebCore::CCThreadProxy::setNeedsRedrawOnCCThread):

Source/WebKit/chromium:

Fixes needed to compile and link with USE_THREADED_COMPOSITING
enabled, and to pass the basic unit test.

Patch by Iain Merrick <husky@google.com> on 2011-09-16
Reviewed by James Robinson.

  • src/GraphicsContext3DChromium.cpp:

(WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
(WebCore::GraphicsContext3DPrivate::platformLayer):

  • src/GraphicsContext3DPrivate.h:
  • tests/CCLayerTreeHostTest.cpp:

(TestHooks::beginCommitOnCCThread):
(TestHooks::commitCompleteOnCCThread):
(TestHooks::drawLayersOnCCThread):
(MockLayerTreeHostImpl::MockLayerTreeHostImpl):
(MockLayerTreeHostImpl::beginCommit):
(MockLayerTreeHostImpl::commitComplete):
(MockLayerTreeHostImpl::drawLayers):
(MockLayerTreeHost::MockLayerTreeHost):
(MockLayerTreeHost::createLayerTreeHostImpl):
(CompositorMockWebGraphicsContext3D::makeContextCurrent):
(CompositorMockWebGraphicsContext3D::createProgram):
(CompositorMockWebGraphicsContext3D::createShader):
(CompositorMockWebGraphicsContext3D::getShaderiv):
(CompositorMockWebGraphicsContext3D::getProgramiv):
(MockLayerTreeHostClient::MockLayerTreeHostClient):
(MockLayerTreeHostClient::animateAndLayout):
(MockLayerTreeHostClient::createCompositorThread):
(MockLayerTreeHostClient::createLayerTreeHostContext3D):
(MockLayerTreeHostClient::createRootLayerPainter):
(MockLayerTreeHostClient::didRecreateGraphicsContext):
(CCLayerTreeHostTest::postSetNeedsCommitToMainThread):
(CCLayerTreeHostTest::postSetNeedsRedrawToMainThread):
(CCLayerTreeHostTest::onEndTest):
(CCLayerTreeHostTest::dispatchSetNeedsCommit):
(CCLayerTreeHostTest::dispatchSetNeedsRedraw):
(CCLayerTreeHostTest::runTest):
(CCLayerTreeHostTest::doBeginTest):
(CCLayerTreeHostTestShortlived2::beginTest):
(CCLayerTreeHostTestShortlived3::beginTest):
(CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest):
(CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread):
(CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersOnCCThread):
(CCLayerTreeHostTestSetNeedsCommit1::beginTest):
(CCLayerTreeHostTestSetNeedsCommit1::drawLayersOnCCThread):
(CCLayerTreeHostTestSetNeedsCommit1::commitCompleteOnCCThread):
(CCLayerTreeHostTestSetNeedsCommit2::beginTest):
(CCLayerTreeHostTestSetNeedsCommit2::drawLayersOnCCThread):
(CCLayerTreeHostTestSetNeedsCommit2::commitCompleteOnCCThread):
(CCLayerTreeHostTestSetNeedsRedraw::beginTest):
(CCLayerTreeHostTestSetNeedsRedraw::drawLayersOnCCThread):
(CCLayerTreeHostTestSetNeedsRedraw::commitCompleteOnCCThread):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r95307 r95309  
     12011-09-16  Iain Merrick  <husky@google.com>
     2
     3        [chromium] Fix CCLayerTreeHostTest
     4        https://bugs.webkit.org/show_bug.cgi?id=67418
     5
     6        This is a minimal set of changes to get CCLayerTreeHostTest
     7        compiling, running and passing with USE_THREADED_COMPOSITING
     8        enabled.
     9
     10        Reviewed by James Robinson.
     11
     12        * platform/graphics/chromium/ContentLayerChromium.cpp:
     13        (WebCore::ContentLayerChromium::createTextureUpdater):
     14        * platform/graphics/chromium/LayerRendererChromium.cpp:
     15        (WebCore::LayerRendererChromium::LayerRendererChromium):
     16        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
     17        (WebCore::CCLayerTreeHost::createLayerTreeHostImpl):
     18        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
     19        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
     20        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
     21        (WebCore::CCThreadProxy::context):
     22        (WebCore::CCThreadProxy::beginFrameAndCommitOnCCThread):
     23        (WebCore::CCThreadProxy::setNeedsCommitAndRedrawOnCCThread):
     24        (WebCore::CCThreadProxy::setNeedsRedrawOnCCThread):
     25
    1262011-09-16  Sheriff Bot  <webkit.review.bot@gmail.com>
    227
  • trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp

    r95148 r95309  
    121121void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
    122122{
     123#if !USE(THREADED_COMPOSITING)
    123124#if USE(SKIA)
    124125    // Note that host->skiaContext() will crash if called while in threaded
     
    130131    }
    131132#endif // SKIA
     133#endif // !THREADED_COMPOSITING
    132134
    133135    m_textureUpdater = LayerTextureUpdaterBitmap::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r95135 r95309  
    149149    , m_offscreenFramebufferId(0)
    150150    , m_zoomAnimatorScale(1)
     151    , m_contentsTextureMemoryUseBytes(0)
    151152    , m_context(context)
    152153    , m_defaultRenderSurface(0)
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

    r95152 r95309  
    100100    PassOwnPtr<CCThread> createCompositorThread();
    101101    PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
    102     PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
     102    virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
    103103    void didRecreateGraphicsContext(bool success);
    104104#if !USE(THREADED_COMPOSITING)
     
    155155protected:
    156156    CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
     157    bool initialize();
    157158
    158159private:
     
    164165    void updateCompositorResources(LayerChromium*, GraphicsContext3D*);
    165166    void clearPendingUpdate();
    166 
    167     bool initialize();
    168167
    169168    bool m_animating;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h

    r95135 r95309  
    4747    virtual ~CCLayerTreeHostImpl();
    4848
     49    // Virtual for testing
    4950    virtual void beginCommit();
    5051    virtual void commitComplete();
     52    virtual void drawLayers();
    5153
    5254    GraphicsContext3D* context();
    53 
    54     void drawLayers();
    5555
    5656    void finishAllRendering();
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp

    r95100 r95309  
    8585GraphicsContext3D* CCThreadProxy::context()
    8686{
    87     ASSERT_NOT_REACHED();
    8887    return 0;
    8988}
     
    187186    TRACE_EVENT("CCThreadProxy::beginFrameAndCommitOnCCThread", this, 0);
    188187    ASSERT(isImplThread());
    189     ASSERT_NOT_REACHED();
    190     // FIXME: call beginFrameAndCommit on main thread
     188    // TEMP HACK so we can exercise this code in unit tests.
     189    CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
    191190}
    192191
     
    248247    ASSERT(isImplThread());
    249248    ASSERT(m_layerTreeHostImpl);
    250     ASSERT_NOT_REACHED();
     249    // TEMP HACK so we can exercise this code in unit tests.
     250    CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
    251251}
    252252
     
    254254{
    255255    TRACE_EVENT("CCThreadProxy::setNeedsRedrawOnCCThread", this, 0);
    256     ASSERT_NOT_REACHED();
     256    // TEMP HACK so we can exercise this code in unit tests.
     257    drawLayersOnCCThread();
    257258}
    258259
     
    285286}
    286287
    287 }
     288} // namespace WebCore
  • trunk/Source/WebKit/chromium/ChangeLog

    r95289 r95309  
     12011-09-16  Iain Merrick  <husky@google.com>
     2
     3        [chromium] Fix CCLayerTreeHostTest
     4        https://bugs.webkit.org/show_bug.cgi?id=67418
     5
     6        Fixes needed to compile and link with USE_THREADED_COMPOSITING
     7        enabled, and to pass the basic unit test.
     8
     9        Reviewed by James Robinson.
     10
     11        * src/GraphicsContext3DChromium.cpp:
     12        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
     13        (WebCore::GraphicsContext3DPrivate::platformLayer):
     14        * src/GraphicsContext3DPrivate.h:
     15        * tests/CCLayerTreeHostTest.cpp:
     16        (TestHooks::beginCommitOnCCThread):
     17        (TestHooks::commitCompleteOnCCThread):
     18        (TestHooks::drawLayersOnCCThread):
     19        (MockLayerTreeHostImpl::MockLayerTreeHostImpl):
     20        (MockLayerTreeHostImpl::beginCommit):
     21        (MockLayerTreeHostImpl::commitComplete):
     22        (MockLayerTreeHostImpl::drawLayers):
     23        (MockLayerTreeHost::MockLayerTreeHost):
     24        (MockLayerTreeHost::createLayerTreeHostImpl):
     25        (CompositorMockWebGraphicsContext3D::makeContextCurrent):
     26        (CompositorMockWebGraphicsContext3D::createProgram):
     27        (CompositorMockWebGraphicsContext3D::createShader):
     28        (CompositorMockWebGraphicsContext3D::getShaderiv):
     29        (CompositorMockWebGraphicsContext3D::getProgramiv):
     30        (MockLayerTreeHostClient::MockLayerTreeHostClient):
     31        (MockLayerTreeHostClient::animateAndLayout):
     32        (MockLayerTreeHostClient::createCompositorThread):
     33        (MockLayerTreeHostClient::createLayerTreeHostContext3D):
     34        (MockLayerTreeHostClient::createRootLayerPainter):
     35        (MockLayerTreeHostClient::didRecreateGraphicsContext):
     36        (CCLayerTreeHostTest::postSetNeedsCommitToMainThread):
     37        (CCLayerTreeHostTest::postSetNeedsRedrawToMainThread):
     38        (CCLayerTreeHostTest::onEndTest):
     39        (CCLayerTreeHostTest::dispatchSetNeedsCommit):
     40        (CCLayerTreeHostTest::dispatchSetNeedsRedraw):
     41        (CCLayerTreeHostTest::runTest):
     42        (CCLayerTreeHostTest::doBeginTest):
     43        (CCLayerTreeHostTestShortlived2::beginTest):
     44        (CCLayerTreeHostTestShortlived3::beginTest):
     45        (CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest):
     46        (CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread):
     47        (CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersOnCCThread):
     48        (CCLayerTreeHostTestSetNeedsCommit1::beginTest):
     49        (CCLayerTreeHostTestSetNeedsCommit1::drawLayersOnCCThread):
     50        (CCLayerTreeHostTestSetNeedsCommit1::commitCompleteOnCCThread):
     51        (CCLayerTreeHostTestSetNeedsCommit2::beginTest):
     52        (CCLayerTreeHostTestSetNeedsCommit2::drawLayersOnCCThread):
     53        (CCLayerTreeHostTestSetNeedsCommit2::commitCompleteOnCCThread):
     54        (CCLayerTreeHostTestSetNeedsRedraw::beginTest):
     55        (CCLayerTreeHostTestSetNeedsRedraw::drawLayersOnCCThread):
     56        (CCLayerTreeHostTestSetNeedsRedraw::commitCompleteOnCCThread):
     57
    1582011-09-16  Andrey Kosyakov  <caseq@chromium.org>
    259
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r89837 r95309  
    2929#include "cc/CCLayerTreeHost.h"
    3030
    31 #include "GraphicsContext3D.h"
     31#include "CCThreadImpl.h"
     32#include "GraphicsContext3DPrivate.h"
     33#include "LayerChromium.h"
     34#include "LayerPainterChromium.h"
     35#include "MockWebGraphicsContext3D.h"
     36#include "TextureManager.h"
    3237#include "cc/CCLayerTreeHostImpl.h"
    3338#include "cc/CCMainThreadTask.h"
     
    3944#include <wtf/Vector.h>
    4045
    41 
    4246using namespace WebCore;
     47using namespace WebKit;
    4348using namespace WTF;
    4449
    4550namespace {
    4651
    47 class MockLayerTreeHost;
    48 class MockLayerTreeHostClient;
    49 class MockLayerTreeHostImpl;
     52// Used by test stubs to notify the test when something interesting happens.
     53class TestHooks {
     54public:
     55    virtual void beginCommitOnCCThread(CCLayerTreeHostImpl*) { }
     56    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { }
     57    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { }
     58};
     59
     60// Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks.
     61class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
     62public:
     63    static PassOwnPtr<MockLayerTreeHostImpl> create(TestHooks* testHooks, const CCSettings& settings)
     64    {
     65        return adoptPtr(new MockLayerTreeHostImpl(testHooks, settings));
     66    }
     67
     68    virtual void beginCommit()
     69    {
     70        CCLayerTreeHostImpl::beginCommit();
     71        m_testHooks->beginCommitOnCCThread(this);
     72    }
     73
     74    virtual void commitComplete()
     75    {
     76        CCLayerTreeHostImpl::commitComplete();
     77        m_testHooks->commitCompleteOnCCThread(this);
     78    }
     79
     80    virtual void drawLayers()
     81    {
     82        CCLayerTreeHostImpl::drawLayers();
     83        m_testHooks->drawLayersOnCCThread(this);
     84    }
     85
     86private:
     87    MockLayerTreeHostImpl(TestHooks* testHooks, const CCSettings& settings)
     88        : CCLayerTreeHostImpl(settings)
     89        , m_testHooks(testHooks)
     90    {
     91    }
     92
     93    TestHooks* m_testHooks;
     94};
     95
     96// Adapts CCLayerTreeHost for test. Injects MockLayerTreeHostImpl.
     97class MockLayerTreeHost : public CCLayerTreeHost {
     98public:
     99    static PassRefPtr<MockLayerTreeHost> create(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
     100    {
     101        return adoptRef(new MockLayerTreeHost(testHooks, client, rootLayer, settings));
     102    }
     103
     104    virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
     105    {
     106        return MockLayerTreeHostImpl::create(m_testHooks, settings());
     107    }
     108
     109private:
     110    MockLayerTreeHost(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
     111        : CCLayerTreeHost(client, rootLayer, settings)
     112        , m_testHooks(testHooks)
     113    {
     114        bool success = initialize();
     115        ASSERT(success);
     116    }
     117
     118    TestHooks* m_testHooks;
     119};
     120
     121// Test stub for WebGraphicsContext3D. Returns canned values needed for compositor initialization.
     122class CompositorMockWebGraphicsContext3D : public MockWebGraphicsContext3D {
     123public:
     124    static PassOwnPtr<CompositorMockWebGraphicsContext3D> create()
     125    {
     126        return adoptPtr(new CompositorMockWebGraphicsContext3D());
     127    }
     128
     129    virtual bool makeContextCurrent() { return true; }
     130    virtual WebGLId createProgram() { return 1; }
     131    virtual WebGLId createShader(WGC3Denum) { return 1; }
     132    virtual void getShaderiv(WebGLId, WGC3Denum, WGC3Dint* value) { *value = 1; }
     133    virtual void getProgramiv(WebGLId, WGC3Denum, WGC3Dint* value) { *value = 1; }
     134
     135private:
     136    CompositorMockWebGraphicsContext3D() { }
     137};
     138
     139// Implementation of CCLayerTreeHost callback interface.
     140class MockLayerTreeHostClient : public CCLayerTreeHostClient {
     141public:
     142    static PassOwnPtr<MockLayerTreeHostClient> create(TestHooks* testHooks)
     143    {
     144        return adoptPtr(new MockLayerTreeHostClient(testHooks));
     145    }
     146
     147    virtual void animateAndLayout(double frameBeginTime)
     148    {
     149    }
     150
     151    virtual PassOwnPtr<CCThread> createCompositorThread()
     152    {
     153        return CCThreadImpl::create();
     154    }
     155
     156    virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
     157    {
     158        OwnPtr<WebGraphicsContext3D> mock = CompositorMockWebGraphicsContext3D::create();
     159        GraphicsContext3D::Attributes attrs;
     160        RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(mock.release(), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow, GraphicsContext3DPrivate::ForUseOnAnotherThread);
     161        return context;
     162    }
     163
     164    virtual PassOwnPtr<LayerPainterChromium> createRootLayerPainter()
     165    {
     166        return nullptr;
     167    }
     168
     169    virtual void didRecreateGraphicsContext(bool)
     170    {
     171    }
     172
     173private:
     174    explicit MockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks(testHooks) { }
     175
     176    TestHooks* m_testHooks;
     177};
    50178
    51179// The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated
     
    59187// The test continues until someone calls endTest. endTest can be called on any thread, but be aware that
    60188// ending the test is an asynchronous process.
    61 class CCLayerTreeHostTest : public testing::Test {
    62 public:
     189class CCLayerTreeHostTest : public testing::Test, TestHooks {
     190public:
     191    virtual void afterTest() = 0;
     192    virtual void beginTest() = 0;
     193
     194    void endTest();
     195
     196    void postSetNeedsCommitToMainThread()
     197    {
     198        callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsCommit, this);
     199    }
     200
     201    void postSetNeedsRedrawToMainThread()
     202    {
     203        callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsRedraw, this);
     204    }
     205
     206protected:
    63207    CCLayerTreeHostTest()
    64208        : m_beginning(false)
     
    67211        , m_timedOut(false) { }
    68212
    69     virtual void afterTest() = 0;
    70 
    71     virtual void beginTest() = 0;
    72     virtual void animateAndLayout(MockLayerTreeHostClient* layerTreeHost, double frameBeginTime) { }
    73     virtual void beginCommitOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
    74     virtual void beginCommitOnMainThread(MockLayerTreeHost* layerTreeHost) { }
    75     virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* layerTreeHostImpl) { }
    76     virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
    77     virtual void commitCompleteOnMainThread(MockLayerTreeHost* layerTreeHost) { }
    78     virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl) { }
    79     virtual void updateLayers(MockLayerTreeHost* layerTreeHost) { }
    80 
    81     void endTest();
    82 
    83 protected:
    84213    void doBeginTest();
    85214
     
    89218    }
    90219
    91     void doEndTest()
    92     {
    93     }
    94 
    95220    static void onEndTest(void* self)
    96221    {
    97222        ASSERT(isMainThread());
     223        webkit_support::QuitMessageLoop();
    98224        CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
     225        ASSERT(test);
    99226        test->m_layerTreeHost.clear();
    100         test->m_client.clear();
    101         webkit_support::QuitMessageLoop();
     227    }
     228
     229    static void dispatchSetNeedsCommit(void* self)
     230    {
     231      ASSERT(isMainThread());
     232      CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
     233      ASSERT(test);
     234      if (test->m_layerTreeHost)
     235          test->m_layerTreeHost->setNeedsCommitAndRedraw();
     236    }
     237
     238    static void dispatchSetNeedsRedraw(void* self)
     239    {
     240      ASSERT(isMainThread());
     241      CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
     242      ASSERT(test);
     243      if (test->m_layerTreeHost)
     244          test->m_layerTreeHost->setNeedsRedraw();
    102245    }
    103246
     
    110253        bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout.
    111254        webkit_support::RunAllPendingMessages();
     255        ASSERT(!m_layerTreeHost.get());
     256        m_client.clear();
    112257        if (timedOut) {
    113             printf("Test timed out");
    114258            FAIL() << "Test timed out";
    115259            return;
     
    127271    }
    128272
    129     Mutex m_tracesLock;
    130     Vector<std::string> m_traces;
    131 
    132273    OwnPtr<MockLayerTreeHostClient> m_client;
    133     RefPtr<MockLayerTreeHost> m_layerTreeHost;
     274    RefPtr<CCLayerTreeHost> m_layerTreeHost;
    134275
    135276private:
     
    140281};
    141282
    142 class MockLayerTreeHostClient : public CCLayerTreeHostClient {
    143 public:
    144     MockLayerTreeHostClient(CCLayerTreeHostTest* test) : m_test(test) { }
    145 
    146     virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
    147     {
    148         return adoptRef<GraphicsContext3D>(0);
    149     }
    150 
    151     virtual void animateAndLayout(double frameBeginTime)
    152     {
    153         m_test->animateAndLayout(this, frameBeginTime);
    154     }
    155 
    156     virtual void updateLayers()
    157     {
    158     }
    159 
    160 private:
    161     CCLayerTreeHostTest* m_test;
    162 };
    163 
    164 class MockLayerTreeHostCommitter : public CCLayerTreeHostCommitter {
    165 public:
    166     static PassOwnPtr<MockLayerTreeHostCommitter> create(CCLayerTreeHostTest* test)
    167     {
    168         return adoptPtr(new MockLayerTreeHostCommitter(test));
    169     }
    170 
    171     virtual void commit(CCLayerTreeHost* host, CCLayerTreeHostImpl* hostImpl)
    172     {
    173         CCLayerTreeHostCommitter::commit(host, hostImpl);
    174         m_test->commitOnCCThread(reinterpret_cast<MockLayerTreeHost*>(host), reinterpret_cast<MockLayerTreeHostImpl*>(hostImpl));
    175     }
    176 
    177 private:
    178     MockLayerTreeHostCommitter(CCLayerTreeHostTest* test) : m_test(test) { }
    179     CCLayerTreeHostTest* m_test;
    180 };
    181 
    182 class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
    183 public:
    184     static PassOwnPtr<MockLayerTreeHostImpl> create(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
    185     {
    186         return adoptPtr(new MockLayerTreeHostImpl(client, test));
    187     }
    188 
    189     virtual void beginCommit()
    190     {
    191         CCLayerTreeHostImpl::beginCommit();
    192         m_test->beginCommitOnCCThread(this);
    193     }
    194 
    195     virtual void commitComplete()
    196     {
    197         CCLayerTreeHostImpl::commitComplete();
    198         m_test->commitCompleteOnCCThread(this);
    199     }
    200 
    201     virtual void drawLayersAndPresent()
    202     {
    203         m_test->drawLayersAndPresentOnCCThread(this);
    204     }
    205 
    206 private:
    207     MockLayerTreeHostImpl(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
    208             : CCLayerTreeHostImpl(client)
    209             , m_test(test)
    210     {
    211     }
    212 
    213     CCLayerTreeHostTest* m_test;
    214 };
    215 
    216 class MockLayerTreeHostImplProxy : public CCLayerTreeHostImplProxy {
    217 public:
    218     static PassOwnPtr<MockLayerTreeHostImplProxy> create(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
    219     {
    220         return adoptPtr(new MockLayerTreeHostImplProxy(host, test));
    221     }
    222 
    223     PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
    224     {
    225         return MockLayerTreeHostImpl::create(this, m_test);
    226     }
    227 
    228 private:
    229     MockLayerTreeHostImplProxy(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
    230         : CCLayerTreeHostImplProxy(host)
    231         , m_test(test) { }
    232 
    233     CCLayerTreeHostTest* m_test;
    234 };
    235 
    236 class MockLayerTreeHost : public CCLayerTreeHost {
    237 public:
    238     MockLayerTreeHost(CCLayerTreeHostClient* client, CCLayerTreeHostTest* test)
    239         : CCLayerTreeHost(client)
    240         , m_test(test) { }
    241 
    242     virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy()
    243     {
    244         OwnPtr<CCLayerTreeHostImplProxy> proxy = MockLayerTreeHostImplProxy::create(this, m_test);
    245         proxy->start();
    246         return proxy.release();
    247     }
    248 
    249     virtual void updateLayers()
    250     {
    251         m_test->updateLayers(this);
    252     }
    253 
    254     virtual PassOwnPtr<CCLayerTreeHostCommitter> createLayerTreeHostCommitter()
    255     {
    256         return MockLayerTreeHostCommitter::create(m_test);
    257     }
    258 
    259     virtual void beginCommit()
    260     {
    261         CCLayerTreeHost::beginCommit();
    262         m_test->beginCommitOnMainThread(this);
    263     }
    264 
    265     virtual void commitComplete()
    266     {
    267         m_test->commitCompleteOnMainThread(this);
    268         CCLayerTreeHost::commitComplete();
    269     }
    270 
    271 private:
    272     CCLayerTreeHostTest* m_test;
    273 };
    274 
    275283void CCLayerTreeHostTest::doBeginTest()
    276284{
     285    ASSERT(isMainThread());
    277286    ASSERT(!m_running);
    278287    m_running = true;
    279     m_client = adoptPtr(new MockLayerTreeHostClient(this));
    280     m_layerTreeHost = adoptRef(new MockLayerTreeHost(m_client.get(), this));
    281     m_layerTreeHost->init();
     288    m_client = MockLayerTreeHostClient::create(this);
     289
     290    CCSettings settings;
     291    settings.enableCompositorThread = true;
     292    RefPtr<LayerChromium> rootLayer;
     293    m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, settings);
     294    ASSERT(m_layerTreeHost);
     295
    282296    m_beginning = true;
    283297    beginTest();
     
    328342    virtual void beginTest()
    329343    {
    330         m_layerTreeHost->setNeedsCommitAndRedraw();
     344        postSetNeedsCommitToMainThread();
    331345        endTest();
    332346    }
     
    348362    virtual void beginTest()
    349363    {
    350         m_layerTreeHost->setNeedsRedraw();
     364        postSetNeedsRedrawToMainThread();
    351365        endTest();
    352366    }
     
    372386    virtual void beginTest()
    373387    {
    374         m_layerTreeHost->setNeedsCommitAndRedraw();
     388        postSetNeedsCommitToMainThread();
    375389        endTest();
    376390    }
    377391
    378     virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
     392    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
    379393    {
    380394        m_numCompleteCommits++;
     
    383397    }
    384398
    385     virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
     399    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*)
    386400    {
    387401        if (m_numDraws == 1)
    388             layerTreeHostImpl->setNeedsCommitAndRedraw();
     402          postSetNeedsCommitToMainThread();
    389403        m_numDraws++;
    390         layerTreeHostImpl->setNeedsRedraw();
     404        postSetNeedsRedrawToMainThread();
    391405    }
    392406
     
    416430    virtual void beginTest()
    417431    {
    418         m_layerTreeHost->setNeedsCommitAndRedraw();
    419         m_layerTreeHost->setNeedsCommitAndRedraw();
    420     }
    421 
    422     virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
     432        postSetNeedsCommitToMainThread();
     433        postSetNeedsCommitToMainThread();
     434    }
     435
     436    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
    423437    {
    424438        m_numDraws++;
    425         if (!layerTreeHostImpl->sourceFrameNumber())
     439        if (!impl->sourceFrameNumber())
    426440            endTest();
    427441    }
    428442
    429     virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
     443    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
    430444    {
    431445        m_numCommits++;
     
    459473    virtual void beginTest()
    460474    {
    461         m_layerTreeHost->setNeedsCommitAndRedraw();
    462     }
    463 
    464     virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
    465     {
    466         if (!layerTreeHostImpl->sourceFrameNumber())
    467             layerTreeHostImpl->setNeedsCommitAndRedraw();
    468         else if (layerTreeHostImpl->sourceFrameNumber() == 1)
     475        postSetNeedsCommitToMainThread();
     476    }
     477
     478    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
     479    {
     480        if (!impl->sourceFrameNumber())
     481            postSetNeedsCommitToMainThread();
     482        else if (impl->sourceFrameNumber() == 1)
    469483            endTest();
    470484    }
    471485
    472     virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
     486    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
    473487    {
    474488        m_numCommits++;
     
    502516    virtual void beginTest()
    503517    {
    504     }
    505 
    506     virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* impl)
     518        postSetNeedsCommitToMainThread();
     519    }
     520
     521    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
    507522    {
    508523        EXPECT_EQ(0, impl->sourceFrameNumber());
    509524        if (!m_numDraws)
    510             impl->setNeedsRedraw(); // redraw again to verify that the second redraw doesnt commit.
     525            postSetNeedsRedrawToMainThread(); // Redraw again to verify that the second redraw doesn't commit.
    511526        else
    512527            endTest();
     
    514529    }
    515530
    516     virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
     531    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
    517532    {
    518533        m_numCommits++;
Note: See TracChangeset for help on using the changeset viewer.