Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: content/common/gpu/client/gl_helper_scaling.h

Issue 1802383002: Move gl_helper to content/browser/compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_
7
8 #include <deque>
9 #include <map>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "content/common/gpu/client/gl_helper.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
16
17 namespace content {
18
19 class ShaderProgram;
20 class ScalerImpl;
21 class GLHelperTest;
22
23 // Implements GPU texture scaling methods.
24 // Note that you should probably not use this class directly.
25 // See gl_helper.cc::CreateScaler instead.
26 class CONTENT_EXPORT GLHelperScaling {
27 public:
28 enum ShaderType {
29 SHADER_BILINEAR,
30 SHADER_BILINEAR2,
31 SHADER_BILINEAR3,
32 SHADER_BILINEAR4,
33 SHADER_BILINEAR2X2,
34 SHADER_BICUBIC_UPSCALE,
35 SHADER_BICUBIC_HALF_1D,
36 SHADER_PLANAR,
37 SHADER_YUV_MRT_PASS1,
38 SHADER_YUV_MRT_PASS2,
39 };
40
41 // Similar to ScalerInterface, but can generate multiple outputs.
42 // Used for YUV conversion in gl_helper.c
43 class CONTENT_EXPORT ShaderInterface {
44 public:
45 ShaderInterface() {}
46 virtual ~ShaderInterface() {}
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.
49 virtual void Execute(GLuint source_texture,
50 const std::vector<GLuint>& dest_textures) = 0;
51 };
52
53 typedef std::pair<ShaderType, bool> ShaderProgramKeyType;
54
55 GLHelperScaling(gpu::gles2::GLES2Interface* gl,
56 GLHelper* helper);
57 ~GLHelperScaling();
58 void InitBuffer();
59
60 GLHelper::ScalerInterface* CreateScaler(
61 GLHelper::ScalerQuality quality,
62 gfx::Size src_size,
63 gfx::Rect src_subrect,
64 const gfx::Size& dst_size,
65 bool vertically_flip_texture,
66 bool swizzle);
67
68 GLHelper::ScalerInterface* CreatePlanarScaler(
69 const gfx::Size& src_size,
70 const gfx::Rect& src_subrect,
71 const gfx::Size& dst_size,
72 bool vertically_flip_texture,
73 bool swizzle,
74 const float color_weights[4]);
75
76 ShaderInterface* CreateYuvMrtShader(
77 const gfx::Size& src_size,
78 const gfx::Rect& src_subrect,
79 const gfx::Size& dst_size,
80 bool vertically_flip_texture,
81 bool swizzle,
82 ShaderType shader);
83
84 private:
85 // A ScaleOp represents a pass in a scaler pipeline, in one dimension.
86 // Note that when quality is GOOD, multiple scaler passes will be
87 // combined into one operation for increased performance.
88 // Exposed in the header file for testing purposes.
89 struct ScaleOp {
90 ScaleOp(int factor, bool x, int size)
91 : scale_factor(factor), scale_x(x), scale_size(size) {
92 }
93
94 // 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
96 // 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
98 // a scale up and scale down with a 3-tap bilinear scale.
99 // The calculated ScaleOps are added to |ops|.
100 static void AddOps(int src,
101 int dst,
102 bool scale_x,
103 bool allow3,
104 std::deque<ScaleOp>* ops) {
105 int num_downscales = 0;
106 if (allow3 && dst * 3 >= src && dst * 2 < src) {
107 // Technically, this should be a scale up and then a
108 // scale down, but it makes the optimization code more
109 // complicated.
110 ops->push_back(ScaleOp(3, scale_x, dst));
111 return;
112 }
113 while ((dst << num_downscales) < src) {
114 num_downscales++;
115 }
116 if ((dst << num_downscales) != src) {
117 ops->push_back(ScaleOp(0, scale_x, dst << num_downscales));
118 }
119 while (num_downscales) {
120 num_downscales--;
121 ops->push_back(ScaleOp(2, scale_x, dst << num_downscales));
122 }
123 }
124
125 // Update |size| to its new size. Before calling this function
126 // |size| should be the size of the input image. After calling it,
127 // |size| will be the size of the image after this particular
128 // scaling operation.
129 void UpdateSize(gfx::Size* subrect) {
130 if (scale_x) {
131 subrect->set_width(scale_size);
132 } else {
133 subrect->set_height(scale_size);
134 }
135 }
136
137 // A scale factor of 0 means upscale
138 // 2 means 50% scale
139 // 3 means 33% scale, etc.
140 int scale_factor;
141 bool scale_x; // Otherwise y
142 int scale_size; // Size to scale to.
143 };
144
145 // Full specification for a single scaling stage.
146 struct ScalerStage {
147 ScalerStage(ShaderType shader_,
148 gfx::Size src_size_,
149 gfx::Rect src_subrect_,
150 gfx::Size dst_size_,
151 bool scale_x_,
152 bool vertically_flip_texture_,
153 bool swizzle_);
154 ScalerStage(const ScalerStage& other);
155 ShaderType shader;
156 gfx::Size src_size;
157 gfx::Rect src_subrect;
158 gfx::Size dst_size;
159 bool scale_x;
160 bool vertically_flip_texture;
161 bool swizzle;
162 };
163
164 // Compute a vector of scaler stages for a particular
165 // set of input/output parameters.
166 void ComputeScalerStages(GLHelper::ScalerQuality quality,
167 const gfx::Size& src_size,
168 const gfx::Rect& src_subrect,
169 const gfx::Size& dst_size,
170 bool vertically_flip_texture,
171 bool swizzle,
172 std::vector<ScalerStage> *scaler_stages);
173
174 // Take two queues of ScaleOp structs and generate a
175 // vector of scaler stages. This is the second half of
176 // ComputeScalerStages.
177 void ConvertScalerOpsToScalerStages(
178 GLHelper::ScalerQuality quality,
179 gfx::Size src_size,
180 gfx::Rect src_subrect,
181 const gfx::Size& dst_size,
182 bool vertically_flip_texture,
183 bool swizzle,
184 std::deque<GLHelperScaling::ScaleOp>* x_ops,
185 std::deque<GLHelperScaling::ScaleOp>* y_ops,
186 std::vector<ScalerStage> *scaler_stages);
187
188
189 scoped_refptr<ShaderProgram> GetShaderProgram(ShaderType type, bool swizzle);
190
191 // Interleaved array of 2-dimentional vertex positions (x, y) and
192 // 2-dimentional texture coordinates (s, t).
193 static const GLfloat kVertexAttributes[];
194
195 gpu::gles2::GLES2Interface* gl_;
196 GLHelper* helper_;
197
198 // The buffer that holds the vertices and the texture coordinates data for
199 // drawing a quad.
200 ScopedBuffer vertex_attributes_buffer_;
201
202 std::map<ShaderProgramKeyType,
203 scoped_refptr<ShaderProgram> > shader_programs_;
204
205 friend class ShaderProgram;
206 friend class ScalerImpl;
207 friend class GLHelperTest;
208 DISALLOW_COPY_AND_ASSIGN(GLHelperScaling);
209 };
210
211
212 } // namespace content
213
214 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_SCALING_H_
OLDNEW
« no previous file with comments | « content/common/gpu/client/gl_helper_readback_support.cc ('k') | content/common/gpu/client/gl_helper_scaling.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698