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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "cc/playback/display_list_raster_source.h" | 6 #include "cc/playback/display_list_raster_source.h" |
7 #include "cc/test/fake_display_list_recording_source.h" | 7 #include "cc/test/fake_display_list_recording_source.h" |
8 #include "cc/test/skia_common.h" | 8 #include "cc/test/skia_common.h" |
9 #include "skia/ext/refptr.h" | 9 #include "skia/ext/refptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 white_paint.setColor(SK_ColorWHITE); | 256 white_paint.setColor(SK_ColorWHITE); |
257 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 257 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
258 white_paint); | 258 white_paint); |
259 recording_source->Rerecord(); | 259 recording_source->Rerecord(); |
260 | 260 |
261 scoped_refptr<DisplayListRasterSource> raster = | 261 scoped_refptr<DisplayListRasterSource> raster = |
262 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 262 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
263 recording_source.get(), false); | 263 recording_source.get(), false); |
264 | 264 |
265 gfx::Size content_bounds( | 265 gfx::Size content_bounds( |
266 gfx::ToCeiledSize(gfx::ScaleSize(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)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 white_paint.setColor(SK_ColorWHITE); | 321 white_paint.setColor(SK_ColorWHITE); |
322 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 322 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
323 white_paint); | 323 white_paint); |
324 recording_source->Rerecord(); | 324 recording_source->Rerecord(); |
325 | 325 |
326 scoped_refptr<DisplayListRasterSource> raster = | 326 scoped_refptr<DisplayListRasterSource> raster = |
327 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 327 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
328 recording_source.get(), false); | 328 recording_source.get(), false); |
329 | 329 |
330 gfx::Size content_bounds( | 330 gfx::Size content_bounds( |
331 gfx::ToCeiledSize(gfx::ScaleSize(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 SkCanvas 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, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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<DisplayListRasterSource> raster = | 422 scoped_refptr<DisplayListRasterSource> raster = |
423 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 423 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
424 recording_source.get(), false); | 424 recording_source.get(), false); |
425 | 425 |
426 gfx::Size content_bounds( | 426 gfx::Size content_bounds( |
427 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 427 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
428 | 428 |
429 SkBitmap bitmap; | 429 SkBitmap bitmap; |
430 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 430 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
431 SkCanvas canvas(bitmap); | 431 SkCanvas canvas(bitmap); |
432 canvas.clear(SK_ColorTRANSPARENT); | 432 canvas.clear(SK_ColorTRANSPARENT); |
433 | 433 |
434 // Playback the full rect which should make everything light gray (alpha=10). | 434 // Playback the full rect which should make everything light gray (alpha=10). |
435 gfx::Rect raster_full_rect(content_bounds); | 435 gfx::Rect raster_full_rect(content_bounds); |
436 gfx::Rect playback_rect(content_bounds); | 436 gfx::Rect playback_rect(content_bounds); |
437 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 437 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
(...skipping 26 matching lines...) Expand all Loading... |
464 white_paint); | 464 white_paint); |
465 recording_source_light->Rerecord(); | 465 recording_source_light->Rerecord(); |
466 | 466 |
467 // Make a new RasterSource from the new recording. | 467 // Make a new RasterSource from the new recording. |
468 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 468 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
469 recording_source_light.get(), false); | 469 recording_source_light.get(), false); |
470 | 470 |
471 // We're going to playback from alpha(18) white rectangle into a smaller area | 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 | 472 // of the recording resulting in a smaller lighter white rectangle over a |
473 // darker white background rectangle. | 473 // darker white background rectangle. |
474 playback_rect = gfx::Rect( | 474 playback_rect = |
475 gfx::ToCeiledSize(gfx::ScaleSize(partial_bounds, contents_scale))); | 475 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); |
476 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 476 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
477 contents_scale); | 477 contents_scale); |
478 | 478 |
479 // Test that the whole playback_rect was cleared and repainted with new alpha. | 479 // Test that the whole playback_rect was cleared and repainted with new alpha. |
480 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 480 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
481 for (int i = 0; i < playback_rect.width(); ++i) { | 481 for (int i = 0; i < playback_rect.width(); ++i) { |
482 for (int j = 0; j < playback_rect.height(); ++j) { | 482 for (int j = 0; j < playback_rect.height(); ++j) { |
483 SCOPED_TRACE(j); | 483 SCOPED_TRACE(j); |
484 SCOPED_TRACE(i); | 484 SCOPED_TRACE(i); |
485 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); | 485 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); |
(...skipping 12 matching lines...) Expand all Loading... |
498 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | 498 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); |
499 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | 499 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); |
500 recording_source->SetRequiresClear(true); | 500 recording_source->SetRequiresClear(true); |
501 recording_source->SetClearCanvasWithDebugColor(false); | 501 recording_source->SetClearCanvasWithDebugColor(false); |
502 recording_source->Rerecord(); | 502 recording_source->Rerecord(); |
503 | 503 |
504 scoped_refptr<DisplayListRasterSource> raster = | 504 scoped_refptr<DisplayListRasterSource> raster = |
505 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 505 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
506 recording_source.get(), false); | 506 recording_source.get(), false); |
507 gfx::Size content_bounds( | 507 gfx::Size content_bounds( |
508 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 508 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
509 | 509 |
510 gfx::Rect canvas_rect(content_bounds); | 510 gfx::Rect canvas_rect(content_bounds); |
511 canvas_rect.Inset(0, 0, -1, -1); | 511 canvas_rect.Inset(0, 0, -1, -1); |
512 | 512 |
513 SkBitmap bitmap; | 513 SkBitmap bitmap; |
514 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 514 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
515 SkCanvas canvas(bitmap); | 515 SkCanvas canvas(bitmap); |
516 | 516 |
517 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); | 517 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); |
518 | 518 |
(...skipping 16 matching lines...) Expand all Loading... |
535 scoped_refptr<DisplayListRasterSource> raster = | 535 scoped_refptr<DisplayListRasterSource> raster = |
536 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 536 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
537 recording_source.get(), false); | 537 recording_source.get(), false); |
538 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 538 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
539 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 539 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
540 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 540 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
541 } | 541 } |
542 | 542 |
543 } // namespace | 543 } // namespace |
544 } // namespace cc | 544 } // namespace cc |
OLD | NEW |