cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / output / shader.h
blob7135befd3899f913c319d70544f8bb1640b32a2c
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"
12 #include "third_party/skia/include/core/SkColorPriv.h"
14 namespace gfx {
15 class Point;
16 class Size;
19 namespace WebKit { class WebGraphicsContext3D; }
21 namespace cc {
23 enum TexCoordPrecision {
24 TexCoordPrecisionNA,
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,
43 gfx::Size max_size);
45 class VertexShaderPosTex {
46 public:
47 VertexShaderPosTex();
49 void Init(WebKit::WebGraphicsContext3D* context,
50 unsigned program,
51 bool using_bind_uniform,
52 int* base_uniform_index);
53 std::string GetShaderString() const;
55 int matrix_location() const { return matrix_location_; }
57 private:
58 int matrix_location_;
60 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex);
63 class VertexShaderPosTexYUVStretch {
64 public:
65 VertexShaderPosTexYUVStretch();
67 void Init(WebKit::WebGraphicsContext3D* context,
68 unsigned program,
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_; }
76 private:
77 int matrix_location_;
78 int tex_scale_location_;
80 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretch);
83 class VertexShaderPos {
84 public:
85 VertexShaderPos();
87 void Init(WebKit::WebGraphicsContext3D* context,
88 unsigned program,
89 bool using_bind_uniform,
90 int* base_uniform_index);
91 std::string GetShaderString() const;
93 int matrix_location() const { return matrix_location_; }
95 private:
96 int matrix_location_;
98 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos);
101 class VertexShaderPosTexIdentity {
102 public:
103 void Init(WebKit::WebGraphicsContext3D* context,
104 unsigned program,
105 bool using_bind_uniform,
106 int* base_uniform_index) {}
107 std::string GetShaderString() const;
110 class VertexShaderPosTexTransform {
111 public:
112 VertexShaderPosTexTransform();
114 void Init(WebKit::WebGraphicsContext3D* context,
115 unsigned program,
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_; }
124 private:
125 int matrix_location_;
126 int tex_transform_location_;
127 int vertex_opacity_location_;
129 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform);
132 class VertexShaderQuad {
133 public:
134 VertexShaderQuad();
136 void Init(WebKit::WebGraphicsContext3D* context,
137 unsigned program,
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; }
147 private:
148 int matrix_location_;
149 int quad_location_;
151 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
154 class VertexShaderQuadAA {
155 public:
156 VertexShaderQuadAA();
158 void Init(WebKit::WebGraphicsContext3D* context,
159 unsigned program,
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_; }
169 private:
170 int matrix_location_;
171 int viewport_location_;
172 int quad_location_;
173 int edge_location_;
175 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA);
179 class VertexShaderQuadTexTransformAA {
180 public:
181 VertexShaderQuadTexTransformAA();
183 void Init(WebKit::WebGraphicsContext3D* context,
184 unsigned program,
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_; }
195 private:
196 int matrix_location_;
197 int viewport_location_;
198 int quad_location_;
199 int edge_location_;
200 int tex_transform_location_;
202 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA);
205 class VertexShaderTile {
206 public:
207 VertexShaderTile();
209 void Init(WebKit::WebGraphicsContext3D* context,
210 unsigned program,
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_;
223 private:
224 int matrix_location_;
225 int quad_location_;
226 int vertex_tex_transform_location_;
228 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);
231 class VertexShaderTileAA {
232 public:
233 VertexShaderTileAA();
235 void Init(WebKit::WebGraphicsContext3D* context,
236 unsigned program,
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_;
249 private:
250 int matrix_location_;
251 int viewport_location_;
252 int quad_location_;
253 int edge_location_;
254 int vertex_tex_transform_location_;
256 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA);
259 class VertexShaderVideoTransform {
260 public:
261 VertexShaderVideoTransform();
263 void Init(WebKit::WebGraphicsContext3D* context,
264 unsigned program,
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_; }
272 private:
273 int matrix_location_;
274 int tex_matrix_location_;
276 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform);
279 class FragmentTexAlphaBinding {
280 public:
281 FragmentTexAlphaBinding();
283 void Init(WebKit::WebGraphicsContext3D* context,
284 unsigned program,
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_; }
291 private:
292 int sampler_location_;
293 int alpha_location_;
295 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
298 class FragmentTexColorMatrixAlphaBinding {
299 public:
300 FragmentTexColorMatrixAlphaBinding();
302 void Init(WebKit::WebGraphicsContext3D* context,
303 unsigned program,
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_; }
312 private:
313 int sampler_location_;
314 int alpha_location_;
315 int color_matrix_location_;
316 int color_offset_location_;
319 class FragmentTexOpaqueBinding {
320 public:
321 FragmentTexOpaqueBinding();
323 void Init(WebKit::WebGraphicsContext3D* context,
324 unsigned program,
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_; }
332 private:
333 int sampler_location_;
335 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
338 class FragmentTexBackgroundBinding {
339 public:
340 FragmentTexBackgroundBinding();
342 void Init(WebKit::WebGraphicsContext3D* context,
343 unsigned program,
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_; }
349 private:
350 int background_color_location_;
351 int sampler_location_;
353 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
356 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
357 public:
358 std::string GetShaderString(TexCoordPrecision precision) const;
361 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
362 public:
363 std::string GetShaderString(TexCoordPrecision precision) const;
366 class FragmentShaderTexBackgroundVaryingAlpha
367 : public FragmentTexBackgroundBinding {
368 public:
369 std::string GetShaderString(TexCoordPrecision precision) const;
372 class FragmentShaderTexBackgroundPremultiplyAlpha
373 : public FragmentTexBackgroundBinding {
374 public:
375 std::string GetShaderString(TexCoordPrecision precision) const;
378 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
379 public:
380 std::string GetShaderString(TexCoordPrecision precision) const;
383 class FragmentShaderRGBATexColorMatrixAlpha
384 : public FragmentTexColorMatrixAlphaBinding {
385 public:
386 std::string GetShaderString(TexCoordPrecision precision) const;
389 class FragmentShaderRGBATexRectVaryingAlpha : public FragmentTexOpaqueBinding {
390 public:
391 std::string GetShaderString(TexCoordPrecision precision) const;
394 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
395 public:
396 std::string GetShaderString(TexCoordPrecision precision) const;
399 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
400 public:
401 std::string GetShaderString(TexCoordPrecision precision) const;
404 // Swizzles the red and blue component of sampled texel with alpha.
405 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding {
406 public:
407 std::string GetShaderString(TexCoordPrecision precision) const;
410 // Swizzles the red and blue component of sampled texel without alpha.
411 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding {
412 public:
413 std::string GetShaderString(TexCoordPrecision precision) const;
416 // Fragment shader for external textures.
417 class FragmentShaderOESImageExternal : public FragmentTexAlphaBinding {
418 public:
419 FragmentShaderOESImageExternal();
421 std::string GetShaderString(TexCoordPrecision precision) const;
422 void Init(WebKit::WebGraphicsContext3D* context,
423 unsigned program,
424 bool using_bind_uniform,
425 int* base_uniform_index);
426 private:
427 int sampler_location_;
429 DISALLOW_COPY_AND_ASSIGN(FragmentShaderOESImageExternal);
432 class FragmentShaderRGBATexAlphaAA {
433 public:
434 FragmentShaderRGBATexAlphaAA();
436 void Init(WebKit::WebGraphicsContext3D* context,
437 unsigned program,
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_; }
445 private:
446 int sampler_location_;
447 int alpha_location_;
449 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
452 class FragmentTexClampAlphaAABinding {
453 public:
454 FragmentTexClampAlphaAABinding();
456 void Init(WebKit::WebGraphicsContext3D* context,
457 unsigned program,
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_;
466 private:
467 int sampler_location_;
468 int alpha_location_;
469 int fragment_tex_transform_location_;
471 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
474 class FragmentShaderRGBATexClampAlphaAA
475 : public FragmentTexClampAlphaAABinding {
476 public:
477 std::string GetShaderString(TexCoordPrecision precision) const;
480 // Swizzles the red and blue component of sampled texel.
481 class FragmentShaderRGBATexClampSwizzleAlphaAA
482 : public FragmentTexClampAlphaAABinding {
483 public:
484 std::string GetShaderString(TexCoordPrecision precision) const;
487 class FragmentShaderRGBATexAlphaMask {
488 public:
489 FragmentShaderRGBATexAlphaMask();
490 std::string GetShaderString(TexCoordPrecision precision) const;
492 void Init(WebKit::WebGraphicsContext3D* context,
493 unsigned program,
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_;
506 private:
507 int sampler_location_;
508 int mask_sampler_location_;
509 int alpha_location_;
510 int mask_tex_coord_scale_location_;
511 int mask_tex_coord_offset_location_;
513 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
516 class FragmentShaderRGBATexAlphaMaskAA {
517 public:
518 FragmentShaderRGBATexAlphaMaskAA();
519 std::string GetShaderString(TexCoordPrecision precision) const;
521 void Init(WebKit::WebGraphicsContext3D* context,
522 unsigned program,
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_;
535 private:
536 int sampler_location_;
537 int mask_sampler_location_;
538 int alpha_location_;
539 int mask_tex_coord_scale_location_;
540 int mask_tex_coord_offset_location_;
542 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
545 class FragmentShaderRGBATexAlphaMaskColorMatrixAA {
546 public:
547 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
548 std::string GetShaderString(TexCoordPrecision precision) const;
550 void Init(WebKit::WebGraphicsContext3D* context,
551 unsigned program,
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_; }
566 private:
567 int sampler_location_;
568 int mask_sampler_location_;
569 int alpha_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 {
577 public:
578 FragmentShaderRGBATexAlphaColorMatrixAA();
579 std::string GetShaderString(TexCoordPrecision precision) const;
581 void Init(WebKit::WebGraphicsContext3D* context,
582 unsigned program,
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_; }
590 private:
591 int sampler_location_;
592 int alpha_location_;
593 int color_matrix_location_;
594 int color_offset_location_;
597 class FragmentShaderRGBATexAlphaMaskColorMatrix {
598 public:
599 FragmentShaderRGBATexAlphaMaskColorMatrix();
600 std::string GetShaderString(TexCoordPrecision precision) const;
602 void Init(WebKit::WebGraphicsContext3D* context,
603 unsigned program,
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_; }
618 private:
619 int sampler_location_;
620 int mask_sampler_location_;
621 int alpha_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 {
629 public:
630 FragmentShaderYUVVideo();
631 std::string GetShaderString(TexCoordPrecision precision) const;
633 void Init(WebKit::WebGraphicsContext3D* context,
634 unsigned program,
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_; }
644 private:
645 int y_texture_location_;
646 int u_texture_location_;
647 int v_texture_location_;
648 int alpha_location_;
649 int yuv_matrix_location_;
650 int yuv_adj_location_;
652 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
656 class FragmentShaderYUVAVideo {
657 public:
658 FragmentShaderYUVAVideo();
659 std::string GetShaderString(TexCoordPrecision precision) const;
661 void Init(WebKit::WebGraphicsContext3D* context,
662 unsigned program,
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_; }
674 private:
675 int y_texture_location_;
676 int u_texture_location_;
677 int v_texture_location_;
678 int a_texture_location_;
679 int alpha_location_;
680 int yuv_matrix_location_;
681 int yuv_adj_location_;
683 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo);
686 class FragmentShaderColor {
687 public:
688 FragmentShaderColor();
689 std::string GetShaderString(TexCoordPrecision precision) const;
691 void Init(WebKit::WebGraphicsContext3D* context,
692 unsigned program,
693 bool using_bind_uniform,
694 int* base_uniform_index);
695 int color_location() const { return color_location_; }
697 private:
698 int color_location_;
700 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
703 class FragmentShaderColorAA {
704 public:
705 FragmentShaderColorAA();
706 std::string GetShaderString(TexCoordPrecision precision) const;
708 void Init(WebKit::WebGraphicsContext3D* context,
709 unsigned program,
710 bool using_bind_uniform,
711 int* base_uniform_index);
712 int color_location() const { return color_location_; }
714 private:
715 int color_location_;
717 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA);
720 class FragmentShaderCheckerboard {
721 public:
722 FragmentShaderCheckerboard();
723 std::string GetShaderString(TexCoordPrecision precision) const;
725 void Init(WebKit::WebGraphicsContext3D* context,
726 unsigned program,
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_; }
734 private:
735 int alpha_location_;
736 int tex_transform_location_;
737 int frequency_location_;
738 int color_location_;
740 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard);
743 } // namespace cc
745 #endif // CC_OUTPUT_SHADER_H_