OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "build/build_config.h" | |
6 #include "cc/layers/solid_color_layer.h" | |
7 #include "cc/layers/texture_layer.h" | |
8 #include "cc/output/copy_output_request.h" | |
9 #include "cc/output/copy_output_result.h" | |
10 #include "cc/test/fake_picture_layer.h" | |
11 #include "cc/test/fake_picture_layer_impl.h" | |
12 #include "cc/test/layer_tree_pixel_test.h" | |
13 #include "cc/test/paths.h" | |
14 #include "cc/test/solid_color_content_layer_client.h" | |
15 #include "cc/trees/layer_tree_impl.h" | |
16 | |
17 #if !defined(OS_ANDROID) | |
18 | |
19 namespace cc { | |
20 namespace { | |
21 | |
22 // Can't templatize a class on its own members, so ReadbackType and | |
23 // ReadbackTestConfig are declared here, before LayerTreeHostReadbackPixelTest. | |
24 enum ReadbackType { | |
25 READBACK_INVALID, | |
26 READBACK_DEFAULT, | |
27 READBACK_BITMAP, | |
28 }; | |
29 | |
30 struct ReadbackTestConfig { | |
31 ReadbackTestConfig(LayerTreePixelTest::PixelTestType pixel_test_type_, | |
32 ReadbackType readback_type_) | |
33 : pixel_test_type(pixel_test_type_), readback_type(readback_type_) {} | |
34 LayerTreePixelTest::PixelTestType pixel_test_type; | |
35 ReadbackType readback_type; | |
36 }; | |
37 | |
38 class LayerTreeHostReadbackPixelTest | |
39 : public LayerTreePixelTest, | |
40 public testing::WithParamInterface<ReadbackTestConfig> { | |
41 protected: | |
42 LayerTreeHostReadbackPixelTest() | |
43 : readback_type_(READBACK_INVALID), | |
44 insert_copy_request_after_frame_count_(0) {} | |
45 | |
46 void RunReadbackTest(PixelTestType test_type, | |
47 ReadbackType readback_type, | |
48 scoped_refptr<Layer> content_root, | |
49 base::FilePath file_name) { | |
50 readback_type_ = readback_type; | |
51 RunPixelTest(test_type, content_root, file_name); | |
52 } | |
53 | |
54 void RunReadbackTestWithReadbackTarget(PixelTestType type, | |
55 ReadbackType readback_type, | |
56 scoped_refptr<Layer> content_root, | |
57 Layer* target, | |
58 base::FilePath file_name) { | |
59 readback_type_ = readback_type; | |
60 RunPixelTestWithReadbackTarget(type, content_root, target, file_name); | |
61 } | |
62 | |
63 scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() override { | |
64 scoped_ptr<CopyOutputRequest> request; | |
65 | |
66 if (readback_type_ == READBACK_BITMAP) { | |
67 request = CopyOutputRequest::CreateBitmapRequest( | |
68 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, | |
69 base::Unretained(this))); | |
70 } else { | |
71 DCHECK_EQ(readback_type_, READBACK_DEFAULT); | |
72 if (test_type_ == PIXEL_TEST_SOFTWARE) { | |
73 request = CopyOutputRequest::CreateRequest( | |
74 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, | |
75 base::Unretained(this))); | |
76 } else { | |
77 DCHECK_EQ(test_type_, PIXEL_TEST_GL); | |
78 request = CopyOutputRequest::CreateRequest( | |
79 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture, | |
80 base::Unretained(this))); | |
81 } | |
82 } | |
83 | |
84 if (!copy_subrect_.IsEmpty()) | |
85 request->set_area(copy_subrect_); | |
86 return request.Pass(); | |
87 } | |
88 | |
89 void BeginTest() override { | |
90 if (insert_copy_request_after_frame_count_ == 0) { | |
91 Layer* const target = | |
92 readback_target_ ? readback_target_ : layer_tree_host()->root_layer(); | |
93 target->RequestCopyOfOutput(CreateCopyOutputRequest().Pass()); | |
94 } | |
95 PostSetNeedsCommitToMainThread(); | |
96 } | |
97 | |
98 void DidCommitAndDrawFrame() override { | |
99 if (insert_copy_request_after_frame_count_ == | |
100 layer_tree_host()->source_frame_number()) { | |
101 Layer* const target = | |
102 readback_target_ ? readback_target_ : layer_tree_host()->root_layer(); | |
103 target->RequestCopyOfOutput(CreateCopyOutputRequest().Pass()); | |
104 } | |
105 } | |
106 | |
107 void ReadbackResultAsBitmap(scoped_ptr<CopyOutputResult> result) { | |
108 EXPECT_TRUE(proxy()->IsMainThread()); | |
109 EXPECT_TRUE(result->HasBitmap()); | |
110 result_bitmap_ = result->TakeBitmap().Pass(); | |
111 EndTest(); | |
112 } | |
113 | |
114 void ReadbackResultAsTexture(scoped_ptr<CopyOutputResult> result) { | |
115 EXPECT_TRUE(proxy()->IsMainThread()); | |
116 EXPECT_TRUE(result->HasTexture()); | |
117 | |
118 TextureMailbox texture_mailbox; | |
119 scoped_ptr<SingleReleaseCallback> release_callback; | |
120 result->TakeTexture(&texture_mailbox, &release_callback); | |
121 EXPECT_TRUE(texture_mailbox.IsValid()); | |
122 EXPECT_TRUE(texture_mailbox.IsTexture()); | |
123 | |
124 scoped_ptr<SkBitmap> bitmap = | |
125 CopyTextureMailboxToBitmap(result->size(), texture_mailbox); | |
126 release_callback->Run(0, false); | |
127 | |
128 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap.Pass())); | |
129 } | |
130 | |
131 ReadbackType readback_type_; | |
132 gfx::Rect copy_subrect_; | |
133 int insert_copy_request_after_frame_count_; | |
134 }; | |
135 | |
136 void IgnoreReadbackResult(scoped_ptr<CopyOutputResult> result) { | |
137 } | |
138 | |
139 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackRootLayer) { | |
140 scoped_refptr<SolidColorLayer> background = | |
141 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
142 | |
143 scoped_refptr<SolidColorLayer> green = | |
144 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
145 background->AddChild(green); | |
146 | |
147 RunReadbackTest(GetParam().pixel_test_type, GetParam().readback_type, | |
148 background, base::FilePath(FILE_PATH_LITERAL("green.png"))); | |
149 } | |
150 | |
151 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild) { | |
152 scoped_refptr<SolidColorLayer> background = | |
153 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
154 | |
155 scoped_refptr<SolidColorLayer> green = | |
156 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
157 background->AddChild(green); | |
158 | |
159 scoped_refptr<SolidColorLayer> blue = | |
160 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | |
161 green->AddChild(blue); | |
162 | |
163 RunReadbackTest( | |
164 GetParam().pixel_test_type, GetParam().readback_type, background, | |
165 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png"))); | |
166 } | |
167 | |
168 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer) { | |
169 scoped_refptr<SolidColorLayer> background = | |
170 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
171 | |
172 scoped_refptr<SolidColorLayer> green = | |
173 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
174 background->AddChild(green); | |
175 | |
176 RunReadbackTestWithReadbackTarget( | |
177 GetParam().pixel_test_type, GetParam().readback_type, background, | |
178 green.get(), base::FilePath(FILE_PATH_LITERAL("green.png"))); | |
179 } | |
180 | |
181 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer) { | |
182 scoped_refptr<SolidColorLayer> background = | |
183 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
184 | |
185 scoped_refptr<SolidColorLayer> green = | |
186 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | |
187 background->AddChild(green); | |
188 | |
189 RunReadbackTestWithReadbackTarget( | |
190 GetParam().pixel_test_type, GetParam().readback_type, background, | |
191 green.get(), base::FilePath(FILE_PATH_LITERAL("green_small.png"))); | |
192 } | |
193 | |
194 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayerWithChild) { | |
195 scoped_refptr<SolidColorLayer> background = | |
196 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
197 | |
198 scoped_refptr<SolidColorLayer> green = | |
199 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | |
200 background->AddChild(green); | |
201 | |
202 scoped_refptr<SolidColorLayer> blue = | |
203 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | |
204 green->AddChild(blue); | |
205 | |
206 RunReadbackTestWithReadbackTarget( | |
207 GetParam().pixel_test_type, GetParam().readback_type, background, | |
208 green.get(), | |
209 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
210 } | |
211 | |
212 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackSubtreeSurroundsTargetLayer) { | |
213 scoped_refptr<SolidColorLayer> background = | |
214 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE); | |
215 | |
216 scoped_refptr<SolidColorLayer> target = | |
217 CreateSolidColorLayer(gfx::Rect(100, 100, 100, 100), SK_ColorRED); | |
218 background->AddChild(target); | |
219 | |
220 scoped_refptr<SolidColorLayer> green = | |
221 CreateSolidColorLayer(gfx::Rect(-100, -100, 300, 300), SK_ColorGREEN); | |
222 target->AddChild(green); | |
223 | |
224 scoped_refptr<SolidColorLayer> blue = | |
225 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | |
226 target->AddChild(blue); | |
227 | |
228 copy_subrect_ = gfx::Rect(0, 0, 100, 100); | |
229 RunReadbackTestWithReadbackTarget( | |
230 GetParam().pixel_test_type, GetParam().readback_type, background, | |
231 target.get(), | |
232 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
233 } | |
234 | |
235 TEST_P(LayerTreeHostReadbackPixelTest, | |
236 ReadbackSubtreeExtendsBeyondTargetLayer) { | |
237 scoped_refptr<SolidColorLayer> background = | |
238 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE); | |
239 | |
240 scoped_refptr<SolidColorLayer> target = | |
241 CreateSolidColorLayer(gfx::Rect(50, 50, 150, 150), SK_ColorRED); | |
242 background->AddChild(target); | |
243 | |
244 scoped_refptr<SolidColorLayer> green = | |
245 CreateSolidColorLayer(gfx::Rect(50, 50, 200, 200), SK_ColorGREEN); | |
246 target->AddChild(green); | |
247 | |
248 scoped_refptr<SolidColorLayer> blue = | |
249 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); | |
250 target->AddChild(blue); | |
251 | |
252 copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
253 RunReadbackTestWithReadbackTarget( | |
254 GetParam().pixel_test_type, GetParam().readback_type, background, | |
255 target.get(), | |
256 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
257 } | |
258 | |
259 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackHiddenSubtree) { | |
260 scoped_refptr<SolidColorLayer> background = | |
261 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK); | |
262 | |
263 scoped_refptr<SolidColorLayer> hidden_target = | |
264 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
265 hidden_target->SetHideLayerAndSubtree(true); | |
266 background->AddChild(hidden_target); | |
267 | |
268 scoped_refptr<SolidColorLayer> blue = | |
269 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | |
270 hidden_target->AddChild(blue); | |
271 | |
272 RunReadbackTestWithReadbackTarget( | |
273 GetParam().pixel_test_type, GetParam().readback_type, background, | |
274 hidden_target.get(), | |
275 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png"))); | |
276 } | |
277 | |
278 TEST_P(LayerTreeHostReadbackPixelTest, | |
279 HiddenSubtreeNotVisibleWhenDrawnForReadback) { | |
280 scoped_refptr<SolidColorLayer> background = | |
281 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK); | |
282 | |
283 scoped_refptr<SolidColorLayer> hidden_target = | |
284 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
285 hidden_target->SetHideLayerAndSubtree(true); | |
286 background->AddChild(hidden_target); | |
287 | |
288 scoped_refptr<SolidColorLayer> blue = | |
289 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | |
290 hidden_target->AddChild(blue); | |
291 | |
292 hidden_target->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | |
293 base::Bind(&IgnoreReadbackResult))); | |
294 RunReadbackTest(GetParam().pixel_test_type, GetParam().readback_type, | |
295 background, base::FilePath(FILE_PATH_LITERAL("black.png"))); | |
296 } | |
297 | |
298 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackSubrect) { | |
299 scoped_refptr<SolidColorLayer> background = | |
300 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
301 | |
302 scoped_refptr<SolidColorLayer> green = | |
303 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
304 background->AddChild(green); | |
305 | |
306 scoped_refptr<SolidColorLayer> blue = | |
307 CreateSolidColorLayer(gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); | |
308 green->AddChild(blue); | |
309 | |
310 // Grab the middle of the root layer. | |
311 copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
312 | |
313 RunReadbackTest( | |
314 GetParam().pixel_test_type, GetParam().readback_type, background, | |
315 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
316 } | |
317 | |
318 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect) { | |
319 scoped_refptr<SolidColorLayer> background = | |
320 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
321 | |
322 scoped_refptr<SolidColorLayer> green = | |
323 CreateSolidColorLayer(gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); | |
324 background->AddChild(green); | |
325 | |
326 scoped_refptr<SolidColorLayer> blue = | |
327 CreateSolidColorLayer(gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); | |
328 green->AddChild(blue); | |
329 | |
330 // Grab the middle of the green layer. | |
331 copy_subrect_ = gfx::Rect(25, 25, 100, 100); | |
332 | |
333 RunReadbackTestWithReadbackTarget( | |
334 GetParam().pixel_test_type, GetParam().readback_type, background, | |
335 green.get(), | |
336 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
337 } | |
338 | |
339 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackWhenNoDamage) { | |
340 scoped_refptr<SolidColorLayer> background = | |
341 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE); | |
342 | |
343 scoped_refptr<SolidColorLayer> parent = | |
344 CreateSolidColorLayer(gfx::Rect(0, 0, 150, 150), SK_ColorRED); | |
345 background->AddChild(parent); | |
346 | |
347 scoped_refptr<SolidColorLayer> target = | |
348 CreateSolidColorLayer(gfx::Rect(0, 0, 100, 100), SK_ColorGREEN); | |
349 parent->AddChild(target); | |
350 | |
351 scoped_refptr<SolidColorLayer> blue = | |
352 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | |
353 target->AddChild(blue); | |
354 | |
355 insert_copy_request_after_frame_count_ = 1; | |
356 RunReadbackTestWithReadbackTarget( | |
357 GetParam().pixel_test_type, GetParam().readback_type, background, | |
358 target.get(), | |
359 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
360 } | |
361 | |
362 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackOutsideViewportWhenNoDamage) { | |
363 scoped_refptr<SolidColorLayer> background = | |
364 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorWHITE); | |
365 | |
366 scoped_refptr<SolidColorLayer> parent = | |
367 CreateSolidColorLayer(gfx::Rect(0, 0, 200, 200), SK_ColorRED); | |
368 EXPECT_FALSE(parent->masks_to_bounds()); | |
369 background->AddChild(parent); | |
370 | |
371 scoped_refptr<SolidColorLayer> target = | |
372 CreateSolidColorLayer(gfx::Rect(250, 250, 100, 100), SK_ColorGREEN); | |
373 parent->AddChild(target); | |
374 | |
375 scoped_refptr<SolidColorLayer> blue = | |
376 CreateSolidColorLayer(gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | |
377 target->AddChild(blue); | |
378 | |
379 insert_copy_request_after_frame_count_ = 1; | |
380 RunReadbackTestWithReadbackTarget( | |
381 GetParam().pixel_test_type, GetParam().readback_type, background, | |
382 target.get(), | |
383 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
384 } | |
385 | |
386 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) { | |
387 scoped_refptr<SolidColorLayer> background = | |
388 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); | |
389 | |
390 scoped_refptr<SolidColorLayer> green = | |
391 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
392 // Only the top left quarter of the layer is inside the viewport, so the | |
393 // blue layer is entirely outside. | |
394 green->SetPosition(gfx::Point(100, 100)); | |
395 background->AddChild(green); | |
396 | |
397 scoped_refptr<SolidColorLayer> blue = | |
398 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | |
399 green->AddChild(blue); | |
400 | |
401 RunReadbackTestWithReadbackTarget( | |
402 GetParam().pixel_test_type, GetParam().readback_type, background, | |
403 green.get(), | |
404 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png"))); | |
405 } | |
406 | |
407 TEST_P(LayerTreeHostReadbackPixelTest, ReadbackNonRootOrFirstLayer) { | |
408 // This test has 3 render passes with the copy request on the render pass in | |
409 // the middle. This test caught an issue where copy requests on non-root | |
410 // non-first render passes were being treated differently from the first | |
411 // render pass. | |
412 scoped_refptr<SolidColorLayer> background = | |
413 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
414 | |
415 scoped_refptr<SolidColorLayer> blue = | |
416 CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | |
417 blue->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | |
418 base::Bind(&IgnoreReadbackResult))); | |
419 background->AddChild(blue); | |
420 | |
421 RunReadbackTestWithReadbackTarget( | |
422 GetParam().pixel_test_type, GetParam().readback_type, background, | |
423 background.get(), | |
424 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png"))); | |
425 } | |
426 | |
427 TEST_P(LayerTreeHostReadbackPixelTest, MultipleReadbacksOnLayer) { | |
428 // This test has 2 copy requests on the background layer. One is added in the | |
429 // test body, another is added in RunReadbackTestWithReadbackTarget. For every | |
430 // copy request after the first, state must be restored via a call to | |
431 // UseRenderPass (see http://crbug.com/99393). This test ensures that the | |
432 // renderer correctly handles cases where UseRenderPass is called multiple | |
433 // times for a single layer. | |
434 scoped_refptr<SolidColorLayer> background = | |
435 CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN); | |
436 | |
437 background->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | |
438 base::Bind(&IgnoreReadbackResult))); | |
439 | |
440 RunReadbackTestWithReadbackTarget( | |
441 GetParam().pixel_test_type, GetParam().readback_type, background, | |
442 background.get(), base::FilePath(FILE_PATH_LITERAL("green.png"))); | |
443 } | |
444 | |
445 INSTANTIATE_TEST_CASE_P( | |
446 LayerTreeHostReadbackPixelTests, | |
447 LayerTreeHostReadbackPixelTest, | |
448 ::testing::Values( | |
449 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_SOFTWARE, | |
450 READBACK_DEFAULT), | |
451 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL, | |
452 READBACK_DEFAULT), | |
453 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL, | |
454 READBACK_BITMAP))); | |
455 | |
456 class LayerTreeHostReadbackDeviceScalePixelTest | |
457 : public LayerTreeHostReadbackPixelTest { | |
458 protected: | |
459 LayerTreeHostReadbackDeviceScalePixelTest() | |
460 : device_scale_factor_(1.f), | |
461 white_client_(SK_ColorWHITE), | |
462 green_client_(SK_ColorGREEN), | |
463 blue_client_(SK_ColorBLUE) {} | |
464 | |
465 void InitializeSettings(LayerTreeSettings* settings) override { | |
466 // Cause the device scale factor to be inherited by contents scales. | |
467 settings->layer_transforms_should_scale_layer_contents = true; | |
468 } | |
469 | |
470 void SetupTree() override { | |
471 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); | |
472 LayerTreePixelTest::SetupTree(); | |
473 } | |
474 | |
475 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
476 EXPECT_EQ(device_scale_factor_, | |
477 host_impl->active_tree()->device_scale_factor()); | |
478 } | |
479 | |
480 float device_scale_factor_; | |
481 SolidColorContentLayerClient white_client_; | |
482 SolidColorContentLayerClient green_client_; | |
483 SolidColorContentLayerClient blue_client_; | |
484 }; | |
485 | |
486 TEST_P(LayerTreeHostReadbackDeviceScalePixelTest, ReadbackSubrect) { | |
487 scoped_refptr<FakePictureLayer> background = | |
488 FakePictureLayer::Create(&white_client_); | |
489 background->SetBounds(gfx::Size(100, 100)); | |
490 background->SetIsDrawable(true); | |
491 | |
492 scoped_refptr<FakePictureLayer> green = | |
493 FakePictureLayer::Create(&green_client_); | |
494 green->SetBounds(gfx::Size(100, 100)); | |
495 green->SetIsDrawable(true); | |
496 background->AddChild(green); | |
497 | |
498 scoped_refptr<FakePictureLayer> blue = | |
499 FakePictureLayer::Create(&blue_client_); | |
500 blue->SetPosition(gfx::Point(50, 50)); | |
501 blue->SetBounds(gfx::Size(25, 25)); | |
502 blue->SetIsDrawable(true); | |
503 green->AddChild(blue); | |
504 | |
505 // Grab the middle of the root layer. | |
506 copy_subrect_ = gfx::Rect(25, 25, 50, 50); | |
507 device_scale_factor_ = 2.f; | |
508 RunReadbackTest( | |
509 GetParam().pixel_test_type, GetParam().readback_type, background, | |
510 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
511 } | |
512 | |
513 TEST_P(LayerTreeHostReadbackDeviceScalePixelTest, ReadbackNonRootLayerSubrect) { | |
514 scoped_refptr<FakePictureLayer> background = | |
515 FakePictureLayer::Create(&white_client_); | |
516 background->SetBounds(gfx::Size(100, 100)); | |
517 background->SetIsDrawable(true); | |
518 | |
519 scoped_refptr<FakePictureLayer> green = | |
520 FakePictureLayer::Create(&green_client_); | |
521 green->SetPosition(gfx::Point(10, 20)); | |
522 green->SetBounds(gfx::Size(90, 80)); | |
523 green->SetIsDrawable(true); | |
524 background->AddChild(green); | |
525 | |
526 scoped_refptr<FakePictureLayer> blue = | |
527 FakePictureLayer::Create(&blue_client_); | |
528 blue->SetPosition(gfx::Point(50, 50)); | |
529 blue->SetBounds(gfx::Size(25, 25)); | |
530 blue->SetIsDrawable(true); | |
531 green->AddChild(blue); | |
532 | |
533 // Grab the green layer's content with blue in the bottom right. | |
534 copy_subrect_ = gfx::Rect(25, 25, 50, 50); | |
535 device_scale_factor_ = 2.f; | |
536 RunReadbackTestWithReadbackTarget( | |
537 GetParam().pixel_test_type, GetParam().readback_type, background, | |
538 green.get(), | |
539 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); | |
540 } | |
541 | |
542 INSTANTIATE_TEST_CASE_P( | |
543 LayerTreeHostReadbackDeviceScalePixelTests, | |
544 LayerTreeHostReadbackDeviceScalePixelTest, | |
545 ::testing::Values( | |
546 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_SOFTWARE, | |
547 READBACK_DEFAULT), | |
548 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL, | |
549 READBACK_DEFAULT), | |
550 ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL, | |
551 READBACK_BITMAP))); | |
552 | |
553 } // namespace | |
554 } // namespace cc | |
555 | |
556 #endif // OS_ANDROID | |
OLD | NEW |