Source/WebCore/ChangeLog

 12011-09-16 Sheriff Bot <webkit.review.bot@gmail.com>
 2
 3 Unreviewed, rolling out r95309.
 4 http://trac.webkit.org/changeset/95309
 5 https://bugs.webkit.org/show_bug.cgi?id=68271
 6
 7 Broke many chromium gpu tests. (Requested by dave_levin on
 8 #webkit).
 9
 10 * platform/graphics/chromium/ContentLayerChromium.cpp:
 11 (WebCore::ContentLayerChromium::createTextureUpdater):
 12 * platform/graphics/chromium/LayerRendererChromium.cpp:
 13 (WebCore::LayerRendererChromium::LayerRendererChromium):
 14 * platform/graphics/chromium/cc/CCLayerTreeHost.h:
 15 * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
 16 * platform/graphics/chromium/cc/CCThreadProxy.cpp:
 17 (WebCore::CCThreadProxy::context):
 18 (WebCore::CCThreadProxy::beginFrameAndCommitOnCCThread):
 19 (WebCore::CCThreadProxy::setNeedsCommitAndRedrawOnCCThread):
 20 (WebCore::CCThreadProxy::setNeedsRedrawOnCCThread):
 21
1222011-09-16 Filip Pizlo <fpizlo@apple.com>
223
324 DFG JIT should inline Math.abs

Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp

@@bool ContentLayerChromium::drawsContent() const
120120
121121void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
122122{
123 #if !USE(THREADED_COMPOSITING)
124123#if USE(SKIA)
125124 // Note that host->skiaContext() will crash if called while in threaded
126125 // mode. This thus depends on CCLayerTreeHost::initialize turning off

@@void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
130129 return;
131130 }
132131#endif // SKIA
133 #endif // !THREADED_COMPOSITING
134132
135133 m_textureUpdater = LayerTextureUpdaterBitmap::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
136134}

Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

@@LayerRendererChromium::LayerRendererChromium(CCLayerTreeHostImpl* owner,
148148 , m_currentRenderSurface(0)
149149 , m_offscreenFramebufferId(0)
150150 , m_zoomAnimatorScale(1)
151  , m_contentsTextureMemoryUseBytes(0)
152151 , m_context(context)
153152 , m_defaultRenderSurface(0)
154153 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f))

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

@@public:
9999 void commitTo(CCLayerTreeHostImpl*);
100100 PassOwnPtr<CCThread> createCompositorThread();
101101 PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
102  virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
 102 PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
103103 void didRecreateGraphicsContext(bool success);
104104#if !USE(THREADED_COMPOSITING)
105105 void scheduleComposite();

@@public:
154154
155155protected:
156156 CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
157  bool initialize();
158157
159158private:
160159 typedef Vector<RefPtr<LayerChromium> > LayerList;

@@private:
165164 void updateCompositorResources(LayerChromium*, GraphicsContext3D*);
166165 void clearPendingUpdate();
167166
 167 bool initialize();
 168
168169 bool m_animating;
169170
170171 CCLayerTreeHostClient* m_client;

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h

@@public:
4646 static PassOwnPtr<CCLayerTreeHostImpl> create(const CCSettings&);
4747 virtual ~CCLayerTreeHostImpl();
4848
49  // Virtual for testing
5049 virtual void beginCommit();
5150 virtual void commitComplete();
52  virtual void drawLayers();
5351
5452 GraphicsContext3D* context();
5553
 54 void drawLayers();
 55
5656 void finishAllRendering();
5757 int frameNumber() const { return m_frameNumber; }
5858

Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp

@@bool CCThreadProxy::compositeAndReadback(void *pixels, const IntRect& rect)
8484
8585GraphicsContext3D* CCThreadProxy::context()
8686{
 87 ASSERT_NOT_REACHED();
8788 return 0;
8889}
8990

