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

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

Issue 2626823002: The great shader refactor: Separate initialization from ctor (Closed)
Patch Set: 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.h ('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/macros.h" 10 #include "base/macros.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // Position source for the vertex shader. 56 // Position source for the vertex shader.
57 enum PositionSource { 57 enum PositionSource {
58 // The position is read directly from the position attribute. 58 // The position is read directly from the position attribute.
59 POSITION_SOURCE_ATTRIBUTE, 59 POSITION_SOURCE_ATTRIBUTE,
60 // The position is read by attribute index into a uniform array for xy, and 60 // The position is read by attribute index into a uniform array for xy, and
61 // getting zw from the attribute. 61 // getting zw from the attribute.
62 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM, 62 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM,
63 }; 63 };
64 64
65 enum AAMode {
66 NO_AA = 0,
67 USE_AA = 1,
68 };
69
70 enum SwizzleMode {
71 NO_SWIZZLE = 0,
72 DO_SWIZZLE = 1,
73 };
74
75 enum PremultipliedAlphaMode {
76 PREMULTIPLIED_ALPHA = 0,
77 NON_PREMULTIPLIED_ALPHA = 1,
78 };
79
65 enum SamplerType { 80 enum SamplerType {
66 SAMPLER_TYPE_NA = 0, 81 SAMPLER_TYPE_NA = 0,
67 SAMPLER_TYPE_2D = 1, 82 SAMPLER_TYPE_2D = 1,
68 SAMPLER_TYPE_2D_RECT = 2, 83 SAMPLER_TYPE_2D_RECT = 2,
69 SAMPLER_TYPE_EXTERNAL_OES = 3, 84 SAMPLER_TYPE_EXTERNAL_OES = 3,
70 LAST_SAMPLER_TYPE = 3 85 LAST_SAMPLER_TYPE = 3
71 }; 86 };
72 87
73 enum BlendMode { 88 enum BlendMode {
74 BLEND_MODE_NONE, 89 BLEND_MODE_NONE,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 int matrix_location() const { return matrix_location_; } 183 int matrix_location() const { return matrix_location_; }
169 184
170 int vertex_opacity_location() const { return vertex_opacity_location_; } 185 int vertex_opacity_location() const { return vertex_opacity_location_; }
171 186
172 int viewport_location() const { return viewport_location_; } 187 int viewport_location() const { return viewport_location_; }
173 int edge_location() const { return edge_location_; } 188 int edge_location() const { return edge_location_; }
174 189
175 int quad_location() const { return quad_location_; } 190 int quad_location() const { return quad_location_; }
176 191
177 protected: 192 protected:
193 template <class VertexShader, class FragmentShader>
194 friend class ProgramBinding;
195
178 // Use arrays of uniforms for matrix, texTransform, and opacity. 196 // Use arrays of uniforms for matrix, texTransform, and opacity.
179 bool use_uniform_arrays_ = false; 197 bool use_uniform_arrays_ = false;
180 198
181 PositionSource position_source_ = POSITION_SOURCE_ATTRIBUTE; 199 PositionSource position_source_ = POSITION_SOURCE_ATTRIBUTE;
182 TexCoordSource tex_coord_source_ = TEX_COORD_SOURCE_NONE; 200 TexCoordSource tex_coord_source_ = TEX_COORD_SOURCE_NONE;
183 TexCoordTransform tex_coord_transform_ = TEX_COORD_TRANSFORM_NONE; 201 TexCoordTransform tex_coord_transform_ = TEX_COORD_TRANSFORM_NONE;
184 202
185 // Used only with TEX_COORD_TRANSFORM_VEC4. 203 // Used only with TEX_COORD_TRANSFORM_VEC4.
186 int vertex_tex_transform_location_ = -1; 204 int vertex_tex_transform_location_ = -1;
187 205
(...skipping 15 matching lines...) Expand all
203 int quad_location_ = -1; 221 int quad_location_ = -1;
204 222
205 // Extra dummy variables to work around bugs on Android. 223 // Extra dummy variables to work around bugs on Android.
206 // TODO(ccameron): This is likley unneeded cargo-culting. 224 // TODO(ccameron): This is likley unneeded cargo-culting.
207 // http://crbug.com/240602 225 // http://crbug.com/240602
208 bool has_dummy_variables_ = false; 226 bool has_dummy_variables_ = false;
209 227
210 bool has_vertex_opacity_ = false; 228 bool has_vertex_opacity_ = false;
211 int vertex_opacity_location_ = -1; 229 int vertex_opacity_location_ = -1;
212 230
213 bool has_aa_ = false; 231 AAMode aa_mode_ = NO_AA;
214 int viewport_location_ = -1; 232 int viewport_location_ = -1;
215 int edge_location_ = -1; 233 int edge_location_ = -1;
216 }; 234 };
217 235
218 class VertexShaderPosTex : public VertexShaderBase { 236 class VertexShaderPosTex : public VertexShaderBase {
219 public: 237 public:
220 VertexShaderPosTex() { 238 void SetSubclassProperties() {
221 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 239 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
222 has_matrix_ = true; 240 has_matrix_ = true;
223 } 241 }
224 }; 242 };
225 243
226 class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase { 244 class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase {
227 public: 245 public:
228 VertexShaderPosTexYUVStretchOffset() { 246 void SetSubclassProperties() {
229 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 247 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
230 has_matrix_ = true; 248 has_matrix_ = true;
231 is_ya_uv_ = true; 249 is_ya_uv_ = true;
232 } 250 }
233 }; 251 };
234 252
235 class VertexShaderPos : public VertexShaderBase { 253 class VertexShaderPos : public VertexShaderBase {
236 public: 254 public:
237 VertexShaderPos() { has_matrix_ = true; } 255 void SetSubclassProperties() { has_matrix_ = true; }
238 }; 256 };
239 257
240 class VertexShaderPosTexTransform : public VertexShaderBase { 258 class VertexShaderPosTexTransform : public VertexShaderBase {
241 public: 259 public:
242 VertexShaderPosTexTransform() { 260 void SetSubclassProperties() {
243 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 261 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
244 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; 262 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
245 has_matrix_ = true; 263 has_matrix_ = true;
246 has_vertex_opacity_ = true; 264 has_vertex_opacity_ = true;
247 use_uniform_arrays_ = true; 265 use_uniform_arrays_ = true;
248 } 266 }
249 }; 267 };
250 268
251 class VertexShaderQuad : public VertexShaderBase { 269 class VertexShaderQuad : public VertexShaderBase {
252 public: 270 public:
253 VertexShaderQuad() { 271 void SetSubclassProperties() {
254 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 272 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
255 has_matrix_ = true; 273 has_matrix_ = true;
256 #if defined(OS_ANDROID) 274 #if defined(OS_ANDROID)
257 has_dummy_variables_ = true; 275 has_dummy_variables_ = true;
258 #endif 276 #endif
259 } 277 }
260 }; 278 };
261 279
262 class VertexShaderQuadAA : public VertexShaderBase { 280 class VertexShaderQuadAA : public VertexShaderBase {
263 public: 281 public:
264 VertexShaderQuadAA() { 282 void SetSubclassProperties() {
265 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 283 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
266 has_matrix_ = true; 284 has_matrix_ = true;
267 has_aa_ = true; 285 aa_mode_ = USE_AA;
268 } 286 }
269 }; 287 };
270 288
271 class VertexShaderQuadTexTransformAA : public VertexShaderBase { 289 class VertexShaderQuadTexTransformAA : public VertexShaderBase {
272 public: 290 public:
273 VertexShaderQuadTexTransformAA() { 291 void SetSubclassProperties() {
274 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 292 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
275 tex_coord_source_ = TEX_COORD_SOURCE_POSITION; 293 tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
276 tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; 294 tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4;
277 has_matrix_ = true; 295 has_matrix_ = true;
278 has_aa_ = true; 296 aa_mode_ = USE_AA;
279 } 297 }
280 }; 298 };
281 299
282 class VertexShaderTile : public VertexShaderBase { 300 class VertexShaderTile : public VertexShaderBase {
283 public: 301 public:
284 VertexShaderTile() { 302 void SetSubclassProperties() {
285 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 303 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
286 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 304 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
287 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; 305 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
288 has_matrix_ = true; 306 has_matrix_ = true;
289 } 307 }
290 }; 308 };
291 309
292 class VertexShaderTileAA : public VertexShaderBase { 310 class VertexShaderTileAA : public VertexShaderBase {
293 public: 311 public:
294 VertexShaderTileAA() { 312 void SetSubclassProperties() {
295 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 313 position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
296 tex_coord_source_ = TEX_COORD_SOURCE_POSITION; 314 tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
297 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; 315 tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
298 has_matrix_ = true; 316 has_matrix_ = true;
299 has_aa_ = true; 317 aa_mode_ = USE_AA;
300 } 318 }
301 }; 319 };
302 320
303 class VertexShaderVideoTransform : public VertexShaderBase { 321 class VertexShaderVideoTransform : public VertexShaderBase {
304 public: 322 public:
305 VertexShaderVideoTransform() { 323 void SetSubclassProperties() {
306 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 324 tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
307 tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; 325 tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX;
308 has_matrix_ = true; 326 has_matrix_ = true;
309 } 327 }
310 }; 328 };
311 329
312 class FragmentShaderBase { 330 class FragmentShaderBase {
313 public: 331 public:
314 virtual void Init(gpu::gles2::GLES2Interface* context, 332 virtual void Init(gpu::gles2::GLES2Interface* context,
315 unsigned program, 333 unsigned program,
316 int* base_uniform_index); 334 int* base_uniform_index);
317 std::string GetShaderString(TexCoordPrecision precision, 335 std::string GetShaderString() const;
318 SamplerType sampler) const;
319 void FillLocations(ShaderLocations* locations) const; 336 void FillLocations(ShaderLocations* locations) const;
320 337
321 BlendMode blend_mode() const { return blend_mode_; }
322 void set_blend_mode(BlendMode blend_mode) { blend_mode_ = blend_mode; }
323 bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; }
324 void set_mask_for_background(bool mask_for_background) {
325 mask_for_background_ = mask_for_background;
326 }
327 bool mask_for_background() const { return mask_for_background_; }
328
329 int sampler_location() const { return sampler_location_; } 338 int sampler_location() const { return sampler_location_; }
330 int alpha_location() const { return alpha_location_; } 339 int alpha_location() const { return alpha_location_; }
331 int color_location() const { return color_location_; } 340 int color_location() const { return color_location_; }
332 int background_color_location() const { return background_color_location_; } 341 int background_color_location() const { return background_color_location_; }
333 int fragment_tex_transform_location() const { 342 int fragment_tex_transform_location() const {
334 return fragment_tex_transform_location_; 343 return fragment_tex_transform_location_;
335 } 344 }
336 345
337 protected: 346 protected:
338 FragmentShaderBase(); 347 FragmentShaderBase();
339 virtual std::string GetShaderSource() const; 348 virtual std::string GetShaderSource() const;
349 bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; }
340 350
341 std::string SetBlendModeFunctions(const std::string& shader_string) const; 351 std::string SetBlendModeFunctions(const std::string& shader_string) const;
342 352
343 // Settings that are modified by sub-classes. 353 // Settings that are modified by sub-classes.
344 bool has_aa_ = false; 354 AAMode aa_mode_ = NO_AA;
345 bool has_varying_alpha_ = false; 355 bool has_varying_alpha_ = false;
346 bool has_swizzle_ = false; 356 SwizzleMode swizzle_mode_ = NO_SWIZZLE;
347 bool has_premultiply_alpha_ = false; 357 PremultipliedAlphaMode premultiply_alpha_mode_ = PREMULTIPLIED_ALPHA;
348 FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 358 FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
349 InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE; 359 InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE;
350 360
351 // Used only if |blend_mode_| is not BLEND_MODE_NONE. 361 // Used only if |blend_mode_| is not BLEND_MODE_NONE.
352 int backdrop_location_ = -1; 362 int backdrop_location_ = -1;
353 int original_backdrop_location_ = -1; 363 int original_backdrop_location_ = -1;
354 int backdrop_rect_location_ = -1; 364 int backdrop_rect_location_ = -1;
355 365
356 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_RGBA_TEXTURE. 366 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_RGBA_TEXTURE.
357 bool has_rgba_fragment_tex_transform_ = false; 367 bool has_rgba_fragment_tex_transform_ = false;
358 int sampler_location_ = -1; 368 int sampler_location_ = -1;
359 int fragment_tex_transform_location_ = -1; 369 int fragment_tex_transform_location_ = -1;
360 370
361 // Always use sampler2D and texture2D for the RGBA texture, regardless of the 371 // Always use sampler2D and texture2D for the RGBA texture, regardless of the
362 // specified SamplerType. 372 // specified SamplerType.
363 // TODO(ccameron): Change GLRenderer to always specify the correct 373 // TODO(ccameron): Change GLRenderer to always specify the correct
364 // SamplerType. 374 // SamplerType.
365 bool ignore_sampler_type_ = false; 375 bool ignore_sampler_type_ = false;
366 376
367 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM. 377 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM.
368 int color_location_ = -1; 378 int color_location_ = -1;
369 379
370 bool has_mask_sampler_ = false; 380 MaskMode mask_mode_ = NO_MASK;
371 int mask_sampler_location_ = -1; 381 int mask_sampler_location_ = -1;
372 int mask_tex_coord_scale_location_ = -1; 382 int mask_tex_coord_scale_location_ = -1;
373 int mask_tex_coord_offset_location_ = -1; 383 int mask_tex_coord_offset_location_ = -1;
374 384
375 bool has_color_matrix_ = false; 385 bool has_color_matrix_ = false;
376 int color_matrix_location_ = -1; 386 int color_matrix_location_ = -1;
377 int color_offset_location_ = -1; 387 int color_offset_location_ = -1;
378 388
379 bool has_uniform_alpha_ = false; 389 bool has_uniform_alpha_ = false;
380 int alpha_location_ = -1; 390 int alpha_location_ = -1;
381 391
382 bool has_background_color_ = false; 392 bool has_background_color_ = false;
383 int background_color_location_ = -1; 393 int background_color_location_ = -1;
384 394
385 private: 395 TexCoordPrecision tex_coord_precision_ = TEX_COORD_PRECISION_NA;
396 SamplerType sampler_type_ = SAMPLER_TYPE_NA;
397
386 BlendMode blend_mode_ = BLEND_MODE_NONE; 398 BlendMode blend_mode_ = BLEND_MODE_NONE;
387 bool mask_for_background_ = false; 399 bool mask_for_background_ = false;
388 400
401 private:
402 template <class VertexShader, class FragmentShader>
403 friend class ProgramBinding;
404
389 std::string GetHelperFunctions() const; 405 std::string GetHelperFunctions() const;
390 std::string GetBlendFunction() const; 406 std::string GetBlendFunction() const;
391 std::string GetBlendFunctionBodyForRGB() const; 407 std::string GetBlendFunctionBodyForRGB() const;
392 408
393 DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase); 409 DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase);
394 }; 410 };
395 411
396 class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase { 412 class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
397 public: 413 public:
398 FragmentShaderRGBATexVaryingAlpha() { 414 void SetSubclassProperties() {
399 has_varying_alpha_ = true; 415 has_varying_alpha_ = true;
400 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 416 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
401 } 417 }
402 }; 418 };
403 419
404 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase { 420 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase {
405 public: 421 public:
406 FragmentShaderRGBATexPremultiplyAlpha() { 422 void SetSubclassProperties() {
407 has_varying_alpha_ = true; 423 has_varying_alpha_ = true;
408 has_premultiply_alpha_ = true; 424 premultiply_alpha_mode_ = NON_PREMULTIPLIED_ALPHA;
409 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 425 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
410 } 426 }
411 }; 427 };
412 428
413 class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase { 429 class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
414 public: 430 public:
415 FragmentShaderTexBackgroundVaryingAlpha() { 431 void SetSubclassProperties() {
416 has_background_color_ = true; 432 has_background_color_ = true;
417 has_varying_alpha_ = true; 433 has_varying_alpha_ = true;
418 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 434 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
419 } 435 }
420 }; 436 };
421 437
422 class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase { 438 class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase {
423 public: 439 public:
424 FragmentShaderTexBackgroundPremultiplyAlpha() { 440 void SetSubclassProperties() {
425 has_background_color_ = true; 441 has_background_color_ = true;
426 has_varying_alpha_ = true; 442 has_varying_alpha_ = true;
427 has_premultiply_alpha_ = true; 443 premultiply_alpha_mode_ = NON_PREMULTIPLIED_ALPHA;
428 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 444 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
429 } 445 }
430 }; 446 };
431 447
432 class FragmentShaderRGBATexAlpha : public FragmentShaderBase { 448 class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
433 public: 449 public:
434 FragmentShaderRGBATexAlpha() { 450 void SetSubclassProperties() {
435 has_uniform_alpha_ = true; 451 has_uniform_alpha_ = true;
436 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 452 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
437 } 453 }
438 }; 454 };
439 455
440 class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase { 456 class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase {
441 public: 457 public:
442 FragmentShaderRGBATexColorMatrixAlpha() { 458 void SetSubclassProperties() {
443 has_uniform_alpha_ = true; 459 has_uniform_alpha_ = true;
444 has_color_matrix_ = true; 460 has_color_matrix_ = true;
445 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 461 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
446 } 462 }
447 }; 463 };
448 464
449 class FragmentShaderRGBATexOpaque : public FragmentShaderBase { 465 class FragmentShaderRGBATexOpaque : public FragmentShaderBase {
450 public: 466 public:
451 FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; } 467 void SetSubclassProperties() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; }
452 }; 468 };
453 469
454 class FragmentShaderRGBATex : public FragmentShaderBase { 470 class FragmentShaderRGBATex : public FragmentShaderBase {
455 public: 471 public:
456 FragmentShaderRGBATex() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; } 472 void SetSubclassProperties() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; }
457 }; 473 };
458 474
459 // Swizzles the red and blue component of sampled texel with alpha. 475 // Swizzles the red and blue component of sampled texel with alpha.
460 class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase { 476 class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase {
461 public: 477 public:
462 FragmentShaderRGBATexSwizzleAlpha() { 478 void SetSubclassProperties() {
463 has_uniform_alpha_ = true; 479 has_uniform_alpha_ = true;
464 has_swizzle_ = true; 480 swizzle_mode_ = DO_SWIZZLE;
465 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 481 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
466 } 482 }
467 }; 483 };
468 484
469 // Swizzles the red and blue component of sampled texel without alpha. 485 // Swizzles the red and blue component of sampled texel without alpha.
470 class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase { 486 class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase {
471 public: 487 public:
472 FragmentShaderRGBATexSwizzleOpaque() { 488 void SetSubclassProperties() {
473 has_swizzle_ = true; 489 swizzle_mode_ = DO_SWIZZLE;
474 frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; 490 frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
475 } 491 }
476 }; 492 };
477 493
478 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { 494 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
479 public: 495 public:
480 FragmentShaderRGBATexAlphaAA() { 496 void SetSubclassProperties() {
481 has_aa_ = true; 497 aa_mode_ = USE_AA;
482 has_uniform_alpha_ = true; 498 has_uniform_alpha_ = true;
483 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 499 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
484 } 500 }
485 }; 501 };
486 502
487 class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase { 503 class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
488 public: 504 public:
489 FragmentShaderRGBATexClampAlphaAA() { 505 void SetSubclassProperties() {
490 has_aa_ = true; 506 aa_mode_ = USE_AA;
491 has_uniform_alpha_ = true; 507 has_uniform_alpha_ = true;
492 has_rgba_fragment_tex_transform_ = true; 508 has_rgba_fragment_tex_transform_ = true;
493 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 509 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
494 } 510 }
495 }; 511 };
496 512
497 // Swizzles the red and blue component of sampled texel. 513 // Swizzles the red and blue component of sampled texel.
498 class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase { 514 class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase {
499 public: 515 public:
500 FragmentShaderRGBATexClampSwizzleAlphaAA() { 516 void SetSubclassProperties() {
501 has_aa_ = true; 517 aa_mode_ = USE_AA;
502 has_uniform_alpha_ = true; 518 has_uniform_alpha_ = true;
503 has_rgba_fragment_tex_transform_ = true; 519 has_rgba_fragment_tex_transform_ = true;
504 has_swizzle_ = true; 520 swizzle_mode_ = DO_SWIZZLE;
505 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 521 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
506 } 522 }
507 }; 523 };
508 524
509 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { 525 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase {
510 public: 526 public:
511 FragmentShaderRGBATexAlphaMask() { 527 void SetSubclassProperties() {
512 has_uniform_alpha_ = true; 528 has_uniform_alpha_ = true;
513 has_mask_sampler_ = true; 529 mask_mode_ = HAS_MASK;
514 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 530 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
515 ignore_sampler_type_ = true; 531 ignore_sampler_type_ = true;
516 } 532 }
517 }; 533 };
518 534
519 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { 535 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
520 public: 536 public:
521 FragmentShaderRGBATexAlphaMaskAA() { 537 void SetSubclassProperties() {
522 has_aa_ = true; 538 aa_mode_ = USE_AA;
523 has_uniform_alpha_ = true; 539 has_uniform_alpha_ = true;
524 has_mask_sampler_ = true; 540 mask_mode_ = HAS_MASK;
525 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 541 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
526 ignore_sampler_type_ = true; 542 ignore_sampler_type_ = true;
527 } 543 }
528 }; 544 };
529 545
530 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { 546 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
531 public: 547 public:
532 FragmentShaderRGBATexAlphaMaskColorMatrixAA() { 548 void SetSubclassProperties() {
533 has_aa_ = true; 549 aa_mode_ = USE_AA;
534 has_uniform_alpha_ = true; 550 has_uniform_alpha_ = true;
535 has_mask_sampler_ = true; 551 mask_mode_ = HAS_MASK;
536 has_color_matrix_ = true; 552 has_color_matrix_ = true;
537 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 553 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
538 ignore_sampler_type_ = true; 554 ignore_sampler_type_ = true;
539 } 555 }
540 }; 556 };
541 557
542 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { 558 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
543 public: 559 public:
544 FragmentShaderRGBATexAlphaColorMatrixAA() { 560 void SetSubclassProperties() {
545 has_aa_ = true; 561 aa_mode_ = USE_AA;
546 has_uniform_alpha_ = true; 562 has_uniform_alpha_ = true;
547 has_color_matrix_ = true; 563 has_color_matrix_ = true;
548 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 564 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
549 } 565 }
550 }; 566 };
551 567
552 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { 568 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
553 public: 569 public:
554 FragmentShaderRGBATexAlphaMaskColorMatrix() { 570 void SetSubclassProperties() {
555 has_uniform_alpha_ = true; 571 has_uniform_alpha_ = true;
556 has_mask_sampler_ = true; 572 mask_mode_ = HAS_MASK;
557 has_color_matrix_ = true; 573 has_color_matrix_ = true;
558 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 574 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
559 ignore_sampler_type_ = true; 575 ignore_sampler_type_ = true;
560 } 576 }
561 }; 577 };
562 578
563 class FragmentShaderYUVVideo : public FragmentShaderBase { 579 class FragmentShaderYUVVideo : public FragmentShaderBase {
564 public: 580 public:
565 FragmentShaderYUVVideo(); 581 FragmentShaderYUVVideo();
566 void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut); 582
583 void SetSubclassProperties() {}
567 584
568 void Init(gpu::gles2::GLES2Interface* context, 585 void Init(gpu::gles2::GLES2Interface* context,
569 unsigned program, 586 unsigned program,
570 int* base_uniform_index) override; 587 int* base_uniform_index) override;
571 int y_texture_location() const { return y_texture_location_; } 588 int y_texture_location() const { return y_texture_location_; }
572 int u_texture_location() const { return u_texture_location_; } 589 int u_texture_location() const { return u_texture_location_; }
573 int v_texture_location() const { return v_texture_location_; } 590 int v_texture_location() const { return v_texture_location_; }
574 int uv_texture_location() const { return uv_texture_location_; } 591 int uv_texture_location() const { return uv_texture_location_; }
575 int a_texture_location() const { return a_texture_location_; } 592 int a_texture_location() const { return a_texture_location_; }
576 int lut_texture_location() const { return lut_texture_location_; } 593 int lut_texture_location() const { return lut_texture_location_; }
577 int alpha_location() const { return alpha_location_; } 594 int alpha_location() const { return alpha_location_; }
578 int yuv_matrix_location() const { return yuv_matrix_location_; } 595 int yuv_matrix_location() const { return yuv_matrix_location_; }
579 int yuv_adj_location() const { return yuv_adj_location_; } 596 int yuv_adj_location() const { return yuv_adj_location_; }
580 int ya_clamp_rect_location() const { return ya_clamp_rect_location_; } 597 int ya_clamp_rect_location() const { return ya_clamp_rect_location_; }
581 int uv_clamp_rect_location() const { return uv_clamp_rect_location_; } 598 int uv_clamp_rect_location() const { return uv_clamp_rect_location_; }
582 int resource_multiplier_location() const { 599 int resource_multiplier_location() const {
583 return resource_multiplier_location_; 600 return resource_multiplier_location_;
584 } 601 }
585 int resource_offset_location() const { return resource_offset_location_; } 602 int resource_offset_location() const { return resource_offset_location_; }
586 603
587 private: 604 private:
605 template <class VertexShader, class FragmentShader>
606 friend class ProgramBinding;
607
588 std::string GetShaderSource() const override; 608 std::string GetShaderSource() const override;
589 609
590 bool use_alpha_texture_ = false; 610 bool use_alpha_texture_ = false;
591 bool use_nv12_ = false; 611 bool use_nv12_ = false;
592 bool use_color_lut_ = false; 612 bool use_color_lut_ = false;
593 613
594 int y_texture_location_ = -1; 614 int y_texture_location_ = -1;
595 int u_texture_location_ = -1; 615 int u_texture_location_ = -1;
596 int v_texture_location_ = -1; 616 int v_texture_location_ = -1;
597 int uv_texture_location_ = -1; 617 int uv_texture_location_ = -1;
598 int a_texture_location_ = -1; 618 int a_texture_location_ = -1;
599 int lut_texture_location_ = -1; 619 int lut_texture_location_ = -1;
600 int alpha_location_ = -1; 620 int alpha_location_ = -1;
601 int yuv_matrix_location_ = -1; 621 int yuv_matrix_location_ = -1;
602 int yuv_adj_location_ = -1; 622 int yuv_adj_location_ = -1;
603 int ya_clamp_rect_location_ = -1; 623 int ya_clamp_rect_location_ = -1;
604 int uv_clamp_rect_location_ = -1; 624 int uv_clamp_rect_location_ = -1;
605 int resource_multiplier_location_ = -1; 625 int resource_multiplier_location_ = -1;
606 int resource_offset_location_ = -1; 626 int resource_offset_location_ = -1;
607 }; 627 };
608 628
609 class FragmentShaderColor : public FragmentShaderBase { 629 class FragmentShaderColor : public FragmentShaderBase {
610 public: 630 public:
611 FragmentShaderColor() { 631 void SetSubclassProperties() {
612 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; 632 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
613 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 633 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
614 } 634 }
615 }; 635 };
616 636
617 class FragmentShaderColorAA : public FragmentShaderBase { 637 class FragmentShaderColorAA : public FragmentShaderBase {
618 public: 638 public:
619 FragmentShaderColorAA() { 639 void SetSubclassProperties() {
620 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; 640 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
621 has_aa_ = true; 641 aa_mode_ = USE_AA;
622 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; 642 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
623 } 643 }
624 }; 644 };
625 645
626 } // namespace cc 646 } // namespace cc
627 647
628 #endif // CC_OUTPUT_SHADER_H_ 648 #endif // CC_OUTPUT_SHADER_H_
OLDNEW
« no previous file with comments | « cc/output/program_binding.h ('k') | cc/output/shader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698