OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/test/layer_tree_test_common.h" | 5 #include "cc/test/layer_tree_test_common.h" |
6 | 6 |
7 #include "cc/active_animation.h" | 7 #include "cc/active_animation.h" |
8 #include "cc/animation_registrar.h" | 8 #include "cc/animation_registrar.h" |
9 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
10 #include "cc/font_atlas.h" | 10 #include "cc/font_atlas.h" |
11 #include "cc/input_handler.h" | 11 #include "cc/input_handler.h" |
12 #include "cc/layer.h" | 12 #include "cc/layer.h" |
13 #include "cc/layer_animation_controller.h" | 13 #include "cc/layer_animation_controller.h" |
14 #include "cc/layer_impl.h" | 14 #include "cc/layer_impl.h" |
15 #include "cc/layer_tree_host_impl.h" | 15 #include "cc/layer_tree_host_impl.h" |
16 #include "cc/scoped_thread_proxy.h" | |
17 #include "cc/single_thread_proxy.h" | 16 #include "cc/single_thread_proxy.h" |
18 #include "cc/thread_impl.h" | 17 #include "cc/thread_impl.h" |
19 #include "cc/test/animation_test_common.h" | 18 #include "cc/test/animation_test_common.h" |
20 #include "cc/test/fake_output_surface.h" | 19 #include "cc/test/fake_output_surface.h" |
21 #include "cc/test/occlusion_tracker_test_common.h" | 20 #include "cc/test/occlusion_tracker_test_common.h" |
22 #include "cc/test/tiled_layer_test_common.h" | 21 #include "cc/test/tiled_layer_test_common.h" |
23 #include "cc/timing_function.h" | 22 #include "cc/timing_function.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" |
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 TestHooks* m_testHooks; | 218 TestHooks* m_testHooks; |
220 }; | 219 }; |
221 | 220 |
222 ThreadedTest::ThreadedTest() | 221 ThreadedTest::ThreadedTest() |
223 : m_beginning(false) | 222 : m_beginning(false) |
224 , m_endWhenBeginReturns(false) | 223 , m_endWhenBeginReturns(false) |
225 , m_timedOut(false) | 224 , m_timedOut(false) |
226 , m_scheduled(false) | 225 , m_scheduled(false) |
227 , m_started(false) | 226 , m_started(false) |
228 , m_implThread(0) | 227 , m_implThread(0) |
| 228 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
229 { | 229 { |
| 230 m_mainThreadWeakPtr = m_weakFactory.GetWeakPtr(); |
230 } | 231 } |
231 | 232 |
232 ThreadedTest::~ThreadedTest() | 233 ThreadedTest::~ThreadedTest() |
233 { | 234 { |
234 } | 235 } |
235 | 236 |
236 void ThreadedTest::endTest() | 237 void ThreadedTest::endTest() |
237 { | 238 { |
238 // For the case where we endTest during beginTest(), set a flag to indicate
that | 239 // For the case where we endTest during beginTest(), set a flag to indicate
that |
239 // the test should end the second beginTest regains control. | 240 // the test should end the second beginTest regains control. |
240 if (m_beginning) | 241 if (m_beginning) |
241 m_endWhenBeginReturns = true; | 242 m_endWhenBeginReturns = true; |
242 else | 243 else |
243 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::realEnd
Test, base::Unretained(this))); | 244 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::realEndTest, m
_mainThreadWeakPtr)); |
244 } | 245 } |
245 | 246 |
246 void ThreadedTest::endTestAfterDelay(int delayMilliseconds) | 247 void ThreadedTest::endTestAfterDelay(int delayMilliseconds) |
247 { | 248 { |
248 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::endTest, ba
se::Unretained(this))); | 249 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::endTest, m_mainThr
eadWeakPtr)); |
249 } | |
250 | |
251 void ThreadedTest::postSetNeedsAnimateToMainThread() | |
252 { | |
253 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsAnimate, base::Unretained(this))); | |
254 } | 250 } |
255 | 251 |
256 void ThreadedTest::postAddAnimationToMainThread(Layer* layerToReceiveAnimation) | 252 void ThreadedTest::postAddAnimationToMainThread(Layer* layerToReceiveAnimation) |
257 { | 253 { |
258 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAdd
Animation, base::Unretained(this), base::Unretained(layerToReceiveAnimation))); | 254 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchAddAnimati
on, m_mainThreadWeakPtr, base::Unretained(layerToReceiveAnimation))); |
259 } | 255 } |
260 | 256 |
261 void ThreadedTest::postAddInstantAnimationToMainThread() | 257 void ThreadedTest::postAddInstantAnimationToMainThread() |
262 { | 258 { |
263 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAdd
InstantAnimation, base::Unretained(this))); | 259 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchAddInstant
Animation, m_mainThreadWeakPtr)); |
264 } | 260 } |
265 | 261 |
266 void ThreadedTest::postSetNeedsCommitToMainThread() | 262 void ThreadedTest::postSetNeedsCommitToMainThread() |
267 { | 263 { |
268 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsCommit, base::Unretained(this))); | 264 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetNeedsCo
mmit, m_mainThreadWeakPtr)); |
269 } | 265 } |
270 | 266 |
271 void ThreadedTest::postAcquireLayerTextures() | 267 void ThreadedTest::postAcquireLayerTextures() |
272 { | 268 { |
273 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAcq
uireLayerTextures, base::Unretained(this))); | 269 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchAcquireLay
erTextures, m_mainThreadWeakPtr)); |
274 } | 270 } |
275 | 271 |
276 void ThreadedTest::postSetNeedsRedrawToMainThread() | 272 void ThreadedTest::postSetNeedsRedrawToMainThread() |
277 { | 273 { |
278 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); | 274 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetNeedsRe
draw, m_mainThreadWeakPtr)); |
279 } | 275 } |
280 | 276 |
281 void ThreadedTest::postSetVisibleToMainThread(bool visible) | 277 void ThreadedTest::postSetVisibleToMainThread(bool visible) |
282 { | 278 { |
283 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); | 279 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchSetVisible
, m_mainThreadWeakPtr, visible)); |
284 } | 280 } |
285 | 281 |
286 void ThreadedTest::doBeginTest() | 282 void ThreadedTest::doBeginTest() |
287 { | 283 { |
288 m_client = ThreadedMockLayerTreeHostClient::create(this); | 284 m_client = ThreadedMockLayerTreeHostClient::create(this); |
289 | 285 |
290 scoped_ptr<cc::Thread> implCCThread(NULL); | 286 scoped_ptr<cc::Thread> implCCThread(NULL); |
291 if (m_implThread) | 287 if (m_implThread) |
292 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); | 288 implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->me
ssage_loop_proxy()); |
293 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); | 289 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), m_settings
, implCCThread.Pass()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 { | 324 { |
329 m_timedOut = true; | 325 m_timedOut = true; |
330 endTest(); | 326 endTest(); |
331 } | 327 } |
332 | 328 |
333 void ThreadedTest::scheduleComposite() | 329 void ThreadedTest::scheduleComposite() |
334 { | 330 { |
335 if (!m_started || m_scheduled) | 331 if (!m_started || m_scheduled) |
336 return; | 332 return; |
337 m_scheduled = true; | 333 m_scheduled = true; |
338 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchCom
posite, base::Unretained(this))); | 334 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::dispatchComposite,
m_mainThreadWeakPtr)); |
339 } | 335 } |
340 | 336 |
341 void ThreadedTest::realEndTest() | 337 void ThreadedTest::realEndTest() |
342 { | 338 { |
343 if (m_layerTreeHost && m_layerTreeHost->proxy()->commitPendingForTesting())
{ | 339 if (m_layerTreeHost && proxy()->commitPendingForTesting()) { |
344 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::realEnd
Test, base::Unretained(this))); | 340 proxy()->mainThread()->postTask(base::Bind(&ThreadedTest::realEndTest, m
_mainThreadWeakPtr)); |
345 return; | 341 return; |
346 } | 342 } |
347 | 343 |
348 MessageLoop::current()->Quit(); | 344 MessageLoop::current()->Quit(); |
349 } | 345 } |
350 | 346 |
351 void ThreadedTest::dispatchSetNeedsAnimate() | |
352 { | |
353 DCHECK(!proxy() || proxy()->isMainThread()); | |
354 | |
355 if (m_layerTreeHost.get()) | |
356 m_layerTreeHost->setNeedsAnimate(); | |
357 } | |
358 | |
359 void ThreadedTest::dispatchAddInstantAnimation() | 347 void ThreadedTest::dispatchAddInstantAnimation() |
360 { | 348 { |
361 DCHECK(!proxy() || proxy()->isMainThread()); | 349 DCHECK(!proxy() || proxy()->isMainThread()); |
362 | 350 |
363 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) | 351 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) |
364 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa
lse); | 352 addOpacityTransitionToLayer(*m_layerTreeHost->rootLayer(), 0, 0, 0.5, fa
lse); |
365 } | 353 } |
366 | 354 |
367 void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) | 355 void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) |
368 { | 356 { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 400 } |
413 | 401 |
414 void ThreadedTest::runTest(bool threaded) | 402 void ThreadedTest::runTest(bool threaded) |
415 { | 403 { |
416 if (threaded) { | 404 if (threaded) { |
417 m_implThread.reset(new base::Thread("ThreadedTest")); | 405 m_implThread.reset(new base::Thread("ThreadedTest")); |
418 ASSERT_TRUE(m_implThread->Start()); | 406 ASSERT_TRUE(m_implThread->Start()); |
419 } | 407 } |
420 | 408 |
421 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); | 409 m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); |
422 m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); | |
423 | 410 |
424 initializeSettings(m_settings); | 411 initializeSettings(m_settings); |
425 | 412 |
426 m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unreta
ined(this))); | 413 m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unreta
ined(this))); |
427 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); | 414 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); |
428 m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); | 415 m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); |
429 MessageLoop::current()->Run(); | 416 MessageLoop::current()->Run(); |
430 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) | 417 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) |
431 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); | 418 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); |
432 m_layerTreeHost.reset(); | 419 m_layerTreeHost.reset(); |
433 | 420 |
434 m_timeout.Cancel(); | 421 m_timeout.Cancel(); |
435 | 422 |
436 ASSERT_FALSE(m_layerTreeHost.get()); | 423 ASSERT_FALSE(m_layerTreeHost.get()); |
437 m_client.reset(); | 424 m_client.reset(); |
438 if (m_timedOut) { | 425 if (m_timedOut) { |
439 FAIL() << "Test timed out"; | 426 FAIL() << "Test timed out"; |
440 return; | 427 return; |
441 } | 428 } |
442 afterTest(); | 429 afterTest(); |
443 } | 430 } |
444 | 431 |
445 } // namespace cc | 432 } // namespace cc |
OLD | NEW |