Factor out a BluetoothChannelMac base class and a BluetoothRfcommChannelMac subclass.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_readback.cc
blob4c808397eba08bc5737a0381eaa21ef49ff495a3
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->SetBounds(gfx::Size(100, 100));
958 background->SetIsDrawable(true);
960 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
961 green->SetBounds(gfx::Size(100, 100));
962 green->SetIsDrawable(true);
963 background->AddChild(green);
965 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
966 blue->SetPosition(gfx::Point(50, 50));
967 blue->SetBounds(gfx::Size(25, 25));
968 blue->SetIsDrawable(true);
969 green->AddChild(blue);
971 // Grab the middle of the root layer.
972 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
973 device_scale_factor_ = 2.f;
975 this->impl_side_painting_ = false;
976 RunPixelTest(SOFTWARE_WITH_DEFAULT,
977 background,
978 base::FilePath(FILE_PATH_LITERAL(
979 "green_small_with_blue_corner.png")));
982 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
983 ReadbackSubrect_GL) {
984 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
985 background->SetBounds(gfx::Size(100, 100));
986 background->SetIsDrawable(true);
988 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
989 green->SetBounds(gfx::Size(100, 100));
990 green->SetIsDrawable(true);
991 background->AddChild(green);
993 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
994 blue->SetPosition(gfx::Point(50, 50));
995 blue->SetBounds(gfx::Size(25, 25));
996 blue->SetIsDrawable(true);
997 green->AddChild(blue);
999 // Grab the middle of the root layer.
1000 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1001 device_scale_factor_ = 2.f;
1003 this->impl_side_painting_ = false;
1004 RunPixelTest(GL_WITH_DEFAULT,
1005 background,
1006 base::FilePath(FILE_PATH_LITERAL(
1007 "green_small_with_blue_corner.png")));
1010 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
1011 ReadbackNonRootLayerSubrect_Software) {
1012 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1013 background->SetBounds(gfx::Size(100, 100));
1014 background->SetIsDrawable(true);
1016 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1017 green->SetPosition(gfx::Point(10, 20));
1018 green->SetBounds(gfx::Size(90, 80));
1019 green->SetIsDrawable(true);
1020 background->AddChild(green);
1022 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1023 blue->SetPosition(gfx::Point(50, 50));
1024 blue->SetBounds(gfx::Size(25, 25));
1025 blue->SetIsDrawable(true);
1026 green->AddChild(blue);
1028 // Grab the green layer's content with blue in the bottom right.
1029 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1030 device_scale_factor_ = 2.f;
1032 this->impl_side_painting_ = false;
1033 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT,
1034 background,
1035 green.get(),
1036 base::FilePath(FILE_PATH_LITERAL(
1037 "green_small_with_blue_corner.png")));
1040 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest,
1041 ReadbackNonRootLayerSubrect_GL) {
1042 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_);
1043 background->SetBounds(gfx::Size(100, 100));
1044 background->SetIsDrawable(true);
1046 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_);
1047 green->SetPosition(gfx::Point(10, 20));
1048 green->SetBounds(gfx::Size(90, 80));
1049 green->SetIsDrawable(true);
1050 background->AddChild(green);
1052 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_);
1053 blue->SetPosition(gfx::Point(50, 50));
1054 blue->SetBounds(gfx::Size(25, 25));
1055 blue->SetIsDrawable(true);
1056 green->AddChild(blue);
1058 // Grab the green layer's content with blue in the bottom right.
1059 copy_subrect_ = gfx::Rect(25, 25, 50, 50);
1060 device_scale_factor_ = 2.f;
1062 this->impl_side_painting_ = false;
1063 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1064 background,
1065 green.get(),
1066 base::FilePath(FILE_PATH_LITERAL(
1067 "green_small_with_blue_corner.png")));
1070 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) {
1071 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
1072 gfx::Rect(200, 200), SK_ColorWHITE);
1074 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
1075 gfx::Rect(200, 200), SK_ColorGREEN);
1076 // Only the top left quarter of the layer is inside the viewport, so the
1077 // blue layer is entirely outside.
1078 green->SetPosition(gfx::Point(100, 100));
1079 background->AddChild(green);
1081 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer(
1082 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
1083 green->AddChild(blue);
1085 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT,
1086 background,
1087 green.get(),
1088 base::FilePath(FILE_PATH_LITERAL(
1089 "green_with_blue_corner.png")));
1092 } // namespace
1093 } // namespace cc
1095 #endif // OS_ANDROID