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 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap
[0][0]);
180 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap
[0][1]);
181 CreateBitmap(gfx::Size(32, 32), "discardable", &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
<SkPixelRef
*> pixel_refs
;
204 raster
->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 1.0, &pixel_refs
);
205 EXPECT_EQ(1u, pixel_refs
.size());
206 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
209 std::vector
<SkPixelRef
*> pixel_refs
;
210 raster
->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 2.0, &pixel_refs
);
211 EXPECT_EQ(1u, pixel_refs
.size());
212 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
215 std::vector
<SkPixelRef
*> pixel_refs
;
216 raster
->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), 0.5, &pixel_refs
);
217 EXPECT_EQ(1u, pixel_refs
.size());
218 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
220 // Shifted tile sized iterators. These should find only one pixel ref.
222 std::vector
<SkPixelRef
*> pixel_refs
;
223 raster
->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), 1.0, &pixel_refs
);
224 EXPECT_EQ(1u, pixel_refs
.size());
225 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[0]);
228 std::vector
<SkPixelRef
*> pixel_refs
;
229 raster
->GatherPixelRefs(gfx::Rect(520, 520, 512, 512), 2.0, &pixel_refs
);
230 EXPECT_EQ(1u, pixel_refs
.size());
231 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[0]);
234 std::vector
<SkPixelRef
*> pixel_refs
;
235 raster
->GatherPixelRefs(gfx::Rect(130, 130, 128, 128), 0.5, &pixel_refs
);
236 EXPECT_EQ(1u, pixel_refs
.size());
237 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[0]);
239 // Ensure there's no discardable pixel refs in the empty cell
241 std::vector
<SkPixelRef
*> pixel_refs
;
242 raster
->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), 1.0, &pixel_refs
);
243 EXPECT_EQ(0u, pixel_refs
.size());
245 // Layer sized iterators. These should find three pixel ref.
247 std::vector
<SkPixelRef
*> pixel_refs
;
248 raster
->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), 1.0, &pixel_refs
);
249 EXPECT_EQ(3u, pixel_refs
.size());
250 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
251 EXPECT_EQ(discardable_bitmap
[0][1].pixelRef(), pixel_refs
[1]);
252 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[2]);
255 std::vector
<SkPixelRef
*> pixel_refs
;
256 raster
->GatherPixelRefs(gfx::Rect(0, 0, 1024, 1024), 2.0, &pixel_refs
);
257 EXPECT_EQ(3u, pixel_refs
.size());
258 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
259 EXPECT_EQ(discardable_bitmap
[0][1].pixelRef(), pixel_refs
[1]);
260 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[2]);
263 std::vector
<SkPixelRef
*> pixel_refs
;
264 raster
->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), 0.5, &pixel_refs
);
265 EXPECT_EQ(3u, pixel_refs
.size());
266 EXPECT_EQ(discardable_bitmap
[0][0].pixelRef(), pixel_refs
[0]);
267 EXPECT_EQ(discardable_bitmap
[0][1].pixelRef(), pixel_refs
[1]);
268 EXPECT_EQ(discardable_bitmap
[1][1].pixelRef(), pixel_refs
[2]);
272 TEST(DisplayListRasterSourceTest
, RasterFullContents
) {
273 gfx::Size
layer_bounds(3, 5);
274 float contents_scale
= 1.5f
;
275 float raster_divisions
= 2.f
;
277 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
278 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
279 recording_source
->SetBackgroundColor(SK_ColorBLACK
);
280 recording_source
->SetClearCanvasWithDebugColor(false);
282 // Because the caller sets content opaque, it also promises that it
283 // has at least filled in layer_bounds opaquely.
285 white_paint
.setColor(SK_ColorWHITE
);
286 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
288 recording_source
->Rerecord();
290 scoped_refptr
<DisplayListRasterSource
> raster
=
291 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
292 recording_source
.get(), false);
294 gfx::Size
content_bounds(
295 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
297 // Simulate drawing into different tiles at different offsets.
298 int step_x
= std::ceil(content_bounds
.width() / raster_divisions
);
299 int step_y
= std::ceil(content_bounds
.height() / raster_divisions
);
300 for (int offset_x
= 0; offset_x
< content_bounds
.width();
301 offset_x
+= step_x
) {
302 for (int offset_y
= 0; offset_y
< content_bounds
.height();
303 offset_y
+= step_y
) {
304 gfx::Rect
content_rect(offset_x
, offset_y
, step_x
, step_y
);
305 content_rect
.Intersect(gfx::Rect(content_bounds
));
307 // Simulate a canvas rect larger than the content rect. Every pixel
308 // up to one pixel outside the content rect is guaranteed to be opaque.
309 // Outside of that is undefined.
310 gfx::Rect
canvas_rect(content_rect
);
311 canvas_rect
.Inset(0, 0, -1, -1);
314 bitmap
.allocN32Pixels(canvas_rect
.width(), canvas_rect
.height());
315 SkCanvas
canvas(bitmap
);
316 canvas
.clear(SK_ColorTRANSPARENT
);
318 raster
->PlaybackToCanvas(&canvas
, canvas_rect
, canvas_rect
,
321 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
322 int num_pixels
= bitmap
.width() * bitmap
.height();
323 bool all_white
= true;
324 for (int i
= 0; i
< num_pixels
; ++i
) {
325 EXPECT_EQ(SkColorGetA(pixels
[i
]), 255u);
326 all_white
&= (SkColorGetR(pixels
[i
]) == 255);
327 all_white
&= (SkColorGetG(pixels
[i
]) == 255);
328 all_white
&= (SkColorGetB(pixels
[i
]) == 255);
331 // If the canvas doesn't extend past the edge of the content,
332 // it should be entirely white. Otherwise, the edge of the content
333 // will be non-white.
334 EXPECT_EQ(all_white
, gfx::Rect(content_bounds
).Contains(canvas_rect
));
339 TEST(DisplayListRasterSourceTest
, RasterPartialContents
) {
340 gfx::Size
layer_bounds(3, 5);
341 float contents_scale
= 1.5f
;
343 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
344 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
345 recording_source
->SetBackgroundColor(SK_ColorGREEN
);
346 recording_source
->SetClearCanvasWithDebugColor(false);
348 // First record everything as white.
350 white_paint
.setColor(SK_ColorWHITE
);
351 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
353 recording_source
->Rerecord();
355 scoped_refptr
<DisplayListRasterSource
> raster
=
356 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
357 recording_source
.get(), false);
359 gfx::Size
content_bounds(
360 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
363 bitmap
.allocN32Pixels(content_bounds
.width(), content_bounds
.height());
364 SkCanvas
canvas(bitmap
);
365 canvas
.clear(SK_ColorTRANSPARENT
);
367 // Playback the full rect which should make everything white.
368 gfx::Rect
raster_full_rect(content_bounds
);
369 gfx::Rect
playback_rect(content_bounds
);
370 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
374 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
375 for (int i
= 0; i
< bitmap
.width(); ++i
) {
376 for (int j
= 0; j
< bitmap
.height(); ++j
) {
379 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
380 EXPECT_EQ(255u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
381 EXPECT_EQ(255u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
382 EXPECT_EQ(255u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
387 // Re-record everything as black.
389 black_paint
.setColor(SK_ColorBLACK
);
390 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
392 recording_source
->Rerecord();
394 // Make a new RasterSource from the new recording.
395 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
396 recording_source
.get(), false);
398 // We're going to playback from "everything is black" into a smaller area,
399 // that touches the edge pixels of the recording.
400 playback_rect
.Inset(1, 2, 0, 1);
401 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
404 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
407 for (int i
= 0; i
< bitmap
.width(); ++i
) {
408 for (int j
= 0; j
< bitmap
.height(); ++j
) {
411 bool expect_black
= playback_rect
.Contains(i
, j
);
413 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
414 EXPECT_EQ(0u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
415 EXPECT_EQ(0u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
416 EXPECT_EQ(0u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
419 EXPECT_EQ(255u, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
420 EXPECT_EQ(255u, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
421 EXPECT_EQ(255u, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
422 EXPECT_EQ(255u, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
427 EXPECT_GT(num_black
, 0);
428 EXPECT_GT(num_white
, 0);
431 TEST(DisplayListRasterSourceTest
, RasterPartialClear
) {
432 gfx::Size
layer_bounds(3, 5);
433 gfx::Size
partial_bounds(2, 4);
434 float contents_scale
= 1.5f
;
436 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
437 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
438 recording_source
->SetBackgroundColor(SK_ColorGREEN
);
439 recording_source
->SetRequiresClear(true);
440 recording_source
->SetClearCanvasWithDebugColor(false);
442 // First record everything as white.
443 const unsigned alpha_dark
= 10u;
445 white_paint
.setColor(SK_ColorWHITE
);
446 white_paint
.setAlpha(alpha_dark
);
447 recording_source
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
449 recording_source
->Rerecord();
451 scoped_refptr
<DisplayListRasterSource
> raster
=
452 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
453 recording_source
.get(), false);
455 gfx::Size
content_bounds(
456 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
459 bitmap
.allocN32Pixels(content_bounds
.width(), content_bounds
.height());
460 SkCanvas
canvas(bitmap
);
461 canvas
.clear(SK_ColorTRANSPARENT
);
463 // Playback the full rect which should make everything light gray (alpha=10).
464 gfx::Rect
raster_full_rect(content_bounds
);
465 gfx::Rect
playback_rect(content_bounds
);
466 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
470 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
471 for (int i
= 0; i
< bitmap
.width(); ++i
) {
472 for (int j
= 0; j
< bitmap
.height(); ++j
) {
475 EXPECT_EQ(alpha_dark
, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
476 EXPECT_EQ(alpha_dark
, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
477 EXPECT_EQ(alpha_dark
, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
478 EXPECT_EQ(alpha_dark
, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
483 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source_light
=
484 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
485 recording_source_light
->SetBackgroundColor(SK_ColorGREEN
);
486 recording_source_light
->SetRequiresClear(true);
487 recording_source_light
->SetClearCanvasWithDebugColor(false);
489 // Record everything as a slightly lighter white.
490 const unsigned alpha_light
= 18u;
491 white_paint
.setAlpha(alpha_light
);
492 recording_source_light
->add_draw_rect_with_paint(gfx::Rect(layer_bounds
),
494 recording_source_light
->Rerecord();
496 // Make a new RasterSource from the new recording.
497 raster
= DisplayListRasterSource::CreateFromDisplayListRecordingSource(
498 recording_source_light
.get(), false);
500 // We're going to playback from alpha(18) white rectangle into a smaller area
501 // of the recording resulting in a smaller lighter white rectangle over a
502 // darker white background rectangle.
503 playback_rect
= gfx::Rect(
504 gfx::ToCeiledSize(gfx::ScaleSize(partial_bounds
, contents_scale
)));
505 raster
->PlaybackToCanvas(&canvas
, raster_full_rect
, playback_rect
,
508 // Test that the whole playback_rect was cleared and repainted with new alpha.
509 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
510 for (int i
= 0; i
< playback_rect
.width(); ++i
) {
511 for (int j
= 0; j
< playback_rect
.height(); ++j
) {
514 EXPECT_EQ(alpha_light
, SkColorGetA(pixels
[i
+ j
* bitmap
.width()]));
515 EXPECT_EQ(alpha_light
, SkColorGetR(pixels
[i
+ j
* bitmap
.width()]));
516 EXPECT_EQ(alpha_light
, SkColorGetG(pixels
[i
+ j
* bitmap
.width()]));
517 EXPECT_EQ(alpha_light
, SkColorGetB(pixels
[i
+ j
* bitmap
.width()]));
522 TEST(DisplayListRasterSourceTest
, RasterContentsTransparent
) {
523 gfx::Size
layer_bounds(5, 3);
524 float contents_scale
= 0.5f
;
526 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
527 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
528 recording_source
->SetBackgroundColor(SK_ColorTRANSPARENT
);
529 recording_source
->SetRequiresClear(true);
530 recording_source
->SetClearCanvasWithDebugColor(false);
531 recording_source
->Rerecord();
533 scoped_refptr
<DisplayListRasterSource
> raster
=
534 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
535 recording_source
.get(), false);
536 gfx::Size
content_bounds(
537 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds
, contents_scale
)));
539 gfx::Rect
canvas_rect(content_bounds
);
540 canvas_rect
.Inset(0, 0, -1, -1);
543 bitmap
.allocN32Pixels(canvas_rect
.width(), canvas_rect
.height());
544 SkCanvas
canvas(bitmap
);
546 raster
->PlaybackToCanvas(&canvas
, canvas_rect
, canvas_rect
, contents_scale
);
548 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
549 int num_pixels
= bitmap
.width() * bitmap
.height();
550 for (int i
= 0; i
< num_pixels
; ++i
) {
551 EXPECT_EQ(SkColorGetA(pixels
[i
]), 0u);
555 TEST(DisplayListRasterSourceTest
,
556 GetPictureMemoryUsageIncludesClientReportedMemory
) {
557 const size_t kReportedMemoryUsageInBytes
= 100 * 1024 * 1024;
558 gfx::Size
layer_bounds(5, 3);
559 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
560 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds
);
561 recording_source
->set_reported_memory_usage(kReportedMemoryUsageInBytes
);
562 recording_source
->Rerecord();
564 scoped_refptr
<DisplayListRasterSource
> raster
=
565 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
566 recording_source
.get(), false);
567 size_t total_memory_usage
= raster
->GetPictureMemoryUsage();
568 EXPECT_GE(total_memory_usage
, kReportedMemoryUsageInBytes
);
569 EXPECT_LT(total_memory_usage
, 2 * kReportedMemoryUsageInBytes
);