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"
27 enum TexCoordPrecision
{
28 TexCoordPrecisionNA
= 0,
29 TexCoordPrecisionMedium
= 1,
30 TexCoordPrecisionHigh
= 2,
31 NumTexCoordPrecisions
= 3
37 SamplerType2DRect
= 2,
38 SamplerTypeExternalOES
= 3,
42 // Note: The highp_threshold_cache must be provided by the caller to make
43 // the caching multi-thread/context safe in an easy low-overhead manner.
44 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
45 // reinitialized, if a new or different context is used.
46 CC_EXPORT TexCoordPrecision
TexCoordPrecisionRequired(
47 gpu::gles2::GLES2Interface
* context
,
48 int *highp_threshold_cache
,
49 int highp_threshold_min
,
50 gfx::Point max_coordinate
);
52 CC_EXPORT TexCoordPrecision
TexCoordPrecisionRequired(
53 gpu::gles2::GLES2Interface
* context
,
54 int *highp_threshold_cache
,
55 int highp_threshold_min
,
58 class VertexShaderPosTex
{
62 void Init(gpu::gles2::GLES2Interface
* context
,
64 int* base_uniform_index
);
65 std::string
GetShaderString() const;
67 int matrix_location() const { return matrix_location_
; }
72 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex
);
75 class VertexShaderPosTexYUVStretch
{
77 VertexShaderPosTexYUVStretch();
79 void Init(gpu::gles2::GLES2Interface
* context
,
81 int* base_uniform_index
);
82 std::string
GetShaderString() const;
84 int matrix_location() const { return matrix_location_
; }
85 int tex_scale_location() const { return tex_scale_location_
; }
89 int tex_scale_location_
;
91 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretch
);
94 class VertexShaderPos
{
98 void Init(gpu::gles2::GLES2Interface
* context
,
100 int* base_uniform_index
);
101 std::string
GetShaderString() const;
103 int matrix_location() const { return matrix_location_
; }
106 int matrix_location_
;
108 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos
);
111 class VertexShaderPosTexIdentity
{
113 void Init(gpu::gles2::GLES2Interface
* context
,
115 int* base_uniform_index
) {}
116 std::string
GetShaderString() const;
119 class VertexShaderPosTexTransform
{
121 VertexShaderPosTexTransform();
123 void Init(gpu::gles2::GLES2Interface
* context
,
125 int* base_uniform_index
);
126 std::string
GetShaderString() const;
128 int matrix_location() const { return matrix_location_
; }
129 int tex_transform_location() const { return tex_transform_location_
; }
130 int vertex_opacity_location() const { return vertex_opacity_location_
; }
133 int matrix_location_
;
134 int tex_transform_location_
;
135 int vertex_opacity_location_
;
137 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform
);
140 class VertexShaderQuad
{
144 void Init(gpu::gles2::GLES2Interface
* context
,
146 int* base_uniform_index
);
147 std::string
GetShaderString() const;
149 int matrix_location() const { return matrix_location_
; }
150 int viewport_location() const { return -1; }
151 int quad_location() const { return quad_location_
; }
152 int edge_location() const { return -1; }
155 int matrix_location_
;
158 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad
);
161 class VertexShaderQuadAA
{
163 VertexShaderQuadAA();
165 void Init(gpu::gles2::GLES2Interface
* context
,
167 int* base_uniform_index
);
168 std::string
GetShaderString() const;
170 int matrix_location() const { return matrix_location_
; }
171 int viewport_location() const { return viewport_location_
; }
172 int quad_location() const { return quad_location_
; }
173 int edge_location() const { return edge_location_
; }
176 int matrix_location_
;
177 int viewport_location_
;
181 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA
);
185 class VertexShaderQuadTexTransformAA
{
187 VertexShaderQuadTexTransformAA();
189 void Init(gpu::gles2::GLES2Interface
* context
,
191 int* base_uniform_index
);
192 std::string
GetShaderString() const;
194 int matrix_location() const { return matrix_location_
; }
195 int viewport_location() const { return viewport_location_
; }
196 int quad_location() const { return quad_location_
; }
197 int edge_location() const { return edge_location_
; }
198 int tex_transform_location() const { return tex_transform_location_
; }
201 int matrix_location_
;
202 int viewport_location_
;
205 int tex_transform_location_
;
207 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA
);
210 class VertexShaderTile
{
214 void Init(gpu::gles2::GLES2Interface
* context
,
216 int* base_uniform_index
);
217 std::string
GetShaderString() const;
219 int matrix_location() const { return matrix_location_
; }
220 int viewport_location() const { return -1; }
221 int quad_location() const { return quad_location_
; }
222 int edge_location() const { return -1; }
223 int vertex_tex_transform_location() const {
224 return vertex_tex_transform_location_
;
228 int matrix_location_
;
230 int vertex_tex_transform_location_
;
232 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile
);
235 class VertexShaderTileAA
{
237 VertexShaderTileAA();
239 void Init(gpu::gles2::GLES2Interface
* context
,
241 int* base_uniform_index
);
242 std::string
GetShaderString() const;
244 int matrix_location() const { return matrix_location_
; }
245 int viewport_location() const { return viewport_location_
; }
246 int quad_location() const { return quad_location_
; }
247 int edge_location() const { return edge_location_
; }
248 int vertex_tex_transform_location() const {
249 return vertex_tex_transform_location_
;
253 int matrix_location_
;
254 int viewport_location_
;
257 int vertex_tex_transform_location_
;
259 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA
);
262 class VertexShaderVideoTransform
{
264 VertexShaderVideoTransform();
266 void Init(gpu::gles2::GLES2Interface
* context
,
268 int* base_uniform_index
);
269 std::string
GetShaderString() const;
271 int matrix_location() const { return matrix_location_
; }
272 int tex_matrix_location() const { return tex_matrix_location_
; }
275 int matrix_location_
;
276 int tex_matrix_location_
;
278 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform
);
281 class FragmentTexAlphaBinding
{
283 FragmentTexAlphaBinding();
285 void Init(gpu::gles2::GLES2Interface
* context
,
287 int* base_uniform_index
);
288 int alpha_location() const { return alpha_location_
; }
289 int fragment_tex_transform_location() const { return -1; }
290 int sampler_location() const { return sampler_location_
; }
293 int sampler_location_
;
296 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding
);
299 class FragmentTexColorMatrixAlphaBinding
{
301 FragmentTexColorMatrixAlphaBinding();
303 void Init(gpu::gles2::GLES2Interface
* context
,
305 int* base_uniform_index
);
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(gpu::gles2::GLES2Interface
* context
,
325 int* base_uniform_index
);
326 int alpha_location() const { return -1; }
327 int fragment_tex_transform_location() const { return -1; }
328 int background_color_location() const { return -1; }
329 int sampler_location() const { return sampler_location_
; }
332 int sampler_location_
;
334 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding
);
337 class FragmentTexBackgroundBinding
{
339 FragmentTexBackgroundBinding();
341 void Init(gpu::gles2::GLES2Interface
* context
,
343 int* base_uniform_index
);
344 int background_color_location() const { return background_color_location_
; }
345 int sampler_location() const { return sampler_location_
; }
348 int background_color_location_
;
349 int sampler_location_
;
351 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding
);
354 class FragmentShaderRGBATexVaryingAlpha
: public FragmentTexOpaqueBinding
{
356 std::string
GetShaderString(
357 TexCoordPrecision precision
, SamplerType sampler
) const;
360 class FragmentShaderRGBATexPremultiplyAlpha
: public FragmentTexOpaqueBinding
{
362 std::string
GetShaderString(
363 TexCoordPrecision precision
, SamplerType sampler
) const;
366 class FragmentShaderTexBackgroundVaryingAlpha
367 : public FragmentTexBackgroundBinding
{
369 std::string
GetShaderString(
370 TexCoordPrecision precision
, SamplerType sampler
) const;
373 class FragmentShaderTexBackgroundPremultiplyAlpha
374 : public FragmentTexBackgroundBinding
{
376 std::string
GetShaderString(
377 TexCoordPrecision precision
, SamplerType sampler
) const;
380 class FragmentShaderRGBATexAlpha
: public FragmentTexAlphaBinding
{
382 std::string
GetShaderString(
383 TexCoordPrecision precision
, SamplerType sampler
) const;
386 class FragmentShaderRGBATexColorMatrixAlpha
387 : public FragmentTexColorMatrixAlphaBinding
{
389 std::string
GetShaderString(
390 TexCoordPrecision precision
, SamplerType sampler
) const;
393 class FragmentShaderRGBATexOpaque
: public FragmentTexOpaqueBinding
{
395 std::string
GetShaderString(
396 TexCoordPrecision precision
, SamplerType sampler
) const;
399 class FragmentShaderRGBATex
: public FragmentTexOpaqueBinding
{
401 std::string
GetShaderString(
402 TexCoordPrecision precision
, SamplerType sampler
) const;
405 // Swizzles the red and blue component of sampled texel with alpha.
406 class FragmentShaderRGBATexSwizzleAlpha
: public FragmentTexAlphaBinding
{
408 std::string
GetShaderString(
409 TexCoordPrecision precision
, SamplerType sampler
) const;
412 // Swizzles the red and blue component of sampled texel without alpha.
413 class FragmentShaderRGBATexSwizzleOpaque
: public FragmentTexOpaqueBinding
{
415 std::string
GetShaderString(
416 TexCoordPrecision precision
, SamplerType sampler
) const;
419 class FragmentShaderRGBATexAlphaAA
{
421 FragmentShaderRGBATexAlphaAA();
423 void Init(gpu::gles2::GLES2Interface
* context
,
425 int* base_uniform_index
);
426 std::string
GetShaderString(
427 TexCoordPrecision precision
, SamplerType sampler
) const;
429 int alpha_location() const { return alpha_location_
; }
430 int sampler_location() const { return sampler_location_
; }
433 int sampler_location_
;
436 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA
);
439 class FragmentTexClampAlphaAABinding
{
441 FragmentTexClampAlphaAABinding();
443 void Init(gpu::gles2::GLES2Interface
* context
,
445 int* base_uniform_index
);
446 int alpha_location() const { return alpha_location_
; }
447 int sampler_location() const { return sampler_location_
; }
448 int fragment_tex_transform_location() const {
449 return fragment_tex_transform_location_
;
453 int sampler_location_
;
455 int fragment_tex_transform_location_
;
457 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding
);
460 class FragmentShaderRGBATexClampAlphaAA
461 : public FragmentTexClampAlphaAABinding
{
463 std::string
GetShaderString(
464 TexCoordPrecision precision
, SamplerType sampler
) const;
467 // Swizzles the red and blue component of sampled texel.
468 class FragmentShaderRGBATexClampSwizzleAlphaAA
469 : public FragmentTexClampAlphaAABinding
{
471 std::string
GetShaderString(
472 TexCoordPrecision precision
, SamplerType sampler
) const;
475 class FragmentShaderRGBATexAlphaMask
{
477 FragmentShaderRGBATexAlphaMask();
478 std::string
GetShaderString(
479 TexCoordPrecision precision
, SamplerType sampler
) const;
481 void Init(gpu::gles2::GLES2Interface
* context
,
483 int* base_uniform_index
);
484 int alpha_location() const { return alpha_location_
; }
485 int sampler_location() const { return sampler_location_
; }
486 int mask_sampler_location() const { return mask_sampler_location_
; }
487 int mask_tex_coord_scale_location() const {
488 return mask_tex_coord_scale_location_
;
490 int mask_tex_coord_offset_location() const {
491 return mask_tex_coord_offset_location_
;
495 int sampler_location_
;
496 int mask_sampler_location_
;
498 int mask_tex_coord_scale_location_
;
499 int mask_tex_coord_offset_location_
;
501 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask
);
504 class FragmentShaderRGBATexAlphaMaskAA
{
506 FragmentShaderRGBATexAlphaMaskAA();
507 std::string
GetShaderString(
508 TexCoordPrecision precision
, SamplerType sampler
) const;
510 void Init(gpu::gles2::GLES2Interface
* context
,
512 int* base_uniform_index
);
513 int alpha_location() const { return alpha_location_
; }
514 int sampler_location() const { return sampler_location_
; }
515 int mask_sampler_location() const { return mask_sampler_location_
; }
516 int mask_tex_coord_scale_location() const {
517 return mask_tex_coord_scale_location_
;
519 int mask_tex_coord_offset_location() const {
520 return mask_tex_coord_offset_location_
;
524 int sampler_location_
;
525 int mask_sampler_location_
;
527 int mask_tex_coord_scale_location_
;
528 int mask_tex_coord_offset_location_
;
530 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA
);
533 class FragmentShaderRGBATexAlphaMaskColorMatrixAA
{
535 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
536 std::string
GetShaderString(
537 TexCoordPrecision precision
, SamplerType sampler
) const;
539 void Init(gpu::gles2::GLES2Interface
* context
,
541 int* base_uniform_index
);
542 int alpha_location() const { return alpha_location_
; }
543 int sampler_location() const { return sampler_location_
; }
544 int mask_sampler_location() const { return mask_sampler_location_
; }
545 int mask_tex_coord_scale_location() const {
546 return mask_tex_coord_scale_location_
;
548 int mask_tex_coord_offset_location() const {
549 return mask_tex_coord_offset_location_
;
551 int color_matrix_location() const { return color_matrix_location_
; }
552 int color_offset_location() const { return color_offset_location_
; }
555 int sampler_location_
;
556 int mask_sampler_location_
;
558 int mask_tex_coord_scale_location_
;
559 int mask_tex_coord_offset_location_
;
560 int color_matrix_location_
;
561 int color_offset_location_
;
564 class FragmentShaderRGBATexAlphaColorMatrixAA
{
566 FragmentShaderRGBATexAlphaColorMatrixAA();
567 std::string
GetShaderString(
568 TexCoordPrecision precision
, SamplerType sampler
) const;
570 void Init(gpu::gles2::GLES2Interface
* context
,
572 int* base_uniform_index
);
573 int alpha_location() const { return alpha_location_
; }
574 int sampler_location() const { return sampler_location_
; }
575 int color_matrix_location() const { return color_matrix_location_
; }
576 int color_offset_location() const { return color_offset_location_
; }
579 int sampler_location_
;
581 int color_matrix_location_
;
582 int color_offset_location_
;
585 class FragmentShaderRGBATexAlphaMaskColorMatrix
{
587 FragmentShaderRGBATexAlphaMaskColorMatrix();
588 std::string
GetShaderString(
589 TexCoordPrecision precision
, SamplerType sampler
) const;
591 void Init(gpu::gles2::GLES2Interface
* context
,
593 int* base_uniform_index
);
594 int alpha_location() const { return alpha_location_
; }
595 int sampler_location() const { return sampler_location_
; }
596 int mask_sampler_location() const { return mask_sampler_location_
; }
597 int mask_tex_coord_scale_location() const {
598 return mask_tex_coord_scale_location_
;
600 int mask_tex_coord_offset_location() const {
601 return mask_tex_coord_offset_location_
;
603 int color_matrix_location() const { return color_matrix_location_
; }
604 int color_offset_location() const { return color_offset_location_
; }
607 int sampler_location_
;
608 int mask_sampler_location_
;
610 int mask_tex_coord_scale_location_
;
611 int mask_tex_coord_offset_location_
;
612 int color_matrix_location_
;
613 int color_offset_location_
;
616 class FragmentShaderYUVVideo
{
618 FragmentShaderYUVVideo();
619 std::string
GetShaderString(
620 TexCoordPrecision precision
, SamplerType sampler
) const;
622 void Init(gpu::gles2::GLES2Interface
* context
,
624 int* base_uniform_index
);
625 int y_texture_location() const { return y_texture_location_
; }
626 int u_texture_location() const { return u_texture_location_
; }
627 int v_texture_location() const { return v_texture_location_
; }
628 int alpha_location() const { return alpha_location_
; }
629 int yuv_matrix_location() const { return yuv_matrix_location_
; }
630 int yuv_adj_location() const { return yuv_adj_location_
; }
633 int y_texture_location_
;
634 int u_texture_location_
;
635 int v_texture_location_
;
637 int yuv_matrix_location_
;
638 int yuv_adj_location_
;
640 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo
);
644 class FragmentShaderYUVAVideo
{
646 FragmentShaderYUVAVideo();
647 std::string
GetShaderString(
648 TexCoordPrecision precision
, SamplerType sampler
) const;
650 void Init(gpu::gles2::GLES2Interface
* context
,
652 int* base_uniform_index
);
654 int y_texture_location() const { return y_texture_location_
; }
655 int u_texture_location() const { return u_texture_location_
; }
656 int v_texture_location() const { return v_texture_location_
; }
657 int a_texture_location() const { return a_texture_location_
; }
658 int alpha_location() const { return alpha_location_
; }
659 int yuv_matrix_location() const { return yuv_matrix_location_
; }
660 int yuv_adj_location() const { return yuv_adj_location_
; }
663 int y_texture_location_
;
664 int u_texture_location_
;
665 int v_texture_location_
;
666 int a_texture_location_
;
668 int yuv_matrix_location_
;
669 int yuv_adj_location_
;
671 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo
);
674 class FragmentShaderColor
{
676 FragmentShaderColor();
677 std::string
GetShaderString(
678 TexCoordPrecision precision
, SamplerType sampler
) const;
680 void Init(gpu::gles2::GLES2Interface
* context
,
682 int* base_uniform_index
);
683 int color_location() const { return color_location_
; }
688 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor
);
691 class FragmentShaderColorAA
{
693 FragmentShaderColorAA();
694 std::string
GetShaderString(
695 TexCoordPrecision precision
, SamplerType sampler
) const;
697 void Init(gpu::gles2::GLES2Interface
* context
,
699 int* base_uniform_index
);
700 int color_location() const { return color_location_
; }
705 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA
);
708 class FragmentShaderCheckerboard
{
710 FragmentShaderCheckerboard();
711 std::string
GetShaderString(
712 TexCoordPrecision precision
, SamplerType sampler
) const;
714 void Init(gpu::gles2::GLES2Interface
* context
,
716 int* base_uniform_index
);
717 int alpha_location() const { return alpha_location_
; }
718 int tex_transform_location() const { return tex_transform_location_
; }
719 int frequency_location() const { return frequency_location_
; }
720 int color_location() const { return color_location_
; }
724 int tex_transform_location_
;
725 int frequency_location_
;
728 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard
);
733 #endif // CC_OUTPUT_SHADER_H_