IndexedDB: fsync after transactions.
[chromium-blink-merge.git] / cc / output / shader.h
blob9473ce8da382ab840ad7b3ce414f881bbc5a3afe
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 gpu {
20 namespace gles2 {
21 class GLES2Interface;
25 namespace cc {
27 enum TexCoordPrecision {
28 TexCoordPrecisionNA = 0,
29 TexCoordPrecisionMedium = 1,
30 TexCoordPrecisionHigh = 2,
31 NumTexCoordPrecisions = 3
34 enum SamplerType {
35 SamplerTypeNA = 0,
36 SamplerType2D = 1,
37 SamplerType2DRect = 2,
38 SamplerTypeExternalOES = 3,
39 NumSamplerTypes = 4
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,
56 gfx::Size max_size);
58 class VertexShaderPosTex {
59 public:
60 VertexShaderPosTex();
62 void Init(gpu::gles2::GLES2Interface* context,
63 unsigned program,
64 int* base_uniform_index);
65 std::string GetShaderString() const;
67 int matrix_location() const { return matrix_location_; }
69 private:
70 int matrix_location_;
72 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex);
75 class VertexShaderPosTexYUVStretch {
76 public:
77 VertexShaderPosTexYUVStretch();
79 void Init(gpu::gles2::GLES2Interface* context,
80 unsigned program,
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_; }
87 private:
88 int matrix_location_;
89 int tex_scale_location_;
91 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretch);
94 class VertexShaderPos {
95 public:
96 VertexShaderPos();
98 void Init(gpu::gles2::GLES2Interface* context,
99 unsigned program,
100 int* base_uniform_index);
101 std::string GetShaderString() const;
103 int matrix_location() const { return matrix_location_; }
105 private:
106 int matrix_location_;
108 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos);
111 class VertexShaderPosTexIdentity {
112 public:
113 void Init(gpu::gles2::GLES2Interface* context,
114 unsigned program,
115 int* base_uniform_index) {}
116 std::string GetShaderString() const;
119 class VertexShaderPosTexTransform {
120 public:
121 VertexShaderPosTexTransform();
123 void Init(gpu::gles2::GLES2Interface* context,
124 unsigned program,
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_; }
132 private:
133 int matrix_location_;
134 int tex_transform_location_;
135 int vertex_opacity_location_;
137 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform);
140 class VertexShaderQuad {
141 public:
142 VertexShaderQuad();
144 void Init(gpu::gles2::GLES2Interface* context,
145 unsigned program,
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; }
154 private:
155 int matrix_location_;
156 int quad_location_;
158 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
161 class VertexShaderQuadAA {
162 public:
163 VertexShaderQuadAA();
165 void Init(gpu::gles2::GLES2Interface* context,
166 unsigned program,
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_; }
175 private:
176 int matrix_location_;
177 int viewport_location_;
178 int quad_location_;
179 int edge_location_;
181 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA);
185 class VertexShaderQuadTexTransformAA {
186 public:
187 VertexShaderQuadTexTransformAA();
189 void Init(gpu::gles2::GLES2Interface* context,
190 unsigned program,
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_; }
200 private:
201 int matrix_location_;
202 int viewport_location_;
203 int quad_location_;
204 int edge_location_;
205 int tex_transform_location_;
207 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA);
210 class VertexShaderTile {
211 public:
212 VertexShaderTile();
214 void Init(gpu::gles2::GLES2Interface* context,
215 unsigned program,
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_;
227 private:
228 int matrix_location_;
229 int quad_location_;
230 int vertex_tex_transform_location_;
232 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);
235 class VertexShaderTileAA {
236 public:
237 VertexShaderTileAA();
239 void Init(gpu::gles2::GLES2Interface* context,
240 unsigned program,
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_;
252 private:
253 int matrix_location_;
254 int viewport_location_;
255 int quad_location_;
256 int edge_location_;
257 int vertex_tex_transform_location_;
259 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA);
262 class VertexShaderVideoTransform {
263 public:
264 VertexShaderVideoTransform();
266 void Init(gpu::gles2::GLES2Interface* context,
267 unsigned program,
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_; }
274 private:
275 int matrix_location_;
276 int tex_matrix_location_;
278 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform);
281 class FragmentTexAlphaBinding {
282 public:
283 FragmentTexAlphaBinding();
285 void Init(gpu::gles2::GLES2Interface* context,
286 unsigned program,
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_; }
292 private:
293 int sampler_location_;
294 int alpha_location_;
296 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
299 class FragmentTexColorMatrixAlphaBinding {
300 public:
301 FragmentTexColorMatrixAlphaBinding();
303 void Init(gpu::gles2::GLES2Interface* context,
304 unsigned program,
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_; }
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(gpu::gles2::GLES2Interface* context,
324 unsigned program,
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_; }
331 private:
332 int sampler_location_;
334 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
337 class FragmentTexBackgroundBinding {
338 public:
339 FragmentTexBackgroundBinding();
341 void Init(gpu::gles2::GLES2Interface* context,
342 unsigned program,
343 int* base_uniform_index);
344 int background_color_location() const { return background_color_location_; }
345 int sampler_location() const { return sampler_location_; }
347 private:
348 int background_color_location_;
349 int sampler_location_;
351 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
354 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
355 public:
356 std::string GetShaderString(
357 TexCoordPrecision precision, SamplerType sampler) const;
360 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
361 public:
362 std::string GetShaderString(
363 TexCoordPrecision precision, SamplerType sampler) const;
366 class FragmentShaderTexBackgroundVaryingAlpha
367 : public FragmentTexBackgroundBinding {
368 public:
369 std::string GetShaderString(
370 TexCoordPrecision precision, SamplerType sampler) const;
373 class FragmentShaderTexBackgroundPremultiplyAlpha
374 : public FragmentTexBackgroundBinding {
375 public:
376 std::string GetShaderString(
377 TexCoordPrecision precision, SamplerType sampler) const;
380 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
381 public:
382 std::string GetShaderString(
383 TexCoordPrecision precision, SamplerType sampler) const;
386 class FragmentShaderRGBATexColorMatrixAlpha
387 : public FragmentTexColorMatrixAlphaBinding {
388 public:
389 std::string GetShaderString(
390 TexCoordPrecision precision, SamplerType sampler) const;
393 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
394 public:
395 std::string GetShaderString(
396 TexCoordPrecision precision, SamplerType sampler) const;
399 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
400 public:
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 {
407 public:
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 {
414 public:
415 std::string GetShaderString(
416 TexCoordPrecision precision, SamplerType sampler) const;
419 class FragmentShaderRGBATexAlphaAA {
420 public:
421 FragmentShaderRGBATexAlphaAA();
423 void Init(gpu::gles2::GLES2Interface* context,
424 unsigned program,
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_; }
432 private:
433 int sampler_location_;
434 int alpha_location_;
436 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
439 class FragmentTexClampAlphaAABinding {
440 public:
441 FragmentTexClampAlphaAABinding();
443 void Init(gpu::gles2::GLES2Interface* context,
444 unsigned program,
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_;
452 private:
453 int sampler_location_;
454 int alpha_location_;
455 int fragment_tex_transform_location_;
457 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
460 class FragmentShaderRGBATexClampAlphaAA
461 : public FragmentTexClampAlphaAABinding {
462 public:
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 {
470 public:
471 std::string GetShaderString(
472 TexCoordPrecision precision, SamplerType sampler) const;
475 class FragmentShaderRGBATexAlphaMask {
476 public:
477 FragmentShaderRGBATexAlphaMask();
478 std::string GetShaderString(
479 TexCoordPrecision precision, SamplerType sampler) const;
481 void Init(gpu::gles2::GLES2Interface* context,
482 unsigned program,
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_;
494 private:
495 int sampler_location_;
496 int mask_sampler_location_;
497 int alpha_location_;
498 int mask_tex_coord_scale_location_;
499 int mask_tex_coord_offset_location_;
501 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
504 class FragmentShaderRGBATexAlphaMaskAA {
505 public:
506 FragmentShaderRGBATexAlphaMaskAA();
507 std::string GetShaderString(
508 TexCoordPrecision precision, SamplerType sampler) const;
510 void Init(gpu::gles2::GLES2Interface* context,
511 unsigned program,
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_;
523 private:
524 int sampler_location_;
525 int mask_sampler_location_;
526 int alpha_location_;
527 int mask_tex_coord_scale_location_;
528 int mask_tex_coord_offset_location_;
530 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
533 class FragmentShaderRGBATexAlphaMaskColorMatrixAA {
534 public:
535 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
536 std::string GetShaderString(
537 TexCoordPrecision precision, SamplerType sampler) const;
539 void Init(gpu::gles2::GLES2Interface* context,
540 unsigned program,
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_; }
554 private:
555 int sampler_location_;
556 int mask_sampler_location_;
557 int alpha_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 {
565 public:
566 FragmentShaderRGBATexAlphaColorMatrixAA();
567 std::string GetShaderString(
568 TexCoordPrecision precision, SamplerType sampler) const;
570 void Init(gpu::gles2::GLES2Interface* context,
571 unsigned program,
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_; }
578 private:
579 int sampler_location_;
580 int alpha_location_;
581 int color_matrix_location_;
582 int color_offset_location_;
585 class FragmentShaderRGBATexAlphaMaskColorMatrix {
586 public:
587 FragmentShaderRGBATexAlphaMaskColorMatrix();
588 std::string GetShaderString(
589 TexCoordPrecision precision, SamplerType sampler) const;
591 void Init(gpu::gles2::GLES2Interface* context,
592 unsigned program,
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_; }
606 private:
607 int sampler_location_;
608 int mask_sampler_location_;
609 int alpha_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 {
617 public:
618 FragmentShaderYUVVideo();
619 std::string GetShaderString(
620 TexCoordPrecision precision, SamplerType sampler) const;
622 void Init(gpu::gles2::GLES2Interface* context,
623 unsigned program,
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_; }
632 private:
633 int y_texture_location_;
634 int u_texture_location_;
635 int v_texture_location_;
636 int alpha_location_;
637 int yuv_matrix_location_;
638 int yuv_adj_location_;
640 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
644 class FragmentShaderYUVAVideo {
645 public:
646 FragmentShaderYUVAVideo();
647 std::string GetShaderString(
648 TexCoordPrecision precision, SamplerType sampler) const;
650 void Init(gpu::gles2::GLES2Interface* context,
651 unsigned program,
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_; }
662 private:
663 int y_texture_location_;
664 int u_texture_location_;
665 int v_texture_location_;
666 int a_texture_location_;
667 int alpha_location_;
668 int yuv_matrix_location_;
669 int yuv_adj_location_;
671 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo);
674 class FragmentShaderColor {
675 public:
676 FragmentShaderColor();
677 std::string GetShaderString(
678 TexCoordPrecision precision, SamplerType sampler) const;
680 void Init(gpu::gles2::GLES2Interface* context,
681 unsigned program,
682 int* base_uniform_index);
683 int color_location() const { return color_location_; }
685 private:
686 int color_location_;
688 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
691 class FragmentShaderColorAA {
692 public:
693 FragmentShaderColorAA();
694 std::string GetShaderString(
695 TexCoordPrecision precision, SamplerType sampler) const;
697 void Init(gpu::gles2::GLES2Interface* context,
698 unsigned program,
699 int* base_uniform_index);
700 int color_location() const { return color_location_; }
702 private:
703 int color_location_;
705 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA);
708 class FragmentShaderCheckerboard {
709 public:
710 FragmentShaderCheckerboard();
711 std::string GetShaderString(
712 TexCoordPrecision precision, SamplerType sampler) const;
714 void Init(gpu::gles2::GLES2Interface* context,
715 unsigned program,
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_; }
722 private:
723 int alpha_location_;
724 int tex_transform_location_;
725 int frequency_location_;
726 int color_location_;
728 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard);
731 } // namespace cc
733 #endif // CC_OUTPUT_SHADER_H_