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