Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / cc / test / layer_tree_test.cc
blobed8de3406c6c6eb514e237307904b38f1d12c80f
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 "testing/gmock/include/gmock/gmock.h"
29 #include "ui/gfx/frame_time.h"
30 #include "ui/gfx/size_conversions.h"
32 namespace cc {
34 TestHooks::TestHooks() {}
36 TestHooks::~TestHooks() {}
38 DrawSwapReadbackResult::DrawResult TestHooks::PrepareToDrawOnThread(
39 LayerTreeHostImpl* host_impl,
40 LayerTreeHostImpl::FrameData* frame_data,
41 DrawSwapReadbackResult::DrawResult draw_result) {
42 return draw_result;
45 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const {
46 return base::TimeDelta::FromMilliseconds(16);
49 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
50 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
51 public:
52 static scoped_ptr<LayerTreeHostImplForTesting> Create(
53 TestHooks* test_hooks,
54 const LayerTreeSettings& settings,
55 LayerTreeHostImplClient* host_impl_client,
56 Proxy* proxy,
57 SharedBitmapManager* manager,
58 RenderingStatsInstrumentation* stats_instrumentation) {
59 return make_scoped_ptr(
60 new LayerTreeHostImplForTesting(test_hooks,
61 settings,
62 host_impl_client,
63 proxy,
64 manager,
65 stats_instrumentation));
68 protected:
69 LayerTreeHostImplForTesting(
70 TestHooks* test_hooks,
71 const LayerTreeSettings& settings,
72 LayerTreeHostImplClient* host_impl_client,
73 Proxy* proxy,
74 SharedBitmapManager* manager,
75 RenderingStatsInstrumentation* stats_instrumentation)
76 : LayerTreeHostImpl(settings,
77 host_impl_client,
78 proxy,
79 stats_instrumentation,
80 manager,
81 0),
82 test_hooks_(test_hooks),
83 block_notify_ready_to_activate_for_testing_(false),
84 notify_ready_to_activate_was_blocked_(false) {}
86 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
87 LayerTreeHostImpl::WillBeginImplFrame(args);
88 test_hooks_->WillBeginImplFrameOnThread(this, args);
91 virtual void BeginMainFrameAborted(bool did_handle) OVERRIDE {
92 LayerTreeHostImpl::BeginMainFrameAborted(did_handle);
93 test_hooks_->BeginMainFrameAbortedOnThread(this, did_handle);
96 virtual void BeginCommit() OVERRIDE {
97 LayerTreeHostImpl::BeginCommit();
98 test_hooks_->BeginCommitOnThread(this);
101 virtual void CommitComplete() OVERRIDE {
102 LayerTreeHostImpl::CommitComplete();
103 test_hooks_->CommitCompleteOnThread(this);
105 if (!settings().impl_side_painting) {
106 test_hooks_->WillActivateTreeOnThread(this);
107 test_hooks_->DidActivateTreeOnThread(this);
111 virtual DrawSwapReadbackResult::DrawResult PrepareToDraw(
112 FrameData* frame,
113 const gfx::Rect& damage_rect) OVERRIDE {
114 DrawSwapReadbackResult::DrawResult draw_result =
115 LayerTreeHostImpl::PrepareToDraw(frame, damage_rect);
116 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result);
119 virtual void DrawLayers(FrameData* frame,
120 base::TimeTicks frame_begin_time) OVERRIDE {
121 LayerTreeHostImpl::DrawLayers(frame, frame_begin_time);
122 test_hooks_->DrawLayersOnThread(this);
125 virtual bool SwapBuffers(const LayerTreeHostImpl::FrameData& frame) OVERRIDE {
126 bool result = LayerTreeHostImpl::SwapBuffers(frame);
127 test_hooks_->SwapBuffersOnThread(this, result);
128 return result;
131 virtual void OnSwapBuffersComplete() OVERRIDE {
132 LayerTreeHostImpl::OnSwapBuffersComplete();
133 test_hooks_->SwapBuffersCompleteOnThread(this);
136 virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE {
137 LayerTreeHostImpl::ReclaimResources(ack);
140 virtual void UpdateVisibleTiles() OVERRIDE {
141 LayerTreeHostImpl::UpdateVisibleTiles();
142 test_hooks_->UpdateVisibleTilesOnThread(this);
145 virtual void NotifyReadyToActivate() OVERRIDE {
146 if (block_notify_ready_to_activate_for_testing_)
147 notify_ready_to_activate_was_blocked_ = true;
148 else
149 client_->NotifyReadyToActivate();
152 virtual void BlockNotifyReadyToActivateForTesting(bool block) OVERRIDE {
153 block_notify_ready_to_activate_for_testing_ = block;
154 if (!block && notify_ready_to_activate_was_blocked_) {
155 NotifyReadyToActivate();
156 notify_ready_to_activate_was_blocked_ = false;
160 virtual void ActivatePendingTree() OVERRIDE {
161 test_hooks_->WillActivateTreeOnThread(this);
162 LayerTreeHostImpl::ActivatePendingTree();
163 DCHECK(!pending_tree());
164 test_hooks_->DidActivateTreeOnThread(this);
167 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface)
168 OVERRIDE {
169 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass());
170 test_hooks_->InitializedRendererOnThread(this, success);
171 return success;
174 virtual void SetVisible(bool visible) OVERRIDE {
175 LayerTreeHostImpl::SetVisible(visible);
176 test_hooks_->DidSetVisibleOnImplTree(this, visible);
179 virtual void AnimateLayers(base::TimeTicks monotonic_time) OVERRIDE {
180 test_hooks_->WillAnimateLayers(this, monotonic_time);
181 LayerTreeHostImpl::AnimateLayers(monotonic_time);
182 test_hooks_->AnimateLayers(this, monotonic_time);
185 virtual void UpdateAnimationState(bool start_ready_animations) OVERRIDE {
186 LayerTreeHostImpl::UpdateAnimationState(start_ready_animations);
187 bool has_unfinished_animation = false;
188 AnimationRegistrar::AnimationControllerMap::const_iterator iter =
189 active_animation_controllers().begin();
190 for (; iter != active_animation_controllers().end(); ++iter) {
191 if (iter->second->HasActiveAnimation()) {
192 has_unfinished_animation = true;
193 break;
196 test_hooks_->UpdateAnimationState(this, has_unfinished_animation);
199 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE {
200 return test_hooks_->LowFrequencyAnimationInterval();
203 private:
204 TestHooks* test_hooks_;
205 bool block_notify_ready_to_activate_for_testing_;
206 bool notify_ready_to_activate_was_blocked_;
209 // Implementation of LayerTreeHost callback interface.
210 class LayerTreeHostClientForTesting : public LayerTreeHostClient,
211 public LayerTreeHostSingleThreadClient {
212 public:
213 static scoped_ptr<LayerTreeHostClientForTesting> Create(
214 TestHooks* test_hooks) {
215 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks));
217 virtual ~LayerTreeHostClientForTesting() {}
219 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {
220 test_hooks_->WillBeginMainFrame();
223 virtual void DidBeginMainFrame() OVERRIDE {
224 test_hooks_->DidBeginMainFrame();
227 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE {
228 test_hooks_->Animate(monotonic_time);
231 virtual void Layout() OVERRIDE { test_hooks_->Layout(); }
233 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
234 float scale) OVERRIDE {
235 test_hooks_->ApplyScrollAndScale(scroll_delta, scale);
238 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
239 OVERRIDE {
240 return test_hooks_->CreateOutputSurface(fallback);
243 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
244 test_hooks_->DidInitializeOutputSurface(succeeded);
247 virtual void DidFailToInitializeOutputSurface() OVERRIDE {
248 test_hooks_->DidFailToInitializeOutputSurface();
251 virtual void WillCommit() OVERRIDE { test_hooks_->WillCommit(); }
253 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); }
255 virtual void DidCommitAndDrawFrame() OVERRIDE {
256 test_hooks_->DidCommitAndDrawFrame();
259 virtual void DidCompleteSwapBuffers() OVERRIDE {
260 test_hooks_->DidCompleteSwapBuffers();
263 virtual void ScheduleComposite() OVERRIDE {
264 test_hooks_->ScheduleComposite();
267 virtual void ScheduleAnimation() OVERRIDE {
268 test_hooks_->ScheduleAnimation();
271 virtual void DidPostSwapBuffers() OVERRIDE {}
272 virtual void DidAbortSwapBuffers() OVERRIDE {}
274 virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE {
275 return test_hooks_->OffscreenContextProvider();
278 private:
279 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
280 : test_hooks_(test_hooks) {}
282 TestHooks* test_hooks_;
285 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
286 class LayerTreeHostForTesting : public LayerTreeHost {
287 public:
288 static scoped_ptr<LayerTreeHostForTesting> Create(
289 TestHooks* test_hooks,
290 LayerTreeHostClientForTesting* client,
291 const LayerTreeSettings& settings,
292 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
293 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
294 new LayerTreeHostForTesting(test_hooks, client, settings));
295 if (impl_task_runner.get())
296 layer_tree_host->InitializeThreaded(impl_task_runner);
297 else
298 layer_tree_host->InitializeSingleThreaded(client);
299 return layer_tree_host.Pass();
302 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
303 LayerTreeHostImplClient* host_impl_client) OVERRIDE {
304 return LayerTreeHostImplForTesting::Create(
305 test_hooks_,
306 settings(),
307 host_impl_client,
308 proxy(),
309 shared_bitmap_manager_.get(),
310 rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>();
313 virtual void SetNeedsCommit() OVERRIDE {
314 if (!test_started_)
315 return;
316 LayerTreeHost::SetNeedsCommit();
319 void set_test_started(bool started) { test_started_ = started; }
321 virtual void DidDeferCommit() OVERRIDE { test_hooks_->DidDeferCommit(); }
323 private:
324 LayerTreeHostForTesting(TestHooks* test_hooks,
325 LayerTreeHostClient* client,
326 const LayerTreeSettings& settings)
327 : LayerTreeHost(client, NULL, settings),
328 shared_bitmap_manager_(new TestSharedBitmapManager()),
329 test_hooks_(test_hooks),
330 test_started_(false) {}
332 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
333 TestHooks* test_hooks_;
334 bool test_started_;
337 LayerTreeTest::LayerTreeTest()
338 : beginning_(false),
339 end_when_begin_returns_(false),
340 timed_out_(false),
341 scheduled_(false),
342 schedule_when_set_visible_true_(false),
343 started_(false),
344 ended_(false),
345 delegating_renderer_(false),
346 timeout_seconds_(0),
347 weak_factory_(this) {
348 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr();
350 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was
351 // specified (for running in a debugger).
352 CommandLine* command_line = CommandLine::ForCurrentProcess();
353 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout))
354 timeout_seconds_ = 5;
357 LayerTreeTest::~LayerTreeTest() {}
359 void LayerTreeTest::EndTest() {
360 if (ended_)
361 return;
362 ended_ = true;
364 // For the case where we EndTest during BeginTest(), set a flag to indicate
365 // that the test should end the second BeginTest regains control.
366 if (beginning_) {
367 end_when_begin_returns_ = true;
368 } else {
369 main_task_runner_->PostTask(
370 FROM_HERE,
371 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
375 void LayerTreeTest::EndTestAfterDelay(int delay_milliseconds) {
376 main_task_runner_->PostDelayedTask(
377 FROM_HERE,
378 base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_),
379 base::TimeDelta::FromMilliseconds(delay_milliseconds));
382 void LayerTreeTest::PostAddAnimationToMainThread(
383 Layer* layer_to_receive_animation) {
384 main_task_runner_->PostTask(
385 FROM_HERE,
386 base::Bind(&LayerTreeTest::DispatchAddAnimation,
387 main_thread_weak_ptr_,
388 base::Unretained(layer_to_receive_animation),
389 0.000001));
392 void LayerTreeTest::PostAddInstantAnimationToMainThread(
393 Layer* layer_to_receive_animation) {
394 main_task_runner_->PostTask(
395 FROM_HERE,
396 base::Bind(&LayerTreeTest::DispatchAddAnimation,
397 main_thread_weak_ptr_,
398 base::Unretained(layer_to_receive_animation),
399 0.0));
402 void LayerTreeTest::PostAddLongAnimationToMainThread(
403 Layer* layer_to_receive_animation) {
404 main_task_runner_->PostTask(
405 FROM_HERE,
406 base::Bind(&LayerTreeTest::DispatchAddAnimation,
407 main_thread_weak_ptr_,
408 base::Unretained(layer_to_receive_animation),
409 1.0));
412 void LayerTreeTest::PostSetNeedsCommitToMainThread() {
413 main_task_runner_->PostTask(FROM_HERE,
414 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit,
415 main_thread_weak_ptr_));
418 void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() {
419 main_task_runner_->PostTask(
420 FROM_HERE,
421 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers,
422 main_thread_weak_ptr_));
425 void LayerTreeTest::PostReadbackToMainThread() {
426 main_task_runner_->PostTask(
427 FROM_HERE,
428 base::Bind(&LayerTreeTest::DispatchReadback, main_thread_weak_ptr_));
431 void LayerTreeTest::PostSetNeedsRedrawToMainThread() {
432 main_task_runner_->PostTask(FROM_HERE,
433 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw,
434 main_thread_weak_ptr_));
437 void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(
438 const gfx::Rect& damage_rect) {
439 main_task_runner_->PostTask(
440 FROM_HERE,
441 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect,
442 main_thread_weak_ptr_,
443 damage_rect));
446 void LayerTreeTest::PostSetVisibleToMainThread(bool visible) {
447 main_task_runner_->PostTask(
448 FROM_HERE,
449 base::Bind(
450 &LayerTreeTest::DispatchSetVisible, main_thread_weak_ptr_, visible));
453 void LayerTreeTest::PostSetNextCommitForcesRedrawToMainThread() {
454 main_task_runner_->PostTask(
455 FROM_HERE,
456 base::Bind(&LayerTreeTest::DispatchSetNextCommitForcesRedraw,
457 main_thread_weak_ptr_));
460 void LayerTreeTest::WillBeginTest() {
461 layer_tree_host_->SetLayerTreeHostClientReady();
464 void LayerTreeTest::DoBeginTest() {
465 client_ = LayerTreeHostClientForTesting::Create(this);
467 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
468 layer_tree_host_ = LayerTreeHostForTesting::Create(
469 this,
470 client_.get(),
471 settings_,
472 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL);
473 ASSERT_TRUE(layer_tree_host_);
475 started_ = true;
476 beginning_ = true;
477 SetupTree();
478 WillBeginTest();
479 BeginTest();
480 beginning_ = false;
481 if (end_when_begin_returns_)
482 RealEndTest();
484 // Allow commits to happen once BeginTest() has had a chance to post tasks
485 // so that those tasks will happen before the first commit.
486 if (layer_tree_host_) {
487 static_cast<LayerTreeHostForTesting*>(layer_tree_host_.get())
488 ->set_test_started(true);
492 void LayerTreeTest::SetupTree() {
493 if (!layer_tree_host_->root_layer()) {
494 scoped_refptr<Layer> root_layer = Layer::Create();
495 root_layer->SetAnchorPoint(gfx::PointF());
496 root_layer->SetBounds(gfx::Size(1, 1));
497 root_layer->SetIsDrawable(true);
498 layer_tree_host_->SetRootLayer(root_layer);
501 gfx::Size root_bounds = layer_tree_host_->root_layer()->bounds();
502 gfx::Size device_root_bounds = gfx::ToCeiledSize(
503 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor()));
504 layer_tree_host_->SetViewportSize(device_root_bounds);
507 void LayerTreeTest::Timeout() {
508 timed_out_ = true;
509 EndTest();
512 void LayerTreeTest::ScheduleComposite() {
513 if (!started_ || scheduled_)
514 return;
515 scheduled_ = true;
516 main_task_runner_->PostTask(
517 FROM_HERE,
518 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_));
521 void LayerTreeTest::RealEndTest() {
522 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) {
523 main_task_runner_->PostTask(
524 FROM_HERE,
525 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
526 return;
529 base::MessageLoop::current()->Quit();
532 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation,
533 double animation_duration) {
534 DCHECK(!proxy() || proxy()->IsMainThread());
536 if (layer_to_receive_animation) {
537 AddOpacityTransitionToLayer(
538 layer_to_receive_animation, animation_duration, 0, 0.5, true);
542 void LayerTreeTest::DispatchSetNeedsCommit() {
543 DCHECK(!proxy() || proxy()->IsMainThread());
545 if (layer_tree_host_)
546 layer_tree_host_->SetNeedsCommit();
549 void LayerTreeTest::DispatchSetNeedsUpdateLayers() {
550 DCHECK(!proxy() || proxy()->IsMainThread());
552 if (layer_tree_host_)
553 layer_tree_host_->SetNeedsUpdateLayers();
556 void LayerTreeTest::DispatchReadback() {
557 DCHECK(!proxy() || proxy()->IsMainThread());
559 if (layer_tree_host_) {
560 char pixels[4];
561 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
565 void LayerTreeTest::DispatchSetNeedsRedraw() {
566 DCHECK(!proxy() || proxy()->IsMainThread());
568 if (layer_tree_host_)
569 layer_tree_host_->SetNeedsRedraw();
572 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) {
573 DCHECK(!proxy() || proxy()->IsMainThread());
575 if (layer_tree_host_)
576 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
579 void LayerTreeTest::DispatchSetVisible(bool visible) {
580 DCHECK(!proxy() || proxy()->IsMainThread());
582 if (!layer_tree_host_)
583 return;
585 layer_tree_host_->SetVisible(visible);
587 // If the LTH is being made visible and a previous ScheduleComposite() was
588 // deferred because the LTH was not visible, re-schedule the composite now.
589 if (layer_tree_host_->visible() && schedule_when_set_visible_true_)
590 ScheduleComposite();
593 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
594 DCHECK(!proxy() || proxy()->IsMainThread());
596 if (layer_tree_host_)
597 layer_tree_host_->SetNextCommitForcesRedraw();
600 void LayerTreeTest::DispatchComposite() {
601 scheduled_ = false;
603 if (!layer_tree_host_)
604 return;
606 // If the LTH is not visible, defer the composite until the LTH is made
607 // visible.
608 if (!layer_tree_host_->visible()) {
609 schedule_when_set_visible_true_ = true;
610 return;
613 schedule_when_set_visible_true_ = false;
614 base::TimeTicks now = gfx::FrameTime::Now();
615 layer_tree_host_->Composite(now);
618 void LayerTreeTest::RunTest(bool threaded,
619 bool delegating_renderer,
620 bool impl_side_painting) {
621 if (threaded) {
622 impl_thread_.reset(new base::Thread("Compositor"));
623 ASSERT_TRUE(impl_thread_->Start());
626 main_task_runner_ = base::MessageLoopProxy::current();
628 delegating_renderer_ = delegating_renderer;
630 // Spend less time waiting for BeginFrame because the output is
631 // mocked out.
632 settings_.refresh_rate = 200.0;
633 if (impl_side_painting) {
634 DCHECK(threaded)
635 << "Don't run single thread + impl side painting, it doesn't exist.";
636 settings_.impl_side_painting = true;
638 InitializeSettings(&settings_);
640 main_task_runner_->PostTask(
641 FROM_HERE,
642 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
644 if (timeout_seconds_) {
645 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
646 main_task_runner_->PostDelayedTask(
647 FROM_HERE,
648 timeout_.callback(),
649 base::TimeDelta::FromSeconds(timeout_seconds_));
652 base::MessageLoop::current()->Run();
653 DestroyLayerTreeHost();
655 timeout_.Cancel();
657 ASSERT_FALSE(layer_tree_host_.get());
658 client_.reset();
659 if (timed_out_) {
660 FAIL() << "Test timed out";
661 return;
663 AfterTest();
666 void LayerTreeTest::RunTestWithImplSidePainting() {
667 RunTest(true, false, true);
670 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) {
671 scoped_ptr<FakeOutputSurface> output_surface =
672 CreateFakeOutputSurface(fallback);
673 output_surface_ = output_surface.get();
674 return output_surface.PassAs<OutputSurface>();
677 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface(
678 bool fallback) {
679 if (delegating_renderer_)
680 return FakeOutputSurface::CreateDelegating3d();
681 else
682 return FakeOutputSurface::Create3d();
685 scoped_refptr<ContextProvider> LayerTreeTest::OffscreenContextProvider() {
686 if (!compositor_contexts_.get() ||
687 compositor_contexts_->DestroyedOnMainThread())
688 compositor_contexts_ = TestContextProvider::Create();
689 return compositor_contexts_;
692 TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
693 return static_cast<TestContextProvider*>(
694 output_surface_->context_provider().get())->TestContext3d();
697 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
698 const {
699 if (impl->pending_tree())
700 return impl->pending_tree()->source_frame_number();
701 if (impl->active_tree())
702 return impl->active_tree()->source_frame_number();
703 // Source frames start at 0, so this is invalid.
704 return -1;
707 void LayerTreeTest::DestroyLayerTreeHost() {
708 if (layer_tree_host_ && layer_tree_host_->root_layer())
709 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
710 layer_tree_host_.reset();
713 } // namespace cc