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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 const int stride = width + offset_x; | 703 const int stride = width + offset_x; |
703 const size_t byte_size = stride * (height + offset_y) * 2; | 704 const size_t byte_size = stride * (height + offset_y) * 2; |
704 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 705 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
705 static_cast<unsigned char*>(base::AlignedAlloc( | 706 static_cast<unsigned char*>(base::AlignedAlloc( |
706 byte_size, media::VideoFrame::kFrameAddressAlignment))); | 707 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
707 const gfx::Rect rect(offset_x, offset_y, width, height); | 708 const gfx::Rect rect(offset_x, offset_y, width, height); |
708 scoped_refptr<media::VideoFrame> video_frame = | 709 scoped_refptr<media::VideoFrame> video_frame = |
709 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, | 710 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, |
710 memory.get(), cropped_frame()->timestamp()); | 711 memory.get(), cropped_frame()->timestamp()); |
711 | 712 |
712 // Create GL context. | |
713 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | |
714 sk_sp<GrContext> gr_context(GrContext::Create( | |
715 kOpenGL_GrBackend, | |
716 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
717 TestGLES2Interface gles2; | 713 TestGLES2Interface gles2; |
718 Context3D context_3d(&gles2, gr_context.get()); | |
719 | |
720 // Bind the texImage2D callback to verify the uint16 to float32 conversion. | 714 // Bind the texImage2D callback to verify the uint16 to float32 conversion. |
721 gles2.teximage2d_callback_ = | 715 gles2.teximage2d_callback_ = |
722 base::Bind([](GLenum target, GLint level, GLint internalformat, | 716 base::Bind([](GLenum target, GLint level, GLint internalformat, |
723 GLsizei width, GLsizei height, GLint border, GLenum format, | 717 GLsizei width, GLsizei height, GLint border, GLenum format, |
724 GLenum type, const void* pixels) { | 718 GLenum type, const void* pixels) { |
725 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); | 719 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); |
726 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), format); | 720 EXPECT_EQ(static_cast<unsigned>(GL_RGBA), format); |
727 EXPECT_EQ(GL_RGBA, internalformat); | 721 EXPECT_EQ(GL_RGBA, internalformat); |
728 EXPECT_EQ(0, border); | 722 EXPECT_EQ(0, border); |
729 EXPECT_EQ(16, width); | 723 EXPECT_EQ(16, width); |
730 EXPECT_EQ(16, height); | 724 EXPECT_EQ(16, height); |
731 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 725 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
732 const float* data = static_cast<const float*>(pixels); | 726 const float* data = static_cast<const float*>(pixels); |
733 for (int j = 0; j < height; j++) { | 727 for (int j = 0; j < height; j++) { |
734 for (int i = 0; i < width; i++) { | 728 for (int i = 0; i < width; i++) { |
735 const int value = i + (height - j - 1) * width; // flip_y is true. | 729 const int value = i + (height - j - 1) * width; // flip_y is true. |
736 float expected_value = | 730 float expected_value = |
737 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; | 731 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; |
738 EXPECT_EQ(expected_value, data[(i + j * width) * 4]); | 732 EXPECT_EQ(expected_value, data[(i + j * width) * 4]); |
739 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 1]); | 733 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 1]); |
740 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); | 734 EXPECT_EQ(expected_value, data[(i + j * width) * 4 + 2]); |
741 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); | 735 EXPECT_EQ(1.0f, data[(i + j * width) * 4 + 3]); |
742 } | 736 } |
743 } | 737 } |
744 }); | 738 }); |
745 SkCanvasVideoRenderer::TexImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), 0, | 739 SkCanvasVideoRenderer::TexImage2D( |
746 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, | 740 GL_TEXTURE_2D, 0, &gles2, gpu::Capabilities(), video_frame.get(), 0, |
747 true); | 741 GL_RGBA, GL_RGBA, GL_FLOAT, true /*flip_y*/, true); |
748 } | 742 } |
749 | 743 |
750 TEST_F(SkCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) { | 744 TEST_F(SkCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) { |
751 // Create test frame. | 745 // Create test frame. |
752 // |offset_x| and |offset_y| define visible rect's offset to coded rect. | 746 // |offset_x| and |offset_y| define visible rect's offset to coded rect. |
753 const int offset_x = 3; | 747 const int offset_x = 3; |
754 const int offset_y = 5; | 748 const int offset_y = 5; |
755 const int width = 16; | 749 const int width = 16; |
756 const int height = 16; | 750 const int height = 16; |
757 const int stride = width + offset_x; | 751 const int stride = width + offset_x; |
758 const size_t byte_size = stride * (height + offset_y) * 2; | 752 const size_t byte_size = stride * (height + offset_y) * 2; |
759 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 753 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
760 static_cast<unsigned char*>(base::AlignedAlloc( | 754 static_cast<unsigned char*>(base::AlignedAlloc( |
761 byte_size, media::VideoFrame::kFrameAddressAlignment))); | 755 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
762 const gfx::Rect rect(offset_x, offset_y, width, height); | 756 const gfx::Rect rect(offset_x, offset_y, width, height); |
763 scoped_refptr<media::VideoFrame> video_frame = | 757 scoped_refptr<media::VideoFrame> video_frame = |
764 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, | 758 CreateTestY16Frame(gfx::Size(stride, offset_y + height), rect, |
765 memory.get(), cropped_frame()->timestamp()); | 759 memory.get(), cropped_frame()->timestamp()); |
766 | 760 |
767 // Create GL context. | |
768 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | |
769 sk_sp<GrContext> gr_context(GrContext::Create( | |
770 kOpenGL_GrBackend, | |
771 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
772 TestGLES2Interface gles2; | 761 TestGLES2Interface gles2; |
773 Context3D context_3d(&gles2, gr_context.get()); | |
774 | |
775 // Bind the texImage2D callback to verify the uint16 to float32 conversion. | 762 // Bind the texImage2D callback to verify the uint16 to float32 conversion. |
776 gles2.texsubimage2d_callback_ = base::Bind([]( | 763 gles2.texsubimage2d_callback_ = base::Bind([]( |
777 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, | 764 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
778 GLsizei height, GLenum format, GLenum type, const void* pixels) { | 765 GLsizei height, GLenum format, GLenum type, const void* pixels) { |
779 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); | 766 EXPECT_EQ(static_cast<unsigned>(GL_FLOAT), type); |
780 EXPECT_EQ(static_cast<unsigned>(GL_RED), format); | 767 EXPECT_EQ(static_cast<unsigned>(GL_RED), format); |
781 EXPECT_EQ(2, xoffset); | 768 EXPECT_EQ(2, xoffset); |
782 EXPECT_EQ(1, yoffset); | 769 EXPECT_EQ(1, yoffset); |
783 EXPECT_EQ(16, width); | 770 EXPECT_EQ(16, width); |
784 EXPECT_EQ(16, height); | 771 EXPECT_EQ(16, height); |
785 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 772 EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
786 const float* data = static_cast<const float*>(pixels); | 773 const float* data = static_cast<const float*>(pixels); |
787 for (int j = 0; j < height; j++) { | 774 for (int j = 0; j < height; j++) { |
788 for (int i = 0; i < width; i++) { | 775 for (int i = 0; i < width; i++) { |
789 const int value = i + j * width; // flip_y is false. | 776 const int value = i + j * width; // flip_y is false. |
790 float expected_value = | 777 float expected_value = |
791 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; | 778 (((value & 0xFF) << 8) | (~value & 0xFF)) / 65535.f; |
792 EXPECT_EQ(expected_value, data[(i + j * width)]); | 779 EXPECT_EQ(expected_value, data[(i + j * width)]); |
793 } | 780 } |
794 } | 781 } |
795 }); | 782 }); |
796 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), | 783 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), |
797 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, | 784 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, |
798 1 /*yoffset*/, false /*flip_y*/, true); | 785 1 /*yoffset*/, false /*flip_y*/, true); |
799 } | 786 } |
800 | 787 |
801 } // namespace media | 788 } // namespace media |
OLD | NEW |