@@void CCThreadProxy::beginFrameAndCommitOnCCThread()
185186{
186187 TRACE_EVENT("CCThreadProxy::beginFrameAndCommitOnCCThread", this, 0);
187188 ASSERT(isImplThread());
188  // TEMP HACK so we can exercise this code in unit tests.
189  CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
 189 ASSERT_NOT_REACHED();
 190 // FIXME: call beginFrameAndCommit on main thread
190191}
191192
192193void CCThreadProxy::beginFrameAndCommit(double frameBeginTime)

@@void CCThreadProxy::setNeedsCommitAndRedrawOnCCThread()
246247 TRACE_EVENT("CCThreadProxy::setNeedsCommitAndRedrawOnCCThread", this, 0);
247248 ASSERT(isImplThread());
248249 ASSERT(m_layerTreeHostImpl);
249  // TEMP HACK so we can exercise this code in unit tests.
250  CCMainThread::postTask(createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, 0.0));
 250 ASSERT_NOT_REACHED();
251251}
252252
253253void CCThreadProxy::setNeedsRedrawOnCCThread()
254254{
255255 TRACE_EVENT("CCThreadProxy::setNeedsRedrawOnCCThread", this, 0);
256  // TEMP HACK so we can exercise this code in unit tests.
257  drawLayersOnCCThread();
 256 ASSERT_NOT_REACHED();
258257}
259258
260259void CCThreadProxy::initializeImplOnCCThread(CCCompletionEvent* completion)

@@void CCThreadProxy::layerTreeHostClosedOnCCThread(CCCompletionEvent* completion)
285284 completion->signal();
286285}
287286
288 } // namespace WebCore
 287}

