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