NaCl: Reinstate the "nacl_revision" field in DEPS
[chromium-blink-merge.git] / cc / output / shader.h
blob3039c80ef2c790f3506babb6b4f714fd8571280b
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "cc/base/cc_export.h"
13 namespace gfx {
14 class Point;
15 class Size;
18 namespace gpu {
19 namespace gles2 {
20 class GLES2Interface;
24 namespace cc {
26 enum TexCoordPrecision {
27 TexCoordPrecisionNA = 0,
28 TexCoordPrecisionMedium = 1,
29 TexCoordPrecisionHigh = 2,
30 NumTexCoordPrecisions = 3
33 enum SamplerType {
34 SamplerTypeNA = 0,
35 SamplerType2D = 1,
36 SamplerType2DRect = 2,
37 SamplerTypeExternalOES = 3,
38 NumSamplerTypes = 4
41 // Note: The highp_threshold_cache must be provided by the caller to make
42 // the caching multi-thread/context safe in an easy low-overhead manner.
43 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
44 // reinitialized, if a new or different context is used.
45 CC_EXPORT TexCoordPrecision
46 TexCoordPrecisionRequired(gpu::gles2::GLES2Interface* context,
47 int* highp_threshold_cache,
48 int highp_threshold_min,
49 const gfx::Point& max_coordinate);
51 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired(
52 gpu::gles2::GLES2Interface* context,
53 int *highp_threshold_cache,
54 int highp_threshold_min,
55 const gfx::Size& max_size);
57 class VertexShaderPosTex {
58 public:
59 VertexShaderPosTex();
61 void Init(gpu::gles2::GLES2Interface* context,
62 unsigned program,
63 int* base_uniform_index);
64 std::string GetShaderString() const;
66 int matrix_location() const { return matrix_location_; }
68 private:
69 int matrix_location_;
71 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex);
74 class VertexShaderPosTexYUVStretchOffset {
75 public:
76 VertexShaderPosTexYUVStretchOffset();
78 void Init(gpu::gles2::GLES2Interface* context,
79 unsigned program,
80 int* base_uniform_index);
81 std::string GetShaderString() const;
83 int matrix_location() const { return matrix_location_; }
84 int tex_scale_location() const { return tex_scale_location_; }
85 int tex_offset_location() const { return tex_offset_location_; }
87 private:
88 int matrix_location_;
89 int tex_scale_location_;
90 int tex_offset_location_;
92 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretchOffset);
95 class VertexShaderPos {
96 public:
97 VertexShaderPos();
99 void Init(gpu::gles2::GLES2Interface* context,
100 unsigned program,
101 int* base_uniform_index);
102 std::string GetShaderString() const;
104 int matrix_location() const { return matrix_location_; }
106 private:
107 int matrix_location_;
109 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos);
112 class VertexShaderPosTexIdentity {
113 public:
114 void Init(gpu::gles2::GLES2Interface* context,
115 unsigned program,
116 int* base_uniform_index) {}
117 std::string GetShaderString() const;
120 class VertexShaderPosTexTransform {
121 public:
122 VertexShaderPosTexTransform();
124 void Init(gpu::gles2::GLES2Interface* context,
125 unsigned program,
126 int* base_uniform_index);
127 std::string GetShaderString() const;
129 int matrix_location() const { return matrix_location_; }
130 int tex_transform_location() const { return tex_transform_location_; }
131 int vertex_opacity_location() const { return vertex_opacity_location_; }
133 private:
134 int matrix_location_;
135 int tex_transform_location_;
136 int vertex_opacity_location_;
138 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform);
141 class VertexShaderQuad {
142 public:
143 VertexShaderQuad();
145 void Init(gpu::gles2::GLES2Interface* context,
146 unsigned program,
147 int* base_uniform_index);
148 std::string GetShaderString() const;
150 int matrix_location() const { return matrix_location_; }
151 int viewport_location() const { return -1; }
152 int quad_location() const { return quad_location_; }
153 int edge_location() const { return -1; }
155 private:
156 int matrix_location_;
157 int quad_location_;
159 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
162 class VertexShaderQuadAA {
163 public:
164 VertexShaderQuadAA();
166 void Init(gpu::gles2::GLES2Interface* context,
167 unsigned program,
168 int* base_uniform_index);
169 std::string GetShaderString() const;
171 int matrix_location() const { return matrix_location_; }
172 int viewport_location() const { return viewport_location_; }
173 int quad_location() const { return quad_location_; }
174 int edge_location() const { return edge_location_; }
176 private:
177 int matrix_location_;
178 int viewport_location_;
179 int quad_location_;
180 int edge_location_;
182 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA);
186 class VertexShaderQuadTexTransformAA {
187 public:
188 VertexShaderQuadTexTransformAA();
190 void Init(gpu::gles2::GLES2Interface* context,
191 unsigned program,
192 int* base_uniform_index);
193 std::string GetShaderString() const;
195 int matrix_location() const { return matrix_location_; }
196 int viewport_location() const { return viewport_location_; }
197 int quad_location() const { return quad_location_; }
198 int edge_location() const { return edge_location_; }
199 int tex_transform_location() const { return tex_transform_location_; }
201 private:
202 int matrix_location_;
203 int viewport_location_;
204 int quad_location_;
205 int edge_location_;
206 int tex_transform_location_;
208 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA);
211 class VertexShaderTile {
212 public:
213 VertexShaderTile();
215 void Init(gpu::gles2::GLES2Interface* context,
216 unsigned program,
217 int* base_uniform_index);
218 std::string GetShaderString() const;
220 int matrix_location() const { return matrix_location_; }
221 int viewport_location() const { return -1; }
222 int quad_location() const { return quad_location_; }
223 int edge_location() const { return -1; }
224 int vertex_tex_transform_location() const {
225 return vertex_tex_transform_location_;
228 private:
229 int matrix_location_;
230 int quad_location_;
231 int vertex_tex_transform_location_;
233 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);
236 class VertexShaderTileAA {
237 public:
238 VertexShaderTileAA();
240 void Init(gpu::gles2::GLES2Interface* context,
241 unsigned program,
242 int* base_uniform_index);
243 std::string GetShaderString() const;
245 int matrix_location() const { return matrix_location_; }
246 int viewport_location() const { return viewport_location_; }
247 int quad_location() const { return quad_location_; }
248 int edge_location() const { return edge_location_; }
249 int vertex_tex_transform_location() const {
250 return vertex_tex_transform_location_;
253 private:
254 int matrix_location_;
255 int viewport_location_;
256 int quad_location_;
257 int edge_location_;
258 int vertex_tex_transform_location_;
260 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA);
263 class VertexShaderVideoTransform {
264 public:
265 VertexShaderVideoTransform();
267 void Init(gpu::gles2::GLES2Interface* context,
268 unsigned program,
269 int* base_uniform_index);
270 std::string GetShaderString() const;
272 int matrix_location() const { return matrix_location_; }
273 int tex_matrix_location() const { return tex_matrix_location_; }
275 private:
276 int matrix_location_;
277 int tex_matrix_location_;
279 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform);
282 class FragmentTexAlphaBinding {
283 public:
284 FragmentTexAlphaBinding();
286 void Init(gpu::gles2::GLES2Interface* context,
287 unsigned program,
288 int* base_uniform_index);
289 int alpha_location() const { return alpha_location_; }
290 int fragment_tex_transform_location() const { return -1; }
291 int sampler_location() const { return sampler_location_; }
293 private:
294 int sampler_location_;
295 int alpha_location_;
297 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
300 class FragmentTexColorMatrixAlphaBinding {
301 public:
302 FragmentTexColorMatrixAlphaBinding();
304 void Init(gpu::gles2::GLES2Interface* context,
305 unsigned program,
306 int* base_uniform_index);
307 int alpha_location() const { return alpha_location_; }
308 int color_matrix_location() const { return color_matrix_location_; }
309 int color_offset_location() const { return color_offset_location_; }
310 int fragment_tex_transform_location() const { return -1; }
311 int sampler_location() const { return sampler_location_; }
313 private:
314 int sampler_location_;
315 int alpha_location_;
316 int color_matrix_location_;
317 int color_offset_location_;
320 class FragmentTexOpaqueBinding {
321 public:
322 FragmentTexOpaqueBinding();
324 void Init(gpu::gles2::GLES2Interface* context,
325 unsigned program,
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_; }
332 private:
333 int sampler_location_;
335 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
338 class FragmentTexBackgroundBinding {
339 public:
340 FragmentTexBackgroundBinding();
342 void Init(gpu::gles2::GLES2Interface* context,
343 unsigned program,
344 int* base_uniform_index);
345 int background_color_location() const { return background_color_location_; }
346 int sampler_location() const { return sampler_location_; }
348 private:
349 int background_color_location_;
350 int sampler_location_;
352 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
355 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
356 public:
357 std::string GetShaderString(
358 TexCoordPrecision precision, SamplerType sampler) const;
361 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
362 public:
363 std::string GetShaderString(
364 TexCoordPrecision precision, SamplerType sampler) const;
367 class FragmentShaderTexBackgroundVaryingAlpha
368 : public FragmentTexBackgroundBinding {
369 public:
370 std::string GetShaderString(
371 TexCoordPrecision precision, SamplerType sampler) const;
374 class FragmentShaderTexBackgroundPremultiplyAlpha
375 : public FragmentTexBackgroundBinding {
376 public:
377 std::string GetShaderString(
378 TexCoordPrecision precision, SamplerType sampler) const;
381 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
382 public:
383 std::string GetShaderString(
384 TexCoordPrecision precision, SamplerType sampler) const;
387 class FragmentShaderRGBATexColorMatrixAlpha
388 : public FragmentTexColorMatrixAlphaBinding {
389 public:
390 std::string GetShaderString(
391 TexCoordPrecision precision, SamplerType sampler) const;
394 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
395 public:
396 std::string GetShaderString(
397 TexCoordPrecision precision, SamplerType sampler) const;
400 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
401 public:
402 std::string GetShaderString(
403 TexCoordPrecision precision, SamplerType sampler) const;
406 // Swizzles the red and blue component of sampled texel with alpha.
407 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding {
408 public:
409 std::string GetShaderString(
410 TexCoordPrecision precision, SamplerType sampler) const;
413 // Swizzles the red and blue component of sampled texel without alpha.
414 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding {
415 public:
416 std::string GetShaderString(
417 TexCoordPrecision precision, SamplerType sampler) const;
420 class FragmentShaderRGBATexAlphaAA {
421 public:
422 FragmentShaderRGBATexAlphaAA();
424 void Init(gpu::gles2::GLES2Interface* context,
425 unsigned program,
426 int* base_uniform_index);
427 std::string GetShaderString(
428 TexCoordPrecision precision, SamplerType sampler) const;
430 int alpha_location() const { return alpha_location_; }
431 int sampler_location() const { return sampler_location_; }
433 private:
434 int sampler_location_;
435 int alpha_location_;
437 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
440 class FragmentTexClampAlphaAABinding {
441 public:
442 FragmentTexClampAlphaAABinding();
444 void Init(gpu::gles2::GLES2Interface* context,
445 unsigned program,
446 int* base_uniform_index);
447 int alpha_location() const { return alpha_location_; }
448 int sampler_location() const { return sampler_location_; }
449 int fragment_tex_transform_location() const {
450 return fragment_tex_transform_location_;
453 private:
454 int sampler_location_;
455 int alpha_location_;
456 int fragment_tex_transform_location_;
458 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
461 class FragmentShaderRGBATexClampAlphaAA
462 : public FragmentTexClampAlphaAABinding {
463 public:
464 std::string GetShaderString(
465 TexCoordPrecision precision, SamplerType sampler) const;
468 // Swizzles the red and blue component of sampled texel.
469 class FragmentShaderRGBATexClampSwizzleAlphaAA
470 : public FragmentTexClampAlphaAABinding {
471 public:
472 std::string GetShaderString(
473 TexCoordPrecision precision, SamplerType sampler) const;
476 class FragmentShaderRGBATexAlphaMask {
477 public:
478 FragmentShaderRGBATexAlphaMask();
479 std::string GetShaderString(
480 TexCoordPrecision precision, SamplerType sampler) const;
482 void Init(gpu::gles2::GLES2Interface* context,
483 unsigned program,
484 int* base_uniform_index);
485 int alpha_location() const { return alpha_location_; }
486 int sampler_location() const { return sampler_location_; }
487 int mask_sampler_location() const { return mask_sampler_location_; }
488 int mask_tex_coord_scale_location() const {
489 return mask_tex_coord_scale_location_;
491 int mask_tex_coord_offset_location() const {
492 return mask_tex_coord_offset_location_;
495 private:
496 int sampler_location_;
497 int mask_sampler_location_;
498 int alpha_location_;
499 int mask_tex_coord_scale_location_;
500 int mask_tex_coord_offset_location_;
502 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
505 class FragmentShaderRGBATexAlphaMaskAA {
506 public:
507 FragmentShaderRGBATexAlphaMaskAA();
508 std::string GetShaderString(
509 TexCoordPrecision precision, SamplerType sampler) const;
511 void Init(gpu::gles2::GLES2Interface* context,
512 unsigned program,
513 int* base_uniform_index);
514 int alpha_location() const { return alpha_location_; }
515 int sampler_location() const { return sampler_location_; }
516 int mask_sampler_location() const { return mask_sampler_location_; }
517 int mask_tex_coord_scale_location() const {
518 return mask_tex_coord_scale_location_;
520 int mask_tex_coord_offset_location() const {
521 return mask_tex_coord_offset_location_;
524 private:
525 int sampler_location_;
526 int mask_sampler_location_;
527 int alpha_location_;
528 int mask_tex_coord_scale_location_;
529 int mask_tex_coord_offset_location_;
531 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
534 class FragmentShaderRGBATexAlphaMaskColorMatrixAA {
535 public:
536 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
537 std::string GetShaderString(
538 TexCoordPrecision precision, SamplerType sampler) const;
540 void Init(gpu::gles2::GLES2Interface* context,
541 unsigned program,
542 int* base_uniform_index);
543 int alpha_location() const { return alpha_location_; }
544 int sampler_location() const { return sampler_location_; }
545 int mask_sampler_location() const { return mask_sampler_location_; }
546 int mask_tex_coord_scale_location() const {
547 return mask_tex_coord_scale_location_;
549 int mask_tex_coord_offset_location() const {
550 return mask_tex_coord_offset_location_;
552 int color_matrix_location() const { return color_matrix_location_; }
553 int color_offset_location() const { return color_offset_location_; }
555 private:
556 int sampler_location_;
557 int mask_sampler_location_;
558 int alpha_location_;
559 int mask_tex_coord_scale_location_;
560 int mask_tex_coord_offset_location_;
561 int color_matrix_location_;
562 int color_offset_location_;
565 class FragmentShaderRGBATexAlphaColorMatrixAA {
566 public:
567 FragmentShaderRGBATexAlphaColorMatrixAA();
568 std::string GetShaderString(
569 TexCoordPrecision precision, SamplerType sampler) const;
571 void Init(gpu::gles2::GLES2Interface* context,
572 unsigned program,
573 int* base_uniform_index);
574 int alpha_location() const { return alpha_location_; }
575 int sampler_location() const { return sampler_location_; }
576 int color_matrix_location() const { return color_matrix_location_; }
577 int color_offset_location() const { return color_offset_location_; }
579 private:
580 int sampler_location_;
581 int alpha_location_;
582 int color_matrix_location_;
583 int color_offset_location_;
586 class FragmentShaderRGBATexAlphaMaskColorMatrix {
587 public:
588 FragmentShaderRGBATexAlphaMaskColorMatrix();
589 std::string GetShaderString(
590 TexCoordPrecision precision, SamplerType sampler) const;
592 void Init(gpu::gles2::GLES2Interface* context,
593 unsigned program,
594 int* base_uniform_index);
595 int alpha_location() const { return alpha_location_; }
596 int sampler_location() const { return sampler_location_; }
597 int mask_sampler_location() const { return mask_sampler_location_; }
598 int mask_tex_coord_scale_location() const {
599 return mask_tex_coord_scale_location_;
601 int mask_tex_coord_offset_location() const {
602 return mask_tex_coord_offset_location_;
604 int color_matrix_location() const { return color_matrix_location_; }
605 int color_offset_location() const { return color_offset_location_; }
607 private:
608 int sampler_location_;
609 int mask_sampler_location_;
610 int alpha_location_;
611 int mask_tex_coord_scale_location_;
612 int mask_tex_coord_offset_location_;
613 int color_matrix_location_;
614 int color_offset_location_;
617 class FragmentShaderYUVVideo {
618 public:
619 FragmentShaderYUVVideo();
620 std::string GetShaderString(
621 TexCoordPrecision precision, SamplerType sampler) const;
623 void Init(gpu::gles2::GLES2Interface* context,
624 unsigned program,
625 int* base_uniform_index);
626 int y_texture_location() const { return y_texture_location_; }
627 int u_texture_location() const { return u_texture_location_; }
628 int v_texture_location() const { return v_texture_location_; }
629 int alpha_location() const { return alpha_location_; }
630 int yuv_matrix_location() const { return yuv_matrix_location_; }
631 int yuv_adj_location() const { return yuv_adj_location_; }
633 private:
634 int y_texture_location_;
635 int u_texture_location_;
636 int v_texture_location_;
637 int alpha_location_;
638 int yuv_matrix_location_;
639 int yuv_adj_location_;
641 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
645 class FragmentShaderYUVAVideo {
646 public:
647 FragmentShaderYUVAVideo();
648 std::string GetShaderString(
649 TexCoordPrecision precision, SamplerType sampler) const;
651 void Init(gpu::gles2::GLES2Interface* context,
652 unsigned program,
653 int* base_uniform_index);
655 int y_texture_location() const { return y_texture_location_; }
656 int u_texture_location() const { return u_texture_location_; }
657 int v_texture_location() const { return v_texture_location_; }
658 int a_texture_location() const { return a_texture_location_; }
659 int alpha_location() const { return alpha_location_; }
660 int yuv_matrix_location() const { return yuv_matrix_location_; }
661 int yuv_adj_location() const { return yuv_adj_location_; }
663 private:
664 int y_texture_location_;
665 int u_texture_location_;
666 int v_texture_location_;
667 int a_texture_location_;
668 int alpha_location_;
669 int yuv_matrix_location_;
670 int yuv_adj_location_;
672 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo);
675 class FragmentShaderColor {
676 public:
677 FragmentShaderColor();
678 std::string GetShaderString(
679 TexCoordPrecision precision, SamplerType sampler) const;
681 void Init(gpu::gles2::GLES2Interface* context,
682 unsigned program,
683 int* base_uniform_index);
684 int color_location() const { return color_location_; }
686 private:
687 int color_location_;
689 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
692 class FragmentShaderColorAA {
693 public:
694 FragmentShaderColorAA();
695 std::string GetShaderString(
696 TexCoordPrecision precision, SamplerType sampler) const;
698 void Init(gpu::gles2::GLES2Interface* context,
699 unsigned program,
700 int* base_uniform_index);
701 int color_location() const { return color_location_; }
703 private:
704 int color_location_;
706 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA);
709 class FragmentShaderCheckerboard {
710 public:
711 FragmentShaderCheckerboard();
712 std::string GetShaderString(
713 TexCoordPrecision precision, SamplerType sampler) const;
715 void Init(gpu::gles2::GLES2Interface* context,
716 unsigned program,
717 int* base_uniform_index);
718 int alpha_location() const { return alpha_location_; }
719 int tex_transform_location() const { return tex_transform_location_; }
720 int frequency_location() const { return frequency_location_; }
721 int color_location() const { return color_location_; }
723 private:
724 int alpha_location_;
725 int tex_transform_location_;
726 int frequency_location_;
727 int color_location_;
729 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard);
732 } // namespace cc
734 #endif // CC_OUTPUT_SHADER_H_