Source/WebKit/chromium/ChangeLog

 12011-09-16 Sheriff Bot <webkit.review.bot@gmail.com>
 2
 3 Unreviewed, rolling out r95309.
 4 http://trac.webkit.org/changeset/95309
 5 https://bugs.webkit.org/show_bug.cgi?id=68271
 6
 7 Broke many chromium gpu tests. (Requested by dave_levin on
 8 #webkit).
 9
 10 * tests/CCLayerTreeHostTest.cpp:
 11 (WTF::CCLayerTreeHostTest::CCLayerTreeHostTest):
 12 (WTF::CCLayerTreeHostTest::animateAndLayout):
 13 (WTF::CCLayerTreeHostTest::beginCommitOnCCThread):
 14 (WTF::CCLayerTreeHostTest::beginCommitOnMainThread):
 15 (WTF::CCLayerTreeHostTest::commitOnCCThread):
 16 (WTF::CCLayerTreeHostTest::commitCompleteOnCCThread):
 17 (WTF::CCLayerTreeHostTest::commitCompleteOnMainThread):
 18 (WTF::CCLayerTreeHostTest::drawLayersAndPresentOnCCThread):
 19 (WTF::CCLayerTreeHostTest::updateLayers):
 20 (WTF::CCLayerTreeHostTest::onBeginTest):
 21 (WTF::CCLayerTreeHostTest::doEndTest):
 22 (WTF::CCLayerTreeHostTest::onEndTest):
 23 (WTF::CCLayerTreeHostTest::runTest):
 24 (WTF::CCLayerTreeHostTest::testTimeout):
 25 (WTF::MockLayerTreeHostClient::MockLayerTreeHostClient):
 26 (WTF::MockLayerTreeHostClient::createLayerTreeHostContext3D):
 27 (WTF::MockLayerTreeHostClient::animateAndLayout):
 28 (WTF::MockLayerTreeHostClient::updateLayers):
 29 (WTF::MockLayerTreeHostCommitter::create):
 30 (WTF::MockLayerTreeHostCommitter::commit):
 31 (WTF::MockLayerTreeHostCommitter::MockLayerTreeHostCommitter):
 32 (WTF::MockLayerTreeHostImpl::create):
 33 (WTF::MockLayerTreeHostImpl::beginCommit):
 34 (WTF::MockLayerTreeHostImpl::commitComplete):
 35 (WTF::MockLayerTreeHostImpl::drawLayersAndPresent):
 36 (WTF::MockLayerTreeHostImpl::MockLayerTreeHostImpl):
 37 (WTF::MockLayerTreeHostImplProxy::create):
 38 (WTF::MockLayerTreeHostImplProxy::createLayerTreeHostImpl):
 39 (WTF::MockLayerTreeHostImplProxy::MockLayerTreeHostImplProxy):
 40 (WTF::MockLayerTreeHost::MockLayerTreeHost):
 41 (WTF::MockLayerTreeHost::createLayerTreeHostImplProxy):
 42 (WTF::MockLayerTreeHost::updateLayers):
 43 (WTF::MockLayerTreeHost::createLayerTreeHostCommitter):
 44 (WTF::MockLayerTreeHost::beginCommit):
 45 (WTF::MockLayerTreeHost::commitComplete):
 46 (WTF::CCLayerTreeHostTest::doBeginTest):
 47 (WTF::CCLayerTreeHostTestShortlived2::beginTest):
 48 (WTF::CCLayerTreeHostTestShortlived3::beginTest):
 49 (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::beginTest):
 50 (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::commitCompleteOnCCThread):
 51 (WTF::CCLayerTreeHostTestCommitingWithContinuousRedraw::drawLayersAndPresentOnCCThread):
 52 (WTF::CCLayerTreeHostTestSetNeedsCommit1::beginTest):
 53 (WTF::CCLayerTreeHostTestSetNeedsCommit1::drawLayersAndPresentOnCCThread):
 54 (WTF::CCLayerTreeHostTestSetNeedsCommit1::commitOnCCThread):
 55 (WTF::CCLayerTreeHostTestSetNeedsCommit2::beginTest):
 56 (WTF::CCLayerTreeHostTestSetNeedsCommit2::drawLayersAndPresentOnCCThread):
 57 (WTF::CCLayerTreeHostTestSetNeedsCommit2::commitOnCCThread):
 58 (WTF::CCLayerTreeHostTestSetNeedsRedraw::beginTest):
 59 (WTF::CCLayerTreeHostTestSetNeedsRedraw::drawLayersAndPresentOnCCThread):
 60 (WTF::CCLayerTreeHostTestSetNeedsRedraw::commitOnCCThread):
 61
1622011-09-16 Iain Merrick <husky@google.com>
263
364 [chromium] Fix CCLayerTreeHostTest

Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

2828
2929#include "cc/CCLayerTreeHost.h"
3030
31 #include "CCThreadImpl.h"
32 #include "GraphicsContext3DPrivate.h"
33 #include "LayerChromium.h"
34 #include "LayerPainterChromium.h"
35 #include "MockWebGraphicsContext3D.h"
36 #include "TextureManager.h"
 31#include "GraphicsContext3D.h"
3732#include "cc/CCLayerTreeHostImpl.h"
3833#include "cc/CCMainThreadTask.h"
3934#include "cc/CCThreadTask.h"

4338#include <wtf/PassRefPtr.h>
4439#include <wtf/Vector.h>
4540
 41
4642using namespace WebCore;
47 using namespace WebKit;
4843using namespace WTF;
4944
5045namespace {
5146
52 // Used by test stubs to notify the test when something interesting happens.
53 class TestHooks {
54 public:
55  virtual void beginCommitOnCCThread(CCLayerTreeHostImpl*) { }
56  virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { }
57  virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { }
58 };
 47class MockLayerTreeHost;
 48class MockLayerTreeHostClient;
 49class MockLayerTreeHostImpl;
5950
60 // Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks.
61 class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
 51// The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated
 52// MockLayerTreeHostImpl/MockLayerTreeHostClient.
 53//
 54// beginTest() is called once the main message loop is running and the layer tree host is initialized.
 55//
 56// Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCLayerTreeHostTest methods of similar names.
 57// To track the commit process, override these functions.
 58//
 59// The test continues until someone calls endTest. endTest can be called on any thread, but be aware that
 60// ending the test is an asynchronous process.
 61class CCLayerTreeHostTest : public testing::Test {
6262public:
63  static PassOwnPtr<MockLayerTreeHostImpl> create(TestHooks* testHooks, const CCSettings& settings)
 63 CCLayerTreeHostTest()
 64 : m_beginning(false)
 65 , m_endWhenBeginReturns(false)
 66 , m_running(false)
 67 , m_timedOut(false) { }
 68
 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
 83protected:
 84 void doBeginTest();
 85
 86 static void onBeginTest(void* self)
6487 {
65  return adoptPtr(new MockLayerTreeHostImpl(testHooks, settings));
 88 static_cast<CCLayerTreeHostTest*>(self)->doBeginTest();
6689 }
6790
68  virtual void beginCommit()
 91 void doEndTest()
6992 {
70  CCLayerTreeHostImpl::beginCommit();
71  m_testHooks->beginCommitOnCCThread(this);
7293 }
7394
74  virtual void commitComplete()
 95 static void onEndTest(void* self)
7596 {
76  CCLayerTreeHostImpl::commitComplete();
77  m_testHooks->commitCompleteOnCCThread(this);
 97 ASSERT(isMainThread());
 98 CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
 99 test->m_layerTreeHost.clear();
 100 test->m_client.clear();
 101 webkit_support::QuitMessageLoop();
78102 }
79103
80  virtual void drawLayers()
 104 void runTest()
81105 {
82  CCLayerTreeHostImpl::drawLayers();
83  m_testHooks->drawLayersOnCCThread(this);
 106 webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
 107 webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast<void*>(this), 5000);
 108 webkit_support::RunMessageLoop();
 109 m_running = false;
 110 bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout.
 111 webkit_support::RunAllPendingMessages();
 112 if (timedOut) {
 113 printf("Test timed out");
 114 FAIL() << "Test timed out";
 115 return;
 116 }
 117 afterTest();
84118 }
85119
86 private:
87  MockLayerTreeHostImpl(TestHooks* testHooks, const CCSettings& settings)
88  : CCLayerTreeHostImpl(settings)
89  , m_testHooks(testHooks)
 120 static void testTimeout(void* self)
90121 {
 122 CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
 123 if (!test->m_running)
 124 return;
 125 test->m_timedOut = true;
 126 test->endTest();
91127 }
92128
93  TestHooks* m_testHooks;
 129 Mutex m_tracesLock;
 130 Vector<std::string> m_traces;
 131
 132 OwnPtr<MockLayerTreeHostClient> m_client;
 133 RefPtr<MockLayerTreeHost> m_layerTreeHost;
 134
 135private:
 136 bool m_beginning;
 137 bool m_endWhenBeginReturns;
 138 bool m_running;
 139 bool m_timedOut;
94140};
95141
96 // Adapts CCLayerTreeHost for test. Injects MockLayerTreeHostImpl.
97 class MockLayerTreeHost : public CCLayerTreeHost {
 142class MockLayerTreeHostClient : public CCLayerTreeHostClient {
98143public:
99  static PassRefPtr<MockLayerTreeHost> create(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
 144 MockLayerTreeHostClient(CCLayerTreeHostTest* test) : m_test(test) { }
 145
 146 virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
100147 {
101  return adoptRef(new MockLayerTreeHost(testHooks, client, rootLayer, settings));
 148 return adoptRef<GraphicsContext3D>(0);
102149 }
103150
104  virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
 151 virtual void animateAndLayout(double frameBeginTime)
105152 {
106  return MockLayerTreeHostImpl::create(m_testHooks, settings());
 153 m_test->animateAndLayout(this, frameBeginTime);
107154 }
108155
109 private:
110  MockLayerTreeHost(TestHooks* testHooks, CCLayerTreeHostClient* client, PassRefPtr<LayerChromium> rootLayer, const CCSettings& settings)
111  : CCLayerTreeHost(client, rootLayer, settings)
112  , m_testHooks(testHooks)
 156 virtual void updateLayers()
113157 {
114  bool success = initialize();
115  ASSERT(success);
116158 }
117159
118  TestHooks* m_testHooks;
 160private:
 161 CCLayerTreeHostTest* m_test;
119162};
120163
121 // Test stub for WebGraphicsContext3D. Returns canned values needed for compositor initialization.
122 class CompositorMockWebGraphicsContext3D : public MockWebGraphicsContext3D {
 164class MockLayerTreeHostCommitter : public CCLayerTreeHostCommitter {
123165public:
124  static PassOwnPtr<CompositorMockWebGraphicsContext3D> create()
 166 static PassOwnPtr<MockLayerTreeHostCommitter> create(CCLayerTreeHostTest* test)
125167 {
126  return adoptPtr(new CompositorMockWebGraphicsContext3D());
 168 return adoptPtr(new MockLayerTreeHostCommitter(test));
127169 }
128170
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; }
 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 }
134176
135177private:
136  CompositorMockWebGraphicsContext3D() { }
 178 MockLayerTreeHostCommitter(CCLayerTreeHostTest* test) : m_test(test) { }
 179 CCLayerTreeHostTest* m_test;
137180};
138181
139 // Implementation of CCLayerTreeHost callback interface.
140 class MockLayerTreeHostClient : public CCLayerTreeHostClient {
 182class MockLayerTreeHostImpl : public CCLayerTreeHostImpl {
141183public:
142  static PassOwnPtr<MockLayerTreeHostClient> create(TestHooks* testHooks)
143  {
144  return adoptPtr(new MockLayerTreeHostClient(testHooks));
145  }
146 
147  virtual void animateAndLayout(double frameBeginTime)
 184 static PassOwnPtr<MockLayerTreeHostImpl> create(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
148185 {
 186 return adoptPtr(new MockLayerTreeHostImpl(client, test));
149187 }
150188
151  virtual PassOwnPtr<CCThread> createCompositorThread()
 189 virtual void beginCommit()
152190 {
153  return CCThreadImpl::create();
 191 CCLayerTreeHostImpl::beginCommit();
 192 m_test->beginCommitOnCCThread(this);
154193 }
155194
156  virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D()
 195 virtual void commitComplete()
157196 {
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;
 197 CCLayerTreeHostImpl::commitComplete();
 198 m_test->commitCompleteOnCCThread(this);
162199 }
163200
164  virtual PassOwnPtr<LayerPainterChromium> createRootLayerPainter()
 201 virtual void drawLayersAndPresent()
165202 {
166  return nullptr;
 203 m_test->drawLayersAndPresentOnCCThread(this);
167204 }
168205
169  virtual void didRecreateGraphicsContext(bool)
 206private:
 207 MockLayerTreeHostImpl(CCLayerTreeHostImplClient* client, CCLayerTreeHostTest* test)
 208 : CCLayerTreeHostImpl(client)
 209 , m_test(test)
170210 {
171211 }
172212
173 private:
174  explicit MockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks(testHooks) { }
175 
176  TestHooks* m_testHooks;
 213 CCLayerTreeHostTest* m_test;
177214};
178215
179 // The CCLayerTreeHostTest runs with the main loop running. It instantiates a single MockLayerTreeHost and associated
180 // MockLayerTreeHostImpl/MockLayerTreeHostClient.
181 //
182 // beginTest() is called once the main message loop is running and the layer tree host is initialized.
183 //
184 // Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCLayerTreeHostTest methods of similar names.
185 // To track the commit process, override these functions.
186 //
187 // The test continues until someone calls endTest. endTest can be called on any thread, but be aware that
188 // ending the test is an asynchronous process.
189 class CCLayerTreeHostTest : public testing::Test, TestHooks {
 216class MockLayerTreeHostImplProxy : public CCLayerTreeHostImplProxy {
190217public:
191  virtual void afterTest() = 0;
192  virtual void beginTest() = 0;
193 
194  void endTest();
195 
196  void postSetNeedsCommitToMainThread()
 218 static PassOwnPtr<MockLayerTreeHostImplProxy> create(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
197219 {
198  callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsCommit, this);
 220 return adoptPtr(new MockLayerTreeHostImplProxy(host, test));
199221 }
200222
201  void postSetNeedsRedrawToMainThread()
 223 PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl()
202224 {
203  callOnMainThread(CCLayerTreeHostTest::dispatchSetNeedsRedraw, this);
 225 return MockLayerTreeHostImpl::create(this, m_test);
204226 }
205227
206 protected:
207  CCLayerTreeHostTest()
208  : m_beginning(false)
209  , m_endWhenBeginReturns(false)
210  , m_running(false)
211  , m_timedOut(false) { }
 228private:
 229 MockLayerTreeHostImplProxy(CCLayerTreeHost* host, CCLayerTreeHostTest* test)
 230 : CCLayerTreeHostImplProxy(host)
 231 , m_test(test) { }
212232
213  void doBeginTest();
 233 CCLayerTreeHostTest* m_test;
 234};
214235
215  static void onBeginTest(void* self)
216  {
217  static_cast<CCLayerTreeHostTest*>(self)->doBeginTest();
218  }
 236class MockLayerTreeHost : public CCLayerTreeHost {
 237public:
 238 MockLayerTreeHost(CCLayerTreeHostClient* client, CCLayerTreeHostTest* test)
 239 : CCLayerTreeHost(client)
 240 , m_test(test) { }
219241
220  static void onEndTest(void* self)
 242 virtual PassOwnPtr<CCLayerTreeHostImplProxy> createLayerTreeHostImplProxy()
221243 {
222  ASSERT(isMainThread());
223  webkit_support::QuitMessageLoop();
224  CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
225  ASSERT(test);
226  test->m_layerTreeHost.clear();
 244 OwnPtr<CCLayerTreeHostImplProxy> proxy = MockLayerTreeHostImplProxy::create(this, m_test);
 245 proxy->start();
 246 return proxy.release();
227247 }
228248
229  static void dispatchSetNeedsCommit(void* self)
 249 virtual void updateLayers()
230250 {
231  ASSERT(isMainThread());
232  CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
233  ASSERT(test);
234  if (test->m_layerTreeHost)
235  test->m_layerTreeHost->setNeedsCommitAndRedraw();
 251 m_test->updateLayers(this);
236252 }
237253
238  static void dispatchSetNeedsRedraw(void* self)
 254 virtual PassOwnPtr<CCLayerTreeHostCommitter> createLayerTreeHostCommitter()
239255 {
240  ASSERT(isMainThread());
241  CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
242  ASSERT(test);
243  if (test->m_layerTreeHost)
244  test->m_layerTreeHost->setNeedsRedraw();
 256 return MockLayerTreeHostCommitter::create(m_test);
245257 }
246258
247  void runTest()
 259 virtual void beginCommit()
248260 {
249  webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
250  webkit_support::PostDelayedTask(CCLayerTreeHostTest::testTimeout, static_cast<void*>(this), 5000);
251  webkit_support::RunMessageLoop();
252  m_running = false;
253  bool timedOut = m_timedOut; // Save whether we're timed out in case RunAllPendingMessages has the timeout.
254  webkit_support::RunAllPendingMessages();
255  ASSERT(!m_layerTreeHost.get());
256  m_client.clear();
257  if (timedOut) {
258  FAIL() << "Test timed out";
259  return;
260  }
261  afterTest();
 261 CCLayerTreeHost::beginCommit();
 262 m_test->beginCommitOnMainThread(this);
262263 }
263264
264  static void testTimeout(void* self)
 265 virtual void commitComplete()
265266 {
266  CCLayerTreeHostTest* test = static_cast<CCLayerTreeHostTest*>(self);
267  if (!test->m_running)
268  return;
269  test->m_timedOut = true;
270  test->endTest();
 267 m_test->commitCompleteOnMainThread(this);
 268 CCLayerTreeHost::commitComplete();
271269 }
272270
273  OwnPtr<MockLayerTreeHostClient> m_client;
274  RefPtr<CCLayerTreeHost> m_layerTreeHost;
275 
276271private:
277  bool m_beginning;
278  bool m_endWhenBeginReturns;
279  bool m_running;
280  bool m_timedOut;
 272 CCLayerTreeHostTest* m_test;
281273};
282274
283275void CCLayerTreeHostTest::doBeginTest()
284276{
285  ASSERT(isMainThread());
286277 ASSERT(!m_running);
287278 m_running = true;
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 
 279 m_client = adoptPtr(new MockLayerTreeHostClient(this));
 280 m_layerTreeHost = adoptRef(new MockLayerTreeHost(m_client.get(), this));
 281 m_layerTreeHost->init();
296282 m_beginning = true;
297283 beginTest();
298284 m_beginning = false;

@@public:
341327
342328 virtual void beginTest()
343329 {
344  postSetNeedsCommitToMainThread();
 330 m_layerTreeHost->setNeedsCommitAndRedraw();
345331 endTest();
346332 }
347333

@@public:
361347
362348 virtual void beginTest()
363349 {
364  postSetNeedsRedrawToMainThread();
 350 m_layerTreeHost->setNeedsRedraw();
365351 endTest();
366352 }
367353

@@public:
385371
386372 virtual void beginTest()
387373 {
388  postSetNeedsCommitToMainThread();
 374 m_layerTreeHost->setNeedsCommitAndRedraw();
389375 endTest();
390376 }
391377
392  virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
 378 virtual void commitCompleteOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
393379 {
394380 m_numCompleteCommits++;
395381 if (m_numCompleteCommits == 2)
396382 endTest();
397383 }
398384
399  virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*)
 385 virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
400386 {
401387 if (m_numDraws == 1)
402  postSetNeedsCommitToMainThread();
 388 layerTreeHostImpl->setNeedsCommitAndRedraw();
403389 m_numDraws++;
404  postSetNeedsRedrawToMainThread();
 390 layerTreeHostImpl->setNeedsRedraw();
405391 }
406392
407393 virtual void afterTest()

@@public:
429415
430416 virtual void beginTest()
431417 {
432  postSetNeedsCommitToMainThread();
433  postSetNeedsCommitToMainThread();
 418 m_layerTreeHost->setNeedsCommitAndRedraw();
 419 m_layerTreeHost->setNeedsCommitAndRedraw();
434420 }
435421
436  virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
 422 virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
437423 {
438424 m_numDraws++;
439  if (!impl->sourceFrameNumber())
 425 if (!layerTreeHostImpl->sourceFrameNumber())
440426 endTest();
441427 }
442428
443  virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
 429 virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
444430 {
445431 m_numCommits++;
446432 }

@@public:
472458
473459 virtual void beginTest()
474460 {
475  postSetNeedsCommitToMainThread();
 461 m_layerTreeHost->setNeedsCommitAndRedraw();
476462 }
477463
478  virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
 464 virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* layerTreeHostImpl)
479465 {
480  if (!impl->sourceFrameNumber())
481  postSetNeedsCommitToMainThread();
482  else if (impl->sourceFrameNumber() == 1)
 466 if (!layerTreeHostImpl->sourceFrameNumber())
 467 layerTreeHostImpl->setNeedsCommitAndRedraw();
 468 else if (layerTreeHostImpl->sourceFrameNumber() == 1)
483469 endTest();
484470 }
485471
486  virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
 472 virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
487473 {
488474 m_numCommits++;
489475 }

@@public:
515501
516502 virtual void beginTest()
517503 {
518  postSetNeedsCommitToMainThread();
519504 }
520505
521  virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
 506 virtual void drawLayersAndPresentOnCCThread(MockLayerTreeHostImpl* impl)
522507 {
523508 EXPECT_EQ(0, impl->sourceFrameNumber());
524509 if (!m_numDraws)
525  postSetNeedsRedrawToMainThread(); // Redraw again to verify that the second redraw doesn't commit.
 510 impl->setNeedsRedraw(); // redraw again to verify that the second redraw doesnt commit.
526511 else
527512 endTest();
528513 m_numDraws++;
529514 }
530515
531  virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
 516 virtual void commitOnCCThread(MockLayerTreeHost* layerTreeHost, MockLayerTreeHostImpl* impl)
532517 {
533518 m_numCommits++;
534519 }