1 // Copyright 2013 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 "build/build_config.h"
6 #include "cc/layers/solid_color_layer.h"
7 #include "cc/layers/texture_layer.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h"
10 #include "cc/test/fake_picture_layer.h"
11 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/layer_tree_pixel_test.h"
13 #include "cc/test/paths.h"
14 #include "cc/test/solid_color_content_layer_client.h"
15 #include "cc/trees/layer_tree_impl.h"
17 #if !defined(OS_ANDROID)
22 class LayerTreeHostReadbackPixelTest
: public LayerTreePixelTest
{
24 LayerTreeHostReadbackPixelTest()
25 : readback_type_(READBACK_INVALID
),
26 insert_copy_request_after_frame_count_(0) {}
34 void RunReadbackTest(PixelTestType test_type
,
35 ReadbackType readback_type
,
36 scoped_refptr
<Layer
> content_root
,
37 base::FilePath file_name
) {
38 readback_type_
= readback_type
;
39 RunPixelTest(test_type
, content_root
, file_name
);
42 void RunReadbackTestWithReadbackTarget(PixelTestType type
,
43 ReadbackType readback_type
,
44 scoped_refptr
<Layer
> content_root
,
46 base::FilePath file_name
) {
47 readback_type_
= readback_type
;
48 RunPixelTestWithReadbackTarget(type
, content_root
, target
, file_name
);
51 scoped_ptr
<CopyOutputRequest
> CreateCopyOutputRequest() override
{
52 scoped_ptr
<CopyOutputRequest
> request
;
54 if (readback_type_
== READBACK_BITMAP
) {
55 request
= CopyOutputRequest::CreateBitmapRequest(
56 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap
,
57 base::Unretained(this)));
59 DCHECK_EQ(readback_type_
, READBACK_DEFAULT
);
60 if (test_type_
== PIXEL_TEST_SOFTWARE
) {
61 request
= CopyOutputRequest::CreateRequest(
62 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap
,
63 base::Unretained(this)));
65 DCHECK_EQ(test_type_
, PIXEL_TEST_GL
);
66 request
= CopyOutputRequest::CreateRequest(
67 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture
,
68 base::Unretained(this)));
72 if (!copy_subrect_
.IsEmpty())
73 request
->set_area(copy_subrect_
);
74 return request
.Pass();
77 void BeginTest() override
{
78 if (insert_copy_request_after_frame_count_
== 0) {
80 readback_target_
? readback_target_
: layer_tree_host()->root_layer();
81 target
->RequestCopyOfOutput(CreateCopyOutputRequest().Pass());
83 PostSetNeedsCommitToMainThread();
86 void DidCommitAndDrawFrame() override
{
87 if (insert_copy_request_after_frame_count_
==
88 layer_tree_host()->source_frame_number()) {
90 readback_target_
? readback_target_
: layer_tree_host()->root_layer();
91 target
->RequestCopyOfOutput(CreateCopyOutputRequest().Pass());
95 void ReadbackResultAsBitmap(scoped_ptr
<CopyOutputResult
> result
) {
96 EXPECT_TRUE(proxy()->IsMainThread());
97 EXPECT_TRUE(result
->HasBitmap());
98 result_bitmap_
= result
->TakeBitmap().Pass();
102 void ReadbackResultAsTexture(scoped_ptr
<CopyOutputResult
> result
) {
103 EXPECT_TRUE(proxy()->IsMainThread());
104 EXPECT_TRUE(result
->HasTexture());
106 TextureMailbox texture_mailbox
;
107 scoped_ptr
<SingleReleaseCallback
> release_callback
;
108 result
->TakeTexture(&texture_mailbox
, &release_callback
);
109 EXPECT_TRUE(texture_mailbox
.IsValid());
110 EXPECT_TRUE(texture_mailbox
.IsTexture());
112 scoped_ptr
<SkBitmap
> bitmap
=
113 CopyTextureMailboxToBitmap(result
->size(), texture_mailbox
);
114 release_callback
->Run(0, false);
116 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap
.Pass()));
119 ReadbackType readback_type_
;
120 gfx::Rect copy_subrect_
;
121 int insert_copy_request_after_frame_count_
;
124 void IgnoreReadbackResult(scoped_ptr
<CopyOutputResult
> result
) {
127 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayer_Software
) {
128 scoped_refptr
<SolidColorLayer
> background
=
129 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
131 scoped_refptr
<SolidColorLayer
> green
=
132 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
133 background
->AddChild(green
);
135 RunReadbackTest(PIXEL_TEST_SOFTWARE
,
138 base::FilePath(FILE_PATH_LITERAL("green.png")));
141 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayer_Software_Bitmap
) {
142 scoped_refptr
<SolidColorLayer
> background
=
143 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
145 scoped_refptr
<SolidColorLayer
> green
=
146 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
147 background
->AddChild(green
);
149 RunReadbackTest(PIXEL_TEST_SOFTWARE
,
152 base::FilePath(FILE_PATH_LITERAL("green.png")));
155 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayer_GL_Bitmap
) {
156 scoped_refptr
<SolidColorLayer
> background
=
157 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
159 scoped_refptr
<SolidColorLayer
> green
=
160 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
161 background
->AddChild(green
);
163 RunReadbackTest(PIXEL_TEST_GL
,
166 base::FilePath(FILE_PATH_LITERAL("green.png")));
169 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayer_GL
) {
170 scoped_refptr
<SolidColorLayer
> background
=
171 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
173 scoped_refptr
<SolidColorLayer
> green
=
174 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
175 background
->AddChild(green
);
177 RunReadbackTest(PIXEL_TEST_GL
,
180 base::FilePath(FILE_PATH_LITERAL("green.png")));
183 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayerWithChild_Software
) {
184 scoped_refptr
<SolidColorLayer
> background
=
185 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
187 scoped_refptr
<SolidColorLayer
> green
=
188 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
189 background
->AddChild(green
);
191 scoped_refptr
<SolidColorLayer
> blue
=
192 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
193 green
->AddChild(blue
);
199 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
202 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayerWithChild_GL_Bitmap
) {
203 scoped_refptr
<SolidColorLayer
> background
=
204 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
206 scoped_refptr
<SolidColorLayer
> green
=
207 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
208 background
->AddChild(green
);
210 scoped_refptr
<SolidColorLayer
> blue
=
211 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
212 green
->AddChild(blue
);
218 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
221 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackRootLayerWithChild_GL
) {
222 scoped_refptr
<SolidColorLayer
> background
=
223 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
225 scoped_refptr
<SolidColorLayer
> green
=
226 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
227 background
->AddChild(green
);
229 scoped_refptr
<SolidColorLayer
> blue
=
230 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
231 green
->AddChild(blue
);
237 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
240 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayer_Software
) {
241 scoped_refptr
<SolidColorLayer
> background
=
242 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
244 scoped_refptr
<SolidColorLayer
> green
=
245 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
246 background
->AddChild(green
);
248 RunReadbackTestWithReadbackTarget(
253 base::FilePath(FILE_PATH_LITERAL("green.png")));
256 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayer_GL_Bitmap
) {
257 scoped_refptr
<SolidColorLayer
> background
=
258 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
260 scoped_refptr
<SolidColorLayer
> green
=
261 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
262 background
->AddChild(green
);
264 RunReadbackTestWithReadbackTarget(
269 base::FilePath(FILE_PATH_LITERAL("green.png")));
272 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayer_GL
) {
273 scoped_refptr
<SolidColorLayer
> background
=
274 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
276 scoped_refptr
<SolidColorLayer
> green
=
277 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
278 background
->AddChild(green
);
280 RunReadbackTestWithReadbackTarget(
285 base::FilePath(FILE_PATH_LITERAL("green.png")));
288 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSmallNonRootLayer_Software
) {
289 scoped_refptr
<SolidColorLayer
> background
=
290 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
292 scoped_refptr
<SolidColorLayer
> green
=
293 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
294 background
->AddChild(green
);
296 RunReadbackTestWithReadbackTarget(
301 base::FilePath(FILE_PATH_LITERAL("green_small.png")));
304 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSmallNonRootLayer_GL_Bitmap
) {
305 scoped_refptr
<SolidColorLayer
> background
=
306 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
308 scoped_refptr
<SolidColorLayer
> green
=
309 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
310 background
->AddChild(green
);
312 RunReadbackTestWithReadbackTarget(
317 base::FilePath(FILE_PATH_LITERAL("green_small.png")));
320 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSmallNonRootLayer_GL
) {
321 scoped_refptr
<SolidColorLayer
> background
=
322 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
324 scoped_refptr
<SolidColorLayer
> green
=
325 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
326 background
->AddChild(green
);
328 RunReadbackTestWithReadbackTarget(
333 base::FilePath(FILE_PATH_LITERAL("green_small.png")));
336 TEST_F(LayerTreeHostReadbackPixelTest
,
337 ReadbackSmallNonRootLayerWithChild_Software
) {
338 scoped_refptr
<SolidColorLayer
> background
=
339 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
341 scoped_refptr
<SolidColorLayer
> green
=
342 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
343 background
->AddChild(green
);
345 scoped_refptr
<SolidColorLayer
> blue
=
346 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
347 green
->AddChild(blue
);
349 RunReadbackTestWithReadbackTarget(
354 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
357 TEST_F(LayerTreeHostReadbackPixelTest
,
358 ReadbackSmallNonRootLayerWithChild_GL_Bitmap
) {
359 scoped_refptr
<SolidColorLayer
> background
=
360 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
362 scoped_refptr
<SolidColorLayer
> green
=
363 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
364 background
->AddChild(green
);
366 scoped_refptr
<SolidColorLayer
> blue
=
367 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
368 green
->AddChild(blue
);
370 RunReadbackTestWithReadbackTarget(
375 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
378 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSmallNonRootLayerWithChild_GL
) {
379 scoped_refptr
<SolidColorLayer
> background
=
380 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
382 scoped_refptr
<SolidColorLayer
> green
=
383 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN
);
384 background
->AddChild(green
);
386 scoped_refptr
<SolidColorLayer
> blue
=
387 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
388 green
->AddChild(blue
);
390 RunReadbackTestWithReadbackTarget(
395 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
398 TEST_F(LayerTreeHostReadbackPixelTest
,
399 ReadbackSubtreeSurroundsTargetLayer_Software
) {
400 scoped_refptr
<SolidColorLayer
> background
=
401 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
403 scoped_refptr
<SolidColorLayer
> target
=
404 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorRED
);
405 background
->AddChild(target
);
407 scoped_refptr
<SolidColorLayer
> green
=
408 CreateSolidColorLayer(gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN
);
409 target
->AddChild(green
);
411 scoped_refptr
<SolidColorLayer
> blue
=
412 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
413 target
->AddChild(blue
);
415 copy_subrect_
= gfx::Rect(0, 0, 100, 100);
416 RunReadbackTestWithReadbackTarget(
421 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
424 TEST_F(LayerTreeHostReadbackPixelTest
,
425 ReadbackSubtreeSurroundsLayer_GL_Bitmap
) {
426 scoped_refptr
<SolidColorLayer
> background
=
427 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
429 scoped_refptr
<SolidColorLayer
> target
=
430 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorRED
);
431 background
->AddChild(target
);
433 scoped_refptr
<SolidColorLayer
> green
=
434 CreateSolidColorLayer(gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN
);
435 target
->AddChild(green
);
437 scoped_refptr
<SolidColorLayer
> blue
=
438 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
439 target
->AddChild(blue
);
441 copy_subrect_
= gfx::Rect(0, 0, 100, 100);
442 RunReadbackTestWithReadbackTarget(
447 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
450 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSubtreeSurroundsTargetLayer_GL
) {
451 scoped_refptr
<SolidColorLayer
> background
=
452 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
454 scoped_refptr
<SolidColorLayer
> target
=
455 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorRED
);
456 background
->AddChild(target
);
458 scoped_refptr
<SolidColorLayer
> green
=
459 CreateSolidColorLayer(gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN
);
460 target
->AddChild(green
);
462 scoped_refptr
<SolidColorLayer
> blue
=
463 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
464 target
->AddChild(blue
);
466 copy_subrect_
= gfx::Rect(0, 0, 100, 100);
467 RunReadbackTestWithReadbackTarget(
472 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
475 TEST_F(LayerTreeHostReadbackPixelTest
,
476 ReadbackSubtreeExtendsBeyondTargetLayer_Software
) {
477 scoped_refptr
<SolidColorLayer
> background
=
478 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
480 scoped_refptr
<SolidColorLayer
> target
=
481 CreateSolidColorLayer(gfx::Rect(50, 50, 150, 150), SK_ColorRED
);
482 background
->AddChild(target
);
484 scoped_refptr
<SolidColorLayer
> green
=
485 CreateSolidColorLayer(gfx::Rect(50, 50, 200, 200), SK_ColorGREEN
);
486 target
->AddChild(green
);
488 scoped_refptr
<SolidColorLayer
> blue
=
489 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
490 target
->AddChild(blue
);
492 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
493 RunReadbackTestWithReadbackTarget(
498 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
501 TEST_F(LayerTreeHostReadbackPixelTest
,
502 ReadbackSubtreeExtendsBeyondTargetLayer_GL_Bitmap
) {
503 scoped_refptr
<SolidColorLayer
> background
=
504 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
506 scoped_refptr
<SolidColorLayer
> target
=
507 CreateSolidColorLayer(gfx::Rect(50, 50, 150, 150), SK_ColorRED
);
508 background
->AddChild(target
);
510 scoped_refptr
<SolidColorLayer
> green
=
511 CreateSolidColorLayer(gfx::Rect(50, 50, 200, 200), SK_ColorGREEN
);
512 target
->AddChild(green
);
514 scoped_refptr
<SolidColorLayer
> blue
=
515 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
516 target
->AddChild(blue
);
518 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
519 RunReadbackTestWithReadbackTarget(
524 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
527 TEST_F(LayerTreeHostReadbackPixelTest
,
528 ReadbackSubtreeExtendsBeyondTargetLayer_GL
) {
529 scoped_refptr
<SolidColorLayer
> background
=
530 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
532 scoped_refptr
<SolidColorLayer
> target
=
533 CreateSolidColorLayer(gfx::Rect(50, 50, 150, 150), SK_ColorRED
);
534 background
->AddChild(target
);
536 scoped_refptr
<SolidColorLayer
> green
=
537 CreateSolidColorLayer(gfx::Rect(50, 50, 200, 200), SK_ColorGREEN
);
538 target
->AddChild(green
);
540 scoped_refptr
<SolidColorLayer
> blue
=
541 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
542 target
->AddChild(blue
);
544 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
545 RunReadbackTestWithReadbackTarget(
550 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
553 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackHiddenSubtree_Software
) {
554 scoped_refptr
<SolidColorLayer
> background
=
555 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
557 scoped_refptr
<SolidColorLayer
> hidden_target
=
558 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
559 hidden_target
->SetHideLayerAndSubtree(true);
560 background
->AddChild(hidden_target
);
562 scoped_refptr
<SolidColorLayer
> blue
=
563 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
564 hidden_target
->AddChild(blue
);
566 RunReadbackTestWithReadbackTarget(
571 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
574 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackHiddenSubtree_GL_Bitmap
) {
575 scoped_refptr
<SolidColorLayer
> background
=
576 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
578 scoped_refptr
<SolidColorLayer
> hidden_target
=
579 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
580 hidden_target
->SetHideLayerAndSubtree(true);
581 background
->AddChild(hidden_target
);
583 scoped_refptr
<SolidColorLayer
> blue
=
584 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
585 hidden_target
->AddChild(blue
);
587 RunReadbackTestWithReadbackTarget(
592 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
595 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackHiddenSubtree_GL
) {
596 scoped_refptr
<SolidColorLayer
> background
=
597 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
599 scoped_refptr
<SolidColorLayer
> hidden_target
=
600 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
601 hidden_target
->SetHideLayerAndSubtree(true);
602 background
->AddChild(hidden_target
);
604 scoped_refptr
<SolidColorLayer
> blue
=
605 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
606 hidden_target
->AddChild(blue
);
608 RunReadbackTestWithReadbackTarget(
613 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
616 TEST_F(LayerTreeHostReadbackPixelTest
,
617 HiddenSubtreeNotVisibleWhenDrawnForReadback_Software
) {
618 scoped_refptr
<SolidColorLayer
> background
=
619 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
621 scoped_refptr
<SolidColorLayer
> hidden_target
=
622 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
623 hidden_target
->SetHideLayerAndSubtree(true);
624 background
->AddChild(hidden_target
);
626 scoped_refptr
<SolidColorLayer
> blue
=
627 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
628 hidden_target
->AddChild(blue
);
630 hidden_target
->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
631 base::Bind(&IgnoreReadbackResult
)));
632 RunReadbackTest(PIXEL_TEST_SOFTWARE
,
635 base::FilePath(FILE_PATH_LITERAL("black.png")));
638 TEST_F(LayerTreeHostReadbackPixelTest
,
639 HiddenSubtreeNotVisibleWhenDrawnForReadback_GL_Bitmap
) {
640 scoped_refptr
<SolidColorLayer
> background
=
641 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
643 scoped_refptr
<SolidColorLayer
> hidden_target
=
644 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
645 hidden_target
->SetHideLayerAndSubtree(true);
646 background
->AddChild(hidden_target
);
648 scoped_refptr
<SolidColorLayer
> blue
=
649 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
650 hidden_target
->AddChild(blue
);
652 hidden_target
->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
653 base::Bind(&IgnoreReadbackResult
)));
654 RunReadbackTest(PIXEL_TEST_GL
,
657 base::FilePath(FILE_PATH_LITERAL("black.png")));
660 TEST_F(LayerTreeHostReadbackPixelTest
,
661 HiddenSubtreeNotVisibleWhenDrawnForReadback_GL
) {
662 scoped_refptr
<SolidColorLayer
> background
=
663 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK
);
665 scoped_refptr
<SolidColorLayer
> hidden_target
=
666 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
667 hidden_target
->SetHideLayerAndSubtree(true);
668 background
->AddChild(hidden_target
);
670 scoped_refptr
<SolidColorLayer
> blue
=
671 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
672 hidden_target
->AddChild(blue
);
674 hidden_target
->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
675 base::Bind(&IgnoreReadbackResult
)));
676 RunReadbackTest(PIXEL_TEST_GL
,
679 base::FilePath(FILE_PATH_LITERAL("black.png")));
682 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSubrect_Software
) {
683 scoped_refptr
<SolidColorLayer
> background
=
684 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
686 scoped_refptr
<SolidColorLayer
> green
=
687 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
688 background
->AddChild(green
);
690 scoped_refptr
<SolidColorLayer
> blue
=
691 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
692 green
->AddChild(blue
);
694 // Grab the middle of the root layer.
695 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
701 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
704 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSubrect_GL_Bitmap
) {
705 scoped_refptr
<SolidColorLayer
> background
=
706 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
708 scoped_refptr
<SolidColorLayer
> green
=
709 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
710 background
->AddChild(green
);
712 scoped_refptr
<SolidColorLayer
> blue
=
713 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
714 green
->AddChild(blue
);
716 // Grab the middle of the root layer.
717 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
723 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
726 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackSubrect_GL
) {
727 scoped_refptr
<SolidColorLayer
> background
=
728 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
730 scoped_refptr
<SolidColorLayer
> green
=
731 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
732 background
->AddChild(green
);
734 scoped_refptr
<SolidColorLayer
> blue
=
735 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE
);
736 green
->AddChild(blue
);
738 // Grab the middle of the root layer.
739 copy_subrect_
= gfx::Rect(50, 50, 100, 100);
745 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
748 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayerSubrect_Software
) {
749 scoped_refptr
<SolidColorLayer
> background
=
750 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
752 scoped_refptr
<SolidColorLayer
> green
=
753 CreateSolidColorLayer(gfx::Rect(25, 25, 150, 150), SK_ColorGREEN
);
754 background
->AddChild(green
);
756 scoped_refptr
<SolidColorLayer
> blue
=
757 CreateSolidColorLayer(gfx::Rect(75, 75, 50, 50), SK_ColorBLUE
);
758 green
->AddChild(blue
);
760 // Grab the middle of the green layer.
761 copy_subrect_
= gfx::Rect(25, 25, 100, 100);
763 RunReadbackTestWithReadbackTarget(
768 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
771 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayerSubrect_GL_Bitmap
) {
772 scoped_refptr
<SolidColorLayer
> background
=
773 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
775 scoped_refptr
<SolidColorLayer
> green
=
776 CreateSolidColorLayer(gfx::Rect(25, 25, 150, 150), SK_ColorGREEN
);
777 background
->AddChild(green
);
779 scoped_refptr
<SolidColorLayer
> blue
=
780 CreateSolidColorLayer(gfx::Rect(75, 75, 50, 50), SK_ColorBLUE
);
781 green
->AddChild(blue
);
783 // Grab the middle of the green layer.
784 copy_subrect_
= gfx::Rect(25, 25, 100, 100);
786 RunReadbackTestWithReadbackTarget(
791 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
794 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayerSubrect_GL
) {
795 scoped_refptr
<SolidColorLayer
> background
=
796 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
798 scoped_refptr
<SolidColorLayer
> green
=
799 CreateSolidColorLayer(gfx::Rect(25, 25, 150, 150), SK_ColorGREEN
);
800 background
->AddChild(green
);
802 scoped_refptr
<SolidColorLayer
> blue
=
803 CreateSolidColorLayer(gfx::Rect(75, 75, 50, 50), SK_ColorBLUE
);
804 green
->AddChild(blue
);
806 // Grab the middle of the green layer.
807 copy_subrect_
= gfx::Rect(25, 25, 100, 100);
809 RunReadbackTestWithReadbackTarget(
814 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
817 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackWhenNoDamage_Software
) {
818 scoped_refptr
<SolidColorLayer
> background
=
819 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
821 scoped_refptr
<SolidColorLayer
> parent
=
822 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED
);
823 background
->AddChild(parent
);
825 scoped_refptr
<SolidColorLayer
> target
=
826 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN
);
827 parent
->AddChild(target
);
829 scoped_refptr
<SolidColorLayer
> blue
=
830 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
831 target
->AddChild(blue
);
833 insert_copy_request_after_frame_count_
= 1;
834 RunReadbackTestWithReadbackTarget(
839 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
842 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackWhenNoDamage_GL_Bitmap
) {
843 scoped_refptr
<SolidColorLayer
> background
=
844 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
846 scoped_refptr
<SolidColorLayer
> parent
=
847 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED
);
848 background
->AddChild(parent
);
850 scoped_refptr
<SolidColorLayer
> target
=
851 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN
);
852 parent
->AddChild(target
);
854 scoped_refptr
<SolidColorLayer
> blue
=
855 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
856 target
->AddChild(blue
);
858 insert_copy_request_after_frame_count_
= 1;
859 RunReadbackTestWithReadbackTarget(
864 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
867 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackWhenNoDamage_GL
) {
868 scoped_refptr
<SolidColorLayer
> background
=
869 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
871 scoped_refptr
<SolidColorLayer
> parent
=
872 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED
);
873 background
->AddChild(parent
);
875 scoped_refptr
<SolidColorLayer
> target
=
876 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN
);
877 parent
->AddChild(target
);
879 scoped_refptr
<SolidColorLayer
> blue
=
880 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
881 target
->AddChild(blue
);
883 insert_copy_request_after_frame_count_
= 1;
884 RunReadbackTestWithReadbackTarget(
889 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
892 TEST_F(LayerTreeHostReadbackPixelTest
,
893 ReadbackOutsideViewportWhenNoDamage_Software
) {
894 scoped_refptr
<SolidColorLayer
> background
=
895 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
897 scoped_refptr
<SolidColorLayer
> parent
=
898 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED
);
899 EXPECT_FALSE(parent
->masks_to_bounds());
900 background
->AddChild(parent
);
902 scoped_refptr
<SolidColorLayer
> target
=
903 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN
);
904 parent
->AddChild(target
);
906 scoped_refptr
<SolidColorLayer
> blue
=
907 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
908 target
->AddChild(blue
);
910 insert_copy_request_after_frame_count_
= 1;
911 RunReadbackTestWithReadbackTarget(
916 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
919 TEST_F(LayerTreeHostReadbackPixelTest
,
920 ReadbackOutsideViewportWhenNoDamage_GL_Bitmap
) {
921 scoped_refptr
<SolidColorLayer
> background
=
922 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
924 scoped_refptr
<SolidColorLayer
> parent
=
925 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED
);
926 EXPECT_FALSE(parent
->masks_to_bounds());
927 background
->AddChild(parent
);
929 scoped_refptr
<SolidColorLayer
> target
=
930 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN
);
931 parent
->AddChild(target
);
933 scoped_refptr
<SolidColorLayer
> blue
=
934 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
935 target
->AddChild(blue
);
937 insert_copy_request_after_frame_count_
= 1;
938 RunReadbackTestWithReadbackTarget(
943 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
946 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackOutsideViewportWhenNoDamage_GL
) {
947 scoped_refptr
<SolidColorLayer
> background
=
948 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE
);
950 scoped_refptr
<SolidColorLayer
> parent
=
951 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED
);
952 EXPECT_FALSE(parent
->masks_to_bounds());
953 background
->AddChild(parent
);
955 scoped_refptr
<SolidColorLayer
> target
=
956 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN
);
957 parent
->AddChild(target
);
959 scoped_refptr
<SolidColorLayer
> blue
=
960 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE
);
961 target
->AddChild(blue
);
963 insert_copy_request_after_frame_count_
= 1;
964 RunReadbackTestWithReadbackTarget(
969 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
972 class LayerTreeHostReadbackDeviceScalePixelTest
973 : public LayerTreeHostReadbackPixelTest
{
975 LayerTreeHostReadbackDeviceScalePixelTest()
976 : device_scale_factor_(1.f
),
977 white_client_(SK_ColorWHITE
),
978 green_client_(SK_ColorGREEN
),
979 blue_client_(SK_ColorBLUE
) {}
981 void InitializeSettings(LayerTreeSettings
* settings
) override
{
982 // Cause the device scale factor to be inherited by contents scales.
983 settings
->layer_transforms_should_scale_layer_contents
= true;
986 void SetupTree() override
{
987 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_
);
988 LayerTreePixelTest::SetupTree();
991 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
992 EXPECT_EQ(device_scale_factor_
,
993 host_impl
->active_tree()->device_scale_factor());
996 float device_scale_factor_
;
997 SolidColorContentLayerClient white_client_
;
998 SolidColorContentLayerClient green_client_
;
999 SolidColorContentLayerClient blue_client_
;
1002 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest
, ReadbackSubrect_Software
) {
1003 scoped_refptr
<FakePictureLayer
> background
=
1004 FakePictureLayer::Create(&white_client_
);
1005 background
->SetBounds(gfx::Size(100, 100));
1006 background
->SetIsDrawable(true);
1008 scoped_refptr
<FakePictureLayer
> green
=
1009 FakePictureLayer::Create(&green_client_
);
1010 green
->SetBounds(gfx::Size(100, 100));
1011 green
->SetIsDrawable(true);
1012 background
->AddChild(green
);
1014 scoped_refptr
<FakePictureLayer
> blue
=
1015 FakePictureLayer::Create(&blue_client_
);
1016 blue
->SetPosition(gfx::Point(50, 50));
1017 blue
->SetBounds(gfx::Size(25, 25));
1018 blue
->SetIsDrawable(true);
1019 green
->AddChild(blue
);
1021 // Grab the middle of the root layer.
1022 copy_subrect_
= gfx::Rect(25, 25, 50, 50);
1023 device_scale_factor_
= 2.f
;
1025 PIXEL_TEST_SOFTWARE
,
1028 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
1031 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest
, ReadbackSubrect_GL
) {
1032 scoped_refptr
<FakePictureLayer
> background
=
1033 FakePictureLayer::Create(&white_client_
);
1034 background
->SetBounds(gfx::Size(100, 100));
1035 background
->SetIsDrawable(true);
1037 scoped_refptr
<FakePictureLayer
> green
=
1038 FakePictureLayer::Create(&green_client_
);
1039 green
->SetBounds(gfx::Size(100, 100));
1040 green
->SetIsDrawable(true);
1041 background
->AddChild(green
);
1043 scoped_refptr
<FakePictureLayer
> blue
=
1044 FakePictureLayer::Create(&blue_client_
);
1045 blue
->SetPosition(gfx::Point(50, 50));
1046 blue
->SetBounds(gfx::Size(25, 25));
1047 blue
->SetIsDrawable(true);
1048 green
->AddChild(blue
);
1050 // Grab the middle of the root layer.
1051 copy_subrect_
= gfx::Rect(25, 25, 50, 50);
1052 device_scale_factor_
= 2.f
;
1057 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
1060 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest
,
1061 ReadbackNonRootLayerSubrect_Software
) {
1062 scoped_refptr
<FakePictureLayer
> background
=
1063 FakePictureLayer::Create(&white_client_
);
1064 background
->SetBounds(gfx::Size(100, 100));
1065 background
->SetIsDrawable(true);
1067 scoped_refptr
<FakePictureLayer
> green
=
1068 FakePictureLayer::Create(&green_client_
);
1069 green
->SetPosition(gfx::Point(10, 20));
1070 green
->SetBounds(gfx::Size(90, 80));
1071 green
->SetIsDrawable(true);
1072 background
->AddChild(green
);
1074 scoped_refptr
<FakePictureLayer
> blue
=
1075 FakePictureLayer::Create(&blue_client_
);
1076 blue
->SetPosition(gfx::Point(50, 50));
1077 blue
->SetBounds(gfx::Size(25, 25));
1078 blue
->SetIsDrawable(true);
1079 green
->AddChild(blue
);
1081 // Grab the green layer's content with blue in the bottom right.
1082 copy_subrect_
= gfx::Rect(25, 25, 50, 50);
1083 device_scale_factor_
= 2.f
;
1084 RunReadbackTestWithReadbackTarget(
1085 PIXEL_TEST_SOFTWARE
,
1089 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
1092 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest
,
1093 ReadbackNonRootLayerSubrect_GL
) {
1094 scoped_refptr
<FakePictureLayer
> background
=
1095 FakePictureLayer::Create(&white_client_
);
1096 background
->SetBounds(gfx::Size(100, 100));
1097 background
->SetIsDrawable(true);
1099 scoped_refptr
<FakePictureLayer
> green
=
1100 FakePictureLayer::Create(&green_client_
);
1101 green
->SetPosition(gfx::Point(10, 20));
1102 green
->SetBounds(gfx::Size(90, 80));
1103 green
->SetIsDrawable(true);
1104 background
->AddChild(green
);
1106 scoped_refptr
<FakePictureLayer
> blue
=
1107 FakePictureLayer::Create(&blue_client_
);
1108 blue
->SetPosition(gfx::Point(50, 50));
1109 blue
->SetBounds(gfx::Size(25, 25));
1110 blue
->SetIsDrawable(true);
1111 green
->AddChild(blue
);
1113 // Grab the green layer's content with blue in the bottom right.
1114 copy_subrect_
= gfx::Rect(25, 25, 50, 50);
1115 device_scale_factor_
= 2.f
;
1116 RunReadbackTestWithReadbackTarget(
1121 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
1124 TEST_F(LayerTreeHostReadbackPixelTest
, ReadbackNonRootLayerOutsideViewport
) {
1125 scoped_refptr
<SolidColorLayer
> background
=
1126 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE
);
1128 scoped_refptr
<SolidColorLayer
> green
=
1129 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN
);
1130 // Only the top left quarter of the layer is inside the viewport, so the
1131 // blue layer is entirely outside.
1132 green
->SetPosition(gfx::Point(100, 100));
1133 background
->AddChild(green
);
1135 scoped_refptr
<SolidColorLayer
> blue
=
1136 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE
);
1137 green
->AddChild(blue
);
1139 RunReadbackTestWithReadbackTarget(
1144 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
1150 #endif // OS_ANDROID