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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "cc/layers/append_quads_data.h" | 6 #include "cc/layers/append_quads_data.h" |
7 #include "cc/output/gl_renderer.h" | 7 #include "cc/output/gl_renderer.h" |
8 #include "cc/quads/draw_quad.h" | 8 #include "cc/quads/draw_quad.h" |
9 #include "cc/quads/picture_draw_quad.h" | 9 #include "cc/quads/picture_draw_quad.h" |
10 #include "cc/quads/texture_draw_quad.h" | 10 #include "cc/quads/texture_draw_quad.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 opacity); | 77 opacity); |
78 return shared_state.Pass(); | 78 return shared_state.Pass(); |
79 } | 79 } |
80 | 80 |
81 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad( | 81 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad( |
82 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) { | 82 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) { |
83 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); | 83 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); |
84 quad->SetNew(shared_state, | 84 quad->SetNew(shared_state, |
85 rect, | 85 rect, |
86 pass_id, | 86 pass_id, |
87 false, // is_replica | 87 false, // is_replica |
88 0, // mask_resource_id | 88 0, // mask_resource_id |
89 rect, // contents_changed_since_last_frame | 89 rect, // contents_changed_since_last_frame |
90 gfx::RectF(), // mask_uv_rect | 90 gfx::RectF(1.f, 1.f), // mask_uv_rect |
91 FilterOperations(), // foreground filters | 91 FilterOperations(), // foreground filters |
92 FilterOperations()); // background filters | 92 FilterOperations()); // background filters |
93 | 93 |
94 return quad.PassAs<DrawQuad>(); | 94 return quad.PassAs<DrawQuad>(); |
95 } | 95 } |
96 | 96 |
97 scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad( | 97 scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad( |
98 gfx::Rect rect, | 98 gfx::Rect rect, |
99 SkColor texel_color, | 99 SkColor texel_color, |
100 SkColor background_color, | 100 SkColor background_color, |
101 bool premultiplied_alpha, | 101 bool premultiplied_alpha, |
102 SharedQuadState* shared_state, | 102 SharedQuadState* shared_state, |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 875 |
876 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); | 876 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); |
877 | 877 |
878 EXPECT_TRUE(this->RunPixelTest( | 878 EXPECT_TRUE(this->RunPixelTest( |
879 &pass_list, | 879 &pass_list, |
880 PixelTest::NoOffscreenContext, | 880 PixelTest::NoOffscreenContext, |
881 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")), | 881 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")), |
882 FuzzyPixelOffByOneComparator(true))); | 882 FuzzyPixelOffByOneComparator(true))); |
883 } | 883 } |
884 | 884 |
| 885 // This tests the case where we have a RenderPass with a mask, but the quad |
| 886 // for the masked surface does not include the full surface texture. |
| 887 TYPED_TEST(RendererPixelTest, RenderPassAndMaskWithPartialQuad) { |
| 888 gfx::Rect viewport_rect(this->device_viewport_size_); |
| 889 |
| 890 RenderPass::Id root_pass_id(1, 1); |
| 891 scoped_ptr<RenderPass> root_pass = |
| 892 CreateTestRootRenderPass(root_pass_id, viewport_rect); |
| 893 scoped_ptr<SharedQuadState> root_pass_shared_state = |
| 894 CreateTestSharedQuadState(gfx::Transform(), viewport_rect); |
| 895 |
| 896 RenderPass::Id child_pass_id(2, 2); |
| 897 gfx::Transform transform_to_root; |
| 898 scoped_ptr<RenderPass> child_pass = |
| 899 CreateTestRenderPass(child_pass_id, viewport_rect, transform_to_root); |
| 900 scoped_ptr<SharedQuadState> child_pass_shared_state = |
| 901 CreateTestSharedQuadState(gfx::Transform(), viewport_rect); |
| 902 |
| 903 // The child render pass is just a green box. |
| 904 static const SkColor kCSSGreen = 0xff008000; |
| 905 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create(); |
| 906 green->SetNew(child_pass_shared_state.get(), viewport_rect, kCSSGreen, false); |
| 907 child_pass->quad_list.push_back(green.PassAs<DrawQuad>()); |
| 908 |
| 909 // Make a mask. |
| 910 gfx::Rect mask_rect = viewport_rect; |
| 911 SkBitmap bitmap; |
| 912 bitmap.setConfig( |
| 913 SkBitmap::kARGB_8888_Config, mask_rect.width(), mask_rect.height()); |
| 914 bitmap.allocPixels(); |
| 915 SkBitmapDevice bitmap_device(bitmap); |
| 916 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(new SkCanvas(&bitmap_device)); |
| 917 SkPaint paint; |
| 918 paint.setStyle(SkPaint::kStroke_Style); |
| 919 paint.setStrokeWidth(SkIntToScalar(4)); |
| 920 paint.setColor(SK_ColorWHITE); |
| 921 canvas->clear(SK_ColorTRANSPARENT); |
| 922 gfx::Rect rect = mask_rect; |
| 923 while (!rect.IsEmpty()) { |
| 924 rect.Inset(6, 6, 4, 4); |
| 925 canvas->drawRect( |
| 926 SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()), |
| 927 paint); |
| 928 rect.Inset(6, 6, 4, 4); |
| 929 } |
| 930 |
| 931 ResourceProvider::ResourceId mask_resource_id = |
| 932 this->resource_provider_->CreateResource( |
| 933 mask_rect.size(), |
| 934 GL_CLAMP_TO_EDGE, |
| 935 ResourceProvider::TextureUsageAny, |
| 936 RGBA_8888); |
| 937 { |
| 938 SkAutoLockPixels lock(bitmap); |
| 939 this->resource_provider_->SetPixels( |
| 940 mask_resource_id, |
| 941 reinterpret_cast<uint8_t*>(bitmap.getPixels()), |
| 942 mask_rect, |
| 943 mask_rect, |
| 944 gfx::Vector2d()); |
| 945 } |
| 946 |
| 947 // This RenderPassDrawQuad does not include the full |viewport_rect| which is |
| 948 // the size of the child render pass. |
| 949 gfx::Rect sub_rect = gfx::Rect(50, 50, 100, 100); |
| 950 EXPECT_NE(sub_rect.x(), child_pass->output_rect.x()); |
| 951 EXPECT_NE(sub_rect.y(), child_pass->output_rect.y()); |
| 952 EXPECT_NE(sub_rect.right(), child_pass->output_rect.right()); |
| 953 EXPECT_NE(sub_rect.bottom(), child_pass->output_rect.bottom()); |
| 954 EXPECT_TRUE(child_pass->output_rect.Contains(sub_rect)); |
| 955 |
| 956 // Set up a mask on the RenderPassDrawQuad. |
| 957 scoped_ptr<RenderPassDrawQuad> mask_quad = RenderPassDrawQuad::Create(); |
| 958 mask_quad->SetNew(root_pass_shared_state.get(), |
| 959 sub_rect, |
| 960 child_pass_id, |
| 961 false, // is_replica |
| 962 mask_resource_id, |
| 963 sub_rect, // contents_changed_since_last_frame |
| 964 gfx::RectF(1.f, 1.f), // mask_uv_rect |
| 965 FilterOperations(), // foreground filters |
| 966 FilterOperations()); // background filters |
| 967 root_pass->quad_list.push_back(mask_quad.PassAs<DrawQuad>()); |
| 968 |
| 969 // White background behind the masked render pass. |
| 970 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create(); |
| 971 white->SetNew( |
| 972 root_pass_shared_state.get(), viewport_rect, SK_ColorWHITE, false); |
| 973 root_pass->quad_list.push_back(white.PassAs<DrawQuad>()); |
| 974 |
| 975 RenderPassList pass_list; |
| 976 pass_list.push_back(child_pass.Pass()); |
| 977 pass_list.push_back(root_pass.Pass()); |
| 978 |
| 979 EXPECT_TRUE(this->RunPixelTest( |
| 980 &pass_list, |
| 981 PixelTest::NoOffscreenContext, |
| 982 base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png")), |
| 983 ExactPixelComparator(true))); |
| 984 } |
| 985 |
885 template <typename RendererType> | 986 template <typename RendererType> |
886 class RendererPixelTestWithBackgroundFilter | 987 class RendererPixelTestWithBackgroundFilter |
887 : public RendererPixelTest<RendererType> { | 988 : public RendererPixelTest<RendererType> { |
888 protected: | 989 protected: |
889 void SetUpRenderPassList() { | 990 void SetUpRenderPassList() { |
890 gfx::Rect device_viewport_rect(this->device_viewport_size_); | 991 gfx::Rect device_viewport_rect(this->device_viewport_size_); |
891 | 992 |
892 RenderPass::Id root_id(1, 1); | 993 RenderPass::Id root_id(1, 1); |
893 scoped_ptr<RenderPass> root_pass = | 994 scoped_ptr<RenderPass> root_pass = |
894 CreateTestRootRenderPass(root_id, device_viewport_rect); | 995 CreateTestRootRenderPass(root_id, device_viewport_rect); |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 EXPECT_TRUE(this->RunPixelTest( | 1850 EXPECT_TRUE(this->RunPixelTest( |
1750 &pass_list, | 1851 &pass_list, |
1751 PixelTest::NoOffscreenContext, | 1852 PixelTest::NoOffscreenContext, |
1752 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), | 1853 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), |
1753 ExactPixelComparator(true))); | 1854 ExactPixelComparator(true))); |
1754 } | 1855 } |
1755 #endif // !defined(OS_ANDROID) | 1856 #endif // !defined(OS_ANDROID) |
1756 | 1857 |
1757 } // namespace | 1858 } // namespace |
1758 } // namespace cc | 1859 } // namespace cc |
OLD | NEW |