OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 2616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2627 template<> | 2627 template<> |
2628 bool IsSoftwareRenderer<SoftwareRenderer>() { | 2628 bool IsSoftwareRenderer<SoftwareRenderer>() { |
2629 return true; | 2629 return true; |
2630 } | 2630 } |
2631 | 2631 |
2632 template<> | 2632 template<> |
2633 bool IsSoftwareRenderer<SoftwareRendererWithExpandedViewport>() { | 2633 bool IsSoftwareRenderer<SoftwareRendererWithExpandedViewport>() { |
2634 return true; | 2634 return true; |
2635 } | 2635 } |
2636 | 2636 |
| 2637 void draw_point_color(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor color) { |
| 2638 SkPaint paint; |
| 2639 paint.setColor(color); |
| 2640 canvas->drawPoint(x, y, paint); |
| 2641 } |
| 2642 |
2637 // If we disable image filtering, then a 2x2 bitmap should appear as four | 2643 // If we disable image filtering, then a 2x2 bitmap should appear as four |
2638 // huge sharp squares. | 2644 // huge sharp squares. |
2639 TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadDisableImageFiltering) { | 2645 TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadDisableImageFiltering) { |
2640 // We only care about this in software mode since bilinear filtering is | 2646 // We only care about this in software mode since bilinear filtering is |
2641 // cheap in hardware. | 2647 // cheap in hardware. |
2642 if (!IsSoftwareRenderer<TypeParam>()) | 2648 if (!IsSoftwareRenderer<TypeParam>()) |
2643 return; | 2649 return; |
2644 | 2650 |
2645 gfx::Rect viewport(this->device_viewport_size_); | 2651 gfx::Rect viewport(this->device_viewport_size_); |
2646 ResourceFormat texture_format = RGBA_8888; | 2652 ResourceFormat texture_format = RGBA_8888; |
2647 bool nearest_neighbor = false; | 2653 bool nearest_neighbor = false; |
2648 | 2654 |
2649 int id = 1; | 2655 int id = 1; |
2650 gfx::Transform transform_to_root; | 2656 gfx::Transform transform_to_root; |
2651 std::unique_ptr<RenderPass> pass = | 2657 std::unique_ptr<RenderPass> pass = |
2652 CreateTestRenderPass(id, viewport, transform_to_root); | 2658 CreateTestRenderPass(id, viewport, transform_to_root); |
2653 | 2659 |
2654 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2); | 2660 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2); |
2655 ASSERT_NE(surface, nullptr); | 2661 ASSERT_NE(surface, nullptr); |
2656 SkCanvas* canvas = surface->getCanvas(); | 2662 SkCanvas* canvas = surface->getCanvas(); |
2657 canvas->drawPoint(0, 0, SK_ColorGREEN); | 2663 draw_point_color(canvas, 0, 0, SK_ColorGREEN); |
2658 canvas->drawPoint(0, 1, SK_ColorBLUE); | 2664 draw_point_color(canvas, 0, 1, SK_ColorBLUE); |
2659 canvas->drawPoint(1, 0, SK_ColorBLUE); | 2665 draw_point_color(canvas, 1, 0, SK_ColorBLUE); |
2660 canvas->drawPoint(1, 1, SK_ColorGREEN); | 2666 draw_point_color(canvas, 1, 1, SK_ColorGREEN); |
2661 | 2667 |
2662 std::unique_ptr<FakeRecordingSource> recording = | 2668 std::unique_ptr<FakeRecordingSource> recording = |
2663 FakeRecordingSource::CreateFilledRecordingSource(viewport.size()); | 2669 FakeRecordingSource::CreateFilledRecordingSource(viewport.size()); |
2664 PaintFlags flags; | 2670 PaintFlags flags; |
2665 flags.setFilterQuality(kLow_SkFilterQuality); | 2671 flags.setFilterQuality(kLow_SkFilterQuality); |
2666 recording->add_draw_image_with_flags(surface->makeImageSnapshot(), | 2672 recording->add_draw_image_with_flags(surface->makeImageSnapshot(), |
2667 gfx::Point(), flags); | 2673 gfx::Point(), flags); |
2668 recording->Rerecord(); | 2674 recording->Rerecord(); |
2669 scoped_refptr<FakeRasterSource> raster_source = | 2675 scoped_refptr<FakeRasterSource> raster_source = |
2670 FakeRasterSource::CreateFromRecordingSource(recording.get(), false); | 2676 FakeRasterSource::CreateFromRecordingSource(recording.get(), false); |
(...skipping 25 matching lines...) Expand all Loading... |
2696 bool nearest_neighbor = true; | 2702 bool nearest_neighbor = true; |
2697 | 2703 |
2698 int id = 1; | 2704 int id = 1; |
2699 gfx::Transform transform_to_root; | 2705 gfx::Transform transform_to_root; |
2700 std::unique_ptr<RenderPass> pass = | 2706 std::unique_ptr<RenderPass> pass = |
2701 CreateTestRenderPass(id, viewport, transform_to_root); | 2707 CreateTestRenderPass(id, viewport, transform_to_root); |
2702 | 2708 |
2703 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2); | 2709 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2); |
2704 ASSERT_NE(surface, nullptr); | 2710 ASSERT_NE(surface, nullptr); |
2705 SkCanvas* canvas = surface->getCanvas(); | 2711 SkCanvas* canvas = surface->getCanvas(); |
2706 canvas->drawPoint(0, 0, SK_ColorGREEN); | 2712 draw_point_color(canvas, 0, 0, SK_ColorGREEN); |
2707 canvas->drawPoint(0, 1, SK_ColorBLUE); | 2713 draw_point_color(canvas, 0, 1, SK_ColorBLUE); |
2708 canvas->drawPoint(1, 0, SK_ColorBLUE); | 2714 draw_point_color(canvas, 1, 0, SK_ColorBLUE); |
2709 canvas->drawPoint(1, 1, SK_ColorGREEN); | 2715 draw_point_color(canvas, 1, 1, SK_ColorGREEN); |
2710 | 2716 |
2711 std::unique_ptr<FakeRecordingSource> recording = | 2717 std::unique_ptr<FakeRecordingSource> recording = |
2712 FakeRecordingSource::CreateFilledRecordingSource(viewport.size()); | 2718 FakeRecordingSource::CreateFilledRecordingSource(viewport.size()); |
2713 PaintFlags flags; | 2719 PaintFlags flags; |
2714 flags.setFilterQuality(kLow_SkFilterQuality); | 2720 flags.setFilterQuality(kLow_SkFilterQuality); |
2715 recording->add_draw_image_with_flags(surface->makeImageSnapshot(), | 2721 recording->add_draw_image_with_flags(surface->makeImageSnapshot(), |
2716 gfx::Point(), flags); | 2722 gfx::Point(), flags); |
2717 recording->Rerecord(); | 2723 recording->Rerecord(); |
2718 scoped_refptr<FakeRasterSource> raster_source = | 2724 scoped_refptr<FakeRasterSource> raster_source = |
2719 FakeRasterSource::CreateFromRecordingSource(recording.get(), false); | 2725 FakeRasterSource::CreateFromRecordingSource(recording.get(), false); |
(...skipping 20 matching lines...) Expand all Loading... |
2740 TYPED_TEST(RendererPixelTest, TileDrawQuadNearestNeighbor) { | 2746 TYPED_TEST(RendererPixelTest, TileDrawQuadNearestNeighbor) { |
2741 gfx::Rect viewport(this->device_viewport_size_); | 2747 gfx::Rect viewport(this->device_viewport_size_); |
2742 bool swizzle_contents = true; | 2748 bool swizzle_contents = true; |
2743 bool nearest_neighbor = true; | 2749 bool nearest_neighbor = true; |
2744 | 2750 |
2745 SkBitmap bitmap; | 2751 SkBitmap bitmap; |
2746 bitmap.allocN32Pixels(2, 2); | 2752 bitmap.allocN32Pixels(2, 2); |
2747 { | 2753 { |
2748 SkAutoLockPixels lock(bitmap); | 2754 SkAutoLockPixels lock(bitmap); |
2749 SkCanvas canvas(bitmap); | 2755 SkCanvas canvas(bitmap); |
2750 canvas.drawPoint(0, 0, SK_ColorGREEN); | 2756 draw_point_color(&canvas, 0, 0, SK_ColorGREEN); |
2751 canvas.drawPoint(0, 1, SK_ColorBLUE); | 2757 draw_point_color(&canvas, 0, 1, SK_ColorBLUE); |
2752 canvas.drawPoint(1, 0, SK_ColorBLUE); | 2758 draw_point_color(&canvas, 1, 0, SK_ColorBLUE); |
2753 canvas.drawPoint(1, 1, SK_ColorGREEN); | 2759 draw_point_color(&canvas, 1, 1, SK_ColorGREEN); |
2754 } | 2760 } |
2755 | 2761 |
2756 gfx::Size tile_size(2, 2); | 2762 gfx::Size tile_size(2, 2); |
2757 ResourceId resource = this->resource_provider_->CreateResource( | 2763 ResourceId resource = this->resource_provider_->CreateResource( |
2758 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, | 2764 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, |
2759 gfx::ColorSpace()); | 2765 gfx::ColorSpace()); |
2760 | 2766 |
2761 { | 2767 { |
2762 SkAutoLockPixels lock(bitmap); | 2768 SkAutoLockPixels lock(bitmap); |
2763 this->resource_provider_->CopyToResource( | 2769 this->resource_provider_->CopyToResource( |
(...skipping 27 matching lines...) Expand all Loading... |
2791 // TextureDrawQuad. | 2797 // TextureDrawQuad. |
2792 TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadNearestNeighbor) { | 2798 TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadNearestNeighbor) { |
2793 gfx::Rect viewport(this->device_viewport_size_); | 2799 gfx::Rect viewport(this->device_viewport_size_); |
2794 bool nearest_neighbor = true; | 2800 bool nearest_neighbor = true; |
2795 | 2801 |
2796 SkBitmap bitmap; | 2802 SkBitmap bitmap; |
2797 bitmap.allocN32Pixels(2, 2); | 2803 bitmap.allocN32Pixels(2, 2); |
2798 { | 2804 { |
2799 SkAutoLockPixels lock(bitmap); | 2805 SkAutoLockPixels lock(bitmap); |
2800 SkCanvas canvas(bitmap); | 2806 SkCanvas canvas(bitmap); |
2801 canvas.drawPoint(0, 0, SK_ColorGREEN); | 2807 draw_point_color(&canvas, 0, 0, SK_ColorGREEN); |
2802 canvas.drawPoint(0, 1, SK_ColorBLUE); | 2808 draw_point_color(&canvas, 0, 1, SK_ColorBLUE); |
2803 canvas.drawPoint(1, 0, SK_ColorBLUE); | 2809 draw_point_color(&canvas, 1, 0, SK_ColorBLUE); |
2804 canvas.drawPoint(1, 1, SK_ColorGREEN); | 2810 draw_point_color(&canvas, 1, 1, SK_ColorGREEN); |
2805 } | 2811 } |
2806 | 2812 |
2807 gfx::Size tile_size(2, 2); | 2813 gfx::Size tile_size(2, 2); |
2808 ResourceId resource = this->resource_provider_->CreateResource( | 2814 ResourceId resource = this->resource_provider_->CreateResource( |
2809 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, | 2815 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, |
2810 gfx::ColorSpace()); | 2816 gfx::ColorSpace()); |
2811 | 2817 |
2812 { | 2818 { |
2813 SkAutoLockPixels lock(bitmap); | 2819 SkAutoLockPixels lock(bitmap); |
2814 this->resource_provider_->CopyToResource( | 2820 this->resource_provider_->CopyToResource( |
(...skipping 28 matching lines...) Expand all Loading... |
2843 // the TextureDrawQuad. | 2849 // the TextureDrawQuad. |
2844 TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadLinear) { | 2850 TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadLinear) { |
2845 gfx::Rect viewport(this->device_viewport_size_); | 2851 gfx::Rect viewport(this->device_viewport_size_); |
2846 bool nearest_neighbor = false; | 2852 bool nearest_neighbor = false; |
2847 | 2853 |
2848 SkBitmap bitmap; | 2854 SkBitmap bitmap; |
2849 bitmap.allocN32Pixels(2, 2); | 2855 bitmap.allocN32Pixels(2, 2); |
2850 { | 2856 { |
2851 SkAutoLockPixels lock(bitmap); | 2857 SkAutoLockPixels lock(bitmap); |
2852 SkCanvas canvas(bitmap); | 2858 SkCanvas canvas(bitmap); |
2853 canvas.drawPoint(0, 0, SK_ColorGREEN); | 2859 draw_point_color(&canvas, 0, 0, SK_ColorGREEN); |
2854 canvas.drawPoint(0, 1, SK_ColorBLUE); | 2860 draw_point_color(&canvas, 0, 1, SK_ColorBLUE); |
2855 canvas.drawPoint(1, 0, SK_ColorBLUE); | 2861 draw_point_color(&canvas, 1, 0, SK_ColorBLUE); |
2856 canvas.drawPoint(1, 1, SK_ColorGREEN); | 2862 draw_point_color(&canvas, 1, 1, SK_ColorGREEN); |
2857 } | 2863 } |
2858 | 2864 |
2859 gfx::Size tile_size(2, 2); | 2865 gfx::Size tile_size(2, 2); |
2860 ResourceId resource = this->resource_provider_->CreateResource( | 2866 ResourceId resource = this->resource_provider_->CreateResource( |
2861 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, | 2867 tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, |
2862 gfx::ColorSpace()); | 2868 gfx::ColorSpace()); |
2863 | 2869 |
2864 { | 2870 { |
2865 SkAutoLockPixels lock(bitmap); | 2871 SkAutoLockPixels lock(bitmap); |
2866 this->resource_provider_->CopyToResource( | 2872 this->resource_provider_->CopyToResource( |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3320 | 3326 |
3321 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( | 3327 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( |
3322 "translucent_rectangles.png")), | 3328 "translucent_rectangles.png")), |
3323 ExactPixelComparator(true))); | 3329 ExactPixelComparator(true))); |
3324 } | 3330 } |
3325 | 3331 |
3326 #endif // !defined(OS_ANDROID) | 3332 #endif // !defined(OS_ANDROID) |
3327 | 3333 |
3328 } // namespace | 3334 } // namespace |
3329 } // namespace cc | 3335 } // namespace cc |
OLD | NEW |