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 "base/memory/scoped_ptr.h"
6 #include "cc/playback/display_list_raster_source.h"
7 #include "cc/test/fake_display_list_recording_source.h"
8 #include "cc/test/skia_common.h"
9 #include "skia/ext/refptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkPixelRef.h"
12 #include "third_party/skia/include/core/SkShader.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size_conversions.h"
19 TEST(DisplayListRasterSourceTest
, AnalyzeIsSolidUnscaled
) {
20 gfx::Size
layer_bounds(400, 400);
22 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
23 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
26 SkColor solid_color
= SkColorSetARGB(255, 12, 23, 34);
27 solid_paint
.setColor(solid_color
);
29 SkColor non_solid_color
= SkColorSetARGB(128, 45, 56, 67);
30 SkPaint non_solid_paint
;
31 non_solid_paint
.setColor(non_solid_color
);
33 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
35 recording_source
->Rerecord();
37 scoped_refptr
<DisplayListRasterSource
> raster
=
38 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
39 recording_source
.get(), false);
41 // Ensure everything is solid.
42 for (int y
= 0; y
<= 300; y
+= 100) {
43 for (int x
= 0; x
<= 300; x
+= 100) {
44 RasterSource::SolidColorAnalysis analysis
;
45 gfx::Rect
rect(x
, y
, 100, 100);
46 raster
->PerformSolidColorAnalysis(rect
, 1.0, &analysis
);
47 EXPECT_TRUE(analysis
.is_solid_color
) << rect
.ToString();
48 EXPECT_EQ(solid_color
, analysis
.solid_color
) << rect
.ToString();
52 // Add one non-solid pixel and recreate the raster source.
53 recording_source
->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
55 recording_source
->Rerecord();
56 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
57 recording_source
.get(), false);
59 RasterSource::SolidColorAnalysis analysis
;
60 raster
->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis
);
61 EXPECT_FALSE(analysis
.is_solid_color
);
63 raster
->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0,
65 EXPECT_TRUE(analysis
.is_solid_color
);
66 EXPECT_EQ(solid_color
, analysis
.solid_color
);
68 // Boundaries should be clipped.
69 analysis
.is_solid_color
= false;
70 raster
->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0,
72 EXPECT_TRUE(analysis
.is_solid_color
);
73 EXPECT_EQ(solid_color
, analysis
.solid_color
);
75 analysis
.is_solid_color
= false;
76 raster
->PerformSolidColorAnalysis(gfx::Rect(0, 350, 100, 100), 1.0,
78 EXPECT_TRUE(analysis
.is_solid_color
);
79 EXPECT_EQ(solid_color
, analysis
.solid_color
);
81 analysis
.is_solid_color
= false;
82 raster
->PerformSolidColorAnalysis(gfx::Rect(350, 350, 100, 100), 1.0,
84 EXPECT_TRUE(analysis
.is_solid_color
);
85 EXPECT_EQ(solid_color
, analysis
.solid_color
);
88 TEST(DisplayListRasterSourceTest
, AnalyzeIsSolidScaled
) {
89 gfx::Size
layer_bounds(400, 400);
91 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
92 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
94 SkColor solid_color
= SkColorSetARGB(255, 12, 23, 34);
96 solid_paint
.setColor(solid_color
);
98 SkColor non_solid_color
= SkColorSetARGB(128, 45, 56, 67);
99 SkPaint non_solid_paint
;
100 non_solid_paint
.setColor(non_solid_color
);
102 recording_source
->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
104 recording_source
->Rerecord();
106 scoped_refptr
<DisplayListRasterSource
> raster
=
107 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
108 recording_source
.get(), false);
110 // Ensure everything is solid.
111 for (int y
= 0; y
<= 30; y
+= 10) {
112 for (int x
= 0; x
<= 30; x
+= 10) {
113 RasterSource::SolidColorAnalysis analysis
;
114 gfx::Rect
rect(x
, y
, 10, 10);
115 raster
->PerformSolidColorAnalysis(rect
, 0.1f
, &analysis
);
116 EXPECT_TRUE(analysis
.is_solid_color
) << rect
.ToString();
117 EXPECT_EQ(analysis
.solid_color
, solid_color
) << rect
.ToString();
121 // Add one non-solid pixel and recreate the raster source.
122 recording_source
->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
124 recording_source
->Rerecord();
125 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
126 recording_source
.get(), false);
128 RasterSource::SolidColorAnalysis analysis
;
129 raster
->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f
, &analysis
);
130 EXPECT_FALSE(analysis
.is_solid_color
);
132 raster
->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f
, &analysis
);
133 EXPECT_TRUE(analysis
.is_solid_color
);
134 EXPECT_EQ(analysis
.solid_color
, solid_color
);
136 // Boundaries should be clipped.
137 analysis
.is_solid_color
= false;
138 raster
->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f
, &analysis
);
139 EXPECT_TRUE(analysis
.is_solid_color
);
140 EXPECT_EQ(analysis
.solid_color
, solid_color
);
142 analysis
.is_solid_color
= false;
143 raster
->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f
, &analysis
);
144 EXPECT_TRUE(analysis
.is_solid_color
);
145 EXPECT_EQ(analysis
.solid_color
, solid_color
);
147 analysis
.is_solid_color
= false;
148 raster
->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 0.1f
, &analysis
);
149 EXPECT_TRUE(analysis
.is_solid_color
);
150 EXPECT_EQ(analysis
.solid_color
, solid_color
);
153 TEST(DisplayListRasterSourceTest
, AnalyzeIsSolidEmpty
) {
154 gfx::Size
layer_bounds(400, 400);
156 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
157 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
158 recording_source
->Rerecord();
160 scoped_refptr
<DisplayListRasterSource
> raster
=
161 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
162 recording_source
.get(), false);
163 RasterSource::SolidColorAnalysis analysis
;
164 EXPECT_FALSE(analysis
.is_solid_color
);
166 raster
->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f
, &analysis
);
168 EXPECT_TRUE(analysis
.is_solid_color
);
169 EXPECT_EQ(analysis
.solid_color
, SkColorSetARGB(0, 0, 0, 0));
172 TEST(DisplayListRasterSourceTest
, PixelRefIteratorDiscardableRefsOneTile
) {
173 gfx::Size
layer_bounds(512, 512);
175 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
176 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
178 SkBitmap discardable_bitmap
[2][2];
179 CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap
[0][0]);
180 CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap
[0][1]);
181 CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap
[1][1]);
183 // Discardable pixel refs are found in the following cells:
189 recording_source
->add_draw_bitmap(discardable_bitmap
[0][0], gfx::Point(0, 0));
190 recording_source
->add_draw_bitmap(discardable_bitmap
[0][1],
192 recording_source
->add_draw_bitmap(discardable_bitmap
[1][1],
193 gfx::Point(260, 260));
194 recording_source
->SetGatherPixelRefs(true);
195 recording_source
->Rerecord();
197 scoped_refptr
<DisplayListRasterSource
> raster
=
198 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
199 recording_source
.get(), false);
201 // Tile sized iterators. These should find only one pixel ref.
203 std::vector
<skia::PositionPixelRef
> pixel_refs
;
204 raster
->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs
);
205 EXPECT_EQ(1u, pixel_refs
.size());
206 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0].pixel_ref
);
207 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
208 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
).ToString());
210 // Shifted tile sized iterators. These should find only one pixel ref.
212 std::vector
<skia::PositionPixelRef
> pixel_refs
;
213 raster
->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), &pixel_refs
);
214 EXPECT_EQ(1u, pixel_refs
.size());
215 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[0].pixel_ref
);
216 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(),
217 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
).ToString());
219 // Ensure there's no discardable pixel refs in the empty cell
221 std::vector
<skia::PositionPixelRef
> pixel_refs
;
222 raster
->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), &pixel_refs
);
223 EXPECT_EQ(0u, pixel_refs
.size());
225 // Layer sized iterators. These should find three pixel ref.
227 std::vector
<skia::PositionPixelRef
> pixel_refs
;
228 raster
->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), &pixel_refs
);
229 EXPECT_EQ(3u, pixel_refs
.size());
230 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0].pixel_ref
);
231 EXPECT_EQ(discardable_bitmap
[0][1].pixelRef(), pixel_refs
[1].pixel_ref
);
232 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[2].pixel_ref
);
233 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
234 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
).ToString());
235 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(),
236 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
).ToString());
237 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(),
238 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
).ToString());
242 TEST(DisplayListRasterSourceTest
, RasterFullContents
) {
243 gfx::Size
layer_bounds(3, 5);
244 float contents_scale
= 1.5f
;
245 float raster_divisions
= 2.f
;
247 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
248 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
249 recording_source
->SetBackgroundColor(SK_ColorBLACK
);
250 recording_source
->SetClearCanvasWithDebugColor(false);
252 // Because the caller sets content opaque, it also promises that it
253 // has at least filled in layer_bounds opaquely.
255 white_paint
.setColor(SK_ColorWHITE
);
256 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
258 recording_source
->Rerecord();
260 scoped_refptr
<DisplayListRasterSource
> raster
=
261 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
262 recording_source
.get(), false);
264 gfx::Size
content_bounds(
265 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
267 // Simulate drawing into different tiles at different offsets.
268 int step_x
= std::ceil(content_bounds
.width() / raster_divisions
);
269 int step_y
= std::ceil(content_bounds
.height() / raster_divisions
);
270 for (int offset_x
= 0; offset_x
< content_bounds
.width();
271 offset_x
+= step_x
) {
272 for (int offset_y
= 0; offset_y
< content_bounds
.height();
273 offset_y
+= step_y
) {
274 gfx::Rect
content_rect(offset_x
, offset_y
, step_x
, step_y
);
275 content_rect
.Intersect(gfx::Rect(content_bounds
));
277 // Simulate a canvas rect larger than the content rect. Every pixel
278 // up to one pixel outside the content rect is guaranteed to be opaque.
279 // Outside of that is undefined.
280 gfx::Rect
canvas_rect(content_rect
);
281 canvas_rect
.Inset(0, 0, -1, -1);
284 bitmap
.allocN32Pixels(canvas_rect
.width(), canvas_rect
.height());
285 SkCanvas
canvas(bitmap
);
286 canvas
.clear(SK_ColorTRANSPARENT
);
288 raster
->PlaybackToCanvas(&canvas
, canvas_rect
, canvas_rect
,
291 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
292 int num_pixels
= bitmap
.width() * bitmap
.height();
293 bool all_white
= true;
294 for (int i
= 0; i
< num_pixels
; ++i
) {
295 EXPECT_EQ(SkColorGetA(pixels
[i
]), 255u);
296 all_white
&= (SkColorGetR(pixels
[i
]) == 255);
297 all_white
&= (SkColorGetG(pixels
[i
]) == 255);
298 all_white
&= (SkColorGetB(pixels
[i
]) == 255);
301 // If the canvas doesn't extend past the edge of the content,
302 // it should be entirely white. Otherwise, the edge of the content
303 // will be non-white.
304 EXPECT_EQ(all_white
, gfx::Rect(content_bounds
).Contains(canvas_rect
));
309 TEST(DisplayListRasterSourceTest
, RasterPartialContents
) {
310 gfx::Size
layer_bounds(3, 5);
311 float contents_scale
= 1.5f
;
313 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
314 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
315 recording_source
->SetBackgroundColor(SK_ColorGREEN
);
316 recording_source
->SetClearCanvasWithDebugColor(false);
318 // First record everything as white.
320 white_paint
.setColor(SK_ColorWHITE
);
321 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
323 recording_source
->Rerecord();
325 scoped_refptr
<DisplayListRasterSource
> raster
=
326 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
327 recording_source
.get(), false);
329 gfx::Size
content_bounds(
330 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
333 bitmap
.allocN32Pixels(content_bounds
.width(), content_bounds
.height());
334 SkCanvas
canvas(bitmap
);
335 canvas
.clear(SK_ColorTRANSPARENT
);
337 // Playback the full rect which should make everything white.
338 gfx::Rect
raster_full_rect(content_bounds
);
339 gfx::Rect
playback_rect(content_bounds
);
340 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
344 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
345 for (int i
= 0; i
< bitmap
.width(); ++i
) {
346 for (int j
= 0; j
< bitmap
.height(); ++j
) {
349 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
350 EXPECT_EQ(255u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
351 EXPECT_EQ(255u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
352 EXPECT_EQ(255u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
357 // Re-record everything as black.
359 black_paint
.setColor(SK_ColorBLACK
);
360 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
362 recording_source
->Rerecord();
364 // Make a new RasterSource from the new recording.
365 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
366 recording_source
.get(), false);
368 // We're going to playback from "everything is black" into a smaller area,
369 // that touches the edge pixels of the recording.
370 playback_rect
.Inset(1, 2, 0, 1);
371 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
374 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
377 for (int i
= 0; i
< bitmap
.width(); ++i
) {
378 for (int j
= 0; j
< bitmap
.height(); ++j
) {
381 bool expect_black
= playback_rect
.Contains(i
, j
);
383 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
384 EXPECT_EQ(0u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
385 EXPECT_EQ(0u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
386 EXPECT_EQ(0u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
389 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
390 EXPECT_EQ(255u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
391 EXPECT_EQ(255u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
392 EXPECT_EQ(255u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
397 EXPECT_GT(num_black
, 0);
398 EXPECT_GT(num_white
, 0);
401 TEST(DisplayListRasterSourceTest
, RasterPartialClear
) {
402 gfx::Size
layer_bounds(3, 5);
403 gfx::Size
partial_bounds(2, 4);
404 float contents_scale
= 1.5f
;
406 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
407 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
408 recording_source
->SetBackgroundColor(SK_ColorGREEN
);
409 recording_source
->SetRequiresClear(true);
410 recording_source
->SetClearCanvasWithDebugColor(false);
412 // First record everything as white.
413 const unsigned alpha_dark
= 10u;
415 white_paint
.setColor(SK_ColorWHITE
);
416 white_paint
.setAlpha(alpha_dark
);
417 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
419 recording_source
->Rerecord();
421 scoped_refptr
<DisplayListRasterSource
> raster
=
422 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
423 recording_source
.get(), false);
425 gfx::Size
content_bounds(
426 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
429 bitmap
.allocN32Pixels(content_bounds
.width(), content_bounds
.height());
430 SkCanvas
canvas(bitmap
);
431 canvas
.clear(SK_ColorTRANSPARENT
);
433 // Playback the full rect which should make everything light gray (alpha=10).
434 gfx::Rect
raster_full_rect(content_bounds
);
435 gfx::Rect
playback_rect(content_bounds
);
436 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
440 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
441 for (int i
= 0; i
< bitmap
.width(); ++i
) {
442 for (int j
= 0; j
< bitmap
.height(); ++j
) {
445 EXPECT_EQ(alpha_dark
, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
446 EXPECT_EQ(alpha_dark
, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
447 EXPECT_EQ(alpha_dark
, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
448 EXPECT_EQ(alpha_dark
, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
453 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source_light
=
454 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
455 recording_source_light
->SetBackgroundColor(SK_ColorGREEN
);
456 recording_source_light
->SetRequiresClear(true);
457 recording_source_light
->SetClearCanvasWithDebugColor(false);
459 // Record everything as a slightly lighter white.
460 const unsigned alpha_light
= 18u;
461 white_paint
.setAlpha(alpha_light
);
462 recording_source_light
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
464 recording_source_light
->Rerecord();
466 // Make a new RasterSource from the new recording.
467 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
468 recording_source_light
.get(), false);
470 // We're going to playback from alpha(18) white rectangle into a smaller area
471 // of the recording resulting in a smaller lighter white rectangle over a
472 // darker white background rectangle.
473 playback_rect
= gfx::Rect(
474 gfx::ToCeiledSize(gfx::ScaleSize(partial_bounds
, contents_scale
)));
475 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
478 // Test that the whole playback_rect was cleared and repainted with new alpha.
479 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
480 for (int i
= 0; i
< playback_rect
.width(); ++i
) {
481 for (int j
= 0; j
< playback_rect
.height(); ++j
) {
484 EXPECT_EQ(alpha_light
, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
485 EXPECT_EQ(alpha_light
, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
486 EXPECT_EQ(alpha_light
, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
487 EXPECT_EQ(alpha_light
, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
492 TEST(DisplayListRasterSourceTest
, RasterContentsTransparent
) {
493 gfx::Size
layer_bounds(5, 3);
494 float contents_scale
= 0.5f
;
496 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
497 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
498 recording_source
->SetBackgroundColor(SK_ColorTRANSPARENT
);
499 recording_source
->SetRequiresClear(true);
500 recording_source
->SetClearCanvasWithDebugColor(false);
501 recording_source
->Rerecord();
503 scoped_refptr
<DisplayListRasterSource
> raster
=
504 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
505 recording_source
.get(), false);
506 gfx::Size
content_bounds(
507 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
509 gfx::Rect
canvas_rect(content_bounds
);
510 canvas_rect
.Inset(0, 0, -1, -1);
513 bitmap
.allocN32Pixels(canvas_rect
.width(), canvas_rect
.height());
514 SkCanvas
canvas(bitmap
);
516 raster
->PlaybackToCanvas(&canvas
, canvas_rect
, canvas_rect
, contents_scale
);
518 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
519 int num_pixels
= bitmap
.width() * bitmap
.height();
520 for (int i
= 0; i
< num_pixels
; ++i
) {
521 EXPECT_EQ(SkColorGetA(pixels
[i
]), 0u);
525 TEST(DisplayListRasterSourceTest
,
526 GetPictureMemoryUsageIncludesClientReportedMemory
) {
527 const size_t kReportedMemoryUsageInBytes
= 100 * 1024 * 1024;
528 gfx::Size
layer_bounds(5, 3);
529 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
530 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
531 recording_source
->set_reported_memory_usage(kReportedMemoryUsageInBytes
);
532 recording_source
->Rerecord();
534 scoped_refptr
<DisplayListRasterSource
> raster
=
535 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
536 recording_source
.get(), false);
537 size_t total_memory_usage
= raster
->GetPictureMemoryUsage();
538 EXPECT_GE(total_memory_usage
, kReportedMemoryUsageInBytes
);
539 EXPECT_LT(total_memory_usage
, 2 * kReportedMemoryUsageInBytes
);