| 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 // This file looks like a unit test, but it contains benchmarks and test | 5 // This file looks like a unit test, but it contains benchmarks and test |
| 6 // utilities intended for manual evaluation of the scalers in | 6 // utilities intended for manual evaluation of the scalers in |
| 7 // gl_helper*. These tests produce output in the form of files and printouts, | 7 // gl_helper*. These tests produce output in the form of files and printouts, |
| 8 // but cannot really "fail". There is no point in making these tests part | 8 // but cannot really "fail". There is no point in making these tests part |
| 9 // of any test automation run. | 9 // of any test automation run. |
| 10 | 10 |
| 11 #include <stddef.h> | 11 #include <stddef.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <cmath> | 13 #include <cmath> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include <GLES2/gl2.h> | 17 #include <GLES2/gl2.h> |
| 18 #include <GLES2/gl2ext.h> | 18 #include <GLES2/gl2ext.h> |
| 19 #include <GLES2/gl2extchromium.h> | 19 #include <GLES2/gl2extchromium.h> |
| 20 | 20 |
| 21 #include "base/at_exit.h" | 21 #include "base/at_exit.h" |
| 22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 23 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
| 24 #include "base/macros.h" | 24 #include "base/macros.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "content/browser/compositor/gl_helper.h" | 27 #include "components/display_compositor/gl_helper.h" |
| 28 #include "content/browser/compositor/gl_helper_scaling.h" | 28 #include "components/display_compositor/gl_helper_scaling.h" |
| 29 #include "gpu/command_buffer/client/gl_in_process_context.h" | 29 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 30 #include "gpu/command_buffer/client/gles2_implementation.h" | 30 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 31 #include "gpu/command_buffer/client/shared_memory_limits.h" | 31 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "third_party/skia/include/core/SkTypes.h" | 34 #include "third_party/skia/include/core/SkTypes.h" |
| 35 #include "ui/gfx/codec/png_codec.h" | 35 #include "ui/gfx/codec/png_codec.h" |
| 36 #include "ui/gl/gl_surface.h" | 36 #include "ui/gl/gl_surface.h" |
| 37 | 37 |
| 38 namespace content { | 38 namespace display_compositor { |
| 39 | 39 |
| 40 content::GLHelper::ScalerQuality kQualities[] = { | 40 namespace { |
| 41 content::GLHelper::SCALER_QUALITY_BEST, | 41 |
| 42 content::GLHelper::SCALER_QUALITY_GOOD, | 42 display_compositor::GLHelper::ScalerQuality kQualities[] = { |
| 43 content::GLHelper::SCALER_QUALITY_FAST, | 43 display_compositor::GLHelper::SCALER_QUALITY_BEST, |
| 44 display_compositor::GLHelper::SCALER_QUALITY_GOOD, |
| 45 display_compositor::GLHelper::SCALER_QUALITY_FAST, |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 const char* const kQualityNames[] = { | 48 const char* const kQualityNames[] = { |
| 47 "best", "good", "fast", | 49 "best", "good", "fast", |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 class GLHelperTest : public testing::Test { | 52 } // namespace |
| 53 |
| 54 class GLHelperBenchmark : public testing::Test { |
| 51 protected: | 55 protected: |
| 52 void SetUp() override { | 56 void SetUp() override { |
| 53 gpu::gles2::ContextCreationAttribHelper attributes; | 57 gpu::gles2::ContextCreationAttribHelper attributes; |
| 54 attributes.alpha_size = 8; | 58 attributes.alpha_size = 8; |
| 55 attributes.depth_size = 24; | 59 attributes.depth_size = 24; |
| 56 attributes.red_size = 8; | 60 attributes.red_size = 8; |
| 57 attributes.green_size = 8; | 61 attributes.green_size = 8; |
| 58 attributes.blue_size = 8; | 62 attributes.blue_size = 8; |
| 59 attributes.stencil_size = 8; | 63 attributes.stencil_size = 8; |
| 60 attributes.samples = 4; | 64 attributes.samples = 4; |
| 61 attributes.sample_buffers = 1; | 65 attributes.sample_buffers = 1; |
| 62 attributes.bind_generates_resource = false; | 66 attributes.bind_generates_resource = false; |
| 63 | 67 |
| 64 context_.reset(gpu::GLInProcessContext::Create( | 68 context_.reset(gpu::GLInProcessContext::Create( |
| 65 nullptr, /* service */ | 69 nullptr, /* service */ |
| 66 nullptr, /* surface */ | 70 nullptr, /* surface */ |
| 67 true, /* offscreen */ | 71 true, /* offscreen */ |
| 68 gfx::kNullAcceleratedWidget, /* window */ | 72 gfx::kNullAcceleratedWidget, /* window */ |
| 69 gfx::Size(1, 1), /* size */ | 73 gfx::Size(1, 1), /* size */ |
| 70 nullptr, /* share_context */ | 74 nullptr, /* share_context */ |
| 71 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(), | 75 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(), |
| 72 nullptr, /* gpu_memory_buffer_manager */ | 76 nullptr, /* gpu_memory_buffer_manager */ |
| 73 nullptr /* image_factory */)); | 77 nullptr /* image_factory */)); |
| 74 gl_ = context_->GetImplementation(); | 78 gl_ = context_->GetImplementation(); |
| 75 gpu::ContextSupport* support = context_->GetImplementation(); | 79 gpu::ContextSupport* support = context_->GetImplementation(); |
| 76 | 80 |
| 77 helper_.reset(new content::GLHelper(gl_, support)); | 81 helper_.reset(new display_compositor::GLHelper(gl_, support)); |
| 78 helper_scaling_.reset(new content::GLHelperScaling(gl_, helper_.get())); | 82 helper_scaling_.reset( |
| 83 new display_compositor::GLHelperScaling(gl_, helper_.get())); |
| 79 } | 84 } |
| 80 | 85 |
| 81 void TearDown() override { | 86 void TearDown() override { |
| 82 helper_scaling_.reset(NULL); | 87 helper_scaling_.reset(NULL); |
| 83 helper_.reset(NULL); | 88 helper_.reset(NULL); |
| 84 context_.reset(NULL); | 89 context_.reset(NULL); |
| 85 } | 90 } |
| 86 | 91 |
| 87 void LoadPngFileToSkBitmap(const base::FilePath& filename, SkBitmap* bitmap) { | 92 void LoadPngFileToSkBitmap(const base::FilePath& filename, SkBitmap* bitmap) { |
| 88 std::string compressed; | 93 std::string compressed; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 105 ASSERT_TRUE(compressed.size()); | 110 ASSERT_TRUE(compressed.size()); |
| 106 FILE* f = base::OpenFile(filename, "wb"); | 111 FILE* f = base::OpenFile(filename, "wb"); |
| 107 ASSERT_TRUE(f); | 112 ASSERT_TRUE(f); |
| 108 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), | 113 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), |
| 109 compressed.size()); | 114 compressed.size()); |
| 110 base::CloseFile(f); | 115 base::CloseFile(f); |
| 111 } | 116 } |
| 112 | 117 |
| 113 std::unique_ptr<gpu::GLInProcessContext> context_; | 118 std::unique_ptr<gpu::GLInProcessContext> context_; |
| 114 gpu::gles2::GLES2Interface* gl_; | 119 gpu::gles2::GLES2Interface* gl_; |
| 115 std::unique_ptr<content::GLHelper> helper_; | 120 std::unique_ptr<display_compositor::GLHelper> helper_; |
| 116 std::unique_ptr<content::GLHelperScaling> helper_scaling_; | 121 std::unique_ptr<display_compositor::GLHelperScaling> helper_scaling_; |
| 117 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 122 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 TEST_F(GLHelperTest, ScaleBenchmark) { | 125 TEST_F(GLHelperBenchmark, ScaleBenchmark) { |
| 121 int output_sizes[] = {1920, 1080, 1249, 720, // Output size on pixel | 126 int output_sizes[] = {1920, 1080, 1249, 720, // Output size on pixel |
| 122 256, 144}; | 127 256, 144}; |
| 123 int input_sizes[] = {3200, 2040, 2560, 1476, // Pixel tab size | 128 int input_sizes[] = {3200, 2040, 2560, 1476, // Pixel tab size |
| 124 1920, 1080, 1280, 720, 800, 480, 256, 144}; | 129 1920, 1080, 1280, 720, 800, 480, 256, 144}; |
| 125 | 130 |
| 126 for (size_t q = 0; q < arraysize(kQualities); q++) { | 131 for (size_t q = 0; q < arraysize(kQualities); q++) { |
| 127 for (size_t outsize = 0; outsize < arraysize(output_sizes); outsize += 2) { | 132 for (size_t outsize = 0; outsize < arraysize(output_sizes); outsize += 2) { |
| 128 for (size_t insize = 0; insize < arraysize(input_sizes); insize += 2) { | 133 for (size_t insize = 0; insize < arraysize(input_sizes); insize += 2) { |
| 129 uint32_t src_texture; | 134 uint32_t src_texture; |
| 130 gl_->GenTextures(1, &src_texture); | 135 gl_->GenTextures(1, &src_texture); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 144 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); | 149 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 145 gl_->BindTexture(GL_TEXTURE_2D, dst_texture); | 150 gl_->BindTexture(GL_TEXTURE_2D, dst_texture); |
| 146 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dst_size.width(), | 151 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dst_size.width(), |
| 147 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | 152 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 148 gl_->BindTexture(GL_TEXTURE_2D, src_texture); | 153 gl_->BindTexture(GL_TEXTURE_2D, src_texture); |
| 149 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_size.width(), | 154 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_size.width(), |
| 150 src_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, | 155 src_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 151 input.getPixels()); | 156 input.getPixels()); |
| 152 | 157 |
| 153 gfx::Rect src_subrect(0, 0, src_size.width(), src_size.height()); | 158 gfx::Rect src_subrect(0, 0, src_size.width(), src_size.height()); |
| 154 std::unique_ptr<content::GLHelper::ScalerInterface> scaler( | 159 std::unique_ptr<display_compositor::GLHelper::ScalerInterface> scaler( |
| 155 helper_->CreateScaler(kQualities[q], src_size, src_subrect, | 160 helper_->CreateScaler(kQualities[q], src_size, src_subrect, |
| 156 dst_size, false, false)); | 161 dst_size, false, false)); |
| 157 // Scale once beforehand before we start measuring. | 162 // Scale once beforehand before we start measuring. |
| 158 scaler->Scale(src_texture, dst_texture); | 163 scaler->Scale(src_texture, dst_texture); |
| 159 gl_->Finish(); | 164 gl_->Finish(); |
| 160 | 165 |
| 161 base::TimeTicks start_time = base::TimeTicks::Now(); | 166 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 162 int iterations = 0; | 167 int iterations = 0; |
| 163 base::TimeTicks end_time; | 168 base::TimeTicks end_time; |
| 164 while (true) { | 169 while (true) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 192 } | 197 } |
| 193 } | 198 } |
| 194 } | 199 } |
| 195 | 200 |
| 196 // This is more of a test utility than a test. | 201 // This is more of a test utility than a test. |
| 197 // Put an PNG image called "testimage.png" in your | 202 // Put an PNG image called "testimage.png" in your |
| 198 // current directory, then run this test. It will | 203 // current directory, then run this test. It will |
| 199 // create testoutput_Q_P.png, where Q is the scaling | 204 // create testoutput_Q_P.png, where Q is the scaling |
| 200 // mode and P is the scaling percentage taken from | 205 // mode and P is the scaling percentage taken from |
| 201 // the table below. | 206 // the table below. |
| 202 TEST_F(GLHelperTest, DISABLED_ScaleTestImage) { | 207 TEST_F(GLHelperBenchmark, DISABLED_ScaleTestImage) { |
| 203 int percents[] = { | 208 int percents[] = { |
| 204 230, 180, 150, 110, 90, 70, 50, 49, 40, 20, 10, | 209 230, 180, 150, 110, 90, 70, 50, 49, 40, 20, 10, |
| 205 }; | 210 }; |
| 206 | 211 |
| 207 SkBitmap input; | 212 SkBitmap input; |
| 208 LoadPngFileToSkBitmap(base::FilePath(FILE_PATH_LITERAL("testimage.png")), | 213 LoadPngFileToSkBitmap(base::FilePath(FILE_PATH_LITERAL("testimage.png")), |
| 209 &input); | 214 &input); |
| 210 | 215 |
| 211 uint32_t framebuffer; | 216 uint32_t framebuffer; |
| 212 gl_->GenFramebuffers(1, &framebuffer); | 217 gl_->GenFramebuffers(1, &framebuffer); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 237 std::string filename = base::StringPrintf("testoutput_%s_%d.ppm", | 242 std::string filename = base::StringPrintf("testoutput_%s_%d.ppm", |
| 238 kQualityNames[q], percents[p]); | 243 kQualityNames[q], percents[p]); |
| 239 VLOG(0) << "Writing " << filename; | 244 VLOG(0) << "Writing " << filename; |
| 240 SaveToFile(&output_pixels, base::FilePath::FromUTF8Unsafe(filename)); | 245 SaveToFile(&output_pixels, base::FilePath::FromUTF8Unsafe(filename)); |
| 241 } | 246 } |
| 242 } | 247 } |
| 243 gl_->DeleteTextures(1, &src_texture); | 248 gl_->DeleteTextures(1, &src_texture); |
| 244 gl_->DeleteFramebuffers(1, &framebuffer); | 249 gl_->DeleteFramebuffers(1, &framebuffer); |
| 245 } | 250 } |
| 246 | 251 |
| 247 } // namespace content | 252 } // namespace display_compositor |
| OLD | NEW |