Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / cc / playback / display_list_raster_source_unittest.cc
blob33cd4ae2c695b93e76739441d869f438b1219e4e
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"
16 namespace cc {
17 namespace {
19 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidUnscaled) {
20 gfx::Size layer_bounds(400, 400);
22 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
23 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
25 SkPaint solid_paint;
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),
34 solid_paint);
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),
54 non_solid_paint);
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,
64 &analysis);
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,
71 &analysis);
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,
77 &analysis);
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,
83 &analysis);
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);
95 SkPaint solid_paint;
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),
103 solid_paint);
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),
123 non_solid_paint);
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 skia::RefPtr<SkImage> discardable_image[2][2];
179 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32));
180 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32));
181 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32));
183 // Discardable pixel refs are found in the following cells:
184 // |---|---|
185 // | x | x |
186 // |---|---|
187 // | | x |
188 // |---|---|
189 recording_source->add_draw_image(discardable_image[0][0].get(),
190 gfx::Point(0, 0));
191 recording_source->add_draw_image(discardable_image[0][1].get(),
192 gfx::Point(260, 0));
193 recording_source->add_draw_image(discardable_image[1][1].get(),
194 gfx::Point(260, 260));
195 recording_source->SetGatherDiscardableImages(true);
196 recording_source->Rerecord();
198 scoped_refptr<DisplayListRasterSource> raster =
199 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
200 recording_source.get(), false);
202 // Tile sized iterators. These should find only one pixel ref.
204 std::vector<skia::PositionImage> images;
205 raster->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images);
206 EXPECT_EQ(1u, images.size());
207 EXPECT_EQ(discardable_image[0][0].get(), images[0].image);
208 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
209 gfx::SkRectToRectF(images[0].image_rect).ToString());
211 // Shifted tile sized iterators. These should find only one pixel ref.
213 std::vector<skia::PositionImage> images;
214 raster->GatherDiscardableImages(gfx::Rect(260, 260, 256, 256), &images);
215 EXPECT_EQ(1u, images.size());
216 EXPECT_EQ(discardable_image[1][1].get(), images[0].image);
217 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(),
218 gfx::SkRectToRectF(images[0].image_rect).ToString());
220 // Ensure there's no discardable pixel refs in the empty cell
222 std::vector<skia::PositionImage> images;
223 raster->GatherDiscardableImages(gfx::Rect(0, 256, 256, 256), &images);
224 EXPECT_EQ(0u, images.size());
226 // Layer sized iterators. These should find three pixel ref.
228 std::vector<skia::PositionImage> images;
229 raster->GatherDiscardableImages(gfx::Rect(0, 0, 512, 512), &images);
230 EXPECT_EQ(3u, images.size());
231 EXPECT_EQ(discardable_image[0][0].get(), images[0].image);
232 EXPECT_EQ(discardable_image[0][1].get(), images[1].image);
233 EXPECT_EQ(discardable_image[1][1].get(), images[2].image);
234 EXPECT_EQ(gfx::RectF(32, 32).ToString(),
235 gfx::SkRectToRectF(images[0].image_rect).ToString());
236 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(),
237 gfx::SkRectToRectF(images[1].image_rect).ToString());
238 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(),
239 gfx::SkRectToRectF(images[2].image_rect).ToString());
243 TEST(DisplayListRasterSourceTest, RasterFullContents) {
244 gfx::Size layer_bounds(3, 5);
245 float contents_scale = 1.5f;
246 float raster_divisions = 2.f;
248 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
249 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
250 recording_source->SetBackgroundColor(SK_ColorBLACK);
251 recording_source->SetClearCanvasWithDebugColor(false);
253 // Because the caller sets content opaque, it also promises that it
254 // has at least filled in layer_bounds opaquely.
255 SkPaint white_paint;
256 white_paint.setColor(SK_ColorWHITE);
257 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
258 white_paint);
259 recording_source->Rerecord();
261 scoped_refptr<DisplayListRasterSource> raster =
262 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
263 recording_source.get(), false);
265 gfx::Size content_bounds(
266 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
268 // Simulate drawing into different tiles at different offsets.
269 int step_x = std::ceil(content_bounds.width() / raster_divisions);
270 int step_y = std::ceil(content_bounds.height() / raster_divisions);
271 for (int offset_x = 0; offset_x < content_bounds.width();
272 offset_x += step_x) {
273 for (int offset_y = 0; offset_y < content_bounds.height();
274 offset_y += step_y) {
275 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y);
276 content_rect.Intersect(gfx::Rect(content_bounds));
278 // Simulate a canvas rect larger than the content rect. Every pixel
279 // up to one pixel outside the content rect is guaranteed to be opaque.
280 // Outside of that is undefined.
281 gfx::Rect canvas_rect(content_rect);
282 canvas_rect.Inset(0, 0, -1, -1);
284 SkBitmap bitmap;
285 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
286 SkCanvas canvas(bitmap);
287 canvas.clear(SK_ColorTRANSPARENT);
289 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect,
290 contents_scale);
292 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
293 int num_pixels = bitmap.width() * bitmap.height();
294 bool all_white = true;
295 for (int i = 0; i < num_pixels; ++i) {
296 EXPECT_EQ(SkColorGetA(pixels[i]), 255u);
297 all_white &= (SkColorGetR(pixels[i]) == 255);
298 all_white &= (SkColorGetG(pixels[i]) == 255);
299 all_white &= (SkColorGetB(pixels[i]) == 255);
302 // If the canvas doesn't extend past the edge of the content,
303 // it should be entirely white. Otherwise, the edge of the content
304 // will be non-white.
305 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect));
310 TEST(DisplayListRasterSourceTest, RasterPartialContents) {
311 gfx::Size layer_bounds(3, 5);
312 float contents_scale = 1.5f;
314 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
315 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
316 recording_source->SetBackgroundColor(SK_ColorGREEN);
317 recording_source->SetClearCanvasWithDebugColor(false);
319 // First record everything as white.
320 SkPaint white_paint;
321 white_paint.setColor(SK_ColorWHITE);
322 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
323 white_paint);
324 recording_source->Rerecord();
326 scoped_refptr<DisplayListRasterSource> raster =
327 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
328 recording_source.get(), false);
330 gfx::Size content_bounds(
331 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
333 SkBitmap bitmap;
334 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
335 SkCanvas canvas(bitmap);
336 canvas.clear(SK_ColorTRANSPARENT);
338 // Playback the full rect which should make everything white.
339 gfx::Rect raster_full_rect(content_bounds);
340 gfx::Rect playback_rect(content_bounds);
341 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
342 contents_scale);
345 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
346 for (int i = 0; i < bitmap.width(); ++i) {
347 for (int j = 0; j < bitmap.height(); ++j) {
348 SCOPED_TRACE(i);
349 SCOPED_TRACE(j);
350 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()]));
351 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()]));
352 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()]));
353 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()]));
358 // Re-record everything as black.
359 SkPaint black_paint;
360 black_paint.setColor(SK_ColorBLACK);
361 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
362 black_paint);
363 recording_source->Rerecord();
365 // Make a new RasterSource from the new recording.
366 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource(
367 recording_source.get(), false);
369 // We're going to playback from "everything is black" into a smaller area,
370 // that touches the edge pixels of the recording.
371 playback_rect.Inset(1, 2, 0, 1);
372 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
373 contents_scale);
375 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
376 int num_black = 0;
377 int num_white = 0;
378 for (int i = 0; i < bitmap.width(); ++i) {
379 for (int j = 0; j < bitmap.height(); ++j) {
380 SCOPED_TRACE(j);
381 SCOPED_TRACE(i);
382 bool expect_black = playback_rect.Contains(i, j);
383 if (expect_black) {
384 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()]));
385 EXPECT_EQ(0u, SkColorGetR(pixels[i + j * bitmap.width()]));
386 EXPECT_EQ(0u, SkColorGetG(pixels[i + j * bitmap.width()]));
387 EXPECT_EQ(0u, SkColorGetB(pixels[i + j * bitmap.width()]));
388 ++num_black;
389 } else {
390 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()]));
391 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()]));
392 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()]));
393 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()]));
394 ++num_white;
398 EXPECT_GT(num_black, 0);
399 EXPECT_GT(num_white, 0);
402 TEST(DisplayListRasterSourceTest, RasterPartialClear) {
403 gfx::Size layer_bounds(3, 5);
404 gfx::Size partial_bounds(2, 4);
405 float contents_scale = 1.5f;
407 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
408 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
409 recording_source->SetBackgroundColor(SK_ColorGREEN);
410 recording_source->SetRequiresClear(true);
411 recording_source->SetClearCanvasWithDebugColor(false);
413 // First record everything as white.
414 const unsigned alpha_dark = 10u;
415 SkPaint white_paint;
416 white_paint.setColor(SK_ColorWHITE);
417 white_paint.setAlpha(alpha_dark);
418 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
419 white_paint);
420 recording_source->Rerecord();
422 scoped_refptr<DisplayListRasterSource> raster =
423 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
424 recording_source.get(), false);
426 gfx::Size content_bounds(
427 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
429 SkBitmap bitmap;
430 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
431 SkCanvas canvas(bitmap);
432 canvas.clear(SK_ColorTRANSPARENT);
434 // Playback the full rect which should make everything light gray (alpha=10).
435 gfx::Rect raster_full_rect(content_bounds);
436 gfx::Rect playback_rect(content_bounds);
437 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
438 contents_scale);
441 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
442 for (int i = 0; i < bitmap.width(); ++i) {
443 for (int j = 0; j < bitmap.height(); ++j) {
444 SCOPED_TRACE(i);
445 SCOPED_TRACE(j);
446 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()]));
447 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()]));
448 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()]));
449 EXPECT_EQ(alpha_dark, SkColorGetB(pixels[i + j * bitmap.width()]));
454 scoped_ptr<FakeDisplayListRecordingSource> recording_source_light =
455 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
456 recording_source_light->SetBackgroundColor(SK_ColorGREEN);
457 recording_source_light->SetRequiresClear(true);
458 recording_source_light->SetClearCanvasWithDebugColor(false);
460 // Record everything as a slightly lighter white.
461 const unsigned alpha_light = 18u;
462 white_paint.setAlpha(alpha_light);
463 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
464 white_paint);
465 recording_source_light->Rerecord();
467 // Make a new RasterSource from the new recording.
468 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource(
469 recording_source_light.get(), false);
471 // We're going to playback from alpha(18) white rectangle into a smaller area
472 // of the recording resulting in a smaller lighter white rectangle over a
473 // darker white background rectangle.
474 playback_rect = gfx::Rect(
475 gfx::ToCeiledSize(gfx::ScaleSize(partial_bounds, contents_scale)));
476 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
477 contents_scale);
479 // Test that the whole playback_rect was cleared and repainted with new alpha.
480 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
481 for (int i = 0; i < playback_rect.width(); ++i) {
482 for (int j = 0; j < playback_rect.height(); ++j) {
483 SCOPED_TRACE(j);
484 SCOPED_TRACE(i);
485 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()]));
486 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()]));
487 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()]));
488 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()]));
493 TEST(DisplayListRasterSourceTest, RasterContentsTransparent) {
494 gfx::Size layer_bounds(5, 3);
495 float contents_scale = 0.5f;
497 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
498 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
499 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
500 recording_source->SetRequiresClear(true);
501 recording_source->SetClearCanvasWithDebugColor(false);
502 recording_source->Rerecord();
504 scoped_refptr<DisplayListRasterSource> raster =
505 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
506 recording_source.get(), false);
507 gfx::Size content_bounds(
508 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
510 gfx::Rect canvas_rect(content_bounds);
511 canvas_rect.Inset(0, 0, -1, -1);
513 SkBitmap bitmap;
514 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
515 SkCanvas canvas(bitmap);
517 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale);
519 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
520 int num_pixels = bitmap.width() * bitmap.height();
521 for (int i = 0; i < num_pixels; ++i) {
522 EXPECT_EQ(SkColorGetA(pixels[i]), 0u);
526 TEST(DisplayListRasterSourceTest,
527 GetPictureMemoryUsageIncludesClientReportedMemory) {
528 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024;
529 gfx::Size layer_bounds(5, 3);
530 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
531 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
532 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes);
533 recording_source->Rerecord();
535 scoped_refptr<DisplayListRasterSource> raster =
536 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
537 recording_source.get(), false);
538 size_t total_memory_usage = raster->GetPictureMemoryUsage();
539 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes);
540 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
543 } // namespace
544 } // namespace cc