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 "cc/playback/raster_source.h" | 5 #include "cc/playback/raster_source.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "cc/test/fake_recording_source.h" | 11 #include "cc/test/fake_recording_source.h" |
12 #include "cc/test/skia_common.h" | 12 #include "cc/test/skia_common.h" |
13 #include "cc/tiles/software_image_decode_cache.h" | 13 #include "cc/tiles/software_image_decode_cache.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/skia/include/core/SkPixelRef.h" | 15 #include "third_party/skia/include/core/SkPixelRef.h" |
16 #include "third_party/skia/include/core/SkRefCnt.h" | 16 #include "third_party/skia/include/core/SkRefCnt.h" |
17 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) { | 24 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) { |
25 gfx::Size layer_bounds(400, 400); | 25 gfx::Size layer_bounds(400, 400); |
26 | 26 |
27 std::unique_ptr<FakeRecordingSource> recording_source = | 27 std::unique_ptr<FakeRecordingSource> recording_source = |
28 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 28 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
29 | 29 |
30 SkPaint solid_paint; | 30 PaintFlags solid_paint; |
31 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 31 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
32 solid_paint.setColor(solid_color); | 32 solid_paint.setColor(solid_color); |
33 | 33 |
34 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 34 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
35 SkColor color = SK_ColorTRANSPARENT; | 35 SkColor color = SK_ColorTRANSPARENT; |
36 SkPaint non_solid_paint; | 36 PaintFlags non_solid_paint; |
37 bool is_solid_color = false; | 37 bool is_solid_color = false; |
38 non_solid_paint.setColor(non_solid_color); | 38 non_solid_paint.setColor(non_solid_color); |
39 | 39 |
40 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 40 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
41 solid_paint); | 41 solid_paint); |
42 recording_source->Rerecord(); | 42 recording_source->Rerecord(); |
43 | 43 |
44 scoped_refptr<RasterSource> raster = | 44 scoped_refptr<RasterSource> raster = |
45 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 45 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
46 | 46 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { | 95 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { |
96 gfx::Size layer_bounds(400, 400); | 96 gfx::Size layer_bounds(400, 400); |
97 | 97 |
98 std::unique_ptr<FakeRecordingSource> recording_source = | 98 std::unique_ptr<FakeRecordingSource> recording_source = |
99 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 99 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
100 | 100 |
101 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 101 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
102 SkColor color = SK_ColorTRANSPARENT; | 102 SkColor color = SK_ColorTRANSPARENT; |
103 SkPaint solid_paint; | 103 PaintFlags solid_paint; |
104 bool is_solid_color = false; | 104 bool is_solid_color = false; |
105 solid_paint.setColor(solid_color); | 105 solid_paint.setColor(solid_color); |
106 | 106 |
107 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 107 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
108 SkPaint non_solid_paint; | 108 PaintFlags non_solid_paint; |
109 non_solid_paint.setColor(non_solid_color); | 109 non_solid_paint.setColor(non_solid_color); |
110 | 110 |
111 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), | 111 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), |
112 solid_paint); | 112 solid_paint); |
113 recording_source->Rerecord(); | 113 recording_source->Rerecord(); |
114 | 114 |
115 scoped_refptr<RasterSource> raster = | 115 scoped_refptr<RasterSource> raster = |
116 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 116 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
117 | 117 |
118 // Ensure everything is solid. | 118 // Ensure everything is solid. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 float contents_scale = 1.5f; | 246 float contents_scale = 1.5f; |
247 float raster_divisions = 2.f; | 247 float raster_divisions = 2.f; |
248 | 248 |
249 std::unique_ptr<FakeRecordingSource> recording_source = | 249 std::unique_ptr<FakeRecordingSource> recording_source = |
250 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 250 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
251 recording_source->SetBackgroundColor(SK_ColorBLACK); | 251 recording_source->SetBackgroundColor(SK_ColorBLACK); |
252 recording_source->SetClearCanvasWithDebugColor(false); | 252 recording_source->SetClearCanvasWithDebugColor(false); |
253 | 253 |
254 // Because the caller sets content opaque, it also promises that it | 254 // Because the caller sets content opaque, it also promises that it |
255 // has at least filled in layer_bounds opaquely. | 255 // has at least filled in layer_bounds opaquely. |
256 SkPaint white_paint; | 256 PaintFlags white_paint; |
257 white_paint.setColor(SK_ColorWHITE); | 257 white_paint.setColor(SK_ColorWHITE); |
258 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 258 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
259 white_paint); | 259 white_paint); |
260 recording_source->Rerecord(); | 260 recording_source->Rerecord(); |
261 | 261 |
262 scoped_refptr<RasterSource> raster = | 262 scoped_refptr<RasterSource> raster = |
263 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 263 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
264 | 264 |
265 gfx::Size content_bounds( | 265 gfx::Size content_bounds( |
266 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 266 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
267 | 267 |
268 // Simulate drawing into different tiles at different offsets. | 268 // Simulate drawing into different tiles at different offsets. |
269 int step_x = std::ceil(content_bounds.width() / raster_divisions); | 269 int step_x = std::ceil(content_bounds.width() / raster_divisions); |
270 int step_y = std::ceil(content_bounds.height() / raster_divisions); | 270 int step_y = std::ceil(content_bounds.height() / raster_divisions); |
271 for (int offset_x = 0; offset_x < content_bounds.width(); | 271 for (int offset_x = 0; offset_x < content_bounds.width(); |
272 offset_x += step_x) { | 272 offset_x += step_x) { |
273 for (int offset_y = 0; offset_y < content_bounds.height(); | 273 for (int offset_y = 0; offset_y < content_bounds.height(); |
274 offset_y += step_y) { | 274 offset_y += step_y) { |
275 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); | 275 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); |
276 content_rect.Intersect(gfx::Rect(content_bounds)); | 276 content_rect.Intersect(gfx::Rect(content_bounds)); |
277 | 277 |
278 // Simulate a canvas rect larger than the content rect. Every pixel | 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. | 279 // up to one pixel outside the content rect is guaranteed to be opaque. |
280 // Outside of that is undefined. | 280 // Outside of that is undefined. |
281 gfx::Rect canvas_rect(content_rect); | 281 gfx::Rect canvas_rect(content_rect); |
282 canvas_rect.Inset(0, 0, -1, -1); | 282 canvas_rect.Inset(0, 0, -1, -1); |
283 | 283 |
284 SkBitmap bitmap; | 284 SkBitmap bitmap; |
285 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 285 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
286 SkCanvas canvas(bitmap); | 286 PaintCanvas canvas(bitmap); |
287 canvas.clear(SK_ColorTRANSPARENT); | 287 canvas.clear(SK_ColorTRANSPARENT); |
288 | 288 |
289 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, | 289 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, |
290 contents_scale, | 290 contents_scale, |
291 RasterSource::PlaybackSettings()); | 291 RasterSource::PlaybackSettings()); |
292 | 292 |
293 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 293 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
294 int num_pixels = bitmap.width() * bitmap.height(); | 294 int num_pixels = bitmap.width() * bitmap.height(); |
295 bool all_white = true; | 295 bool all_white = true; |
296 for (int i = 0; i < num_pixels; ++i) { | 296 for (int i = 0; i < num_pixels; ++i) { |
(...skipping 14 matching lines...) Expand all Loading... |
311 TEST(RasterSourceTest, RasterPartialContents) { | 311 TEST(RasterSourceTest, RasterPartialContents) { |
312 gfx::Size layer_bounds(3, 5); | 312 gfx::Size layer_bounds(3, 5); |
313 float contents_scale = 1.5f; | 313 float contents_scale = 1.5f; |
314 | 314 |
315 std::unique_ptr<FakeRecordingSource> recording_source = | 315 std::unique_ptr<FakeRecordingSource> recording_source = |
316 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 316 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
317 recording_source->SetBackgroundColor(SK_ColorGREEN); | 317 recording_source->SetBackgroundColor(SK_ColorGREEN); |
318 recording_source->SetClearCanvasWithDebugColor(false); | 318 recording_source->SetClearCanvasWithDebugColor(false); |
319 | 319 |
320 // First record everything as white. | 320 // First record everything as white. |
321 SkPaint white_paint; | 321 PaintFlags white_paint; |
322 white_paint.setColor(SK_ColorWHITE); | 322 white_paint.setColor(SK_ColorWHITE); |
323 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 323 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
324 white_paint); | 324 white_paint); |
325 recording_source->Rerecord(); | 325 recording_source->Rerecord(); |
326 | 326 |
327 scoped_refptr<RasterSource> raster = | 327 scoped_refptr<RasterSource> raster = |
328 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 328 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
329 | 329 |
330 gfx::Size content_bounds( | 330 gfx::Size content_bounds( |
331 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 331 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
332 | 332 |
333 SkBitmap bitmap; | 333 SkBitmap bitmap; |
334 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 334 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
335 SkCanvas canvas(bitmap); | 335 PaintCanvas canvas(bitmap); |
336 canvas.clear(SK_ColorTRANSPARENT); | 336 canvas.clear(SK_ColorTRANSPARENT); |
337 | 337 |
338 // Playback the full rect which should make everything white. | 338 // Playback the full rect which should make everything white. |
339 gfx::Rect raster_full_rect(content_bounds); | 339 gfx::Rect raster_full_rect(content_bounds); |
340 gfx::Rect playback_rect(content_bounds); | 340 gfx::Rect playback_rect(content_bounds); |
341 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 341 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
342 contents_scale, RasterSource::PlaybackSettings()); | 342 contents_scale, RasterSource::PlaybackSettings()); |
343 | 343 |
344 { | 344 { |
345 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 345 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
346 for (int i = 0; i < bitmap.width(); ++i) { | 346 for (int i = 0; i < bitmap.width(); ++i) { |
347 for (int j = 0; j < bitmap.height(); ++j) { | 347 for (int j = 0; j < bitmap.height(); ++j) { |
348 SCOPED_TRACE(i); | 348 SCOPED_TRACE(i); |
349 SCOPED_TRACE(j); | 349 SCOPED_TRACE(j); |
350 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); | 350 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); |
351 EXPECT_EQ(255u, SkColorGetR(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()])); | 352 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); |
353 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); | 353 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); |
354 } | 354 } |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 // Re-record everything as black. | 358 // Re-record everything as black. |
359 SkPaint black_paint; | 359 PaintFlags black_paint; |
360 black_paint.setColor(SK_ColorBLACK); | 360 black_paint.setColor(SK_ColorBLACK); |
361 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 361 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
362 black_paint); | 362 black_paint); |
363 recording_source->Rerecord(); | 363 recording_source->Rerecord(); |
364 | 364 |
365 // Make a new RasterSource from the new recording. | 365 // Make a new RasterSource from the new recording. |
366 raster = | 366 raster = |
367 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 367 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
368 | 368 |
369 // We're going to playback from "everything is black" into a smaller area, | 369 // We're going to playback from "everything is black" into a smaller area, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 float contents_scale = 1.5f; | 405 float contents_scale = 1.5f; |
406 | 406 |
407 std::unique_ptr<FakeRecordingSource> recording_source = | 407 std::unique_ptr<FakeRecordingSource> recording_source = |
408 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 408 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
409 recording_source->SetBackgroundColor(SK_ColorGREEN); | 409 recording_source->SetBackgroundColor(SK_ColorGREEN); |
410 recording_source->SetRequiresClear(true); | 410 recording_source->SetRequiresClear(true); |
411 recording_source->SetClearCanvasWithDebugColor(false); | 411 recording_source->SetClearCanvasWithDebugColor(false); |
412 | 412 |
413 // First record everything as white. | 413 // First record everything as white. |
414 const unsigned alpha_dark = 10u; | 414 const unsigned alpha_dark = 10u; |
415 SkPaint white_paint; | 415 PaintFlags white_paint; |
416 white_paint.setColor(SK_ColorWHITE); | 416 white_paint.setColor(SK_ColorWHITE); |
417 white_paint.setAlpha(alpha_dark); | 417 white_paint.setAlpha(alpha_dark); |
418 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 418 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
419 white_paint); | 419 white_paint); |
420 recording_source->Rerecord(); | 420 recording_source->Rerecord(); |
421 | 421 |
422 scoped_refptr<RasterSource> raster = | 422 scoped_refptr<RasterSource> raster = |
423 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 423 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
424 | 424 |
425 gfx::Size content_bounds( | 425 gfx::Size content_bounds( |
426 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 426 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
427 | 427 |
428 SkBitmap bitmap; | 428 SkBitmap bitmap; |
429 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 429 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
430 SkCanvas canvas(bitmap); | 430 PaintCanvas canvas(bitmap); |
431 canvas.clear(SK_ColorTRANSPARENT); | 431 canvas.clear(SK_ColorTRANSPARENT); |
432 | 432 |
433 // Playback the full rect which should make everything light gray (alpha=10). | 433 // Playback the full rect which should make everything light gray (alpha=10). |
434 gfx::Rect raster_full_rect(content_bounds); | 434 gfx::Rect raster_full_rect(content_bounds); |
435 gfx::Rect playback_rect(content_bounds); | 435 gfx::Rect playback_rect(content_bounds); |
436 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 436 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
437 contents_scale, RasterSource::PlaybackSettings()); | 437 contents_scale, RasterSource::PlaybackSettings()); |
438 | 438 |
439 { | 439 { |
440 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 440 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 scoped_refptr<RasterSource> raster = | 503 scoped_refptr<RasterSource> raster = |
504 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 504 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
505 gfx::Size content_bounds( | 505 gfx::Size content_bounds( |
506 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 506 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
507 | 507 |
508 gfx::Rect canvas_rect(content_bounds); | 508 gfx::Rect canvas_rect(content_bounds); |
509 canvas_rect.Inset(0, 0, -1, -1); | 509 canvas_rect.Inset(0, 0, -1, -1); |
510 | 510 |
511 SkBitmap bitmap; | 511 SkBitmap bitmap; |
512 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 512 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
513 SkCanvas canvas(bitmap); | 513 PaintCanvas canvas(bitmap); |
514 | 514 |
515 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale, | 515 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale, |
516 RasterSource::PlaybackSettings()); | 516 RasterSource::PlaybackSettings()); |
517 | 517 |
518 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 518 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
519 int num_pixels = bitmap.width() * bitmap.height(); | 519 int num_pixels = bitmap.width() * bitmap.height(); |
520 for (int i = 0; i < num_pixels; ++i) { | 520 for (int i = 0; i < num_pixels; ++i) { |
521 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 521 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
522 } | 522 } |
523 } | 523 } |
(...skipping 21 matching lines...) Expand all Loading... |
545 // scaling). Note that we paint an image first, so that we can force image | 545 // scaling). Note that we paint an image first, so that we can force image |
546 // hijack canvas to be used. | 546 // hijack canvas to be used. |
547 std::unique_ptr<FakeRecordingSource> recording_source = | 547 std::unique_ptr<FakeRecordingSource> recording_source = |
548 FakeRecordingSource::CreateFilledRecordingSource(size); | 548 FakeRecordingSource::CreateFilledRecordingSource(size); |
549 | 549 |
550 // 1. Paint the image. | 550 // 1. Paint the image. |
551 recording_source->add_draw_image(CreateDiscardableImage(gfx::Size(5, 5)), | 551 recording_source->add_draw_image(CreateDiscardableImage(gfx::Size(5, 5)), |
552 gfx::Point(0, 0)); | 552 gfx::Point(0, 0)); |
553 | 553 |
554 // 2. Cover everything in red. | 554 // 2. Cover everything in red. |
555 SkPaint paint; | 555 PaintFlags paint; |
556 paint.setColor(SK_ColorRED); | 556 paint.setColor(SK_ColorRED); |
557 recording_source->add_draw_rect_with_paint(gfx::Rect(size), paint); | 557 recording_source->add_draw_rect_with_paint(gfx::Rect(size), paint); |
558 | 558 |
559 // 3. Draw 4x4 green rects into every corner. | 559 // 3. Draw 4x4 green rects into every corner. |
560 paint.setColor(SK_ColorGREEN); | 560 paint.setColor(SK_ColorGREEN); |
561 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 4, 4), paint); | 561 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 4, 4), paint); |
562 recording_source->add_draw_rect_with_paint( | 562 recording_source->add_draw_rect_with_paint( |
563 gfx::Rect(size.width() - 4, 0, 4, 4), paint); | 563 gfx::Rect(size.width() - 4, 0, 4, 4), paint); |
564 recording_source->add_draw_rect_with_paint( | 564 recording_source->add_draw_rect_with_paint( |
565 gfx::Rect(0, size.height() - 4, 4, 4), paint); | 565 gfx::Rect(0, size.height() - 4, 4, 4), paint); |
566 recording_source->add_draw_rect_with_paint( | 566 recording_source->add_draw_rect_with_paint( |
567 gfx::Rect(size.width() - 4, size.height() - 4, 4, 4), paint); | 567 gfx::Rect(size.width() - 4, size.height() - 4, 4, 4), paint); |
568 | 568 |
569 recording_source->SetGenerateDiscardableImagesMetadata(true); | 569 recording_source->SetGenerateDiscardableImagesMetadata(true); |
570 recording_source->Rerecord(); | 570 recording_source->Rerecord(); |
571 | 571 |
572 bool can_use_lcd = true; | 572 bool can_use_lcd = true; |
573 scoped_refptr<RasterSource> raster_source = | 573 scoped_refptr<RasterSource> raster_source = |
574 recording_source->CreateRasterSource(can_use_lcd); | 574 recording_source->CreateRasterSource(can_use_lcd); |
575 SoftwareImageDecodeCache controller( | 575 SoftwareImageDecodeCache controller( |
576 ResourceFormat::RGBA_8888, | 576 ResourceFormat::RGBA_8888, |
577 LayerTreeSettings().software_decoded_image_budget_bytes); | 577 LayerTreeSettings().software_decoded_image_budget_bytes); |
578 raster_source->set_image_decode_cache(&controller); | 578 raster_source->set_image_decode_cache(&controller); |
579 | 579 |
580 SkBitmap bitmap; | 580 SkBitmap bitmap; |
581 bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f); | 581 bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f); |
582 SkCanvas canvas(bitmap); | 582 PaintCanvas canvas(bitmap); |
583 canvas.scale(0.5f, 0.25f); | 583 canvas.scale(0.5f, 0.25f); |
584 | 584 |
585 RasterSource::PlaybackSettings settings; | 585 RasterSource::PlaybackSettings settings; |
586 settings.playback_to_shared_canvas = true; | 586 settings.playback_to_shared_canvas = true; |
587 settings.use_image_hijack_canvas = true; | 587 settings.use_image_hijack_canvas = true; |
588 raster_source->PlaybackToCanvas(&canvas, gfx::Rect(size), gfx::Rect(size), | 588 raster_source->PlaybackToCanvas(&canvas, gfx::Rect(size), gfx::Rect(size), |
589 1.f, settings); | 589 1.f, settings); |
590 | 590 |
591 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0)); | 591 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0)); |
592 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0)); | 592 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0)); |
593 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); | 593 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); |
594 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); | 594 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); |
595 for (int x = 0; x < 49; ++x) | 595 for (int x = 0; x < 49; ++x) |
596 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); | 596 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); |
597 for (int y = 0; y < 24; ++y) | 597 for (int y = 0; y < 24; ++y) |
598 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); | 598 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); |
599 } | 599 } |
600 | 600 |
601 } // namespace | 601 } // namespace |
602 } // namespace cc | 602 } // namespace cc |
OLD | NEW |