| 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/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "components/display_compositor/gl_helper.h" | 28 #include "components/viz/display_compositor/gl_helper.h" |
| 29 #include "components/display_compositor/gl_helper_scaling.h" | 29 #include "components/viz/display_compositor/gl_helper_scaling.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 "gpu/ipc/gl_in_process_context.h" | 32 #include "gpu/ipc/gl_in_process_context.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 35 #include "third_party/skia/include/core/SkTypes.h" | 35 #include "third_party/skia/include/core/SkTypes.h" |
| 36 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
| 37 #include "ui/gl/gl_surface.h" | 37 #include "ui/gl/gl_surface.h" |
| 38 | 38 |
| 39 namespace display_compositor { | 39 namespace viz { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 display_compositor::GLHelper::ScalerQuality kQualities[] = { | 43 GLHelper::ScalerQuality kQualities[] = { |
| 44 display_compositor::GLHelper::SCALER_QUALITY_BEST, | 44 GLHelper::SCALER_QUALITY_BEST, GLHelper::SCALER_QUALITY_GOOD, |
| 45 display_compositor::GLHelper::SCALER_QUALITY_GOOD, | 45 GLHelper::SCALER_QUALITY_FAST, |
| 46 display_compositor::GLHelper::SCALER_QUALITY_FAST, | |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 const char* const kQualityNames[] = { | 48 const char* const kQualityNames[] = { |
| 50 "best", "good", "fast", | 49 "best", "good", "fast", |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 } // namespace | 52 } // namespace |
| 54 | 53 |
| 55 class GLHelperBenchmark : public testing::Test { | 54 class GLHelperBenchmark : public testing::Test { |
| 56 protected: | 55 protected: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 73 true, /* offscreen */ | 72 true, /* offscreen */ |
| 74 gpu::kNullSurfaceHandle, /* window */ | 73 gpu::kNullSurfaceHandle, /* window */ |
| 75 nullptr, /* share_context */ | 74 nullptr, /* share_context */ |
| 76 attributes, gpu::SharedMemoryLimits(), | 75 attributes, gpu::SharedMemoryLimits(), |
| 77 nullptr, /* gpu_memory_buffer_manager */ | 76 nullptr, /* gpu_memory_buffer_manager */ |
| 78 nullptr, /* image_factory */ | 77 nullptr, /* image_factory */ |
| 79 base::ThreadTaskRunnerHandle::Get())); | 78 base::ThreadTaskRunnerHandle::Get())); |
| 80 gl_ = context_->GetImplementation(); | 79 gl_ = context_->GetImplementation(); |
| 81 gpu::ContextSupport* support = context_->GetImplementation(); | 80 gpu::ContextSupport* support = context_->GetImplementation(); |
| 82 | 81 |
| 83 helper_.reset(new display_compositor::GLHelper(gl_, support)); | 82 helper_.reset(new GLHelper(gl_, support)); |
| 84 helper_scaling_.reset( | 83 helper_scaling_.reset(new GLHelperScaling(gl_, helper_.get())); |
| 85 new display_compositor::GLHelperScaling(gl_, helper_.get())); | |
| 86 } | 84 } |
| 87 | 85 |
| 88 void TearDown() override { | 86 void TearDown() override { |
| 89 helper_scaling_.reset(NULL); | 87 helper_scaling_.reset(NULL); |
| 90 helper_.reset(NULL); | 88 helper_.reset(NULL); |
| 91 context_.reset(NULL); | 89 context_.reset(NULL); |
| 92 } | 90 } |
| 93 | 91 |
| 94 void LoadPngFileToSkBitmap(const base::FilePath& filename, SkBitmap* bitmap) { | 92 void LoadPngFileToSkBitmap(const base::FilePath& filename, SkBitmap* bitmap) { |
| 95 std::string compressed; | 93 std::string compressed; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 112 ASSERT_TRUE(compressed.size()); | 110 ASSERT_TRUE(compressed.size()); |
| 113 FILE* f = base::OpenFile(filename, "wb"); | 111 FILE* f = base::OpenFile(filename, "wb"); |
| 114 ASSERT_TRUE(f); | 112 ASSERT_TRUE(f); |
| 115 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), | 113 ASSERT_EQ(fwrite(&*compressed.begin(), 1, compressed.size(), f), |
| 116 compressed.size()); | 114 compressed.size()); |
| 117 base::CloseFile(f); | 115 base::CloseFile(f); |
| 118 } | 116 } |
| 119 | 117 |
| 120 std::unique_ptr<gpu::GLInProcessContext> context_; | 118 std::unique_ptr<gpu::GLInProcessContext> context_; |
| 121 gpu::gles2::GLES2Interface* gl_; | 119 gpu::gles2::GLES2Interface* gl_; |
| 122 std::unique_ptr<display_compositor::GLHelper> helper_; | 120 std::unique_ptr<GLHelper> helper_; |
| 123 std::unique_ptr<display_compositor::GLHelperScaling> helper_scaling_; | 121 std::unique_ptr<GLHelperScaling> helper_scaling_; |
| 124 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 122 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
| 125 }; | 123 }; |
| 126 | 124 |
| 127 TEST_F(GLHelperBenchmark, ScaleBenchmark) { | 125 TEST_F(GLHelperBenchmark, ScaleBenchmark) { |
| 128 int output_sizes[] = {1920, 1080, 1249, 720, // Output size on pixel | 126 int output_sizes[] = {1920, 1080, 1249, 720, // Output size on pixel |
| 129 256, 144}; | 127 256, 144}; |
| 130 int input_sizes[] = {3200, 2040, 2560, 1476, // Pixel tab size | 128 int input_sizes[] = {3200, 2040, 2560, 1476, // Pixel tab size |
| 131 1920, 1080, 1280, 720, 800, 480, 256, 144}; | 129 1920, 1080, 1280, 720, 800, 480, 256, 144}; |
| 132 | 130 |
| 133 for (size_t q = 0; q < arraysize(kQualities); q++) { | 131 for (size_t q = 0; q < arraysize(kQualities); q++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 151 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); | 149 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 152 gl_->BindTexture(GL_TEXTURE_2D, dst_texture); | 150 gl_->BindTexture(GL_TEXTURE_2D, dst_texture); |
| 153 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dst_size.width(), | 151 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dst_size.width(), |
| 154 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | 152 dst_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 155 gl_->BindTexture(GL_TEXTURE_2D, src_texture); | 153 gl_->BindTexture(GL_TEXTURE_2D, src_texture); |
| 156 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_size.width(), | 154 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_size.width(), |
| 157 src_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, | 155 src_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 158 input.getPixels()); | 156 input.getPixels()); |
| 159 | 157 |
| 160 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()); |
| 161 std::unique_ptr<display_compositor::GLHelper::ScalerInterface> scaler( | 159 std::unique_ptr<GLHelper::ScalerInterface> scaler(helper_->CreateScaler( |
| 162 helper_->CreateScaler(kQualities[q], src_size, src_subrect, | 160 kQualities[q], src_size, src_subrect, dst_size, false, false)); |
| 163 dst_size, false, false)); | |
| 164 // Scale once beforehand before we start measuring. | 161 // Scale once beforehand before we start measuring. |
| 165 scaler->Scale(src_texture, dst_texture); | 162 scaler->Scale(src_texture, dst_texture); |
| 166 gl_->Finish(); | 163 gl_->Finish(); |
| 167 | 164 |
| 168 base::TimeTicks start_time = base::TimeTicks::Now(); | 165 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 169 int iterations = 0; | 166 int iterations = 0; |
| 170 base::TimeTicks end_time; | 167 base::TimeTicks end_time; |
| 171 while (true) { | 168 while (true) { |
| 172 for (int i = 0; i < 50; i++) { | 169 for (int i = 0; i < 50; i++) { |
| 173 iterations++; | 170 iterations++; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 std::string filename = base::StringPrintf("testoutput_%s_%d.ppm", | 241 std::string filename = base::StringPrintf("testoutput_%s_%d.ppm", |
| 245 kQualityNames[q], percents[p]); | 242 kQualityNames[q], percents[p]); |
| 246 VLOG(0) << "Writing " << filename; | 243 VLOG(0) << "Writing " << filename; |
| 247 SaveToFile(&output_pixels, base::FilePath::FromUTF8Unsafe(filename)); | 244 SaveToFile(&output_pixels, base::FilePath::FromUTF8Unsafe(filename)); |
| 248 } | 245 } |
| 249 } | 246 } |
| 250 gl_->DeleteTextures(1, &src_texture); | 247 gl_->DeleteTextures(1, &src_texture); |
| 251 gl_->DeleteFramebuffers(1, &framebuffer); | 248 gl_->DeleteFramebuffers(1, &framebuffer); |
| 252 } | 249 } |
| 253 | 250 |
| 254 } // namespace display_compositor | 251 } // namespace viz |
| OLD | NEW |