Move prefs::kLastPolicyStatisticsUpdate to the policy component.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_readback.cc
blobd8e286183f559765859607b73a78b1d6130bb9f4
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 RunPixelTest(SOFTWARE_WITH_DEFAULT,
683 background,
684 base::FilePath(FILE_PATH_LITERAL(
685 "green_small_with_blue_corner.png")));
688 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
689 ReadbackSubrect_GL) {
690 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
691 background->SetAnchorPoint(gfx::PointF());
692 background->SetBounds(gfx::Size(100, 100));
693 background->SetIsDrawable(true);
695 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
696 green->SetAnchorPoint(gfx::PointF());
697 green->SetBounds(gfx::Size(100, 100));
698 green->SetIsDrawable(true);
699 background->AddChild(green);
701 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
702 blue->SetAnchorPoint(gfx::PointF());
703 blue->SetPosition(gfx::Point(50, 50));
704 blue->SetBounds(gfx::Size(25, 25));
705 blue->SetIsDrawable(true);
706 green->AddChild(blue);
708 // Grab the middle of the root layer.
709 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
710 device_scale_factor_ = 2.f;
712 RunPixelTest(GL_WITH_DEFAULT,
713 background,
714 base::FilePath(FILE_PATH_LITERAL(
715 "green_small_with_blue_corner.png")));
718 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
719 ReadbackNonRootLayerSubrect_Software) {
720 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
721 background->SetAnchorPoint(gfx::PointF());
722 background->SetBounds(gfx::Size(100, 100));
723 background->SetIsDrawable(true);
725 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
726 green->SetAnchorPoint(gfx::PointF());
727 green->SetPosition(gfx::Point(10, 20));
728 green->SetBounds(gfx::Size(90, 80));
729 green->SetIsDrawable(true);
730 background->AddChild(green);
732 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
733 blue->SetAnchorPoint(gfx::PointF());
734 blue->SetPosition(gfx::Point(50, 50));
735 blue->SetBounds(gfx::Size(25, 25));
736 blue->SetIsDrawable(true);
737 green->AddChild(blue);
739 // Grab the green layer's content with blue in the bottom right.
740 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
741 device_scale_factor_ = 2.f;
743 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
744 background,
745 green.get(),
746 base::FilePath(FILE_PATH_LITERAL(
747 "green_small_with_blue_corner.png")));
750 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
751 ReadbackNonRootLayerSubrect_GL) {
752 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
753 background->SetAnchorPoint(gfx::PointF());
754 background->SetBounds(gfx::Size(100, 100));
755 background->SetIsDrawable(true);
757 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
758 green->SetAnchorPoint(gfx::PointF());
759 green->SetPosition(gfx::Point(10, 20));
760 green->SetBounds(gfx::Size(90, 80));
761 green->SetIsDrawable(true);
762 background->AddChild(green);
764 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
765 blue->SetAnchorPoint(gfx::PointF());
766 blue->SetPosition(gfx::Point(50, 50));
767 blue->SetBounds(gfx::Size(25, 25));
768 blue->SetIsDrawable(true);
769 green->AddChild(blue);
771 // Grab the green layer's content with blue in the bottom right.
772 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
773 device_scale_factor_ = 2.f;
775 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
776 background,
777 green.get(),
778 base::FilePath(FILE_PATH_LITERAL(
779 "green_small_with_blue_corner.png")));
782 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest
783 : public LayerTreePixelTest {
784 protected:
785 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest()
786 : device_scale_factor_(1.f),
787 white_client_(SK_ColorWHITE),
788 green_client_(SK_ColorGREEN),
789 blue_client_(SK_ColorBLUE) {}
791 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
792 // Cause the device scale factor to be inherited by contents scales.
793 settings->layer_transforms_should_scale_layer_contents = true;
796 virtual void SetupTree() OVERRIDE {
797 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
798 LayerTreePixelTest::SetupTree();
801 virtual void BeginTest() OVERRIDE {
802 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor());
803 if (TestEnded())
804 return;
806 gfx::Rect device_viewport_copy_rect(
807 layer_tree_host()->device_viewport_size());
808 if (!device_viewport_copy_subrect_.IsEmpty())
809 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_);
811 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
812 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
813 device_viewport_copy_rect.width(),
814 device_viewport_copy_rect.height());
815 bitmap->allocPixels();
817 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap));
818 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(),
819 device_viewport_copy_rect);
822 result_bitmap_ = bitmap.Pass();
823 EndTest();
826 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
827 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
829 LayerImpl* background_impl = root_impl->children()[0];
830 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x());
831 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y());
833 LayerImpl* green_impl = background_impl->children()[0];
834 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x());
835 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y());
837 LayerImpl* blue_impl = green_impl->children()[0];
838 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x());
839 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y());
842 gfx::Rect device_viewport_copy_subrect_;
843 float device_scale_factor_;
844 SolidColorContentLayerClient white_client_;
845 SolidColorContentLayerClient green_client_;
846 SolidColorContentLayerClient blue_client_;
849 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
850 CompositeAndReadback_Software_1) {
851 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
852 background->SetAnchorPoint(gfx::PointF());
853 background->SetBounds(gfx::Size(200, 200));
854 background->SetIsDrawable(true);
856 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
857 green->SetAnchorPoint(gfx::PointF());
858 green->SetBounds(gfx::Size(200, 200));
859 green->SetIsDrawable(true);
860 background->AddChild(green);
862 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
863 blue->SetAnchorPoint(gfx::PointF());
864 blue->SetPosition(gfx::Point(100, 100));
865 blue->SetBounds(gfx::Size(50, 50));
866 blue->SetIsDrawable(true);
867 green->AddChild(blue);
869 // Grab the middle of the device viewport.
870 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
871 device_scale_factor_ = 1.f;
873 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
874 background,
875 green.get(),
876 base::FilePath(FILE_PATH_LITERAL(
877 "green_small_with_blue_corner.png")));
880 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
881 CompositeAndReadback_Software_2) {
882 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
883 background->SetAnchorPoint(gfx::PointF());
884 background->SetBounds(gfx::Size(100, 100));
885 background->SetIsDrawable(true);
887 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
888 green->SetAnchorPoint(gfx::PointF());
889 green->SetBounds(gfx::Size(100, 100));
890 green->SetIsDrawable(true);
891 background->AddChild(green);
893 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
894 blue->SetAnchorPoint(gfx::PointF());
895 blue->SetPosition(gfx::Point(50, 50));
896 blue->SetBounds(gfx::Size(25, 25));
897 blue->SetIsDrawable(true);
898 green->AddChild(blue);
900 // Grab the middle of the device viewport.
901 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
902 device_scale_factor_ = 2.f;
904 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
905 background,
906 green.get(),
907 base::FilePath(FILE_PATH_LITERAL(
908 "green_small_with_blue_corner.png")));
911 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
912 CompositeAndReadback_GL_1) {
913 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
914 background->SetAnchorPoint(gfx::PointF());
915 background->SetBounds(gfx::Size(200, 200));
916 background->SetIsDrawable(true);
918 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
919 green->SetAnchorPoint(gfx::PointF());
920 green->SetBounds(gfx::Size(200, 200));
921 green->SetIsDrawable(true);
922 background->AddChild(green);
924 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
925 blue->SetAnchorPoint(gfx::PointF());
926 blue->SetPosition(gfx::Point(100, 100));
927 blue->SetBounds(gfx::Size(50, 50));
928 blue->SetIsDrawable(true);
929 green->AddChild(blue);
931 // Grab the middle of the device viewport.
932 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
933 device_scale_factor_ = 1.f;
935 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
936 background,
937 green.get(),
938 base::FilePath(FILE_PATH_LITERAL(
939 "green_small_with_blue_corner.png")));
942 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest,
943 CompositeAndReadback_GL_2) {
944 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
945 background->SetAnchorPoint(gfx::PointF());
946 background->SetBounds(gfx::Size(100, 100));
947 background->SetIsDrawable(true);
949 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
950 green->SetAnchorPoint(gfx::PointF());
951 green->SetBounds(gfx::Size(100, 100));
952 green->SetIsDrawable(true);
953 background->AddChild(green);
955 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
956 blue->SetAnchorPoint(gfx::PointF());
957 blue->SetPosition(gfx::Point(50, 50));
958 blue->SetBounds(gfx::Size(25, 25));
959 blue->SetIsDrawable(true);
960 green->AddChild(blue);
962 // Grab the middle of the device viewport.
963 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100);
964 device_scale_factor_ = 2.f;
966 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
967 background,
968 green.get(),
969 base::FilePath(FILE_PATH_LITERAL(
970 "green_small_with_blue_corner.png")));
973 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) {
974 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
975 gfx::Rect(200, 200), SK_ColorWHITE);
977 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
978 gfx::Rect(200, 200), SK_ColorGREEN);
979 // Only the top left quarter of the layer is inside the viewport, so the
980 // blue layer is entirely outside.
981 green->SetPosition(gfx::Point(100, 100));
982 background->AddChild(green);
984 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
985 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
986 green->AddChild(blue);
988 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
989 background,
990 green.get(),
991 base::FilePath(FILE_PATH_LITERAL(
992 "green_with_blue_corner.png")));
995 // TextureLayers are clipped differently than SolidColorLayers, verify they
996 // also can be copied when outside of the viewport.
997 TEST_F(LayerTreeHostReadbackPixelTest,
998 ReadbackNonRootTextureLayerOutsideViewport) {
999 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
1000 gfx::Rect(200, 200), SK_ColorWHITE);
1002 SkBitmap bitmap;
1003 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200);
1004 bitmap.allocPixels();
1005 bitmap.eraseColor(SK_ColorGREEN);
1007 SkBitmapDevice device(bitmap);
1008 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(new SkCanvas(&device));
1009 SkPaint paint;
1010 paint.setStyle(SkPaint::kFill_Style);
1011 paint.setColor(SK_ColorBLUE);
1012 canvas->drawRect(SkRect::MakeXYWH(150, 150, 50, 50), paint);
1015 scoped_refptr<TextureLayer> texture = CreateTextureLayer(
1016 gfx::Rect(200, 200), bitmap);
1018 // Tests with solid color layers verify correctness when CanClipSelf is false.
1019 EXPECT_FALSE(background->CanClipSelf());
1020 // This test verifies correctness when CanClipSelf is true.
1021 EXPECT_TRUE(texture->CanClipSelf());
1023 // Only the top left quarter of the layer is inside the viewport, so the
1024 // blue corner is entirely outside.
1025 texture->SetPosition(gfx::Point(100, 100));
1026 background->AddChild(texture);
1028 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1029 background,
1030 texture.get(),
1031 base::FilePath(FILE_PATH_LITERAL(
1032 "green_with_blue_corner.png")));
1035 } // namespace
1036 } // namespace cc
1038 #endif // OS_ANDROID