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

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

Issue 619843002: cc: Make separate interface for BeginFrame ipc from OutputSurface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/fake_layer_tree_host_client.h" 19 #include "cc/test/fake_layer_tree_host_client.h"
19 #include "cc/test/fake_output_surface.h" 20 #include "cc/test/fake_output_surface.h"
20 #include "cc/test/test_context_provider.h" 21 #include "cc/test/test_context_provider.h"
21 #include "cc/test/test_gpu_memory_buffer_manager.h" 22 #include "cc/test/test_gpu_memory_buffer_manager.h"
22 #include "cc/test/test_shared_bitmap_manager.h" 23 #include "cc/test/test_shared_bitmap_manager.h"
23 #include "cc/test/tiled_layer_test_common.h" 24 #include "cc/test/tiled_layer_test_common.h"
24 #include "cc/trees/layer_tree_host_client.h" 25 #include "cc/trees/layer_tree_host_client.h"
25 #include "cc/trees/layer_tree_host_impl.h" 26 #include "cc/trees/layer_tree_host_impl.h"
26 #include "cc/trees/layer_tree_host_single_thread_client.h" 27 #include "cc/trees/layer_tree_host_single_thread_client.h"
27 #include "cc/trees/layer_tree_impl.h" 28 #include "cc/trees/layer_tree_impl.h"
(...skipping 13 matching lines...) Expand all
41 LayerTreeHostImpl* host_impl, 42 LayerTreeHostImpl* host_impl,
42 LayerTreeHostImpl::FrameData* frame_data, 43 LayerTreeHostImpl::FrameData* frame_data,
43 DrawResult draw_result) { 44 DrawResult draw_result) {
44 return draw_result; 45 return draw_result;
45 } 46 }
46 47
47 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { 48 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const {
48 return base::TimeDelta::FromMilliseconds(16); 49 return base::TimeDelta::FromMilliseconds(16);
49 } 50 }
50 51
52 class ExternalBeginFrameSourceForTest
53 : public BeginFrameSourceMixIn,
54 public NON_EXPORTED_BASE(base::NonThreadSafe) {
55 public:
56 explicit ExternalBeginFrameSourceForTest(double refresh_rate)
57 : milliseconds_per_frame_(1000.0 / refresh_rate),
58 weak_ptr_factory_(this) {
59 DetachFromThread();
60 }
61
62 virtual ~ExternalBeginFrameSourceForTest() {
63 DCHECK(CalledOnValidThread());
64 }
65
66 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
67 DCHECK(CalledOnValidThread());
68 if (needs_begin_frames) {
69 base::MessageLoop::current()->PostDelayedTask(
70 FROM_HERE,
71 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame,
72 weak_ptr_factory_.GetWeakPtr()),
73 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_));
74 }
75 }
76
77 void TestOnBeginFrame() {
78 DCHECK(CalledOnValidThread());
79 CallOnBeginFrame(CreateBeginFrameArgsForTesting());
80 }
81
82 private:
83 double milliseconds_per_frame_;
84 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_;
85 };
86
51 // Adapts ThreadProxy for test. Injects test hooks for testing. 87 // Adapts ThreadProxy for test. Injects test hooks for testing.
52 class ThreadProxyForTest : public ThreadProxy { 88 class ThreadProxyForTest : public ThreadProxy {
53 public: 89 public:
54 static scoped_ptr<Proxy> Create( 90 static scoped_ptr<Proxy> Create(
55 TestHooks* test_hooks, 91 TestHooks* test_hooks,
56 LayerTreeHost* host, 92 LayerTreeHost* host,
57 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 93 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
58 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { 94 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
95 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
59 return make_scoped_ptr(new ThreadProxyForTest( 96 return make_scoped_ptr(new ThreadProxyForTest(
60 test_hooks, host, main_task_runner, impl_task_runner)); 97 test_hooks,
98 host,
99 main_task_runner,
100 impl_task_runner,
101 external_begin_frame_source.Pass()));
61 } 102 }
62 103
63 ~ThreadProxyForTest() override {} 104 ~ThreadProxyForTest() override {}
64 105
65 void test() { 106 void test() {
66 test_hooks_->Layout(); 107 test_hooks_->Layout();
67 } 108 }
68 109
69 private: 110 private:
70 TestHooks* test_hooks_; 111 TestHooks* test_hooks_;
(...skipping 22 matching lines...) Expand all
93 134
94 void ScheduledActionBeginOutputSurfaceCreation() override { 135 void ScheduledActionBeginOutputSurfaceCreation() override {
95 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); 136 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
96 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); 137 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
97 } 138 }
98 139
99 ThreadProxyForTest( 140 ThreadProxyForTest(
100 TestHooks* test_hooks, 141 TestHooks* test_hooks,
101 LayerTreeHost* host, 142 LayerTreeHost* host,
102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 143 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
103 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) 144 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
104 : ThreadProxy(host, main_task_runner, impl_task_runner), 145 scoped_ptr<BeginFrameSource> external_begin_frame_source)
146 : ThreadProxy(host, main_task_runner,
147 impl_task_runner,
148 external_begin_frame_source.Pass()),
105 test_hooks_(test_hooks) {} 149 test_hooks_(test_hooks) {}
106 }; 150 };
107 151
108 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. 152 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
109 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { 153 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
110 public: 154 public:
111 static scoped_ptr<LayerTreeHostImplForTesting> Create( 155 static scoped_ptr<LayerTreeHostImplForTesting> Create(
112 TestHooks* test_hooks, 156 TestHooks* test_hooks,
113 const LayerTreeSettings& settings, 157 const LayerTreeSettings& settings,
114 LayerTreeHostImplClient* host_impl_client, 158 LayerTreeHostImplClient* host_impl_client,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 }; 380 };
337 381
338 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 382 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
339 class LayerTreeHostForTesting : public LayerTreeHost { 383 class LayerTreeHostForTesting : public LayerTreeHost {
340 public: 384 public:
341 static scoped_ptr<LayerTreeHostForTesting> Create( 385 static scoped_ptr<LayerTreeHostForTesting> Create(
342 TestHooks* test_hooks, 386 TestHooks* test_hooks,
343 LayerTreeHostClientForTesting* client, 387 LayerTreeHostClientForTesting* client,
344 const LayerTreeSettings& settings, 388 const LayerTreeSettings& settings,
345 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 389 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
346 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { 390 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
391 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
347 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( 392 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
348 new LayerTreeHostForTesting(test_hooks, client, settings)); 393 new LayerTreeHostForTesting(test_hooks, client, settings));
349 if (impl_task_runner.get()) { 394 if (impl_task_runner.get()) {
350 layer_tree_host->InitializeForTesting( 395 layer_tree_host->InitializeForTesting(
351 ThreadProxyForTest::Create(test_hooks, 396 ThreadProxyForTest::Create(test_hooks,
352 layer_tree_host.get(), 397 layer_tree_host.get(),
353 main_task_runner, 398 main_task_runner,
354 impl_task_runner)); 399 impl_task_runner,
400 external_begin_frame_source.Pass()));
355 } else { 401 } else {
356 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( 402 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create(
357 layer_tree_host.get(), client, main_task_runner)); 403 layer_tree_host.get(),
404 client,
405 main_task_runner,
406 external_begin_frame_source.Pass()));
358 } 407 }
359 return layer_tree_host.Pass(); 408 return layer_tree_host.Pass();
360 } 409 }
361 410
362 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( 411 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
363 LayerTreeHostImplClient* host_impl_client) override { 412 LayerTreeHostImplClient* host_impl_client) override {
364 return LayerTreeHostImplForTesting::Create( 413 return LayerTreeHostImplForTesting::Create(
365 test_hooks_, 414 test_hooks_,
366 settings(), 415 settings(),
367 host_impl_client, 416 host_impl_client,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 main_thread_weak_ptr_)); 562 main_thread_weak_ptr_));
514 } 563 }
515 564
516 void LayerTreeTest::WillBeginTest() { 565 void LayerTreeTest::WillBeginTest() {
517 layer_tree_host_->SetLayerTreeHostClientReady(); 566 layer_tree_host_->SetLayerTreeHostClientReady();
518 } 567 }
519 568
520 void LayerTreeTest::DoBeginTest() { 569 void LayerTreeTest::DoBeginTest() {
521 client_ = LayerTreeHostClientForTesting::Create(this); 570 client_ = LayerTreeHostClientForTesting::Create(this);
522 571
572 scoped_ptr<BeginFrameSource> external_begin_frame_source;
573 if (settings_.begin_frame_scheduling_enabled &&
574 settings_.throttle_frame_production)
575 external_begin_frame_source.reset(
576 new ExternalBeginFrameSourceForTest(settings_.refresh_rate));
577
523 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); 578 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
524 layer_tree_host_ = LayerTreeHostForTesting::Create( 579 layer_tree_host_ = LayerTreeHostForTesting::Create(
525 this, 580 this,
526 client_.get(), 581 client_.get(),
527 settings_, 582 settings_,
528 base::MessageLoopProxy::current(), 583 base::MessageLoopProxy::current(),
529 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); 584 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL,
585 external_begin_frame_source.Pass());
530 ASSERT_TRUE(layer_tree_host_); 586 ASSERT_TRUE(layer_tree_host_);
531 587
532 started_ = true; 588 started_ = true;
533 beginning_ = true; 589 beginning_ = true;
534 SetupTree(); 590 SetupTree();
535 WillBeginTest(); 591 WillBeginTest();
536 BeginTest(); 592 BeginTest();
537 beginning_ = false; 593 beginning_ = false;
538 if (end_when_begin_returns_) 594 if (end_when_begin_returns_)
539 RealEndTest(); 595 RealEndTest();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 return -1; 770 return -1;
715 } 771 }
716 772
717 void LayerTreeTest::DestroyLayerTreeHost() { 773 void LayerTreeTest::DestroyLayerTreeHost() {
718 if (layer_tree_host_ && layer_tree_host_->root_layer()) 774 if (layer_tree_host_ && layer_tree_host_->root_layer())
719 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 775 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
720 layer_tree_host_ = nullptr; 776 layer_tree_host_ = nullptr;
721 } 777 }
722 778
723 } // namespace cc 779 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698