[go: nahoru, domu]

blob: 0613f853ba9f6b31dd3f85c1066c7bfa53dc0541 [file] [log] [blame]
danakj@chromium.orge216fef02013-03-20 22:56:101// 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.
4
5#include "cc/test/layer_tree_test.h"
6
danakj@chromium.org4fc1b792013-03-26 08:58:577#include "base/command_line.h"
danakj@chromium.orge216fef02013-03-20 22:56:108#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"
vollick@chromium.org8309341c2013-04-29 21:11:3112#include "cc/base/switches.h"
danakj@chromium.orge216fef02013-03-20 22:56:1013#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"
simonhonga7e3ac42014-11-11 20:50:2218#include "cc/test/begin_frame_args_test.h"
danakj6e3bf8012014-12-16 18:27:5319#include "cc/test/fake_external_begin_frame_source.h"
danakj@chromium.orge216fef02013-03-20 22:56:1020#include "cc/test/fake_layer_tree_host_client.h"
21#include "cc/test/fake_output_surface.h"
jamesr@chromium.orgc2610b9f2013-10-31 06:54:5922#include "cc/test/test_context_provider.h"
reveman22dd9292014-10-13 20:52:0523#include "cc/test/test_gpu_memory_buffer_manager.h"
jbauman@chromium.org4e2eb352014-03-20 17:25:4524#include "cc/test/test_shared_bitmap_manager.h"
danakj@chromium.orge216fef02013-03-20 22:56:1025#include "cc/test/tiled_layer_test_common.h"
jamesr@chromium.org943528e2013-11-07 05:01:3226#include "cc/trees/layer_tree_host_client.h"
danakj@chromium.orge216fef02013-03-20 22:56:1027#include "cc/trees/layer_tree_host_impl.h"
jamesr@chromium.org943528e2013-11-07 05:01:3228#include "cc/trees/layer_tree_host_single_thread_client.h"
enne@chromium.org98ea818e2014-01-24 10:22:0829#include "cc/trees/layer_tree_impl.h"
danakj@chromium.orge216fef02013-03-20 22:56:1030#include "cc/trees/single_thread_proxy.h"
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5631#include "cc/trees/thread_proxy.h"
danakj@chromium.orge216fef02013-03-20 22:56:1032#include "testing/gmock/include/gmock/gmock.h"
brianderson@chromium.orgde2cf8c2013-10-25 19:46:4633#include "ui/gfx/frame_time.h"
heejin.r.chungd28506ba2014-10-23 16:36:2034#include "ui/gfx/geometry/size_conversions.h"
danakj@chromium.orge216fef02013-03-20 22:56:1035
36namespace cc {
37
danakj@chromium.org4145d172013-05-10 16:54:3638TestHooks::TestHooks() {}
danakj@chromium.orge216fef02013-03-20 22:56:1039
40TestHooks::~TestHooks() {}
41
simonhong@chromium.org30d82142014-05-12 04:26:0242DrawResult TestHooks::PrepareToDrawOnThread(
enne@chromium.org7ddfe7e82014-01-30 07:22:1143 LayerTreeHostImpl* host_impl,
44 LayerTreeHostImpl::FrameData* frame_data,
simonhong@chromium.org30d82142014-05-12 04:26:0245 DrawResult draw_result) {
enne@chromium.org7ddfe7e82014-01-30 07:22:1146 return draw_result;
danakj@chromium.orge216fef02013-03-20 22:56:1047}
48
vmiuraa30e1ea2014-12-09 19:23:5149void TestHooks::CreateResourceAndTileTaskWorkerPool(
enne03dbe8ae2014-10-30 01:32:5550 LayerTreeHostImpl* host_impl,
vmiuraa30e1ea2014-12-09 19:23:5151 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
enne03dbe8ae2014-10-30 01:32:5552 scoped_ptr<ResourcePool>* resource_pool,
53 scoped_ptr<ResourcePool>* staging_resource_pool) {
vmiuraa30e1ea2014-12-09 19:23:5154 host_impl->LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
55 tile_task_worker_pool, resource_pool, staging_resource_pool);
enne03dbe8ae2014-10-30 01:32:5556}
simonhonga7e3ac42014-11-11 20:50:2257
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5658// Adapts ThreadProxy for test. Injects test hooks for testing.
59class ThreadProxyForTest : public ThreadProxy {
60 public:
61 static scoped_ptr<Proxy> Create(
62 TestHooks* test_hooks,
63 LayerTreeHost* host,
skyostil@chromium.org27e6a212014-07-18 15:51:2764 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
simonhonga7e3ac42014-11-11 20:50:2265 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
66 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
danakjf446a072014-09-27 21:55:4867 return make_scoped_ptr(new ThreadProxyForTest(
simonhonga7e3ac42014-11-11 20:50:2268 test_hooks,
69 host,
70 main_task_runner,
71 impl_task_runner,
72 external_begin_frame_source.Pass()));
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5673 }
74
dcheng716bedf2014-10-21 09:51:0875 ~ThreadProxyForTest() override {}
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5676
77 void test() {
78 test_hooks_->Layout();
79 }
80
81 private:
82 TestHooks* test_hooks_;
83
dcheng716bedf2014-10-21 09:51:0884 void ScheduledActionSendBeginMainFrame() override {
danakj@chromium.org922186942014-06-11 16:30:3585 test_hooks_->ScheduledActionWillSendBeginMainFrame();
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5686 ThreadProxy::ScheduledActionSendBeginMainFrame();
87 test_hooks_->ScheduledActionSendBeginMainFrame();
mithro@mithis.com9e54b0cf2014-06-19 21:16:4888 }
89
dcheng716bedf2014-10-21 09:51:0890 DrawResult ScheduledActionDrawAndSwapIfPossible() override {
mithro@mithis.com9e54b0cf2014-06-19 21:16:4891 DrawResult result = ThreadProxy::ScheduledActionDrawAndSwapIfPossible();
92 test_hooks_->ScheduledActionDrawAndSwapIfPossible();
93 return result;
94 }
95
dcheng716bedf2014-10-21 09:51:0896 void ScheduledActionAnimate() override {
mithro@mithis.com9e54b0cf2014-06-19 21:16:4897 ThreadProxy::ScheduledActionAnimate();
98 test_hooks_->ScheduledActionAnimate();
simonhong@chromium.org6f0fdcb2014-05-22 02:51:5699 }
100
dcheng716bedf2014-10-21 09:51:08101 void ScheduledActionCommit() override {
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56102 ThreadProxy::ScheduledActionCommit();
103 test_hooks_->ScheduledActionCommit();
104 }
105
dcheng716bedf2014-10-21 09:51:08106 void ScheduledActionBeginOutputSurfaceCreation() override {
mithro@mithis.com9e54b0cf2014-06-19 21:16:48107 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
108 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56109 }
110
vmiura59ea9b4042014-12-09 20:50:39111 void ScheduledActionPrepareTiles() override {
112 ThreadProxy::ScheduledActionPrepareTiles();
113 test_hooks_->ScheduledActionPrepareTiles();
vmpstredb488e2014-12-03 16:10:06114 }
115
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56116 ThreadProxyForTest(
117 TestHooks* test_hooks,
118 LayerTreeHost* host,
skyostil@chromium.org27e6a212014-07-18 15:51:27119 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
simonhonga7e3ac42014-11-11 20:50:22120 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
121 scoped_ptr<BeginFrameSource> external_begin_frame_source)
122 : ThreadProxy(host, main_task_runner,
123 impl_task_runner,
124 external_begin_frame_source.Pass()),
skyostil@chromium.org27e6a212014-07-18 15:51:27125 test_hooks_(test_hooks) {}
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56126};
brianderson@chromium.orgd9fce6722013-08-30 01:10:01127
danakj@chromium.orge216fef02013-03-20 22:56:10128// Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
129class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
130 public:
danakj@chromium.orge216fef02013-03-20 22:56:10131 static scoped_ptr<LayerTreeHostImplForTesting> Create(
132 TestHooks* test_hooks,
133 const LayerTreeSettings& settings,
134 LayerTreeHostImplClient* host_impl_client,
egraether@chromium.org372bad5f2013-03-21 16:38:43135 Proxy* proxy,
reveman22dd9292014-10-13 20:52:05136 SharedBitmapManager* shared_bitmap_manager,
revemanf9a8a232014-10-28 17:54:52137 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
egraether@chromium.org372bad5f2013-03-21 16:38:43138 RenderingStatsInstrumentation* stats_instrumentation) {
jbauman@chromium.org4e2eb352014-03-20 17:25:45139 return make_scoped_ptr(
140 new LayerTreeHostImplForTesting(test_hooks,
141 settings,
142 host_impl_client,
143 proxy,
reveman22dd9292014-10-13 20:52:05144 shared_bitmap_manager,
145 gpu_memory_buffer_manager,
jbauman@chromium.org4e2eb352014-03-20 17:25:45146 stats_instrumentation));
danakj@chromium.orge216fef02013-03-20 22:56:10147 }
148
149 protected:
egraether@chromium.org372bad5f2013-03-21 16:38:43150 LayerTreeHostImplForTesting(
151 TestHooks* test_hooks,
152 const LayerTreeSettings& settings,
153 LayerTreeHostImplClient* host_impl_client,
154 Proxy* proxy,
reveman22dd9292014-10-13 20:52:05155 SharedBitmapManager* shared_bitmap_manager,
revemanf9a8a232014-10-28 17:54:52156 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
egraether@chromium.org372bad5f2013-03-21 16:38:43157 RenderingStatsInstrumentation* stats_instrumentation)
158 : LayerTreeHostImpl(settings,
159 host_impl_client,
160 proxy,
jbauman@chromium.orga7f35682013-10-22 23:05:57161 stats_instrumentation,
reveman22dd9292014-10-13 20:52:05162 shared_bitmap_manager,
163 gpu_memory_buffer_manager,
caseq@chromium.orgdbe759a2013-12-02 19:23:02164 0),
brianderson@chromium.org4f48f6e2013-08-27 06:33:38165 test_hooks_(test_hooks),
166 block_notify_ready_to_activate_for_testing_(false),
167 notify_ready_to_activate_was_blocked_(false) {}
enne03dbe8ae2014-10-30 01:32:55168
vmiuraa30e1ea2014-12-09 19:23:51169 void CreateResourceAndTileTaskWorkerPool(
170 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
enne03dbe8ae2014-10-30 01:32:55171 scoped_ptr<ResourcePool>* resource_pool,
172 scoped_ptr<ResourcePool>* staging_resource_pool) override {
vmiuraa30e1ea2014-12-09 19:23:51173 test_hooks_->CreateResourceAndTileTaskWorkerPool(
174 this, tile_task_worker_pool, resource_pool, staging_resource_pool);
enne03dbe8ae2014-10-30 01:32:55175 }
brianderson@chromium.org4f48f6e2013-08-27 06:33:38176
dcheng716bedf2014-10-21 09:51:08177 void WillBeginImplFrame(const BeginFrameArgs& args) override {
brianderson@chromium.org97e9ccd62014-04-12 01:07:15178 LayerTreeHostImpl::WillBeginImplFrame(args);
brianderson@chromium.org4f48f6e2013-08-27 06:33:38179 test_hooks_->WillBeginImplFrameOnThread(this, args);
brianderson@chromium.org4f48f6e2013-08-27 06:33:38180 }
danakj@chromium.orge216fef02013-03-20 22:56:10181
dcheng716bedf2014-10-21 09:51:08182 void BeginMainFrameAborted(bool did_handle) override {
brianderson@chromium.org097a0cbf2013-12-12 17:04:58183 LayerTreeHostImpl::BeginMainFrameAborted(did_handle);
184 test_hooks_->BeginMainFrameAbortedOnThread(this, did_handle);
185 }
186
dcheng716bedf2014-10-21 09:51:08187 void BeginCommit() override {
danakj@chromium.orge216fef02013-03-20 22:56:10188 LayerTreeHostImpl::BeginCommit();
189 test_hooks_->BeginCommitOnThread(this);
190 }
191
dcheng716bedf2014-10-21 09:51:08192 void CommitComplete() override {
danakj@chromium.orge216fef02013-03-20 22:56:10193 LayerTreeHostImpl::CommitComplete();
alokp@chromium.orgb6061062014-06-27 19:20:08194 test_hooks_->CommitCompleteOnThread(this);
danakj@chromium.orge216fef02013-03-20 22:56:10195 }
196
dcheng716bedf2014-10-21 09:51:08197 DrawResult PrepareToDraw(FrameData* frame) override {
danakj@chromium.org2aae96792014-05-15 23:10:50198 DrawResult draw_result = LayerTreeHostImpl::PrepareToDraw(frame);
enne@chromium.org7ddfe7e82014-01-30 07:22:11199 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result);
danakj@chromium.orge216fef02013-03-20 22:56:10200 }
201
dcheng716bedf2014-10-21 09:51:08202 void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time) override {
ccameron@chromium.org2e316b272014-07-19 05:01:20203 LayerTreeHostImpl::DrawLayers(frame, frame_begin_time);
danakj@chromium.orge216fef02013-03-20 22:56:10204 test_hooks_->DrawLayersOnThread(this);
205 }
206
dcheng716bedf2014-10-21 09:51:08207 bool SwapBuffers(const LayerTreeHostImpl::FrameData& frame) override {
danakj@chromium.orge0341352013-04-06 05:01:20208 bool result = LayerTreeHostImpl::SwapBuffers(frame);
danakj@chromium.orge216fef02013-03-20 22:56:10209 test_hooks_->SwapBuffersOnThread(this, result);
210 return result;
211 }
212
dcheng716bedf2014-10-21 09:51:08213 void DidSwapBuffersComplete() override {
brianderson@chromium.orgc14902662014-04-18 05:06:11214 LayerTreeHostImpl::DidSwapBuffersComplete();
piman@chromium.org2ae13edf2013-05-08 16:02:38215 test_hooks_->SwapBuffersCompleteOnThread(this);
216 }
217
dcheng716bedf2014-10-21 09:51:08218 void ReclaimResources(const CompositorFrameAck* ack) override {
jbauman@chromium.orga7335e0b2013-09-18 09:34:51219 LayerTreeHostImpl::ReclaimResources(ack);
220 }
221
dcheng716bedf2014-10-21 09:51:08222 void NotifyReadyToActivate() override {
ernstmdfac03e2014-11-11 20:18:05223 if (block_notify_ready_to_activate_for_testing_) {
brianderson@chromium.org4f48f6e2013-08-27 06:33:38224 notify_ready_to_activate_was_blocked_ = true;
ernstmdfac03e2014-11-11 20:18:05225 } else {
danakja819c2552014-11-14 02:05:04226 LayerTreeHostImpl::NotifyReadyToActivate();
ernstmdfac03e2014-11-11 20:18:05227 test_hooks_->NotifyReadyToActivateOnThread(this);
228 }
229 }
230
231 void NotifyReadyToDraw() override {
danakja819c2552014-11-14 02:05:04232 LayerTreeHostImpl::NotifyReadyToDraw();
ernstmdfac03e2014-11-11 20:18:05233 test_hooks_->NotifyReadyToDrawOnThread(this);
brianderson@chromium.org4f48f6e2013-08-27 06:33:38234 }
danakj@chromium.orge216fef02013-03-20 22:56:10235
dcheng716bedf2014-10-21 09:51:08236 void BlockNotifyReadyToActivateForTesting(bool block) override {
enne98f3a6c2014-10-09 20:09:44237 CHECK(settings().impl_side_painting);
238 CHECK(proxy()->ImplThreadTaskRunner())
239 << "Not supported for single-threaded mode.";
brianderson@chromium.org4f48f6e2013-08-27 06:33:38240 block_notify_ready_to_activate_for_testing_ = block;
241 if (!block && notify_ready_to_activate_was_blocked_) {
242 NotifyReadyToActivate();
243 notify_ready_to_activate_was_blocked_ = false;
244 }
enne@chromium.org94bf75c2013-06-12 13:20:04245 }
246
dcheng716bedf2014-10-21 09:51:08247 void ActivateSyncTree() override {
enne@chromium.org94bf75c2013-06-12 13:20:04248 test_hooks_->WillActivateTreeOnThread(this);
alokp@chromium.orgfc20d142014-07-01 00:49:15249 LayerTreeHostImpl::ActivateSyncTree();
enne@chromium.org94bf75c2013-06-12 13:20:04250 DCHECK(!pending_tree());
251 test_hooks_->DidActivateTreeOnThread(this);
danakj@chromium.orge216fef02013-03-20 22:56:10252 }
253
dcheng716bedf2014-10-21 09:51:08254 bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface) override {
danakj@chromium.orge216fef02013-03-20 22:56:10255 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass());
256 test_hooks_->InitializedRendererOnThread(this, success);
257 return success;
258 }
259
dcheng716bedf2014-10-21 09:51:08260 void SetVisible(bool visible) override {
danakj@chromium.orge216fef02013-03-20 22:56:10261 LayerTreeHostImpl::SetVisible(visible);
262 test_hooks_->DidSetVisibleOnImplTree(this, visible);
263 }
264
dcheng716bedf2014-10-21 09:51:08265 void AnimateLayers(base::TimeTicks monotonic_time) override {
danakj@chromium.orge216fef02013-03-20 22:56:10266 test_hooks_->WillAnimateLayers(this, monotonic_time);
mithro@mithis.com27152642014-03-11 20:42:00267 LayerTreeHostImpl::AnimateLayers(monotonic_time);
danakj@chromium.orge216fef02013-03-20 22:56:10268 test_hooks_->AnimateLayers(this, monotonic_time);
269 }
270
dcheng716bedf2014-10-21 09:51:08271 void UpdateAnimationState(bool start_ready_animations) override {
danakj@chromium.org3d9f7432013-04-06 00:35:18272 LayerTreeHostImpl::UpdateAnimationState(start_ready_animations);
danakj@chromium.orge216fef02013-03-20 22:56:10273 bool has_unfinished_animation = false;
274 AnimationRegistrar::AnimationControllerMap::const_iterator iter =
275 active_animation_controllers().begin();
276 for (; iter != active_animation_controllers().end(); ++iter) {
277 if (iter->second->HasActiveAnimation()) {
278 has_unfinished_animation = true;
279 break;
280 }
281 }
282 test_hooks_->UpdateAnimationState(this, has_unfinished_animation);
danakja819c2552014-11-14 02:05:04283 }
284
285 void NotifyTileStateChanged(const Tile* tile) override {
286 LayerTreeHostImpl::NotifyTileStateChanged(tile);
287 test_hooks_->NotifyTileStateChangedOnThread(this, tile);
danakj@chromium.orge216fef02013-03-20 22:56:10288 }
289
290 private:
291 TestHooks* test_hooks_;
brianderson@chromium.org4f48f6e2013-08-27 06:33:38292 bool block_notify_ready_to_activate_for_testing_;
293 bool notify_ready_to_activate_was_blocked_;
danakj@chromium.orge216fef02013-03-20 22:56:10294};
295
danakj@chromium.orge216fef02013-03-20 22:56:10296// Implementation of LayerTreeHost callback interface.
jamesr@chromium.org943528e2013-11-07 05:01:32297class LayerTreeHostClientForTesting : public LayerTreeHostClient,
298 public LayerTreeHostSingleThreadClient {
danakj@chromium.orge216fef02013-03-20 22:56:10299 public:
300 static scoped_ptr<LayerTreeHostClientForTesting> Create(
301 TestHooks* test_hooks) {
302 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks));
303 }
dcheng716bedf2014-10-21 09:51:08304 ~LayerTreeHostClientForTesting() override {}
danakj@chromium.orge216fef02013-03-20 22:56:10305
dcheng716bedf2014-10-21 09:51:08306 void WillBeginMainFrame(int frame_id) override {
dominikg@chromium.orgdaea3d42013-10-23 17:04:50307 test_hooks_->WillBeginMainFrame();
308 }
danakj@chromium.orge216fef02013-03-20 22:56:10309
dcheng716bedf2014-10-21 09:51:08310 void DidBeginMainFrame() override { test_hooks_->DidBeginMainFrame(); }
danakj@chromium.orge216fef02013-03-20 22:56:10311
dcheng716bedf2014-10-21 09:51:08312 void BeginMainFrame(const BeginFrameArgs& args) override {
skyostil@chromium.org04c5900d2014-08-18 13:38:36313 test_hooks_->BeginMainFrame(args);
danakj@chromium.orge216fef02013-03-20 22:56:10314 }
315
dcheng716bedf2014-10-21 09:51:08316 void Layout() override { test_hooks_->Layout(); }
danakj@chromium.orge216fef02013-03-20 22:56:10317
dcheng716bedf2014-10-21 09:51:08318 void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
319 const gfx::Vector2d& outer_delta,
ccameron98be9ac2014-12-09 19:56:32320 const gfx::Vector2dF& elastic_overscroll_delta,
dcheng716bedf2014-10-21 09:51:08321 float page_scale,
322 float top_controls_delta) override {
ccameron98be9ac2014-12-09 19:56:32323 test_hooks_->ApplyViewportDeltas(inner_delta, outer_delta,
324 elastic_overscroll_delta, page_scale,
bokan59379b092014-09-29 13:47:21325 top_controls_delta);
326 }
dcheng716bedf2014-10-21 09:51:08327 void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
328 float scale,
329 float top_controls_delta) override {
bokan88eae012014-09-09 20:40:42330 test_hooks_->ApplyViewportDeltas(scroll_delta,
331 scale,
332 top_controls_delta);
danakj@chromium.orge216fef02013-03-20 22:56:10333 }
334
enne7f8fdde2014-12-10 21:32:09335 void RequestNewOutputSurface() override {
336 test_hooks_->RequestNewOutputSurface();
danakj@chromium.orge216fef02013-03-20 22:56:10337 }
338
dcheng716bedf2014-10-21 09:51:08339 void DidInitializeOutputSurface() override {
danakj@chromium.orgda8e3b72b2014-04-25 02:33:45340 test_hooks_->DidInitializeOutputSurface();
danakj@chromium.orge216fef02013-03-20 22:56:10341 }
342
simonhongd3d5f7f2014-11-21 16:38:03343 void SendBeginFramesToChildren(const BeginFrameArgs& args) override {
344 test_hooks_->SendBeginFramesToChildren(args);
345 }
346
dcheng716bedf2014-10-21 09:51:08347 void DidFailToInitializeOutputSurface() override {
boliu@chromium.org04049fc2013-05-01 03:13:20348 test_hooks_->DidFailToInitializeOutputSurface();
enne7f8fdde2014-12-10 21:32:09349 RequestNewOutputSurface();
danakj@chromium.orge216fef02013-03-20 22:56:10350 }
351
dcheng716bedf2014-10-21 09:51:08352 void WillCommit() override { test_hooks_->WillCommit(); }
danakj@chromium.orge216fef02013-03-20 22:56:10353
dcheng716bedf2014-10-21 09:51:08354 void DidCommit() override { test_hooks_->DidCommit(); }
danakj@chromium.orge216fef02013-03-20 22:56:10355
dcheng716bedf2014-10-21 09:51:08356 void DidCommitAndDrawFrame() override {
danakj@chromium.orge216fef02013-03-20 22:56:10357 test_hooks_->DidCommitAndDrawFrame();
358 }
359
dcheng716bedf2014-10-21 09:51:08360 void DidCompleteSwapBuffers() override {
piman@chromium.org2ae13edf2013-05-08 16:02:38361 test_hooks_->DidCompleteSwapBuffers();
362 }
danakj@chromium.orge216fef02013-03-20 22:56:10363
dcheng716bedf2014-10-21 09:51:08364 void DidPostSwapBuffers() override {}
365 void DidAbortSwapBuffers() override {}
jbauman399aec1a2014-10-25 02:33:32366 void ScheduleComposite() override { test_hooks_->ScheduleComposite(); }
jamesr@chromium.org943528e2013-11-07 05:01:32367
danakj@chromium.orge216fef02013-03-20 22:56:10368 private:
369 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
370 : test_hooks_(test_hooks) {}
371
372 TestHooks* test_hooks_;
373};
374
jamesr@chromium.org943528e2013-11-07 05:01:32375// Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
376class LayerTreeHostForTesting : public LayerTreeHost {
377 public:
378 static scoped_ptr<LayerTreeHostForTesting> Create(
379 TestHooks* test_hooks,
380 LayerTreeHostClientForTesting* client,
381 const LayerTreeSettings& settings,
skyostil@chromium.org27e6a212014-07-18 15:51:27382 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
simonhonga7e3ac42014-11-11 20:50:22383 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
384 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
jamesr@chromium.org943528e2013-11-07 05:01:32385 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
386 new LayerTreeHostForTesting(test_hooks, client, settings));
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56387 if (impl_task_runner.get()) {
388 layer_tree_host->InitializeForTesting(
389 ThreadProxyForTest::Create(test_hooks,
390 layer_tree_host.get(),
skyostil@chromium.org27e6a212014-07-18 15:51:27391 main_task_runner,
simonhonga7e3ac42014-11-11 20:50:22392 impl_task_runner,
393 external_begin_frame_source.Pass()));
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56394 } else {
skyostil@chromium.org27e6a212014-07-18 15:51:27395 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create(
simonhonga7e3ac42014-11-11 20:50:22396 layer_tree_host.get(),
397 client,
398 main_task_runner,
399 external_begin_frame_source.Pass()));
simonhong@chromium.org6f0fdcb2014-05-22 02:51:56400 }
jamesr@chromium.org943528e2013-11-07 05:01:32401 return layer_tree_host.Pass();
402 }
403
dcheng716bedf2014-10-21 09:51:08404 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
mostynbf68776d82014-10-06 18:07:37405 LayerTreeHostImplClient* host_impl_client) override {
jamesr@chromium.org943528e2013-11-07 05:01:32406 return LayerTreeHostImplForTesting::Create(
danakjf446a072014-09-27 21:55:48407 test_hooks_,
408 settings(),
409 host_impl_client,
410 proxy(),
411 shared_bitmap_manager_.get(),
reveman22dd9292014-10-13 20:52:05412 gpu_memory_buffer_manager_.get(),
danakjf446a072014-09-27 21:55:48413 rendering_stats_instrumentation());
jamesr@chromium.org943528e2013-11-07 05:01:32414 }
415
dcheng716bedf2014-10-21 09:51:08416 void SetNeedsCommit() override {
jamesr@chromium.org943528e2013-11-07 05:01:32417 if (!test_started_)
418 return;
419 LayerTreeHost::SetNeedsCommit();
420 }
421
422 void set_test_started(bool started) { test_started_ = started; }
423
dcheng716bedf2014-10-21 09:51:08424 void DidDeferCommit() override { test_hooks_->DidDeferCommit(); }
jamesr@chromium.org943528e2013-11-07 05:01:32425
426 private:
427 LayerTreeHostForTesting(TestHooks* test_hooks,
428 LayerTreeHostClient* client,
429 const LayerTreeSettings& settings)
reveman22dd9292014-10-13 20:52:05430 : LayerTreeHost(client, NULL, NULL, settings),
431 shared_bitmap_manager_(new TestSharedBitmapManager),
432 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager),
jamesr@chromium.org943528e2013-11-07 05:01:32433 test_hooks_(test_hooks),
434 test_started_(false) {}
435
reveman22dd9292014-10-13 20:52:05436 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
437 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
jamesr@chromium.org943528e2013-11-07 05:01:32438 TestHooks* test_hooks_;
439 bool test_started_;
440};
441
danakj@chromium.orge216fef02013-03-20 22:56:10442LayerTreeTest::LayerTreeTest()
enne03dbe8ae2014-10-30 01:32:55443 : output_surface_(nullptr),
simonhonga7e3ac42014-11-11 20:50:22444 external_begin_frame_source_(nullptr),
enne03dbe8ae2014-10-30 01:32:55445 beginning_(false),
danakj@chromium.orge216fef02013-03-20 22:56:10446 end_when_begin_returns_(false),
447 timed_out_(false),
448 scheduled_(false),
danakj@chromium.orge216fef02013-03-20 22:56:10449 started_(false),
450 ended_(false),
danakj@chromium.org2a61ad52013-05-13 14:01:29451 delegating_renderer_(false),
danakj@chromium.org4fc1b792013-03-26 08:58:57452 timeout_seconds_(0),
scherkus@chromium.org257b1a072013-04-26 08:01:40453 weak_factory_(this) {
danakj@chromium.orge216fef02013-03-20 22:56:10454 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr();
danakj@chromium.org4fc1b792013-03-26 08:58:57455
456 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was
457 // specified (for running in a debugger).
pgal.u-szeged8c867962014-11-18 16:24:44458 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
vollick@chromium.org8309341c2013-04-29 21:11:31459 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout))
danakj@chromium.org4fc1b792013-03-26 08:58:57460 timeout_seconds_ = 5;
danakj@chromium.orge216fef02013-03-20 22:56:10461}
462
463LayerTreeTest::~LayerTreeTest() {}
464
465void LayerTreeTest::EndTest() {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38466 if (ended_)
467 return;
enne@chromium.org66bfba62013-07-13 00:27:01468 ended_ = true;
469
danakj@chromium.org7ac8dcb2013-10-31 09:58:38470 // For the case where we EndTest during BeginTest(), set a flag to indicate
471 // that the test should end the second BeginTest regains control.
leandrogracia@chromium.org7539d512013-03-22 15:56:44472 if (beginning_) {
danakj@chromium.orge216fef02013-03-20 22:56:10473 end_when_begin_returns_ = true;
danakj@chromium.org7ac8dcb2013-10-31 09:58:38474 } else {
475 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15476 FROM_HERE,
danakj@chromium.orge216fef02013-03-20 22:56:10477 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
leandrogracia@chromium.org7539d512013-03-22 15:56:44478 }
danakj@chromium.orge216fef02013-03-20 22:56:10479}
480
danakja819c2552014-11-14 02:05:04481void LayerTreeTest::EndTestAfterDelayMs(int delay_milliseconds) {
caseq@chromium.org2c6998c2014-04-03 11:33:57482 main_task_runner_->PostDelayedTask(
483 FROM_HERE,
484 base::Bind(&LayerTreeTest::EndTest, main_thread_weak_ptr_),
485 base::TimeDelta::FromMilliseconds(delay_milliseconds));
danakj@chromium.orge216fef02013-03-20 22:56:10486}
487
488void LayerTreeTest::PostAddAnimationToMainThread(
489 Layer* layer_to_receive_animation) {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38490 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15491 FROM_HERE,
behara.ms591d77f92014-11-18 16:01:40492 base::Bind(&LayerTreeTest::DispatchAddAnimation, main_thread_weak_ptr_,
493 base::Unretained(layer_to_receive_animation), 0.000004));
danakj@chromium.orge216fef02013-03-20 22:56:10494}
495
danakj@chromium.org3d9f7432013-04-06 00:35:18496void LayerTreeTest::PostAddInstantAnimationToMainThread(
497 Layer* layer_to_receive_animation) {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38498 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15499 FROM_HERE,
ajuma@chromium.org40880faa2013-11-18 08:10:00500 base::Bind(&LayerTreeTest::DispatchAddAnimation,
danakj@chromium.org3d9f7432013-04-06 00:35:18501 main_thread_weak_ptr_,
ajuma@chromium.org40880faa2013-11-18 08:10:00502 base::Unretained(layer_to_receive_animation),
503 0.0));
504}
505
506void LayerTreeTest::PostAddLongAnimationToMainThread(
507 Layer* layer_to_receive_animation) {
508 main_task_runner_->PostTask(
509 FROM_HERE,
510 base::Bind(&LayerTreeTest::DispatchAddAnimation,
511 main_thread_weak_ptr_,
512 base::Unretained(layer_to_receive_animation),
513 1.0));
danakj@chromium.orge216fef02013-03-20 22:56:10514}
515
516void LayerTreeTest::PostSetNeedsCommitToMainThread() {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38517 main_task_runner_->PostTask(FROM_HERE,
518 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit,
519 main_thread_weak_ptr_));
danakj@chromium.orge216fef02013-03-20 22:56:10520}
521
miletus@chromium.orgb69c1db2013-11-27 00:05:19522void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() {
523 main_task_runner_->PostTask(
524 FROM_HERE,
525 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers,
526 main_thread_weak_ptr_));
527}
528
danakj@chromium.orge216fef02013-03-20 22:56:10529void LayerTreeTest::PostSetNeedsRedrawToMainThread() {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38530 main_task_runner_->PostTask(FROM_HERE,
531 base::Bind(&LayerTreeTest::DispatchSetNeedsRedraw,
532 main_thread_weak_ptr_));
danakj@chromium.orge216fef02013-03-20 22:56:10533}
534
prashant.n@samsung.com0023fc72014-01-10 20:05:06535void LayerTreeTest::PostSetNeedsRedrawRectToMainThread(
536 const gfx::Rect& damage_rect) {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38537 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15538 FROM_HERE,
skaslev@chromium.org878705be2013-04-15 22:44:02539 base::Bind(&LayerTreeTest::DispatchSetNeedsRedrawRect,
danakj@chromium.org7ac8dcb2013-10-31 09:58:38540 main_thread_weak_ptr_,
541 damage_rect));
skaslev@chromium.org878705be2013-04-15 22:44:02542}
543
danakj@chromium.orge216fef02013-03-20 22:56:10544void LayerTreeTest::PostSetVisibleToMainThread(bool visible) {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38545 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15546 FROM_HERE,
danakj@chromium.org7ac8dcb2013-10-31 09:58:38547 base::Bind(
548 &LayerTreeTest::DispatchSetVisible, main_thread_weak_ptr_, visible));
danakj@chromium.orge216fef02013-03-20 22:56:10549}
550
kbr@chromium.org7d08a9352013-10-15 08:24:56551void LayerTreeTest::PostSetNextCommitForcesRedrawToMainThread() {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38552 main_task_runner_->PostTask(
kbr@chromium.org7d08a9352013-10-15 08:24:56553 FROM_HERE,
554 base::Bind(&LayerTreeTest::DispatchSetNextCommitForcesRedraw,
555 main_thread_weak_ptr_));
556}
557
enne69277cb2014-10-29 23:03:40558void LayerTreeTest::PostCompositeImmediatelyToMainThread() {
559 main_task_runner_->PostTask(
560 FROM_HERE,
561 base::Bind(&LayerTreeTest::DispatchCompositeImmediately,
562 main_thread_weak_ptr_));
563}
564
sievers@google.come96e3432013-12-19 18:56:07565void LayerTreeTest::WillBeginTest() {
566 layer_tree_host_->SetLayerTreeHostClientReady();
567}
568
danakj@chromium.orge216fef02013-03-20 22:56:10569void LayerTreeTest::DoBeginTest() {
570 client_ = LayerTreeHostClientForTesting::Create(this);
571
danakj6e3bf8012014-12-16 18:27:53572 scoped_ptr<FakeExternalBeginFrameSource> external_begin_frame_source;
simonhong2880b8e2014-11-11 23:25:36573 if (settings_.use_external_begin_frame_source &&
simonhonga7e3ac42014-11-11 20:50:22574 settings_.throttle_frame_production) {
danakj6e3bf8012014-12-16 18:27:53575 external_begin_frame_source.reset(new FakeExternalBeginFrameSource(
jbaumanc5be44c2014-11-20 22:17:12576 settings_.renderer_settings.refresh_rate));
simonhonga7e3ac42014-11-11 20:50:22577 external_begin_frame_source_ = external_begin_frame_source.get();
578 }
579
rsleevi@chromium.org198b5902013-06-27 10:36:11580 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get());
danakj@chromium.org810d40b72013-06-20 18:26:15581 layer_tree_host_ = LayerTreeHostForTesting::Create(
582 this,
583 client_.get(),
584 settings_,
skyostil@chromium.org27e6a212014-07-18 15:51:27585 base::MessageLoopProxy::current(),
simonhonga7e3ac42014-11-11 20:50:22586 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL,
587 external_begin_frame_source.Pass());
danakj@chromium.orge216fef02013-03-20 22:56:10588 ASSERT_TRUE(layer_tree_host_);
589
590 started_ = true;
591 beginning_ = true;
592 SetupTree();
sievers@google.come96e3432013-12-19 18:56:07593 WillBeginTest();
danakj@chromium.orge216fef02013-03-20 22:56:10594 BeginTest();
595 beginning_ = false;
596 if (end_when_begin_returns_)
597 RealEndTest();
598
599 // Allow commits to happen once BeginTest() has had a chance to post tasks
600 // so that those tasks will happen before the first commit.
601 if (layer_tree_host_) {
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11602 static_cast<LayerTreeHostForTesting*>(layer_tree_host_.get())
603 ->set_test_started(true);
danakj@chromium.orge216fef02013-03-20 22:56:10604 }
605}
606
607void LayerTreeTest::SetupTree() {
608 if (!layer_tree_host_->root_layer()) {
609 scoped_refptr<Layer> root_layer = Layer::Create();
610 root_layer->SetBounds(gfx::Size(1, 1));
danakj@chromium.orge0341352013-04-06 05:01:20611 root_layer->SetIsDrawable(true);
danakj@chromium.orge216fef02013-03-20 22:56:10612 layer_tree_host_->SetRootLayer(root_layer);
613 }
614
615 gfx::Size root_bounds = layer_tree_host_->root_layer()->bounds();
616 gfx::Size device_root_bounds = gfx::ToCeiledSize(
617 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor()));
aelias@chromium.org18ce59702013-04-09 04:58:40618 layer_tree_host_->SetViewportSize(device_root_bounds);
danakj@chromium.orge216fef02013-03-20 22:56:10619}
620
621void LayerTreeTest::Timeout() {
622 timed_out_ = true;
623 EndTest();
624}
625
danakj@chromium.orge216fef02013-03-20 22:56:10626void LayerTreeTest::RealEndTest() {
danakj@chromium.org4ea293f72014-08-13 03:03:17627 if (layer_tree_host_ && !timed_out_ &&
628 proxy()->MainFrameWillHappenForTesting()) {
danakj@chromium.org7ac8dcb2013-10-31 09:58:38629 main_task_runner_->PostTask(
danakj@chromium.org810d40b72013-06-20 18:26:15630 FROM_HERE,
danakj@chromium.orge216fef02013-03-20 22:56:10631 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
632 return;
633 }
jamesr@chromium.orgbf691c22013-03-26 21:15:06634
xhwang@chromium.org2811f312013-04-27 05:21:17635 base::MessageLoop::current()->Quit();
danakj@chromium.orge216fef02013-03-20 22:56:10636}
637
ajuma@chromium.org40880faa2013-11-18 08:10:00638void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation,
639 double animation_duration) {
danakj@chromium.orge216fef02013-03-20 22:56:10640 DCHECK(!proxy() || proxy()->IsMainThread());
641
danakj@chromium.org3d9f7432013-04-06 00:35:18642 if (layer_to_receive_animation) {
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11643 AddOpacityTransitionToLayer(
644 layer_to_receive_animation, animation_duration, 0, 0.5, true);
danakj@chromium.org3d9f7432013-04-06 00:35:18645 }
danakj@chromium.orge216fef02013-03-20 22:56:10646}
647
648void LayerTreeTest::DispatchSetNeedsCommit() {
649 DCHECK(!proxy() || proxy()->IsMainThread());
650
651 if (layer_tree_host_)
652 layer_tree_host_->SetNeedsCommit();
653}
654
miletus@chromium.orgb69c1db2013-11-27 00:05:19655void LayerTreeTest::DispatchSetNeedsUpdateLayers() {
656 DCHECK(!proxy() || proxy()->IsMainThread());
657
658 if (layer_tree_host_)
659 layer_tree_host_->SetNeedsUpdateLayers();
danakj@chromium.orge216fef02013-03-20 22:56:10660}
661
662void LayerTreeTest::DispatchSetNeedsRedraw() {
663 DCHECK(!proxy() || proxy()->IsMainThread());
664
665 if (layer_tree_host_)
666 layer_tree_host_->SetNeedsRedraw();
667}
668
prashant.n@samsung.com0023fc72014-01-10 20:05:06669void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) {
skaslev@chromium.org878705be2013-04-15 22:44:02670 DCHECK(!proxy() || proxy()->IsMainThread());
671
672 if (layer_tree_host_)
673 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
674}
675
danakj@chromium.orge216fef02013-03-20 22:56:10676void LayerTreeTest::DispatchSetVisible(bool visible) {
677 DCHECK(!proxy() || proxy()->IsMainThread());
enne@chromium.orgaeeedad2014-08-22 18:16:22678 if (layer_tree_host_)
679 layer_tree_host_->SetVisible(visible);
danakj@chromium.orge216fef02013-03-20 22:56:10680}
681
kbr@chromium.org7d08a9352013-10-15 08:24:56682void LayerTreeTest::DispatchSetNextCommitForcesRedraw() {
683 DCHECK(!proxy() || proxy()->IsMainThread());
684
685 if (layer_tree_host_)
mark@chromium.org8b9e52b2014-01-17 16:35:31686 layer_tree_host_->SetNextCommitForcesRedraw();
enne@chromium.org2decdd782014-08-13 22:36:06687}
688
enne69277cb2014-10-29 23:03:40689void LayerTreeTest::DispatchCompositeImmediately() {
690 DCHECK(!proxy() || proxy()->IsMainThread());
691 if (layer_tree_host_)
692 layer_tree_host_->Composite(gfx::FrameTime::Now());
693}
694
danakj@chromium.org2a61ad52013-05-13 14:01:29695void LayerTreeTest::RunTest(bool threaded,
696 bool delegating_renderer,
697 bool impl_side_painting) {
danakj@chromium.orge216fef02013-03-20 22:56:10698 if (threaded) {
vollick@chromium.org8309341c2013-04-29 21:11:31699 impl_thread_.reset(new base::Thread("Compositor"));
danakj@chromium.orge216fef02013-03-20 22:56:10700 ASSERT_TRUE(impl_thread_->Start());
701 }
702
danakj@chromium.orgbcc5c382013-09-19 22:42:17703 main_task_runner_ = base::MessageLoopProxy::current();
danakj@chromium.org4145d172013-05-10 16:54:36704
705 delegating_renderer_ = delegating_renderer;
danakj@chromium.orge216fef02013-03-20 22:56:10706
brianderson@chromium.org97e9ccd62014-04-12 01:07:15707 // Spend less time waiting for BeginFrame because the output is
brianderson@chromium.orgc8cbae72013-05-23 10:45:03708 // mocked out.
jbaumanc5be44c2014-11-20 22:17:12709 settings_.renderer_settings.refresh_rate = 200.0;
mithro719bf6792014-11-10 15:36:47710 settings_.background_animation_rate = 200.0;
enne98f3a6c2014-10-09 20:09:44711 settings_.impl_side_painting = impl_side_painting;
vollick51ed1a22014-12-17 02:03:00712 settings_.verify_property_trees = true;
danakj@chromium.orge216fef02013-03-20 22:56:10713 InitializeSettings(&settings_);
714
danakj@chromium.org810d40b72013-06-20 18:26:15715 main_task_runner_->PostTask(
716 FROM_HERE,
danakj@chromium.orge216fef02013-03-20 22:56:10717 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this)));
danakj@chromium.org4fc1b792013-03-26 08:58:57718
719 if (timeout_seconds_) {
720 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this)));
danakj@chromium.org810d40b72013-06-20 18:26:15721 main_task_runner_->PostDelayedTask(
722 FROM_HERE,
danakj@chromium.org4fc1b792013-03-26 08:58:57723 timeout_.callback(),
724 base::TimeDelta::FromSeconds(timeout_seconds_));
725 }
726
xhwang@chromium.org2811f312013-04-27 05:21:17727 base::MessageLoop::current()->Run();
danakj@chromium.orgdf17af52014-02-06 02:20:40728 DestroyLayerTreeHost();
danakj@chromium.orge216fef02013-03-20 22:56:10729
730 timeout_.Cancel();
731
732 ASSERT_FALSE(layer_tree_host_.get());
danakjf446a072014-09-27 21:55:48733 client_ = nullptr;
danakj@chromium.orge216fef02013-03-20 22:56:10734 if (timed_out_) {
735 FAIL() << "Test timed out";
736 return;
737 }
738 AfterTest();
739}
740
clholgat@chromium.orgc0f7a7f2013-10-15 21:33:56741void LayerTreeTest::RunTestWithImplSidePainting() {
742 RunTest(true, false, true);
743}
744
enne7f8fdde2014-12-10 21:32:09745void LayerTreeTest::RequestNewOutputSurface() {
746 layer_tree_host_->SetOutputSurface(CreateOutputSurface());
enne2097cab2014-09-25 20:16:31747}
748
enne7f8fdde2014-12-10 21:32:09749scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface() {
750 scoped_ptr<FakeOutputSurface> output_surface = CreateFakeOutputSurface();
751 DCHECK_EQ(delegating_renderer_,
752 output_surface->capabilities().delegated_rendering);
brianderson@chromium.org049fc7a2013-06-18 12:32:35753 output_surface_ = output_surface.get();
simonhonga7e3ac42014-11-11 20:50:22754
simonhong2880b8e2014-11-11 23:25:36755 if (settings_.use_external_begin_frame_source &&
simonhonga7e3ac42014-11-11 20:50:22756 settings_.throttle_frame_production) {
757 DCHECK(external_begin_frame_source_);
758 DCHECK(external_begin_frame_source_->is_ready());
759 }
danakjf446a072014-09-27 21:55:48760 return output_surface.Pass();
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11761}
762
enne7f8fdde2014-12-10 21:32:09763scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface() {
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11764 if (delegating_renderer_)
765 return FakeOutputSurface::CreateDelegating3d();
766 else
767 return FakeOutputSurface::Create3d();
danakj@chromium.org4145d172013-05-10 16:54:36768}
769
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11770TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
dcheng6afa17002014-08-26 19:11:31771 return static_cast<TestContextProvider*>(output_surface_->context_provider())
772 ->TestContext3d();
jamesr@chromium.orge7e7ebd2014-01-16 00:11:11773}
774
enne@chromium.org98ea818e2014-01-24 10:22:08775int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
776 const {
777 if (impl->pending_tree())
778 return impl->pending_tree()->source_frame_number();
779 if (impl->active_tree())
780 return impl->active_tree()->source_frame_number();
781 // Source frames start at 0, so this is invalid.
782 return -1;
783}
784
danakj@chromium.orgdf17af52014-02-06 02:20:40785void LayerTreeTest::DestroyLayerTreeHost() {
786 if (layer_tree_host_ && layer_tree_host_->root_layer())
787 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
danakjf446a072014-09-27 21:55:48788 layer_tree_host_ = nullptr;
danakj@chromium.orgdf17af52014-02-06 02:20:40789}
790
danakj@chromium.orge216fef02013-03-20 22:56:10791} // namespace cc