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 "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "third_party/skia/include/core/SkTypes.h" | 33 #include "third_party/skia/include/core/SkTypes.h" |
34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
35 #include "ui/gl/gl_surface.h" | 35 #include "ui/gl/gl_surface.h" |
36 | 36 |
37 namespace content { | 37 namespace display_compositor { |
38 | 38 |
39 content::GLHelper::ScalerQuality kQualities[] = { | 39 namespace { |
40 content::GLHelper::SCALER_QUALITY_BEST, | 40 |
41 content::GLHelper::SCALER_QUALITY_GOOD, | 41 display_compositor::GLHelper::ScalerQuality kQualities[] = { |
42 content::GLHelper::SCALER_QUALITY_FAST, | 42 display_compositor::GLHelper::SCALER_QUALITY_BEST, |
43 display_compositor::GLHelper::SCALER_QUALITY_GOOD, | |
44 display_compositor::GLHelper::SCALER_QUALITY_FAST, | |
43 }; | 45 }; |
44 | 46 |
45 const char* const kQualityNames[] = { | 47 const char* const kQualityNames[] = { |
46 "best", "good", "fast", | 48 "best", "good", "fast", |
47 }; | 49 }; |
48 | 50 |
51 } // namespace | |
52 | |
49 class GLHelperTest : public testing::Test { | 53 class GLHelperTest : public testing::Test { |
piman
2016/04/20 20:07:22
nit: this should probably be in the anonymous name
Fady Samuel
2016/04/20 21:41:11
This turns out to be hard because GLHelperScaling:
piman
2016/04/20 21:51:22
I checked, and we actually do have ODR issues - bo
Fady Samuel
2016/04/20 22:12:59
Done.
| |
50 protected: | 54 protected: |
51 void SetUp() override { | 55 void SetUp() override { |
52 gpu::gles2::ContextCreationAttribHelper attributes; | 56 gpu::gles2::ContextCreationAttribHelper attributes; |
53 attributes.alpha_size = 8; | 57 attributes.alpha_size = 8; |
54 attributes.depth_size = 24; | 58 attributes.depth_size = 24; |
55 attributes.red_size = 8; | 59 attributes.red_size = 8; |
56 attributes.green_size = 8; | 60 attributes.green_size = 8; |
57 attributes.blue_size = 8; | 61 attributes.blue_size = 8; |
58 attributes.stencil_size = 8; | 62 attributes.stencil_size = 8; |
59 attributes.samples = 4; | 63 attributes.samples = 4; |
60 attributes.sample_buffers = 1; | 64 attributes.sample_buffers = 1; |
61 attributes.bind_generates_resource = false; | 65 attributes.bind_generates_resource = false; |
62 | 66 |
63 context_.reset(gpu::GLInProcessContext::Create( | 67 context_.reset(gpu::GLInProcessContext::Create( |
64 nullptr, /* service */ | 68 nullptr, /* service */ |
65 nullptr, /* surface */ | 69 nullptr, /* surface */ |
66 true, /* offscreen */ | 70 true, /* offscreen */ |
67 gfx::kNullAcceleratedWidget, /* window */ | 71 gfx::kNullAcceleratedWidget, /* window */ |
68 gfx::Size(1, 1), /* size */ | 72 gfx::Size(1, 1), /* size */ |
69 nullptr, /* share_context */ | 73 nullptr, /* share_context */ |
70 attributes, gfx::PreferDiscreteGpu, | 74 attributes, gfx::PreferDiscreteGpu, |
71 ::gpu::GLInProcessContextSharedMemoryLimits(), | 75 ::gpu::GLInProcessContextSharedMemoryLimits(), |
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(GLHelperTest, 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++) { |
(...skipping 17 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |