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

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

Issue 2650303002: cc: Remove the LayerTreeHost abstraction. (Closed)
Patch Set: missed ui Created 3 years, 11 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
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/trees/layer_tree_host.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 "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 private: 327 private:
328 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) 328 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
329 : test_hooks_(test_hooks) {} 329 : test_hooks_(test_hooks) {}
330 330
331 TestHooks* test_hooks_; 331 TestHooks* test_hooks_;
332 }; 332 };
333 333
334 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 334 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
335 class LayerTreeHostForTesting : public LayerTreeHostInProcess { 335 class LayerTreeHostForTesting : public LayerTreeHost {
336 public: 336 public:
337 static std::unique_ptr<LayerTreeHostForTesting> Create( 337 static std::unique_ptr<LayerTreeHostForTesting> Create(
338 TestHooks* test_hooks, 338 TestHooks* test_hooks,
339 CompositorMode mode, 339 CompositorMode mode,
340 LayerTreeHostClient* client, 340 LayerTreeHostClient* client,
341 LayerTreeHostSingleThreadClient* single_thread_client, 341 LayerTreeHostSingleThreadClient* single_thread_client,
342 TaskGraphRunner* task_graph_runner, 342 TaskGraphRunner* task_graph_runner,
343 const LayerTreeSettings& settings, 343 const LayerTreeSettings& settings,
344 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 344 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
345 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 345 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
346 MutatorHost* mutator_host) { 346 MutatorHost* mutator_host) {
347 LayerTreeHostInProcess::InitParams params; 347 LayerTreeHost::InitParams params;
348 params.client = client; 348 params.client = client;
349 params.task_graph_runner = task_graph_runner; 349 params.task_graph_runner = task_graph_runner;
350 params.settings = &settings; 350 params.settings = &settings;
351 params.mutator_host = mutator_host; 351 params.mutator_host = mutator_host;
352 352
353 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host( 353 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host(
354 new LayerTreeHostForTesting(test_hooks, &params, mode)); 354 new LayerTreeHostForTesting(test_hooks, &params, mode));
355 std::unique_ptr<TaskRunnerProvider> task_runner_provider = 355 std::unique_ptr<TaskRunnerProvider> task_runner_provider =
356 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 356 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
357 std::unique_ptr<Proxy> proxy; 357 std::unique_ptr<Proxy> proxy;
(...skipping 21 matching lines...) Expand all
379 test_hooks_, GetSettings(), host_impl_client, 379 test_hooks_, GetSettings(), host_impl_client,
380 GetTaskRunnerProvider(), task_graph_runner(), 380 GetTaskRunnerProvider(), task_graph_runner(),
381 rendering_stats_instrumentation()); 381 rendering_stats_instrumentation());
382 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); 382 input_handler_weak_ptr_ = host_impl->AsWeakPtr();
383 return host_impl; 383 return host_impl;
384 } 384 }
385 385
386 void SetNeedsCommit() override { 386 void SetNeedsCommit() override {
387 if (!test_started_) 387 if (!test_started_)
388 return; 388 return;
389 LayerTreeHostInProcess::SetNeedsCommit(); 389 LayerTreeHost::SetNeedsCommit();
390 } 390 }
391 391
392 void SetNeedsUpdateLayers() override { 392 void SetNeedsUpdateLayers() override {
393 if (!test_started_) 393 if (!test_started_)
394 return; 394 return;
395 LayerTreeHostInProcess::SetNeedsUpdateLayers(); 395 LayerTreeHost::SetNeedsUpdateLayers();
396 } 396 }
397 397
398 void set_test_started(bool started) { test_started_ = started; } 398 void set_test_started(bool started) { test_started_ = started; }
399 399
400 private: 400 private:
401 LayerTreeHostForTesting(TestHooks* test_hooks, 401 LayerTreeHostForTesting(TestHooks* test_hooks,
402 LayerTreeHostInProcess::InitParams* params, 402 LayerTreeHost::InitParams* params,
403 CompositorMode mode) 403 CompositorMode mode)
404 : LayerTreeHostInProcess(params, mode), 404 : LayerTreeHost(params, mode),
405 test_hooks_(test_hooks), 405 test_hooks_(test_hooks),
406 test_started_(false) {} 406 test_started_(false) {}
407 407
408 TestHooks* test_hooks_; 408 TestHooks* test_hooks_;
409 bool test_started_; 409 bool test_started_;
410 }; 410 };
411 411
412 class LayerTreeTestCompositorFrameSinkClient 412 class LayerTreeTestCompositorFrameSinkClient
413 : public TestCompositorFrameSinkClient { 413 : public TestCompositorFrameSinkClient {
414 public: 414 public:
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 587
588 DCHECK(!impl_thread_ || impl_thread_->task_runner().get()); 588 DCHECK(!impl_thread_ || impl_thread_->task_runner().get());
589 589
590 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = 590 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner =
591 base::ThreadTaskRunnerHandle::Get(); 591 base::ThreadTaskRunnerHandle::Get();
592 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner = 592 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner =
593 impl_thread_ ? impl_thread_->task_runner() : nullptr; 593 impl_thread_ ? impl_thread_->task_runner() : nullptr;
594 594
595 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 595 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
596 596
597 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host_for_testing = 597 layer_tree_host_ = LayerTreeHostForTesting::Create(
598 LayerTreeHostForTesting::Create( 598 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(),
599 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(), 599 settings_, main_task_runner, impl_task_runner, animation_host_.get());
600 settings_, main_task_runner, impl_task_runner, animation_host_.get());
601 layer_tree_host_in_process_ = layer_tree_host_for_testing.get();
602 layer_tree_host_ = std::move(layer_tree_host_for_testing);
603
604 ASSERT_TRUE(layer_tree_host_); 600 ASSERT_TRUE(layer_tree_host_);
605 601
606 main_task_runner_ = 602 main_task_runner_ =
607 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner(); 603 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner();
608 impl_task_runner_ = 604 impl_task_runner_ =
609 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner(); 605 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner();
610 if (!impl_task_runner_) { 606 if (!impl_task_runner_) {
611 // For tests, if there's no impl thread, make things easier by just giving 607 // For tests, if there's no impl thread, make things easier by just giving
612 // the main thread task runner. 608 // the main thread task runner.
613 impl_task_runner_ = main_task_runner_; 609 impl_task_runner_ = main_task_runner_;
(...skipping 10 matching lines...) Expand all
624 beginning_ = true; 620 beginning_ = true;
625 SetupTree(); 621 SetupTree();
626 WillBeginTest(); 622 WillBeginTest();
627 BeginTest(); 623 BeginTest();
628 beginning_ = false; 624 beginning_ = false;
629 if (end_when_begin_returns_) 625 if (end_when_begin_returns_)
630 RealEndTest(); 626 RealEndTest();
631 627
632 // Allow commits to happen once BeginTest() has had a chance to post tasks 628 // Allow commits to happen once BeginTest() has had a chance to post tasks
633 // so that those tasks will happen before the first commit. 629 // so that those tasks will happen before the first commit.
634 if (layer_tree_host_in_process_) { 630 if (layer_tree_host_) {
635 static_cast<LayerTreeHostForTesting*>(layer_tree_host_in_process_) 631 static_cast<LayerTreeHostForTesting*>(layer_tree_host_.get())
636 ->set_test_started(true); 632 ->set_test_started(true);
637 } 633 }
638 } 634 }
639 635
640 void LayerTreeTest::SetupTree() { 636 void LayerTreeTest::SetupTree() {
641 if (!layer_tree()->root_layer()) { 637 if (!layer_tree()->root_layer()) {
642 scoped_refptr<Layer> root_layer = Layer::Create(); 638 scoped_refptr<Layer> root_layer = Layer::Create();
643 root_layer->SetBounds(gfx::Size(1, 1)); 639 root_layer->SetBounds(gfx::Size(1, 1));
644 layer_tree()->SetRootLayer(root_layer); 640 layer_tree()->SetRootLayer(root_layer);
645 } 641 }
646 642
647 gfx::Size root_bounds = layer_tree()->root_layer()->bounds(); 643 gfx::Size root_bounds = layer_tree()->root_layer()->bounds();
648 gfx::Size device_root_bounds = 644 gfx::Size device_root_bounds =
649 gfx::ScaleToCeiledSize(root_bounds, layer_tree()->device_scale_factor()); 645 gfx::ScaleToCeiledSize(root_bounds, layer_tree()->device_scale_factor());
650 layer_tree()->SetViewportSize(device_root_bounds); 646 layer_tree()->SetViewportSize(device_root_bounds);
651 layer_tree()->root_layer()->SetIsDrawable(true); 647 layer_tree()->root_layer()->SetIsDrawable(true);
652 } 648 }
653 649
654 void LayerTreeTest::Timeout() { 650 void LayerTreeTest::Timeout() {
655 timed_out_ = true; 651 timed_out_ = true;
656 EndTest(); 652 EndTest();
657 } 653 }
658 654
659 void LayerTreeTest::RealEndTest() { 655 void LayerTreeTest::RealEndTest() {
660 // TODO(mithro): Make this method only end when not inside an impl frame. 656 // TODO(mithro): Make this method only end when not inside an impl frame.
661 bool main_frame_will_happen = layer_tree_host_in_process_ 657 bool main_frame_will_happen =
662 ? layer_tree_host_in_process_->proxy() 658 layer_tree_host_
663 ->MainFrameWillHappenForTesting() 659 ? layer_tree_host_->proxy()->MainFrameWillHappenForTesting()
664 : false; 660 : false;
665 661
666 if (main_frame_will_happen && !timed_out_) { 662 if (main_frame_will_happen && !timed_out_) {
667 main_task_runner_->PostTask( 663 main_task_runner_->PostTask(
668 FROM_HERE, 664 FROM_HERE,
669 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); 665 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
670 return; 666 return;
671 } 667 }
672 668
673 base::MessageLoop::current()->QuitWhenIdle(); 669 base::MessageLoop::current()->QuitWhenIdle();
674 } 670 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 LayerTreeTest::CreateDisplayOutputSurfaceOnThread( 809 LayerTreeTest::CreateDisplayOutputSurfaceOnThread(
814 scoped_refptr<ContextProvider> compositor_context_provider) { 810 scoped_refptr<ContextProvider> compositor_context_provider) {
815 // By default the Display shares a context with the LayerTreeHostImpl. 811 // By default the Display shares a context with the LayerTreeHostImpl.
816 return FakeOutputSurface::Create3d(std::move(compositor_context_provider)); 812 return FakeOutputSurface::Create3d(std::move(compositor_context_provider));
817 } 813 }
818 814
819 void LayerTreeTest::DestroyLayerTreeHost() { 815 void LayerTreeTest::DestroyLayerTreeHost() {
820 if (layer_tree_host_ && layer_tree_host_->GetLayerTree()->root_layer()) 816 if (layer_tree_host_ && layer_tree_host_->GetLayerTree()->root_layer())
821 layer_tree_host_->GetLayerTree()->root_layer()->SetLayerTreeHost(NULL); 817 layer_tree_host_->GetLayerTree()->root_layer()->SetLayerTreeHost(NULL);
822 layer_tree_host_ = nullptr; 818 layer_tree_host_ = nullptr;
823 layer_tree_host_in_process_ = nullptr;
824 } 819 }
825 820
826 TaskRunnerProvider* LayerTreeTest::task_runner_provider() const { 821 TaskRunnerProvider* LayerTreeTest::task_runner_provider() const {
827 LayerTreeHost* host = layer_tree_host_.get(); 822 LayerTreeHost* host = layer_tree_host_.get();
828 823
829 // If this fails, the test has ended and there is no task runners to find 824 // If this fails, the test has ended and there is no task runners to find
830 // anymore. 825 // anymore.
831 DCHECK(host); 826 DCHECK(host);
832 827
833 return host->GetTaskRunnerProvider(); 828 return host->GetTaskRunnerProvider();
834 } 829 }
835 830
836 LayerTreeHost* LayerTreeTest::layer_tree_host() { 831 LayerTreeHost* LayerTreeTest::layer_tree_host() {
837 DCHECK(task_runner_provider()->IsMainThread() || 832 DCHECK(task_runner_provider()->IsMainThread() ||
838 task_runner_provider()->IsMainThreadBlocked()); 833 task_runner_provider()->IsMainThreadBlocked());
839 return layer_tree_host_.get(); 834 return layer_tree_host_.get();
840 } 835 }
841 836
842 LayerTreeHostInProcess* LayerTreeTest::layer_tree_host_in_process() {
843 DCHECK(task_runner_provider()->IsMainThread() ||
844 task_runner_provider()->IsMainThreadBlocked());
845 return layer_tree_host_in_process_;
846 }
847
848 Proxy* LayerTreeTest::proxy() { 837 Proxy* LayerTreeTest::proxy() {
849 return layer_tree_host_in_process() ? layer_tree_host_in_process()->proxy() 838 return layer_tree_host() ? layer_tree_host()->proxy() : NULL;
850 : NULL;
851 } 839 }
852 840
853 } // namespace cc 841 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/trees/layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698