| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 TextureDrawQuad* quad = | 148 TextureDrawQuad* quad = |
| 149 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 149 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 150 quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, | 150 quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, |
| 151 premultiplied_alpha, uv_top_left, uv_bottom_right, | 151 premultiplied_alpha, uv_top_left, uv_bottom_right, |
| 152 background_color, vertex_opacity, flipped, nearest_neighbor, | 152 background_color, vertex_opacity, flipped, nearest_neighbor, |
| 153 false); | 153 false); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void CreateTestTextureDrawQuad(const gfx::Rect& rect, | 156 void CreateTestTextureDrawQuad(const gfx::Rect& rect, |
| 157 SkColor texel_color, | 157 SkColor texel_color, |
| 158 float vertex_opacity[4], |
| 158 SkColor background_color, | 159 SkColor background_color, |
| 159 bool premultiplied_alpha, | 160 bool premultiplied_alpha, |
| 160 const SharedQuadState* shared_state, | 161 const SharedQuadState* shared_state, |
| 161 ResourceProvider* resource_provider, | 162 ResourceProvider* resource_provider, |
| 162 RenderPass* render_pass) { | 163 RenderPass* render_pass) { |
| 163 SkPMColor pixel_color = premultiplied_alpha ? | 164 SkPMColor pixel_color = premultiplied_alpha ? |
| 164 SkPreMultiplyColor(texel_color) : | 165 SkPreMultiplyColor(texel_color) : |
| 165 SkPackARGB32NoCheck(SkColorGetA(texel_color), | 166 SkPackARGB32NoCheck(SkColorGetA(texel_color), |
| 166 SkColorGetR(texel_color), | 167 SkColorGetR(texel_color), |
| 167 SkColorGetG(texel_color), | 168 SkColorGetG(texel_color), |
| 168 SkColorGetB(texel_color)); | 169 SkColorGetB(texel_color)); |
| 169 size_t num_pixels = static_cast<size_t>(rect.width()) * rect.height(); | 170 size_t num_pixels = static_cast<size_t>(rect.width()) * rect.height(); |
| 170 std::vector<uint32_t> pixels(num_pixels, pixel_color); | 171 std::vector<uint32_t> pixels(num_pixels, pixel_color); |
| 171 | 172 |
| 172 ResourceId resource = resource_provider->CreateResource( | 173 ResourceId resource = resource_provider->CreateResource( |
| 173 rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, | 174 rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, |
| 174 gfx::ColorSpace()); | 175 gfx::ColorSpace()); |
| 175 resource_provider->CopyToResource( | 176 resource_provider->CopyToResource( |
| 176 resource, reinterpret_cast<uint8_t*>(&pixels.front()), rect.size()); | 177 resource, reinterpret_cast<uint8_t*>(&pixels.front()), rect.size()); |
| 177 | 178 |
| 178 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | |
| 179 | |
| 180 const gfx::PointF uv_top_left(0.0f, 0.0f); | 179 const gfx::PointF uv_top_left(0.0f, 0.0f); |
| 181 const gfx::PointF uv_bottom_right(1.0f, 1.0f); | 180 const gfx::PointF uv_bottom_right(1.0f, 1.0f); |
| 182 const bool flipped = false; | 181 const bool flipped = false; |
| 183 const bool nearest_neighbor = false; | 182 const bool nearest_neighbor = false; |
| 184 TextureDrawQuad* quad = | 183 TextureDrawQuad* quad = |
| 185 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 184 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 186 quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, | 185 quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, |
| 187 premultiplied_alpha, uv_top_left, uv_bottom_right, | 186 premultiplied_alpha, uv_top_left, uv_bottom_right, |
| 188 background_color, vertex_opacity, flipped, nearest_neighbor, | 187 background_color, vertex_opacity, flipped, nearest_neighbor, |
| 189 false); | 188 false); |
| 190 } | 189 } |
| 191 | 190 |
| 191 void CreateTestTextureDrawQuad(const gfx::Rect& rect, |
| 192 SkColor texel_color, |
| 193 SkColor background_color, |
| 194 bool premultiplied_alpha, |
| 195 const SharedQuadState* shared_state, |
| 196 ResourceProvider* resource_provider, |
| 197 RenderPass* render_pass) { |
| 198 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 199 CreateTestTextureDrawQuad(rect, texel_color, vertex_opacity, background_color, |
| 200 premultiplied_alpha, shared_state, |
| 201 resource_provider, render_pass); |
| 202 } |
| 203 |
| 192 void CreateTestYUVVideoDrawQuad_FromVideoFrame( | 204 void CreateTestYUVVideoDrawQuad_FromVideoFrame( |
| 193 const SharedQuadState* shared_state, | 205 const SharedQuadState* shared_state, |
| 194 scoped_refptr<media::VideoFrame> video_frame, | 206 scoped_refptr<media::VideoFrame> video_frame, |
| 195 uint8_t alpha_value, | 207 uint8_t alpha_value, |
| 196 const gfx::RectF& tex_coord_rect, | 208 const gfx::RectF& tex_coord_rect, |
| 197 RenderPass* render_pass, | 209 RenderPass* render_pass, |
| 198 VideoResourceUpdater* video_resource_updater, | 210 VideoResourceUpdater* video_resource_updater, |
| 199 const gfx::Rect& rect, | 211 const gfx::Rect& rect, |
| 200 const gfx::Rect& visible_rect, | 212 const gfx::Rect& visible_rect, |
| 201 ResourceProvider* resource_provider) { | 213 ResourceProvider* resource_provider) { |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 801 |
| 790 RenderPassList pass_list; | 802 RenderPassList pass_list; |
| 791 pass_list.push_back(std::move(pass)); | 803 pass_list.push_back(std::move(pass)); |
| 792 | 804 |
| 793 EXPECT_TRUE(this->RunPixelTest( | 805 EXPECT_TRUE(this->RunPixelTest( |
| 794 &pass_list, | 806 &pass_list, |
| 795 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), | 807 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 796 FuzzyPixelOffByOneComparator(true))); | 808 FuzzyPixelOffByOneComparator(true))); |
| 797 } | 809 } |
| 798 | 810 |
| 811 TEST_F(GLRendererPixelTest, |
| 812 PremultipliedTextureWithBackgroundAndVertexOpacity) { |
| 813 gfx::Rect rect(this->device_viewport_size_); |
| 814 |
| 815 int id = 1; |
| 816 std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 817 |
| 818 SharedQuadState* texture_quad_state = |
| 819 CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
| 820 texture_quad_state->opacity = 0.8f; |
| 821 |
| 822 float vertex_opacity[4] = {1.f, 1.f, 0.f, 0.f}; |
| 823 CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_), |
| 824 SkColorSetARGB(204, 120, 255, 120), // Texel color. |
| 825 vertex_opacity, |
| 826 SK_ColorGREEN, // Background color. |
| 827 true, // Premultiplied alpha. |
| 828 texture_quad_state, this->resource_provider_.get(), |
| 829 pass.get()); |
| 830 |
| 831 SharedQuadState* color_quad_state = |
| 832 CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); |
| 833 SolidColorDrawQuad* color_quad = |
| 834 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 835 color_quad->SetNew(color_quad_state, rect, rect, SK_ColorWHITE, false); |
| 836 |
| 837 RenderPassList pass_list; |
| 838 pass_list.push_back(std::move(pass)); |
| 839 |
| 840 EXPECT_TRUE(this->RunPixelTest( |
| 841 &pass_list, |
| 842 base::FilePath(FILE_PATH_LITERAL("green_alpha_vertex_opacity.png")), |
| 843 FuzzyPixelOffByOneComparator(true))); |
| 844 } |
| 845 |
| 799 template <typename TypeParam> | 846 template <typename TypeParam> |
| 800 class IntersectingQuadPixelTest : public RendererPixelTest<TypeParam> { | 847 class IntersectingQuadPixelTest : public RendererPixelTest<TypeParam> { |
| 801 protected: | 848 protected: |
| 802 void SetupQuadStateAndRenderPass() { | 849 void SetupQuadStateAndRenderPass() { |
| 803 // This sets up a pair of draw quads. They are both rotated | 850 // This sets up a pair of draw quads. They are both rotated |
| 804 // relative to the root plane, they are also rotated relative to each other. | 851 // relative to the root plane, they are also rotated relative to each other. |
| 805 // The intersect in the middle at a non-perpendicular angle so that any | 852 // The intersect in the middle at a non-perpendicular angle so that any |
| 806 // errors are hopefully magnified. | 853 // errors are hopefully magnified. |
| 807 // The quads should intersect correctly, as in the front quad should only | 854 // The quads should intersect correctly, as in the front quad should only |
| 808 // be partially in front of the back quad, and partially behind. | 855 // be partially in front of the back quad, and partially behind. |
| (...skipping 2524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3333 | 3380 |
| 3334 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( | 3381 EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL( |
| 3335 "translucent_rectangles.png")), | 3382 "translucent_rectangles.png")), |
| 3336 ExactPixelComparator(true))); | 3383 ExactPixelComparator(true))); |
| 3337 } | 3384 } |
| 3338 | 3385 |
| 3339 #endif // !defined(OS_ANDROID) | 3386 #endif // !defined(OS_ANDROID) |
| 3340 | 3387 |
| 3341 } // namespace | 3388 } // namespace |
| 3342 } // namespace cc | 3389 } // namespace cc |
| OLD | NEW |