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

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

Powered by Google App Engine
This is Rietveld 408576698