Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: cc/test/layer_tree_test.cc

Issue 17114008: cc: Remove cc::Thread and cc::ThreadImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm-thread: NULLrefptrs Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/test/scheduler_test_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "cc/test/layer_tree_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "cc/animation/animation.h" 8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_registrar.h" 9 #include "cc/animation/animation_registrar.h"
10 #include "cc/animation/layer_animation_controller.h" 10 #include "cc/animation/layer_animation_controller.h"
11 #include "cc/animation/timing_function.h" 11 #include "cc/animation/timing_function.h"
12 #include "cc/base/switches.h" 12 #include "cc/base/switches.h"
13 #include "cc/base/thread_impl.h"
14 #include "cc/input/input_handler.h" 13 #include "cc/input/input_handler.h"
15 #include "cc/layers/content_layer.h" 14 #include "cc/layers/content_layer.h"
16 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
17 #include "cc/layers/layer_impl.h" 16 #include "cc/layers/layer_impl.h"
18 #include "cc/test/animation_test_common.h" 17 #include "cc/test/animation_test_common.h"
19 #include "cc/test/fake_context_provider.h" 18 #include "cc/test/fake_context_provider.h"
20 #include "cc/test/fake_layer_tree_host_client.h" 19 #include "cc/test/fake_layer_tree_host_client.h"
21 #include "cc/test/fake_output_surface.h" 20 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/occlusion_tracker_test_common.h" 21 #include "cc/test/occlusion_tracker_test_common.h"
23 #include "cc/test/tiled_layer_test_common.h" 22 #include "cc/test/tiled_layer_test_common.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 TestHooks* test_hooks_; 171 TestHooks* test_hooks_;
173 }; 172 };
174 173
175 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 174 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
176 class LayerTreeHostForTesting : public cc::LayerTreeHost { 175 class LayerTreeHostForTesting : public cc::LayerTreeHost {
177 public: 176 public:
178 static scoped_ptr<LayerTreeHostForTesting> Create( 177 static scoped_ptr<LayerTreeHostForTesting> Create(
179 TestHooks* test_hooks, 178 TestHooks* test_hooks,
180 cc::LayerTreeHostClient* host_client, 179 cc::LayerTreeHostClient* host_client,
181 const cc::LayerTreeSettings& settings, 180 const cc::LayerTreeSettings& settings,
182 scoped_ptr<cc::Thread> impl_thread) { 181 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
183 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( 182 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
184 new LayerTreeHostForTesting(test_hooks, host_client, settings)); 183 new LayerTreeHostForTesting(test_hooks, host_client, settings));
185 bool success = layer_tree_host->Initialize(impl_thread.Pass()); 184 bool success = layer_tree_host->Initialize(impl_task_runner);
186 EXPECT_TRUE(success); 185 EXPECT_TRUE(success);
187 return layer_tree_host.Pass(); 186 return layer_tree_host.Pass();
188 } 187 }
189 188
190 virtual scoped_ptr<cc::LayerTreeHostImpl> CreateLayerTreeHostImpl( 189 virtual scoped_ptr<cc::LayerTreeHostImpl> CreateLayerTreeHostImpl(
191 cc::LayerTreeHostImplClient* host_impl_client) OVERRIDE { 190 cc::LayerTreeHostImplClient* host_impl_client) OVERRIDE {
192 return LayerTreeHostImplForTesting::Create( 191 return LayerTreeHostImplForTesting::Create(
193 test_hooks_, 192 test_hooks_,
194 settings(), 193 settings(),
195 host_impl_client, 194 host_impl_client,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 LayerTreeTest::~LayerTreeTest() {} 317 LayerTreeTest::~LayerTreeTest() {}
319 318
320 void LayerTreeTest::EndTest() { 319 void LayerTreeTest::EndTest() {
321 // For the case where we EndTest during BeginTest(), set a flag to indicate 320 // For the case where we EndTest during BeginTest(), set a flag to indicate
322 // that the test should end the second BeginTest regains control. 321 // that the test should end the second BeginTest regains control.
323 if (beginning_) { 322 if (beginning_) {
324 end_when_begin_returns_ = true; 323 end_when_begin_returns_ = true;
325 } else if (proxy()) { 324 } else if (proxy()) {
326 // Racy timeouts and explicit EndTest calls might have cleaned up 325 // Racy timeouts and explicit EndTest calls might have cleaned up
327 // the tree host. Should check proxy first. 326 // the tree host. Should check proxy first.
328 proxy()->MainThread()->PostTask( 327 proxy()->MainThreadTaskRunner()->PostTask(
328 FROM_HERE,
329 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); 329 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
330 } 330 }
331 } 331 }
332 332
333 void LayerTreeTest::EndTestAfterDelay(int delay_milliseconds) { 333 void LayerTreeTest::EndTestAfterDelay(int delay_milliseconds) {
334 proxy()->MainThread()->PostTask( 334 proxy()->MainThreadTaskRunner()->PostTask(
335 FROM_HERE,
335 base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_)); 336 base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_));
336 } 337 }
337 338
338 void LayerTreeTest::PostAddAnimationToMainThread( 339 void LayerTreeTest::PostAddAnimationToMainThread(
339 Layer* layer_to_receive_animation) { 340 Layer* layer_to_receive_animation) {
340 proxy()->MainThread()->PostTask( 341 proxy()->MainThreadTaskRunner()->PostTask(
342 FROM_HERE,
341 base::Bind(&LayerTreeTest::DispatchAddAnimation, 343 base::Bind(&LayerTreeTest::DispatchAddAnimation,
342 main_thread_weak_ptr_, 344 main_thread_weak_ptr_,
343 base::Unretained(layer_to_receive_animation))); 345 base::Unretained(layer_to_receive_animation)));
344 } 346 }
345 347
346 void LayerTreeTest::PostAddInstantAnimationToMainThread( 348 void LayerTreeTest::PostAddInstantAnimationToMainThread(
347 Layer* layer_to_receive_animation) { 349 Layer* layer_to_receive_animation) {
348 proxy()->MainThread()->PostTask( 350 proxy()->MainThreadTaskRunner()->PostTask(
351 FROM_HERE,
349 base::Bind(&LayerTreeTest::DispatchAddInstantAnimation, 352 base::Bind(&LayerTreeTest::DispatchAddInstantAnimation,
350 main_thread_weak_ptr_, 353 main_thread_weak_ptr_,
351 base::Unretained(layer_to_receive_animation))); 354 base::Unretained(layer_to_receive_animation)));
352 } 355 }
353 356
354 void LayerTreeTest::PostSetNeedsCommitToMainThread() { 357 void LayerTreeTest::PostSetNeedsCommitToMainThread() {
355 proxy()->MainThread()->PostTask( 358 proxy()->MainThreadTaskRunner()->PostTask(
359 FROM_HERE,
356 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit, 360 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit,
357 main_thread_weak_ptr_)); 361 main_thread_weak_ptr_));
358 } 362 }
359 363
360 void LayerTreeTest::PostAcquireLayerTextures() { 364 void LayerTreeTest::PostAcquireLayerTextures() {
361 proxy()->MainThread()->PostTask( 365 proxy()->MainThreadTaskRunner()->PostTask(
366 FROM_HERE,
362 base::Bind(&LayerTreeTest::DispatchAcquireLayerTextures, 367 base::Bind(&LayerTreeTest::DispatchAcquireLayerTextures,
363 main_thread_weak_ptr_)); 368 main_thread_weak_ptr_));
364 } 369 }
365 370
366 void LayerTreeTest::PostSetNeedsRedrawToMainThread() { 371 void LayerTreeTest::PostSetNeedsRedrawToMainThread() {
367 proxy()->MainThread()->PostTask( 372 proxy()->MainThreadTaskRunner()->PostTask(
373 FROM_HERE,
368 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw, 374 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw,
369 main_thread_weak_ptr_)); 375 main_thread_weak_ptr_));
370 } 376 }
371 377
372 void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(gfx::Rect damage_rect) { 378 void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(gfx::Rect damage_rect) {
373 proxy()->MainThread()->PostTask( 379 proxy()->MainThreadTaskRunner()->PostTask(
380 FROM_HERE,
374 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect, 381 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect,
375 main_thread_weak_ptr_, damage_rect)); 382 main_thread_weak_ptr_, damage_rect));
376 } 383 }
377 384
378 void LayerTreeTest::PostSetVisibleToMainThread(bool visible) { 385 void LayerTreeTest::PostSetVisibleToMainThread(bool visible) {
379 proxy()->MainThread()->PostTask( 386 proxy()->MainThreadTaskRunner()->PostTask(
387 FROM_HERE,
380 base::Bind(&LayerTreeTest::DispatchSetVisible, 388 base::Bind(&LayerTreeTest::DispatchSetVisible,
381 main_thread_weak_ptr_, 389 main_thread_weak_ptr_,
382 visible)); 390 visible));
383 } 391 }
384 392
385 void LayerTreeTest::DoBeginTest() { 393 void LayerTreeTest::DoBeginTest() {
386 client_ = LayerTreeHostClientForTesting::Create(this); 394 client_ = LayerTreeHostClientForTesting::Create(this);
387 395
388 scoped_ptr<cc::Thread> impl_ccthread; 396 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy());
389 if (impl_thread_) { 397 layer_tree_host_ = LayerTreeHostForTesting::Create(
390 impl_ccthread = cc::ThreadImpl::CreateForDifferentThread( 398 this,
391 impl_thread_->message_loop_proxy()); 399 client_.get(),
392 } 400 settings_,
393 layer_tree_host_ = LayerTreeHostForTesting::Create(this, 401 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL);
394 client_.get(),
395 settings_,
396 impl_ccthread.Pass());
397 ASSERT_TRUE(layer_tree_host_); 402 ASSERT_TRUE(layer_tree_host_);
398 403
399 started_ = true; 404 started_ = true;
400 beginning_ = true; 405 beginning_ = true;
401 SetupTree(); 406 SetupTree();
402 layer_tree_host_->SetLayerTreeHostClientReady(); 407 layer_tree_host_->SetLayerTreeHostClientReady();
403 BeginTest(); 408 BeginTest();
404 beginning_ = false; 409 beginning_ = false;
405 if (end_when_begin_returns_) 410 if (end_when_begin_returns_)
406 RealEndTest(); 411 RealEndTest();
(...skipping 25 matching lines...) Expand all
432 437
433 void LayerTreeTest::Timeout() { 438 void LayerTreeTest::Timeout() {
434 timed_out_ = true; 439 timed_out_ = true;
435 EndTest(); 440 EndTest();
436 } 441 }
437 442
438 void LayerTreeTest::ScheduleComposite() { 443 void LayerTreeTest::ScheduleComposite() {
439 if (!started_ || scheduled_) 444 if (!started_ || scheduled_)
440 return; 445 return;
441 scheduled_ = true; 446 scheduled_ = true;
442 proxy()->MainThread()->PostTask( 447 proxy()->MainThreadTaskRunner()->PostTask(
448 FROM_HERE,
443 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_)); 449 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_));
444 } 450 }
445 451
446 void LayerTreeTest::RealEndTest() { 452 void LayerTreeTest::RealEndTest() {
447 ended_ = true; 453 ended_ = true;
448 454
449 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) { 455 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) {
450 proxy()->MainThread()->PostTask( 456 proxy()->MainThreadTaskRunner()->PostTask(
457 FROM_HERE,
451 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); 458 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
452 return; 459 return;
453 } 460 }
454 461
455 base::MessageLoop::current()->Quit(); 462 base::MessageLoop::current()->Quit();
456 } 463 }
457 464
458 void LayerTreeTest::DispatchAddInstantAnimation( 465 void LayerTreeTest::DispatchAddInstantAnimation(
459 Layer* layer_to_receive_animation) { 466 Layer* layer_to_receive_animation) {
460 DCHECK(!proxy() || proxy()->IsMainThread()); 467 DCHECK(!proxy() || proxy()->IsMainThread());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 548 }
542 549
543 void LayerTreeTest::RunTest(bool threaded, 550 void LayerTreeTest::RunTest(bool threaded,
544 bool delegating_renderer, 551 bool delegating_renderer,
545 bool impl_side_painting) { 552 bool impl_side_painting) {
546 if (threaded) { 553 if (threaded) {
547 impl_thread_.reset(new base::Thread("Compositor")); 554 impl_thread_.reset(new base::Thread("Compositor"));
548 ASSERT_TRUE(impl_thread_->Start()); 555 ASSERT_TRUE(impl_thread_->Start());
549 } 556 }
550 557
551 main_ccthread_ = cc::ThreadImpl::CreateForCurrentThread(); 558 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_ =
559 base::MessageLoopProxy::current();
552 560
553 delegating_renderer_ = delegating_renderer; 561 delegating_renderer_ = delegating_renderer;
554 562
555 // Spend less time waiting for BeginFrame because the output is 563 // Spend less time waiting for BeginFrame because the output is
556 // mocked out. 564 // mocked out.
557 settings_.refresh_rate = 200.0; 565 settings_.refresh_rate = 200.0;
558 if (impl_side_painting) { 566 if (impl_side_painting) {
559 DCHECK(threaded) << 567 DCHECK(threaded) <<
560 "Don't run single thread + impl side painting, it doesn't exist."; 568 "Don't run single thread + impl side painting, it doesn't exist.";
561 settings_.impl_side_painting = true; 569 settings_.impl_side_painting = true;
562 } 570 }
563 InitializeSettings(&settings_); 571 InitializeSettings(&settings_);
564 572
565 main_ccthread_->PostTask( 573 main_task_runner_->PostTask(
574 FROM_HERE,
566 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); 575 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
567 576
568 if (timeout_seconds_) { 577 if (timeout_seconds_) {
569 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); 578 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
570 main_ccthread_->PostDelayedTask( 579 main_task_runner_->PostDelayedTask(
580 FROM_HERE,
571 timeout_.callback(), 581 timeout_.callback(),
572 base::TimeDelta::FromSeconds(timeout_seconds_)); 582 base::TimeDelta::FromSeconds(timeout_seconds_));
573 } 583 }
574 584
575 base::MessageLoop::current()->Run(); 585 base::MessageLoop::current()->Run();
576 if (layer_tree_host_ && layer_tree_host_->root_layer()) 586 if (layer_tree_host_ && layer_tree_host_->root_layer())
577 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 587 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
578 layer_tree_host_.reset(); 588 layer_tree_host_.reset();
579 589
580 timeout_.Cancel(); 590 timeout_.Cancel();
(...skipping 30 matching lines...) Expand all
611 621
612 scoped_refptr<cc::ContextProvider> LayerTreeTest:: 622 scoped_refptr<cc::ContextProvider> LayerTreeTest::
613 OffscreenContextProviderForCompositorThread() { 623 OffscreenContextProviderForCompositorThread() {
614 if (!compositor_thread_contexts_.get() || 624 if (!compositor_thread_contexts_.get() ||
615 compositor_thread_contexts_->DestroyedOnMainThread()) 625 compositor_thread_contexts_->DestroyedOnMainThread())
616 compositor_thread_contexts_ = FakeContextProvider::Create(); 626 compositor_thread_contexts_ = FakeContextProvider::Create();
617 return compositor_thread_contexts_; 627 return compositor_thread_contexts_;
618 } 628 }
619 629
620 } // namespace cc 630 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/test/scheduler_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698