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 <stddef.h> | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "cc/playback/display_list_raster_source.h" | |
9 #include "cc/test/fake_display_list_recording_source.h" | |
10 #include "cc/test/skia_common.h" | |
11 #include "skia/ext/refptr.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "third_party/skia/include/core/SkPixelRef.h" | |
14 #include "third_party/skia/include/core/SkShader.h" | |
15 #include "ui/gfx/geometry/rect.h" | |
16 #include "ui/gfx/geometry/size_conversions.h" | |
17 | |
18 namespace cc { | |
19 namespace { | |
20 | |
21 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidUnscaled) { | |
22 gfx::Size layer_bounds(400, 400); | |
23 | |
24 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
25 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
26 | |
27 SkPaint solid_paint; | |
28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | |
29 solid_paint.setColor(solid_color); | |
30 | |
31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | |
32 SkColor color = SK_ColorTRANSPARENT; | |
33 SkPaint non_solid_paint; | |
34 bool is_solid_color = false; | |
35 non_solid_paint.setColor(non_solid_color); | |
36 | |
37 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
38 solid_paint); | |
39 recording_source->Rerecord(); | |
40 | |
41 scoped_refptr<DisplayListRasterSource> raster = | |
42 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
43 recording_source.get(), false); | |
44 | |
45 // Ensure everything is solid. | |
46 for (int y = 0; y <= 300; y += 100) { | |
47 for (int x = 0; x <= 300; x += 100) { | |
48 gfx::Rect rect(x, y, 100, 100); | |
49 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.0, &color); | |
50 EXPECT_TRUE(is_solid_color) << rect.ToString(); | |
51 EXPECT_EQ(solid_color, color) << rect.ToString(); | |
52 } | |
53 } | |
54 | |
55 // Add one non-solid pixel and recreate the raster source. | |
56 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | |
57 non_solid_paint); | |
58 recording_source->Rerecord(); | |
59 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
60 recording_source.get(), false); | |
61 | |
62 color = SK_ColorTRANSPARENT; | |
63 is_solid_color = | |
64 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &color); | |
65 EXPECT_FALSE(is_solid_color); | |
66 | |
67 color = SK_ColorTRANSPARENT; | |
68 is_solid_color = raster->PerformSolidColorAnalysis( | |
69 gfx::Rect(100, 0, 100, 100), 1.0, &color); | |
70 EXPECT_TRUE(is_solid_color); | |
71 EXPECT_EQ(solid_color, color); | |
72 | |
73 // Boundaries should be clipped. | |
74 color = SK_ColorTRANSPARENT; | |
75 is_solid_color = raster->PerformSolidColorAnalysis( | |
76 gfx::Rect(350, 0, 100, 100), 1.0, &color); | |
77 EXPECT_TRUE(is_solid_color); | |
78 EXPECT_EQ(solid_color, color); | |
79 | |
80 color = SK_ColorTRANSPARENT; | |
81 is_solid_color = raster->PerformSolidColorAnalysis( | |
82 gfx::Rect(0, 350, 100, 100), 1.0, &color); | |
83 EXPECT_TRUE(is_solid_color); | |
84 EXPECT_EQ(solid_color, color); | |
85 | |
86 color = SK_ColorTRANSPARENT; | |
87 is_solid_color = raster->PerformSolidColorAnalysis( | |
88 gfx::Rect(350, 350, 100, 100), 1.0, &color); | |
89 EXPECT_TRUE(is_solid_color); | |
90 EXPECT_EQ(solid_color, color); | |
91 } | |
92 | |
93 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidScaled) { | |
94 gfx::Size layer_bounds(400, 400); | |
95 | |
96 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
97 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
98 | |
99 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | |
100 SkColor color = SK_ColorTRANSPARENT; | |
101 SkPaint solid_paint; | |
102 bool is_solid_color = false; | |
103 solid_paint.setColor(solid_color); | |
104 | |
105 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | |
106 SkPaint non_solid_paint; | |
107 non_solid_paint.setColor(non_solid_color); | |
108 | |
109 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), | |
110 solid_paint); | |
111 recording_source->Rerecord(); | |
112 | |
113 scoped_refptr<DisplayListRasterSource> raster = | |
114 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
115 recording_source.get(), false); | |
116 | |
117 // Ensure everything is solid. | |
118 for (int y = 0; y <= 30; y += 10) { | |
119 for (int x = 0; x <= 30; x += 10) { | |
120 gfx::Rect rect(x, y, 10, 10); | |
121 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color); | |
122 EXPECT_TRUE(is_solid_color) << rect.ToString(); | |
123 EXPECT_EQ(color, solid_color) << rect.ToString(); | |
124 } | |
125 } | |
126 | |
127 // Add one non-solid pixel and recreate the raster source. | |
128 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | |
129 non_solid_paint); | |
130 recording_source->Rerecord(); | |
131 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
132 recording_source.get(), false); | |
133 | |
134 color = SK_ColorTRANSPARENT; | |
135 is_solid_color = | |
136 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color); | |
137 EXPECT_FALSE(is_solid_color); | |
138 | |
139 color = SK_ColorTRANSPARENT; | |
140 is_solid_color = | |
141 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color); | |
142 EXPECT_TRUE(is_solid_color); | |
143 EXPECT_EQ(color, solid_color); | |
144 | |
145 // Boundaries should be clipped. | |
146 color = SK_ColorTRANSPARENT; | |
147 is_solid_color = | |
148 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &color); | |
149 EXPECT_TRUE(is_solid_color); | |
150 EXPECT_EQ(color, solid_color); | |
151 | |
152 color = SK_ColorTRANSPARENT; | |
153 is_solid_color = | |
154 raster->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &color); | |
155 EXPECT_TRUE(is_solid_color); | |
156 EXPECT_EQ(color, solid_color); | |
157 | |
158 color = SK_ColorTRANSPARENT; | |
159 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), | |
160 0.1f, &color); | |
161 EXPECT_TRUE(is_solid_color); | |
162 EXPECT_EQ(color, solid_color); | |
163 } | |
164 | |
165 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) { | |
166 gfx::Size layer_bounds(400, 400); | |
167 | |
168 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
169 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
170 recording_source->Rerecord(); | |
171 | |
172 scoped_refptr<DisplayListRasterSource> raster = | |
173 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
174 recording_source.get(), false); | |
175 | |
176 SkColor color = SK_ColorTRANSPARENT; | |
177 bool is_solid_color = | |
178 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); | |
179 | |
180 EXPECT_TRUE(is_solid_color); | |
181 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); | |
182 } | |
183 | |
184 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { | |
185 gfx::Size layer_bounds(512, 512); | |
186 | |
187 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
188 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
189 | |
190 skia::RefPtr<SkImage> discardable_image[2][2]; | |
191 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); | |
192 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); | |
193 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); | |
194 | |
195 // Discardable pixel refs are found in the following cells: | |
196 // |---|---| | |
197 // | x | x | | |
198 // |---|---| | |
199 // | | x | | |
200 // |---|---| | |
201 recording_source->add_draw_image(discardable_image[0][0].get(), | |
202 gfx::Point(0, 0)); | |
203 recording_source->add_draw_image(discardable_image[0][1].get(), | |
204 gfx::Point(260, 0)); | |
205 recording_source->add_draw_image(discardable_image[1][1].get(), | |
206 gfx::Point(260, 260)); | |
207 recording_source->SetGenerateDiscardableImagesMetadata(true); | |
208 recording_source->Rerecord(); | |
209 | |
210 scoped_refptr<DisplayListRasterSource> raster = | |
211 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
212 recording_source.get(), false); | |
213 | |
214 // Tile sized iterators. These should find only one pixel ref. | |
215 { | |
216 std::vector<DrawImage> images; | |
217 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), 1.f, &images); | |
218 EXPECT_EQ(1u, images.size()); | |
219 EXPECT_EQ(discardable_image[0][0].get(), images[0].image()); | |
220 } | |
221 // Shifted tile sized iterators. These should find only one pixel ref. | |
222 { | |
223 std::vector<DrawImage> images; | |
224 raster->GetDiscardableImagesInRect(gfx::Rect(260, 260, 256, 256), 1.f, | |
225 &images); | |
226 EXPECT_EQ(1u, images.size()); | |
227 EXPECT_EQ(discardable_image[1][1].get(), images[0].image()); | |
228 } | |
229 // Ensure there's no discardable pixel refs in the empty cell | |
230 { | |
231 std::vector<DrawImage> images; | |
232 raster->GetDiscardableImagesInRect(gfx::Rect(0, 256, 256, 256), 1.f, | |
233 &images); | |
234 EXPECT_EQ(0u, images.size()); | |
235 } | |
236 // Layer sized iterators. These should find three pixel ref. | |
237 { | |
238 std::vector<DrawImage> images; | |
239 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 512, 512), 1.f, &images); | |
240 EXPECT_EQ(3u, images.size()); | |
241 EXPECT_EQ(discardable_image[0][0].get(), images[0].image()); | |
242 EXPECT_EQ(discardable_image[0][1].get(), images[1].image()); | |
243 EXPECT_EQ(discardable_image[1][1].get(), images[2].image()); | |
244 } | |
245 } | |
246 | |
247 TEST(DisplayListRasterSourceTest, RasterFullContents) { | |
248 gfx::Size layer_bounds(3, 5); | |
249 float contents_scale = 1.5f; | |
250 float raster_divisions = 2.f; | |
251 | |
252 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
253 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
254 recording_source->SetBackgroundColor(SK_ColorBLACK); | |
255 recording_source->SetClearCanvasWithDebugColor(false); | |
256 | |
257 // Because the caller sets content opaque, it also promises that it | |
258 // has at least filled in layer_bounds opaquely. | |
259 SkPaint white_paint; | |
260 white_paint.setColor(SK_ColorWHITE); | |
261 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
262 white_paint); | |
263 recording_source->Rerecord(); | |
264 | |
265 scoped_refptr<DisplayListRasterSource> raster = | |
266 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
267 recording_source.get(), false); | |
268 | |
269 gfx::Size content_bounds( | |
270 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | |
271 | |
272 // Simulate drawing into different tiles at different offsets. | |
273 int step_x = std::ceil(content_bounds.width() / raster_divisions); | |
274 int step_y = std::ceil(content_bounds.height() / raster_divisions); | |
275 for (int offset_x = 0; offset_x < content_bounds.width(); | |
276 offset_x += step_x) { | |
277 for (int offset_y = 0; offset_y < content_bounds.height(); | |
278 offset_y += step_y) { | |
279 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); | |
280 content_rect.Intersect(gfx::Rect(content_bounds)); | |
281 | |
282 // Simulate a canvas rect larger than the content rect. Every pixel | |
283 // up to one pixel outside the content rect is guaranteed to be opaque. | |
284 // Outside of that is undefined. | |
285 gfx::Rect canvas_rect(content_rect); | |
286 canvas_rect.Inset(0, 0, -1, -1); | |
287 | |
288 SkBitmap bitmap; | |
289 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | |
290 SkCanvas canvas(bitmap); | |
291 canvas.clear(SK_ColorTRANSPARENT); | |
292 | |
293 const bool include_images = true; | |
294 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, | |
295 contents_scale, include_images); | |
296 | |
297 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
298 int num_pixels = bitmap.width() * bitmap.height(); | |
299 bool all_white = true; | |
300 for (int i = 0; i < num_pixels; ++i) { | |
301 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); | |
302 all_white &= (SkColorGetR(pixels[i]) == 255); | |
303 all_white &= (SkColorGetG(pixels[i]) == 255); | |
304 all_white &= (SkColorGetB(pixels[i]) == 255); | |
305 } | |
306 | |
307 // If the canvas doesn't extend past the edge of the content, | |
308 // it should be entirely white. Otherwise, the edge of the content | |
309 // will be non-white. | |
310 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); | |
311 } | |
312 } | |
313 } | |
314 | |
315 TEST(DisplayListRasterSourceTest, RasterPartialContents) { | |
316 gfx::Size layer_bounds(3, 5); | |
317 float contents_scale = 1.5f; | |
318 | |
319 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
320 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
321 recording_source->SetBackgroundColor(SK_ColorGREEN); | |
322 recording_source->SetClearCanvasWithDebugColor(false); | |
323 | |
324 // First record everything as white. | |
325 SkPaint white_paint; | |
326 white_paint.setColor(SK_ColorWHITE); | |
327 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
328 white_paint); | |
329 recording_source->Rerecord(); | |
330 | |
331 scoped_refptr<DisplayListRasterSource> raster = | |
332 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
333 recording_source.get(), false); | |
334 | |
335 gfx::Size content_bounds( | |
336 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | |
337 | |
338 SkBitmap bitmap; | |
339 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | |
340 SkCanvas canvas(bitmap); | |
341 canvas.clear(SK_ColorTRANSPARENT); | |
342 | |
343 // Playback the full rect which should make everything white. | |
344 gfx::Rect raster_full_rect(content_bounds); | |
345 gfx::Rect playback_rect(content_bounds); | |
346 const bool include_images = true; | |
347 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | |
348 contents_scale, include_images); | |
349 | |
350 { | |
351 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
352 for (int i = 0; i < bitmap.width(); ++i) { | |
353 for (int j = 0; j < bitmap.height(); ++j) { | |
354 SCOPED_TRACE(i); | |
355 SCOPED_TRACE(j); | |
356 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); | |
357 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()])); | |
358 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); | |
359 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); | |
360 } | |
361 } | |
362 } | |
363 | |
364 // Re-record everything as black. | |
365 SkPaint black_paint; | |
366 black_paint.setColor(SK_ColorBLACK); | |
367 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
368 black_paint); | |
369 recording_source->Rerecord(); | |
370 | |
371 // Make a new DisplayListRasterSource from the new recording. | |
372 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
373 recording_source.get(), false); | |
374 | |
375 // We're going to playback from "everything is black" into a smaller area, | |
376 // that touches the edge pixels of the recording. | |
377 playback_rect.Inset(1, 2, 0, 1); | |
378 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | |
379 contents_scale, include_images); | |
380 | |
381 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
382 int num_black = 0; | |
383 int num_white = 0; | |
384 for (int i = 0; i < bitmap.width(); ++i) { | |
385 for (int j = 0; j < bitmap.height(); ++j) { | |
386 SCOPED_TRACE(j); | |
387 SCOPED_TRACE(i); | |
388 bool expect_black = playback_rect.Contains(i, j); | |
389 if (expect_black) { | |
390 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); | |
391 EXPECT_EQ(0u, SkColorGetR(pixels[i + j * bitmap.width()])); | |
392 EXPECT_EQ(0u, SkColorGetG(pixels[i + j * bitmap.width()])); | |
393 EXPECT_EQ(0u, SkColorGetB(pixels[i + j * bitmap.width()])); | |
394 ++num_black; | |
395 } else { | |
396 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); | |
397 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()])); | |
398 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); | |
399 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); | |
400 ++num_white; | |
401 } | |
402 } | |
403 } | |
404 EXPECT_GT(num_black, 0); | |
405 EXPECT_GT(num_white, 0); | |
406 } | |
407 | |
408 TEST(DisplayListRasterSourceTest, RasterPartialClear) { | |
409 gfx::Size layer_bounds(3, 5); | |
410 gfx::Size partial_bounds(2, 4); | |
411 float contents_scale = 1.5f; | |
412 | |
413 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
414 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
415 recording_source->SetBackgroundColor(SK_ColorGREEN); | |
416 recording_source->SetRequiresClear(true); | |
417 recording_source->SetClearCanvasWithDebugColor(false); | |
418 | |
419 // First record everything as white. | |
420 const unsigned alpha_dark = 10u; | |
421 SkPaint white_paint; | |
422 white_paint.setColor(SK_ColorWHITE); | |
423 white_paint.setAlpha(alpha_dark); | |
424 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
425 white_paint); | |
426 recording_source->Rerecord(); | |
427 | |
428 scoped_refptr<DisplayListRasterSource> raster = | |
429 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
430 recording_source.get(), false); | |
431 | |
432 gfx::Size content_bounds( | |
433 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | |
434 | |
435 SkBitmap bitmap; | |
436 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | |
437 SkCanvas canvas(bitmap); | |
438 canvas.clear(SK_ColorTRANSPARENT); | |
439 | |
440 // Playback the full rect which should make everything light gray (alpha=10). | |
441 gfx::Rect raster_full_rect(content_bounds); | |
442 gfx::Rect playback_rect(content_bounds); | |
443 const bool include_images = true; | |
444 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | |
445 contents_scale, include_images); | |
446 | |
447 { | |
448 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
449 for (int i = 0; i < bitmap.width(); ++i) { | |
450 for (int j = 0; j < bitmap.height(); ++j) { | |
451 SCOPED_TRACE(i); | |
452 SCOPED_TRACE(j); | |
453 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()])); | |
454 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()])); | |
455 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()])); | |
456 EXPECT_EQ(alpha_dark, SkColorGetB(pixels[i + j * bitmap.width()])); | |
457 } | |
458 } | |
459 } | |
460 | |
461 scoped_ptr<FakeDisplayListRecordingSource> recording_source_light = | |
462 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
463 recording_source_light->SetBackgroundColor(SK_ColorGREEN); | |
464 recording_source_light->SetRequiresClear(true); | |
465 recording_source_light->SetClearCanvasWithDebugColor(false); | |
466 | |
467 // Record everything as a slightly lighter white. | |
468 const unsigned alpha_light = 18u; | |
469 white_paint.setAlpha(alpha_light); | |
470 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
471 white_paint); | |
472 recording_source_light->Rerecord(); | |
473 | |
474 // Make a new DisplayListRasterSource from the new recording. | |
475 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
476 recording_source_light.get(), false); | |
477 | |
478 // We're going to playback from alpha(18) white rectangle into a smaller area | |
479 // of the recording resulting in a smaller lighter white rectangle over a | |
480 // darker white background rectangle. | |
481 playback_rect = | |
482 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); | |
483 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | |
484 contents_scale, include_images); | |
485 | |
486 // Test that the whole playback_rect was cleared and repainted with new alpha. | |
487 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
488 for (int i = 0; i < playback_rect.width(); ++i) { | |
489 for (int j = 0; j < playback_rect.height(); ++j) { | |
490 SCOPED_TRACE(j); | |
491 SCOPED_TRACE(i); | |
492 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); | |
493 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()])); | |
494 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); | |
495 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()])); | |
496 } | |
497 } | |
498 } | |
499 | |
500 TEST(DisplayListRasterSourceTest, RasterContentsTransparent) { | |
501 gfx::Size layer_bounds(5, 3); | |
502 float contents_scale = 0.5f; | |
503 | |
504 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
505 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
506 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | |
507 recording_source->SetRequiresClear(true); | |
508 recording_source->SetClearCanvasWithDebugColor(false); | |
509 recording_source->Rerecord(); | |
510 | |
511 scoped_refptr<DisplayListRasterSource> raster = | |
512 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
513 recording_source.get(), false); | |
514 gfx::Size content_bounds( | |
515 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | |
516 | |
517 gfx::Rect canvas_rect(content_bounds); | |
518 canvas_rect.Inset(0, 0, -1, -1); | |
519 | |
520 SkBitmap bitmap; | |
521 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | |
522 SkCanvas canvas(bitmap); | |
523 | |
524 const bool include_images = true; | |
525 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale, | |
526 include_images); | |
527 | |
528 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
529 int num_pixels = bitmap.width() * bitmap.height(); | |
530 for (int i = 0; i < num_pixels; ++i) { | |
531 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | |
532 } | |
533 } | |
534 | |
535 TEST(DisplayListRasterSourceTest, | |
536 GetPictureMemoryUsageIncludesClientReportedMemory) { | |
537 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024; | |
538 gfx::Size layer_bounds(5, 3); | |
539 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | |
540 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | |
541 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); | |
542 recording_source->Rerecord(); | |
543 | |
544 scoped_refptr<DisplayListRasterSource> raster = | |
545 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
546 recording_source.get(), false); | |
547 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | |
548 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | |
549 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | |
550 } | |
551 | |
552 } // namespace | |
553 } // namespace cc | |
OLD | NEW |