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.h" | 5 #include "base/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/resources/platform_color.h" | 11 #include "cc/resources/platform_color.h" |
11 #include "cc/resources/sync_point_helper.h" | 12 #include "cc/resources/sync_point_helper.h" |
12 #include "cc/test/fake_picture_pile_impl.h" | 13 #include "cc/test/fake_picture_pile_impl.h" |
13 #include "cc/test/pixel_test.h" | 14 #include "cc/test/pixel_test.h" |
14 #include "gpu/GLES2/gl2extchromium.h" | 15 #include "gpu/GLES2/gl2extchromium.h" |
15 #include "third_party/skia/include/core/SkImageFilter.h" | 16 #include "third_party/skia/include/core/SkImageFilter.h" |
16 #include "third_party/skia/include/core/SkMatrix.h" | 17 #include "third_party/skia/include/core/SkMatrix.h" |
17 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 18 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
18 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 19 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
19 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 0, // mask_resource_id | 88 0, // mask_resource_id |
88 rect, // contents_changed_since_last_frame | 89 rect, // contents_changed_since_last_frame |
89 gfx::RectF(), // mask_uv_rect | 90 gfx::RectF(), // mask_uv_rect |
90 FilterOperations(), // foreground filters | 91 FilterOperations(), // foreground filters |
91 skia::RefPtr<SkImageFilter>(), // foreground filter | 92 skia::RefPtr<SkImageFilter>(), // foreground filter |
92 FilterOperations()); // background filters | 93 FilterOperations()); // background filters |
93 | 94 |
94 return quad.PassAs<DrawQuad>(); | 95 return quad.PassAs<DrawQuad>(); |
95 } | 96 } |
96 | 97 |
| 98 scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad( |
| 99 gfx::Rect rect, |
| 100 SkColor texel_color, |
| 101 SkColor background_color, |
| 102 bool premultiplied_alpha, |
| 103 SharedQuadState* shared_state, |
| 104 ResourceProvider* resource_provider) { |
| 105 uint32_t pixel_color = premultiplied_alpha ? |
| 106 SkPreMultiplyColor(texel_color) : texel_color; |
| 107 std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color); |
| 108 |
| 109 ResourceProvider::ResourceId resource = resource_provider->CreateResource( |
| 110 rect.size(), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 111 resource_provider->SetPixels( |
| 112 resource, |
| 113 reinterpret_cast<uint8_t*>(&pixels.front()), |
| 114 rect, |
| 115 rect, |
| 116 gfx::Vector2d()); |
| 117 |
| 118 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 119 |
| 120 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 121 quad->SetNew(shared_state, |
| 122 rect, |
| 123 gfx::Rect(), |
| 124 resource, |
| 125 premultiplied_alpha, |
| 126 gfx::PointF(0.0f, 0.0f), // uv_top_left |
| 127 gfx::PointF(1.0f, 1.0f), // uv_bottom_right |
| 128 background_color, |
| 129 vertex_opacity, |
| 130 false); // flipped |
| 131 return quad.Pass(); |
| 132 } |
| 133 |
97 typedef ::testing::Types<GLRenderer, | 134 typedef ::testing::Types<GLRenderer, |
98 SoftwareRenderer, | 135 SoftwareRenderer, |
99 GLRendererWithExpandedViewport, | 136 GLRendererWithExpandedViewport, |
100 SoftwareRendererWithExpandedViewport> RendererTypes; | 137 SoftwareRendererWithExpandedViewport> RendererTypes; |
101 TYPED_TEST_CASE(RendererPixelTest, RendererTypes); | 138 TYPED_TEST_CASE(RendererPixelTest, RendererTypes); |
102 | 139 |
103 typedef ::testing::Types<GLRenderer, | 140 typedef ::testing::Types<GLRenderer, |
104 GLRendererWithSkiaGPUBackend, | 141 GLRendererWithSkiaGPUBackend, |
105 SoftwareRenderer> RendererTypesWithSkiaGPUBackend; | 142 SoftwareRenderer> RendererTypesWithSkiaGPUBackend; |
106 template <typename RendererType> | 143 template <typename RendererType> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 pass_list.push_back(child_pass.Pass()); | 248 pass_list.push_back(child_pass.Pass()); |
212 pass_list.push_back(root_pass.Pass()); | 249 pass_list.push_back(root_pass.Pass()); |
213 | 250 |
214 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget( | 251 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget( |
215 &pass_list, | 252 &pass_list, |
216 child_pass_ptr, | 253 child_pass_ptr, |
217 base::FilePath(FILE_PATH_LITERAL("green_small.png")), | 254 base::FilePath(FILE_PATH_LITERAL("green_small.png")), |
218 ExactPixelComparator(true))); | 255 ExactPixelComparator(true))); |
219 } | 256 } |
220 | 257 |
| 258 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithoutBackground) { |
| 259 gfx::Rect rect(this->device_viewport_size_); |
| 260 |
| 261 RenderPass::Id id(1, 1); |
| 262 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 263 |
| 264 scoped_ptr<SharedQuadState> shared_state = |
| 265 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 266 |
| 267 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad( |
| 268 gfx::Rect(this->device_viewport_size_), |
| 269 SkColorSetARGB(128, 0, 255, 0), // Texel color. |
| 270 SK_ColorTRANSPARENT, // Background color. |
| 271 true, // Premultiplied alpha. |
| 272 shared_state.get(), |
| 273 this->resource_provider_.get()); |
| 274 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>()); |
| 275 |
| 276 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 277 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false); |
| 278 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 279 |
| 280 RenderPassList pass_list; |
| 281 pass_list.push_back(pass.Pass()); |
| 282 |
| 283 EXPECT_TRUE(this->RunPixelTest( |
| 284 &pass_list, |
| 285 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 286 FuzzyPixelOffByOneComparator(true))); |
| 287 } |
| 288 |
| 289 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) { |
| 290 gfx::Rect rect(this->device_viewport_size_); |
| 291 |
| 292 RenderPass::Id id(1, 1); |
| 293 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 294 |
| 295 scoped_ptr<SharedQuadState> texture_quad_state = |
| 296 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 297 texture_quad_state->opacity = 0.5f; |
| 298 |
| 299 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad( |
| 300 gfx::Rect(this->device_viewport_size_), |
| 301 SK_ColorTRANSPARENT, // Texel color. |
| 302 SK_ColorGREEN, // Background color. |
| 303 true, // Premultiplied alpha. |
| 304 texture_quad_state.get(), |
| 305 this->resource_provider_.get()); |
| 306 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>()); |
| 307 |
| 308 scoped_ptr<SharedQuadState> color_quad_state = |
| 309 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 310 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 311 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false); |
| 312 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 313 |
| 314 RenderPassList pass_list; |
| 315 pass_list.push_back(pass.Pass()); |
| 316 |
| 317 EXPECT_TRUE(this->RunPixelTest( |
| 318 &pass_list, |
| 319 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 320 FuzzyPixelOffByOneComparator(true))); |
| 321 } |
| 322 |
| 323 // TODO(skaslev): The software renderer does not support non-premultplied alpha. |
| 324 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) { |
| 325 gfx::Rect rect(this->device_viewport_size_); |
| 326 |
| 327 RenderPass::Id id(1, 1); |
| 328 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 329 |
| 330 scoped_ptr<SharedQuadState> shared_state = |
| 331 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 332 |
| 333 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad( |
| 334 gfx::Rect(this->device_viewport_size_), |
| 335 SkColorSetARGB(128, 0, 255, 0), // Texel color. |
| 336 SK_ColorTRANSPARENT, // Background color. |
| 337 false, // Premultiplied alpha. |
| 338 shared_state.get(), |
| 339 this->resource_provider_.get()); |
| 340 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>()); |
| 341 |
| 342 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 343 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false); |
| 344 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 345 |
| 346 RenderPassList pass_list; |
| 347 pass_list.push_back(pass.Pass()); |
| 348 |
| 349 EXPECT_TRUE(this->RunPixelTest( |
| 350 &pass_list, |
| 351 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 352 FuzzyPixelOffByOneComparator(true))); |
| 353 } |
| 354 |
| 355 // TODO(skaslev): The software renderer does not support non-premultplied alpha. |
| 356 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) { |
| 357 gfx::Rect rect(this->device_viewport_size_); |
| 358 |
| 359 RenderPass::Id id(1, 1); |
| 360 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 361 |
| 362 scoped_ptr<SharedQuadState> texture_quad_state = |
| 363 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 364 texture_quad_state->opacity = 0.5f; |
| 365 |
| 366 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad( |
| 367 gfx::Rect(this->device_viewport_size_), |
| 368 SK_ColorTRANSPARENT, // Texel color. |
| 369 SK_ColorGREEN, // Background color. |
| 370 false, // Premultiplied alpha. |
| 371 texture_quad_state.get(), |
| 372 this->resource_provider_.get()); |
| 373 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>()); |
| 374 |
| 375 scoped_ptr<SharedQuadState> color_quad_state = |
| 376 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 377 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 378 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false); |
| 379 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 380 |
| 381 RenderPassList pass_list; |
| 382 pass_list.push_back(pass.Pass()); |
| 383 |
| 384 EXPECT_TRUE(this->RunPixelTest( |
| 385 &pass_list, |
| 386 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 387 FuzzyPixelOffByOneComparator(true))); |
| 388 } |
| 389 |
221 class VideoGLRendererPixelTest : public GLRendererPixelTest { | 390 class VideoGLRendererPixelTest : public GLRendererPixelTest { |
222 protected: | 391 protected: |
223 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad( | 392 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad( |
224 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) { | 393 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) { |
225 gfx::Rect rect(this->device_viewport_size_); | 394 gfx::Rect rect(this->device_viewport_size_); |
226 gfx::Rect opaque_rect(0, 0, 0, 0); | 395 gfx::Rect opaque_rect(0, 0, 0, 0); |
227 | 396 |
228 ResourceProvider::ResourceId y_resource = | 397 ResourceProvider::ResourceId y_resource = |
229 resource_provider_->CreateResource( | 398 resource_provider_->CreateResource( |
230 this->device_viewport_size_, | 399 this->device_viewport_size_, |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1406 |
1238 EXPECT_TRUE(this->RunPixelTest( | 1407 EXPECT_TRUE(this->RunPixelTest( |
1239 &pass_list, | 1408 &pass_list, |
1240 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), | 1409 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), |
1241 ExactPixelComparator(true))); | 1410 ExactPixelComparator(true))); |
1242 } | 1411 } |
1243 #endif // !defined(OS_ANDROID) | 1412 #endif // !defined(OS_ANDROID) |
1244 | 1413 |
1245 } // namespace | 1414 } // namespace |
1246 } // namespace cc | 1415 } // namespace cc |
OLD | NEW |