Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: media/renderers/skcanvas_video_renderer_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698