OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <string> | 10 #include <string> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "base/run_loop.h" | 25 #include "base/run_loop.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/synchronization/waitable_event.h" | 27 #include "base/synchronization/waitable_event.h" |
28 #include "base/test/launcher/unit_test_launcher.h" | 28 #include "base/test/launcher/unit_test_launcher.h" |
29 #include "base/test/test_suite.h" | 29 #include "base/test/test_suite.h" |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
32 #include "content/common/gpu/client/gl_helper.h" | 32 #include "content/common/gpu/client/gl_helper.h" |
33 #include "content/common/gpu/client/gl_helper_readback_support.h" | 33 #include "content/common/gpu/client/gl_helper_readback_support.h" |
34 #include "content/common/gpu/client/gl_helper_scaling.h" | 34 #include "content/common/gpu/client/gl_helper_scaling.h" |
35 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 35 #include "gpu/command_buffer/client/gl_in_process_context.h" |
36 #include "gpu/command_buffer/client/gles2_implementation.h" | |
36 #include "media/base/video_frame.h" | 37 #include "media/base/video_frame.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
38 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
39 #include "third_party/skia/include/core/SkTypes.h" | 40 #include "third_party/skia/include/core/SkTypes.h" |
40 #include "ui/gl/gl_implementation.h" | 41 #include "ui/gl/gl_implementation.h" |
41 | 42 |
42 namespace content { | 43 namespace content { |
43 | 44 |
44 using blink::WebGLId; | |
45 using blink::WebGraphicsContext3D; | |
46 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; | |
47 | |
48 content::GLHelper::ScalerQuality kQualities[] = { | 45 content::GLHelper::ScalerQuality kQualities[] = { |
49 content::GLHelper::SCALER_QUALITY_BEST, | 46 content::GLHelper::SCALER_QUALITY_BEST, |
50 content::GLHelper::SCALER_QUALITY_GOOD, | 47 content::GLHelper::SCALER_QUALITY_GOOD, |
51 content::GLHelper::SCALER_QUALITY_FAST, }; | 48 content::GLHelper::SCALER_QUALITY_FAST, }; |
52 | 49 |
53 const char* kQualityNames[] = {"best", "good", "fast", }; | 50 const char* kQualityNames[] = {"best", "good", "fast", }; |
54 | 51 |
55 class GLHelperTest : public testing::Test { | 52 class GLHelperTest : public testing::Test { |
56 protected: | 53 protected: |
57 void SetUp() override { | 54 void SetUp() override { |
58 WebGraphicsContext3D::Attributes attributes; | 55 gpu::gles2::ContextCreationAttribHelper attributes; |
59 bool lose_context_when_out_of_memory = false; | 56 attributes.alpha_size = 8; |
Ken Russell (switch to Gerrit)
2016/03/16 01:34:38
Is the default value for this at lower levels "fal
danakj
2016/03/16 01:44:48
Yeah.
https://code.google.com/p/chromium/codesear
| |
60 context_ = | 57 attributes.depth_size = 24; |
61 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | 58 attributes.red_size = 8; |
62 attributes, lose_context_when_out_of_memory); | 59 attributes.green_size = 8; |
63 context_->InitializeOnCurrentThread(); | 60 attributes.blue_size = 8; |
64 context_support_ = context_->GetContextSupport(); | 61 attributes.stencil_size = 8; |
65 helper_.reset( | 62 attributes.samples = 4; |
66 new content::GLHelper(context_->GetGLInterface(), context_support_)); | 63 attributes.sample_buffers = 1; |
67 helper_scaling_.reset(new content::GLHelperScaling( | 64 attributes.bind_generates_resource = false; |
68 context_->GetGLInterface(), helper_.get())); | 65 |
66 context_.reset(gpu::GLInProcessContext::Create( | |
67 nullptr, /* service */ | |
68 nullptr, /* surface */ | |
69 true, /* offscreen */ | |
70 gfx::kNullAcceleratedWidget, /* window */ | |
71 gfx::Size(1, 1), /* size */ | |
72 nullptr, /* share_context */ | |
73 true, /* use_global_share_group */ | |
74 attributes, gfx::PreferDiscreteGpu, | |
75 ::gpu::GLInProcessContextSharedMemoryLimits(), | |
76 nullptr, /* gpu_memory_buffer_manager */ | |
77 nullptr /* image_factory */)); | |
78 gl_ = context_->GetImplementation(); | |
79 gpu::ContextSupport* support = context_->GetImplementation(); | |
80 | |
81 helper_.reset(new content::GLHelper(gl_, support)); | |
82 helper_scaling_.reset(new content::GLHelperScaling(gl_, helper_.get())); | |
69 } | 83 } |
70 | 84 |
71 void TearDown() override { | 85 void TearDown() override { |
72 helper_scaling_.reset(NULL); | 86 helper_scaling_.reset(NULL); |
73 helper_.reset(NULL); | 87 helper_.reset(NULL); |
74 context_.reset(NULL); | 88 context_.reset(NULL); |
75 } | 89 } |
76 | 90 |
77 void StartTracing(const std::string& filter) { | 91 void StartTracing(const std::string& filter) { |
78 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 92 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 SetChannel(bitmap.get(), x, y, 2, (x + y) / 5 * 50 + 5); | 707 SetChannel(bitmap.get(), x, y, 2, (x + y) / 5 * 50 + 5); |
694 SetChannel(bitmap.get(), x, y, 3, 255); | 708 SetChannel(bitmap.get(), x, y, 3, 255); |
695 break; | 709 break; |
696 } | 710 } |
697 } | 711 } |
698 } | 712 } |
699 return bitmap; | 713 return bitmap; |
700 } | 714 } |
701 | 715 |
702 // Binds texture and framebuffer and loads the bitmap pixels into the texture. | 716 // Binds texture and framebuffer and loads the bitmap pixels into the texture. |
703 void BindTextureAndFrameBuffer(WebGLId texture, | 717 void BindTextureAndFrameBuffer(GLuint texture, |
704 WebGLId framebuffer, | 718 GLuint framebuffer, |
705 SkBitmap* bitmap, | 719 SkBitmap* bitmap, |
706 int width, | 720 int width, |
707 int height) { | 721 int height) { |
708 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); | 722 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
709 context_->bindTexture(GL_TEXTURE_2D, texture); | 723 gl_->BindTexture(GL_TEXTURE_2D, texture); |
710 context_->texImage2D(GL_TEXTURE_2D, | 724 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, |
711 0, | 725 GL_UNSIGNED_BYTE, bitmap->getPixels()); |
712 GL_RGBA, | |
713 width, | |
714 height, | |
715 0, | |
716 GL_RGBA, | |
717 GL_UNSIGNED_BYTE, | |
718 bitmap->getPixels()); | |
719 } | 726 } |
720 | 727 |
721 // Create a test image, transform it using | 728 // Create a test image, transform it using |
722 // GLHelper::CropScaleReadbackAndCleanTexture and a reference implementation | 729 // GLHelper::CropScaleReadbackAndCleanTexture and a reference implementation |
723 // and compare the results. | 730 // and compare the results. |
724 void TestCropScaleReadbackAndCleanTexture(int xsize, | 731 void TestCropScaleReadbackAndCleanTexture(int xsize, |
725 int ysize, | 732 int ysize, |
726 int scaled_xsize, | 733 int scaled_xsize, |
727 int scaled_ysize, | 734 int scaled_ysize, |
728 int test_pattern, | 735 int test_pattern, |
729 SkColorType out_color_type, | 736 SkColorType out_color_type, |
730 bool swizzle, | 737 bool swizzle, |
731 size_t quality_index) { | 738 size_t quality_index) { |
732 DCHECK(out_color_type == kAlpha_8_SkColorType || | 739 DCHECK(out_color_type == kAlpha_8_SkColorType || |
733 out_color_type == kRGBA_8888_SkColorType || | 740 out_color_type == kRGBA_8888_SkColorType || |
734 out_color_type == kBGRA_8888_SkColorType); | 741 out_color_type == kBGRA_8888_SkColorType); |
735 WebGLId src_texture = context_->createTexture(); | 742 GLuint src_texture; |
736 WebGLId framebuffer = context_->createFramebuffer(); | 743 gl_->GenTextures(1, &src_texture); |
744 GLuint framebuffer; | |
745 gl_->GenFramebuffers(1, &framebuffer); | |
737 scoped_ptr<SkBitmap> input_pixels = | 746 scoped_ptr<SkBitmap> input_pixels = |
738 CreateTestBitmap(xsize, ysize, test_pattern); | 747 CreateTestBitmap(xsize, ysize, test_pattern); |
739 BindTextureAndFrameBuffer( | 748 BindTextureAndFrameBuffer( |
740 src_texture, framebuffer, input_pixels.get(), xsize, ysize); | 749 src_texture, framebuffer, input_pixels.get(), xsize, ysize); |
741 | 750 |
742 std::string message = base::StringPrintf( | 751 std::string message = base::StringPrintf( |
743 "input size: %dx%d " | 752 "input size: %dx%d " |
744 "output size: %dx%d " | 753 "output size: %dx%d " |
745 "pattern: %d , quality: %s, " | 754 "pattern: %d , quality: %s, " |
746 "out_color_type: %d", | 755 "out_color_type: %d", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 // Now compare the results. | 815 // Now compare the results. |
807 SkAutoLockPixels lock_input(truth_pixels); | 816 SkAutoLockPixels lock_input(truth_pixels); |
808 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; | 817 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; |
809 Compare(&truth_pixels, | 818 Compare(&truth_pixels, |
810 &output_pixels, | 819 &output_pixels, |
811 2, | 820 2, |
812 input_pixels.get(), | 821 input_pixels.get(), |
813 dummy_stages, | 822 dummy_stages, |
814 message + " comparing against transformed/scaled"); | 823 message + " comparing against transformed/scaled"); |
815 | 824 |
816 context_->deleteTexture(src_texture); | 825 gl_->DeleteTextures(1, &src_texture); |
817 context_->deleteFramebuffer(framebuffer); | 826 gl_->DeleteFramebuffers(1, &framebuffer); |
818 } | 827 } |
819 | 828 |
820 // Scaling test: Create a test image, scale it using GLHelperScaling | 829 // Scaling test: Create a test image, scale it using GLHelperScaling |
821 // and a reference implementation and compare the results. | 830 // and a reference implementation and compare the results. |
822 void TestScale(int xsize, | 831 void TestScale(int xsize, |
823 int ysize, | 832 int ysize, |
824 int scaled_xsize, | 833 int scaled_xsize, |
825 int scaled_ysize, | 834 int scaled_ysize, |
826 int test_pattern, | 835 int test_pattern, |
827 size_t quality_index, | 836 size_t quality_index, |
828 bool flip) { | 837 bool flip) { |
829 WebGLId src_texture = context_->createTexture(); | 838 GLuint src_texture; |
830 WebGLId framebuffer = context_->createFramebuffer(); | 839 gl_->GenTextures(1, &src_texture); |
840 GLuint framebuffer; | |
841 gl_->GenFramebuffers(1, &framebuffer); | |
831 scoped_ptr<SkBitmap> input_pixels = | 842 scoped_ptr<SkBitmap> input_pixels = |
832 CreateTestBitmap(xsize, ysize, test_pattern); | 843 CreateTestBitmap(xsize, ysize, test_pattern); |
833 BindTextureAndFrameBuffer( | 844 BindTextureAndFrameBuffer( |
834 src_texture, framebuffer, input_pixels.get(), xsize, ysize); | 845 src_texture, framebuffer, input_pixels.get(), xsize, ysize); |
835 | 846 |
836 std::string message = base::StringPrintf( | 847 std::string message = base::StringPrintf( |
837 "input size: %dx%d " | 848 "input size: %dx%d " |
838 "output size: %dx%d " | 849 "output size: %dx%d " |
839 "pattern: %d quality: %s", | 850 "pattern: %d quality: %s", |
840 xsize, | 851 xsize, |
841 ysize, | 852 ysize, |
842 scaled_xsize, | 853 scaled_xsize, |
843 scaled_ysize, | 854 scaled_ysize, |
844 test_pattern, | 855 test_pattern, |
845 kQualityNames[quality_index]); | 856 kQualityNames[quality_index]); |
846 | 857 |
847 std::vector<GLHelperScaling::ScalerStage> stages; | 858 std::vector<GLHelperScaling::ScalerStage> stages; |
848 helper_scaling_->ComputeScalerStages(kQualities[quality_index], | 859 helper_scaling_->ComputeScalerStages(kQualities[quality_index], |
849 gfx::Size(xsize, ysize), | 860 gfx::Size(xsize, ysize), |
850 gfx::Rect(0, 0, xsize, ysize), | 861 gfx::Rect(0, 0, xsize, ysize), |
851 gfx::Size(scaled_xsize, scaled_ysize), | 862 gfx::Size(scaled_xsize, scaled_ysize), |
852 flip, | 863 flip, |
853 false, | 864 false, |
854 &stages); | 865 &stages); |
855 ValidateScalerStages(kQualities[quality_index], | 866 ValidateScalerStages(kQualities[quality_index], |
856 stages, | 867 stages, |
857 gfx::Size(scaled_xsize, scaled_ysize), | 868 gfx::Size(scaled_xsize, scaled_ysize), |
858 message); | 869 message); |
859 | 870 |
860 WebGLId dst_texture = | 871 GLuint dst_texture = helper_->CopyAndScaleTexture( |
861 helper_->CopyAndScaleTexture(src_texture, | 872 src_texture, gfx::Size(xsize, ysize), |
862 gfx::Size(xsize, ysize), | 873 gfx::Size(scaled_xsize, scaled_ysize), flip, kQualities[quality_index]); |
863 gfx::Size(scaled_xsize, scaled_ysize), | |
864 flip, | |
865 kQualities[quality_index]); | |
866 | 874 |
867 SkBitmap output_pixels; | 875 SkBitmap output_pixels; |
868 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, | 876 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, |
869 scaled_ysize, | 877 scaled_ysize, |
870 kRGBA_8888_SkColorType, | 878 kRGBA_8888_SkColorType, |
871 kPremul_SkAlphaType)); | 879 kPremul_SkAlphaType)); |
872 | 880 |
873 helper_->ReadbackTextureSync( | 881 helper_->ReadbackTextureSync( |
874 dst_texture, | 882 dst_texture, |
875 gfx::Rect(0, 0, scaled_xsize, scaled_ysize), | 883 gfx::Rect(0, 0, scaled_xsize, scaled_ysize), |
(...skipping 23 matching lines...) Expand all Loading... | |
899 kPremul_SkAlphaType)); | 907 kPremul_SkAlphaType)); |
900 ScaleSlowRecursive( | 908 ScaleSlowRecursive( |
901 input_pixels.get(), &truth_pixels, kQualities[quality_index]); | 909 input_pixels.get(), &truth_pixels, kQualities[quality_index]); |
902 Compare(&truth_pixels, | 910 Compare(&truth_pixels, |
903 &output_pixels, | 911 &output_pixels, |
904 2, | 912 2, |
905 input_pixels.get(), | 913 input_pixels.get(), |
906 stages, | 914 stages, |
907 message + " comparing against scaled"); | 915 message + " comparing against scaled"); |
908 | 916 |
909 context_->deleteTexture(src_texture); | 917 gl_->DeleteTextures(1, &src_texture); |
910 context_->deleteTexture(dst_texture); | 918 gl_->DeleteTextures(1, &dst_texture); |
911 context_->deleteFramebuffer(framebuffer); | 919 gl_->DeleteFramebuffers(1, &framebuffer); |
912 } | 920 } |
913 | 921 |
914 // Create a scaling pipeline and check that it is made up of | 922 // Create a scaling pipeline and check that it is made up of |
915 // valid scaling operations. | 923 // valid scaling operations. |
916 void TestScalerPipeline(size_t quality, | 924 void TestScalerPipeline(size_t quality, |
917 int xsize, | 925 int xsize, |
918 int ysize, | 926 int ysize, |
919 int dst_xsize, | 927 int dst_xsize, |
920 int dst_ysize) { | 928 int dst_ysize) { |
921 std::vector<GLHelperScaling::ScalerStage> stages; | 929 std::vector<GLHelperScaling::ScalerStage> stages; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 } | 1183 } |
1176 } | 1184 } |
1177 } | 1185 } |
1178 return true; | 1186 return true; |
1179 } | 1187 } |
1180 | 1188 |
1181 void BindAndAttachTextureWithPixels(GLuint src_texture, | 1189 void BindAndAttachTextureWithPixels(GLuint src_texture, |
1182 SkColorType color_type, | 1190 SkColorType color_type, |
1183 const gfx::Size& src_size, | 1191 const gfx::Size& src_size, |
1184 const SkBitmap& input_pixels) { | 1192 const SkBitmap& input_pixels) { |
1185 context_->bindTexture(GL_TEXTURE_2D, src_texture); | 1193 gl_->BindTexture(GL_TEXTURE_2D, src_texture); |
1186 GLenum format = 0; | 1194 GLenum format = 0; |
1187 switch (color_type) { | 1195 switch (color_type) { |
1188 case kBGRA_8888_SkColorType: | 1196 case kBGRA_8888_SkColorType: |
1189 format = GL_BGRA_EXT; | 1197 format = GL_BGRA_EXT; |
1190 break; | 1198 break; |
1191 case kRGBA_8888_SkColorType: | 1199 case kRGBA_8888_SkColorType: |
1192 format = GL_RGBA; | 1200 format = GL_RGBA; |
1193 break; | 1201 break; |
1194 case kRGB_565_SkColorType: | 1202 case kRGB_565_SkColorType: |
1195 format = GL_RGB; | 1203 format = GL_RGB; |
1196 break; | 1204 break; |
1197 default: | 1205 default: |
1198 NOTREACHED(); | 1206 NOTREACHED(); |
1199 } | 1207 } |
1200 GLenum type = (color_type == kRGB_565_SkColorType) ? | 1208 GLenum type = (color_type == kRGB_565_SkColorType) ? |
1201 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | 1209 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; |
1202 context_->texImage2D(GL_TEXTURE_2D, | 1210 gl_->TexImage2D(GL_TEXTURE_2D, 0, format, src_size.width(), |
1203 0, | 1211 src_size.height(), 0, format, type, |
1204 format, | 1212 input_pixels.getPixels()); |
1205 src_size.width(), | |
1206 src_size.height(), | |
1207 0, | |
1208 format, | |
1209 type, | |
1210 input_pixels.getPixels()); | |
1211 } | 1213 } |
1212 | 1214 |
1213 void ReadBackTexture(GLuint src_texture, | 1215 void ReadBackTexture(GLuint src_texture, |
1214 const gfx::Size& src_size, | 1216 const gfx::Size& src_size, |
1215 unsigned char* pixels, | 1217 unsigned char* pixels, |
1216 SkColorType color_type, | 1218 SkColorType color_type, |
1217 bool async) { | 1219 bool async) { |
1218 if (async) { | 1220 if (async) { |
1219 base::RunLoop run_loop; | 1221 base::RunLoop run_loop; |
1220 helper_->ReadbackTextureAsync(src_texture, | 1222 helper_->ReadbackTextureAsync(src_texture, |
(...skipping 16 matching lines...) Expand all Loading... | |
1237 bool async) { | 1239 bool async) { |
1238 SkImageInfo info = | 1240 SkImageInfo info = |
1239 SkImageInfo::Make(src_size.width(), | 1241 SkImageInfo::Make(src_size.width(), |
1240 src_size.height(), | 1242 src_size.height(), |
1241 color_type, | 1243 color_type, |
1242 kPremul_SkAlphaType); | 1244 kPremul_SkAlphaType); |
1243 if (!helper_->IsReadbackConfigSupported(color_type)) { | 1245 if (!helper_->IsReadbackConfigSupported(color_type)) { |
1244 LOG(INFO) << "Skipping test format not supported" << color_type; | 1246 LOG(INFO) << "Skipping test format not supported" << color_type; |
1245 return true; | 1247 return true; |
1246 } | 1248 } |
1247 WebGLId src_texture = context_->createTexture(); | 1249 GLuint src_texture; |
1250 gl_->GenTextures(1, &src_texture); | |
1248 SkBitmap input_pixels; | 1251 SkBitmap input_pixels; |
1249 input_pixels.allocPixels(info); | 1252 input_pixels.allocPixels(info); |
1250 // Test Pattern-1, Fill with Plain color pattern. | 1253 // Test Pattern-1, Fill with Plain color pattern. |
1251 // Erase the input bitmap with red color. | 1254 // Erase the input bitmap with red color. |
1252 input_pixels.eraseColor(SK_ColorRED); | 1255 input_pixels.eraseColor(SK_ColorRED); |
1253 BindAndAttachTextureWithPixels(src_texture, | 1256 BindAndAttachTextureWithPixels(src_texture, |
1254 color_type, | 1257 color_type, |
1255 src_size, | 1258 src_size, |
1256 input_pixels); | 1259 input_pixels); |
1257 SkBitmap output_pixels; | 1260 SkBitmap output_pixels; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 BindAndAttachTextureWithPixels(src_texture, | 1294 BindAndAttachTextureWithPixels(src_texture, |
1292 color_type, | 1295 color_type, |
1293 src_size, | 1296 src_size, |
1294 input_pixels); | 1297 input_pixels); |
1295 ReadBackTexture(src_texture, src_size, pixels, color_type, async); | 1298 ReadBackTexture(src_texture, src_size, pixels, color_type, async); |
1296 result = IsEqual(input_pixels, output_pixels); | 1299 result = IsEqual(input_pixels, output_pixels); |
1297 if (!result) { | 1300 if (!result) { |
1298 LOG(ERROR) << "Bitmap comparision failure Pattern-3"; | 1301 LOG(ERROR) << "Bitmap comparision failure Pattern-3"; |
1299 return false; | 1302 return false; |
1300 } | 1303 } |
1301 context_->deleteTexture(src_texture); | 1304 gl_->DeleteTextures(1, &src_texture); |
1302 if (HasFailure()) { | 1305 if (HasFailure()) { |
1303 return false; | 1306 return false; |
1304 } | 1307 } |
1305 return true; | 1308 return true; |
1306 } | 1309 } |
1307 | 1310 |
1308 // YUV readback test. Create a test pattern, convert to YUV | 1311 // YUV readback test. Create a test pattern, convert to YUV |
1309 // with reference implementation and compare to what gl_helper | 1312 // with reference implementation and compare to what gl_helper |
1310 // returns. | 1313 // returns. |
1311 void TestYUVReadback(int xsize, | 1314 void TestYUVReadback(int xsize, |
1312 int ysize, | 1315 int ysize, |
1313 int output_xsize, | 1316 int output_xsize, |
1314 int output_ysize, | 1317 int output_ysize, |
1315 int xmargin, | 1318 int xmargin, |
1316 int ymargin, | 1319 int ymargin, |
1317 int test_pattern, | 1320 int test_pattern, |
1318 bool flip, | 1321 bool flip, |
1319 bool use_mrt, | 1322 bool use_mrt, |
1320 content::GLHelper::ScalerQuality quality) { | 1323 content::GLHelper::ScalerQuality quality) { |
1321 WebGLId src_texture = context_->createTexture(); | 1324 GLuint src_texture; |
1325 gl_->GenTextures(1, &src_texture); | |
1322 SkBitmap input_pixels; | 1326 SkBitmap input_pixels; |
1323 input_pixels.allocN32Pixels(xsize, ysize); | 1327 input_pixels.allocN32Pixels(xsize, ysize); |
1324 | 1328 |
1325 for (int x = 0; x < xsize; ++x) { | 1329 for (int x = 0; x < xsize; ++x) { |
1326 for (int y = 0; y < ysize; ++y) { | 1330 for (int y = 0; y < ysize; ++y) { |
1327 switch (test_pattern) { | 1331 switch (test_pattern) { |
1328 case 0: // Smooth test pattern | 1332 case 0: // Smooth test pattern |
1329 SetChannel(&input_pixels, x, y, 0, x * 10); | 1333 SetChannel(&input_pixels, x, y, 0, x * 10); |
1330 SetChannel(&input_pixels, x, y, 1, y * 10); | 1334 SetChannel(&input_pixels, x, y, 1, y * 10); |
1331 SetChannel(&input_pixels, x, y, 2, (x + y) * 10); | 1335 SetChannel(&input_pixels, x, y, 2, (x + y) * 10); |
1332 SetChannel(&input_pixels, x, y, 3, 255); | 1336 SetChannel(&input_pixels, x, y, 3, 255); |
1333 break; | 1337 break; |
1334 case 1: // Small blocks | 1338 case 1: // Small blocks |
1335 SetChannel(&input_pixels, x, y, 0, x & 1 ? 255 : 0); | 1339 SetChannel(&input_pixels, x, y, 0, x & 1 ? 255 : 0); |
1336 SetChannel(&input_pixels, x, y, 1, y & 1 ? 255 : 0); | 1340 SetChannel(&input_pixels, x, y, 1, y & 1 ? 255 : 0); |
1337 SetChannel(&input_pixels, x, y, 2, (x + y) & 1 ? 255 : 0); | 1341 SetChannel(&input_pixels, x, y, 2, (x + y) & 1 ? 255 : 0); |
1338 SetChannel(&input_pixels, x, y, 3, 255); | 1342 SetChannel(&input_pixels, x, y, 3, 255); |
1339 break; | 1343 break; |
1340 case 2: // Medium blocks | 1344 case 2: // Medium blocks |
1341 SetChannel(&input_pixels, x, y, 0, 10 + x / 2 * 50); | 1345 SetChannel(&input_pixels, x, y, 0, 10 + x / 2 * 50); |
1342 SetChannel(&input_pixels, x, y, 1, 10 + y / 3 * 50); | 1346 SetChannel(&input_pixels, x, y, 1, 10 + y / 3 * 50); |
1343 SetChannel(&input_pixels, x, y, 2, (x + y) / 5 * 50 + 5); | 1347 SetChannel(&input_pixels, x, y, 2, (x + y) / 5 * 50 + 5); |
1344 SetChannel(&input_pixels, x, y, 3, 255); | 1348 SetChannel(&input_pixels, x, y, 3, 255); |
1345 break; | 1349 break; |
1346 } | 1350 } |
1347 } | 1351 } |
1348 } | 1352 } |
1349 | 1353 |
1350 context_->bindTexture(GL_TEXTURE_2D, src_texture); | 1354 gl_->BindTexture(GL_TEXTURE_2D, src_texture); |
1351 context_->texImage2D(GL_TEXTURE_2D, | 1355 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsize, ysize, 0, GL_RGBA, |
1352 0, | 1356 GL_UNSIGNED_BYTE, input_pixels.getPixels()); |
1353 GL_RGBA, | |
1354 xsize, | |
1355 ysize, | |
1356 0, | |
1357 GL_RGBA, | |
1358 GL_UNSIGNED_BYTE, | |
1359 input_pixels.getPixels()); | |
1360 | 1357 |
1361 gpu::Mailbox mailbox; | 1358 gpu::Mailbox mailbox; |
1362 context_->genMailboxCHROMIUM(mailbox.name); | 1359 gl_->GenMailboxCHROMIUM(mailbox.name); |
1363 EXPECT_FALSE(mailbox.IsZero()); | 1360 EXPECT_FALSE(mailbox.IsZero()); |
1364 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1361 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
1365 const blink::WGC3Duint64 fence_sync = context_->insertFenceSyncCHROMIUM(); | 1362 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); |
1366 context_->GetGLInterface()->ShallowFlushCHROMIUM(); | 1363 gl_->ShallowFlushCHROMIUM(); |
1367 | 1364 |
1368 gpu::SyncToken sync_token; | 1365 gpu::SyncToken sync_token; |
1369 ASSERT_TRUE(context_->genSyncTokenCHROMIUM(fence_sync, | 1366 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
1370 sync_token.GetData())); | |
1371 | 1367 |
1372 std::string message = base::StringPrintf( | 1368 std::string message = base::StringPrintf( |
1373 "input size: %dx%d " | 1369 "input size: %dx%d " |
1374 "output size: %dx%d " | 1370 "output size: %dx%d " |
1375 "margin: %dx%d " | 1371 "margin: %dx%d " |
1376 "pattern: %d %s %s", | 1372 "pattern: %d %s %s", |
1377 xsize, | 1373 xsize, |
1378 ysize, | 1374 ysize, |
1379 output_xsize, | 1375 output_xsize, |
1380 output_ysize, | 1376 output_ysize, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1486 ComparePlane(V, | 1482 ComparePlane(V, |
1487 v_stride, | 1483 v_stride, |
1488 output_frame->visible_data(media::VideoFrame::kVPlane), | 1484 output_frame->visible_data(media::VideoFrame::kVPlane), |
1489 output_frame->stride(media::VideoFrame::kVPlane), | 1485 output_frame->stride(media::VideoFrame::kVPlane), |
1490 2, | 1486 2, |
1491 output_xsize / 2, | 1487 output_xsize / 2, |
1492 output_ysize / 2, | 1488 output_ysize / 2, |
1493 &input_pixels, | 1489 &input_pixels, |
1494 message + " V plane"); | 1490 message + " V plane"); |
1495 | 1491 |
1496 context_->deleteTexture(src_texture); | 1492 gl_->DeleteTextures(1, &src_texture); |
1497 } | 1493 } |
1498 | 1494 |
1499 void TestAddOps(int src, int dst, bool scale_x, bool allow3) { | 1495 void TestAddOps(int src, int dst, bool scale_x, bool allow3) { |
1500 std::deque<GLHelperScaling::ScaleOp> ops; | 1496 std::deque<GLHelperScaling::ScaleOp> ops; |
1501 GLHelperScaling::ScaleOp::AddOps(src, dst, scale_x, allow3, &ops); | 1497 GLHelperScaling::ScaleOp::AddOps(src, dst, scale_x, allow3, &ops); |
1502 // Scale factor 3 is a special case. | 1498 // Scale factor 3 is a special case. |
1503 // It is currently only allowed by itself. | 1499 // It is currently only allowed by itself. |
1504 if (allow3 && dst * 3 >= src && dst * 2 < src) { | 1500 if (allow3 && dst * 3 >= src && dst * 2 < src) { |
1505 EXPECT_EQ(ops[0].scale_factor, 3); | 1501 EXPECT_EQ(ops[0].scale_factor, 3); |
1506 EXPECT_EQ(ops.size(), 1U); | 1502 EXPECT_EQ(ops.size(), 1U); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1688 100, | 1684 100, |
1689 1, | 1685 1, |
1690 1, | 1686 1, |
1691 "100x100 -> 100x32 bilinear4 Y\n" | 1687 "100x100 -> 100x32 bilinear4 Y\n" |
1692 "100x32 -> 100x4 bilinear4 Y\n" | 1688 "100x32 -> 100x4 bilinear4 Y\n" |
1693 "100x4 -> 64x1 bilinear2x2\n" | 1689 "100x4 -> 64x1 bilinear2x2\n" |
1694 "64x1 -> 8x1 bilinear4 X\n" | 1690 "64x1 -> 8x1 bilinear4 X\n" |
1695 "8x1 -> 1x1 bilinear4 X\n"); | 1691 "8x1 -> 1x1 bilinear4 X\n"); |
1696 } | 1692 } |
1697 | 1693 |
1698 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; | 1694 scoped_ptr<gpu::GLInProcessContext> context_; |
1699 gpu::ContextSupport* context_support_; | 1695 gpu::gles2::GLES2Interface* gl_; |
1700 scoped_ptr<content::GLHelper> helper_; | 1696 scoped_ptr<content::GLHelper> helper_; |
1701 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1697 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
1702 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1698 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1703 }; | 1699 }; |
1704 | 1700 |
1705 class GLHelperPixelTest : public GLHelperTest { | 1701 class GLHelperPixelTest : public GLHelperTest { |
1706 private: | 1702 private: |
1707 gfx::DisableNullDrawGLBindings enable_pixel_output_; | 1703 gfx::DisableNullDrawGLBindings enable_pixel_output_; |
1708 }; | 1704 }; |
1709 | 1705 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1987 } | 1983 } |
1988 } | 1984 } |
1989 } | 1985 } |
1990 | 1986 |
1991 TEST_F(GLHelperTest, CheckOptimizations) { | 1987 TEST_F(GLHelperTest, CheckOptimizations) { |
1992 // Test in baseclass since it is friends with GLHelperScaling | 1988 // Test in baseclass since it is friends with GLHelperScaling |
1993 CheckOptimizationsTest(); | 1989 CheckOptimizationsTest(); |
1994 } | 1990 } |
1995 | 1991 |
1996 } // namespace content | 1992 } // namespace content |
OLD | NEW |