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

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 ExternalBeginFrameSourceForTest() : weak_ptr_factory_(this) {
57 DetachFromThread();
58 }
59
60 virtual ~ExternalBeginFrameSourceForTest() {
61 DCHECK(CalledOnValidThread());
62 }
63
64 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
65 DCHECK(CalledOnValidThread());
66 if (needs_begin_frames) {
67 base::MessageLoop::current()->PostDelayedTask(
68 FROM_HERE,
69 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame,
70 weak_ptr_factory_.GetWeakPtr()),
71 base::TimeDelta::FromMilliseconds(16));
brianderson 2014/10/18 00:08:45 Will this slow down the LayerTree tests? I think t
danakj 2014/10/18 18:02:39 https://code.google.com/p/chromium/codesearch#chro
simonhong 2014/10/23 01:03:08 Modified to use refresh_rate.
72 }
73 }
74
75 void TestOnBeginFrame() {
76 DCHECK(CalledOnValidThread());
77 CallOnBeginFrame(CreateBeginFrameArgsForTesting());
78 }
79
80 private:
81 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_;
82 };
83
51 // Adapts ThreadProxy for test. Injects test hooks for testing. 84 // Adapts ThreadProxy for test. Injects test hooks for testing.
52 class ThreadProxyForTest : public ThreadProxy { 85 class ThreadProxyForTest : public ThreadProxy {
53 public: 86 public:
54 static scoped_ptr<Proxy> Create( 87 static scoped_ptr<Proxy> Create(
55 TestHooks* test_hooks, 88 TestHooks* test_hooks,
56 LayerTreeHost* host, 89 LayerTreeHost* host,
57 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 90 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
58 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { 91 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
92 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
59 return make_scoped_ptr(new ThreadProxyForTest( 93 return make_scoped_ptr(new ThreadProxyForTest(
60 test_hooks, host, main_task_runner, impl_task_runner)); 94 test_hooks,
95 host,
96 main_task_runner,
97 impl_task_runner,
98 external_begin_frame_source.Pass()));
61 } 99 }
62 100
63 virtual ~ThreadProxyForTest() {} 101 virtual ~ThreadProxyForTest() {}
64 102
65 void test() { 103 void test() {
66 test_hooks_->Layout(); 104 test_hooks_->Layout();
67 } 105 }
68 106
69 private: 107 private:
70 TestHooks* test_hooks_; 108 TestHooks* test_hooks_;
(...skipping 22 matching lines...) Expand all
93 131
94 virtual void ScheduledActionBeginOutputSurfaceCreation() override { 132 virtual void ScheduledActionBeginOutputSurfaceCreation() override {
95 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); 133 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
96 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); 134 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
97 } 135 }
98 136
99 ThreadProxyForTest( 137 ThreadProxyForTest(
100 TestHooks* test_hooks, 138 TestHooks* test_hooks,
101 LayerTreeHost* host, 139 LayerTreeHost* host,
102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 140 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
103 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) 141 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
104 : ThreadProxy(host, main_task_runner, impl_task_runner), 142 scoped_ptr<BeginFrameSource> external_begin_frame_source)
143 : ThreadProxy(host, main_task_runner,
144 impl_task_runner,
145 external_begin_frame_source.Pass()),
105 test_hooks_(test_hooks) {} 146 test_hooks_(test_hooks) {}
106 }; 147 };
107 148
108 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. 149 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
109 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { 150 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
110 public: 151 public:
111 static scoped_ptr<LayerTreeHostImplForTesting> Create( 152 static scoped_ptr<LayerTreeHostImplForTesting> Create(
112 TestHooks* test_hooks, 153 TestHooks* test_hooks,
113 const LayerTreeSettings& settings, 154 const LayerTreeSettings& settings,
114 LayerTreeHostImplClient* host_impl_client, 155 LayerTreeHostImplClient* host_impl_client,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 }; 381 };
341 382
342 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 383 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
343 class LayerTreeHostForTesting : public LayerTreeHost { 384 class LayerTreeHostForTesting : public LayerTreeHost {
344 public: 385 public:
345 static scoped_ptr<LayerTreeHostForTesting> Create( 386 static scoped_ptr<LayerTreeHostForTesting> Create(
346 TestHooks* test_hooks, 387 TestHooks* test_hooks,
347 LayerTreeHostClientForTesting* client, 388 LayerTreeHostClientForTesting* client,
348 const LayerTreeSettings& settings, 389 const LayerTreeSettings& settings,
349 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 390 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
350 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { 391 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
392 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
351 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( 393 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
352 new LayerTreeHostForTesting(test_hooks, client, settings)); 394 new LayerTreeHostForTesting(test_hooks, client, settings));
353 if (impl_task_runner.get()) { 395 if (impl_task_runner.get()) {
354 layer_tree_host->InitializeForTesting( 396 layer_tree_host->InitializeForTesting(
355 ThreadProxyForTest::Create(test_hooks, 397 ThreadProxyForTest::Create(test_hooks,
356 layer_tree_host.get(), 398 layer_tree_host.get(),
357 main_task_runner, 399 main_task_runner,
358 impl_task_runner)); 400 impl_task_runner,
401 external_begin_frame_source.Pass()));
359 } else { 402 } else {
360 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( 403 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create(
361 layer_tree_host.get(), client, main_task_runner)); 404 layer_tree_host.get(),
405 client,
406 main_task_runner,
407 external_begin_frame_source.Pass()));
362 } 408 }
363 return layer_tree_host.Pass(); 409 return layer_tree_host.Pass();
364 } 410 }
365 411
366 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( 412 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
367 LayerTreeHostImplClient* host_impl_client) override { 413 LayerTreeHostImplClient* host_impl_client) override {
368 return LayerTreeHostImplForTesting::Create( 414 return LayerTreeHostImplForTesting::Create(
369 test_hooks_, 415 test_hooks_,
370 settings(), 416 settings(),
371 host_impl_client, 417 host_impl_client,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 main_thread_weak_ptr_)); 563 main_thread_weak_ptr_));
518 } 564 }
519 565
520 void LayerTreeTest::WillBeginTest() { 566 void LayerTreeTest::WillBeginTest() {
521 layer_tree_host_->SetLayerTreeHostClientReady(); 567 layer_tree_host_->SetLayerTreeHostClientReady();
522 } 568 }
523 569
524 void LayerTreeTest::DoBeginTest() { 570 void LayerTreeTest::DoBeginTest() {
525 client_ = LayerTreeHostClientForTesting::Create(this); 571 client_ = LayerTreeHostClientForTesting::Create(this);
526 572
573 scoped_ptr<BeginFrameSource> external_begin_frame_source;
574 if (settings_.begin_frame_scheduling_enabled &&
575 settings_.throttle_frame_production)
576 external_begin_frame_source.reset(new ExternalBeginFrameSourceForTest);
577
527 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); 578 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
528 layer_tree_host_ = LayerTreeHostForTesting::Create( 579 layer_tree_host_ = LayerTreeHostForTesting::Create(
529 this, 580 this,
530 client_.get(), 581 client_.get(),
531 settings_, 582 settings_,
532 base::MessageLoopProxy::current(), 583 base::MessageLoopProxy::current(),
533 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); 584 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL,
585 external_begin_frame_source.Pass());
534 ASSERT_TRUE(layer_tree_host_); 586 ASSERT_TRUE(layer_tree_host_);
535 587
536 started_ = true; 588 started_ = true;
537 beginning_ = true; 589 beginning_ = true;
538 SetupTree(); 590 SetupTree();
539 WillBeginTest(); 591 WillBeginTest();
540 BeginTest(); 592 BeginTest();
541 beginning_ = false; 593 beginning_ = false;
542 if (end_when_begin_returns_) 594 if (end_when_begin_returns_)
543 RealEndTest(); 595 RealEndTest();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return -1; 770 return -1;
719 } 771 }
720 772
721 void LayerTreeTest::DestroyLayerTreeHost() { 773 void LayerTreeTest::DestroyLayerTreeHost() {
722 if (layer_tree_host_ && layer_tree_host_->root_layer()) 774 if (layer_tree_host_ && layer_tree_host_->root_layer())
723 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 775 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
724 layer_tree_host_ = nullptr; 776 layer_tree_host_ = nullptr;
725 } 777 }
726 778
727 } // namespace cc 779 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698