| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <GLES3/gl3.h> |
| 5 #include <stdint.h> | 6 #include <stdint.h> |
| 6 | 7 |
| 7 #include "base/macros.h" | 8 #include "base/macros.h" |
| 8 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 11 #include "gpu/GLES2/gl2extchromium.h" |
| 11 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 12 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
| 12 #include "media/base/timestamp_constants.h" | 13 #include "media/base/timestamp_constants.h" |
| 13 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 14 #include "media/base/video_util.h" | 15 #include "media/base/video_util.h" |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 GLint border, | 587 GLint border, |
| 587 GLenum format, | 588 GLenum format, |
| 588 GLenum type, | 589 GLenum type, |
| 589 const void* pixels) override { | 590 const void* pixels) override { |
| 590 if (!teximage2d_callback_.is_null()) { | 591 if (!teximage2d_callback_.is_null()) { |
| 591 teximage2d_callback_.Run(target, level, internalformat, width, height, | 592 teximage2d_callback_.Run(target, level, internalformat, width, height, |
| 592 border, format, type, pixels); | 593 border, format, type, pixels); |
| 593 } | 594 } |
| 594 } | 595 } |
| 595 | 596 |
| 597 void TexSubImage2D(GLenum target, |
| 598 GLint level, |
| 599 GLint xoffset, |
| 600 GLint yoffset, |
| 601 GLsizei width, |
| 602 GLsizei height, |
| 603 GLenum format, |
| 604 GLenum type, |
| 605 const void* pixels) override { |
| 606 if (!texsubimage2d_callback_.is_null()) { |
| 607 texsubimage2d_callback_.Run(target, level, xoffset, yoffset, width, |
| 608 height, format, type, pixels); |
| 609 } |
| 610 } |
| 611 |
| 596 base::Callback<void(GLenum target, | 612 base::Callback<void(GLenum target, |
| 597 GLint level, | 613 GLint level, |
| 598 GLint internalformat, | 614 GLint internalformat, |
| 599 GLsizei width, | 615 GLsizei width, |
| 600 GLsizei height, | 616 GLsizei height, |
| 601 GLint border, | 617 GLint border, |
| 602 GLenum format, | 618 GLenum format, |
| 603 GLenum type, | 619 GLenum type, |
| 604 const void* pixels)> | 620 const void* pixels)> |
| 605 teximage2d_callback_; | 621 teximage2d_callback_; |
| 622 |
| 623 base::Callback<void(GLenum target, |
| 624 GLint level, |
| 625 GLint xoffset, |
| 626 GLint yoffset, |
| 627 GLsizei width, |
| 628 GLsizei height, |
| 629 GLenum format, |
| 630 GLenum type, |
| 631 const void* pixels)> |
| 632 texsubimage2d_callback_; |
| 606 }; | 633 }; |
| 607 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} | 634 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} |
| 608 } // namespace | 635 } // namespace |
| 609 | 636 |
| 610 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is | 637 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is |
| 611 // abandoned. | 638 // abandoned. |
| 612 TEST_F(SkCanvasVideoRendererTest, ContextLost) { | 639 TEST_F(SkCanvasVideoRendererTest, ContextLost) { |
| 613 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | 640 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); |
| 614 sk_sp<GrContext> gr_context(GrContext::Create( | 641 sk_sp<GrContext> gr_context(GrContext::Create( |
| 615 kOpenGL_GrBackend, | 642 kOpenGL_GrBackend, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 694 |
| 668 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); | 695 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); |
| 669 SkPaint paint; | 696 SkPaint paint; |
| 670 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, | 697 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, |
| 671 context_3d); | 698 context_3d); |
| 672 | 699 |
| 673 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); | 700 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); |
| 674 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); | 701 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); |
| 675 } | 702 } |
| 676 | 703 |
| 677 TEST_F(SkCanvasVideoRendererTest, TexImageImplY16) { | 704 TEST_F(SkCanvasVideoRendererTest, TexImage2D_Y16_RGBA32F) { |
| 678 // Create test frame. | 705 // Create test frame. |
| 679 // |offset_x| and |offset_y| define visible rect's offset to coded rect. | 706 // |offset_x| and |offset_y| define visible rect's offset to coded rect. |
| 680 const int offset_x = 3; | 707 const int offset_x = 3; |
| 681 const int offset_y = 5; | 708 const int offset_y = 5; |
| 682 const int width = 16; | 709 const int width = 16; |
| 683 const int height = 16; | 710 const int height = 16; |
| 684 const int stride = width + offset_x; | 711 const int stride = width + offset_x; |
| 685 const size_t byte_size = stride * (height + offset_y) * 2; | 712 const size_t byte_size = stride * (height + offset_y) * 2; |
| 686 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 713 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
| 687 static_cast<unsigned char*>(base::AlignedAlloc( | 714 static_cast<unsigned char*>(base::AlignedAlloc( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); | 749 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); |
| 723 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); | 750 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); |
| 724 } | 751 } |
| 725 } | 752 } |
| 726 }); | 753 }); |
| 727 SkCanvasVideoRenderer::TexImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), 0, | 754 SkCanvasVideoRenderer::TexImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), 0, |
| 728 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, | 755 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, |
| 729 true); | 756 true); |
| 730 } | 757 } |
| 731 | 758 |
| 759 TEST_F(SkCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) { |
| 760 // Create test frame. |
| 761 // |offset_x| and |offset_y| define visible rect's offset to coded rect. |
| 762 const int offset_x = 3; |
| 763 const int offset_y = 5; |
| 764 const int width = 16; |
| 765 const int height = 16; |
| 766 const int stride = width + offset_x; |
| 767 const size_t byte_size = stride * (height + offset_y) * 2; |
| 768 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
| 769 static_cast<unsigned char*>(base::AlignedAlloc( |
| 770 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
| 771 const gfx::Rect rect(offset_x, offset_y, width, height); |
| 772 scoped_refptr<media::VideoFrame> video_frame = |
| 773 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, |
| 774 memory.get(), cropped_frame()->timestamp()); |
| 775 |
| 776 // Create GL context. |
| 777 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); |
| 778 sk_sp<GrContext> gr_context(GrContext::Create( |
| 779 kOpenGL_GrBackend, |
| 780 reinterpret_cast<GrBackendContext>(null_interface.get()))); |
| 781 TestGLES2Interface gles2; |
| 782 Context3D context_3d(&gles2, gr_context.get()); |
| 783 |
| 784 // Bind the texImage2D callback to verify the uint16 to float32 conversion. |
| 785 gles2.texsubimage2d_callback_ = base::Bind([]( |
| 786 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
| 787 GLsizei height, GLenum format, GLenum type, const void* pixels) { |
| 788 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); |
| 789 EXPECT_EQ(static_cast<unsigned>(GL_RED), format); |
| 790 EXPECT_EQ(2, xoffset); |
| 791 EXPECT_EQ(1, yoffset); |
| 792 EXPECT_EQ(16, width); |
| 793 EXPECT_EQ(16, height); |
| 794 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 795 const float* data = static_cast<const float*>(pixels); |
| 796 for (int j = 0; j < height; j++) { |
| 797 for (int i = 0; i < width; i++) { |
| 798 const int value = i + j * width; // flip_y is false. |
| 799 float expected_value = |
| 800 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; |
| 801 EXPECT_EQ(expected_value, data[(i + j * width)]); |
| 802 } |
| 803 } |
| 804 }); |
| 805 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), |
| 806 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, |
| 807 1 /*yoffset*/, false /*flip_y*/, true); |
| 808 } |
| 809 |
| 732 } // namespace media | 810 } // namespace media |
| OLD | NEW |