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/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
7 #include "cc/test/fake_rendering_stats_instrumentation.h" | 7 #include "cc/test/fake_rendering_stats_instrumentation.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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); | 667 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); |
668 content_rect.Intersect(gfx::Rect(content_bounds)); | 668 content_rect.Intersect(gfx::Rect(content_bounds)); |
669 | 669 |
670 // Simulate a canvas rect larger than the content rect. Every pixel | 670 // Simulate a canvas rect larger than the content rect. Every pixel |
671 // up to one pixel outside the content rect is guaranteed to be opaque. | 671 // up to one pixel outside the content rect is guaranteed to be opaque. |
672 // Outside of that is undefined. | 672 // Outside of that is undefined. |
673 gfx::Rect canvas_rect(content_rect); | 673 gfx::Rect canvas_rect(content_rect); |
674 canvas_rect.Inset(0, 0, -1, -1); | 674 canvas_rect.Inset(0, 0, -1, -1); |
675 | 675 |
676 SkBitmap bitmap; | 676 SkBitmap bitmap; |
677 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 677 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
678 canvas_rect.width(), | |
679 canvas_rect.height()); | |
680 bitmap.allocPixels(); | |
681 SkCanvas canvas(bitmap); | 678 SkCanvas canvas(bitmap); |
682 canvas.clear(SK_ColorTRANSPARENT); | 679 canvas.clear(SK_ColorTRANSPARENT); |
683 | 680 |
684 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | 681 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; |
685 | 682 |
686 pile->RasterToBitmap(&canvas, | 683 pile->RasterToBitmap(&canvas, |
687 canvas_rect, | 684 canvas_rect, |
688 contents_scale, | 685 contents_scale, |
689 &rendering_stats_instrumentation); | 686 &rendering_stats_instrumentation); |
690 | 687 |
(...skipping 28 matching lines...) Expand all Loading... |
719 pile->set_clear_canvas_with_debug_color(false); | 716 pile->set_clear_canvas_with_debug_color(false); |
720 pile->RerecordPile(); | 717 pile->RerecordPile(); |
721 | 718 |
722 gfx::Size content_bounds( | 719 gfx::Size content_bounds( |
723 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 720 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
724 | 721 |
725 gfx::Rect canvas_rect(content_bounds); | 722 gfx::Rect canvas_rect(content_bounds); |
726 canvas_rect.Inset(0, 0, -1, -1); | 723 canvas_rect.Inset(0, 0, -1, -1); |
727 | 724 |
728 SkBitmap bitmap; | 725 SkBitmap bitmap; |
729 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 726 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
730 canvas_rect.width(), | |
731 canvas_rect.height()); | |
732 bitmap.allocPixels(); | |
733 SkCanvas canvas(bitmap); | 727 SkCanvas canvas(bitmap); |
734 | 728 |
735 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | 729 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; |
736 pile->RasterToBitmap( | 730 pile->RasterToBitmap( |
737 &canvas, canvas_rect, contents_scale, &rendering_stats_instrumentation); | 731 &canvas, canvas_rect, contents_scale, &rendering_stats_instrumentation); |
738 | 732 |
739 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 733 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
740 int num_pixels = bitmap.width() * bitmap.height(); | 734 int num_pixels = bitmap.width() * bitmap.height(); |
741 for (int i = 0; i < num_pixels; ++i) { | 735 for (int i = 0; i < num_pixels; ++i) { |
742 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 736 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 EXPECT_TRUE(iterator); | 875 EXPECT_TRUE(iterator); |
882 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 876 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
883 EXPECT_TRUE(++iterator); | 877 EXPECT_TRUE(++iterator); |
884 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 878 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
885 EXPECT_FALSE(++iterator); | 879 EXPECT_FALSE(++iterator); |
886 } | 880 } |
887 } | 881 } |
888 | 882 |
889 } // namespace | 883 } // namespace |
890 } // namespace cc | 884 } // namespace cc |
OLD | NEW |