OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_ | 5 #ifndef CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_ |
6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_ | 6 #define CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "content/common/gpu/client/gl_helper.h" | 13 #include "content/browser/compositor/gl_helper.h" |
14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 class ShaderProgram; | 19 class ShaderProgram; |
20 class ScalerImpl; | 20 class ScalerImpl; |
21 class GLHelperTest; | 21 class GLHelperTest; |
22 | 22 |
23 // Implements GPU texture scaling methods. | 23 // Implements GPU texture scaling methods. |
(...skipping 21 matching lines...) Expand all Loading... |
45 ShaderInterface() {} | 45 ShaderInterface() {} |
46 virtual ~ShaderInterface() {} | 46 virtual ~ShaderInterface() {} |
47 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 47 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
48 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 48 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
49 virtual void Execute(GLuint source_texture, | 49 virtual void Execute(GLuint source_texture, |
50 const std::vector<GLuint>& dest_textures) = 0; | 50 const std::vector<GLuint>& dest_textures) = 0; |
51 }; | 51 }; |
52 | 52 |
53 typedef std::pair<ShaderType, bool> ShaderProgramKeyType; | 53 typedef std::pair<ShaderType, bool> ShaderProgramKeyType; |
54 | 54 |
55 GLHelperScaling(gpu::gles2::GLES2Interface* gl, | 55 GLHelperScaling(gpu::gles2::GLES2Interface* gl, GLHelper* helper); |
56 GLHelper* helper); | |
57 ~GLHelperScaling(); | 56 ~GLHelperScaling(); |
58 void InitBuffer(); | 57 void InitBuffer(); |
59 | 58 |
60 GLHelper::ScalerInterface* CreateScaler( | 59 GLHelper::ScalerInterface* CreateScaler(GLHelper::ScalerQuality quality, |
61 GLHelper::ScalerQuality quality, | 60 gfx::Size src_size, |
62 gfx::Size src_size, | 61 gfx::Rect src_subrect, |
63 gfx::Rect src_subrect, | 62 const gfx::Size& dst_size, |
64 const gfx::Size& dst_size, | 63 bool vertically_flip_texture, |
65 bool vertically_flip_texture, | 64 bool swizzle); |
66 bool swizzle); | |
67 | 65 |
68 GLHelper::ScalerInterface* CreatePlanarScaler( | 66 GLHelper::ScalerInterface* CreatePlanarScaler(const gfx::Size& src_size, |
69 const gfx::Size& src_size, | 67 const gfx::Rect& src_subrect, |
70 const gfx::Rect& src_subrect, | 68 const gfx::Size& dst_size, |
71 const gfx::Size& dst_size, | 69 bool vertically_flip_texture, |
72 bool vertically_flip_texture, | 70 bool swizzle, |
73 bool swizzle, | 71 const float color_weights[4]); |
74 const float color_weights[4]); | |
75 | 72 |
76 ShaderInterface* CreateYuvMrtShader( | 73 ShaderInterface* CreateYuvMrtShader(const gfx::Size& src_size, |
77 const gfx::Size& src_size, | 74 const gfx::Rect& src_subrect, |
78 const gfx::Rect& src_subrect, | 75 const gfx::Size& dst_size, |
79 const gfx::Size& dst_size, | 76 bool vertically_flip_texture, |
80 bool vertically_flip_texture, | 77 bool swizzle, |
81 bool swizzle, | 78 ShaderType shader); |
82 ShaderType shader); | |
83 | 79 |
84 private: | 80 private: |
85 // A ScaleOp represents a pass in a scaler pipeline, in one dimension. | 81 // A ScaleOp represents a pass in a scaler pipeline, in one dimension. |
86 // Note that when quality is GOOD, multiple scaler passes will be | 82 // Note that when quality is GOOD, multiple scaler passes will be |
87 // combined into one operation for increased performance. | 83 // combined into one operation for increased performance. |
88 // Exposed in the header file for testing purposes. | 84 // Exposed in the header file for testing purposes. |
89 struct ScaleOp { | 85 struct ScaleOp { |
90 ScaleOp(int factor, bool x, int size) | 86 ScaleOp(int factor, bool x, int size) |
91 : scale_factor(factor), scale_x(x), scale_size(size) { | 87 : scale_factor(factor), scale_x(x), scale_size(size) {} |
92 } | |
93 | 88 |
94 // Calculate a set of ScaleOp needed to convert an image of size | 89 // Calculate a set of ScaleOp needed to convert an image of size |
95 // |src| into an image of size |dst|. If |scale_x| is true, then | 90 // |src| into an image of size |dst|. If |scale_x| is true, then |
96 // the calculations are for the X axis of the image, otherwise Y. | 91 // the calculations are for the X axis of the image, otherwise Y. |
97 // If |allow3| is true, we can use a SHADER_BILINEAR3 to replace | 92 // If |allow3| is true, we can use a SHADER_BILINEAR3 to replace |
98 // a scale up and scale down with a 3-tap bilinear scale. | 93 // a scale up and scale down with a 3-tap bilinear scale. |
99 // The calculated ScaleOps are added to |ops|. | 94 // The calculated ScaleOps are added to |ops|. |
100 static void AddOps(int src, | 95 static void AddOps(int src, |
101 int dst, | 96 int dst, |
102 bool scale_x, | 97 bool scale_x, |
(...skipping 28 matching lines...) Expand all Loading... |
131 subrect->set_width(scale_size); | 126 subrect->set_width(scale_size); |
132 } else { | 127 } else { |
133 subrect->set_height(scale_size); | 128 subrect->set_height(scale_size); |
134 } | 129 } |
135 } | 130 } |
136 | 131 |
137 // A scale factor of 0 means upscale | 132 // A scale factor of 0 means upscale |
138 // 2 means 50% scale | 133 // 2 means 50% scale |
139 // 3 means 33% scale, etc. | 134 // 3 means 33% scale, etc. |
140 int scale_factor; | 135 int scale_factor; |
141 bool scale_x; // Otherwise y | 136 bool scale_x; // Otherwise y |
142 int scale_size; // Size to scale to. | 137 int scale_size; // Size to scale to. |
143 }; | 138 }; |
144 | 139 |
145 // Full specification for a single scaling stage. | 140 // Full specification for a single scaling stage. |
146 struct ScalerStage { | 141 struct ScalerStage { |
147 ScalerStage(ShaderType shader_, | 142 ScalerStage(ShaderType shader_, |
148 gfx::Size src_size_, | 143 gfx::Size src_size_, |
149 gfx::Rect src_subrect_, | 144 gfx::Rect src_subrect_, |
150 gfx::Size dst_size_, | 145 gfx::Size dst_size_, |
151 bool scale_x_, | 146 bool scale_x_, |
(...skipping 10 matching lines...) Expand all Loading... |
162 }; | 157 }; |
163 | 158 |
164 // Compute a vector of scaler stages for a particular | 159 // Compute a vector of scaler stages for a particular |
165 // set of input/output parameters. | 160 // set of input/output parameters. |
166 void ComputeScalerStages(GLHelper::ScalerQuality quality, | 161 void ComputeScalerStages(GLHelper::ScalerQuality quality, |
167 const gfx::Size& src_size, | 162 const gfx::Size& src_size, |
168 const gfx::Rect& src_subrect, | 163 const gfx::Rect& src_subrect, |
169 const gfx::Size& dst_size, | 164 const gfx::Size& dst_size, |
170 bool vertically_flip_texture, | 165 bool vertically_flip_texture, |
171 bool swizzle, | 166 bool swizzle, |
172 std::vector<ScalerStage> *scaler_stages); | 167 std::vector<ScalerStage>* scaler_stages); |
173 | 168 |
174 // Take two queues of ScaleOp structs and generate a | 169 // Take two queues of ScaleOp structs and generate a |
175 // vector of scaler stages. This is the second half of | 170 // vector of scaler stages. This is the second half of |
176 // ComputeScalerStages. | 171 // ComputeScalerStages. |
177 void ConvertScalerOpsToScalerStages( | 172 void ConvertScalerOpsToScalerStages( |
178 GLHelper::ScalerQuality quality, | 173 GLHelper::ScalerQuality quality, |
179 gfx::Size src_size, | 174 gfx::Size src_size, |
180 gfx::Rect src_subrect, | 175 gfx::Rect src_subrect, |
181 const gfx::Size& dst_size, | 176 const gfx::Size& dst_size, |
182 bool vertically_flip_texture, | 177 bool vertically_flip_texture, |
183 bool swizzle, | 178 bool swizzle, |
184 std::deque<GLHelperScaling::ScaleOp>* x_ops, | 179 std::deque<GLHelperScaling::ScaleOp>* x_ops, |
185 std::deque<GLHelperScaling::ScaleOp>* y_ops, | 180 std::deque<GLHelperScaling::ScaleOp>* y_ops, |
186 std::vector<ScalerStage> *scaler_stages); | 181 std::vector<ScalerStage>* scaler_stages); |
187 | |
188 | 182 |
189 scoped_refptr<ShaderProgram> GetShaderProgram(ShaderType type, bool swizzle); | 183 scoped_refptr<ShaderProgram> GetShaderProgram(ShaderType type, bool swizzle); |
190 | 184 |
191 // Interleaved array of 2-dimentional vertex positions (x, y) and | 185 // Interleaved array of 2-dimentional vertex positions (x, y) and |
192 // 2-dimentional texture coordinates (s, t). | 186 // 2-dimentional texture coordinates (s, t). |
193 static const GLfloat kVertexAttributes[]; | 187 static const GLfloat kVertexAttributes[]; |
194 | 188 |
195 gpu::gles2::GLES2Interface* gl_; | 189 gpu::gles2::GLES2Interface* gl_; |
196 GLHelper* helper_; | 190 GLHelper* helper_; |
197 | 191 |
198 // The buffer that holds the vertices and the texture coordinates data for | 192 // The buffer that holds the vertices and the texture coordinates data for |
199 // drawing a quad. | 193 // drawing a quad. |
200 ScopedBuffer vertex_attributes_buffer_; | 194 ScopedBuffer vertex_attributes_buffer_; |
201 | 195 |
202 std::map<ShaderProgramKeyType, | 196 std::map<ShaderProgramKeyType, scoped_refptr<ShaderProgram>> shader_programs_; |
203 scoped_refptr<ShaderProgram> > shader_programs_; | |
204 | 197 |
205 friend class ShaderProgram; | 198 friend class ShaderProgram; |
206 friend class ScalerImpl; | 199 friend class ScalerImpl; |
207 friend class GLHelperTest; | 200 friend class GLHelperTest; |
208 DISALLOW_COPY_AND_ASSIGN(GLHelperScaling); | 201 DISALLOW_COPY_AND_ASSIGN(GLHelperScaling); |
209 }; | 202 }; |
210 | 203 |
211 | |
212 } // namespace content | 204 } // namespace content |
213 | 205 |
214 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_ | 206 #endif // CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_ |
OLD | NEW |