OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "cc/layers/content_layer.h" |
6 #include "cc/output/copy_output_request.h" | 7 #include "cc/output/copy_output_request.h" |
7 #include "cc/output/copy_output_result.h" | 8 #include "cc/output/copy_output_result.h" |
8 #include "cc/test/layer_tree_pixel_test.h" | 9 #include "cc/test/layer_tree_pixel_test.h" |
9 #include "cc/test/paths.h" | 10 #include "cc/test/paths.h" |
| 11 #include "cc/test/solid_color_content_layer_client.h" |
| 12 #include "cc/trees/layer_tree_impl.h" |
10 | 13 |
11 #if !defined(OS_ANDROID) | 14 #if !defined(OS_ANDROID) |
12 | 15 |
13 namespace cc { | 16 namespace cc { |
14 namespace { | 17 namespace { |
15 | 18 |
16 class LayerTreeHostReadbackPixelTest : public LayerTreePixelTest { | 19 class LayerTreeHostReadbackPixelTest : public LayerTreePixelTest { |
17 protected: | 20 protected: |
18 LayerTreeHostReadbackPixelTest() : force_readback_as_bitmap_(false) {} | 21 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE { |
| 22 scoped_ptr<CopyOutputRequest> request; |
19 | 23 |
20 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE { | 24 switch (test_type_) { |
21 if (force_readback_as_bitmap_) { | 25 case GL_WITH_BITMAP: |
22 return CopyOutputRequest::CreateBitmapRequest( | 26 case SOFTWARE_WITH_BITMAP: |
23 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, | 27 request = CopyOutputRequest::CreateBitmapRequest( |
24 base::Unretained(this))); | 28 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, |
| 29 base::Unretained(this))); |
| 30 break; |
| 31 case SOFTWARE_WITH_DEFAULT: |
| 32 request = CopyOutputRequest::CreateRequest( |
| 33 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, |
| 34 base::Unretained(this))); |
| 35 break; |
| 36 case GL_WITH_DEFAULT: |
| 37 request = CopyOutputRequest::CreateRequest( |
| 38 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture, |
| 39 base::Unretained(this))); |
| 40 break; |
25 } | 41 } |
26 | 42 |
27 if (!use_gl_) { | 43 if (!copy_subrect_.IsEmpty()) |
28 return CopyOutputRequest::CreateRequest( | 44 request->set_area(copy_subrect_); |
29 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap, | 45 return request.Pass(); |
30 base::Unretained(this))); | |
31 } | |
32 | |
33 return CopyOutputRequest::CreateRequest( | |
34 base::Bind(&LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture, | |
35 base::Unretained(this))); | |
36 } | 46 } |
37 | 47 |
38 void ReadbackResultAsBitmap(scoped_ptr<CopyOutputResult> result) { | 48 void ReadbackResultAsBitmap(scoped_ptr<CopyOutputResult> result) { |
39 EXPECT_TRUE(result->HasBitmap()); | 49 EXPECT_TRUE(result->HasBitmap()); |
40 result_bitmap_ = result->TakeBitmap().Pass(); | 50 result_bitmap_ = result->TakeBitmap().Pass(); |
41 EndTest(); | 51 EndTest(); |
42 } | 52 } |
43 | 53 |
44 void ReadbackResultAsTexture(scoped_ptr<CopyOutputResult> result) { | 54 void ReadbackResultAsTexture(scoped_ptr<CopyOutputResult> result) { |
45 EXPECT_TRUE(result->HasTexture()); | 55 EXPECT_TRUE(result->HasTexture()); |
46 | 56 |
47 scoped_ptr<TextureMailbox> texture_mailbox = result->TakeTexture().Pass(); | 57 scoped_ptr<TextureMailbox> texture_mailbox = result->TakeTexture().Pass(); |
48 EXPECT_TRUE(texture_mailbox->IsValid()); | 58 EXPECT_TRUE(texture_mailbox->IsValid()); |
49 EXPECT_TRUE(texture_mailbox->IsTexture()); | 59 EXPECT_TRUE(texture_mailbox->IsTexture()); |
50 | 60 |
51 scoped_ptr<SkBitmap> bitmap = | 61 scoped_ptr<SkBitmap> bitmap = |
52 CopyTextureMailboxToBitmap(result->size(), *texture_mailbox); | 62 CopyTextureMailboxToBitmap(result->size(), *texture_mailbox); |
53 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap.Pass())); | 63 ReadbackResultAsBitmap(CopyOutputResult::CreateBitmapResult(bitmap.Pass())); |
54 | 64 |
55 texture_mailbox->RunReleaseCallback(0, false); | 65 texture_mailbox->RunReleaseCallback(0, false); |
56 } | 66 } |
57 | 67 |
58 bool force_readback_as_bitmap_; | 68 gfx::Rect copy_subrect_; |
59 }; | 69 }; |
60 | 70 |
61 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software) { | 71 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software) { |
62 use_gl_ = false; | |
63 force_readback_as_bitmap_ = false; | |
64 | |
65 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 72 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
66 gfx::Rect(200, 200), SK_ColorWHITE); | 73 gfx::Rect(200, 200), SK_ColorWHITE); |
67 | 74 |
68 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 75 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
69 gfx::Rect(200, 200), SK_ColorGREEN); | 76 gfx::Rect(200, 200), SK_ColorGREEN); |
70 background->AddChild(green); | 77 background->AddChild(green); |
71 | 78 |
72 RunPixelTest(background, | 79 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
| 80 background, |
73 base::FilePath(FILE_PATH_LITERAL( | 81 base::FilePath(FILE_PATH_LITERAL( |
74 "green.png"))); | 82 "green.png"))); |
75 } | 83 } |
76 | 84 |
77 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software_Bitmap) { | 85 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_Software_Bitmap) { |
78 use_gl_ = false; | |
79 force_readback_as_bitmap_ = true; | |
80 | |
81 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 86 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
82 gfx::Rect(200, 200), SK_ColorWHITE); | 87 gfx::Rect(200, 200), SK_ColorWHITE); |
83 | 88 |
84 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 89 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
85 gfx::Rect(200, 200), SK_ColorGREEN); | 90 gfx::Rect(200, 200), SK_ColorGREEN); |
86 background->AddChild(green); | 91 background->AddChild(green); |
87 | 92 |
88 RunPixelTest(background, | 93 RunPixelTest(SOFTWARE_WITH_BITMAP, |
| 94 background, |
89 base::FilePath(FILE_PATH_LITERAL( | 95 base::FilePath(FILE_PATH_LITERAL( |
90 "green.png"))); | 96 "green.png"))); |
91 } | 97 } |
92 | 98 |
93 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL_Bitmap) { | 99 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL_Bitmap) { |
94 use_gl_ = true; | |
95 force_readback_as_bitmap_ = true; | |
96 | |
97 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 100 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
98 gfx::Rect(200, 200), SK_ColorWHITE); | 101 gfx::Rect(200, 200), SK_ColorWHITE); |
99 | 102 |
100 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 103 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
101 gfx::Rect(200, 200), SK_ColorGREEN); | 104 gfx::Rect(200, 200), SK_ColorGREEN); |
102 background->AddChild(green); | 105 background->AddChild(green); |
103 | 106 |
104 RunPixelTest(background, | 107 RunPixelTest(GL_WITH_BITMAP, |
| 108 background, |
105 base::FilePath(FILE_PATH_LITERAL( | 109 base::FilePath(FILE_PATH_LITERAL( |
106 "green.png"))); | 110 "green.png"))); |
107 } | 111 } |
108 | 112 |
109 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL) { | 113 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayer_GL) { |
110 use_gl_ = true; | |
111 force_readback_as_bitmap_ = false; | |
112 | |
113 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 114 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
114 gfx::Rect(200, 200), SK_ColorWHITE); | 115 gfx::Rect(200, 200), SK_ColorWHITE); |
115 | 116 |
116 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 117 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
117 gfx::Rect(200, 200), SK_ColorGREEN); | 118 gfx::Rect(200, 200), SK_ColorGREEN); |
118 background->AddChild(green); | 119 background->AddChild(green); |
119 | 120 |
120 RunPixelTest(background, | 121 RunPixelTest(GL_WITH_DEFAULT, |
| 122 background, |
121 base::FilePath(FILE_PATH_LITERAL( | 123 base::FilePath(FILE_PATH_LITERAL( |
122 "green.png"))); | 124 "green.png"))); |
123 } | 125 } |
124 | 126 |
125 TEST_F(LayerTreeHostReadbackPixelTest, | 127 TEST_F(LayerTreeHostReadbackPixelTest, |
126 ReadbackRootLayerWithChild_Software) { | 128 ReadbackRootLayerWithChild_Software) { |
127 use_gl_ = false; | |
128 force_readback_as_bitmap_ = false; | |
129 | |
130 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 129 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
131 gfx::Rect(200, 200), SK_ColorWHITE); | 130 gfx::Rect(200, 200), SK_ColorWHITE); |
132 | 131 |
133 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 132 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
134 gfx::Rect(200, 200), SK_ColorGREEN); | 133 gfx::Rect(200, 200), SK_ColorGREEN); |
135 background->AddChild(green); | 134 background->AddChild(green); |
136 | 135 |
137 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 136 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
138 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | 137 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); |
139 green->AddChild(blue); | 138 green->AddChild(blue); |
140 | 139 |
141 RunPixelTest(background, | 140 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
| 141 background, |
142 base::FilePath(FILE_PATH_LITERAL( | 142 base::FilePath(FILE_PATH_LITERAL( |
143 "green_with_blue_corner.png"))); | 143 "green_with_blue_corner.png"))); |
144 } | 144 } |
145 | 145 |
146 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL_Bitmap) { | 146 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL_Bitmap) { |
147 use_gl_ = true; | |
148 force_readback_as_bitmap_ = true; | |
149 | |
150 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 147 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
151 gfx::Rect(200, 200), SK_ColorWHITE); | 148 gfx::Rect(200, 200), SK_ColorWHITE); |
152 | 149 |
153 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 150 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
154 gfx::Rect(200, 200), SK_ColorGREEN); | 151 gfx::Rect(200, 200), SK_ColorGREEN); |
155 background->AddChild(green); | 152 background->AddChild(green); |
156 | 153 |
157 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 154 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
158 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | 155 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); |
159 green->AddChild(blue); | 156 green->AddChild(blue); |
160 | 157 |
161 RunPixelTest(background, | 158 RunPixelTest(GL_WITH_BITMAP, |
| 159 background, |
162 base::FilePath(FILE_PATH_LITERAL( | 160 base::FilePath(FILE_PATH_LITERAL( |
163 "green_with_blue_corner.png"))); | 161 "green_with_blue_corner.png"))); |
164 } | 162 } |
165 | 163 |
166 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL) { | 164 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackRootLayerWithChild_GL) { |
167 use_gl_ = true; | |
168 force_readback_as_bitmap_ = false; | |
169 | |
170 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 165 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
171 gfx::Rect(200, 200), SK_ColorWHITE); | 166 gfx::Rect(200, 200), SK_ColorWHITE); |
172 | 167 |
173 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 168 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
174 gfx::Rect(200, 200), SK_ColorGREEN); | 169 gfx::Rect(200, 200), SK_ColorGREEN); |
175 background->AddChild(green); | 170 background->AddChild(green); |
176 | 171 |
177 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 172 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
178 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | 173 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); |
179 green->AddChild(blue); | 174 green->AddChild(blue); |
180 | 175 |
181 RunPixelTest(background, | 176 RunPixelTest(GL_WITH_DEFAULT, |
| 177 background, |
182 base::FilePath(FILE_PATH_LITERAL( | 178 base::FilePath(FILE_PATH_LITERAL( |
183 "green_with_blue_corner.png"))); | 179 "green_with_blue_corner.png"))); |
184 } | 180 } |
185 | 181 |
186 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_Software) { | 182 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_Software) { |
187 use_gl_ = false; | |
188 force_readback_as_bitmap_ = false; | |
189 | |
190 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 183 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
191 gfx::Rect(200, 200), SK_ColorWHITE); | 184 gfx::Rect(200, 200), SK_ColorWHITE); |
192 | 185 |
193 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 186 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
194 gfx::Rect(200, 200), SK_ColorGREEN); | 187 gfx::Rect(200, 200), SK_ColorGREEN); |
195 background->AddChild(green); | 188 background->AddChild(green); |
196 | 189 |
197 RunPixelTestWithReadbackTarget(background, | 190 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 191 background, |
198 green.get(), | 192 green.get(), |
199 base::FilePath(FILE_PATH_LITERAL( | 193 base::FilePath(FILE_PATH_LITERAL( |
200 "green.png"))); | 194 "green.png"))); |
201 } | 195 } |
202 | 196 |
203 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL_Bitmap) { | 197 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL_Bitmap) { |
204 use_gl_ = true; | |
205 force_readback_as_bitmap_ = true; | |
206 | |
207 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 198 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
208 gfx::Rect(200, 200), SK_ColorWHITE); | 199 gfx::Rect(200, 200), SK_ColorWHITE); |
209 | 200 |
210 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 201 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
211 gfx::Rect(200, 200), SK_ColorGREEN); | 202 gfx::Rect(200, 200), SK_ColorGREEN); |
212 background->AddChild(green); | 203 background->AddChild(green); |
213 | 204 |
214 RunPixelTestWithReadbackTarget(background, | 205 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, |
| 206 background, |
215 green.get(), | 207 green.get(), |
216 base::FilePath(FILE_PATH_LITERAL( | 208 base::FilePath(FILE_PATH_LITERAL( |
217 "green.png"))); | 209 "green.png"))); |
218 } | 210 } |
219 | 211 |
220 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL) { | 212 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayer_GL) { |
221 use_gl_ = true; | |
222 force_readback_as_bitmap_ = false; | |
223 | |
224 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 213 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
225 gfx::Rect(200, 200), SK_ColorWHITE); | 214 gfx::Rect(200, 200), SK_ColorWHITE); |
226 | 215 |
227 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 216 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
228 gfx::Rect(200, 200), SK_ColorGREEN); | 217 gfx::Rect(200, 200), SK_ColorGREEN); |
229 background->AddChild(green); | 218 background->AddChild(green); |
230 | 219 |
231 RunPixelTestWithReadbackTarget(background, | 220 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 221 background, |
232 green.get(), | 222 green.get(), |
233 base::FilePath(FILE_PATH_LITERAL( | 223 base::FilePath(FILE_PATH_LITERAL( |
234 "green.png"))); | 224 "green.png"))); |
235 } | 225 } |
236 | 226 |
237 TEST_F(LayerTreeHostReadbackPixelTest, | 227 TEST_F(LayerTreeHostReadbackPixelTest, |
238 ReadbackSmallNonRootLayer_Software) { | 228 ReadbackSmallNonRootLayer_Software) { |
239 use_gl_ = false; | |
240 force_readback_as_bitmap_ = false; | |
241 | |
242 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 229 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
243 gfx::Rect(200, 200), SK_ColorWHITE); | 230 gfx::Rect(200, 200), SK_ColorWHITE); |
244 | 231 |
245 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 232 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
246 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 233 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
247 background->AddChild(green); | 234 background->AddChild(green); |
248 | 235 |
249 RunPixelTestWithReadbackTarget(background, | 236 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 237 background, |
250 green.get(), | 238 green.get(), |
251 base::FilePath(FILE_PATH_LITERAL( | 239 base::FilePath(FILE_PATH_LITERAL( |
252 "green_small.png"))); | 240 "green_small.png"))); |
253 } | 241 } |
254 | 242 |
255 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL_Bitmap) { | 243 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL_Bitmap) { |
256 use_gl_ = true; | |
257 force_readback_as_bitmap_ = true; | |
258 | |
259 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 244 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
260 gfx::Rect(200, 200), SK_ColorWHITE); | 245 gfx::Rect(200, 200), SK_ColorWHITE); |
261 | 246 |
262 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 247 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
263 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 248 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
264 background->AddChild(green); | 249 background->AddChild(green); |
265 | 250 |
266 RunPixelTestWithReadbackTarget(background, | 251 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, |
| 252 background, |
267 green.get(), | 253 green.get(), |
268 base::FilePath(FILE_PATH_LITERAL( | 254 base::FilePath(FILE_PATH_LITERAL( |
269 "green_small.png"))); | 255 "green_small.png"))); |
270 } | 256 } |
271 | 257 |
272 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL) { | 258 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayer_GL) { |
273 use_gl_ = true; | |
274 force_readback_as_bitmap_ = false; | |
275 | |
276 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 259 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
277 gfx::Rect(200, 200), SK_ColorWHITE); | 260 gfx::Rect(200, 200), SK_ColorWHITE); |
278 | 261 |
279 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 262 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
280 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 263 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
281 background->AddChild(green); | 264 background->AddChild(green); |
282 | 265 |
283 RunPixelTestWithReadbackTarget(background, | 266 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 267 background, |
284 green.get(), | 268 green.get(), |
285 base::FilePath(FILE_PATH_LITERAL( | 269 base::FilePath(FILE_PATH_LITERAL( |
286 "green_small.png"))); | 270 "green_small.png"))); |
287 } | 271 } |
288 | 272 |
289 TEST_F(LayerTreeHostReadbackPixelTest, | 273 TEST_F(LayerTreeHostReadbackPixelTest, |
290 ReadbackSmallNonRootLayerWithChild_Software) { | 274 ReadbackSmallNonRootLayerWithChild_Software) { |
291 use_gl_ = false; | |
292 force_readback_as_bitmap_ = false; | |
293 | |
294 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 275 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
295 gfx::Rect(200, 200), SK_ColorWHITE); | 276 gfx::Rect(200, 200), SK_ColorWHITE); |
296 | 277 |
297 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 278 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
298 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 279 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
299 background->AddChild(green); | 280 background->AddChild(green); |
300 | 281 |
301 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 282 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
302 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | 283 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); |
303 green->AddChild(blue); | 284 green->AddChild(blue); |
304 | 285 |
305 RunPixelTestWithReadbackTarget(background, | 286 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 287 background, |
306 green.get(), | 288 green.get(), |
307 base::FilePath(FILE_PATH_LITERAL( | 289 base::FilePath(FILE_PATH_LITERAL( |
308 "green_small_with_blue_corner.png"))); | 290 "green_small_with_blue_corner.png"))); |
309 } | 291 } |
310 | 292 |
311 TEST_F(LayerTreeHostReadbackPixelTest, | 293 TEST_F(LayerTreeHostReadbackPixelTest, |
312 ReadbackSmallNonRootLayerWithChild_GL_Bitmap) { | 294 ReadbackSmallNonRootLayerWithChild_GL_Bitmap) { |
313 use_gl_ = true; | |
314 force_readback_as_bitmap_ = true; | |
315 | |
316 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 295 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
317 gfx::Rect(200, 200), SK_ColorWHITE); | 296 gfx::Rect(200, 200), SK_ColorWHITE); |
318 | 297 |
319 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 298 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
320 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 299 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
321 background->AddChild(green); | 300 background->AddChild(green); |
322 | 301 |
323 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 302 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
324 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | 303 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); |
325 green->AddChild(blue); | 304 green->AddChild(blue); |
326 | 305 |
327 RunPixelTestWithReadbackTarget(background, | 306 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, |
| 307 background, |
328 green.get(), | 308 green.get(), |
329 base::FilePath(FILE_PATH_LITERAL( | 309 base::FilePath(FILE_PATH_LITERAL( |
330 "green_small_with_blue_corner.png"))); | 310 "green_small_with_blue_corner.png"))); |
331 } | 311 } |
332 | 312 |
333 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayerWithChild_GL) { | 313 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSmallNonRootLayerWithChild_GL) { |
334 use_gl_ = true; | |
335 force_readback_as_bitmap_ = false; | |
336 | |
337 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 314 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
338 gfx::Rect(200, 200), SK_ColorWHITE); | 315 gfx::Rect(200, 200), SK_ColorWHITE); |
339 | 316 |
340 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 317 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
341 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); | 318 gfx::Rect(100, 100, 100, 100), SK_ColorGREEN); |
342 background->AddChild(green); | 319 background->AddChild(green); |
343 | 320 |
344 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 321 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
345 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); | 322 gfx::Rect(50, 50, 50, 50), SK_ColorBLUE); |
346 green->AddChild(blue); | 323 green->AddChild(blue); |
347 | 324 |
348 RunPixelTestWithReadbackTarget(background, | 325 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
349 green.get(), | 326 background, |
350 base::FilePath(FILE_PATH_LITERAL( | 327 green.get(), |
351 "green_small_with_blue_corner.png"))); | 328 base::FilePath(FILE_PATH_LITERAL( |
| 329 "green_small_with_blue_corner.png"))); |
| 330 } |
| 331 |
| 332 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_Software) { |
| 333 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 334 gfx::Rect(200, 200), SK_ColorWHITE); |
| 335 |
| 336 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 337 gfx::Rect(200, 200), SK_ColorGREEN); |
| 338 background->AddChild(green); |
| 339 |
| 340 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 341 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
| 342 green->AddChild(blue); |
| 343 |
| 344 // Grab the middle of the root layer. |
| 345 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 346 |
| 347 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
| 348 background, |
| 349 base::FilePath(FILE_PATH_LITERAL( |
| 350 "green_small_with_blue_corner.png"))); |
| 351 } |
| 352 |
| 353 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL_Bitmap) { |
| 354 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 355 gfx::Rect(200, 200), SK_ColorWHITE); |
| 356 |
| 357 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 358 gfx::Rect(200, 200), SK_ColorGREEN); |
| 359 background->AddChild(green); |
| 360 |
| 361 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 362 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
| 363 green->AddChild(blue); |
| 364 |
| 365 // Grab the middle of the root layer. |
| 366 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 367 |
| 368 RunPixelTest(GL_WITH_BITMAP, |
| 369 background, |
| 370 base::FilePath(FILE_PATH_LITERAL( |
| 371 "green_small_with_blue_corner.png"))); |
| 372 } |
| 373 |
| 374 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL) { |
| 375 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 376 gfx::Rect(200, 200), SK_ColorWHITE); |
| 377 |
| 378 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 379 gfx::Rect(200, 200), SK_ColorGREEN); |
| 380 background->AddChild(green); |
| 381 |
| 382 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 383 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
| 384 green->AddChild(blue); |
| 385 |
| 386 // Grab the middle of the root layer. |
| 387 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 388 |
| 389 RunPixelTest(GL_WITH_DEFAULT, |
| 390 background, |
| 391 base::FilePath(FILE_PATH_LITERAL( |
| 392 "green_small_with_blue_corner.png"))); |
| 393 } |
| 394 |
| 395 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_Software) { |
| 396 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 397 gfx::Rect(200, 200), SK_ColorWHITE); |
| 398 |
| 399 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 400 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
| 401 background->AddChild(green); |
| 402 |
| 403 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 404 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
| 405 green->AddChild(blue); |
| 406 |
| 407 // Grab the middle of the green layer. |
| 408 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
| 409 |
| 410 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 411 background, |
| 412 green.get(), |
| 413 base::FilePath(FILE_PATH_LITERAL( |
| 414 "green_small_with_blue_corner.png"))); |
| 415 } |
| 416 |
| 417 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL_Bitmap) { |
| 418 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 419 gfx::Rect(200, 200), SK_ColorWHITE); |
| 420 |
| 421 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 422 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
| 423 background->AddChild(green); |
| 424 |
| 425 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 426 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
| 427 green->AddChild(blue); |
| 428 |
| 429 // Grab the middle of the green layer. |
| 430 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
| 431 |
| 432 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, |
| 433 background, |
| 434 green.get(), |
| 435 base::FilePath(FILE_PATH_LITERAL( |
| 436 "green_small_with_blue_corner.png"))); |
| 437 } |
| 438 |
| 439 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL) { |
| 440 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 441 gfx::Rect(200, 200), SK_ColorWHITE); |
| 442 |
| 443 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
| 444 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
| 445 background->AddChild(green); |
| 446 |
| 447 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
| 448 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
| 449 green->AddChild(blue); |
| 450 |
| 451 // Grab the middle of the green layer. |
| 452 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
| 453 |
| 454 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 455 background, |
| 456 green.get(), |
| 457 base::FilePath(FILE_PATH_LITERAL( |
| 458 "green_small_with_blue_corner.png"))); |
| 459 } |
| 460 |
| 461 class LayerTreeHostReadbackDeviceScalePixelTest |
| 462 : public LayerTreeHostReadbackPixelTest { |
| 463 protected: |
| 464 LayerTreeHostReadbackDeviceScalePixelTest() |
| 465 : device_scale_factor_(1.f), |
| 466 white_client_(SK_ColorWHITE), |
| 467 green_client_(SK_ColorGREEN), |
| 468 blue_client_(SK_ColorBLUE) {} |
| 469 |
| 470 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 471 // Cause the device scale factor to be inherited by contents scales. |
| 472 settings->layer_transforms_should_scale_layer_contents = true; |
| 473 } |
| 474 |
| 475 virtual void SetupTree() OVERRIDE { |
| 476 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 477 LayerTreePixelTest::SetupTree(); |
| 478 } |
| 479 |
| 480 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 481 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 482 |
| 483 LayerImpl* background_impl = root_impl->children()[0]; |
| 484 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x()); |
| 485 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y()); |
| 486 |
| 487 LayerImpl* green_impl = background_impl->children()[0]; |
| 488 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x()); |
| 489 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y()); |
| 490 |
| 491 LayerImpl* blue_impl = green_impl->children()[0]; |
| 492 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x()); |
| 493 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y()); |
| 494 } |
| 495 |
| 496 float device_scale_factor_; |
| 497 SolidColorContentLayerClient white_client_; |
| 498 SolidColorContentLayerClient green_client_; |
| 499 SolidColorContentLayerClient blue_client_; |
| 500 }; |
| 501 |
| 502 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 503 ReadbackSubrect_Software) { |
| 504 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 505 background->SetAnchorPoint(gfx::PointF()); |
| 506 background->SetBounds(gfx::Size(100, 100)); |
| 507 background->SetIsDrawable(true); |
| 508 |
| 509 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 510 green->SetAnchorPoint(gfx::PointF()); |
| 511 green->SetBounds(gfx::Size(100, 100)); |
| 512 green->SetIsDrawable(true); |
| 513 background->AddChild(green); |
| 514 |
| 515 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 516 blue->SetAnchorPoint(gfx::PointF()); |
| 517 blue->SetPosition(gfx::Point(50, 50)); |
| 518 blue->SetBounds(gfx::Size(25, 25)); |
| 519 blue->SetIsDrawable(true); |
| 520 green->AddChild(blue); |
| 521 |
| 522 // Grab the middle of the root layer. |
| 523 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 524 device_scale_factor_ = 2.f; |
| 525 |
| 526 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
| 527 background, |
| 528 base::FilePath(FILE_PATH_LITERAL( |
| 529 "green_small_with_blue_corner.png"))); |
| 530 } |
| 531 |
| 532 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 533 ReadbackSubrect_GL) { |
| 534 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 535 background->SetAnchorPoint(gfx::PointF()); |
| 536 background->SetBounds(gfx::Size(100, 100)); |
| 537 background->SetIsDrawable(true); |
| 538 |
| 539 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 540 green->SetAnchorPoint(gfx::PointF()); |
| 541 green->SetBounds(gfx::Size(100, 100)); |
| 542 green->SetIsDrawable(true); |
| 543 background->AddChild(green); |
| 544 |
| 545 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 546 blue->SetAnchorPoint(gfx::PointF()); |
| 547 blue->SetPosition(gfx::Point(50, 50)); |
| 548 blue->SetBounds(gfx::Size(25, 25)); |
| 549 blue->SetIsDrawable(true); |
| 550 green->AddChild(blue); |
| 551 |
| 552 // Grab the middle of the root layer. |
| 553 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 554 device_scale_factor_ = 2.f; |
| 555 |
| 556 RunPixelTest(GL_WITH_DEFAULT, |
| 557 background, |
| 558 base::FilePath(FILE_PATH_LITERAL( |
| 559 "green_small_with_blue_corner.png"))); |
| 560 } |
| 561 |
| 562 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 563 ReadbackNonRootLayerSubrect_Software) { |
| 564 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 565 background->SetAnchorPoint(gfx::PointF()); |
| 566 background->SetBounds(gfx::Size(100, 100)); |
| 567 background->SetIsDrawable(true); |
| 568 |
| 569 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 570 green->SetAnchorPoint(gfx::PointF()); |
| 571 green->SetPosition(gfx::Point(10, 20)); |
| 572 green->SetBounds(gfx::Size(90, 80)); |
| 573 green->SetIsDrawable(true); |
| 574 background->AddChild(green); |
| 575 |
| 576 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 577 blue->SetAnchorPoint(gfx::PointF()); |
| 578 blue->SetPosition(gfx::Point(50, 50)); |
| 579 blue->SetBounds(gfx::Size(25, 25)); |
| 580 blue->SetIsDrawable(true); |
| 581 green->AddChild(blue); |
| 582 |
| 583 // Grab the green layer's content with blue in the bottom right. |
| 584 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 585 device_scale_factor_ = 2.f; |
| 586 |
| 587 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 588 background, |
| 589 green.get(), |
| 590 base::FilePath(FILE_PATH_LITERAL( |
| 591 "green_small_with_blue_corner.png"))); |
| 592 } |
| 593 |
| 594 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 595 ReadbackNonRootLayerSubrect_GL) { |
| 596 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 597 background->SetAnchorPoint(gfx::PointF()); |
| 598 background->SetBounds(gfx::Size(100, 100)); |
| 599 background->SetIsDrawable(true); |
| 600 |
| 601 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 602 green->SetAnchorPoint(gfx::PointF()); |
| 603 green->SetPosition(gfx::Point(10, 20)); |
| 604 green->SetBounds(gfx::Size(90, 80)); |
| 605 green->SetIsDrawable(true); |
| 606 background->AddChild(green); |
| 607 |
| 608 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 609 blue->SetAnchorPoint(gfx::PointF()); |
| 610 blue->SetPosition(gfx::Point(50, 50)); |
| 611 blue->SetBounds(gfx::Size(25, 25)); |
| 612 blue->SetIsDrawable(true); |
| 613 green->AddChild(blue); |
| 614 |
| 615 // Grab the green layer's content with blue in the bottom right. |
| 616 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 617 device_scale_factor_ = 2.f; |
| 618 |
| 619 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 620 background, |
| 621 green.get(), |
| 622 base::FilePath(FILE_PATH_LITERAL( |
| 623 "green_small_with_blue_corner.png"))); |
| 624 } |
| 625 |
| 626 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest |
| 627 : public LayerTreePixelTest { |
| 628 protected: |
| 629 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest() |
| 630 : device_scale_factor_(1.f), |
| 631 white_client_(SK_ColorWHITE), |
| 632 green_client_(SK_ColorGREEN), |
| 633 blue_client_(SK_ColorBLUE) {} |
| 634 |
| 635 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 636 // Cause the device scale factor to be inherited by contents scales. |
| 637 settings->layer_transforms_should_scale_layer_contents = true; |
| 638 } |
| 639 |
| 640 virtual void SetupTree() OVERRIDE { |
| 641 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 642 LayerTreePixelTest::SetupTree(); |
| 643 } |
| 644 |
| 645 virtual void BeginTest() OVERRIDE { |
| 646 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor()); |
| 647 if (TestEnded()) |
| 648 return; |
| 649 |
| 650 gfx::Rect device_viewport_copy_rect( |
| 651 layer_tree_host()->device_viewport_size()); |
| 652 if (!device_viewport_copy_subrect_.IsEmpty()) |
| 653 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_); |
| 654 |
| 655 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 656 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 657 device_viewport_copy_rect.width(), |
| 658 device_viewport_copy_rect.height()); |
| 659 bitmap->allocPixels(); |
| 660 { |
| 661 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap)); |
| 662 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(), |
| 663 device_viewport_copy_rect); |
| 664 } |
| 665 |
| 666 result_bitmap_ = bitmap.Pass(); |
| 667 EndTest(); |
| 668 } |
| 669 |
| 670 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 671 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 672 |
| 673 LayerImpl* background_impl = root_impl->children()[0]; |
| 674 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x()); |
| 675 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y()); |
| 676 |
| 677 LayerImpl* green_impl = background_impl->children()[0]; |
| 678 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x()); |
| 679 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y()); |
| 680 |
| 681 LayerImpl* blue_impl = green_impl->children()[0]; |
| 682 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x()); |
| 683 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y()); |
| 684 } |
| 685 |
| 686 gfx::Rect device_viewport_copy_subrect_; |
| 687 float device_scale_factor_; |
| 688 SolidColorContentLayerClient white_client_; |
| 689 SolidColorContentLayerClient green_client_; |
| 690 SolidColorContentLayerClient blue_client_; |
| 691 }; |
| 692 |
| 693 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 694 CompositeAndReadback_Software_1) { |
| 695 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 696 background->SetAnchorPoint(gfx::PointF()); |
| 697 background->SetBounds(gfx::Size(200, 200)); |
| 698 background->SetIsDrawable(true); |
| 699 |
| 700 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 701 green->SetAnchorPoint(gfx::PointF()); |
| 702 green->SetBounds(gfx::Size(200, 200)); |
| 703 green->SetIsDrawable(true); |
| 704 background->AddChild(green); |
| 705 |
| 706 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 707 blue->SetAnchorPoint(gfx::PointF()); |
| 708 blue->SetPosition(gfx::Point(100, 100)); |
| 709 blue->SetBounds(gfx::Size(50, 50)); |
| 710 blue->SetIsDrawable(true); |
| 711 green->AddChild(blue); |
| 712 |
| 713 // Grab the middle of the device viewport. |
| 714 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 715 device_scale_factor_ = 1.f; |
| 716 |
| 717 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 718 background, |
| 719 green.get(), |
| 720 base::FilePath(FILE_PATH_LITERAL( |
| 721 "green_small_with_blue_corner.png"))); |
| 722 } |
| 723 |
| 724 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 725 CompositeAndReadback_Software_2) { |
| 726 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 727 background->SetAnchorPoint(gfx::PointF()); |
| 728 background->SetBounds(gfx::Size(100, 100)); |
| 729 background->SetIsDrawable(true); |
| 730 |
| 731 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 732 green->SetAnchorPoint(gfx::PointF()); |
| 733 green->SetBounds(gfx::Size(100, 100)); |
| 734 green->SetIsDrawable(true); |
| 735 background->AddChild(green); |
| 736 |
| 737 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 738 blue->SetAnchorPoint(gfx::PointF()); |
| 739 blue->SetPosition(gfx::Point(50, 50)); |
| 740 blue->SetBounds(gfx::Size(25, 25)); |
| 741 blue->SetIsDrawable(true); |
| 742 green->AddChild(blue); |
| 743 |
| 744 // Grab the middle of the device viewport. |
| 745 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 746 device_scale_factor_ = 2.f; |
| 747 |
| 748 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 749 background, |
| 750 green.get(), |
| 751 base::FilePath(FILE_PATH_LITERAL( |
| 752 "green_small_with_blue_corner.png"))); |
| 753 } |
| 754 |
| 755 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 756 CompositeAndReadback_GL_1) { |
| 757 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 758 background->SetAnchorPoint(gfx::PointF()); |
| 759 background->SetBounds(gfx::Size(200, 200)); |
| 760 background->SetIsDrawable(true); |
| 761 |
| 762 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 763 green->SetAnchorPoint(gfx::PointF()); |
| 764 green->SetBounds(gfx::Size(200, 200)); |
| 765 green->SetIsDrawable(true); |
| 766 background->AddChild(green); |
| 767 |
| 768 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 769 blue->SetAnchorPoint(gfx::PointF()); |
| 770 blue->SetPosition(gfx::Point(100, 100)); |
| 771 blue->SetBounds(gfx::Size(50, 50)); |
| 772 blue->SetIsDrawable(true); |
| 773 green->AddChild(blue); |
| 774 |
| 775 // Grab the middle of the device viewport. |
| 776 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 777 device_scale_factor_ = 1.f; |
| 778 |
| 779 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 780 background, |
| 781 green.get(), |
| 782 base::FilePath(FILE_PATH_LITERAL( |
| 783 "green_small_with_blue_corner.png"))); |
| 784 } |
| 785 |
| 786 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 787 CompositeAndReadback_GL_2) { |
| 788 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 789 background->SetAnchorPoint(gfx::PointF()); |
| 790 background->SetBounds(gfx::Size(100, 100)); |
| 791 background->SetIsDrawable(true); |
| 792 |
| 793 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 794 green->SetAnchorPoint(gfx::PointF()); |
| 795 green->SetBounds(gfx::Size(100, 100)); |
| 796 green->SetIsDrawable(true); |
| 797 background->AddChild(green); |
| 798 |
| 799 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 800 blue->SetAnchorPoint(gfx::PointF()); |
| 801 blue->SetPosition(gfx::Point(50, 50)); |
| 802 blue->SetBounds(gfx::Size(25, 25)); |
| 803 blue->SetIsDrawable(true); |
| 804 green->AddChild(blue); |
| 805 |
| 806 // Grab the middle of the device viewport. |
| 807 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 808 device_scale_factor_ = 2.f; |
| 809 |
| 810 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 811 background, |
| 812 green.get(), |
| 813 base::FilePath(FILE_PATH_LITERAL( |
| 814 "green_small_with_blue_corner.png"))); |
352 } | 815 } |
353 | 816 |
354 } // namespace | 817 } // namespace |
355 } // namespace cc | 818 } // namespace cc |
356 | 819 |
357 #endif // OS_ANDROID | 820 #endif // OS_ANDROID |
OLD | NEW |