| 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_controller.h" |
| 13 #include "skia/ext/refptr.h" | 14 #include "skia/ext/refptr.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/core/SkPixelRef.h" | 16 #include "third_party/skia/include/core/SkPixelRef.h" |
| 16 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); | 532 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); |
| 532 recording_source->Rerecord(); | 533 recording_source->Rerecord(); |
| 533 | 534 |
| 534 scoped_refptr<RasterSource> raster = | 535 scoped_refptr<RasterSource> raster = |
| 535 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 536 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
| 536 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 537 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
| 537 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 538 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
| 538 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 539 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
| 539 } | 540 } |
| 540 | 541 |
| 542 TEST(RasterSourceTest, ImageHijackCanvasRespectsSharedCanvasTransform) { |
| 543 gfx::Size size(100, 100); |
| 544 |
| 545 // Create a recording source that is filled with red and every corner is |
| 546 // green (4x4 rects in the corner are green to account for blending when |
| 547 // scaling). Note that we paint an image first, so that we can force image |
| 548 // hijack canvas to be used. |
| 549 std::unique_ptr<FakeRecordingSource> recording_source = |
| 550 FakeRecordingSource::CreateFilledRecordingSource(size); |
| 551 |
| 552 // 1. Paint the image. |
| 553 skia::RefPtr<SkImage> image = CreateDiscardableImage(gfx::Size(5, 5)); |
| 554 recording_source->add_draw_image(image.get(), gfx::Point(0, 0)); |
| 555 |
| 556 // 2. Cover everything in red. |
| 557 SkPaint paint; |
| 558 paint.setColor(SK_ColorRED); |
| 559 recording_source->add_draw_rect_with_paint(gfx::Rect(size), paint); |
| 560 |
| 561 // 3. Draw 4x4 green rects into every corner. |
| 562 paint.setColor(SK_ColorGREEN); |
| 563 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 4, 4), paint); |
| 564 recording_source->add_draw_rect_with_paint( |
| 565 gfx::Rect(size.width() - 4, 0, 4, 4), paint); |
| 566 recording_source->add_draw_rect_with_paint( |
| 567 gfx::Rect(0, size.height() - 4, 4, 4), paint); |
| 568 recording_source->add_draw_rect_with_paint( |
| 569 gfx::Rect(size.width() - 4, size.height() - 4, 4, 4), paint); |
| 570 |
| 571 recording_source->SetGenerateDiscardableImagesMetadata(true); |
| 572 recording_source->Rerecord(); |
| 573 |
| 574 bool can_use_lcd = true; |
| 575 scoped_refptr<RasterSource> raster_source = |
| 576 recording_source->CreateRasterSource(can_use_lcd); |
| 577 SoftwareImageDecodeController controller; |
| 578 raster_source->SetImageDecodeController(&controller); |
| 579 |
| 580 SkBitmap bitmap; |
| 581 bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f); |
| 582 SkCanvas canvas(bitmap); |
| 583 canvas.scale(0.5f, 0.25f); |
| 584 |
| 585 RasterSource::PlaybackSettings settings; |
| 586 settings.playback_to_shared_canvas = true; |
| 587 settings.use_image_hijack_canvas = true; |
| 588 raster_source->PlaybackToCanvas(&canvas, gfx::Rect(size), gfx::Rect(size), |
| 589 1.f, settings); |
| 590 |
| 591 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0)); |
| 592 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0)); |
| 593 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); |
| 594 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); |
| 595 for (int x = 0; x < 49; ++x) |
| 596 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); |
| 597 for (int y = 0; y < 24; ++y) |
| 598 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); |
| 599 } |
| 600 |
| 541 } // namespace | 601 } // namespace |
| 542 } // namespace cc | 602 } // namespace cc |
| OLD | NEW |