Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_readback.cc
blobe5bfcd245995d54cc19df95416d4175f2a63eedb
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 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE {
24 scoped_ptr<CopyOutputRequest> request;
26 switch (test_type_) {
27 case GL_WITH_BITMAP:
28 case SOFTWARE_WITH_BITMAP:
29 request = CopyOutputRequest::CreateBitmapRequest(
30 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
31 base::Unretained(this)));
32 break;
33 case SOFTWARE_WITH_DEFAULT:
34 request = CopyOutputRequest::CreateRequest(
35 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
36 base::Unretained(this)));
37 break;
38 case GL_WITH_DEFAULT:
39 request = CopyOutputRequest::CreateRequest(
40 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture,
41 base::Unretained(this)));
42 break;
45 if (!copy_subrect_.IsEmpty())
46 request->set_area(copy_subrect_);
47 return request.Pass();
50 void ReadbackResultAsBitmap(scoped_ptr<CopyOutputResult> result) {
51 EXPECT_TRUE(proxy()->IsMainThread());
52 EXPECT_TRUE(result->HasBitmap());
53 result_bitmap_ = result->TakeBitmap().Pass();
54 EndTest();
57 void ReadbackResultAsTexture(scoped_ptr<CopyOutputResult> result) {
58 EXPECT_TRUE(proxy()->IsMainThread());
59 EXPECT_TRUE(result->HasTexture());
61 TextureMailbox texture_mailbox;
62 scoped_ptr<SingleReleaseCallback> release_callback;
63 result->TakeTexture(&texture_mailbox, &release_callback);
64 EXPECT_TRUE(texture_mailbox.IsValid());
65 EXPECT_TRUE(texture_mailbox.IsTexture());
67 scoped_ptr<SkBitmap> bitmap =
68 CopyTextureMailboxToBitmap(result->size(), texture_mailbox);
69 release_callback->Run(0, false);
71 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap.Pass()));
74 gfx::Rect copy_subrect_;
77 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software) {
78 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
79 gfx::Rect(200, 200), SK_ColorWHITE);
81 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
82 gfx::Rect(200, 200), SK_ColorGREEN);
83 background->AddChild(green);
85 RunPixelTest(SOFTWARE_WITH_DEFAULT,
86 background,
87 base::FilePath(FILE_PATH_LITERAL(
88 "green.png")));
91 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software_Bitmap) {
92 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
93 gfx::Rect(200, 200), SK_ColorWHITE);
95 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
96 gfx::Rect(200, 200), SK_ColorGREEN);
97 background->AddChild(green);
99 RunPixelTest(SOFTWARE_WITH_BITMAP,
100 background,
101 base::FilePath(FILE_PATH_LITERAL(
102 "green.png")));
105 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL_Bitmap) {
106 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
107 gfx::Rect(200, 200), SK_ColorWHITE);
109 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
110 gfx::Rect(200, 200), SK_ColorGREEN);
111 background->AddChild(green);
113 RunPixelTest(GL_WITH_BITMAP,
114 background,
115 base::FilePath(FILE_PATH_LITERAL(
116 "green.png")));
119 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL) {
120 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
121 gfx::Rect(200, 200), SK_ColorWHITE);
123 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
124 gfx::Rect(200, 200), SK_ColorGREEN);
125 background->AddChild(green);
127 RunPixelTest(GL_WITH_DEFAULT,
128 background,
129 base::FilePath(FILE_PATH_LITERAL(
130 "green.png")));
133 TEST_F(LayerTreeHostReadbackPixelTest,
134 ReadbackRootLayerWithChild_Software) {
135 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
136 gfx::Rect(200, 200), SK_ColorWHITE);
138 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
139 gfx::Rect(200, 200), SK_ColorGREEN);
140 background->AddChild(green);
142 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
143 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
144 green->AddChild(blue);
146 RunPixelTest(SOFTWARE_WITH_DEFAULT,
147 background,
148 base::FilePath(FILE_PATH_LITERAL(
149 "green_with_blue_corner.png")));
152 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL_Bitmap) {
153 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
154 gfx::Rect(200, 200), SK_ColorWHITE);
156 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
157 gfx::Rect(200, 200), SK_ColorGREEN);
158 background->AddChild(green);
160 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
161 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
162 green->AddChild(blue);
164 RunPixelTest(GL_WITH_BITMAP,
165 background,
166 base::FilePath(FILE_PATH_LITERAL(
167 "green_with_blue_corner.png")));
170 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL) {
171 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
172 gfx::Rect(200, 200), SK_ColorWHITE);
174 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
175 gfx::Rect(200, 200), SK_ColorGREEN);
176 background->AddChild(green);
178 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
179 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
180 green->AddChild(blue);
182 RunPixelTest(GL_WITH_DEFAULT,
183 background,
184 base::FilePath(FILE_PATH_LITERAL(
185 "green_with_blue_corner.png")));
188 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_Software) {
189 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
190 gfx::Rect(200, 200), SK_ColorWHITE);
192 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
193 gfx::Rect(200, 200), SK_ColorGREEN);
194 background->AddChild(green);
196 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
197 background,
198 green.get(),
199 base::FilePath(FILE_PATH_LITERAL(
200 "green.png")));
203 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL_Bitmap) {
204 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
205 gfx::Rect(200, 200), SK_ColorWHITE);
207 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
208 gfx::Rect(200, 200), SK_ColorGREEN);
209 background->AddChild(green);
211 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
212 background,
213 green.get(),
214 base::FilePath(FILE_PATH_LITERAL(
215 "green.png")));
218 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL) {
219 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
220 gfx::Rect(200, 200), SK_ColorWHITE);
222 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
223 gfx::Rect(200, 200), SK_ColorGREEN);
224 background->AddChild(green);
226 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
227 background,
228 green.get(),
229 base::FilePath(FILE_PATH_LITERAL(
230 "green.png")));
233 TEST_F(LayerTreeHostReadbackPixelTest,
234 ReadbackSmallNonRootLayer_Software) {
235 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
236 gfx::Rect(200, 200), SK_ColorWHITE);
238 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
239 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
240 background->AddChild(green);
242 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
243 background,
244 green.get(),
245 base::FilePath(FILE_PATH_LITERAL(
246 "green_small.png")));
249 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL_Bitmap) {
250 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
251 gfx::Rect(200, 200), SK_ColorWHITE);
253 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
254 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
255 background->AddChild(green);
257 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
258 background,
259 green.get(),
260 base::FilePath(FILE_PATH_LITERAL(
261 "green_small.png")));
264 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL) {
265 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
266 gfx::Rect(200, 200), SK_ColorWHITE);
268 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
269 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
270 background->AddChild(green);
272 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
273 background,
274 green.get(),
275 base::FilePath(FILE_PATH_LITERAL(
276 "green_small.png")));
279 TEST_F(LayerTreeHostReadbackPixelTest,
280 ReadbackSmallNonRootLayerWithChild_Software) {
281 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
282 gfx::Rect(200, 200), SK_ColorWHITE);
284 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
285 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
286 background->AddChild(green);
288 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
289 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
290 green->AddChild(blue);
292 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
293 background,
294 green.get(),
295 base::FilePath(FILE_PATH_LITERAL(
296 "green_small_with_blue_corner.png")));
299 TEST_F(LayerTreeHostReadbackPixelTest,
300 ReadbackSmallNonRootLayerWithChild_GL_Bitmap) {
301 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
302 gfx::Rect(200, 200), SK_ColorWHITE);
304 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
305 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
306 background->AddChild(green);
308 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
309 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
310 green->AddChild(blue);
312 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
313 background,
314 green.get(),
315 base::FilePath(FILE_PATH_LITERAL(
316 "green_small_with_blue_corner.png")));
319 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayerWithChild_GL) {
320 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
321 gfx::Rect(200, 200), SK_ColorWHITE);
323 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
324 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN);
325 background->AddChild(green);
327 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
328 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
329 green->AddChild(blue);
331 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
332 background,
333 green.get(),
334 base::FilePath(FILE_PATH_LITERAL(
335 "green_small_with_blue_corner.png")));
338 TEST_F(LayerTreeHostReadbackPixelTest,
339 ReadbackSubtreeSurroundsTargetLayer_Software) {
340 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
341 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
343 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
344 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
345 background->AddChild(target);
347 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
348 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
349 target->AddChild(green);
351 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
352 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
353 target->AddChild(blue);
355 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
356 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
357 background,
358 target.get(),
359 base::FilePath(FILE_PATH_LITERAL(
360 "green_small_with_blue_corner.png")));
363 TEST_F(LayerTreeHostReadbackPixelTest,
364 ReadbackSubtreeSurroundsLayer_GL_Bitmap) {
365 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
366 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
368 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
369 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
370 background->AddChild(target);
372 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
373 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
374 target->AddChild(green);
376 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
377 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
378 target->AddChild(blue);
380 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
381 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
382 background,
383 target.get(),
384 base::FilePath(FILE_PATH_LITERAL(
385 "green_small_with_blue_corner.png")));
388 TEST_F(LayerTreeHostReadbackPixelTest,
389 ReadbackSubtreeSurroundsTargetLayer_GL) {
390 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
391 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
393 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
394 gfx::Rect(100, 100, 100, 100), SK_ColorRED);
395 background->AddChild(target);
397 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
398 gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN);
399 target->AddChild(green);
401 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
402 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE);
403 target->AddChild(blue);
405 copy_subrect_ = gfx::Rect(0, 0, 100, 100);
406 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
407 background,
408 target.get(),
409 base::FilePath(FILE_PATH_LITERAL(
410 "green_small_with_blue_corner.png")));
413 TEST_F(LayerTreeHostReadbackPixelTest,
414 ReadbackSubtreeExtendsBeyondTargetLayer_Software) {
415 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
416 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
418 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
419 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
420 background->AddChild(target);
422 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
423 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
424 target->AddChild(green);
426 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
427 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
428 target->AddChild(blue);
430 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
431 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
432 background,
433 target.get(),
434 base::FilePath(FILE_PATH_LITERAL(
435 "green_small_with_blue_corner.png")));
438 TEST_F(LayerTreeHostReadbackPixelTest,
439 ReadbackSubtreeExtendsBeyondTargetLayer_GL_Bitmap) {
440 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
441 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
443 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
444 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
445 background->AddChild(target);
447 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
448 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
449 target->AddChild(green);
451 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
452 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
453 target->AddChild(blue);
455 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
456 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
457 background,
458 target.get(),
459 base::FilePath(FILE_PATH_LITERAL(
460 "green_small_with_blue_corner.png")));
463 TEST_F(LayerTreeHostReadbackPixelTest,
464 ReadbackSubtreeExtendsBeyondTargetLayer_GL) {
465 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
466 gfx::Rect(0, 0, 200, 200), SK_ColorWHITE);
468 scoped_refptr<SolidColorLayer> target = CreateSolidColorLayer(
469 gfx::Rect(50, 50, 150, 150), SK_ColorRED);
470 background->AddChild(target);
472 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
473 gfx::Rect(50, 50, 200, 200), SK_ColorGREEN);
474 target->AddChild(green);
476 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
477 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
478 target->AddChild(blue);
480 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
481 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
482 background,
483 target.get(),
484 base::FilePath(FILE_PATH_LITERAL(
485 "green_small_with_blue_corner.png")));
488 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_Software) {
489 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
490 gfx::Rect(200, 200), SK_ColorWHITE);
492 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
493 gfx::Rect(200, 200), SK_ColorGREEN);
494 background->AddChild(green);
496 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
497 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
498 green->AddChild(blue);
500 // Grab the middle of the root layer.
501 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
503 RunPixelTest(SOFTWARE_WITH_DEFAULT,
504 background,
505 base::FilePath(FILE_PATH_LITERAL(
506 "green_small_with_blue_corner.png")));
509 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL_Bitmap) {
510 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
511 gfx::Rect(200, 200), SK_ColorWHITE);
513 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
514 gfx::Rect(200, 200), SK_ColorGREEN);
515 background->AddChild(green);
517 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
518 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
519 green->AddChild(blue);
521 // Grab the middle of the root layer.
522 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
524 RunPixelTest(GL_WITH_BITMAP,
525 background,
526 base::FilePath(FILE_PATH_LITERAL(
527 "green_small_with_blue_corner.png")));
530 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL) {
531 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
532 gfx::Rect(200, 200), SK_ColorWHITE);
534 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
535 gfx::Rect(200, 200), SK_ColorGREEN);
536 background->AddChild(green);
538 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
539 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE);
540 green->AddChild(blue);
542 // Grab the middle of the root layer.
543 copy_subrect_ = gfx::Rect(50, 50, 100, 100);
545 RunPixelTest(GL_WITH_DEFAULT,
546 background,
547 base::FilePath(FILE_PATH_LITERAL(
548 "green_small_with_blue_corner.png")));
551 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_Software) {
552 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
553 gfx::Rect(200, 200), SK_ColorWHITE);
555 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
556 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
557 background->AddChild(green);
559 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
560 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
561 green->AddChild(blue);
563 // Grab the middle of the green layer.
564 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
566 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
567 background,
568 green.get(),
569 base::FilePath(FILE_PATH_LITERAL(
570 "green_small_with_blue_corner.png")));
573 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL_Bitmap) {
574 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
575 gfx::Rect(200, 200), SK_ColorWHITE);
577 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
578 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
579 background->AddChild(green);
581 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
582 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
583 green->AddChild(blue);
585 // Grab the middle of the green layer.
586 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
588 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP,
589 background,
590 green.get(),
591 base::FilePath(FILE_PATH_LITERAL(
592 "green_small_with_blue_corner.png")));
595 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL) {
596 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
597 gfx::Rect(200, 200), SK_ColorWHITE);
599 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
600 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN);
601 background->AddChild(green);
603 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
604 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE);
605 green->AddChild(blue);
607 // Grab the middle of the green layer.
608 copy_subrect_ = gfx::Rect(25, 25, 100, 100);
610 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
611 background,
612 green.get(),
613 base::FilePath(FILE_PATH_LITERAL(
614 "green_small_with_blue_corner.png")));
617 class LayerTreeHostReadbackDeviceScalePixelTest
618 : public LayerTreeHostReadbackPixelTest {
619 protected:
620 LayerTreeHostReadbackDeviceScalePixelTest()
621 : device_scale_factor_(1.f),
622 white_client_(SK_ColorWHITE),
623 green_client_(SK_ColorGREEN),
624 blue_client_(SK_ColorBLUE) {}
626 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
627 // Cause the device scale factor to be inherited by contents scales.
628 settings->layer_transforms_should_scale_layer_contents = true;
631 virtual void SetupTree() OVERRIDE {
632 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
633 LayerTreePixelTest::SetupTree();
636 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
637 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
639 LayerImpl* background_impl = root_impl->children()[0];
640 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x());
641 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y());
643 LayerImpl* green_impl = background_impl->children()[0];
644 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x());
645 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y());
647 LayerImpl* blue_impl = green_impl->children()[0];
648 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x());
649 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y());
652 float device_scale_factor_;
653 SolidColorContentLayerClient white_client_;
654 SolidColorContentLayerClient green_client_;
655 SolidColorContentLayerClient blue_client_;
658 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
659 ReadbackSubrect_Software) {
660 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
661 background->SetAnchorPoint(gfx::PointF());
662 background->SetBounds(gfx::Size(100, 100));
663 background->SetIsDrawable(true);
665 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
666 green->SetAnchorPoint(gfx::PointF());
667 green->SetBounds(gfx::Size(100, 100));
668 green->SetIsDrawable(true);
669 background->AddChild(green);
671 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
672 blue->SetAnchorPoint(gfx::PointF());
673 blue->SetPosition(gfx::Point(50, 50));
674 blue->SetBounds(gfx::Size(25, 25));
675 blue->SetIsDrawable(true);
676 green->AddChild(blue);
678 // Grab the middle of the root layer.
679 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
680 device_scale_factor_ = 2.f;
682 this->impl_side_painting_ = false;
683 RunPixelTest(SOFTWARE_WITH_DEFAULT,
684 background,
685 base::FilePath(FILE_PATH_LITERAL(
686 "green_small_with_blue_corner.png")));
689 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
690 ReadbackSubrect_GL) {
691 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
692 background->SetAnchorPoint(gfx::PointF());
693 background->SetBounds(gfx::Size(100, 100));
694 background->SetIsDrawable(true);
696 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
697 green->SetAnchorPoint(gfx::PointF());
698 green->SetBounds(gfx::Size(100, 100));
699 green->SetIsDrawable(true);
700 background->AddChild(green);
702 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
703 blue->SetAnchorPoint(gfx::PointF());
704 blue->SetPosition(gfx::Point(50, 50));
705 blue->SetBounds(gfx::Size(25, 25));
706 blue->SetIsDrawable(true);
707 green->AddChild(blue);
709 // Grab the middle of the root layer.
710 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
711 device_scale_factor_ = 2.f;
713 this->impl_side_painting_ = false;
714 RunPixelTest(GL_WITH_DEFAULT,
715 background,
716 base::FilePath(FILE_PATH_LITERAL(
717 "green_small_with_blue_corner.png")));
720 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
721 ReadbackNonRootLayerSubrect_Software) {
722 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
723 background->SetAnchorPoint(gfx::PointF());
724 background->SetBounds(gfx::Size(100, 100));
725 background->SetIsDrawable(true);
727 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
728 green->SetAnchorPoint(gfx::PointF());
729 green->SetPosition(gfx::Point(10, 20));
730 green->SetBounds(gfx::Size(90, 80));
731 green->SetIsDrawable(true);
732 background->AddChild(green);
734 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
735 blue->SetAnchorPoint(gfx::PointF());
736 blue->SetPosition(gfx::Point(50, 50));
737 blue->SetBounds(gfx::Size(25, 25));
738 blue->SetIsDrawable(true);
739 green->AddChild(blue);
741 // Grab the green layer's content with blue in the bottom right.
742 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
743 device_scale_factor_ = 2.f;
745 this->impl_side_painting_ = false;
746 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
747 background,
748 green.get(),
749 base::FilePath(FILE_PATH_LITERAL(
750 "green_small_with_blue_corner.png")));
753 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
754 ReadbackNonRootLayerSubrect_GL) {
755 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
756 background->SetAnchorPoint(gfx::PointF());
757 background->SetBounds(gfx::Size(100, 100));
758 background->SetIsDrawable(true);
760 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
761 green->SetAnchorPoint(gfx::PointF());
762 green->SetPosition(gfx::Point(10, 20));
763 green->SetBounds(gfx::Size(90, 80));
764 green->SetIsDrawable(true);
765 background->AddChild(green);
767 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
768 blue->SetAnchorPoint(gfx::PointF());
769 blue->SetPosition(gfx::Point(50, 50));
770 blue->SetBounds(gfx::Size(25, 25));
771 blue->SetIsDrawable(true);
772 green->AddChild(blue);
774 // Grab the green layer's content with blue in the bottom right.
775 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
776 device_scale_factor_ = 2.f;
778 this->impl_side_painting_ = false;
779 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
780 background,
781 green.get(),
782 base::FilePath(FILE_PATH_LITERAL(
783 "green_small_with_blue_corner.png")));
786 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest
787 : public LayerTreePixelTest {
788 protected:
789 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest()
790 : device_scale_factor_(1.f),
791 white_client_(SK_ColorWHITE),
792 green_client_(SK_ColorGREEN),
793 blue_client_(SK_ColorBLUE) {}
795 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
796 // Cause the device scale factor to be inherited by contents scales.
797 settings->layer_transforms_should_scale_layer_contents = true;
800 virtual void SetupTree() OVERRIDE {
801 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
802 LayerTreePixelTest::SetupTree();
805 virtual void BeginTest() OVERRIDE {
806 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor());
807 if (TestEnded())
808 return;
810 gfx::Rect device_viewport_copy_rect(
811 layer_tree_host()->device_viewport_size());
812 if (!device_viewport_copy_subrect_.IsEmpty())
813 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_);
815 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
816 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
817 device_viewport_copy_rect.width(),
818 device_viewport_copy_rect.height());
819 bitmap->allocPixels();
821 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap));
822 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(),
823 device_viewport_copy_rect);
826 result_bitmap_ = bitmap.Pass();
827 EndTest();
830 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
831 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
833 LayerImpl* background_impl = root_impl->children()[0];
834 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x());
835 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y());
837 LayerImpl* green_impl = background_impl->children()[0];
838 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x());
839 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y());
841 LayerImpl* blue_impl = green_impl->children()[0];
842 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x());
843 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y());
846 gfx::Rect device_viewport_copy_subrect_;
847 float device_scale_factor_;
848 SolidColorContentLayerClient white_client_;
849 SolidColorContentLayerClient green_client_;
850 SolidColorContentLayerClient blue_client_;
853 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
854 CompositeAndReadback_Software_1) {
855 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
856 background->SetAnchorPoint(gfx::PointF());
857 background->SetBounds(gfx::Size(200, 200));
858 background->SetIsDrawable(true);
860 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
861 green->SetAnchorPoint(gfx::PointF());
862 green->SetBounds(gfx::Size(200, 200));
863 green->SetIsDrawable(true);
864 background->AddChild(green);
866 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
867 blue->SetAnchorPoint(gfx::PointF());
868 blue->SetPosition(gfx::Point(100, 100));
869 blue->SetBounds(gfx::Size(50, 50));
870 blue->SetIsDrawable(true);
871 green->AddChild(blue);
873 // Grab the middle of the device viewport.
874 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
875 device_scale_factor_ = 1.f;
877 this->impl_side_painting_ = false;
878 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
879 background,
880 green.get(),
881 base::FilePath(FILE_PATH_LITERAL(
882 "green_small_with_blue_corner.png")));
885 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
886 CompositeAndReadback_Software_2) {
887 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
888 background->SetAnchorPoint(gfx::PointF());
889 background->SetBounds(gfx::Size(100, 100));
890 background->SetIsDrawable(true);
892 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
893 green->SetAnchorPoint(gfx::PointF());
894 green->SetBounds(gfx::Size(100, 100));
895 green->SetIsDrawable(true);
896 background->AddChild(green);
898 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
899 blue->SetAnchorPoint(gfx::PointF());
900 blue->SetPosition(gfx::Point(50, 50));
901 blue->SetBounds(gfx::Size(25, 25));
902 blue->SetIsDrawable(true);
903 green->AddChild(blue);
905 // Grab the middle of the device viewport.
906 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
907 device_scale_factor_ = 2.f;
909 this->impl_side_painting_ = false;
910 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
911 background,
912 green.get(),
913 base::FilePath(FILE_PATH_LITERAL(
914 "green_small_with_blue_corner.png")));
917 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
918 CompositeAndReadback_GL_1) {
919 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
920 background->SetAnchorPoint(gfx::PointF());
921 background->SetBounds(gfx::Size(200, 200));
922 background->SetIsDrawable(true);
924 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
925 green->SetAnchorPoint(gfx::PointF());
926 green->SetBounds(gfx::Size(200, 200));
927 green->SetIsDrawable(true);
928 background->AddChild(green);
930 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
931 blue->SetAnchorPoint(gfx::PointF());
932 blue->SetPosition(gfx::Point(100, 100));
933 blue->SetBounds(gfx::Size(50, 50));
934 blue->SetIsDrawable(true);
935 green->AddChild(blue);
937 // Grab the middle of the device viewport.
938 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
939 device_scale_factor_ = 1.f;
941 this->impl_side_painting_ = false;
942 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
943 background,
944 green.get(),
945 base::FilePath(FILE_PATH_LITERAL(
946 "green_small_with_blue_corner.png")));
949 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
950 CompositeAndReadback_GL_2) {
951 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
952 background->SetAnchorPoint(gfx::PointF());
953 background->SetBounds(gfx::Size(100, 100));
954 background->SetIsDrawable(true);
956 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
957 green->SetAnchorPoint(gfx::PointF());
958 green->SetBounds(gfx::Size(100, 100));
959 green->SetIsDrawable(true);
960 background->AddChild(green);
962 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
963 blue->SetAnchorPoint(gfx::PointF());
964 blue->SetPosition(gfx::Point(50, 50));
965 blue->SetBounds(gfx::Size(25, 25));
966 blue->SetIsDrawable(true);
967 green->AddChild(blue);
969 // Grab the middle of the device viewport.
970 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
971 device_scale_factor_ = 2.f;
973 this->impl_side_painting_ = false;
974 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
975 background,
976 green.get(),
977 base::FilePath(FILE_PATH_LITERAL(
978 "green_small_with_blue_corner.png")));
981 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) {
982 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
983 gfx::Rect(200, 200), SK_ColorWHITE);
985 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
986 gfx::Rect(200, 200), SK_ColorGREEN);
987 // Only the top left quarter of the layer is inside the viewport, so the
988 // blue layer is entirely outside.
989 green->SetPosition(gfx::Point(100, 100));
990 background->AddChild(green);
992 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
993 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
994 green->AddChild(blue);
996 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
997 background,
998 green.get(),
999 base::FilePath(FILE_PATH_LITERAL(
1000 "green_with_blue_corner.png")));
1003 } // namespace
1004 } // namespace cc
1006 #endif // OS_ANDROID