| 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 <GLES3/gl3.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "cc/paint/paint_flags.h" | 11 #include "cc/paint/paint_flags.h" |
| 12 #include "cc/paint/skia_paint_canvas.h" | 12 #include "cc/paint/skia_paint_canvas.h" |
| 13 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
| 14 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 14 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
| 15 #include "gpu/command_buffer/common/capabilities.h" |
| 15 #include "media/base/timestamp_constants.h" | 16 #include "media/base/timestamp_constants.h" |
| 16 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 17 #include "media/base/video_util.h" | 18 #include "media/base/video_util.h" |
| 18 #include "media/renderers/skcanvas_video_renderer.h" | 19 #include "media/renderers/skcanvas_video_renderer.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/libyuv/include/libyuv/convert.h" | 21 #include "third_party/libyuv/include/libyuv/convert.h" |
| 21 #include "third_party/skia/include/core/SkImage.h" | 22 #include "third_party/skia/include/core/SkImage.h" |
| 22 #include "third_party/skia/include/core/SkRefCnt.h" | 23 #include "third_party/skia/include/core/SkRefCnt.h" |
| 23 #include "third_party/skia/include/core/SkSurface.h" | 24 #include "third_party/skia/include/core/SkSurface.h" |
| 24 #include "third_party/skia/include/gpu/GrContext.h" | 25 #include "third_party/skia/include/gpu/GrContext.h" |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 const int stride = width + offset_x; | 714 const int stride = width + offset_x; |
| 714 const size_t byte_size = stride * (height + offset_y) * 2; | 715 const size_t byte_size = stride * (height + offset_y) * 2; |
| 715 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 716 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
| 716 static_cast<unsigned char*>(base::AlignedAlloc( | 717 static_cast<unsigned char*>(base::AlignedAlloc( |
| 717 byte_size, media::VideoFrame::kFrameAddressAlignment))); | 718 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
| 718 const gfx::Rect rect(offset_x, offset_y, width, height); | 719 const gfx::Rect rect(offset_x, offset_y, width, height); |
| 719 scoped_refptr<media::VideoFrame> video_frame = | 720 scoped_refptr<media::VideoFrame> video_frame = |
| 720 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, | 721 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, |
| 721 memory.get(), cropped_frame()->timestamp()); | 722 memory.get(), cropped_frame()->timestamp()); |
| 722 | 723 |
| 723 // Create GL context. | |
| 724 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | |
| 725 sk_sp<GrContext> gr_context(GrContext::Create( | |
| 726 kOpenGL_GrBackend, | |
| 727 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
| 728 TestGLES2Interface gles2; | 724 TestGLES2Interface gles2; |
| 729 Context3D context_3d(&gles2, gr_context.get()); | |
| 730 | |
| 731 // Bind the texImage2D callback to verify the uint16 to float32 conversion. | 725 // Bind the texImage2D callback to verify the uint16 to float32 conversion. |
| 732 gles2.teximage2d_callback_ = | 726 gles2.teximage2d_callback_ = |
| 733 base::Bind([](GLenum target, GLint level, GLint internalformat, | 727 base::Bind([](GLenum target, GLint level, GLint internalformat, |
| 734 GLsizei width, GLsizei height, GLint border, GLenum format, | 728 GLsizei width, GLsizei height, GLint border, GLenum format, |
| 735 GLenum type, const void* pixels) { | 729 GLenum type, const void* pixels) { |
| 736 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); | 730 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); |
| 737 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), format); | 731 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), format); |
| 738 EXPECT_EQ(GL_RGBA, internalformat); | 732 EXPECT_EQ(GL_RGBA, internalformat); |
| 739 EXPECT_EQ(0, border); | 733 EXPECT_EQ(0, border); |
| 740 EXPECT_EQ(16, width); | 734 EXPECT_EQ(16, width); |
| 741 EXPECT_EQ(16, height); | 735 EXPECT_EQ(16, height); |
| 742 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 736 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 743 const float* data = static_cast<const float*>(pixels); | 737 const float* data = static_cast<const float*>(pixels); |
| 744 for (int j = 0; j < height; j++) { | 738 for (int j = 0; j < height; j++) { |
| 745 for (int i = 0; i < width; i++) { | 739 for (int i = 0; i < width; i++) { |
| 746 const int value = i + (height - j - 1) * width; // flip_y is true. | 740 const int value = i + (height - j - 1) * width; // flip_y is true. |
| 747 float expected_value = | 741 float expected_value = |
| 748 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; | 742 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; |
| 749 EXPECT_EQ(expected_value, data[(i + j * width) * 4]); | 743 EXPECT_EQ(expected_value, data[(i + j * width) * 4]); |
| 750 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 1]); | 744 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 1]); |
| 751 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); | 745 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); |
| 752 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); | 746 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); |
| 753 } | 747 } |
| 754 } | 748 } |
| 755 }); | 749 }); |
| 756 SkCanvasVideoRenderer::TexImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), 0, | 750 SkCanvasVideoRenderer::TexImage2D( |
| 757 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, | 751 GL_TEXTURE_2D, 0, &gles2, gpu::Capabilities(), video_frame.get(), 0, |
| 758 true); | 752 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, true); |
| 759 } | 753 } |
| 760 | 754 |
| 761 TEST_F(SkCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) { | 755 TEST_F(SkCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) { |
| 762 // Create test frame. | 756 // Create test frame. |
| 763 // |offset_x| and |offset_y| define visible rect's offset to coded rect. | 757 // |offset_x| and |offset_y| define visible rect's offset to coded rect. |
| 764 const int offset_x = 3; | 758 const int offset_x = 3; |
| 765 const int offset_y = 5; | 759 const int offset_y = 5; |
| 766 const int width = 16; | 760 const int width = 16; |
| 767 const int height = 16; | 761 const int height = 16; |
| 768 const int stride = width + offset_x; | 762 const int stride = width + offset_x; |
| 769 const size_t byte_size = stride * (height + offset_y) * 2; | 763 const size_t byte_size = stride * (height + offset_y) * 2; |
| 770 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 764 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
| 771 static_cast<unsigned char*>(base::AlignedAlloc( | 765 static_cast<unsigned char*>(base::AlignedAlloc( |
| 772 byte_size, media::VideoFrame::kFrameAddressAlignment))); | 766 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
| 773 const gfx::Rect rect(offset_x, offset_y, width, height); | 767 const gfx::Rect rect(offset_x, offset_y, width, height); |
| 774 scoped_refptr<media::VideoFrame> video_frame = | 768 scoped_refptr<media::VideoFrame> video_frame = |
| 775 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, | 769 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, |
| 776 memory.get(), cropped_frame()->timestamp()); | 770 memory.get(), cropped_frame()->timestamp()); |
| 777 | 771 |
| 778 // Create GL context. | |
| 779 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | |
| 780 sk_sp<GrContext> gr_context(GrContext::Create( | |
| 781 kOpenGL_GrBackend, | |
| 782 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
| 783 TestGLES2Interface gles2; | 772 TestGLES2Interface gles2; |
| 784 Context3D context_3d(&gles2, gr_context.get()); | |
| 785 | |
| 786 // Bind the texImage2D callback to verify the uint16 to float32 conversion. | 773 // Bind the texImage2D callback to verify the uint16 to float32 conversion. |
| 787 gles2.texsubimage2d_callback_ = base::Bind([]( | 774 gles2.texsubimage2d_callback_ = base::Bind([]( |
| 788 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, | 775 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
| 789 GLsizei height, GLenum format, GLenum type, const void* pixels) { | 776 GLsizei height, GLenum format, GLenum type, const void* pixels) { |
| 790 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); | 777 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); |
| 791 EXPECT_EQ(static_cast<unsigned>(GL_RED), format); | 778 EXPECT_EQ(static_cast<unsigned>(GL_RED), format); |
| 792 EXPECT_EQ(2, xoffset); | 779 EXPECT_EQ(2, xoffset); |
| 793 EXPECT_EQ(1, yoffset); | 780 EXPECT_EQ(1, yoffset); |
| 794 EXPECT_EQ(16, width); | 781 EXPECT_EQ(16, width); |
| 795 EXPECT_EQ(16, height); | 782 EXPECT_EQ(16, height); |
| 796 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 783 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 797 const float* data = static_cast<const float*>(pixels); | 784 const float* data = static_cast<const float*>(pixels); |
| 798 for (int j = 0; j < height; j++) { | 785 for (int j = 0; j < height; j++) { |
| 799 for (int i = 0; i < width; i++) { | 786 for (int i = 0; i < width; i++) { |
| 800 const int value = i + j * width; // flip_y is false. | 787 const int value = i + j * width; // flip_y is false. |
| 801 float expected_value = | 788 float expected_value = |
| 802 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; | 789 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; |
| 803 EXPECT_EQ(expected_value, data[(i + j * width)]); | 790 EXPECT_EQ(expected_value, data[(i + j * width)]); |
| 804 } | 791 } |
| 805 } | 792 } |
| 806 }); | 793 }); |
| 807 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), | 794 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), |
| 808 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, | 795 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, |
| 809 1 /*yoffset*/, false /*flip_y*/, true); | 796 1 /*yoffset*/, false /*flip_y*/, true); |
| 810 } | 797 } |
| 811 | 798 |
| 812 } // namespace media | 799 } // namespace media |
| OLD | NEW |