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

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

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/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/input/input_handler.h" 13 #include "cc/input/input_handler.h"
14 #include "cc/layers/content_layer.h" 14 #include "cc/layers/content_layer.h"
15 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_impl.h" 16 #include "cc/layers/layer_impl.h"
17 #include "cc/test/animation_test_common.h" 17 #include "cc/test/animation_test_common.h"
18 #include "cc/test/begin_frame_args_test.h" 18 #include "cc/test/begin_frame_args_test.h"
19 #include "cc/test/fake_external_begin_frame_source.h"
19 #include "cc/test/fake_layer_tree_host_client.h" 20 #include "cc/test/fake_layer_tree_host_client.h"
20 #include "cc/test/fake_output_surface.h" 21 #include "cc/test/fake_output_surface.h"
21 #include "cc/test/test_context_provider.h" 22 #include "cc/test/test_context_provider.h"
22 #include "cc/test/test_gpu_memory_buffer_manager.h" 23 #include "cc/test/test_gpu_memory_buffer_manager.h"
23 #include "cc/test/test_shared_bitmap_manager.h" 24 #include "cc/test/test_shared_bitmap_manager.h"
24 #include "cc/test/tiled_layer_test_common.h" 25 #include "cc/test/tiled_layer_test_common.h"
25 #include "cc/trees/layer_tree_host_client.h" 26 #include "cc/trees/layer_tree_host_client.h"
26 #include "cc/trees/layer_tree_host_impl.h" 27 #include "cc/trees/layer_tree_host_impl.h"
27 #include "cc/trees/layer_tree_host_single_thread_client.h" 28 #include "cc/trees/layer_tree_host_single_thread_client.h"
28 #include "cc/trees/layer_tree_impl.h" 29 #include "cc/trees/layer_tree_impl.h"
(...skipping 18 matching lines...) Expand all
47 48
48 void TestHooks::CreateResourceAndTileTaskWorkerPool( 49 void TestHooks::CreateResourceAndTileTaskWorkerPool(
49 LayerTreeHostImpl* host_impl, 50 LayerTreeHostImpl* host_impl,
50 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, 51 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
51 scoped_ptr<ResourcePool>* resource_pool, 52 scoped_ptr<ResourcePool>* resource_pool,
52 scoped_ptr<ResourcePool>* staging_resource_pool) { 53 scoped_ptr<ResourcePool>* staging_resource_pool) {
53 host_impl->LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( 54 host_impl->LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
54 tile_task_worker_pool, resource_pool, staging_resource_pool); 55 tile_task_worker_pool, resource_pool, staging_resource_pool);
55 } 56 }
56 57
57 class ExternalBeginFrameSourceForTest
58 : public BeginFrameSourceMixIn,
59 public NON_EXPORTED_BASE(base::NonThreadSafe) {
60 public:
61 explicit ExternalBeginFrameSourceForTest(double refresh_rate)
62 : milliseconds_per_frame_(1000.0 / refresh_rate),
63 is_ready_(false),
64 weak_ptr_factory_(this) {
65 DetachFromThread();
66 }
67
68 virtual ~ExternalBeginFrameSourceForTest() {
69 DCHECK(CalledOnValidThread());
70 }
71
72 void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
73 DCHECK(CalledOnValidThread());
74 if (needs_begin_frames) {
75 base::MessageLoop::current()->PostDelayedTask(
76 FROM_HERE,
77 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame,
78 weak_ptr_factory_.GetWeakPtr()),
79 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_));
80 }
81 }
82
83 void SetClientReady() override {
84 DCHECK(CalledOnValidThread());
85 is_ready_ = true;
86 }
87
88 bool is_ready() const {
89 return is_ready_;
90 }
91
92 void TestOnBeginFrame() {
93 DCHECK(CalledOnValidThread());
94 CallOnBeginFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
95 }
96
97 private:
98 double milliseconds_per_frame_;
99 bool is_ready_;
100 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_;
101 };
102
103 // Adapts ThreadProxy for test. Injects test hooks for testing. 58 // Adapts ThreadProxy for test. Injects test hooks for testing.
104 class ThreadProxyForTest : public ThreadProxy { 59 class ThreadProxyForTest : public ThreadProxy {
105 public: 60 public:
106 static scoped_ptr<Proxy> Create( 61 static scoped_ptr<Proxy> Create(
107 TestHooks* test_hooks, 62 TestHooks* test_hooks,
108 LayerTreeHost* host, 63 LayerTreeHost* host,
109 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 64 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
110 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 65 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
111 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 66 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
112 return make_scoped_ptr(new ThreadProxyForTest( 67 return make_scoped_ptr(new ThreadProxyForTest(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 scoped_ptr<ResourcePool>* staging_resource_pool) override { 172 scoped_ptr<ResourcePool>* staging_resource_pool) override {
218 test_hooks_->CreateResourceAndTileTaskWorkerPool( 173 test_hooks_->CreateResourceAndTileTaskWorkerPool(
219 this, tile_task_worker_pool, resource_pool, staging_resource_pool); 174 this, tile_task_worker_pool, resource_pool, staging_resource_pool);
220 } 175 }
221 176
222 void WillBeginImplFrame(const BeginFrameArgs& args) override { 177 void WillBeginImplFrame(const BeginFrameArgs& args) override {
223 LayerTreeHostImpl::WillBeginImplFrame(args); 178 LayerTreeHostImpl::WillBeginImplFrame(args);
224 test_hooks_->WillBeginImplFrameOnThread(this, args); 179 test_hooks_->WillBeginImplFrameOnThread(this, args);
225 } 180 }
226 181
227 void BeginMainFrameAborted(bool did_handle) override { 182 void BeginMainFrameAborted(CommitEarlyOutReason reason) override {
228 LayerTreeHostImpl::BeginMainFrameAborted(did_handle); 183 LayerTreeHostImpl::BeginMainFrameAborted(reason);
229 test_hooks_->BeginMainFrameAbortedOnThread(this, did_handle); 184 test_hooks_->BeginMainFrameAbortedOnThread(this, reason);
230 } 185 }
231 186
232 void BeginCommit() override { 187 void BeginCommit() override {
233 LayerTreeHostImpl::BeginCommit(); 188 LayerTreeHostImpl::BeginCommit();
234 test_hooks_->BeginCommitOnThread(this); 189 test_hooks_->BeginCommitOnThread(this);
235 } 190 }
236 191
237 void CommitComplete() override { 192 void CommitComplete() override {
238 LayerTreeHostImpl::CommitComplete(); 193 LayerTreeHostImpl::CommitComplete();
239 test_hooks_->CommitCompleteOnThread(this); 194 test_hooks_->CommitCompleteOnThread(this);
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 main_thread_weak_ptr_)); 562 main_thread_weak_ptr_));
608 } 563 }
609 564
610 void LayerTreeTest::WillBeginTest() { 565 void LayerTreeTest::WillBeginTest() {
611 layer_tree_host_->SetLayerTreeHostClientReady(); 566 layer_tree_host_->SetLayerTreeHostClientReady();
612 } 567 }
613 568
614 void LayerTreeTest::DoBeginTest() { 569 void LayerTreeTest::DoBeginTest() {
615 client_ = LayerTreeHostClientForTesting::Create(this); 570 client_ = LayerTreeHostClientForTesting::Create(this);
616 571
617 scoped_ptr<ExternalBeginFrameSourceForTest> external_begin_frame_source; 572 scoped_ptr<FakeExternalBeginFrameSource> external_begin_frame_source;
618 if (settings_.use_external_begin_frame_source && 573 if (settings_.use_external_begin_frame_source &&
619 settings_.throttle_frame_production) { 574 settings_.throttle_frame_production) {
620 external_begin_frame_source.reset(new ExternalBeginFrameSourceForTest( 575 external_begin_frame_source.reset(new FakeExternalBeginFrameSource(
621 settings_.renderer_settings.refresh_rate)); 576 settings_.renderer_settings.refresh_rate));
622 external_begin_frame_source_ = external_begin_frame_source.get(); 577 external_begin_frame_source_ = external_begin_frame_source.get();
623 } 578 }
624 579
625 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); 580 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
626 layer_tree_host_ = LayerTreeHostForTesting::Create( 581 layer_tree_host_ = LayerTreeHostForTesting::Create(
627 this, 582 this,
628 client_.get(), 583 client_.get(),
629 settings_, 584 settings_,
630 base::MessageLoopProxy::current(), 585 base::MessageLoopProxy::current(),
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 702
748 main_task_runner_ = base::MessageLoopProxy::current(); 703 main_task_runner_ = base::MessageLoopProxy::current();
749 704
750 delegating_renderer_ = delegating_renderer; 705 delegating_renderer_ = delegating_renderer;
751 706
752 // Spend less time waiting for BeginFrame because the output is 707 // Spend less time waiting for BeginFrame because the output is
753 // mocked out. 708 // mocked out.
754 settings_.renderer_settings.refresh_rate = 200.0; 709 settings_.renderer_settings.refresh_rate = 200.0;
755 settings_.background_animation_rate = 200.0; 710 settings_.background_animation_rate = 200.0;
756 settings_.impl_side_painting = impl_side_painting; 711 settings_.impl_side_painting = impl_side_painting;
712 settings_.verify_property_trees = true;
757 InitializeSettings(&settings_); 713 InitializeSettings(&settings_);
758 714
759 main_task_runner_->PostTask( 715 main_task_runner_->PostTask(
760 FROM_HERE, 716 FROM_HERE,
761 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); 717 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
762 718
763 if (timeout_seconds_) { 719 if (timeout_seconds_) {
764 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); 720 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
765 main_task_runner_->PostDelayedTask( 721 main_task_runner_->PostDelayedTask(
766 FROM_HERE, 722 FROM_HERE,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 return -1; 782 return -1;
827 } 783 }
828 784
829 void LayerTreeTest::DestroyLayerTreeHost() { 785 void LayerTreeTest::DestroyLayerTreeHost() {
830 if (layer_tree_host_ && layer_tree_host_->root_layer()) 786 if (layer_tree_host_ && layer_tree_host_->root_layer())
831 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 787 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
832 layer_tree_host_ = nullptr; 788 layer_tree_host_ = nullptr;
833 } 789 }
834 790
835 } // namespace cc 791 } // 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