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

Side by Side Diff: content/browser/compositor/gl_helper_scaling.h

Issue 1904773004: 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 CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_
6 #define CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_
7
8 #include <deque>
9 #include <map>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "content/browser/compositor/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, GLHelper* helper);
56 ~GLHelperScaling();
57 void InitBuffer();
58
59 GLHelper::ScalerInterface* CreateScaler(GLHelper::ScalerQuality quality,
60 gfx::Size src_size,
61 gfx::Rect src_subrect,
62 const gfx::Size& dst_size,
63 bool vertically_flip_texture,
64 bool swizzle);
65
66 GLHelper::ScalerInterface* CreatePlanarScaler(const gfx::Size& src_size,
67 const gfx::Rect& src_subrect,
68 const gfx::Size& dst_size,
69 bool vertically_flip_texture,
70 bool swizzle,
71 const float color_weights[4]);
72
73 ShaderInterface* CreateYuvMrtShader(const gfx::Size& src_size,
74 const gfx::Rect& src_subrect,
75 const gfx::Size& dst_size,
76 bool vertically_flip_texture,
77 bool swizzle,
78 ShaderType shader);
79
80 private:
81 // A ScaleOp represents a pass in a scaler pipeline, in one dimension.
82 // Note that when quality is GOOD, multiple scaler passes will be
83 // combined into one operation for increased performance.
84 // Exposed in the header file for testing purposes.
85 struct ScaleOp {
86 ScaleOp(int factor, bool x, int size)
87 : scale_factor(factor), scale_x(x), scale_size(size) {}
88
89 // Calculate a set of ScaleOp needed to convert an image of size
90 // |src| into an image of size |dst|. If |scale_x| is true, then
91 // the calculations are for the X axis of the image, otherwise Y.
92 // If |allow3| is true, we can use a SHADER_BILINEAR3 to replace
93 // a scale up and scale down with a 3-tap bilinear scale.
94 // The calculated ScaleOps are added to |ops|.
95 static void AddOps(int src,
96 int dst,
97 bool scale_x,
98 bool allow3,
99 std::deque<ScaleOp>* ops) {
100 int num_downscales = 0;
101 if (allow3 && dst * 3 >= src && dst * 2 < src) {
102 // Technically, this should be a scale up and then a
103 // scale down, but it makes the optimization code more
104 // complicated.
105 ops->push_back(ScaleOp(3, scale_x, dst));
106 return;
107 }
108 while ((dst << num_downscales) < src) {
109 num_downscales++;
110 }
111 if ((dst << num_downscales) != src) {
112 ops->push_back(ScaleOp(0, scale_x, dst << num_downscales));
113 }
114 while (num_downscales) {
115 num_downscales--;
116 ops->push_back(ScaleOp(2, scale_x, dst << num_downscales));
117 }
118 }
119
120 // Update |size| to its new size. Before calling this function
121 // |size| should be the size of the input image. After calling it,
122 // |size| will be the size of the image after this particular
123 // scaling operation.
124 void UpdateSize(gfx::Size* subrect) {
125 if (scale_x) {
126 subrect->set_width(scale_size);
127 } else {
128 subrect->set_height(scale_size);
129 }
130 }
131
132 // A scale factor of 0 means upscale
133 // 2 means 50% scale
134 // 3 means 33% scale, etc.
135 int scale_factor;
136 bool scale_x; // Otherwise y
137 int scale_size; // Size to scale to.
138 };
139
140 // Full specification for a single scaling stage.
141 struct ScalerStage {
142 ScalerStage(ShaderType shader_,
143 gfx::Size src_size_,
144 gfx::Rect src_subrect_,
145 gfx::Size dst_size_,
146 bool scale_x_,
147 bool vertically_flip_texture_,
148 bool swizzle_);
149 ScalerStage(const ScalerStage& other);
150 ShaderType shader;
151 gfx::Size src_size;
152 gfx::Rect src_subrect;
153 gfx::Size dst_size;
154 bool scale_x;
155 bool vertically_flip_texture;
156 bool swizzle;
157 };
158
159 // Compute a vector of scaler stages for a particular
160 // set of input/output parameters.
161 void ComputeScalerStages(GLHelper::ScalerQuality quality,
162 const gfx::Size& src_size,
163 const gfx::Rect& src_subrect,
164 const gfx::Size& dst_size,
165 bool vertically_flip_texture,
166 bool swizzle,
167 std::vector<ScalerStage>* scaler_stages);
168
169 // Take two queues of ScaleOp structs and generate a
170 // vector of scaler stages. This is the second half of
171 // ComputeScalerStages.
172 void ConvertScalerOpsToScalerStages(
173 GLHelper::ScalerQuality quality,
174 gfx::Size src_size,
175 gfx::Rect src_subrect,
176 const gfx::Size& dst_size,
177 bool vertically_flip_texture,
178 bool swizzle,
179 std::deque<GLHelperScaling::ScaleOp>* x_ops,
180 std::deque<GLHelperScaling::ScaleOp>* y_ops,
181 std::vector<ScalerStage>* scaler_stages);
182
183 scoped_refptr<ShaderProgram> GetShaderProgram(ShaderType type, bool swizzle);
184
185 // Interleaved array of 2-dimentional vertex positions (x, y) and
186 // 2-dimentional texture coordinates (s, t).
187 static const GLfloat kVertexAttributes[];
188
189 gpu::gles2::GLES2Interface* gl_;
190 GLHelper* helper_;
191
192 // The buffer that holds the vertices and the texture coordinates data for
193 // drawing a quad.
194 ScopedBuffer vertex_attributes_buffer_;
195
196 std::map<ShaderProgramKeyType, scoped_refptr<ShaderProgram>> shader_programs_;
197
198 friend class ShaderProgram;
199 friend class ScalerImpl;
200 friend class GLHelperTest;
201 DISALLOW_COPY_AND_ASSIGN(GLHelperScaling);
202 };
203
204 } // namespace content
205
206 #endif // CONTENT_BROWSER_COMPOSITOR_GL_HELPER_SCALING_H_
OLDNEW
« no previous file with comments | « content/browser/compositor/gl_helper_readback_support.cc ('k') | content/browser/compositor/gl_helper_scaling.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698