Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / test / layer_tree_test.cc
blobe53af8eb482aefaa510ad179be6ca14c74f92367
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
3 // found in the LICENSE file.
5 #include "cc/test/layer_tree_test.h"
7 #include "base/command_line.h"
8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_registrar.h"
10 #include "cc/animation/layer_animation_controller.h"
11 #include "cc/animation/timing_function.h"
12 #include "cc/base/switches.h"
13 #include "cc/input/input_handler.h"
14 #include "cc/layers/content_layer.h"
15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/test/animation_test_common.h"
18 #include "cc/test/fake_layer_tree_host_client.h"
19 #include "cc/test/fake_output_surface.h"
20 #include "cc/test/test_context_provider.h"
21 #include "cc/test/test_shared_bitmap_manager.h"
22 #include "cc/test/tiled_layer_test_common.h"
23 #include "cc/trees/layer_tree_host_client.h"
24 #include "cc/trees/layer_tree_host_impl.h"
25 #include "cc/trees/layer_tree_host_single_thread_client.h"
26 #include "cc/trees/layer_tree_impl.h"
27 #include "cc/trees/single_thread_proxy.h"
28 #include "cc/trees/thread_proxy.h"
29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "ui/gfx/frame_time.h"
31 #include "ui/gfx/size_conversions.h"
33 namespace cc {
35 TestHooks::TestHooks() {}
37 TestHooks::~TestHooks() {}
39 DrawResult TestHooks::PrepareToDrawOnThread(
40 LayerTreeHostImpl* host_impl,
41 LayerTreeHostImpl::FrameData* frame_data,
42 DrawResult draw_result) {
43 return draw_result;
46 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const {
47 return base::TimeDelta::FromMilliseconds(16);
50 // Adapts ThreadProxy for test. Injects test hooks for testing.
51 class ThreadProxyForTest : public ThreadProxy {
52 public:
53 static scoped_ptr<Proxy> Create(
54 TestHooks* test_hooks,
55 LayerTreeHost* host,
56 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
57 return make_scoped_ptr(
58 new ThreadProxyForTest(test_hooks,
59 host,
60 impl_task_runner)).PassAs<Proxy>();
63 virtual ~ThreadProxyForTest() {}
65 void test() {
66 test_hooks_->Layout();
69 private:
70 TestHooks* test_hooks_;
72 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
73 test_hooks_->ScheduledActionWillSendBeginMainFrame();
74 ThreadProxy::ScheduledActionSendBeginMainFrame();
75 test_hooks_->ScheduledActionSendBeginMainFrame();
78 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE {
79 DrawResult result = ThreadProxy::ScheduledActionDrawAndSwapIfPossible();
80 test_hooks_->ScheduledActionDrawAndSwapIfPossible();
81 return result;
84 virtual void ScheduledActionAnimate() OVERRIDE {
85 ThreadProxy::ScheduledActionAnimate();
86 test_hooks_->ScheduledActionAnimate();
89 virtual void ScheduledActionCommit() OVERRIDE {
90 ThreadProxy::ScheduledActionCommit();
91 test_hooks_->ScheduledActionCommit();
94 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {
95 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
96 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
99 ThreadProxyForTest(
100 TestHooks* test_hooks,
101 LayerTreeHost* host,
102 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
103 : ThreadProxy(host, impl_task_runner),
104 test_hooks_(test_hooks) {
108 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
109 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
110 public:
111 static scoped_ptr<LayerTreeHostImplForTesting> Create(
112 TestHooks* test_hooks,
113 const LayerTreeSettings& settings,
114 LayerTreeHostImplClient* host_impl_client,
115 Proxy* proxy,
116 SharedBitmapManager* manager,
117 RenderingStatsInstrumentation* stats_instrumentation) {
118 return make_scoped_ptr(
119 new LayerTreeHostImplForTesting(test_hooks,
120 settings,
121 host_impl_client,
122 proxy,
123 manager,
124 stats_instrumentation));
127 protected:
128 LayerTreeHostImplForTesting(
129 TestHooks* test_hooks,
130 const LayerTreeSettings& settings,
131 LayerTreeHostImplClient* host_impl_client,
132 Proxy* proxy,
133 SharedBitmapManager* manager,
134 RenderingStatsInstrumentation* stats_instrumentation)
135 : LayerTreeHostImpl(settings,
136 host_impl_client,
137 proxy,
138 stats_instrumentation,
139 manager,
141 test_hooks_(test_hooks),
142 block_notify_ready_to_activate_for_testing_(false),
143 notify_ready_to_activate_was_blocked_(false) {}
145 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
146 LayerTreeHostImpl::WillBeginImplFrame(args);
147 test_hooks_->WillBeginImplFrameOnThread(this, args);
150 virtual void BeginMainFrameAborted(bool did_handle) OVERRIDE {
151 LayerTreeHostImpl::BeginMainFrameAborted(did_handle);
152 test_hooks_->BeginMainFrameAbortedOnThread(this, did_handle);
155 virtual void BeginCommit() OVERRIDE {
156 LayerTreeHostImpl::BeginCommit();
157 test_hooks_->BeginCommitOnThread(this);
160 virtual void CommitComplete() OVERRIDE {
161 LayerTreeHostImpl::CommitComplete();
162 test_hooks_->CommitCompleteOnThread(this);
165 virtual DrawResult PrepareToDraw(FrameData* frame) OVERRIDE {
166 DrawResult draw_result = LayerTreeHostImpl::PrepareToDraw(frame);
167 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result);
170 virtual void DrawLayers(FrameData* frame) OVERRIDE {
171 LayerTreeHostImpl::DrawLayers(frame);
172 test_hooks_->DrawLayersOnThread(this);
175 virtual bool SwapBuffers(const LayerTreeHostImpl::FrameData& frame) OVERRIDE {
176 bool result = LayerTreeHostImpl::SwapBuffers(frame);
177 test_hooks_->SwapBuffersOnThread(this, result);
178 return result;
181 virtual void DidSwapBuffersComplete() OVERRIDE {
182 LayerTreeHostImpl::DidSwapBuffersComplete();
183 test_hooks_->SwapBuffersCompleteOnThread(this);
186 virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE {
187 LayerTreeHostImpl::ReclaimResources(ack);
190 virtual void UpdateVisibleTiles() OVERRIDE {
191 LayerTreeHostImpl::UpdateVisibleTiles();
192 test_hooks_->UpdateVisibleTilesOnThread(this);
195 virtual void NotifyReadyToActivate() OVERRIDE {
196 if (block_notify_ready_to_activate_for_testing_)
197 notify_ready_to_activate_was_blocked_ = true;
198 else
199 client_->NotifyReadyToActivate();
202 virtual void BlockNotifyReadyToActivateForTesting(bool block) OVERRIDE {
203 block_notify_ready_to_activate_for_testing_ = block;
204 if (!block && notify_ready_to_activate_was_blocked_) {
205 NotifyReadyToActivate();
206 notify_ready_to_activate_was_blocked_ = false;
210 virtual void ActivateSyncTree() OVERRIDE {
211 test_hooks_->WillActivateTreeOnThread(this);
212 LayerTreeHostImpl::ActivateSyncTree();
213 DCHECK(!pending_tree());
214 test_hooks_->DidActivateTreeOnThread(this);
217 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface)
218 OVERRIDE {
219 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass());
220 test_hooks_->InitializedRendererOnThread(this, success);
221 return success;
224 virtual void SetVisible(bool visible) OVERRIDE {
225 LayerTreeHostImpl::SetVisible(visible);
226 test_hooks_->DidSetVisibleOnImplTree(this, visible);
229 virtual void AnimateLayers(base::TimeTicks monotonic_time) OVERRIDE {
230 test_hooks_->WillAnimateLayers(this, monotonic_time);
231 LayerTreeHostImpl::AnimateLayers(monotonic_time);
232 test_hooks_->AnimateLayers(this, monotonic_time);
235 virtual void UpdateAnimationState(bool start_ready_animations) OVERRIDE {
236 LayerTreeHostImpl::UpdateAnimationState(start_ready_animations);
237 bool has_unfinished_animation = false;
238 AnimationRegistrar::AnimationControllerMap::const_iterator iter =
239 active_animation_controllers().begin();
240 for (; iter != active_animation_controllers().end(); ++iter) {
241 if (iter->second->HasActiveAnimation()) {
242 has_unfinished_animation = true;
243 break;
246 test_hooks_->UpdateAnimationState(this, has_unfinished_animation);
249 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE {
250 return test_hooks_->LowFrequencyAnimationInterval();
253 private:
254 TestHooks* test_hooks_;
255 bool block_notify_ready_to_activate_for_testing_;
256 bool notify_ready_to_activate_was_blocked_;
259 // Implementation of LayerTreeHost callback interface.
260 class LayerTreeHostClientForTesting : public LayerTreeHostClient,
261 public LayerTreeHostSingleThreadClient {
262 public:
263 static scoped_ptr<LayerTreeHostClientForTesting> Create(
264 TestHooks* test_hooks) {
265 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks));
267 virtual ~LayerTreeHostClientForTesting() {}
269 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {
270 test_hooks_->WillBeginMainFrame();
273 virtual void DidBeginMainFrame() OVERRIDE {
274 test_hooks_->DidBeginMainFrame();
277 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE {
278 test_hooks_->Animate(monotonic_time);
281 virtual void Layout() OVERRIDE { test_hooks_->Layout(); }
283 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
284 float scale) OVERRIDE {
285 test_hooks_->ApplyScrollAndScale(scroll_delta, scale);
288 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
289 OVERRIDE {
290 return test_hooks_->CreateOutputSurface(fallback);
293 virtual void DidInitializeOutputSurface() OVERRIDE {
294 test_hooks_->DidInitializeOutputSurface();
297 virtual void DidFailToInitializeOutputSurface() OVERRIDE {
298 test_hooks_->DidFailToInitializeOutputSurface();
301 virtual void WillCommit() OVERRIDE { test_hooks_->WillCommit(); }
303 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); }
305 virtual void DidCommitAndDrawFrame() OVERRIDE {
306 test_hooks_->DidCommitAndDrawFrame();
309 virtual void DidCompleteSwapBuffers() OVERRIDE {
310 test_hooks_->DidCompleteSwapBuffers();
313 virtual void ScheduleComposite() OVERRIDE {
314 test_hooks_->ScheduleComposite();
317 virtual void ScheduleAnimation() OVERRIDE {
318 test_hooks_->ScheduleAnimation();
321 virtual void DidPostSwapBuffers() OVERRIDE {}
322 virtual void DidAbortSwapBuffers() OVERRIDE {}
324 private:
325 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
326 : test_hooks_(test_hooks) {}
328 TestHooks* test_hooks_;
331 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
332 class LayerTreeHostForTesting : public LayerTreeHost {
333 public:
334 static scoped_ptr<LayerTreeHostForTesting> Create(
335 TestHooks* test_hooks,
336 LayerTreeHostClientForTesting* client,
337 const LayerTreeSettings& settings,
338 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
339 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
340 new LayerTreeHostForTesting(test_hooks, client, settings));
341 if (impl_task_runner.get()) {
342 layer_tree_host->InitializeForTesting(
343 ThreadProxyForTest::Create(test_hooks,
344 layer_tree_host.get(),
345 impl_task_runner));
346 } else {
347 layer_tree_host->InitializeForTesting(
348 SingleThreadProxy::Create(layer_tree_host.get(), client));
350 return layer_tree_host.Pass();
353 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
354 LayerTreeHostImplClient* host_impl_client) OVERRIDE {
355 return LayerTreeHostImplForTesting::Create(
356 test_hooks_,
357 settings(),
358 host_impl_client,
359 proxy(),
360 shared_bitmap_manager_.get(),
361 rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>();
364 virtual void SetNeedsCommit() OVERRIDE {
365 if (!test_started_)
366 return;
367 LayerTreeHost::SetNeedsCommit();
370 void set_test_started(bool started) { test_started_ = started; }
372 virtual void DidDeferCommit() OVERRIDE { test_hooks_->DidDeferCommit(); }
374 private:
375 LayerTreeHostForTesting(TestHooks* test_hooks,
376 LayerTreeHostClient* client,
377 const LayerTreeSettings& settings)
378 : LayerTreeHost(client, NULL, settings),
379 shared_bitmap_manager_(new TestSharedBitmapManager()),
380 test_hooks_(test_hooks),
381 test_started_(false) {}
383 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
384 TestHooks* test_hooks_;
385 bool test_started_;
388 LayerTreeTest::LayerTreeTest()
389 : beginning_(false),
390 end_when_begin_returns_(false),
391 timed_out_(false),
392 scheduled_(false),
393 schedule_when_set_visible_true_(false),
394 started_(false),
395 ended_(false),
396 delegating_renderer_(false),
397 timeout_seconds_(0),
398 weak_factory_(this) {
399 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr();
401 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was
402 // specified (for running in a debugger).
403 CommandLine* command_line = CommandLine::ForCurrentProcess();
404 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout))
405 timeout_seconds_ = 5;
408 LayerTreeTest::~LayerTreeTest() {}
410 void LayerTreeTest::EndTest() {
411 if (ended_)
412 return;
413 ended_ = true;
415 // For the case where we EndTest during BeginTest(), set a flag to indicate
416 // that the test should end the second BeginTest regains control.
417 if (beginning_) {
418 end_when_begin_returns_ = true;
419 } else {
420 main_task_runner_->PostTask(
421 FROM_HERE,
422 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
426 void LayerTreeTest::EndTestAfterDelay(int delay_milliseconds) {
427 main_task_runner_->PostDelayedTask(
428 FROM_HERE,
429 base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_),
430 base::TimeDelta::FromMilliseconds(delay_milliseconds));
433 void LayerTreeTest::PostAddAnimationToMainThread(
434 Layer* layer_to_receive_animation) {
435 main_task_runner_->PostTask(
436 FROM_HERE,
437 base::Bind(&LayerTreeTest::DispatchAddAnimation,
438 main_thread_weak_ptr_,
439 base::Unretained(layer_to_receive_animation),
440 0.000001));
443 void LayerTreeTest::PostAddInstantAnimationToMainThread(
444 Layer* layer_to_receive_animation) {
445 main_task_runner_->PostTask(
446 FROM_HERE,
447 base::Bind(&LayerTreeTest::DispatchAddAnimation,
448 main_thread_weak_ptr_,
449 base::Unretained(layer_to_receive_animation),
450 0.0));
453 void LayerTreeTest::PostAddLongAnimationToMainThread(
454 Layer* layer_to_receive_animation) {
455 main_task_runner_->PostTask(
456 FROM_HERE,
457 base::Bind(&LayerTreeTest::DispatchAddAnimation,
458 main_thread_weak_ptr_,
459 base::Unretained(layer_to_receive_animation),
460 1.0));
463 void LayerTreeTest::PostSetNeedsCommitToMainThread() {
464 main_task_runner_->PostTask(FROM_HERE,
465 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit,
466 main_thread_weak_ptr_));
469 void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() {
470 main_task_runner_->PostTask(
471 FROM_HERE,
472 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers,
473 main_thread_weak_ptr_));
476 void LayerTreeTest::PostSetNeedsRedrawToMainThread() {
477 main_task_runner_->PostTask(FROM_HERE,
478 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw,
479 main_thread_weak_ptr_));
482 void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(
483 const gfx::Rect& damage_rect) {
484 main_task_runner_->PostTask(
485 FROM_HERE,
486 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect,
487 main_thread_weak_ptr_,
488 damage_rect));
491 void LayerTreeTest::PostSetVisibleToMainThread(bool visible) {
492 main_task_runner_->PostTask(
493 FROM_HERE,
494 base::Bind(
495 &LayerTreeTest::DispatchSetVisible, main_thread_weak_ptr_, visible));
498 void LayerTreeTest::PostSetNextCommitForcesRedrawToMainThread() {
499 main_task_runner_->PostTask(
500 FROM_HERE,
501 base::Bind(&LayerTreeTest::DispatchSetNextCommitForcesRedraw,
502 main_thread_weak_ptr_));
505 void LayerTreeTest::WillBeginTest() {
506 layer_tree_host_->SetLayerTreeHostClientReady();
509 void LayerTreeTest::DoBeginTest() {
510 client_ = LayerTreeHostClientForTesting::Create(this);
512 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
513 layer_tree_host_ = LayerTreeHostForTesting::Create(
514 this,
515 client_.get(),
516 settings_,
517 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL);
518 ASSERT_TRUE(layer_tree_host_);
520 started_ = true;
521 beginning_ = true;
522 SetupTree();
523 WillBeginTest();
524 BeginTest();
525 beginning_ = false;
526 if (end_when_begin_returns_)
527 RealEndTest();
529 // Allow commits to happen once BeginTest() has had a chance to post tasks
530 // so that those tasks will happen before the first commit.
531 if (layer_tree_host_) {
532 static_cast<LayerTreeHostForTesting*>(layer_tree_host_.get())
533 ->set_test_started(true);
537 void LayerTreeTest::SetupTree() {
538 if (!layer_tree_host_->root_layer()) {
539 scoped_refptr<Layer> root_layer = Layer::Create();
540 root_layer->SetBounds(gfx::Size(1, 1));
541 root_layer->SetIsDrawable(true);
542 layer_tree_host_->SetRootLayer(root_layer);
545 gfx::Size root_bounds = layer_tree_host_->root_layer()->bounds();
546 gfx::Size device_root_bounds = gfx::ToCeiledSize(
547 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor()));
548 layer_tree_host_->SetViewportSize(device_root_bounds);
551 void LayerTreeTest::Timeout() {
552 timed_out_ = true;
553 EndTest();
556 void LayerTreeTest::ScheduleComposite() {
557 if (!started_ || scheduled_)
558 return;
559 scheduled_ = true;
560 main_task_runner_->PostTask(
561 FROM_HERE,
562 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_));
565 void LayerTreeTest::RealEndTest() {
566 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) {
567 main_task_runner_->PostTask(
568 FROM_HERE,
569 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
570 return;
573 base::MessageLoop::current()->Quit();
576 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation,
577 double animation_duration) {
578 DCHECK(!proxy() || proxy()->IsMainThread());
580 if (layer_to_receive_animation) {
581 AddOpacityTransitionToLayer(
582 layer_to_receive_animation, animation_duration, 0, 0.5, true);
586 void LayerTreeTest::DispatchSetNeedsCommit() {
587 DCHECK(!proxy() || proxy()->IsMainThread());
589 if (layer_tree_host_)
590 layer_tree_host_->SetNeedsCommit();
593 void LayerTreeTest::DispatchSetNeedsUpdateLayers() {
594 DCHECK(!proxy() || proxy()->IsMainThread());
596 if (layer_tree_host_)
597 layer_tree_host_->SetNeedsUpdateLayers();
600 void LayerTreeTest::DispatchSetNeedsRedraw() {
601 DCHECK(!proxy() || proxy()->IsMainThread());
603 if (layer_tree_host_)
604 layer_tree_host_->SetNeedsRedraw();
607 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) {
608 DCHECK(!proxy() || proxy()->IsMainThread());
610 if (layer_tree_host_)
611 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
614 void LayerTreeTest::DispatchSetVisible(bool visible) {
615 DCHECK(!proxy() || proxy()->IsMainThread());
617 if (!layer_tree_host_)
618 return;
620 layer_tree_host_->SetVisible(visible);
622 // If the LTH is being made visible and a previous ScheduleComposite() was
623 // deferred because the LTH was not visible, re-schedule the composite now.
624 if (layer_tree_host_->visible() && schedule_when_set_visible_true_)
625 ScheduleComposite();
628 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
629 DCHECK(!proxy() || proxy()->IsMainThread());
631 if (layer_tree_host_)
632 layer_tree_host_->SetNextCommitForcesRedraw();
635 void LayerTreeTest::DispatchComposite() {
636 scheduled_ = false;
638 if (!layer_tree_host_)
639 return;
641 // If the LTH is not visible, defer the composite until the LTH is made
642 // visible.
643 if (!layer_tree_host_->visible()) {
644 schedule_when_set_visible_true_ = true;
645 return;
648 schedule_when_set_visible_true_ = false;
649 base::TimeTicks now = gfx::FrameTime::Now();
650 layer_tree_host_->Composite(now);
653 void LayerTreeTest::RunTest(bool threaded,
654 bool delegating_renderer,
655 bool impl_side_painting) {
656 if (threaded) {
657 impl_thread_.reset(new base::Thread("Compositor"));
658 ASSERT_TRUE(impl_thread_->Start());
661 main_task_runner_ = base::MessageLoopProxy::current();
663 delegating_renderer_ = delegating_renderer;
665 // Spend less time waiting for BeginFrame because the output is
666 // mocked out.
667 settings_.refresh_rate = 200.0;
668 if (impl_side_painting) {
669 DCHECK(threaded)
670 << "Don't run single thread + impl side painting, it doesn't exist.";
671 settings_.impl_side_painting = true;
673 InitializeSettings(&settings_);
675 main_task_runner_->PostTask(
676 FROM_HERE,
677 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
679 if (timeout_seconds_) {
680 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
681 main_task_runner_->PostDelayedTask(
682 FROM_HERE,
683 timeout_.callback(),
684 base::TimeDelta::FromSeconds(timeout_seconds_));
687 base::MessageLoop::current()->Run();
688 DestroyLayerTreeHost();
690 timeout_.Cancel();
692 ASSERT_FALSE(layer_tree_host_.get());
693 client_.reset();
694 if (timed_out_) {
695 FAIL() << "Test timed out";
696 return;
698 AfterTest();
701 void LayerTreeTest::RunTestWithImplSidePainting() {
702 RunTest(true, false, true);
705 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) {
706 scoped_ptr<FakeOutputSurface> output_surface =
707 CreateFakeOutputSurface(fallback);
708 if (output_surface) {
709 DCHECK_EQ(delegating_renderer_,
710 output_surface->capabilities().delegated_rendering);
712 output_surface_ = output_surface.get();
713 return output_surface.PassAs<OutputSurface>();
716 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface(
717 bool fallback) {
718 if (delegating_renderer_)
719 return FakeOutputSurface::CreateDelegating3d();
720 else
721 return FakeOutputSurface::Create3d();
724 TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
725 return static_cast<TestContextProvider*>(
726 output_surface_->context_provider().get())->TestContext3d();
729 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
730 const {
731 if (impl->pending_tree())
732 return impl->pending_tree()->source_frame_number();
733 if (impl->active_tree())
734 return impl->active_tree()->source_frame_number();
735 // Source frames start at 0, so this is invalid.
736 return -1;
739 void LayerTreeTest::DestroyLayerTreeHost() {
740 if (layer_tree_host_ && layer_tree_host_->root_layer())
741 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
742 layer_tree_host_.reset();
745 } // namespace cc