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

Side by Side Diff: components/display_compositor/gl_helper_scaling.h

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

Powered by Google App Engine
This is Rietveld 408576698