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
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_SHADER_H_
6 #define CC_OUTPUT_SHADER_H_
10 #include "base/basictypes.h"
11 #include "cc/base/cc_export.h"
12 #include "third_party/skia/include/core/SkColorPriv.h"
19 namespace WebKit { class WebGraphicsContext3D; }
23 enum TexCoordPrecision {
25 TexCoordPrecisionMedium,
26 TexCoordPrecisionHigh,
29 // Note: The highp_threshold_cache must be provided by the caller to make
30 // the caching multi-thread/context safe in an easy low-overhead manner.
31 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
32 // reinitialized, if a new or different context is used.
33 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired(
34 WebKit::WebGraphicsContext3D* context,
35 int *highp_threshold_cache,
36 int highp_threshold_min,
37 gfx::Point max_coordinate);
39 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired(
40 WebKit::WebGraphicsContext3D* context,
41 int *highp_threshold_cache,
42 int highp_threshold_min,
45 class VertexShaderPosTex {
49 void Init(WebKit::WebGraphicsContext3D* context,
51 bool using_bind_uniform,
52 int* base_uniform_index);
53 std::string GetShaderString() const;
55 int matrix_location() const { return matrix_location_; }
60 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex);
63 class VertexShaderPosTexYUVStretch {
65 VertexShaderPosTexYUVStretch();
67 void Init(WebKit::WebGraphicsContext3D* context,
69 bool using_bind_uniform,
70 int* base_uniform_index);
71 std::string GetShaderString() const;
73 int matrix_location() const { return matrix_location_; }
74 int tex_scale_location() const { return tex_scale_location_; }
78 int tex_scale_location_;
80 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretch);
83 class VertexShaderPos {
87 void Init(WebKit::WebGraphicsContext3D* context,
89 bool using_bind_uniform,
90 int* base_uniform_index);
91 std::string GetShaderString() const;
93 int matrix_location() const { return matrix_location_; }
98 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos);
101 class VertexShaderPosTexIdentity {
103 void Init(WebKit::WebGraphicsContext3D* context,
105 bool using_bind_uniform,
106 int* base_uniform_index) {}
107 std::string GetShaderString() const;
110 class VertexShaderPosTexTransform {
112 VertexShaderPosTexTransform();
114 void Init(WebKit::WebGraphicsContext3D* context,
116 bool using_bind_uniform,
117 int* base_uniform_index);
118 std::string GetShaderString() const;
120 int matrix_location() const { return matrix_location_; }
121 int tex_transform_location() const { return tex_transform_location_; }
122 int vertex_opacity_location() const { return vertex_opacity_location_; }
125 int matrix_location_;
126 int tex_transform_location_;
127 int vertex_opacity_location_;
129 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform);
132 class VertexShaderQuad {
136 void Init(WebKit::WebGraphicsContext3D* context,
138 bool using_bind_uniform,
139 int* base_uniform_index);
140 std::string GetShaderString() const;
142 int matrix_location() const { return matrix_location_; }
143 int viewport_location() const { return -1; }
144 int quad_location() const { return quad_location_; }
145 int edge_location() const { return -1; }
148 int matrix_location_;
151 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
154 class VertexShaderQuadAA {
156 VertexShaderQuadAA();
158 void Init(WebKit::WebGraphicsContext3D* context,
160 bool using_bind_uniform,
161 int* base_uniform_index);
162 std::string GetShaderString() const;
164 int matrix_location() const { return matrix_location_; }
165 int viewport_location() const { return viewport_location_; }
166 int quad_location() const { return quad_location_; }
167 int edge_location() const { return edge_location_; }
170 int matrix_location_;
171 int viewport_location_;
175 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA);
179 class VertexShaderQuadTexTransformAA {
181 VertexShaderQuadTexTransformAA();
183 void Init(WebKit::WebGraphicsContext3D* context,
185 bool using_bind_uniform,
186 int* base_uniform_index);
187 std::string GetShaderString() const;
189 int matrix_location() const { return matrix_location_; }
190 int viewport_location() const { return viewport_location_; }
191 int quad_location() const { return quad_location_; }
192 int edge_location() const { return edge_location_; }
193 int tex_transform_location() const { return tex_transform_location_; }
196 int matrix_location_;
197 int viewport_location_;
200 int tex_transform_location_;
202 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA);
205 class VertexShaderTile {
209 void Init(WebKit::WebGraphicsContext3D* context,
211 bool using_bind_uniform,
212 int* base_uniform_index);
213 std::string GetShaderString() const;
215 int matrix_location() const { return matrix_location_; }
216 int viewport_location() const { return -1; }
217 int quad_location() const { return quad_location_; }
218 int edge_location() const { return -1; }
219 int vertex_tex_transform_location() const {
220 return vertex_tex_transform_location_;
224 int matrix_location_;
226 int vertex_tex_transform_location_;
228 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);
231 class VertexShaderTileAA {
233 VertexShaderTileAA();
235 void Init(WebKit::WebGraphicsContext3D* context,
237 bool using_bind_uniform,
238 int* base_uniform_index);
239 std::string GetShaderString() const;
241 int matrix_location() const { return matrix_location_; }
242 int viewport_location() const { return viewport_location_; }
243 int quad_location() const { return quad_location_; }
244 int edge_location() const { return edge_location_; }
245 int vertex_tex_transform_location() const {
246 return vertex_tex_transform_location_;
250 int matrix_location_;
251 int viewport_location_;
254 int vertex_tex_transform_location_;
256 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA);
259 class VertexShaderVideoTransform {
261 VertexShaderVideoTransform();
263 void Init(WebKit::WebGraphicsContext3D* context,
265 bool using_bind_uniform,
266 int* base_uniform_index);
267 std::string GetShaderString() const;
269 int matrix_location() const { return matrix_location_; }
270 int tex_matrix_location() const { return tex_matrix_location_; }
273 int matrix_location_;
274 int tex_matrix_location_;
276 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform);
279 class FragmentTexAlphaBinding {
281 FragmentTexAlphaBinding();
283 void Init(WebKit::WebGraphicsContext3D* context,
285 bool using_bind_uniform,
286 int* base_uniform_index);
287 int alpha_location() const { return alpha_location_; }
288 int fragment_tex_transform_location() const { return -1; }
289 int sampler_location() const { return sampler_location_; }
292 int sampler_location_;
295 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
298 class FragmentTexColorMatrixAlphaBinding {
300 FragmentTexColorMatrixAlphaBinding();
302 void Init(WebKit::WebGraphicsContext3D* context,
304 bool usingBindUniform,
305 int* baseUniformIndex);
306 int alpha_location() const { return alpha_location_; }
307 int color_matrix_location() const { return color_matrix_location_; }
308 int color_offset_location() const { return color_offset_location_; }
309 int fragment_tex_transform_location() const { return -1; }
310 int sampler_location() const { return sampler_location_; }
313 int sampler_location_;
315 int color_matrix_location_;
316 int color_offset_location_;
319 class FragmentTexOpaqueBinding {
321 FragmentTexOpaqueBinding();
323 void Init(WebKit::WebGraphicsContext3D* context,
325 bool using_bind_uniform,
326 int* base_uniform_index);
327 int alpha_location() const { return -1; }
328 int fragment_tex_transform_location() const { return -1; }
329 int background_color_location() const { return -1; }
330 int sampler_location() const { return sampler_location_; }
333 int sampler_location_;
335 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
338 class FragmentTexBackgroundBinding {
340 FragmentTexBackgroundBinding();
342 void Init(WebKit::WebGraphicsContext3D* context,
344 bool using_bind_uniform,
345 int* base_uniform_index);
346 int background_color_location() const { return background_color_location_; }
347 int sampler_location() const { return sampler_location_; }
350 int background_color_location_;
351 int sampler_location_;
353 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
356 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
358 std::string GetShaderString(TexCoordPrecision precision) const;
361 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
363 std::string GetShaderString(TexCoordPrecision precision) const;
366 class FragmentShaderTexBackgroundVaryingAlpha
367 : public FragmentTexBackgroundBinding {
369 std::string GetShaderString(TexCoordPrecision precision) const;
372 class FragmentShaderTexBackgroundPremultiplyAlpha
373 : public FragmentTexBackgroundBinding {
375 std::string GetShaderString(TexCoordPrecision precision) const;
378 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
380 std::string GetShaderString(TexCoordPrecision precision) const;
383 class FragmentShaderRGBATexColorMatrixAlpha
384 : public FragmentTexColorMatrixAlphaBinding {
386 std::string GetShaderString(TexCoordPrecision precision) const;
389 class FragmentShaderRGBATexRectVaryingAlpha : public FragmentTexOpaqueBinding {
391 std::string GetShaderString(TexCoordPrecision precision) const;
394 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
396 std::string GetShaderString(TexCoordPrecision precision) const;
399 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
401 std::string GetShaderString(TexCoordPrecision precision) const;
404 // Swizzles the red and blue component of sampled texel with alpha.
405 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding {
407 std::string GetShaderString(TexCoordPrecision precision) const;
410 // Swizzles the red and blue component of sampled texel without alpha.
411 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding {
413 std::string GetShaderString(TexCoordPrecision precision) const;
416 // Fragment shader for external textures.
417 class FragmentShaderOESImageExternal : public FragmentTexAlphaBinding {
419 FragmentShaderOESImageExternal();
421 std::string GetShaderString(TexCoordPrecision precision) const;
422 void Init(WebKit::WebGraphicsContext3D* context,
424 bool using_bind_uniform,
425 int* base_uniform_index);
427 int sampler_location_;
429 DISALLOW_COPY_AND_ASSIGN(FragmentShaderOESImageExternal);
432 class FragmentShaderRGBATexAlphaAA {
434 FragmentShaderRGBATexAlphaAA();
436 void Init(WebKit::WebGraphicsContext3D* context,
438 bool using_bind_uniform,
439 int* base_uniform_index);
440 std::string GetShaderString(TexCoordPrecision precision) const;
442 int alpha_location() const { return alpha_location_; }
443 int sampler_location() const { return sampler_location_; }
446 int sampler_location_;
449 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
452 class FragmentTexClampAlphaAABinding {
454 FragmentTexClampAlphaAABinding();
456 void Init(WebKit::WebGraphicsContext3D* context,
458 bool using_bind_uniform,
459 int* base_uniform_index);
460 int alpha_location() const { return alpha_location_; }
461 int sampler_location() const { return sampler_location_; }
462 int fragment_tex_transform_location() const {
463 return fragment_tex_transform_location_;
467 int sampler_location_;
469 int fragment_tex_transform_location_;
471 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
474 class FragmentShaderRGBATexClampAlphaAA
475 : public FragmentTexClampAlphaAABinding {
477 std::string GetShaderString(TexCoordPrecision precision) const;
480 // Swizzles the red and blue component of sampled texel.
481 class FragmentShaderRGBATexClampSwizzleAlphaAA
482 : public FragmentTexClampAlphaAABinding {
484 std::string GetShaderString(TexCoordPrecision precision) const;
487 class FragmentShaderRGBATexAlphaMask {
489 FragmentShaderRGBATexAlphaMask();
490 std::string GetShaderString(TexCoordPrecision precision) const;
492 void Init(WebKit::WebGraphicsContext3D* context,
494 bool using_bind_uniform,
495 int* base_uniform_index);
496 int alpha_location() const { return alpha_location_; }
497 int sampler_location() const { return sampler_location_; }
498 int mask_sampler_location() const { return mask_sampler_location_; }
499 int mask_tex_coord_scale_location() const {
500 return mask_tex_coord_scale_location_;
502 int mask_tex_coord_offset_location() const {
503 return mask_tex_coord_offset_location_;
507 int sampler_location_;
508 int mask_sampler_location_;
510 int mask_tex_coord_scale_location_;
511 int mask_tex_coord_offset_location_;
513 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
516 class FragmentShaderRGBATexAlphaMaskAA {
518 FragmentShaderRGBATexAlphaMaskAA();
519 std::string GetShaderString(TexCoordPrecision precision) const;
521 void Init(WebKit::WebGraphicsContext3D* context,
523 bool using_bind_uniform,
524 int* base_uniform_index);
525 int alpha_location() const { return alpha_location_; }
526 int sampler_location() const { return sampler_location_; }
527 int mask_sampler_location() const { return mask_sampler_location_; }
528 int mask_tex_coord_scale_location() const {
529 return mask_tex_coord_scale_location_;
531 int mask_tex_coord_offset_location() const {
532 return mask_tex_coord_offset_location_;
536 int sampler_location_;
537 int mask_sampler_location_;
539 int mask_tex_coord_scale_location_;
540 int mask_tex_coord_offset_location_;
542 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
545 class FragmentShaderRGBATexAlphaMaskColorMatrixAA {
547 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
548 std::string GetShaderString(TexCoordPrecision precision) const;
550 void Init(WebKit::WebGraphicsContext3D* context,
552 bool using_bind_uniform,
553 int* base_uniform_index);
554 int alpha_location() const { return alpha_location_; }
555 int sampler_location() const { return sampler_location_; }
556 int mask_sampler_location() const { return mask_sampler_location_; }
557 int mask_tex_coord_scale_location() const {
558 return mask_tex_coord_scale_location_;
560 int mask_tex_coord_offset_location() const {
561 return mask_tex_coord_offset_location_;
563 int color_matrix_location() const { return color_matrix_location_; }
564 int color_offset_location() const { return color_offset_location_; }
567 int sampler_location_;
568 int mask_sampler_location_;
570 int mask_tex_coord_scale_location_;
571 int mask_tex_coord_offset_location_;
572 int color_matrix_location_;
573 int color_offset_location_;
576 class FragmentShaderRGBATexAlphaColorMatrixAA {
578 FragmentShaderRGBATexAlphaColorMatrixAA();
579 std::string GetShaderString(TexCoordPrecision precision) const;
581 void Init(WebKit::WebGraphicsContext3D* context,
583 bool using_bind_uniform,
584 int* base_uniform_index);
585 int alpha_location() const { return alpha_location_; }
586 int sampler_location() const { return sampler_location_; }
587 int color_matrix_location() const { return color_matrix_location_; }
588 int color_offset_location() const { return color_offset_location_; }
591 int sampler_location_;
593 int color_matrix_location_;
594 int color_offset_location_;
597 class FragmentShaderRGBATexAlphaMaskColorMatrix {
599 FragmentShaderRGBATexAlphaMaskColorMatrix();
600 std::string GetShaderString(TexCoordPrecision precision) const;
602 void Init(WebKit::WebGraphicsContext3D* context,
604 bool using_bind_uniform,
605 int* base_uniform_index);
606 int alpha_location() const { return alpha_location_; }
607 int sampler_location() const { return sampler_location_; }
608 int mask_sampler_location() const { return mask_sampler_location_; }
609 int mask_tex_coord_scale_location() const {
610 return mask_tex_coord_scale_location_;
612 int mask_tex_coord_offset_location() const {
613 return mask_tex_coord_offset_location_;
615 int color_matrix_location() const { return color_matrix_location_; }
616 int color_offset_location() const { return color_offset_location_; }
619 int sampler_location_;
620 int mask_sampler_location_;
622 int mask_tex_coord_scale_location_;
623 int mask_tex_coord_offset_location_;
624 int color_matrix_location_;
625 int color_offset_location_;
628 class FragmentShaderYUVVideo {
630 FragmentShaderYUVVideo();
631 std::string GetShaderString(TexCoordPrecision precision) const;
633 void Init(WebKit::WebGraphicsContext3D* context,
635 bool using_bind_uniform,
636 int* base_uniform_index);
637 int y_texture_location() const { return y_texture_location_; }
638 int u_texture_location() const { return u_texture_location_; }
639 int v_texture_location() const { return v_texture_location_; }
640 int alpha_location() const { return alpha_location_; }
641 int yuv_matrix_location() const { return yuv_matrix_location_; }
642 int yuv_adj_location() const { return yuv_adj_location_; }
645 int y_texture_location_;
646 int u_texture_location_;
647 int v_texture_location_;
649 int yuv_matrix_location_;
650 int yuv_adj_location_;
652 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
656 class FragmentShaderYUVAVideo {
658 FragmentShaderYUVAVideo();
659 std::string GetShaderString(TexCoordPrecision precision) const;
661 void Init(WebKit::WebGraphicsContext3D* context,
663 bool using_bind_uniform,
664 int* base_uniform_index);
666 int y_texture_location() const { return y_texture_location_; }
667 int u_texture_location() const { return u_texture_location_; }
668 int v_texture_location() const { return v_texture_location_; }
669 int a_texture_location() const { return a_texture_location_; }
670 int alpha_location() const { return alpha_location_; }
671 int yuv_matrix_location() const { return yuv_matrix_location_; }
672 int yuv_adj_location() const { return yuv_adj_location_; }
675 int y_texture_location_;
676 int u_texture_location_;
677 int v_texture_location_;
678 int a_texture_location_;
680 int yuv_matrix_location_;
681 int yuv_adj_location_;
683 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo);
686 class FragmentShaderColor {
688 FragmentShaderColor();
689 std::string GetShaderString(TexCoordPrecision precision) const;
691 void Init(WebKit::WebGraphicsContext3D* context,
693 bool using_bind_uniform,
694 int* base_uniform_index);
695 int color_location() const { return color_location_; }
700 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
703 class FragmentShaderColorAA {
705 FragmentShaderColorAA();
706 std::string GetShaderString(TexCoordPrecision precision) const;
708 void Init(WebKit::WebGraphicsContext3D* context,
710 bool using_bind_uniform,
711 int* base_uniform_index);
712 int color_location() const { return color_location_; }
717 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA);
720 class FragmentShaderCheckerboard {
722 FragmentShaderCheckerboard();
723 std::string GetShaderString(TexCoordPrecision precision) const;
725 void Init(WebKit::WebGraphicsContext3D* context,
727 bool using_bind_uniform,
728 int* base_uniform_index);
729 int alpha_location() const { return alpha_location_; }
730 int tex_transform_location() const { return tex_transform_location_; }
731 int frequency_location() const { return frequency_location_; }
732 int color_location() const { return color_location_; }
736 int tex_transform_location_;
737 int frequency_location_;
740 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard);
745 #endif // CC_OUTPUT_SHADER_H_