Add very simple loading test for non-SFI NaCl.
[chromium-blink-merge.git] / cc / test / layer_tree_test.cc
blob12908020f8b7c2aee01b972d2d144eeaf6a3ef76
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/tiled_layer_test_common.h"
22 #include "cc/trees/layer_tree_host_client.h"
23 #include "cc/trees/layer_tree_host_impl.h"
24 #include "cc/trees/layer_tree_host_single_thread_client.h"
25 #include "cc/trees/layer_tree_impl.h"
26 #include "cc/trees/single_thread_proxy.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "ui/gfx/frame_time.h"
29 #include "ui/gfx/size_conversions.h"
31 namespace cc {
33 TestHooks::TestHooks() {}
35 TestHooks::~TestHooks() {}
37 DrawSwapReadbackResult::DrawResult TestHooks::PrepareToDrawOnThread(
38 LayerTreeHostImpl* host_impl,
39 LayerTreeHostImpl::FrameData* frame_data,
40 DrawSwapReadbackResult::DrawResult draw_result) {
41 return draw_result;
44 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const {
45 return base::TimeDelta::FromMilliseconds(16);
48 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
49 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
50 public:
51 static scoped_ptr<LayerTreeHostImplForTesting> Create(
52 TestHooks* test_hooks,
53 const LayerTreeSettings& settings,
54 LayerTreeHostImplClient* host_impl_client,
55 Proxy* proxy,
56 RenderingStatsInstrumentation* stats_instrumentation) {
57 return make_scoped_ptr(new LayerTreeHostImplForTesting(
58 test_hooks, settings, host_impl_client, proxy, stats_instrumentation));
61 protected:
62 LayerTreeHostImplForTesting(
63 TestHooks* test_hooks,
64 const LayerTreeSettings& settings,
65 LayerTreeHostImplClient* host_impl_client,
66 Proxy* proxy,
67 RenderingStatsInstrumentation* stats_instrumentation)
68 : LayerTreeHostImpl(settings,
69 host_impl_client,
70 proxy,
71 stats_instrumentation,
72 NULL,
73 0),
74 test_hooks_(test_hooks),
75 block_notify_ready_to_activate_for_testing_(false),
76 notify_ready_to_activate_was_blocked_(false) {}
78 virtual void BeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
79 test_hooks_->WillBeginImplFrameOnThread(this, args);
80 LayerTreeHostImpl::BeginImplFrame(args);
81 test_hooks_->DidBeginImplFrameOnThread(this, args);
84 virtual void BeginMainFrameAborted(bool did_handle) OVERRIDE {
85 LayerTreeHostImpl::BeginMainFrameAborted(did_handle);
86 test_hooks_->BeginMainFrameAbortedOnThread(this, did_handle);
89 virtual void BeginCommit() OVERRIDE {
90 LayerTreeHostImpl::BeginCommit();
91 test_hooks_->BeginCommitOnThread(this);
94 virtual void CommitComplete() OVERRIDE {
95 LayerTreeHostImpl::CommitComplete();
96 test_hooks_->CommitCompleteOnThread(this);
98 if (!settings().impl_side_painting) {
99 test_hooks_->WillActivateTreeOnThread(this);
100 test_hooks_->DidActivateTreeOnThread(this);
104 virtual DrawSwapReadbackResult::DrawResult PrepareToDraw(
105 FrameData* frame,
106 const gfx::Rect& damage_rect) OVERRIDE {
107 DrawSwapReadbackResult::DrawResult draw_result =
108 LayerTreeHostImpl::PrepareToDraw(frame, damage_rect);
109 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result);
112 virtual void DrawLayers(FrameData* frame,
113 base::TimeTicks frame_begin_time) OVERRIDE {
114 LayerTreeHostImpl::DrawLayers(frame, frame_begin_time);
115 test_hooks_->DrawLayersOnThread(this);
118 virtual bool SwapBuffers(const LayerTreeHostImpl::FrameData& frame) OVERRIDE {
119 bool result = LayerTreeHostImpl::SwapBuffers(frame);
120 test_hooks_->SwapBuffersOnThread(this, result);
121 return result;
124 virtual void OnSwapBuffersComplete() OVERRIDE {
125 LayerTreeHostImpl::OnSwapBuffersComplete();
126 test_hooks_->SwapBuffersCompleteOnThread(this);
129 virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE {
130 LayerTreeHostImpl::ReclaimResources(ack);
133 virtual void UpdateVisibleTiles() OVERRIDE {
134 LayerTreeHostImpl::UpdateVisibleTiles();
135 test_hooks_->UpdateVisibleTilesOnThread(this);
138 virtual void NotifyReadyToActivate() OVERRIDE {
139 if (block_notify_ready_to_activate_for_testing_)
140 notify_ready_to_activate_was_blocked_ = true;
141 else
142 client_->NotifyReadyToActivate();
145 virtual void BlockNotifyReadyToActivateForTesting(bool block) OVERRIDE {
146 block_notify_ready_to_activate_for_testing_ = block;
147 if (!block && notify_ready_to_activate_was_blocked_) {
148 NotifyReadyToActivate();
149 notify_ready_to_activate_was_blocked_ = false;
153 virtual void ActivatePendingTree() OVERRIDE {
154 test_hooks_->WillActivateTreeOnThread(this);
155 LayerTreeHostImpl::ActivatePendingTree();
156 DCHECK(!pending_tree());
157 test_hooks_->DidActivateTreeOnThread(this);
160 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface)
161 OVERRIDE {
162 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass());
163 test_hooks_->InitializedRendererOnThread(this, success);
164 return success;
167 virtual void SetVisible(bool visible) OVERRIDE {
168 LayerTreeHostImpl::SetVisible(visible);
169 test_hooks_->DidSetVisibleOnImplTree(this, visible);
172 virtual void AnimateLayers(base::TimeTicks monotonic_time) OVERRIDE {
173 test_hooks_->WillAnimateLayers(this, monotonic_time);
174 LayerTreeHostImpl::AnimateLayers(monotonic_time);
175 test_hooks_->AnimateLayers(this, monotonic_time);
178 virtual void UpdateAnimationState(bool start_ready_animations) OVERRIDE {
179 LayerTreeHostImpl::UpdateAnimationState(start_ready_animations);
180 bool has_unfinished_animation = false;
181 AnimationRegistrar::AnimationControllerMap::const_iterator iter =
182 active_animation_controllers().begin();
183 for (; iter != active_animation_controllers().end(); ++iter) {
184 if (iter->second->HasActiveAnimation()) {
185 has_unfinished_animation = true;
186 break;
189 test_hooks_->UpdateAnimationState(this, has_unfinished_animation);
192 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE {
193 return test_hooks_->LowFrequencyAnimationInterval();
196 private:
197 TestHooks* test_hooks_;
198 bool block_notify_ready_to_activate_for_testing_;
199 bool notify_ready_to_activate_was_blocked_;
202 // Implementation of LayerTreeHost callback interface.
203 class LayerTreeHostClientForTesting : public LayerTreeHostClient,
204 public LayerTreeHostSingleThreadClient {
205 public:
206 static scoped_ptr<LayerTreeHostClientForTesting> Create(
207 TestHooks* test_hooks) {
208 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks));
210 virtual ~LayerTreeHostClientForTesting() {}
212 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {
213 test_hooks_->WillBeginMainFrame();
216 virtual void DidBeginMainFrame() OVERRIDE {
217 test_hooks_->DidBeginMainFrame();
220 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE {
221 test_hooks_->Animate(monotonic_time);
224 virtual void Layout() OVERRIDE { test_hooks_->Layout(); }
226 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
227 float scale) OVERRIDE {
228 test_hooks_->ApplyScrollAndScale(scroll_delta, scale);
231 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
232 OVERRIDE {
233 return test_hooks_->CreateOutputSurface(fallback);
236 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
237 test_hooks_->DidInitializeOutputSurface(succeeded);
240 virtual void DidFailToInitializeOutputSurface() OVERRIDE {
241 test_hooks_->DidFailToInitializeOutputSurface();
244 virtual void WillCommit() OVERRIDE { test_hooks_->WillCommit(); }
246 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); }
248 virtual void DidCommitAndDrawFrame() OVERRIDE {
249 test_hooks_->DidCommitAndDrawFrame();
252 virtual void DidCompleteSwapBuffers() OVERRIDE {
253 test_hooks_->DidCompleteSwapBuffers();
256 virtual void ScheduleComposite() OVERRIDE {
257 test_hooks_->ScheduleComposite();
260 virtual void ScheduleAnimation() OVERRIDE {
261 test_hooks_->ScheduleAnimation();
264 virtual void DidPostSwapBuffers() OVERRIDE {}
265 virtual void DidAbortSwapBuffers() OVERRIDE {}
267 virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE {
268 return test_hooks_->OffscreenContextProvider();
271 private:
272 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
273 : test_hooks_(test_hooks) {}
275 TestHooks* test_hooks_;
278 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
279 class LayerTreeHostForTesting : public LayerTreeHost {
280 public:
281 static scoped_ptr<LayerTreeHostForTesting> Create(
282 TestHooks* test_hooks,
283 LayerTreeHostClientForTesting* client,
284 const LayerTreeSettings& settings,
285 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
286 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
287 new LayerTreeHostForTesting(test_hooks, client, settings));
288 if (impl_task_runner.get())
289 layer_tree_host->InitializeThreaded(impl_task_runner);
290 else
291 layer_tree_host->InitializeSingleThreaded(client);
292 return layer_tree_host.Pass();
295 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
296 LayerTreeHostImplClient* host_impl_client) OVERRIDE {
297 return LayerTreeHostImplForTesting::Create(
298 test_hooks_,
299 settings(),
300 host_impl_client,
301 proxy(),
302 rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>();
305 virtual void SetNeedsCommit() OVERRIDE {
306 if (!test_started_)
307 return;
308 LayerTreeHost::SetNeedsCommit();
311 void set_test_started(bool started) { test_started_ = started; }
313 virtual void DidDeferCommit() OVERRIDE { test_hooks_->DidDeferCommit(); }
315 private:
316 LayerTreeHostForTesting(TestHooks* test_hooks,
317 LayerTreeHostClient* client,
318 const LayerTreeSettings& settings)
319 : LayerTreeHost(client, NULL, settings),
320 test_hooks_(test_hooks),
321 test_started_(false) {}
323 TestHooks* test_hooks_;
324 bool test_started_;
327 LayerTreeTest::LayerTreeTest()
328 : beginning_(false),
329 end_when_begin_returns_(false),
330 timed_out_(false),
331 scheduled_(false),
332 schedule_when_set_visible_true_(false),
333 started_(false),
334 ended_(false),
335 delegating_renderer_(false),
336 timeout_seconds_(0),
337 weak_factory_(this) {
338 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr();
340 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was
341 // specified (for running in a debugger).
342 CommandLine* command_line = CommandLine::ForCurrentProcess();
343 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout))
344 timeout_seconds_ = 5;
347 LayerTreeTest::~LayerTreeTest() {}
349 void LayerTreeTest::EndTest() {
350 if (ended_)
351 return;
352 ended_ = true;
354 // For the case where we EndTest during BeginTest(), set a flag to indicate
355 // that the test should end the second BeginTest regains control.
356 if (beginning_) {
357 end_when_begin_returns_ = true;
358 } else {
359 main_task_runner_->PostTask(
360 FROM_HERE,
361 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
365 void LayerTreeTest::EndTestAfterDelay(int delay_milliseconds) {
366 main_task_runner_->PostTask(
367 FROM_HERE, base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_));
370 void LayerTreeTest::PostAddAnimationToMainThread(
371 Layer* layer_to_receive_animation) {
372 main_task_runner_->PostTask(
373 FROM_HERE,
374 base::Bind(&LayerTreeTest::DispatchAddAnimation,
375 main_thread_weak_ptr_,
376 base::Unretained(layer_to_receive_animation),
377 0.000001));
380 void LayerTreeTest::PostAddInstantAnimationToMainThread(
381 Layer* layer_to_receive_animation) {
382 main_task_runner_->PostTask(
383 FROM_HERE,
384 base::Bind(&LayerTreeTest::DispatchAddAnimation,
385 main_thread_weak_ptr_,
386 base::Unretained(layer_to_receive_animation),
387 0.0));
390 void LayerTreeTest::PostAddLongAnimationToMainThread(
391 Layer* layer_to_receive_animation) {
392 main_task_runner_->PostTask(
393 FROM_HERE,
394 base::Bind(&LayerTreeTest::DispatchAddAnimation,
395 main_thread_weak_ptr_,
396 base::Unretained(layer_to_receive_animation),
397 1.0));
400 void LayerTreeTest::PostSetNeedsCommitToMainThread() {
401 main_task_runner_->PostTask(FROM_HERE,
402 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit,
403 main_thread_weak_ptr_));
406 void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() {
407 main_task_runner_->PostTask(
408 FROM_HERE,
409 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers,
410 main_thread_weak_ptr_));
413 void LayerTreeTest::PostReadbackToMainThread() {
414 main_task_runner_->PostTask(
415 FROM_HERE,
416 base::Bind(&LayerTreeTest::DispatchReadback, main_thread_weak_ptr_));
419 void LayerTreeTest::PostAcquireLayerTextures() {
420 main_task_runner_->PostTask(
421 FROM_HERE,
422 base::Bind(&LayerTreeTest::DispatchAcquireLayerTextures,
423 main_thread_weak_ptr_));
426 void LayerTreeTest::PostSetNeedsRedrawToMainThread() {
427 main_task_runner_->PostTask(FROM_HERE,
428 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw,
429 main_thread_weak_ptr_));
432 void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(
433 const gfx::Rect& damage_rect) {
434 main_task_runner_->PostTask(
435 FROM_HERE,
436 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect,
437 main_thread_weak_ptr_,
438 damage_rect));
441 void LayerTreeTest::PostSetVisibleToMainThread(bool visible) {
442 main_task_runner_->PostTask(
443 FROM_HERE,
444 base::Bind(
445 &LayerTreeTest::DispatchSetVisible, main_thread_weak_ptr_, visible));
448 void LayerTreeTest::PostSetNextCommitForcesRedrawToMainThread() {
449 main_task_runner_->PostTask(
450 FROM_HERE,
451 base::Bind(&LayerTreeTest::DispatchSetNextCommitForcesRedraw,
452 main_thread_weak_ptr_));
455 void LayerTreeTest::WillBeginTest() {
456 layer_tree_host_->SetLayerTreeHostClientReady();
459 void LayerTreeTest::DoBeginTest() {
460 client_ = LayerTreeHostClientForTesting::Create(this);
462 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
463 layer_tree_host_ = LayerTreeHostForTesting::Create(
464 this,
465 client_.get(),
466 settings_,
467 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL);
468 ASSERT_TRUE(layer_tree_host_);
470 started_ = true;
471 beginning_ = true;
472 SetupTree();
473 WillBeginTest();
474 BeginTest();
475 beginning_ = false;
476 if (end_when_begin_returns_)
477 RealEndTest();
479 // Allow commits to happen once BeginTest() has had a chance to post tasks
480 // so that those tasks will happen before the first commit.
481 if (layer_tree_host_) {
482 static_cast<LayerTreeHostForTesting*>(layer_tree_host_.get())
483 ->set_test_started(true);
487 void LayerTreeTest::SetupTree() {
488 if (!layer_tree_host_->root_layer()) {
489 scoped_refptr<Layer> root_layer = Layer::Create();
490 root_layer->SetAnchorPoint(gfx::PointF());
491 root_layer->SetBounds(gfx::Size(1, 1));
492 root_layer->SetIsDrawable(true);
493 layer_tree_host_->SetRootLayer(root_layer);
496 gfx::Size root_bounds = layer_tree_host_->root_layer()->bounds();
497 gfx::Size device_root_bounds = gfx::ToCeiledSize(
498 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor()));
499 layer_tree_host_->SetViewportSize(device_root_bounds);
502 void LayerTreeTest::Timeout() {
503 timed_out_ = true;
504 EndTest();
507 void LayerTreeTest::ScheduleComposite() {
508 if (!started_ || scheduled_)
509 return;
510 scheduled_ = true;
511 main_task_runner_->PostTask(
512 FROM_HERE,
513 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_));
516 void LayerTreeTest::RealEndTest() {
517 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) {
518 main_task_runner_->PostTask(
519 FROM_HERE,
520 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
521 return;
524 base::MessageLoop::current()->Quit();
527 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation,
528 double animation_duration) {
529 DCHECK(!proxy() || proxy()->IsMainThread());
531 if (layer_to_receive_animation) {
532 AddOpacityTransitionToLayer(
533 layer_to_receive_animation, animation_duration, 0, 0.5, true);
537 void LayerTreeTest::DispatchSetNeedsCommit() {
538 DCHECK(!proxy() || proxy()->IsMainThread());
540 if (layer_tree_host_)
541 layer_tree_host_->SetNeedsCommit();
544 void LayerTreeTest::DispatchSetNeedsUpdateLayers() {
545 DCHECK(!proxy() || proxy()->IsMainThread());
547 if (layer_tree_host_)
548 layer_tree_host_->SetNeedsUpdateLayers();
551 void LayerTreeTest::DispatchReadback() {
552 DCHECK(!proxy() || proxy()->IsMainThread());
554 if (layer_tree_host_) {
555 char pixels[4];
556 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
560 void LayerTreeTest::DispatchAcquireLayerTextures() {
561 DCHECK(!proxy() || proxy()->IsMainThread());
563 if (layer_tree_host_)
564 layer_tree_host_->AcquireLayerTextures();
567 void LayerTreeTest::DispatchSetNeedsRedraw() {
568 DCHECK(!proxy() || proxy()->IsMainThread());
570 if (layer_tree_host_)
571 layer_tree_host_->SetNeedsRedraw();
574 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) {
575 DCHECK(!proxy() || proxy()->IsMainThread());
577 if (layer_tree_host_)
578 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
581 void LayerTreeTest::DispatchSetVisible(bool visible) {
582 DCHECK(!proxy() || proxy()->IsMainThread());
584 if (!layer_tree_host_)
585 return;
587 layer_tree_host_->SetVisible(visible);
589 // If the LTH is being made visible and a previous ScheduleComposite() was
590 // deferred because the LTH was not visible, re-schedule the composite now.
591 if (layer_tree_host_->visible() && schedule_when_set_visible_true_)
592 ScheduleComposite();
595 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
596 DCHECK(!proxy() || proxy()->IsMainThread());
598 if (layer_tree_host_)
599 layer_tree_host_->SetNextCommitForcesRedraw();
602 void LayerTreeTest::DispatchComposite() {
603 scheduled_ = false;
605 if (!layer_tree_host_)
606 return;
608 // If the LTH is not visible, defer the composite until the LTH is made
609 // visible.
610 if (!layer_tree_host_->visible()) {
611 schedule_when_set_visible_true_ = true;
612 return;
615 schedule_when_set_visible_true_ = false;
616 base::TimeTicks now = gfx::FrameTime::Now();
617 layer_tree_host_->Composite(now);
620 void LayerTreeTest::RunTest(bool threaded,
621 bool delegating_renderer,
622 bool impl_side_painting) {
623 if (threaded) {
624 impl_thread_.reset(new base::Thread("Compositor"));
625 ASSERT_TRUE(impl_thread_->Start());
628 main_task_runner_ = base::MessageLoopProxy::current();
630 delegating_renderer_ = delegating_renderer;
632 // Spend less time waiting for BeginImplFrame because the output is
633 // mocked out.
634 settings_.refresh_rate = 200.0;
635 if (impl_side_painting) {
636 DCHECK(threaded)
637 << "Don't run single thread + impl side painting, it doesn't exist.";
638 settings_.impl_side_painting = true;
640 InitializeSettings(&settings_);
642 main_task_runner_->PostTask(
643 FROM_HERE,
644 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
646 if (timeout_seconds_) {
647 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
648 main_task_runner_->PostDelayedTask(
649 FROM_HERE,
650 timeout_.callback(),
651 base::TimeDelta::FromSeconds(timeout_seconds_));
654 base::MessageLoop::current()->Run();
655 DestroyLayerTreeHost();
657 timeout_.Cancel();
659 ASSERT_FALSE(layer_tree_host_.get());
660 client_.reset();
661 if (timed_out_) {
662 FAIL() << "Test timed out";
663 return;
665 AfterTest();
668 void LayerTreeTest::RunTestWithImplSidePainting() {
669 RunTest(true, false, true);
672 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) {
673 scoped_ptr<FakeOutputSurface> output_surface =
674 CreateFakeOutputSurface(fallback);
675 output_surface_ = output_surface.get();
676 return output_surface.PassAs<OutputSurface>();
679 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface(
680 bool fallback) {
681 if (delegating_renderer_)
682 return FakeOutputSurface::CreateDelegating3d();
683 else
684 return FakeOutputSurface::Create3d();
687 scoped_refptr<ContextProvider> LayerTreeTest::OffscreenContextProvider() {
688 if (!compositor_contexts_.get() ||
689 compositor_contexts_->DestroyedOnMainThread())
690 compositor_contexts_ = TestContextProvider::Create();
691 return compositor_contexts_;
694 TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
695 return static_cast<TestContextProvider*>(
696 output_surface_->context_provider().get())->TestContext3d();
699 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
700 const {
701 if (impl->pending_tree())
702 return impl->pending_tree()->source_frame_number();
703 if (impl->active_tree())
704 return impl->active_tree()->source_frame_number();
705 // Source frames start at 0, so this is invalid.
706 return -1;
709 void LayerTreeTest::DestroyLayerTreeHost() {
710 if (layer_tree_host_ && layer_tree_host_->root_layer())
711 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
712 layer_tree_host_.reset();
715 } // namespace cc