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

Side by Side Diff: cc/output/shader.h

Issue 2622053005: The great shader refactor: Merge YUV shader class (Closed)
Patch Set: Rebase Created 3 years, 11 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
« no previous file with comments | « cc/output/program_binding.cc ('k') | cc/output/shader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 CC_OUTPUT_SHADER_H_ 5 #ifndef CC_OUTPUT_SHADER_H_
6 #define CC_OUTPUT_SHADER_H_ 6 #define CC_OUTPUT_SHADER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 class GLES2Interface; 21 class GLES2Interface;
22 } 22 }
23 } 23 }
24 24
25 namespace cc { 25 namespace cc {
26 26
27 enum TexCoordPrecision { 27 enum TexCoordPrecision {
28 TEX_COORD_PRECISION_NA = 0, 28 TEX_COORD_PRECISION_NA = 0,
29 TEX_COORD_PRECISION_MEDIUM = 1, 29 TEX_COORD_PRECISION_MEDIUM = 1,
30 TEX_COORD_PRECISION_HIGH = 2, 30 TEX_COORD_PRECISION_HIGH = 2,
31 LAST_TEX_COORD_PRECISION = 2
32 }; 31 };
33 32
34 // Texture coordinate sources for the vertex shader. 33 // Texture coordinate sources for the vertex shader.
35 enum TexCoordSource { 34 enum TexCoordSource {
36 // Vertex shader does not populate a texture coordinate. 35 // Vertex shader does not populate a texture coordinate.
37 TEX_COORD_SOURCE_NONE, 36 TEX_COORD_SOURCE_NONE,
38 // Texture coordinate is set to the untransformed position. 37 // Texture coordinate is set to the untransformed position.
39 TEX_COORD_SOURCE_POSITION, 38 TEX_COORD_SOURCE_POSITION,
40 // Texture coordinate has its own attribute. 39 // Texture coordinate has its own attribute.
41 TEX_COORD_SOURCE_ATTRIBUTE, 40 TEX_COORD_SOURCE_ATTRIBUTE,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 enum PremultipliedAlphaMode { 75 enum PremultipliedAlphaMode {
77 PREMULTIPLIED_ALPHA = 0, 76 PREMULTIPLIED_ALPHA = 0,
78 NON_PREMULTIPLIED_ALPHA = 1, 77 NON_PREMULTIPLIED_ALPHA = 1,
79 }; 78 };
80 79
81 enum SamplerType { 80 enum SamplerType {
82 SAMPLER_TYPE_NA = 0, 81 SAMPLER_TYPE_NA = 0,
83 SAMPLER_TYPE_2D = 1, 82 SAMPLER_TYPE_2D = 1,
84 SAMPLER_TYPE_2D_RECT = 2, 83 SAMPLER_TYPE_2D_RECT = 2,
85 SAMPLER_TYPE_EXTERNAL_OES = 3, 84 SAMPLER_TYPE_EXTERNAL_OES = 3,
86 LAST_SAMPLER_TYPE = 3
87 }; 85 };
88 86
89 enum BlendMode { 87 enum BlendMode {
90 BLEND_MODE_NONE, 88 BLEND_MODE_NONE,
91 BLEND_MODE_NORMAL, 89 BLEND_MODE_NORMAL,
92 BLEND_MODE_SCREEN, 90 BLEND_MODE_SCREEN,
93 BLEND_MODE_OVERLAY, 91 BLEND_MODE_OVERLAY,
94 BLEND_MODE_DARKEN, 92 BLEND_MODE_DARKEN,
95 BLEND_MODE_LIGHTEN, 93 BLEND_MODE_LIGHTEN,
96 BLEND_MODE_COLOR_DODGE, 94 BLEND_MODE_COLOR_DODGE,
97 BLEND_MODE_COLOR_BURN, 95 BLEND_MODE_COLOR_BURN,
98 BLEND_MODE_HARD_LIGHT, 96 BLEND_MODE_HARD_LIGHT,
99 BLEND_MODE_SOFT_LIGHT, 97 BLEND_MODE_SOFT_LIGHT,
100 BLEND_MODE_DIFFERENCE, 98 BLEND_MODE_DIFFERENCE,
101 BLEND_MODE_EXCLUSION, 99 BLEND_MODE_EXCLUSION,
102 BLEND_MODE_MULTIPLY, 100 BLEND_MODE_MULTIPLY,
103 BLEND_MODE_HUE, 101 BLEND_MODE_HUE,
104 BLEND_MODE_SATURATION, 102 BLEND_MODE_SATURATION,
105 BLEND_MODE_COLOR, 103 BLEND_MODE_COLOR,
106 BLEND_MODE_LUMINOSITY, 104 BLEND_MODE_LUMINOSITY,
107 LAST_BLEND_MODE = BLEND_MODE_LUMINOSITY 105 LAST_BLEND_MODE = BLEND_MODE_LUMINOSITY
108 }; 106 };
109 107
110 enum InputColorSource { 108 enum InputColorSource {
109 // This includes RGB and RGBA textures.
111 INPUT_COLOR_SOURCE_RGBA_TEXTURE, 110 INPUT_COLOR_SOURCE_RGBA_TEXTURE,
111 // This includes Y and either UV or U-and-V textures.
112 INPUT_COLOR_SOURCE_YUV_TEXTURES,
113 // A solid color specified as a uniform value.
112 INPUT_COLOR_SOURCE_UNIFORM, 114 INPUT_COLOR_SOURCE_UNIFORM,
113 }; 115 };
114 116
115 // TODO(ccameron): Merge this with BlendMode. 117 // TODO(ccameron): Merge this with BlendMode.
116 enum FragColorMode { 118 enum FragColorMode {
117 FRAG_COLOR_MODE_DEFAULT, 119 FRAG_COLOR_MODE_DEFAULT,
118 FRAG_COLOR_MODE_OPAQUE, 120 FRAG_COLOR_MODE_OPAQUE,
119 FRAG_COLOR_MODE_APPLY_BLEND_MODE, 121 FRAG_COLOR_MODE_APPLY_BLEND_MODE,
120 }; 122 };
121 123
122 enum MaskMode { 124 enum MaskMode {
123 NO_MASK = 0, 125 NO_MASK = 0,
124 HAS_MASK = 1, 126 HAS_MASK = 1,
125 LAST_MASK_VALUE = HAS_MASK
126 }; 127 };
127 128
128 // Note: The highp_threshold_cache must be provided by the caller to make 129 // Note: The highp_threshold_cache must be provided by the caller to make
129 // the caching multi-thread/context safe in an easy low-overhead manner. 130 // the caching multi-thread/context safe in an easy low-overhead manner.
130 // The caller must make sure to clear highp_threshold_cache to 0, so it can be 131 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
131 // reinitialized, if a new or different context is used. 132 // reinitialized, if a new or different context is used.
132 CC_EXPORT TexCoordPrecision 133 CC_EXPORT TexCoordPrecision
133 TexCoordPrecisionRequired(gpu::gles2::GLES2Interface* context, 134 TexCoordPrecisionRequired(gpu::gles2::GLES2Interface* context,
134 int* highp_threshold_cache, 135 int* highp_threshold_cache,
135 int highp_threshold_min, 136 int highp_threshold_min,
136 const gfx::Point& max_coordinate); 137 const gfx::Point& max_coordinate);
137 138
138 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired( 139 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired(
139 gpu::gles2::GLES2Interface* context, 140 gpu::gles2::GLES2Interface* context,
140 int *highp_threshold_cache, 141 int *highp_threshold_cache,
141 int highp_threshold_min, 142 int highp_threshold_min,
142 const gfx::Size& max_size); 143 const gfx::Size& max_size);
143 144
144 class VertexShaderBase { 145 class VertexShader {
145 public: 146 public:
146 VertexShaderBase(); 147 VertexShader();
147 void Init(gpu::gles2::GLES2Interface* context, 148 void Init(gpu::gles2::GLES2Interface* context,
148 unsigned program, 149 unsigned program,
149 int* base_uniform_index); 150 int* base_uniform_index);
150 std::string GetShaderString() const; 151 std::string GetShaderString() const;
151 152
152 protected: 153 protected:
153 template <class VertexShader, class FragmentShader> 154 friend class Program;
154 friend class ProgramBinding;
155 155
156 // Use arrays of uniforms for matrix, texTransform, and opacity. 156 // Use arrays of uniforms for matrix, texTransform, and opacity.
157 bool use_uniform_arrays_ = false; 157 bool use_uniform_arrays_ = false;
158 158
159 PositionSource position_source_ = POSITION_SOURCE_ATTRIBUTE; 159 PositionSource position_source_ = POSITION_SOURCE_ATTRIBUTE;
160 TexCoordSource tex_coord_source_ = TEX_COORD_SOURCE_NONE; 160 TexCoordSource tex_coord_source_ = TEX_COORD_SOURCE_NONE;
161 TexCoordTransform tex_coord_transform_ = TEX_COORD_TRANSFORM_NONE; 161 TexCoordTransform tex_coord_transform_ = TEX_COORD_TRANSFORM_NONE;
162 162
163 // Used only with TEX_COORD_TRANSFORM_VEC4. 163 // Used only with TEX_COORD_TRANSFORM_VEC4.
164 int vertex_tex_transform_location_ = -1; 164 int vertex_tex_transform_location_ = -1;
(...skipping 21 matching lines...) Expand all
186 bool has_dummy_variables_ = false; 186 bool has_dummy_variables_ = false;
187 187
188 bool has_vertex_opacity_ = false; 188 bool has_vertex_opacity_ = false;
189 int vertex_opacity_location_ = -1; 189 int vertex_opacity_location_ = -1;
190 190
191 AAMode aa_mode_ = NO_AA; 191 AAMode aa_mode_ = NO_AA;
192 int viewport_location_ = -1; 192 int viewport_location_ = -1;
193 int edge_location_ = -1; 193 int edge_location_ = -1;
194 }; 194 };
195 195
196 class FragmentShaderBase { 196 class FragmentShader {
197 public: 197 public:
198 virtual void Init(gpu::gles2::GLES2Interface* context, 198 virtual void Init(gpu::gles2::GLES2Interface* context,
199 unsigned program, 199 unsigned program,
200 int* base_uniform_index); 200 int* base_uniform_index);
201 std::string GetShaderString() const; 201 std::string GetShaderString() const;
202 202
203 protected: 203 protected:
204 FragmentShaderBase(); 204 FragmentShader();
205 virtual std::string GetShaderSource() const; 205 virtual std::string GetShaderSource() const;
206 bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; } 206 bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; }
207 207
208 std::string SetBlendModeFunctions(const std::string& shader_string) const; 208 std::string SetBlendModeFunctions(const std::string& shader_string) const;
209 209
210 // Settings that are modified by sub-classes. 210 // Settings that are modified by sub-classes.
211 AAMode aa_mode_ = NO_AA; 211 AAMode aa_mode_ = NO_AA;
212 bool has_varying_alpha_ = false; 212 bool has_varying_alpha_ = false;
213 SwizzleMode swizzle_mode_ = NO_SWIZZLE; 213 SwizzleMode swizzle_mode_ = NO_SWIZZLE;
214 PremultipliedAlphaMode premultiply_alpha_mode_ = PREMULTIPLIED_ALPHA; 214 PremultipliedAlphaMode premultiply_alpha_mode_ = PREMULTIPLIED_ALPHA;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 bool has_background_color_ = false; 249 bool has_background_color_ = false;
250 int background_color_location_ = -1; 250 int background_color_location_ = -1;
251 251
252 TexCoordPrecision tex_coord_precision_ = TEX_COORD_PRECISION_NA; 252 TexCoordPrecision tex_coord_precision_ = TEX_COORD_PRECISION_NA;
253 SamplerType sampler_type_ = SAMPLER_TYPE_NA; 253 SamplerType sampler_type_ = SAMPLER_TYPE_NA;
254 254
255 BlendMode blend_mode_ = BLEND_MODE_NONE; 255 BlendMode blend_mode_ = BLEND_MODE_NONE;
256 bool mask_for_background_ = false; 256 bool mask_for_background_ = false;
257 257
258 private: 258 // YUV-only parameters.
259 template <class VertexShader, class FragmentShader>
260 friend class ProgramBinding;
261
262 std::string GetHelperFunctions() const;
263 std::string GetBlendFunction() const;
264 std::string GetBlendFunctionBodyForRGB() const;
265
266 DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase);
267 };
268
269 class FragmentShaderYUVVideo : public FragmentShaderBase {
270 public:
271 FragmentShaderYUVVideo();
272
273 void CheckSubclassProperties() {}
274
275 void Init(gpu::gles2::GLES2Interface* context,
276 unsigned program,
277 int* base_uniform_index) override;
278 int y_texture_location() const { return y_texture_location_; }
279 int u_texture_location() const { return u_texture_location_; }
280 int v_texture_location() const { return v_texture_location_; }
281 int uv_texture_location() const { return uv_texture_location_; }
282 int a_texture_location() const { return a_texture_location_; }
283 int lut_texture_location() const { return lut_texture_location_; }
284 int alpha_location() const { return alpha_location_; }
285 int yuv_matrix_location() const { return yuv_matrix_location_; }
286 int yuv_adj_location() const { return yuv_adj_location_; }
287 int ya_clamp_rect_location() const { return ya_clamp_rect_location_; }
288 int uv_clamp_rect_location() const { return uv_clamp_rect_location_; }
289 int resource_multiplier_location() const {
290 return resource_multiplier_location_;
291 }
292 int resource_offset_location() const { return resource_offset_location_; }
293
294 private:
295 template <class VertexShader, class FragmentShader>
296 friend class ProgramBinding;
297
298 std::string GetShaderSource() const override;
299
300 bool use_alpha_texture_ = false; 259 bool use_alpha_texture_ = false;
301 bool use_nv12_ = false; 260 bool use_nv12_ = false;
302 bool use_color_lut_ = false; 261 bool use_color_lut_ = false;
303 262
263 // YUV uniform locations.
304 int y_texture_location_ = -1; 264 int y_texture_location_ = -1;
305 int u_texture_location_ = -1; 265 int u_texture_location_ = -1;
306 int v_texture_location_ = -1; 266 int v_texture_location_ = -1;
307 int uv_texture_location_ = -1; 267 int uv_texture_location_ = -1;
308 int a_texture_location_ = -1; 268 int a_texture_location_ = -1;
309 int lut_texture_location_ = -1; 269 int lut_texture_location_ = -1;
310 int alpha_location_ = -1;
311 int yuv_matrix_location_ = -1; 270 int yuv_matrix_location_ = -1;
312 int yuv_adj_location_ = -1; 271 int yuv_adj_location_ = -1;
313 int ya_clamp_rect_location_ = -1; 272 int ya_clamp_rect_location_ = -1;
314 int uv_clamp_rect_location_ = -1; 273 int uv_clamp_rect_location_ = -1;
315 int resource_multiplier_location_ = -1; 274 int resource_multiplier_location_ = -1;
316 int resource_offset_location_ = -1; 275 int resource_offset_location_ = -1;
276
277 private:
278 friend class Program;
279
280 // Functions specific to YUV video.
281 std::string GetShaderStringYUVVideo() const;
282 void InitYUVVideo(gpu::gles2::GLES2Interface* context,
283 unsigned program,
284 int* base_uniform_index);
285
286 std::string GetHelperFunctions() const;
287 std::string GetBlendFunction() const;
288 std::string GetBlendFunctionBodyForRGB() const;
289
290 DISALLOW_COPY_AND_ASSIGN(FragmentShader);
317 }; 291 };
318 292
319 } // namespace cc 293 } // namespace cc
320 294
321 #endif // CC_OUTPUT_SHADER_H_ 295 #endif // CC_OUTPUT_SHADER_H_
OLDNEW
« no previous file with comments | « cc/output/program_binding.cc ('k') | cc/output/shader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698