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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/test/layer_tree_test_common.h" | 7 #include "cc/test/layer_tree_test_common.h" |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "cc/active_animation.h" | 10 #include "cc/active_animation.h" |
11 #include "cc/content_layer.h" | 11 #include "cc/content_layer.h" |
12 #include "cc/input_handler.h" | 12 #include "cc/input_handler.h" |
13 #include "cc/layer.h" | 13 #include "cc/layer.h" |
14 #include "cc/layer_animation_controller.h" | 14 #include "cc/layer_animation_controller.h" |
15 #include "cc/layer_impl.h" | 15 #include "cc/layer_impl.h" |
16 #include "cc/layer_tree_host_impl.h" | 16 #include "cc/layer_tree_host_impl.h" |
17 #include "cc/scoped_thread_proxy.h" | 17 #include "cc/scoped_thread_proxy.h" |
18 #include "cc/settings.h" | 18 #include "cc/settings.h" |
19 #include "cc/single_thread_proxy.h" | 19 #include "cc/single_thread_proxy.h" |
| 20 #include "cc/thread_impl.h" |
20 #include "cc/test/animation_test_common.h" | 21 #include "cc/test/animation_test_common.h" |
21 #include "cc/test/fake_web_compositor_output_surface.h" | 22 #include "cc/test/fake_web_compositor_output_surface.h" |
22 #include "cc/test/fake_web_graphics_context_3d.h" | 23 #include "cc/test/fake_web_graphics_context_3d.h" |
23 #include "cc/test/occlusion_tracker_test_common.h" | 24 #include "cc/test/occlusion_tracker_test_common.h" |
24 #include "cc/test/test_common.h" | 25 #include "cc/test/test_common.h" |
25 #include "cc/test/tiled_layer_test_common.h" | 26 #include "cc/test/tiled_layer_test_common.h" |
26 #include "cc/thread_task.h" | |
27 #include "cc/timing_function.h" | 27 #include "cc/timing_function.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 #include <public/Platform.h> | |
30 #include <public/WebCompositorSupport.h> | |
31 #include <public/WebFilterOperation.h> | 29 #include <public/WebFilterOperation.h> |
32 #include <public/WebFilterOperations.h> | 30 #include <public/WebFilterOperations.h> |
33 #include <public/WebThread.h> | 31 #include <public/WebThread.h> |
34 | 32 |
35 using namespace cc; | 33 using namespace cc; |
36 using namespace WebKit; | 34 using namespace WebKit; |
37 | 35 |
38 namespace WebKitTests { | 36 namespace WebKitTests { |
39 | 37 |
40 scoped_ptr<CompositorFakeWebGraphicsContext3DWithTextureTracking> CompositorFake
WebGraphicsContext3DWithTextureTracking::create(Attributes attrs) | 38 scoped_ptr<CompositorFakeWebGraphicsContext3DWithTextureTracking> CompositorFake
WebGraphicsContext3DWithTextureTracking::create(Attributes attrs) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 { | 261 { |
264 m_testHooks->scheduleComposite(); | 262 m_testHooks->scheduleComposite(); |
265 } | 263 } |
266 | 264 |
267 private: | 265 private: |
268 explicit ThreadedMockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks
(testHooks) { } | 266 explicit ThreadedMockLayerTreeHostClient(TestHooks* testHooks) : m_testHooks
(testHooks) { } |
269 | 267 |
270 TestHooks* m_testHooks; | 268 TestHooks* m_testHooks; |
271 }; | 269 }; |
272 | 270 |
273 class TimeoutTask : public WebThread::Task { | |
274 public: | |
275 explicit TimeoutTask(ThreadedTest* test) | |
276 : m_test(test) | |
277 { | |
278 } | |
279 | |
280 void clearTest() | |
281 { | |
282 m_test = 0; | |
283 } | |
284 | |
285 virtual ~TimeoutTask() | |
286 { | |
287 if (m_test) | |
288 m_test->clearTimeout(); | |
289 } | |
290 | |
291 virtual void run() | |
292 { | |
293 if (m_test) | |
294 m_test->timeout(); | |
295 } | |
296 | |
297 private: | |
298 ThreadedTest* m_test; | |
299 }; | |
300 | |
301 class BeginTask : public WebThread::Task { | |
302 public: | |
303 explicit BeginTask(ThreadedTest* test) | |
304 : m_test(test) | |
305 { | |
306 } | |
307 | |
308 virtual ~BeginTask() { } | |
309 virtual void run() | |
310 { | |
311 m_test->doBeginTest(); | |
312 } | |
313 private: | |
314 ThreadedTest* m_test; | |
315 }; | |
316 | |
317 ThreadedTest::ThreadedTest() | 271 ThreadedTest::ThreadedTest() |
318 : m_beginning(false) | 272 : m_beginning(false) |
319 , m_endWhenBeginReturns(false) | 273 , m_endWhenBeginReturns(false) |
320 , m_timedOut(false) | 274 , m_timedOut(false) |
321 , m_finished(false) | 275 , m_finished(false) |
322 , m_scheduled(false) | 276 , m_scheduled(false) |
323 , m_started(false) | 277 , m_started(false) |
324 { | 278 { |
325 } | 279 } |
326 | 280 |
327 ThreadedTest::~ThreadedTest() | 281 ThreadedTest::~ThreadedTest() |
328 { | 282 { |
329 } | 283 } |
330 | 284 |
331 void ThreadedTest::endTest() | 285 void ThreadedTest::endTest() |
332 { | 286 { |
333 m_finished = true; | 287 m_finished = true; |
334 | 288 |
335 // For the case where we endTest during beginTest(), set a flag to indicate
that | 289 // For the case where we endTest during beginTest(), set a flag to indicate
that |
336 // the test should end the second beginTest regains control. | 290 // the test should end the second beginTest regains control. |
337 if (m_beginning) | 291 if (m_beginning) |
338 m_endWhenBeginReturns = true; | 292 m_endWhenBeginReturns = true; |
339 else | 293 else |
340 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::realEn
dTest)); | 294 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::realEnd
Test, base::Unretained(this))); |
341 } | 295 } |
342 | 296 |
343 void ThreadedTest::endTestAfterDelay(int delayMilliseconds) | 297 void ThreadedTest::endTestAfterDelay(int delayMilliseconds) |
344 { | 298 { |
345 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::endTest)); | 299 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::endTest, ba
se::Unretained(this))); |
346 } | 300 } |
347 | 301 |
348 void ThreadedTest::postSetNeedsAnimateToMainThread() | 302 void ThreadedTest::postSetNeedsAnimateToMainThread() |
349 { | 303 { |
350 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe
tNeedsAnimate)); | 304 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsAnimate, base::Unretained(this))); |
351 } | 305 } |
352 | 306 |
353 void ThreadedTest::postAddAnimationToMainThread() | 307 void ThreadedTest::postAddAnimationToMainThread() |
354 { | 308 { |
355 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAd
dAnimation)); | 309 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAdd
Animation, base::Unretained(this))); |
356 } | 310 } |
357 | 311 |
358 void ThreadedTest::postAddInstantAnimationToMainThread() | 312 void ThreadedTest::postAddInstantAnimationToMainThread() |
359 { | 313 { |
360 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAd
dInstantAnimation)); | 314 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAdd
InstantAnimation, base::Unretained(this))); |
361 } | 315 } |
362 | 316 |
363 void ThreadedTest::postSetNeedsCommitToMainThread() | 317 void ThreadedTest::postSetNeedsCommitToMainThread() |
364 { | 318 { |
365 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe
tNeedsCommit)); | 319 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsCommit, base::Unretained(this))); |
366 } | 320 } |
367 | 321 |
368 void ThreadedTest::postAcquireLayerTextures() | 322 void ThreadedTest::postAcquireLayerTextures() |
369 { | 323 { |
370 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchAc
quireLayerTextures)); | 324 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchAcq
uireLayerTextures, base::Unretained(this))); |
371 } | 325 } |
372 | 326 |
373 void ThreadedTest::postSetNeedsRedrawToMainThread() | 327 void ThreadedTest::postSetNeedsRedrawToMainThread() |
374 { | 328 { |
375 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe
tNeedsRedraw)); | 329 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsRedraw, base::Unretained(this))); |
376 } | 330 } |
377 | 331 |
378 void ThreadedTest::postSetNeedsAnimateAndCommitToMainThread() | 332 void ThreadedTest::postSetNeedsAnimateAndCommitToMainThread() |
379 { | 333 { |
380 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe
tNeedsAnimateAndCommit)); | 334 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
NeedsAnimateAndCommit, base::Unretained(this))); |
381 } | 335 } |
382 | 336 |
383 void ThreadedTest::postSetVisibleToMainThread(bool visible) | 337 void ThreadedTest::postSetVisibleToMainThread(bool visible) |
384 { | 338 { |
385 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchSe
tVisible, visible)); | 339 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchSet
Visible, base::Unretained(this), visible)); |
386 } | 340 } |
387 | 341 |
388 void ThreadedTest::postDidAddAnimationToMainThread() | 342 void ThreadedTest::postDidAddAnimationToMainThread() |
389 { | 343 { |
390 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchDi
dAddAnimation)); | 344 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchDid
AddAnimation, base::Unretained(this))); |
391 } | 345 } |
392 | 346 |
393 void ThreadedTest::doBeginTest() | 347 void ThreadedTest::doBeginTest() |
394 { | 348 { |
395 DCHECK(Proxy::isMainThread()); | 349 DCHECK(Proxy::isMainThread()); |
396 m_client = ThreadedMockLayerTreeHostClient::create(this); | 350 m_client = ThreadedMockLayerTreeHostClient::create(this); |
397 | 351 |
398 scoped_refptr<Layer> rootLayer = Layer::create(); | 352 scoped_refptr<Layer> rootLayer = Layer::create(); |
399 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer,
m_settings); | 353 m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer,
m_settings); |
400 ASSERT_TRUE(m_layerTreeHost.get()); | 354 ASSERT_TRUE(m_layerTreeHost.get()); |
(...skipping 17 matching lines...) Expand all Loading... |
418 { | 372 { |
419 m_timedOut = true; | 373 m_timedOut = true; |
420 endTest(); | 374 endTest(); |
421 } | 375 } |
422 | 376 |
423 void ThreadedTest::scheduleComposite() | 377 void ThreadedTest::scheduleComposite() |
424 { | 378 { |
425 if (!m_started || m_scheduled || m_finished) | 379 if (!m_started || m_scheduled || m_finished) |
426 return; | 380 return; |
427 m_scheduled = true; | 381 m_scheduled = true; |
428 m_mainThreadProxy->postTask(createThreadTask(this, &ThreadedTest::dispatchCo
mposite)); | 382 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&ThreadedTest::dispatchCom
posite, base::Unretained(this))); |
429 } | 383 } |
430 | 384 |
431 void ThreadedTest::realEndTest() | 385 void ThreadedTest::realEndTest() |
432 { | 386 { |
433 DCHECK(Proxy::isMainThread()); | 387 DCHECK(Proxy::isMainThread()); |
434 WebKit::Platform::current()->currentThread()->exitRunLoop(); | 388 MessageLoop::current()->Quit(); |
435 } | 389 } |
436 | 390 |
437 void ThreadedTest::dispatchSetNeedsAnimate() | 391 void ThreadedTest::dispatchSetNeedsAnimate() |
438 { | 392 { |
439 DCHECK(Proxy::isMainThread()); | 393 DCHECK(Proxy::isMainThread()); |
440 | 394 |
441 if (m_finished) | 395 if (m_finished) |
442 return; | 396 return; |
443 | 397 |
444 if (m_layerTreeHost.get()) | 398 if (m_layerTreeHost.get()) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 m_layerTreeHost->didAddAnimation(); | 496 m_layerTreeHost->didAddAnimation(); |
543 } | 497 } |
544 | 498 |
545 void ThreadedTest::runTest(bool threaded) | 499 void ThreadedTest::runTest(bool threaded) |
546 { | 500 { |
547 // For these tests, we will enable threaded animations. | 501 // For these tests, we will enable threaded animations. |
548 ScopedSettings scopedSettings; | 502 ScopedSettings scopedSettings; |
549 Settings::setAcceleratedAnimationEnabled(true); | 503 Settings::setAcceleratedAnimationEnabled(true); |
550 | 504 |
551 if (threaded) { | 505 if (threaded) { |
552 m_webThread.reset(WebKit::Platform::current()->createThread("ThreadedTes
t")); | 506 m_implThread.reset(new base::Thread("ThreadedTest")); |
553 Platform::current()->compositorSupport()->initialize(m_webThread.get()); | 507 ASSERT_TRUE(m_implThread->Start()); |
554 } else | 508 m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->
message_loop_proxy()); |
555 Platform::current()->compositorSupport()->initialize(0); | 509 cc::Proxy::setImplThread(m_implCCThread.get()); |
| 510 } |
556 | 511 |
557 DCHECK(Proxy::isMainThread()); | 512 DCHECK(Proxy::isMainThread()); |
558 m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); | 513 m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); |
559 | 514 |
560 initializeSettings(m_settings); | 515 initializeSettings(m_settings); |
561 | 516 |
562 m_beginTask = new BeginTask(this); | 517 cc::Proxy::mainThread()->postTask(base::Bind(&ThreadedTest::doBeginTest, bas
e::Unretained(this))); |
563 WebKit::Platform::current()->currentThread()->postDelayedTask(m_beginTask, 0
); // postDelayedTask takes ownership of the task | 518 m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); |
564 m_timeoutTask = new TimeoutTask(this); | 519 cc::Proxy::mainThread()->postDelayedTask(m_timeout.callback(), 5000); |
565 WebKit::Platform::current()->currentThread()->postDelayedTask(m_timeoutTask,
5000); | 520 MessageLoop::current()->Run(); |
566 WebKit::Platform::current()->currentThread()->enterRunLoop(); | |
567 | |
568 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) | 521 if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) |
569 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); | 522 m_layerTreeHost->rootLayer()->setLayerTreeHost(0); |
570 m_layerTreeHost.reset(); | 523 m_layerTreeHost.reset(); |
571 | 524 |
572 if (m_timeoutTask) | 525 cc::Proxy::setImplThread(0); |
573 m_timeoutTask->clearTest(); | 526 |
| 527 m_timeout.Cancel(); |
574 | 528 |
575 ASSERT_FALSE(m_layerTreeHost.get()); | 529 ASSERT_FALSE(m_layerTreeHost.get()); |
576 m_client.reset(); | 530 m_client.reset(); |
577 if (m_timedOut) { | 531 if (m_timedOut) { |
578 FAIL() << "Test timed out"; | 532 FAIL() << "Test timed out"; |
579 Platform::current()->compositorSupport()->shutdown(); | |
580 return; | 533 return; |
581 } | 534 } |
582 afterTest(); | 535 afterTest(); |
583 Platform::current()->compositorSupport()->shutdown(); | |
584 } | 536 } |
585 | 537 |
586 } // namespace WebKitTests | 538 } // namespace WebKitTests |
OLD | NEW |