Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_readback.cc
blobe8ad466dfa72633c83b7b164a5239bc501ee9ba1
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/content_layer.h"
7 #include "cc/layers/solid_color_layer.h"
8 #include "cc/layers/texture_layer.h"
9 #include "cc/output/copy_output_request.h"
10 #include "cc/output/copy_output_result.h"
11 #include "cc/test/layer_tree_pixel_test.h"
12 #include "cc/test/paths.h"
13 #include "cc/test/solid_color_content_layer_client.h"
14 #include "cc/trees/layer_tree_impl.h"
16 #if !defined(OS_ANDROID)
18 namespace cc {
19 namespace {
21 class LayerTreeHostReadbackPixelTest : public LayerTreePixelTest {
22 protected:
23 LayerTreeHostReadbackPixelTest()
24 : insert_copy_request_after_frame_count_(0) {}
26 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE {
27 scoped_ptr<CopyOutputRequest> request;
29 switch (test_type_) {
30 case GL_WITH_BITMAP:
31 case SOFTWARE_WITH_BITMAP:
32 request = CopyOutputRequest::CreateBitmapRequest(
33 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
34 base::Unretained(this)));
35 break;
36 case SOFTWARE_WITH_DEFAULT:
37 request = CopyOutputRequest::CreateRequest(
38 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
39 base::Unretained(this)));
40 break;
41 case GL_WITH_DEFAULT:
42 request = CopyOutputRequest::CreateRequest(
43 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture,
44 base::Unretained(this)));
45 break;
48 if (!copy_subrect_.IsEmpty())
49 request->set_area(copy_subrect_);
50 return request.Pass();
53 virtual void BeginTest() OVERRIDE {
54 if (insert_copy_request_after_frame_count_ == 0) {
55 Layer* const target =
56 readback_target_ ? readback_target_ : layer_tree_host()->root_layer();
57 target->RequestCopyOfOutput(CreateCopyOutputRequest().Pass());
59 PostSetNeedsCommitToMainThread();
62 virtual void DidCommitAndDrawFrame() OVERRIDE {
63 if (insert_copy_request_after_frame_count_ ==
64 layer_tree_host()->source_frame_number()) {
65 Layer* const target =
66 readback_target_ ? readback_target_ : layer_tree_host()->root_layer();
67 target->RequestCopyOfOutput(CreateCopyOutputRequest().Pass());
71 void ReadbackResultAsBitmap(scoped_ptr<CopyOutputResult> result) {
72 EXPECT_TRUE(proxy()->IsMainThread());
73 EXPECT_TRUE(result->HasBitmap());
74 result_bitmap_ = result->TakeBitmap().Pass();
75 EndTest();
78 void ReadbackResultAsTexture(scoped_ptr<CopyOutputResult> result) {
79 EXPECT_TRUE(proxy()->IsMainThread());
80 EXPECT_TRUE(result->HasTexture());
82 TextureMailbox texture_mailbox;
83 scoped_ptr<SingleReleaseCallback> release_callback;
84 result->TakeTexture(&texture_mailbox, &release_callback);
85 EXPECT_TRUE(texture_mailbox.IsValid());
86 EXPECT_TRUE(texture_mailbox.IsTexture());
88 scoped_ptr<SkBitmap> bitmap =
89 CopyTextureMailboxToBitmap(result->size(), texture_mailbox);
90 release_callback->Run(0, false);
92 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap.Pass()));
95 gfx::Rect copy_subrect_;
96 int insert_copy_request_after_frame_count_;
99 void IgnoreReadbackResult(scoped_ptr<CopyOutputResult> result) {}
101 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software) {
102 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
103 gfx::Rect(200, 200), SK_ColorWHITE);
105 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
106 gfx::Rect(200, 200), SK_ColorGREEN);
107 background->AddChild(green);
109 RunPixelTest(SOFTWARE_WITH_DEFAULT,
110 background,
111 base::FilePath(FILE_PATH_LITERAL(
112 "green.png")));
115 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software_Bitmap) {
116 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
117 gfx::Rect(200, 200), SK_ColorWHITE);
119 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
120 gfx::Rect(200, 200), SK_ColorGREEN);
121 background->AddChild(green);
123 RunPixelTest(SOFTWARE_WITH_BITMAP,
124 background,
125 base::FilePath(FILE_PATH_LITERAL(
126 "green.png")));
129 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL_Bitmap) {
130 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
131 gfx::Rect(200, 200), SK_ColorWHITE);
133 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
134 gfx::Rect(200, 200), SK_ColorGREEN);
135 background->AddChild(green);
137 RunPixelTest(GL_WITH_BITMAP,
138 background,
139 base::FilePath(FILE_PATH_LITERAL(
140 "green.png")));
143 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL) {
144 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
145 gfx::Rect(200, 200), SK_ColorWHITE);
147 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
148 gfx::Rect(200, 200), SK_ColorGREEN);
149 background->AddChild(green);
151 RunPixelTest(GL_WITH_DEFAULT,
152 background,
153 base::FilePath(FILE_PATH_LITERAL(
154 "green.png")));
157 TEST_F(LayerTreeHostReadbackPixelTest,
158 ReadbackRootLayerWithChild_Software) {
159 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
160 gfx::Rect(200, 200), SK_ColorWHITE);
162 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
163 gfx::Rect(200, 200), SK_ColorGREEN);
164 background->AddChild(green);
166 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
167 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
168 green->AddChild(blue);
170 RunPixelTest(SOFTWARE_WITH_DEFAULT,
171 background,
172 base::FilePath(FILE_PATH_LITERAL(
173 "green_with_blue_corner.png")));
176 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL_Bitmap) {
177 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
178 gfx::Rect(200, 200), SK_ColorWHITE);
180 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
181 gfx::Rect(200, 200), SK_ColorGREEN);
182 background->AddChild(green);
184 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
185 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
186 green->AddChild(blue);
188 RunPixelTest(GL_WITH_BITMAP,
189 background,
190 base::FilePath(FILE_PATH_LITERAL(
191 "green_with_blue_corner.png")));
194 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL) {
195 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
196 gfx::Rect(200, 200), SK_ColorWHITE);
198 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
199 gfx::Rect(200, 200), SK_ColorGREEN);
200 background->AddChild(green);
202 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
203 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
204 green->AddChild(blue);
206 RunPixelTest(GL_WITH_DEFAULT,
207 background,
208 base::FilePath(FILE_PATH_LITERAL(
209 "green_with_blue_corner.png")));
212 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_Software) {
213 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
214 gfx::Rect(200, 200), SK_ColorWHITE);
216 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
217 gfx::Rect(200, 200), SK_ColorGREEN);
218 background->AddChild(green);
220 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
221 background,
222 green.get(),
223 base::FilePath(FILE_PATH_LITERAL(
224 "green.png")));
227 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL_Bitmap) {
228 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
229 gfx::Rect(200, 200), SK_ColorWHITE);
231 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
232 gfx::Rect(200, 200), SK_ColorGREEN);
233 background->AddChild(green);
235 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
236 background,
237 green.get(),
238 base::FilePath(FILE_PATH_LITERAL(
239 "green.png")));
242 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL) {
243 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
244 gfx::Rect(200, 200), SK_ColorWHITE);
246 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
247 gfx::Rect(200, 200), SK_ColorGREEN);
248 background->AddChild(green);
250 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
251 background,
252 green.get(),
253 base::FilePath(FILE_PATH_LITERAL(
254 "green.png")));
257 TEST_F(LayerTreeHostReadbackPixelTest,
258 ReadbackSmallNonRootLayer_Software) {
259 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
260 gfx::Rect(200, 200), SK_ColorWHITE);
262 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
263 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
264 background->AddChild(green);
266 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
267 background,
268 green.get(),
269 base::FilePath(FILE_PATH_LITERAL(
270 "green_small.png")));
273 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL_Bitmap) {
274 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
275 gfx::Rect(200, 200), SK_ColorWHITE);
277 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
278 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
279 background->AddChild(green);
281 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
282 background,
283 green.get(),
284 base::FilePath(FILE_PATH_LITERAL(
285 "green_small.png")));
288 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL) {
289 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
290 gfx::Rect(200, 200), SK_ColorWHITE);
292 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
293 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
294 background->AddChild(green);
296 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
297 background,
298 green.get(),
299 base::FilePath(FILE_PATH_LITERAL(
300 "green_small.png")));
303 TEST_F(LayerTreeHostReadbackPixelTest,
304 ReadbackSmallNonRootLayerWithChild_Software) {
305 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
306 gfx::Rect(200, 200), SK_ColorWHITE);
308 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
309 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
310 background->AddChild(green);
312 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
313 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
314 green->AddChild(blue);
316 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
317 background,
318 green.get(),
319 base::FilePath(FILE_PATH_LITERAL(
320 "green_small_with_blue_corner.png")));
323 TEST_F(LayerTreeHostReadbackPixelTest,
324 ReadbackSmallNonRootLayerWithChild_GL_Bitmap) {
325 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
326 gfx::Rect(200, 200), SK_ColorWHITE);
328 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
329 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
330 background->AddChild(green);
332 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
333 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
334 green->AddChild(blue);
336 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
337 background,
338 green.get(),
339 base::FilePath(FILE_PATH_LITERAL(
340 "green_small_with_blue_corner.png")));
343 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayerWithChild_GL) {
344 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
345 gfx::Rect(200, 200), SK_ColorWHITE);
347 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
348 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
349 background->AddChild(green);
351 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
352 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
353 green->AddChild(blue);
355 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
356 background,
357 green.get(),
358 base::FilePath(FILE_PATH_LITERAL(
359 "green_small_with_blue_corner.png")));
362 TEST_F(LayerTreeHostReadbackPixelTest,
363 ReadbackSubtreeSurroundsTargetLayer_Software) {
364 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
365 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
367 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
368 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
369 background->AddChild(target);
371 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
372 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
373 target->AddChild(green);
375 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
376 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
377 target->AddChild(blue);
379 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
380 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
381 background,
382 target.get(),
383 base::FilePath(FILE_PATH_LITERAL(
384 "green_small_with_blue_corner.png")));
387 TEST_F(LayerTreeHostReadbackPixelTest,
388 ReadbackSubtreeSurroundsLayer_GL_Bitmap) {
389 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
390 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
392 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
393 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
394 background->AddChild(target);
396 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
397 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
398 target->AddChild(green);
400 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
401 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
402 target->AddChild(blue);
404 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
405 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
406 background,
407 target.get(),
408 base::FilePath(FILE_PATH_LITERAL(
409 "green_small_with_blue_corner.png")));
412 TEST_F(LayerTreeHostReadbackPixelTest,
413 ReadbackSubtreeSurroundsTargetLayer_GL) {
414 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
415 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
417 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
418 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
419 background->AddChild(target);
421 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
422 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
423 target->AddChild(green);
425 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
426 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
427 target->AddChild(blue);
429 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
430 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
431 background,
432 target.get(),
433 base::FilePath(FILE_PATH_LITERAL(
434 "green_small_with_blue_corner.png")));
437 TEST_F(LayerTreeHostReadbackPixelTest,
438 ReadbackSubtreeExtendsBeyondTargetLayer_Software) {
439 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
440 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
442 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
443 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
444 background->AddChild(target);
446 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
447 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
448 target->AddChild(green);
450 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
451 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
452 target->AddChild(blue);
454 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
455 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
456 background,
457 target.get(),
458 base::FilePath(FILE_PATH_LITERAL(
459 "green_small_with_blue_corner.png")));
462 TEST_F(LayerTreeHostReadbackPixelTest,
463 ReadbackSubtreeExtendsBeyondTargetLayer_GL_Bitmap) {
464 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
465 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
467 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
468 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
469 background->AddChild(target);
471 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
472 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
473 target->AddChild(green);
475 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
476 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
477 target->AddChild(blue);
479 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
480 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
481 background,
482 target.get(),
483 base::FilePath(FILE_PATH_LITERAL(
484 "green_small_with_blue_corner.png")));
487 TEST_F(LayerTreeHostReadbackPixelTest,
488 ReadbackSubtreeExtendsBeyondTargetLayer_GL) {
489 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
490 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
492 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
493 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
494 background->AddChild(target);
496 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
497 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
498 target->AddChild(green);
500 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
501 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
502 target->AddChild(blue);
504 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
505 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
506 background,
507 target.get(),
508 base::FilePath(FILE_PATH_LITERAL(
509 "green_small_with_blue_corner.png")));
512 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackHiddenSubtree_Software) {
513 scoped_refptr<SolidColorLayer> background =
514 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
516 scoped_refptr<SolidColorLayer> hidden_target =
517 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
518 hidden_target->SetHideLayerAndSubtree(true);
519 background->AddChild(hidden_target);
521 scoped_refptr<SolidColorLayer> blue =
522 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
523 hidden_target->AddChild(blue);
525 RunPixelTestWithReadbackTarget(
526 SOFTWARE_WITH_DEFAULT,
527 background,
528 hidden_target.get(),
529 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
532 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackHiddenSubtree_GL_Bitmap) {
533 scoped_refptr<SolidColorLayer> background =
534 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
536 scoped_refptr<SolidColorLayer> hidden_target =
537 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
538 hidden_target->SetHideLayerAndSubtree(true);
539 background->AddChild(hidden_target);
541 scoped_refptr<SolidColorLayer> blue =
542 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
543 hidden_target->AddChild(blue);
545 RunPixelTestWithReadbackTarget(
546 GL_WITH_BITMAP,
547 background,
548 hidden_target.get(),
549 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
552 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackHiddenSubtree_GL) {
553 scoped_refptr<SolidColorLayer> background =
554 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
556 scoped_refptr<SolidColorLayer> hidden_target =
557 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
558 hidden_target->SetHideLayerAndSubtree(true);
559 background->AddChild(hidden_target);
561 scoped_refptr<SolidColorLayer> blue =
562 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
563 hidden_target->AddChild(blue);
565 RunPixelTestWithReadbackTarget(
566 GL_WITH_DEFAULT,
567 background,
568 hidden_target.get(),
569 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")));
572 TEST_F(LayerTreeHostReadbackPixelTest,
573 HiddenSubtreeNotVisibleWhenDrawnForReadback_Software) {
574 scoped_refptr<SolidColorLayer> background =
575 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
577 scoped_refptr<SolidColorLayer> hidden_target =
578 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
579 hidden_target->SetHideLayerAndSubtree(true);
580 background->AddChild(hidden_target);
582 scoped_refptr<SolidColorLayer> blue =
583 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
584 hidden_target->AddChild(blue);
586 hidden_target->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
587 base::Bind(&IgnoreReadbackResult)));
588 RunPixelTest(SOFTWARE_WITH_DEFAULT,
589 background,
590 base::FilePath(FILE_PATH_LITERAL("black.png")));
593 TEST_F(LayerTreeHostReadbackPixelTest,
594 HiddenSubtreeNotVisibleWhenDrawnForReadback_GL_Bitmap) {
595 scoped_refptr<SolidColorLayer> background =
596 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
598 scoped_refptr<SolidColorLayer> hidden_target =
599 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
600 hidden_target->SetHideLayerAndSubtree(true);
601 background->AddChild(hidden_target);
603 scoped_refptr<SolidColorLayer> blue =
604 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
605 hidden_target->AddChild(blue);
607 hidden_target->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
608 base::Bind(&IgnoreReadbackResult)));
609 RunPixelTest(GL_WITH_BITMAP,
610 background,
611 base::FilePath(FILE_PATH_LITERAL("black.png")));
614 TEST_F(LayerTreeHostReadbackPixelTest,
615 HiddenSubtreeNotVisibleWhenDrawnForReadback_GL) {
616 scoped_refptr<SolidColorLayer> background =
617 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
619 scoped_refptr<SolidColorLayer> hidden_target =
620 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
621 hidden_target->SetHideLayerAndSubtree(true);
622 background->AddChild(hidden_target);
624 scoped_refptr<SolidColorLayer> blue =
625 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
626 hidden_target->AddChild(blue);
628 hidden_target->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
629 base::Bind(&IgnoreReadbackResult)));
630 RunPixelTest(GL_WITH_DEFAULT,
631 background,
632 base::FilePath(FILE_PATH_LITERAL("black.png")));
635 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_Software) {
636 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
637 gfx::Rect(200, 200), SK_ColorWHITE);
639 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
640 gfx::Rect(200, 200), SK_ColorGREEN);
641 background->AddChild(green);
643 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
644 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
645 green->AddChild(blue);
647 // Grab the middle of the root layer.
648 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
650 RunPixelTest(SOFTWARE_WITH_DEFAULT,
651 background,
652 base::FilePath(FILE_PATH_LITERAL(
653 "green_small_with_blue_corner.png")));
656 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL_Bitmap) {
657 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
658 gfx::Rect(200, 200), SK_ColorWHITE);
660 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
661 gfx::Rect(200, 200), SK_ColorGREEN);
662 background->AddChild(green);
664 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
665 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
666 green->AddChild(blue);
668 // Grab the middle of the root layer.
669 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
671 RunPixelTest(GL_WITH_BITMAP,
672 background,
673 base::FilePath(FILE_PATH_LITERAL(
674 "green_small_with_blue_corner.png")));
677 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL) {
678 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
679 gfx::Rect(200, 200), SK_ColorWHITE);
681 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
682 gfx::Rect(200, 200), SK_ColorGREEN);
683 background->AddChild(green);
685 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
686 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
687 green->AddChild(blue);
689 // Grab the middle of the root layer.
690 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
692 RunPixelTest(GL_WITH_DEFAULT,
693 background,
694 base::FilePath(FILE_PATH_LITERAL(
695 "green_small_with_blue_corner.png")));
698 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_Software) {
699 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
700 gfx::Rect(200, 200), SK_ColorWHITE);
702 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
703 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
704 background->AddChild(green);
706 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
707 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
708 green->AddChild(blue);
710 // Grab the middle of the green layer.
711 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
713 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
714 background,
715 green.get(),
716 base::FilePath(FILE_PATH_LITERAL(
717 "green_small_with_blue_corner.png")));
720 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL_Bitmap) {
721 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
722 gfx::Rect(200, 200), SK_ColorWHITE);
724 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
725 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
726 background->AddChild(green);
728 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
729 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
730 green->AddChild(blue);
732 // Grab the middle of the green layer.
733 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
735 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
736 background,
737 green.get(),
738 base::FilePath(FILE_PATH_LITERAL(
739 "green_small_with_blue_corner.png")));
742 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL) {
743 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
744 gfx::Rect(200, 200), SK_ColorWHITE);
746 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
747 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
748 background->AddChild(green);
750 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
751 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
752 green->AddChild(blue);
754 // Grab the middle of the green layer.
755 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
757 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
758 background,
759 green.get(),
760 base::FilePath(FILE_PATH_LITERAL(
761 "green_small_with_blue_corner.png")));
764 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackWhenNoDamage_Software) {
765 scoped_refptr<SolidColorLayer> background =
766 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
768 scoped_refptr<SolidColorLayer> parent =
769 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED);
770 background->AddChild(parent);
772 scoped_refptr<SolidColorLayer> target =
773 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN);
774 parent->AddChild(target);
776 scoped_refptr<SolidColorLayer> blue =
777 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
778 target->AddChild(blue);
780 insert_copy_request_after_frame_count_ = 1;
781 RunPixelTestWithReadbackTarget(
782 SOFTWARE_WITH_DEFAULT,
783 background,
784 target.get(),
785 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
788 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackWhenNoDamage_GL_Bitmap) {
789 scoped_refptr<SolidColorLayer> background =
790 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
792 scoped_refptr<SolidColorLayer> parent =
793 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED);
794 background->AddChild(parent);
796 scoped_refptr<SolidColorLayer> target =
797 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN);
798 parent->AddChild(target);
800 scoped_refptr<SolidColorLayer> blue =
801 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
802 target->AddChild(blue);
804 insert_copy_request_after_frame_count_ = 1;
805 RunPixelTestWithReadbackTarget(
806 GL_WITH_BITMAP,
807 background,
808 target.get(),
809 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
812 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackWhenNoDamage_GL) {
813 scoped_refptr<SolidColorLayer> background =
814 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
816 scoped_refptr<SolidColorLayer> parent =
817 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED);
818 background->AddChild(parent);
820 scoped_refptr<SolidColorLayer> target =
821 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN);
822 parent->AddChild(target);
824 scoped_refptr<SolidColorLayer> blue =
825 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
826 target->AddChild(blue);
828 insert_copy_request_after_frame_count_ = 1;
829 RunPixelTestWithReadbackTarget(
830 GL_WITH_DEFAULT,
831 background,
832 target.get(),
833 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
836 TEST_F(LayerTreeHostReadbackPixelTest,
837 ReadbackOutsideViewportWhenNoDamage_Software) {
838 scoped_refptr<SolidColorLayer> background =
839 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
841 scoped_refptr<SolidColorLayer> parent =
842 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED);
843 EXPECT_FALSE(parent->masks_to_bounds());
844 background->AddChild(parent);
846 scoped_refptr<SolidColorLayer> target =
847 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN);
848 parent->AddChild(target);
850 scoped_refptr<SolidColorLayer> blue =
851 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
852 target->AddChild(blue);
854 insert_copy_request_after_frame_count_ = 1;
855 RunPixelTestWithReadbackTarget(
856 SOFTWARE_WITH_DEFAULT,
857 background,
858 target.get(),
859 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
862 TEST_F(LayerTreeHostReadbackPixelTest,
863 ReadbackOutsideViewportWhenNoDamage_GL_Bitmap) {
864 scoped_refptr<SolidColorLayer> background =
865 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
867 scoped_refptr<SolidColorLayer> parent =
868 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED);
869 EXPECT_FALSE(parent->masks_to_bounds());
870 background->AddChild(parent);
872 scoped_refptr<SolidColorLayer> target =
873 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN);
874 parent->AddChild(target);
876 scoped_refptr<SolidColorLayer> blue =
877 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
878 target->AddChild(blue);
880 insert_copy_request_after_frame_count_ = 1;
881 RunPixelTestWithReadbackTarget(
882 GL_WITH_BITMAP,
883 background,
884 target.get(),
885 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
888 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackOutsideViewportWhenNoDamage_GL) {
889 scoped_refptr<SolidColorLayer> background =
890 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
892 scoped_refptr<SolidColorLayer> parent =
893 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED);
894 EXPECT_FALSE(parent->masks_to_bounds());
895 background->AddChild(parent);
897 scoped_refptr<SolidColorLayer> target =
898 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN);
899 parent->AddChild(target);
901 scoped_refptr<SolidColorLayer> blue =
902 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
903 target->AddChild(blue);
905 insert_copy_request_after_frame_count_ = 1;
906 RunPixelTestWithReadbackTarget(
907 GL_WITH_DEFAULT,
908 background,
909 target.get(),
910 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")));
913 class LayerTreeHostReadbackDeviceScalePixelTest
914 : public LayerTreeHostReadbackPixelTest {
915 protected:
916 LayerTreeHostReadbackDeviceScalePixelTest()
917 : device_scale_factor_(1.f),
918 white_client_(SK_ColorWHITE),
919 green_client_(SK_ColorGREEN),
920 blue_client_(SK_ColorBLUE) {}
922 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
923 // Cause the device scale factor to be inherited by contents scales.
924 settings->layer_transforms_should_scale_layer_contents = true;
927 virtual void SetupTree() OVERRIDE {
928 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
929 LayerTreePixelTest::SetupTree();
932 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
933 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
935 LayerImpl* background_impl = root_impl->children()[0];
936 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x());
937 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y());
939 LayerImpl* green_impl = background_impl->children()[0];
940 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x());
941 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y());
943 LayerImpl* blue_impl = green_impl->children()[0];
944 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x());
945 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y());
948 float device_scale_factor_;
949 SolidColorContentLayerClient white_client_;
950 SolidColorContentLayerClient green_client_;
951 SolidColorContentLayerClient blue_client_;
954 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
955 ReadbackSubrect_Software) {
956 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
957 background->SetAnchorPoint(gfx::PointF());
958 background->SetBounds(gfx::Size(100, 100));
959 background->SetIsDrawable(true);
961 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
962 green->SetAnchorPoint(gfx::PointF());
963 green->SetBounds(gfx::Size(100, 100));
964 green->SetIsDrawable(true);
965 background->AddChild(green);
967 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
968 blue->SetAnchorPoint(gfx::PointF());
969 blue->SetPosition(gfx::Point(50, 50));
970 blue->SetBounds(gfx::Size(25, 25));
971 blue->SetIsDrawable(true);
972 green->AddChild(blue);
974 // Grab the middle of the root layer.
975 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
976 device_scale_factor_ = 2.f;
978 this->impl_side_painting_ = false;
979 RunPixelTest(SOFTWARE_WITH_DEFAULT,
980 background,
981 base::FilePath(FILE_PATH_LITERAL(
982 "green_small_with_blue_corner.png")));
985 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
986 ReadbackSubrect_GL) {
987 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
988 background->SetAnchorPoint(gfx::PointF());
989 background->SetBounds(gfx::Size(100, 100));
990 background->SetIsDrawable(true);
992 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
993 green->SetAnchorPoint(gfx::PointF());
994 green->SetBounds(gfx::Size(100, 100));
995 green->SetIsDrawable(true);
996 background->AddChild(green);
998 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
999 blue->SetAnchorPoint(gfx::PointF());
1000 blue->SetPosition(gfx::Point(50, 50));
1001 blue->SetBounds(gfx::Size(25, 25));
1002 blue->SetIsDrawable(true);
1003 green->AddChild(blue);
1005 // Grab the middle of the root layer.
1006 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1007 device_scale_factor_ = 2.f;
1009 this->impl_side_painting_ = false;
1010 RunPixelTest(GL_WITH_DEFAULT,
1011 background,
1012 base::FilePath(FILE_PATH_LITERAL(
1013 "green_small_with_blue_corner.png")));
1016 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
1017 ReadbackNonRootLayerSubrect_Software) {
1018 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1019 background->SetAnchorPoint(gfx::PointF());
1020 background->SetBounds(gfx::Size(100, 100));
1021 background->SetIsDrawable(true);
1023 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1024 green->SetAnchorPoint(gfx::PointF());
1025 green->SetPosition(gfx::Point(10, 20));
1026 green->SetBounds(gfx::Size(90, 80));
1027 green->SetIsDrawable(true);
1028 background->AddChild(green);
1030 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1031 blue->SetAnchorPoint(gfx::PointF());
1032 blue->SetPosition(gfx::Point(50, 50));
1033 blue->SetBounds(gfx::Size(25, 25));
1034 blue->SetIsDrawable(true);
1035 green->AddChild(blue);
1037 // Grab the green layer's content with blue in the bottom right.
1038 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1039 device_scale_factor_ = 2.f;
1041 this->impl_side_painting_ = false;
1042 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
1043 background,
1044 green.get(),
1045 base::FilePath(FILE_PATH_LITERAL(
1046 "green_small_with_blue_corner.png")));
1049 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
1050 ReadbackNonRootLayerSubrect_GL) {
1051 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1052 background->SetAnchorPoint(gfx::PointF());
1053 background->SetBounds(gfx::Size(100, 100));
1054 background->SetIsDrawable(true);
1056 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1057 green->SetAnchorPoint(gfx::PointF());
1058 green->SetPosition(gfx::Point(10, 20));
1059 green->SetBounds(gfx::Size(90, 80));
1060 green->SetIsDrawable(true);
1061 background->AddChild(green);
1063 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1064 blue->SetAnchorPoint(gfx::PointF());
1065 blue->SetPosition(gfx::Point(50, 50));
1066 blue->SetBounds(gfx::Size(25, 25));
1067 blue->SetIsDrawable(true);
1068 green->AddChild(blue);
1070 // Grab the green layer's content with blue in the bottom right.
1071 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1072 device_scale_factor_ = 2.f;
1074 this->impl_side_painting_ = false;
1075 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1076 background,
1077 green.get(),
1078 base::FilePath(FILE_PATH_LITERAL(
1079 "green_small_with_blue_corner.png")));
1082 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest
1083 : public LayerTreePixelTest {
1084 protected:
1085 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest()
1086 : device_scale_factor_(1.f),
1087 white_client_(SK_ColorWHITE),
1088 green_client_(SK_ColorGREEN),
1089 blue_client_(SK_ColorBLUE) {}
1091 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1092 // Cause the device scale factor to be inherited by contents scales.
1093 settings->layer_transforms_should_scale_layer_contents = true;
1096 virtual void SetupTree() OVERRIDE {
1097 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
1098 LayerTreePixelTest::SetupTree();
1101 virtual void BeginTest() OVERRIDE {
1102 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor());
1103 if (TestEnded())
1104 return;
1106 gfx::Rect device_viewport_copy_rect(
1107 layer_tree_host()->device_viewport_size());
1108 if (!device_viewport_copy_subrect_.IsEmpty())
1109 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_);
1111 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1112 bitmap->allocN32Pixels(device_viewport_copy_rect.width(),
1113 device_viewport_copy_rect.height());
1114 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(),
1115 device_viewport_copy_rect);
1117 result_bitmap_ = bitmap.Pass();
1118 EndTest();
1121 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1122 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
1124 LayerImpl* background_impl = root_impl->children()[0];
1125 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x());
1126 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y());
1128 LayerImpl* green_impl = background_impl->children()[0];
1129 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x());
1130 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y());
1132 LayerImpl* blue_impl = green_impl->children()[0];
1133 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x());
1134 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y());
1137 gfx::Rect device_viewport_copy_subrect_;
1138 float device_scale_factor_;
1139 SolidColorContentLayerClient white_client_;
1140 SolidColorContentLayerClient green_client_;
1141 SolidColorContentLayerClient blue_client_;
1144 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
1145 CompositeAndReadback_Software_1) {
1146 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1147 background->SetAnchorPoint(gfx::PointF());
1148 background->SetBounds(gfx::Size(200, 200));
1149 background->SetIsDrawable(true);
1151 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1152 green->SetAnchorPoint(gfx::PointF());
1153 green->SetBounds(gfx::Size(200, 200));
1154 green->SetIsDrawable(true);
1155 background->AddChild(green);
1157 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1158 blue->SetAnchorPoint(gfx::PointF());
1159 blue->SetPosition(gfx::Point(100, 100));
1160 blue->SetBounds(gfx::Size(50, 50));
1161 blue->SetIsDrawable(true);
1162 green->AddChild(blue);
1164 // Grab the middle of the device viewport.
1165 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
1166 device_scale_factor_ = 1.f;
1168 this->impl_side_painting_ = false;
1169 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
1170 background,
1171 green.get(),
1172 base::FilePath(FILE_PATH_LITERAL(
1173 "green_small_with_blue_corner.png")));
1176 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
1177 CompositeAndReadback_Software_2) {
1178 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1179 background->SetAnchorPoint(gfx::PointF());
1180 background->SetBounds(gfx::Size(100, 100));
1181 background->SetIsDrawable(true);
1183 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1184 green->SetAnchorPoint(gfx::PointF());
1185 green->SetBounds(gfx::Size(100, 100));
1186 green->SetIsDrawable(true);
1187 background->AddChild(green);
1189 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1190 blue->SetAnchorPoint(gfx::PointF());
1191 blue->SetPosition(gfx::Point(50, 50));
1192 blue->SetBounds(gfx::Size(25, 25));
1193 blue->SetIsDrawable(true);
1194 green->AddChild(blue);
1196 // Grab the middle of the device viewport.
1197 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
1198 device_scale_factor_ = 2.f;
1200 this->impl_side_painting_ = false;
1201 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
1202 background,
1203 green.get(),
1204 base::FilePath(FILE_PATH_LITERAL(
1205 "green_small_with_blue_corner.png")));
1208 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
1209 CompositeAndReadback_GL_1) {
1210 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1211 background->SetAnchorPoint(gfx::PointF());
1212 background->SetBounds(gfx::Size(200, 200));
1213 background->SetIsDrawable(true);
1215 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1216 green->SetAnchorPoint(gfx::PointF());
1217 green->SetBounds(gfx::Size(200, 200));
1218 green->SetIsDrawable(true);
1219 background->AddChild(green);
1221 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1222 blue->SetAnchorPoint(gfx::PointF());
1223 blue->SetPosition(gfx::Point(100, 100));
1224 blue->SetBounds(gfx::Size(50, 50));
1225 blue->SetIsDrawable(true);
1226 green->AddChild(blue);
1228 // Grab the middle of the device viewport.
1229 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
1230 device_scale_factor_ = 1.f;
1232 this->impl_side_painting_ = false;
1233 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1234 background,
1235 green.get(),
1236 base::FilePath(FILE_PATH_LITERAL(
1237 "green_small_with_blue_corner.png")));
1240 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
1241 CompositeAndReadback_GL_2) {
1242 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1243 background->SetAnchorPoint(gfx::PointF());
1244 background->SetBounds(gfx::Size(100, 100));
1245 background->SetIsDrawable(true);
1247 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1248 green->SetAnchorPoint(gfx::PointF());
1249 green->SetBounds(gfx::Size(100, 100));
1250 green->SetIsDrawable(true);
1251 background->AddChild(green);
1253 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1254 blue->SetAnchorPoint(gfx::PointF());
1255 blue->SetPosition(gfx::Point(50, 50));
1256 blue->SetBounds(gfx::Size(25, 25));
1257 blue->SetIsDrawable(true);
1258 green->AddChild(blue);
1260 // Grab the middle of the device viewport.
1261 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
1262 device_scale_factor_ = 2.f;
1264 this->impl_side_painting_ = false;
1265 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1266 background,
1267 green.get(),
1268 base::FilePath(FILE_PATH_LITERAL(
1269 "green_small_with_blue_corner.png")));
1272 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) {
1273 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
1274 gfx::Rect(200, 200), SK_ColorWHITE);
1276 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
1277 gfx::Rect(200, 200), SK_ColorGREEN);
1278 // Only the top left quarter of the layer is inside the viewport, so the
1279 // blue layer is entirely outside.
1280 green->SetPosition(gfx::Point(100, 100));
1281 background->AddChild(green);
1283 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
1284 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
1285 green->AddChild(blue);
1287 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1288 background,
1289 green.get(),
1290 base::FilePath(FILE_PATH_LITERAL(
1291 "green_with_blue_corner.png")));
1294 } // namespace
1295 } // namespace cc
1297 #endif // OS_ANDROID