1 // Copyright 2012 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/trees/layer_tree_host.h"
7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/layer.h"
9 #include "cc/layers/layer_impl.h"
10 #include "cc/layers/picture_layer.h"
11 #include "cc/test/fake_content_layer_client.h"
12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_picture_layer.h"
14 #include "cc/test/fake_picture_layer_impl.h"
15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/test/layer_tree_test.h"
17 #include "cc/test/test_shared_bitmap_manager.h"
18 #include "cc/trees/layer_tree_impl.h"
19 #include "ui/gfx/point_conversions.h"
20 #include "ui/gfx/size_conversions.h"
21 #include "ui/gfx/vector2d_conversions.h"
26 class LayerTreeHostScrollTest
: public LayerTreeTest
{};
28 class LayerTreeHostScrollTestScrollSimple
: public LayerTreeHostScrollTest
{
30 LayerTreeHostScrollTestScrollSimple()
31 : initial_scroll_(10, 20),
32 second_scroll_(40, 5),
33 scroll_amount_(2, -1),
36 virtual void BeginTest() OVERRIDE
{
37 Layer
* root_layer
= layer_tree_host()->root_layer();
38 scoped_refptr
<Layer
> scroll_layer
= Layer::Create();
39 root_layer
->AddChild(scroll_layer
);
40 // Create an effective max_scroll_offset of (100, 100).
41 scroll_layer
->SetBounds(gfx::Size(root_layer
->bounds().width() + 100,
42 root_layer
->bounds().height() + 100));
43 scroll_layer
->SetIsDrawable(true);
44 scroll_layer
->SetIsContainerForFixedPositionLayers(true);
45 scroll_layer
->SetScrollClipLayerId(root_layer
->id());
46 scroll_layer
->SetScrollOffset(initial_scroll_
);
47 layer_tree_host()->RegisterViewportLayers(root_layer
, scroll_layer
, NULL
);
48 PostSetNeedsCommitToMainThread();
51 virtual void Layout() OVERRIDE
{
52 Layer
* root
= layer_tree_host()->root_layer();
53 Layer
* scroll_layer
= root
->children()[0].get();
54 if (!layer_tree_host()->source_frame_number()) {
55 EXPECT_VECTOR_EQ(initial_scroll_
, scroll_layer
->scroll_offset());
57 EXPECT_VECTOR_EQ(initial_scroll_
+ scroll_amount_
,
58 scroll_layer
->scroll_offset());
60 // Pretend like Javascript updated the scroll position itself.
61 scroll_layer
->SetScrollOffset(second_scroll_
);
65 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
66 LayerImpl
* root
= impl
->active_tree()->root_layer();
67 LayerImpl
* scroll_layer
= root
->children()[0];
68 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer
->ScrollDelta());
70 scroll_layer
->SetScrollClipLayer(root
->id());
71 scroll_layer
->SetBounds(
72 gfx::Size(root
->bounds().width() + 100, root
->bounds().height() + 100));
73 scroll_layer
->ScrollBy(scroll_amount_
);
75 switch (impl
->active_tree()->source_frame_number()) {
77 EXPECT_VECTOR_EQ(initial_scroll_
, scroll_layer
->scroll_offset());
78 EXPECT_VECTOR_EQ(scroll_amount_
, scroll_layer
->ScrollDelta());
79 PostSetNeedsCommitToMainThread();
82 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), second_scroll_
);
83 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), scroll_amount_
);
89 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
90 float scale
) OVERRIDE
{
94 virtual void AfterTest() OVERRIDE
{ EXPECT_EQ(1, num_scrolls_
); }
97 gfx::Vector2d initial_scroll_
;
98 gfx::Vector2d second_scroll_
;
99 gfx::Vector2d scroll_amount_
;
103 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple
);
105 class LayerTreeHostScrollTestScrollMultipleRedraw
106 : public LayerTreeHostScrollTest
{
108 LayerTreeHostScrollTestScrollMultipleRedraw()
109 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {}
111 virtual void BeginTest() OVERRIDE
{
112 Layer
* root_layer
= layer_tree_host()->root_layer();
113 scroll_layer_
= Layer::Create();
114 root_layer
->AddChild(scroll_layer_
);
115 // Create an effective max_scroll_offset of (100, 100).
116 scroll_layer_
->SetBounds(gfx::Size(root_layer
->bounds().width() + 100,
117 root_layer
->bounds().height() + 100));
118 scroll_layer_
->SetIsDrawable(true);
119 scroll_layer_
->SetIsContainerForFixedPositionLayers(true);
120 scroll_layer_
->SetScrollClipLayerId(root_layer
->id());
121 scroll_layer_
->SetScrollOffset(initial_scroll_
);
122 layer_tree_host()->RegisterViewportLayers(root_layer
, scroll_layer_
, NULL
);
123 PostSetNeedsCommitToMainThread();
126 virtual void BeginCommitOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
127 switch (layer_tree_host()->source_frame_number()) {
129 EXPECT_VECTOR_EQ(scroll_layer_
->scroll_offset(), initial_scroll_
);
132 EXPECT_VECTOR_EQ(scroll_layer_
->scroll_offset(),
133 initial_scroll_
+ scroll_amount_
+ scroll_amount_
);
135 EXPECT_VECTOR_EQ(scroll_layer_
->scroll_offset(),
136 initial_scroll_
+ scroll_amount_
+ scroll_amount_
);
141 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
142 LayerImpl
* scroll_layer
=
143 impl
->active_tree()->LayerById(scroll_layer_
->id());
144 if (impl
->active_tree()->source_frame_number() == 0 &&
145 impl
->SourceAnimationFrameNumber() == 1) {
146 // First draw after first commit.
147 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), gfx::Vector2d());
148 scroll_layer
->ScrollBy(scroll_amount_
);
149 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), scroll_amount_
);
151 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
152 PostSetNeedsRedrawToMainThread();
153 } else if (impl
->active_tree()->source_frame_number() == 0 &&
154 impl
->SourceAnimationFrameNumber() == 2) {
155 // Second draw after first commit.
156 EXPECT_EQ(scroll_layer
->ScrollDelta(), scroll_amount_
);
157 scroll_layer
->ScrollBy(scroll_amount_
);
158 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(),
159 scroll_amount_
+ scroll_amount_
);
161 EXPECT_VECTOR_EQ(scroll_layer_
->scroll_offset(), initial_scroll_
);
162 PostSetNeedsCommitToMainThread();
163 } else if (impl
->active_tree()->source_frame_number() == 1) {
164 // Third or later draw after second commit.
165 EXPECT_GE(impl
->SourceAnimationFrameNumber(), 3);
166 EXPECT_VECTOR_EQ(scroll_layer_
->ScrollDelta(), gfx::Vector2d());
167 EXPECT_VECTOR_EQ(scroll_layer_
->scroll_offset(),
168 initial_scroll_
+ scroll_amount_
+ scroll_amount_
);
173 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
174 float scale
) OVERRIDE
{
178 virtual void AfterTest() OVERRIDE
{ EXPECT_EQ(1, num_scrolls_
); }
181 gfx::Vector2d initial_scroll_
;
182 gfx::Vector2d scroll_amount_
;
184 scoped_refptr
<Layer
> scroll_layer_
;
187 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw
);
189 class LayerTreeHostScrollTestScrollAbortedCommit
190 : public LayerTreeHostScrollTest
{
192 LayerTreeHostScrollTestScrollAbortedCommit()
193 : initial_scroll_(50, 60),
195 second_main_scroll_(14, -3),
197 num_will_begin_main_frames_(0),
198 num_did_begin_main_frames_(0),
199 num_will_commits_(0),
201 num_impl_commits_(0),
202 num_impl_scrolls_(0) {}
204 virtual void BeginTest() OVERRIDE
{ PostSetNeedsCommitToMainThread(); }
206 virtual void SetupTree() OVERRIDE
{
207 LayerTreeHostScrollTest::SetupTree();
208 Layer
* root_layer
= layer_tree_host()->root_layer();
209 scoped_refptr
<Layer
> root_scroll_layer
= Layer::Create();
210 root_scroll_layer
->SetScrollClipLayerId(root_layer
->id());
211 root_scroll_layer
->SetScrollOffset(initial_scroll_
);
212 root_scroll_layer
->SetBounds(gfx::Size(200, 200));
213 root_scroll_layer
->SetIsDrawable(true);
214 root_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
215 root_layer
->AddChild(root_scroll_layer
);
217 layer_tree_host()->RegisterViewportLayers(
218 root_layer
, root_scroll_layer
, NULL
);
219 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.01f
, 100.f
);
222 virtual void WillBeginMainFrame() OVERRIDE
{
223 num_will_begin_main_frames_
++;
224 Layer
* root_scroll_layer
=
225 layer_tree_host()->root_layer()->children()[0].get();
226 switch (num_will_begin_main_frames_
) {
228 // This will not be aborted because of the initial prop changes.
229 EXPECT_EQ(0, num_impl_scrolls_
);
230 EXPECT_EQ(0, layer_tree_host()->source_frame_number());
231 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(), initial_scroll_
);
232 EXPECT_EQ(1.f
, layer_tree_host()->page_scale_factor());
235 // This commit will be aborted, and another commit will be
236 // initiated from the redraw.
237 EXPECT_EQ(1, num_impl_scrolls_
);
238 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
239 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(),
240 initial_scroll_
+ impl_scroll_
);
241 EXPECT_EQ(impl_scale_
, layer_tree_host()->page_scale_factor());
242 PostSetNeedsRedrawToMainThread();
245 // This commit will not be aborted because of the scroll change.
246 EXPECT_EQ(2, num_impl_scrolls_
);
247 // The source frame number still increases even with the abort.
248 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
249 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(),
250 initial_scroll_
+ impl_scroll_
+ impl_scroll_
);
251 EXPECT_EQ(impl_scale_
* impl_scale_
,
252 layer_tree_host()->page_scale_factor());
253 root_scroll_layer
->SetScrollOffset(root_scroll_layer
->scroll_offset() +
254 second_main_scroll_
);
257 // This commit will also be aborted.
258 EXPECT_EQ(3, num_impl_scrolls_
);
259 EXPECT_EQ(3, layer_tree_host()->source_frame_number());
260 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(),
261 initial_scroll_
+ impl_scroll_
+ impl_scroll_
+
262 impl_scroll_
+ second_main_scroll_
);
263 // End the test by drawing to verify this commit is also aborted.
264 PostSetNeedsRedrawToMainThread();
269 virtual void DidBeginMainFrame() OVERRIDE
{ num_did_begin_main_frames_
++; }
271 virtual void WillCommit() OVERRIDE
{ num_will_commits_
++; }
273 virtual void DidCommit() OVERRIDE
{ num_did_commits_
++; }
275 virtual void BeginCommitOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
279 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
280 LayerImpl
* root_scroll_layer
=
281 impl
->active_tree()->root_layer()->children()[0];
283 if (impl
->active_tree()->source_frame_number() == 0 &&
284 impl
->SourceAnimationFrameNumber() == 1) {
286 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), gfx::Vector2d());
287 root_scroll_layer
->ScrollBy(impl_scroll_
);
288 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), impl_scroll_
);
289 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(), initial_scroll_
);
291 EXPECT_EQ(1.f
, impl
->active_tree()->page_scale_delta());
292 EXPECT_EQ(1.f
, impl
->active_tree()->total_page_scale_factor());
293 impl
->active_tree()->SetPageScaleDelta(impl_scale_
);
294 EXPECT_EQ(impl_scale_
, impl
->active_tree()->page_scale_delta());
295 EXPECT_EQ(impl_scale_
, impl
->active_tree()->total_page_scale_factor());
297 // To simplify the testing flow, don't redraw here, just commit.
298 impl
->SetNeedsCommit();
299 } else if (impl
->active_tree()->source_frame_number() == 0 &&
300 impl
->SourceAnimationFrameNumber() == 2) {
301 // Test a second draw after an aborted commit.
302 // The scroll/scale values should be baked into the offset/scale factor
303 // since the main thread consumed but aborted the begin frame.
304 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), gfx::Vector2d());
305 root_scroll_layer
->ScrollBy(impl_scroll_
);
306 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), impl_scroll_
);
307 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(),
308 initial_scroll_
+ impl_scroll_
);
310 EXPECT_EQ(1.f
, impl
->active_tree()->page_scale_delta());
311 EXPECT_EQ(impl_scale_
, impl
->active_tree()->total_page_scale_factor());
312 impl
->active_tree()->SetPageScaleDelta(impl_scale_
);
313 EXPECT_EQ(impl_scale_
, impl
->active_tree()->page_scale_delta());
314 EXPECT_EQ(impl_scale_
* impl_scale_
,
315 impl
->active_tree()->total_page_scale_factor());
317 impl
->SetNeedsCommit();
318 } else if (impl
->active_tree()->source_frame_number() == 1) {
319 // Commit for source frame 1 is aborted.
321 } else if (impl
->active_tree()->source_frame_number() == 2 &&
322 impl
->SourceAnimationFrameNumber() == 3) {
323 // Third draw after the second full commit.
324 EXPECT_EQ(root_scroll_layer
->ScrollDelta(), gfx::Vector2d());
325 root_scroll_layer
->ScrollBy(impl_scroll_
);
326 impl
->SetNeedsCommit();
327 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), impl_scroll_
);
329 root_scroll_layer
->scroll_offset(),
330 initial_scroll_
+ impl_scroll_
+ impl_scroll_
+ second_main_scroll_
);
331 } else if (impl
->active_tree()->source_frame_number() == 2 &&
332 impl
->SourceAnimationFrameNumber() == 4) {
333 // Final draw after the second aborted commit.
334 EXPECT_VECTOR_EQ(root_scroll_layer
->ScrollDelta(), gfx::Vector2d());
335 EXPECT_VECTOR_EQ(root_scroll_layer
->scroll_offset(),
336 initial_scroll_
+ impl_scroll_
+ impl_scroll_
+
337 impl_scroll_
+ second_main_scroll_
);
340 // Commit for source frame 3 is aborted.
345 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
346 float scale
) OVERRIDE
{
350 virtual void AfterTest() OVERRIDE
{
351 EXPECT_EQ(3, num_impl_scrolls_
);
352 // Verify that the embedder sees aborted commits as real commits.
353 EXPECT_EQ(4, num_will_begin_main_frames_
);
354 EXPECT_EQ(4, num_did_begin_main_frames_
);
355 EXPECT_EQ(4, num_will_commits_
);
356 EXPECT_EQ(4, num_did_commits_
);
357 // ...but the compositor thread only sees two real ones.
358 EXPECT_EQ(2, num_impl_commits_
);
362 gfx::Vector2d initial_scroll_
;
363 gfx::Vector2d impl_scroll_
;
364 gfx::Vector2d second_main_scroll_
;
366 int num_will_begin_main_frames_
;
367 int num_did_begin_main_frames_
;
368 int num_will_commits_
;
369 int num_did_commits_
;
370 int num_impl_commits_
;
371 int num_impl_scrolls_
;
374 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit
);
376 class LayerTreeHostScrollTestFractionalScroll
: public LayerTreeHostScrollTest
{
378 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
380 virtual void SetupTree() OVERRIDE
{
381 LayerTreeHostScrollTest::SetupTree();
382 Layer
* root_layer
= layer_tree_host()->root_layer();
383 scoped_refptr
<Layer
> root_scroll_layer
= Layer::Create();
384 root_scroll_layer
->SetScrollClipLayerId(root_layer
->id());
385 root_scroll_layer
->SetBounds(
386 gfx::Size(root_layer
->bounds().width() + 100,
387 root_layer
->bounds().height() + 100));
388 root_scroll_layer
->SetIsDrawable(true);
389 root_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
390 root_layer
->AddChild(root_scroll_layer
);
392 layer_tree_host()->RegisterViewportLayers(
393 root_layer
, root_scroll_layer
, NULL
);
394 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.01f
, 100.f
);
397 virtual void BeginTest() OVERRIDE
{
398 PostSetNeedsCommitToMainThread();
401 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
402 LayerImpl
* root
= impl
->active_tree()->root_layer();
403 LayerImpl
* scroll_layer
= root
->children()[0];
405 // Check that a fractional scroll delta is correctly accumulated over
407 switch (impl
->active_tree()->source_frame_number()) {
409 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), gfx::Vector2d(0, 0));
410 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), gfx::Vector2d(0, 0));
411 PostSetNeedsCommitToMainThread();
414 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(),
415 gfx::ToFlooredVector2d(scroll_amount_
));
416 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(),
417 gfx::Vector2dF(fmod(scroll_amount_
.x(), 1.0f
), 0.0f
));
418 PostSetNeedsCommitToMainThread();
422 scroll_layer
->scroll_offset(),
423 gfx::ToFlooredVector2d(scroll_amount_
+ scroll_amount_
));
425 scroll_layer
->ScrollDelta(),
426 gfx::Vector2dF(fmod(2.0f
* scroll_amount_
.x(), 1.0f
), 0.0f
));
430 scroll_layer
->ScrollBy(scroll_amount_
);
433 virtual void AfterTest() OVERRIDE
{}
436 gfx::Vector2dF scroll_amount_
;
439 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll
);
441 class LayerTreeHostScrollTestCaseWithChild
: public LayerTreeHostScrollTest
{
443 LayerTreeHostScrollTestCaseWithChild()
444 : initial_offset_(10, 20),
445 javascript_scroll_(40, 5),
446 scroll_amount_(2, -1),
449 virtual void SetupTree() OVERRIDE
{
450 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_
);
452 scoped_refptr
<Layer
> root_layer
= Layer::Create();
453 root_layer
->SetBounds(gfx::Size(10, 10));
455 root_scroll_layer_
= FakePictureLayer::Create(&fake_content_layer_client_
);
456 root_scroll_layer_
->SetBounds(gfx::Size(110, 110));
458 root_scroll_layer_
->SetPosition(gfx::Point());
460 root_scroll_layer_
->SetIsDrawable(true);
461 root_scroll_layer_
->SetScrollClipLayerId(root_layer
->id());
462 root_scroll_layer_
->SetIsContainerForFixedPositionLayers(true);
463 root_layer
->AddChild(root_scroll_layer_
);
465 child_layer_
= FakePictureLayer::Create(&fake_content_layer_client_
);
466 child_layer_
->set_did_scroll_callback(
467 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll
,
468 base::Unretained(this)));
469 child_layer_
->SetBounds(gfx::Size(110, 110));
471 if (scroll_child_layer_
) {
472 // Scrolls on the child layer will happen at 5, 5. If they are treated
473 // like device pixels, and device scale factor is 2, then they will
474 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer.
475 child_layer_
->SetPosition(gfx::Point(5, 5));
477 // Adjust the child layer horizontally so that scrolls will never hit it.
478 child_layer_
->SetPosition(gfx::Point(60, 5));
481 child_layer_
->SetIsDrawable(true);
482 child_layer_
->SetScrollClipLayerId(root_layer
->id());
483 child_layer_
->SetBounds(root_scroll_layer_
->bounds());
484 root_scroll_layer_
->AddChild(child_layer_
);
486 if (scroll_child_layer_
) {
487 expected_scroll_layer_
= child_layer_
;
488 expected_no_scroll_layer_
= root_scroll_layer_
;
490 expected_scroll_layer_
= root_scroll_layer_
;
491 expected_no_scroll_layer_
= child_layer_
;
494 expected_scroll_layer_
->SetScrollOffset(initial_offset_
);
496 layer_tree_host()->SetRootLayer(root_layer
);
497 layer_tree_host()->RegisterViewportLayers(
498 root_layer
, root_scroll_layer_
, NULL
);
499 LayerTreeHostScrollTest::SetupTree();
502 virtual void BeginTest() OVERRIDE
{ PostSetNeedsCommitToMainThread(); }
504 virtual void WillCommit() OVERRIDE
{
505 // Keep the test committing (otherwise the early out for no update
506 // will stall the test).
507 if (layer_tree_host()->source_frame_number() < 2) {
508 layer_tree_host()->SetNeedsCommit();
513 final_scroll_offset_
= expected_scroll_layer_
->scroll_offset();
516 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
517 float scale
) OVERRIDE
{
521 virtual void Layout() OVERRIDE
{
522 EXPECT_VECTOR_EQ(gfx::Vector2d(),
523 expected_no_scroll_layer_
->scroll_offset());
525 switch (layer_tree_host()->source_frame_number()) {
527 EXPECT_VECTOR_EQ(initial_offset_
,
528 expected_scroll_layer_
->scroll_offset());
531 EXPECT_VECTOR_EQ(initial_offset_
+ scroll_amount_
,
532 expected_scroll_layer_
->scroll_offset());
534 // Pretend like Javascript updated the scroll position itself.
535 expected_scroll_layer_
->SetScrollOffset(javascript_scroll_
);
538 EXPECT_VECTOR_EQ(javascript_scroll_
+ scroll_amount_
,
539 expected_scroll_layer_
->scroll_offset());
544 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
545 LayerImpl
* root_impl
= impl
->active_tree()->root_layer();
546 FakePictureLayerImpl
* root_scroll_layer_impl
=
547 static_cast<FakePictureLayerImpl
*>(root_impl
->children()[0]);
548 FakePictureLayerImpl
* child_layer_impl
= static_cast<FakePictureLayerImpl
*>(
549 root_scroll_layer_impl
->children()[0]);
551 LayerImpl
* expected_scroll_layer_impl
= NULL
;
552 LayerImpl
* expected_no_scroll_layer_impl
= NULL
;
553 if (scroll_child_layer_
) {
554 expected_scroll_layer_impl
= child_layer_impl
;
555 expected_no_scroll_layer_impl
= root_scroll_layer_impl
;
557 expected_scroll_layer_impl
= root_scroll_layer_impl
;
558 expected_no_scroll_layer_impl
= child_layer_impl
;
561 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl
->ScrollDelta());
562 EXPECT_VECTOR_EQ(gfx::Vector2d(),
563 expected_no_scroll_layer_impl
->ScrollDelta());
565 // Ensure device scale factor is affecting the layers.
566 EXPECT_FLOAT_EQ(device_scale_factor_
,
567 root_scroll_layer_impl
->HighResTiling()->contents_scale());
569 EXPECT_FLOAT_EQ(device_scale_factor_
,
570 child_layer_impl
->HighResTiling()->contents_scale());
572 switch (impl
->active_tree()->source_frame_number()) {
574 // Gesture scroll on impl thread.
575 InputHandler::ScrollStatus status
= impl
->ScrollBegin(
576 gfx::ToCeiledPoint(expected_scroll_layer_impl
->position() -
577 gfx::Vector2dF(0.5f
, 0.5f
)),
578 InputHandler::Gesture
);
579 EXPECT_EQ(InputHandler::ScrollStarted
, status
);
580 impl
->ScrollBy(gfx::Point(), scroll_amount_
);
583 // Check the scroll is applied as a delta.
584 EXPECT_VECTOR_EQ(initial_offset_
,
585 expected_scroll_layer_impl
->scroll_offset());
586 EXPECT_VECTOR_EQ(scroll_amount_
,
587 expected_scroll_layer_impl
->ScrollDelta());
591 // Wheel scroll on impl thread.
592 InputHandler::ScrollStatus status
= impl
->ScrollBegin(
593 gfx::ToCeiledPoint(expected_scroll_layer_impl
->position() +
594 gfx::Vector2dF(0.5f
, 0.5f
)),
595 InputHandler::Wheel
);
596 EXPECT_EQ(InputHandler::ScrollStarted
, status
);
597 impl
->ScrollBy(gfx::Point(), scroll_amount_
);
600 // Check the scroll is applied as a delta.
601 EXPECT_VECTOR_EQ(javascript_scroll_
,
602 expected_scroll_layer_impl
->scroll_offset());
603 EXPECT_VECTOR_EQ(scroll_amount_
,
604 expected_scroll_layer_impl
->ScrollDelta());
609 EXPECT_VECTOR_EQ(javascript_scroll_
+ scroll_amount_
,
610 expected_scroll_layer_impl
->scroll_offset());
611 EXPECT_VECTOR_EQ(gfx::Vector2d(),
612 expected_scroll_layer_impl
->ScrollDelta());
619 virtual void AfterTest() OVERRIDE
{
620 if (scroll_child_layer_
) {
621 EXPECT_EQ(0, num_scrolls_
);
622 EXPECT_VECTOR_EQ(javascript_scroll_
+ scroll_amount_
,
623 final_scroll_offset_
);
625 EXPECT_EQ(2, num_scrolls_
);
626 EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_
);
631 float device_scale_factor_
;
632 bool scroll_child_layer_
;
634 gfx::Vector2d initial_offset_
;
635 gfx::Vector2d javascript_scroll_
;
636 gfx::Vector2d scroll_amount_
;
638 gfx::Vector2d final_scroll_offset_
;
640 FakeContentLayerClient fake_content_layer_client_
;
642 scoped_refptr
<Layer
> root_scroll_layer_
;
643 scoped_refptr
<Layer
> child_layer_
;
644 scoped_refptr
<Layer
> expected_scroll_layer_
;
645 scoped_refptr
<Layer
> expected_no_scroll_layer_
;
648 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
649 DeviceScaleFactor1_ScrollChild_DirectRenderer
) {
650 device_scale_factor_
= 1.f
;
651 scroll_child_layer_
= true;
652 RunTest(true, false, true);
655 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
656 DeviceScaleFactor1_ScrollChild_DelegatingRenderer
) {
657 device_scale_factor_
= 1.f
;
658 scroll_child_layer_
= true;
659 RunTest(true, true, true);
662 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
663 DeviceScaleFactor15_ScrollChild_DirectRenderer
) {
664 device_scale_factor_
= 1.5f
;
665 scroll_child_layer_
= true;
666 RunTest(true, false, true);
669 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
670 DeviceScaleFactor15_ScrollChild_DelegatingRenderer
) {
671 device_scale_factor_
= 1.5f
;
672 scroll_child_layer_
= true;
673 RunTest(true, true, true);
676 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
677 DeviceScaleFactor2_ScrollChild_DirectRenderer
) {
678 device_scale_factor_
= 2.f
;
679 scroll_child_layer_
= true;
680 RunTest(true, false, true);
683 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
684 DeviceScaleFactor2_ScrollChild_DelegatingRenderer
) {
685 device_scale_factor_
= 2.f
;
686 scroll_child_layer_
= true;
687 RunTest(true, true, true);
690 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
691 DeviceScaleFactor1_ScrollRootScrollLayer_DirectRenderer
) {
692 device_scale_factor_
= 1.f
;
693 scroll_child_layer_
= false;
694 RunTest(true, false, true);
697 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
698 DeviceScaleFactor1_ScrollRootScrollLayer_DelegatingRenderer
) {
699 device_scale_factor_
= 1.f
;
700 scroll_child_layer_
= false;
701 RunTest(true, true, true);
704 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
705 DeviceScaleFactor15_ScrollRootScrollLayer_DirectRenderer
) {
706 device_scale_factor_
= 1.5f
;
707 scroll_child_layer_
= false;
708 RunTest(true, false, true);
711 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
712 DeviceScaleFactor15_ScrollRootScrollLayer_DelegatingRenderer
) {
713 device_scale_factor_
= 1.5f
;
714 scroll_child_layer_
= false;
715 RunTest(true, true, true);
718 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
719 DeviceScaleFactor2_ScrollRootScrollLayer_DirectRenderer
) {
720 device_scale_factor_
= 2.f
;
721 scroll_child_layer_
= false;
722 RunTest(true, false, true);
725 TEST_F(LayerTreeHostScrollTestCaseWithChild
,
726 DeviceScaleFactor2_ScrollRootScrollLayer_DelegatingRenderer
) {
727 device_scale_factor_
= 2.f
;
728 scroll_child_layer_
= false;
729 RunTest(true, true, true);
732 class ImplSidePaintingScrollTest
: public LayerTreeHostScrollTest
{
734 virtual void InitializeSettings(LayerTreeSettings
* settings
) OVERRIDE
{
735 settings
->impl_side_painting
= true;
738 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
739 if (impl
->pending_tree())
740 impl
->SetNeedsRedraw();
744 class ImplSidePaintingScrollTestSimple
: public ImplSidePaintingScrollTest
{
746 ImplSidePaintingScrollTestSimple()
747 : initial_scroll_(10, 20),
748 main_thread_scroll_(40, 5),
749 impl_thread_scroll1_(2, -1),
750 impl_thread_scroll2_(-3, 10),
753 virtual void SetupTree() OVERRIDE
{
754 LayerTreeHostScrollTest::SetupTree();
755 Layer
* root_layer
= layer_tree_host()->root_layer();
756 scoped_refptr
<Layer
> root_scroll_layer
= Layer::Create();
757 root_scroll_layer
->SetScrollClipLayerId(root_layer
->id());
758 root_scroll_layer
->SetScrollOffset(initial_scroll_
);
759 root_scroll_layer
->SetBounds(
760 gfx::Size(root_layer
->bounds().width() + 100,
761 root_layer
->bounds().height() + 100));
762 root_scroll_layer
->SetIsDrawable(true);
763 root_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
764 root_layer
->AddChild(root_scroll_layer
);
766 layer_tree_host()->RegisterViewportLayers(
767 root_layer
, root_scroll_layer
, NULL
);
768 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.01f
, 100.f
);
771 virtual void BeginTest() OVERRIDE
{
772 PostSetNeedsCommitToMainThread();
775 virtual void Layout() OVERRIDE
{
776 Layer
* root
= layer_tree_host()->root_layer();
777 Layer
* scroll_layer
= root
->children()[0].get();
778 if (!layer_tree_host()->source_frame_number()) {
779 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
781 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(),
782 initial_scroll_
+ impl_thread_scroll1_
);
784 // Pretend like Javascript updated the scroll position itself with a
785 // change of main_thread_scroll.
786 scroll_layer
->SetScrollOffset(initial_scroll_
+ main_thread_scroll_
+
787 impl_thread_scroll1_
);
791 virtual void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
792 // We force a second draw here of the first commit before activating
793 // the second commit.
794 if (impl
->active_tree()->source_frame_number() == 0)
795 impl
->SetNeedsRedraw();
798 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
799 ImplSidePaintingScrollTest::DrawLayersOnThread(impl
);
801 LayerImpl
* root
= impl
->active_tree()->root_layer();
802 LayerImpl
* scroll_layer
= root
->children()[0];
803 LayerImpl
* pending_root
=
804 impl
->active_tree()->FindPendingTreeLayerById(root
->id());
806 switch (impl
->active_tree()->source_frame_number()) {
808 if (!impl
->pending_tree()) {
809 impl
->BlockNotifyReadyToActivateForTesting(true);
810 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), gfx::Vector2d());
811 scroll_layer
->ScrollBy(impl_thread_scroll1_
);
813 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
814 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), impl_thread_scroll1_
);
815 EXPECT_VECTOR_EQ(scroll_layer
->sent_scroll_delta(), gfx::Vector2d());
816 PostSetNeedsCommitToMainThread();
818 // CommitCompleteOnThread will trigger this function again
819 // and cause us to take the else clause.
821 impl
->BlockNotifyReadyToActivateForTesting(false);
822 ASSERT_TRUE(pending_root
);
823 EXPECT_EQ(impl
->pending_tree()->source_frame_number(), 1);
825 scroll_layer
->ScrollBy(impl_thread_scroll2_
);
826 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
827 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(),
828 impl_thread_scroll1_
+ impl_thread_scroll2_
);
829 EXPECT_VECTOR_EQ(scroll_layer
->sent_scroll_delta(),
830 impl_thread_scroll1_
);
832 LayerImpl
* pending_scroll_layer
= pending_root
->children()[0];
834 pending_scroll_layer
->scroll_offset(),
835 initial_scroll_
+ main_thread_scroll_
+ impl_thread_scroll1_
);
836 EXPECT_VECTOR_EQ(pending_scroll_layer
->ScrollDelta(),
837 impl_thread_scroll2_
);
838 EXPECT_VECTOR_EQ(pending_scroll_layer
->sent_scroll_delta(),
843 EXPECT_FALSE(impl
->pending_tree());
845 scroll_layer
->scroll_offset(),
846 initial_scroll_
+ main_thread_scroll_
+ impl_thread_scroll1_
);
847 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), impl_thread_scroll2_
);
848 EXPECT_VECTOR_EQ(scroll_layer
->sent_scroll_delta(), gfx::Vector2d());
854 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
855 float scale
) OVERRIDE
{
859 virtual void AfterTest() OVERRIDE
{ EXPECT_EQ(1, num_scrolls_
); }
862 gfx::Vector2d initial_scroll_
;
863 gfx::Vector2d main_thread_scroll_
;
864 gfx::Vector2d impl_thread_scroll1_
;
865 gfx::Vector2d impl_thread_scroll2_
;
869 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple
);
871 // This test makes sure that layers pick up scrolls that occur between
872 // beginning a commit and finishing a commit (aka scroll deltas not
873 // included in sent scroll delta) still apply to layers that don't
875 class ImplSidePaintingScrollTestImplOnlyScroll
876 : public ImplSidePaintingScrollTest
{
878 ImplSidePaintingScrollTestImplOnlyScroll()
879 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {}
881 virtual void SetupTree() OVERRIDE
{
882 LayerTreeHostScrollTest::SetupTree();
883 Layer
* root_layer
= layer_tree_host()->root_layer();
884 scoped_refptr
<Layer
> root_scroll_layer
= Layer::Create();
885 root_scroll_layer
->SetScrollClipLayerId(root_layer
->id());
886 root_scroll_layer
->SetScrollOffset(initial_scroll_
);
887 root_scroll_layer
->SetBounds(
888 gfx::Size(root_layer
->bounds().width() + 100,
889 root_layer
->bounds().height() + 100));
890 root_scroll_layer
->SetIsDrawable(true);
891 root_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
892 root_layer
->AddChild(root_scroll_layer
);
894 layer_tree_host()->RegisterViewportLayers(
895 root_layer
, root_scroll_layer
, NULL
);
896 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.01f
, 100.f
);
899 virtual void BeginTest() OVERRIDE
{
900 PostSetNeedsCommitToMainThread();
903 virtual void WillCommit() OVERRIDE
{
904 Layer
* root
= layer_tree_host()->root_layer();
905 Layer
* scroll_layer
= root
->children()[0].get();
906 switch (layer_tree_host()->source_frame_number()) {
908 EXPECT_TRUE(scroll_layer
->needs_push_properties());
911 // Even if this layer doesn't need push properties, it should
912 // still pick up scrolls that happen on the active layer during
914 EXPECT_FALSE(scroll_layer
->needs_push_properties());
919 virtual void BeginCommitOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
920 // Scroll after the 2nd commit has started.
921 if (impl
->active_tree()->source_frame_number() == 0) {
922 LayerImpl
* active_root
= impl
->active_tree()->root_layer();
923 LayerImpl
* active_scroll_layer
= active_root
->children()[0];
924 ASSERT_TRUE(active_root
);
925 ASSERT_TRUE(active_scroll_layer
);
926 active_scroll_layer
->ScrollBy(impl_thread_scroll_
);
930 virtual void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
931 // We force a second draw here of the first commit before activating
932 // the second commit.
933 LayerImpl
* active_root
= impl
->active_tree()->root_layer();
934 LayerImpl
* active_scroll_layer
=
935 active_root
? active_root
->children()[0] : NULL
;
936 LayerImpl
* pending_root
= impl
->pending_tree()->root_layer();
937 LayerImpl
* pending_scroll_layer
= pending_root
->children()[0];
939 ASSERT_TRUE(pending_root
);
940 ASSERT_TRUE(pending_scroll_layer
);
941 switch (impl
->pending_tree()->source_frame_number()) {
943 EXPECT_VECTOR_EQ(pending_scroll_layer
->scroll_offset(),
945 EXPECT_VECTOR_EQ(pending_scroll_layer
->ScrollDelta(), gfx::Vector2d());
946 EXPECT_VECTOR_EQ(pending_scroll_layer
->sent_scroll_delta(),
948 EXPECT_FALSE(active_root
);
951 // Even though the scroll happened during the commit, both layers
952 // should have the appropriate scroll delta.
953 EXPECT_VECTOR_EQ(pending_scroll_layer
->scroll_offset(),
955 EXPECT_VECTOR_EQ(pending_scroll_layer
->ScrollDelta(),
956 impl_thread_scroll_
);
957 EXPECT_VECTOR_EQ(pending_scroll_layer
->sent_scroll_delta(),
959 ASSERT_TRUE(active_root
);
960 EXPECT_VECTOR_EQ(active_scroll_layer
->scroll_offset(), initial_scroll_
);
961 EXPECT_VECTOR_EQ(active_scroll_layer
->ScrollDelta(),
962 impl_thread_scroll_
);
963 EXPECT_VECTOR_EQ(active_scroll_layer
->sent_scroll_delta(),
967 // On the next commit, this delta should have been sent and applied.
968 EXPECT_VECTOR_EQ(pending_scroll_layer
->scroll_offset(),
969 initial_scroll_
+ impl_thread_scroll_
);
970 EXPECT_VECTOR_EQ(pending_scroll_layer
->ScrollDelta(), gfx::Vector2d());
971 EXPECT_VECTOR_EQ(pending_scroll_layer
->sent_scroll_delta(),
978 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
979 ImplSidePaintingScrollTest::DrawLayersOnThread(impl
);
981 LayerImpl
* root
= impl
->active_tree()->root_layer();
982 LayerImpl
* scroll_layer
= root
->children()[0];
984 switch (impl
->active_tree()->source_frame_number()) {
986 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
987 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), gfx::Vector2d());
988 EXPECT_VECTOR_EQ(scroll_layer
->sent_scroll_delta(), gfx::Vector2d());
989 PostSetNeedsCommitToMainThread();
992 EXPECT_VECTOR_EQ(scroll_layer
->scroll_offset(), initial_scroll_
);
993 EXPECT_VECTOR_EQ(scroll_layer
->ScrollDelta(), impl_thread_scroll_
);
994 EXPECT_VECTOR_EQ(scroll_layer
->sent_scroll_delta(), gfx::Vector2d());
995 PostSetNeedsCommitToMainThread();
1000 virtual void AfterTest() OVERRIDE
{}
1003 gfx::Vector2d initial_scroll_
;
1004 gfx::Vector2d impl_thread_scroll_
;
1007 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll
);
1009 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
1010 : public LayerTreeHostScrollTest
{
1012 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
1014 virtual void SetupTree() OVERRIDE
{
1015 LayerTreeTest::SetupTree();
1016 scoped_refptr
<Layer
> scroll_layer
= Layer::Create();
1017 layer_tree_host()->root_layer()->AddChild(scroll_layer
);
1020 virtual void BeginTest() OVERRIDE
{ PostSetNeedsCommitToMainThread(); }
1022 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
1023 LayerImpl
* root
= impl
->active_tree()->root_layer();
1024 LayerImpl
* scroll_layer
= root
->children()[0];
1025 scroll_layer
->SetScrollClipLayer(root
->id());
1027 // Set max_scroll_offset = (100, 100).
1028 scroll_layer
->SetBounds(
1029 gfx::Size(root
->bounds().width() + 100, root
->bounds().height() + 100));
1030 EXPECT_EQ(InputHandler::ScrollStarted
,
1031 scroll_layer
->TryScroll(gfx::PointF(0.0f
, 1.0f
),
1032 InputHandler::Gesture
));
1034 // Set max_scroll_offset = (0, 0).
1035 scroll_layer
->SetBounds(root
->bounds());
1036 EXPECT_EQ(InputHandler::ScrollIgnored
,
1037 scroll_layer
->TryScroll(gfx::PointF(0.0f
, 1.0f
),
1038 InputHandler::Gesture
));
1040 // Set max_scroll_offset = (-100, -100).
1041 scroll_layer
->SetBounds(gfx::Size());
1042 EXPECT_EQ(InputHandler::ScrollIgnored
,
1043 scroll_layer
->TryScroll(gfx::PointF(0.0f
, 1.0f
),
1044 InputHandler::Gesture
));
1049 virtual void AfterTest() OVERRIDE
{}
1052 SINGLE_AND_MULTI_THREAD_TEST_F(
1053 LayerTreeHostScrollTestScrollZeroMaxScrollOffset
);
1055 class ThreadCheckingInputHandlerClient
: public InputHandlerClient
{
1057 ThreadCheckingInputHandlerClient(base::SingleThreadTaskRunner
* runner
,
1058 bool* received_stop_flinging
)
1059 : task_runner_(runner
), received_stop_flinging_(received_stop_flinging
) {}
1061 virtual void WillShutdown() OVERRIDE
{
1062 if (!received_stop_flinging_
)
1063 ADD_FAILURE() << "WillShutdown() called before fling stopped";
1066 virtual void Animate(base::TimeTicks time
) OVERRIDE
{
1067 if (!task_runner_
->BelongsToCurrentThread())
1068 ADD_FAILURE() << "Animate called on wrong thread";
1071 virtual void MainThreadHasStoppedFlinging() OVERRIDE
{
1072 if (!task_runner_
->BelongsToCurrentThread())
1073 ADD_FAILURE() << "MainThreadHasStoppedFlinging called on wrong thread";
1074 *received_stop_flinging_
= true;
1077 virtual void DidOverscroll(
1078 const gfx::PointF
& causal_event_viewport_point
,
1079 const gfx::Vector2dF
& accumulated_overscroll
,
1080 const gfx::Vector2dF
& latest_overscroll_delta
) OVERRIDE
{
1081 if (!task_runner_
->BelongsToCurrentThread())
1082 ADD_FAILURE() << "DidOverscroll called on wrong thread";
1086 base::SingleThreadTaskRunner
* task_runner_
;
1087 bool* received_stop_flinging_
;
1090 void BindInputHandlerOnCompositorThread(
1091 const base::WeakPtr
<InputHandler
>& input_handler
,
1092 ThreadCheckingInputHandlerClient
* client
) {
1093 input_handler
->BindToClient(client
);
1096 TEST(LayerTreeHostFlingTest
, DidStopFlingingThread
) {
1097 base::Thread
impl_thread("cc");
1098 ASSERT_TRUE(impl_thread
.Start());
1100 bool received_stop_flinging
= false;
1101 LayerTreeSettings settings
;
1103 ThreadCheckingInputHandlerClient
input_handler_client(
1104 impl_thread
.message_loop_proxy().get(), &received_stop_flinging
);
1105 FakeLayerTreeHostClient
client(FakeLayerTreeHostClient::DIRECT_3D
);
1107 ASSERT_TRUE(impl_thread
.message_loop_proxy().get());
1108 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager(
1109 new TestSharedBitmapManager());
1110 scoped_ptr
<LayerTreeHost
> layer_tree_host
=
1111 LayerTreeHost::CreateThreaded(&client
,
1112 shared_bitmap_manager
.get(),
1114 base::MessageLoopProxy::current(),
1115 impl_thread
.message_loop_proxy());
1117 impl_thread
.message_loop_proxy()
1118 ->PostTask(FROM_HERE
,
1119 base::Bind(&BindInputHandlerOnCompositorThread
,
1120 layer_tree_host
->GetInputHandler(),
1121 base::Unretained(&input_handler_client
)));
1123 layer_tree_host
->DidStopFlinging();
1124 layer_tree_host
.reset();
1126 EXPECT_TRUE(received_stop_flinging
);
1129 class LayerTreeHostScrollTestLayerStructureChange
1130 : public LayerTreeHostScrollTest
{
1132 LayerTreeHostScrollTestLayerStructureChange()
1133 : scroll_destroy_whole_tree_(false) {}
1135 virtual void SetupTree() OVERRIDE
{
1136 scoped_refptr
<Layer
> root_layer
= Layer::Create();
1137 root_layer
->SetBounds(gfx::Size(10, 10));
1139 Layer
* root_scroll_layer
=
1140 CreateScrollLayer(root_layer
.get(), &root_scroll_layer_client_
);
1141 CreateScrollLayer(root_layer
.get(), &sibling_scroll_layer_client_
);
1142 CreateScrollLayer(root_scroll_layer
, &child_scroll_layer_client_
);
1144 layer_tree_host()->SetRootLayer(root_layer
);
1145 LayerTreeHostScrollTest::SetupTree();
1148 virtual void BeginTest() OVERRIDE
{
1149 PostSetNeedsCommitToMainThread();
1152 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
1153 LayerImpl
* root
= impl
->active_tree()->root_layer();
1154 switch (impl
->active_tree()->source_frame_number()) {
1156 root
->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5));
1157 root
->child_at(0)->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5));
1158 root
->child_at(1)->SetScrollDelta(gfx::Vector2dF(5, 5));
1159 PostSetNeedsCommitToMainThread();
1167 virtual void AfterTest() OVERRIDE
{}
1169 virtual void DidScroll(Layer
* layer
) {
1170 if (scroll_destroy_whole_tree_
) {
1171 layer_tree_host()->SetRootLayer(NULL
);
1175 layer
->RemoveFromParent();
1179 class FakeLayerScrollClient
{
1182 owner_
->DidScroll(layer_
);
1184 LayerTreeHostScrollTestLayerStructureChange
* owner_
;
1188 Layer
* CreateScrollLayer(Layer
* parent
, FakeLayerScrollClient
* client
) {
1189 scoped_refptr
<PictureLayer
> scroll_layer
=
1190 PictureLayer::Create(&fake_content_layer_client_
);
1191 scroll_layer
->SetBounds(gfx::Size(110, 110));
1192 scroll_layer
->SetPosition(gfx::Point(0, 0));
1193 scroll_layer
->SetIsDrawable(true);
1194 scroll_layer
->SetScrollClipLayerId(parent
->id());
1195 scroll_layer
->SetBounds(gfx::Size(parent
->bounds().width() + 100,
1196 parent
->bounds().height() + 100));
1197 scroll_layer
->set_did_scroll_callback(base::Bind(
1198 &FakeLayerScrollClient::DidScroll
, base::Unretained(client
)));
1199 client
->owner_
= this;
1200 client
->layer_
= scroll_layer
.get();
1201 parent
->AddChild(scroll_layer
);
1202 return scroll_layer
.get();
1205 FakeLayerScrollClient root_scroll_layer_client_
;
1206 FakeLayerScrollClient sibling_scroll_layer_client_
;
1207 FakeLayerScrollClient child_scroll_layer_client_
;
1209 FakeContentLayerClient fake_content_layer_client_
;
1211 bool scroll_destroy_whole_tree_
;
1214 TEST_F(LayerTreeHostScrollTestLayerStructureChange
, ScrollDestroyLayer
) {
1215 RunTest(true, false, true);
1218 TEST_F(LayerTreeHostScrollTestLayerStructureChange
, ScrollDestroyWholeTree
) {
1219 scroll_destroy_whole_tree_
= true;
1220 RunTest(true, false, true);