Chromium Code Reviews| 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 EXPECT_TRUE(this->RunPixelTest( | 396 EXPECT_TRUE(this->RunPixelTest( |
| 397 &pass_list, | 397 &pass_list, |
| 398 PixelTest::NoOffscreenContext, | 398 PixelTest::NoOffscreenContext, |
| 399 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), | 399 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), |
| 400 FuzzyPixelOffByOneComparator(true))); | 400 FuzzyPixelOffByOneComparator(true))); |
| 401 } | 401 } |
| 402 | 402 |
| 403 class VideoGLRendererPixelTest : public GLRendererPixelTest { | 403 class VideoGLRendererPixelTest : public GLRendererPixelTest { |
| 404 protected: | 404 protected: |
| 405 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad( | 405 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad( |
| 406 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) { | 406 SharedQuadState* shared_state, |
| 407 gfx::Rect rect(this->device_viewport_size_); | 407 bool with_alpha, |
| 408 gfx::Rect opaque_rect(0, 0, 0, 0); | 408 bool is_transparent, |
| 409 const gfx::RectF& tex_coord_rect) { | |
| 410 const gfx::Rect rect(this->device_viewport_size_); | |
| 411 const gfx::Rect uv_rect(0, 0, rect.width() + 1 / 2, rect.height() + 1 / 2); | |
|
danakj
2014/03/21 18:11:11
a + 1 / 2 == a + (1/2) == a + 0
for integer divis
sheu
2014/03/21 20:44:50
:-(
Forgot parentheses. Fixed.
| |
| 412 const gfx::Rect opaque_rect(0, 0, 0, 0); | |
| 409 | 413 |
| 410 ResourceProvider::ResourceId y_resource = | 414 ResourceProvider::ResourceId y_resource = |
| 411 resource_provider_->CreateResource( | 415 resource_provider_->CreateResource( |
| 412 this->device_viewport_size_, | 416 this->device_viewport_size_, |
| 413 GL_CLAMP_TO_EDGE, | 417 GL_CLAMP_TO_EDGE, |
| 414 ResourceProvider::TextureUsageAny, | 418 ResourceProvider::TextureUsageAny, |
| 415 LUMINANCE_8); | 419 LUMINANCE_8); |
| 416 ResourceProvider::ResourceId u_resource = | 420 ResourceProvider::ResourceId u_resource = |
| 417 resource_provider_->CreateResource( | 421 resource_provider_->CreateResource( |
| 418 this->device_viewport_size_, | 422 this->device_viewport_size_, |
| 419 GL_CLAMP_TO_EDGE, | 423 GL_CLAMP_TO_EDGE, |
| 420 ResourceProvider::TextureUsageAny, | 424 ResourceProvider::TextureUsageAny, |
| 421 LUMINANCE_8); | 425 LUMINANCE_8); |
| 422 ResourceProvider::ResourceId v_resource = | 426 ResourceProvider::ResourceId v_resource = |
| 423 resource_provider_->CreateResource( | 427 resource_provider_->CreateResource( |
| 424 this->device_viewport_size_, | 428 this->device_viewport_size_, |
| 425 GL_CLAMP_TO_EDGE, | 429 GL_CLAMP_TO_EDGE, |
| 426 ResourceProvider::TextureUsageAny, | 430 ResourceProvider::TextureUsageAny, |
| 427 LUMINANCE_8); | 431 LUMINANCE_8); |
| 428 ResourceProvider::ResourceId a_resource = 0; | 432 ResourceProvider::ResourceId a_resource = 0; |
| 429 if (with_alpha) { | 433 if (with_alpha) { |
| 430 a_resource = resource_provider_->CreateResource( | 434 a_resource = resource_provider_->CreateResource( |
| 431 this->device_viewport_size_, | 435 this->device_viewport_size_, |
| 432 GL_CLAMP_TO_EDGE, | 436 GL_CLAMP_TO_EDGE, |
| 433 ResourceProvider::TextureUsageAny, | 437 ResourceProvider::TextureUsageAny, |
| 434 LUMINANCE_8); | 438 LUMINANCE_8); |
| 435 } | 439 } |
| 436 | 440 |
| 437 int w = this->device_viewport_size_.width(); | 441 const int y_plane_size = rect.size().GetArea(); |
| 438 int h = this->device_viewport_size_.height(); | |
| 439 const int y_plane_size = w * h; | |
| 440 gfx::Rect uv_rect((w + 1) / 2, (h + 1) / 2); | |
| 441 const int uv_plane_size = uv_rect.size().GetArea(); | 442 const int uv_plane_size = uv_rect.size().GetArea(); |
| 442 scoped_ptr<uint8_t[]> y_plane(new uint8_t[y_plane_size]); | 443 scoped_ptr<uint8_t[]> y_plane(new uint8_t[y_plane_size]); |
| 443 scoped_ptr<uint8_t[]> u_plane(new uint8_t[uv_plane_size]); | 444 scoped_ptr<uint8_t[]> u_plane(new uint8_t[uv_plane_size]); |
| 444 scoped_ptr<uint8_t[]> v_plane(new uint8_t[uv_plane_size]); | 445 scoped_ptr<uint8_t[]> v_plane(new uint8_t[uv_plane_size]); |
| 445 scoped_ptr<uint8_t[]> a_plane; | 446 scoped_ptr<uint8_t[]> a_plane; |
| 446 if (with_alpha) | 447 if (with_alpha) |
| 447 a_plane.reset(new uint8_t[y_plane_size]); | 448 a_plane.reset(new uint8_t[y_plane_size]); |
| 448 // YUV values representing Green. | 449 // YUV values representing a striped pattern of green. |
| 449 memset(y_plane.get(), 149, y_plane_size); | 450 uint8_t luma = 0; |
| 451 for (int i = 0; i < y_plane_size; ++i) | |
| 452 y_plane.get()[i] = (luma += 1); | |
| 450 memset(u_plane.get(), 43, uv_plane_size); | 453 memset(u_plane.get(), 43, uv_plane_size); |
| 451 memset(v_plane.get(), 21, uv_plane_size); | 454 memset(v_plane.get(), 21, uv_plane_size); |
| 452 if (with_alpha) | 455 if (with_alpha) |
| 453 memset(a_plane.get(), is_transparent ? 0 : 128, y_plane_size); | 456 memset(a_plane.get(), is_transparent ? 0 : 128, y_plane_size); |
| 454 | 457 |
| 455 resource_provider_->SetPixels(y_resource, y_plane.get(), rect, rect, | 458 resource_provider_->SetPixels( |
| 456 gfx::Vector2d()); | 459 y_resource, y_plane.get(), rect, rect, gfx::Vector2d()); |
| 457 resource_provider_->SetPixels(u_resource, u_plane.get(), uv_rect, uv_rect, | 460 resource_provider_->SetPixels( |
| 458 gfx::Vector2d()); | 461 u_resource, u_plane.get(), rect, uv_rect, gfx::Vector2d()); |
| 459 resource_provider_->SetPixels(v_resource, v_plane.get(), uv_rect, uv_rect, | 462 resource_provider_->SetPixels( |
| 460 gfx::Vector2d()); | 463 v_resource, v_plane.get(), rect, uv_rect, gfx::Vector2d()); |
| 461 if (with_alpha) { | 464 if (with_alpha) { |
| 462 resource_provider_->SetPixels(a_resource, a_plane.get(), rect, rect, | 465 resource_provider_->SetPixels(a_resource, a_plane.get(), rect, rect, |
| 463 gfx::Vector2d()); | 466 gfx::Vector2d()); |
| 464 } | 467 } |
| 465 | 468 |
| 466 scoped_ptr<YUVVideoDrawQuad> yuv_quad = YUVVideoDrawQuad::Create(); | 469 scoped_ptr<YUVVideoDrawQuad> yuv_quad = YUVVideoDrawQuad::Create(); |
| 467 yuv_quad->SetNew(shared_state, | 470 yuv_quad->SetNew(shared_state, |
| 468 rect, | 471 rect, |
| 469 opaque_rect, | 472 opaque_rect, |
| 470 rect, | 473 rect, |
| 471 gfx::Size(), | 474 tex_coord_rect, |
| 472 y_resource, | 475 y_resource, |
| 473 u_resource, | 476 u_resource, |
| 474 v_resource, | 477 v_resource, |
| 475 a_resource); | 478 a_resource); |
| 476 return yuv_quad.Pass(); | 479 return yuv_quad.Pass(); |
| 477 } | 480 } |
| 478 }; | 481 }; |
| 479 | 482 |
| 480 TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) { | 483 TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) { |
| 481 gfx::Rect rect(this->device_viewport_size_); | 484 gfx::Rect rect(this->device_viewport_size_); |
| 482 | 485 |
| 483 RenderPass::Id id(1, 1); | 486 RenderPass::Id id(1, 1); |
| 484 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 487 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 485 | 488 |
| 486 scoped_ptr<SharedQuadState> shared_state = | 489 scoped_ptr<SharedQuadState> shared_state = |
| 487 CreateTestSharedQuadState(gfx::Transform(), rect); | 490 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 488 | 491 |
| 489 scoped_ptr<YUVVideoDrawQuad> yuv_quad = | 492 scoped_ptr<YUVVideoDrawQuad> yuv_quad = CreateTestYUVVideoDrawQuad( |
| 490 CreateTestYUVVideoDrawQuad(shared_state.get(), false, false); | 493 shared_state.get(), false, false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f)); |
| 491 | 494 |
| 492 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); | 495 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); |
| 493 | 496 |
| 497 RenderPassList pass_list; | |
| 498 pass_list.push_back(pass.Pass()); | |
| 499 | |
| 500 EXPECT_TRUE( | |
| 501 this->RunPixelTest(&pass_list, | |
| 502 PixelTest::NoOffscreenContext, | |
| 503 base::FilePath(FILE_PATH_LITERAL("green_stripes.png")), | |
| 504 ExactPixelComparator(true))); | |
| 505 } | |
| 506 | |
| 507 TEST_F(VideoGLRendererPixelTest, OffsetYUVRect) { | |
| 508 gfx::Rect rect(this->device_viewport_size_); | |
| 509 | |
| 510 RenderPass::Id id(1, 1); | |
| 511 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | |
| 512 | |
| 513 scoped_ptr<SharedQuadState> shared_state = | |
| 514 CreateTestSharedQuadState(gfx::Transform(), rect); | |
| 515 | |
| 516 scoped_ptr<YUVVideoDrawQuad> yuv_quad = CreateTestYUVVideoDrawQuad( | |
| 517 shared_state.get(), false, false, gfx::RectF(0.125f, 0.25f, 0.75f, 0.5f)); | |
| 518 | |
| 519 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); | |
| 520 | |
| 494 RenderPassList pass_list; | 521 RenderPassList pass_list; |
| 495 pass_list.push_back(pass.Pass()); | 522 pass_list.push_back(pass.Pass()); |
| 496 | 523 |
| 497 EXPECT_TRUE(this->RunPixelTest( | 524 EXPECT_TRUE(this->RunPixelTest( |
| 498 &pass_list, | 525 &pass_list, |
| 499 PixelTest::NoOffscreenContext, | 526 PixelTest::NoOffscreenContext, |
| 500 base::FilePath(FILE_PATH_LITERAL("green.png")), | 527 base::FilePath(FILE_PATH_LITERAL("green_stripes_offset.png")), |
| 501 ExactPixelComparator(true))); | 528 ExactPixelComparator(true))); |
| 502 } | 529 } |
| 503 | 530 |
| 504 TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) { | 531 TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) { |
| 505 gfx::Rect rect(this->device_viewport_size_); | 532 gfx::Rect rect(this->device_viewport_size_); |
| 506 | 533 |
| 507 RenderPass::Id id(1, 1); | 534 RenderPass::Id id(1, 1); |
| 508 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 535 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 509 | 536 |
| 510 scoped_ptr<SharedQuadState> shared_state = | 537 scoped_ptr<SharedQuadState> shared_state = |
| 511 CreateTestSharedQuadState(gfx::Transform(), rect); | 538 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 512 | 539 |
| 513 scoped_ptr<YUVVideoDrawQuad> yuv_quad = | 540 scoped_ptr<YUVVideoDrawQuad> yuv_quad = CreateTestYUVVideoDrawQuad( |
| 514 CreateTestYUVVideoDrawQuad(shared_state.get(), true, false); | 541 shared_state.get(), true, false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f)); |
| 515 | 542 |
| 516 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); | 543 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); |
| 517 | 544 |
| 518 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | 545 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 519 color_quad->SetNew(shared_state.get(), rect, rect, SK_ColorWHITE, false); | 546 color_quad->SetNew(shared_state.get(), rect, rect, SK_ColorWHITE, false); |
| 520 | 547 |
| 521 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | 548 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 522 | 549 |
| 523 RenderPassList pass_list; | 550 RenderPassList pass_list; |
| 524 pass_list.push_back(pass.Pass()); | 551 pass_list.push_back(pass.Pass()); |
| 525 | 552 |
| 526 EXPECT_TRUE(this->RunPixelTest( | 553 EXPECT_TRUE(this->RunPixelTest( |
| 527 &pass_list, | 554 &pass_list, |
| 528 PixelTest::NoOffscreenContext, | 555 PixelTest::NoOffscreenContext, |
| 529 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), | 556 base::FilePath(FILE_PATH_LITERAL("green_stripes_alpha.png")), |
| 530 ExactPixelComparator(true))); | 557 ExactPixelComparator(true))); |
| 531 } | 558 } |
| 532 | 559 |
| 533 TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) { | 560 TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) { |
| 534 gfx::Rect rect(this->device_viewport_size_); | 561 gfx::Rect rect(this->device_viewport_size_); |
| 535 | 562 |
| 536 RenderPass::Id id(1, 1); | 563 RenderPass::Id id(1, 1); |
| 537 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | 564 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); |
| 538 | 565 |
| 539 scoped_ptr<SharedQuadState> shared_state = | 566 scoped_ptr<SharedQuadState> shared_state = |
| 540 CreateTestSharedQuadState(gfx::Transform(), rect); | 567 CreateTestSharedQuadState(gfx::Transform(), rect); |
| 541 | 568 |
| 542 scoped_ptr<YUVVideoDrawQuad> yuv_quad = | 569 scoped_ptr<YUVVideoDrawQuad> yuv_quad = CreateTestYUVVideoDrawQuad( |
| 543 CreateTestYUVVideoDrawQuad(shared_state.get(), true, true); | 570 shared_state.get(), true, true, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f)); |
|
danakj
2014/03/21 18:11:11
nit: gfx::RectF(1.f, 1.f) is much shorter way to s
sheu
2014/03/21 20:44:50
I'm adding offset support to the tests (see: new O
| |
| 544 | 571 |
| 545 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); | 572 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>()); |
| 546 | 573 |
| 547 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | 574 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); |
| 548 color_quad->SetNew(shared_state.get(), rect, rect, SK_ColorBLACK, false); | 575 color_quad->SetNew(shared_state.get(), rect, rect, SK_ColorBLACK, false); |
| 549 | 576 |
| 550 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | 577 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); |
| 551 | 578 |
| 552 RenderPassList pass_list; | 579 RenderPassList pass_list; |
| 553 pass_list.push_back(pass.Pass()); | 580 pass_list.push_back(pass.Pass()); |
| (...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2069 &pass_list, | 2096 &pass_list, |
| 2070 PixelTest::NoOffscreenContext, | 2097 PixelTest::NoOffscreenContext, |
| 2071 base::FilePath(FILE_PATH_LITERAL("wrap_mode_repeat.png")), | 2098 base::FilePath(FILE_PATH_LITERAL("wrap_mode_repeat.png")), |
| 2072 FuzzyPixelOffByOneComparator(true))); | 2099 FuzzyPixelOffByOneComparator(true))); |
| 2073 } | 2100 } |
| 2074 | 2101 |
| 2075 #endif // !defined(OS_ANDROID) | 2102 #endif // !defined(OS_ANDROID) |
| 2076 | 2103 |
| 2077 } // namespace | 2104 } // namespace |
| 2078 } // namespace cc | 2105 } // namespace cc |
| OLD | NEW |