Reland 1: "mac: Allow Chrome to hand off its active URL to other devices."
[chromium-blink-merge.git] / cc / output / shader.h
blob8c1f2647946906b1a87ce00618b3ba3384c020ca
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 enum BlendMode {
42 BlendModeNone,
43 BlendModeNormal,
44 BlendModeScreen,
45 BlendModeOverlay,
46 BlendModeDarken,
47 BlendModeLighten,
48 BlendModeColorDodge,
49 BlendModeColorBurn,
50 BlendModeHardLight,
51 BlendModeSoftLight,
52 BlendModeDifference,
53 BlendModeExclusion,
54 BlendModeMultiply,
55 BlendModeHue,
56 BlendModeSaturation,
57 BlendModeColor,
58 BlendModeLuminosity,
59 NumBlendModes
62 // Note: The highp_threshold_cache must be provided by the caller to make
63 // the caching multi-thread/context safe in an easy low-overhead manner.
64 // The caller must make sure to clear highp_threshold_cache to 0, so it can be
65 // reinitialized, if a new or different context is used.
66 CC_EXPORT TexCoordPrecision
67 TexCoordPrecisionRequired(gpu::gles2::GLES2Interface* context,
68 int* highp_threshold_cache,
69 int highp_threshold_min,
70 const gfx::Point& max_coordinate);
72 CC_EXPORT TexCoordPrecision TexCoordPrecisionRequired(
73 gpu::gles2::GLES2Interface* context,
74 int *highp_threshold_cache,
75 int highp_threshold_min,
76 const gfx::Size& max_size);
78 class VertexShaderPosTex {
79 public:
80 VertexShaderPosTex();
82 void Init(gpu::gles2::GLES2Interface* context,
83 unsigned program,
84 int* base_uniform_index);
85 std::string GetShaderString() const;
87 int matrix_location() const { return matrix_location_; }
89 private:
90 int matrix_location_;
92 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTex);
95 class VertexShaderPosTexYUVStretchOffset {
96 public:
97 VertexShaderPosTexYUVStretchOffset();
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_; }
105 int tex_scale_location() const { return tex_scale_location_; }
106 int tex_offset_location() const { return tex_offset_location_; }
108 private:
109 int matrix_location_;
110 int tex_scale_location_;
111 int tex_offset_location_;
113 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexYUVStretchOffset);
116 class VertexShaderPos {
117 public:
118 VertexShaderPos();
120 void Init(gpu::gles2::GLES2Interface* context,
121 unsigned program,
122 int* base_uniform_index);
123 std::string GetShaderString() const;
125 int matrix_location() const { return matrix_location_; }
127 private:
128 int matrix_location_;
130 DISALLOW_COPY_AND_ASSIGN(VertexShaderPos);
133 class VertexShaderPosTexIdentity {
134 public:
135 void Init(gpu::gles2::GLES2Interface* context,
136 unsigned program,
137 int* base_uniform_index) {}
138 std::string GetShaderString() const;
141 class VertexShaderPosTexTransform {
142 public:
143 VertexShaderPosTexTransform();
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 tex_transform_location() const { return tex_transform_location_; }
152 int vertex_opacity_location() const { return vertex_opacity_location_; }
154 private:
155 int matrix_location_;
156 int tex_transform_location_;
157 int vertex_opacity_location_;
159 DISALLOW_COPY_AND_ASSIGN(VertexShaderPosTexTransform);
162 class VertexShaderQuad {
163 public:
164 VertexShaderQuad();
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 -1; }
173 int quad_location() const { return quad_location_; }
174 int edge_location() const { return -1; }
176 private:
177 int matrix_location_;
178 int quad_location_;
180 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
183 class VertexShaderQuadAA {
184 public:
185 VertexShaderQuadAA();
187 void Init(gpu::gles2::GLES2Interface* context,
188 unsigned program,
189 int* base_uniform_index);
190 std::string GetShaderString() const;
192 int matrix_location() const { return matrix_location_; }
193 int viewport_location() const { return viewport_location_; }
194 int quad_location() const { return quad_location_; }
195 int edge_location() const { return edge_location_; }
197 private:
198 int matrix_location_;
199 int viewport_location_;
200 int quad_location_;
201 int edge_location_;
203 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadAA);
207 class VertexShaderQuadTexTransformAA {
208 public:
209 VertexShaderQuadTexTransformAA();
211 void Init(gpu::gles2::GLES2Interface* context,
212 unsigned program,
213 int* base_uniform_index);
214 std::string GetShaderString() const;
216 int matrix_location() const { return matrix_location_; }
217 int viewport_location() const { return viewport_location_; }
218 int quad_location() const { return quad_location_; }
219 int edge_location() const { return edge_location_; }
220 int tex_transform_location() const { return tex_transform_location_; }
222 private:
223 int matrix_location_;
224 int viewport_location_;
225 int quad_location_;
226 int edge_location_;
227 int tex_transform_location_;
229 DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTexTransformAA);
232 class VertexShaderTile {
233 public:
234 VertexShaderTile();
236 void Init(gpu::gles2::GLES2Interface* context,
237 unsigned program,
238 int* base_uniform_index);
239 std::string GetShaderString() const;
241 int matrix_location() const { return matrix_location_; }
242 int viewport_location() const { return -1; }
243 int quad_location() const { return quad_location_; }
244 int edge_location() const { return -1; }
245 int vertex_tex_transform_location() const {
246 return vertex_tex_transform_location_;
249 private:
250 int matrix_location_;
251 int quad_location_;
252 int vertex_tex_transform_location_;
254 DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);
257 class VertexShaderTileAA {
258 public:
259 VertexShaderTileAA();
261 void Init(gpu::gles2::GLES2Interface* context,
262 unsigned program,
263 int* base_uniform_index);
264 std::string GetShaderString() const;
266 int matrix_location() const { return matrix_location_; }
267 int viewport_location() const { return viewport_location_; }
268 int quad_location() const { return quad_location_; }
269 int edge_location() const { return edge_location_; }
270 int vertex_tex_transform_location() const {
271 return vertex_tex_transform_location_;
274 private:
275 int matrix_location_;
276 int viewport_location_;
277 int quad_location_;
278 int edge_location_;
279 int vertex_tex_transform_location_;
281 DISALLOW_COPY_AND_ASSIGN(VertexShaderTileAA);
284 class VertexShaderVideoTransform {
285 public:
286 VertexShaderVideoTransform();
288 void Init(gpu::gles2::GLES2Interface* context,
289 unsigned program,
290 int* base_uniform_index);
291 std::string GetShaderString() const;
293 int matrix_location() const { return matrix_location_; }
294 int tex_matrix_location() const { return tex_matrix_location_; }
296 private:
297 int matrix_location_;
298 int tex_matrix_location_;
300 DISALLOW_COPY_AND_ASSIGN(VertexShaderVideoTransform);
303 class FragmentTexBlendMode {
304 public:
305 int backdrop_location() const { return backdrop_location_; }
306 int backdrop_rect_location() const { return backdrop_rect_location_; }
308 BlendMode blend_mode() const { return blend_mode_; }
309 void set_blend_mode(BlendMode blend_mode) { blend_mode_ = blend_mode; }
310 bool has_blend_mode() const { return blend_mode_ != BlendModeNone; }
312 protected:
313 FragmentTexBlendMode();
315 std::string SetBlendModeFunctions(std::string shader_string) const;
317 int backdrop_location_;
318 int backdrop_rect_location_;
320 private:
321 BlendMode blend_mode_;
323 std::string GetHelperFunctions() const;
324 std::string GetBlendFunction() const;
325 std::string GetBlendFunctionBodyForRGB() const;
328 class FragmentTexAlphaBinding : public FragmentTexBlendMode {
329 public:
330 FragmentTexAlphaBinding();
332 void Init(gpu::gles2::GLES2Interface* context,
333 unsigned program,
334 int* base_uniform_index);
335 int alpha_location() const { return alpha_location_; }
336 int fragment_tex_transform_location() const { return -1; }
337 int sampler_location() const { return sampler_location_; }
339 private:
340 int sampler_location_;
341 int alpha_location_;
343 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
346 class FragmentTexColorMatrixAlphaBinding : public FragmentTexBlendMode {
347 public:
348 FragmentTexColorMatrixAlphaBinding();
350 void Init(gpu::gles2::GLES2Interface* context,
351 unsigned program,
352 int* base_uniform_index);
353 int alpha_location() const { return alpha_location_; }
354 int color_matrix_location() const { return color_matrix_location_; }
355 int color_offset_location() const { return color_offset_location_; }
356 int fragment_tex_transform_location() const { return -1; }
357 int sampler_location() const { return sampler_location_; }
359 private:
360 int sampler_location_;
361 int alpha_location_;
362 int color_matrix_location_;
363 int color_offset_location_;
366 class FragmentTexOpaqueBinding : public FragmentTexBlendMode {
367 public:
368 FragmentTexOpaqueBinding();
370 void Init(gpu::gles2::GLES2Interface* context,
371 unsigned program,
372 int* base_uniform_index);
373 int alpha_location() const { return -1; }
374 int fragment_tex_transform_location() const { return -1; }
375 int background_color_location() const { return -1; }
376 int sampler_location() const { return sampler_location_; }
378 private:
379 int sampler_location_;
381 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
384 class FragmentTexBackgroundBinding : public FragmentTexBlendMode {
385 public:
386 FragmentTexBackgroundBinding();
388 void Init(gpu::gles2::GLES2Interface* context,
389 unsigned program,
390 int* base_uniform_index);
391 int background_color_location() const { return background_color_location_; }
392 int sampler_location() const { return sampler_location_; }
394 private:
395 int background_color_location_;
396 int sampler_location_;
398 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
401 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
402 public:
403 std::string GetShaderString(
404 TexCoordPrecision precision, SamplerType sampler) const;
407 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
408 public:
409 std::string GetShaderString(
410 TexCoordPrecision precision, SamplerType sampler) const;
413 class FragmentShaderTexBackgroundVaryingAlpha
414 : public FragmentTexBackgroundBinding {
415 public:
416 std::string GetShaderString(
417 TexCoordPrecision precision, SamplerType sampler) const;
420 class FragmentShaderTexBackgroundPremultiplyAlpha
421 : public FragmentTexBackgroundBinding {
422 public:
423 std::string GetShaderString(
424 TexCoordPrecision precision, SamplerType sampler) const;
427 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
428 public:
429 std::string GetShaderString(
430 TexCoordPrecision precision, SamplerType sampler) const;
433 class FragmentShaderRGBATexColorMatrixAlpha
434 : public FragmentTexColorMatrixAlphaBinding {
435 public:
436 std::string GetShaderString(
437 TexCoordPrecision precision, SamplerType sampler) const;
440 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
441 public:
442 std::string GetShaderString(
443 TexCoordPrecision precision, SamplerType sampler) const;
446 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
447 public:
448 std::string GetShaderString(
449 TexCoordPrecision precision, SamplerType sampler) const;
452 // Swizzles the red and blue component of sampled texel with alpha.
453 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding {
454 public:
455 std::string GetShaderString(
456 TexCoordPrecision precision, SamplerType sampler) const;
459 // Swizzles the red and blue component of sampled texel without alpha.
460 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding {
461 public:
462 std::string GetShaderString(
463 TexCoordPrecision precision, SamplerType sampler) const;
466 class FragmentShaderRGBATexAlphaAA : public FragmentTexBlendMode {
467 public:
468 FragmentShaderRGBATexAlphaAA();
470 void Init(gpu::gles2::GLES2Interface* context,
471 unsigned program,
472 int* base_uniform_index);
473 std::string GetShaderString(
474 TexCoordPrecision precision, SamplerType sampler) const;
476 int alpha_location() const { return alpha_location_; }
477 int sampler_location() const { return sampler_location_; }
479 private:
480 int sampler_location_;
481 int alpha_location_;
483 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
486 class FragmentTexClampAlphaAABinding : public FragmentTexBlendMode {
487 public:
488 FragmentTexClampAlphaAABinding();
490 void Init(gpu::gles2::GLES2Interface* context,
491 unsigned program,
492 int* base_uniform_index);
493 int alpha_location() const { return alpha_location_; }
494 int sampler_location() const { return sampler_location_; }
495 int fragment_tex_transform_location() const {
496 return fragment_tex_transform_location_;
499 private:
500 int sampler_location_;
501 int alpha_location_;
502 int fragment_tex_transform_location_;
504 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
507 class FragmentShaderRGBATexClampAlphaAA
508 : public FragmentTexClampAlphaAABinding {
509 public:
510 std::string GetShaderString(
511 TexCoordPrecision precision, SamplerType sampler) const;
514 // Swizzles the red and blue component of sampled texel.
515 class FragmentShaderRGBATexClampSwizzleAlphaAA
516 : public FragmentTexClampAlphaAABinding {
517 public:
518 std::string GetShaderString(
519 TexCoordPrecision precision, SamplerType sampler) const;
522 class FragmentShaderRGBATexAlphaMask : public FragmentTexBlendMode {
523 public:
524 FragmentShaderRGBATexAlphaMask();
525 std::string GetShaderString(
526 TexCoordPrecision precision, SamplerType sampler) const;
528 void Init(gpu::gles2::GLES2Interface* context,
529 unsigned program,
530 int* base_uniform_index);
531 int alpha_location() const { return alpha_location_; }
532 int sampler_location() const { return sampler_location_; }
533 int mask_sampler_location() const { return mask_sampler_location_; }
534 int mask_tex_coord_scale_location() const {
535 return mask_tex_coord_scale_location_;
537 int mask_tex_coord_offset_location() const {
538 return mask_tex_coord_offset_location_;
541 private:
542 int sampler_location_;
543 int mask_sampler_location_;
544 int alpha_location_;
545 int mask_tex_coord_scale_location_;
546 int mask_tex_coord_offset_location_;
548 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
551 class FragmentShaderRGBATexAlphaMaskAA : public FragmentTexBlendMode {
552 public:
553 FragmentShaderRGBATexAlphaMaskAA();
554 std::string GetShaderString(
555 TexCoordPrecision precision, SamplerType sampler) const;
557 void Init(gpu::gles2::GLES2Interface* context,
558 unsigned program,
559 int* base_uniform_index);
560 int alpha_location() const { return alpha_location_; }
561 int sampler_location() const { return sampler_location_; }
562 int mask_sampler_location() const { return mask_sampler_location_; }
563 int mask_tex_coord_scale_location() const {
564 return mask_tex_coord_scale_location_;
566 int mask_tex_coord_offset_location() const {
567 return mask_tex_coord_offset_location_;
570 private:
571 int sampler_location_;
572 int mask_sampler_location_;
573 int alpha_location_;
574 int mask_tex_coord_scale_location_;
575 int mask_tex_coord_offset_location_;
577 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
580 class FragmentShaderRGBATexAlphaMaskColorMatrixAA
581 : public FragmentTexBlendMode {
582 public:
583 FragmentShaderRGBATexAlphaMaskColorMatrixAA();
584 std::string GetShaderString(
585 TexCoordPrecision precision, SamplerType sampler) const;
587 void Init(gpu::gles2::GLES2Interface* context,
588 unsigned program,
589 int* base_uniform_index);
590 int alpha_location() const { return alpha_location_; }
591 int sampler_location() const { return sampler_location_; }
592 int mask_sampler_location() const { return mask_sampler_location_; }
593 int mask_tex_coord_scale_location() const {
594 return mask_tex_coord_scale_location_;
596 int mask_tex_coord_offset_location() const {
597 return mask_tex_coord_offset_location_;
599 int color_matrix_location() const { return color_matrix_location_; }
600 int color_offset_location() const { return color_offset_location_; }
602 private:
603 int sampler_location_;
604 int mask_sampler_location_;
605 int alpha_location_;
606 int mask_tex_coord_scale_location_;
607 int mask_tex_coord_offset_location_;
608 int color_matrix_location_;
609 int color_offset_location_;
612 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentTexBlendMode {
613 public:
614 FragmentShaderRGBATexAlphaColorMatrixAA();
615 std::string GetShaderString(
616 TexCoordPrecision precision, SamplerType sampler) const;
618 void Init(gpu::gles2::GLES2Interface* context,
619 unsigned program,
620 int* base_uniform_index);
621 int alpha_location() const { return alpha_location_; }
622 int sampler_location() const { return sampler_location_; }
623 int color_matrix_location() const { return color_matrix_location_; }
624 int color_offset_location() const { return color_offset_location_; }
626 private:
627 int sampler_location_;
628 int alpha_location_;
629 int color_matrix_location_;
630 int color_offset_location_;
633 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentTexBlendMode {
634 public:
635 FragmentShaderRGBATexAlphaMaskColorMatrix();
636 std::string GetShaderString(
637 TexCoordPrecision precision, SamplerType sampler) const;
639 void Init(gpu::gles2::GLES2Interface* context,
640 unsigned program,
641 int* base_uniform_index);
642 int alpha_location() const { return alpha_location_; }
643 int sampler_location() const { return sampler_location_; }
644 int mask_sampler_location() const { return mask_sampler_location_; }
645 int mask_tex_coord_scale_location() const {
646 return mask_tex_coord_scale_location_;
648 int mask_tex_coord_offset_location() const {
649 return mask_tex_coord_offset_location_;
651 int color_matrix_location() const { return color_matrix_location_; }
652 int color_offset_location() const { return color_offset_location_; }
654 private:
655 int sampler_location_;
656 int mask_sampler_location_;
657 int alpha_location_;
658 int mask_tex_coord_scale_location_;
659 int mask_tex_coord_offset_location_;
660 int color_matrix_location_;
661 int color_offset_location_;
664 class FragmentShaderYUVVideo : public FragmentTexBlendMode {
665 public:
666 FragmentShaderYUVVideo();
667 std::string GetShaderString(
668 TexCoordPrecision precision, SamplerType sampler) const;
670 void Init(gpu::gles2::GLES2Interface* context,
671 unsigned program,
672 int* base_uniform_index);
673 int y_texture_location() const { return y_texture_location_; }
674 int u_texture_location() const { return u_texture_location_; }
675 int v_texture_location() const { return v_texture_location_; }
676 int alpha_location() const { return alpha_location_; }
677 int yuv_matrix_location() const { return yuv_matrix_location_; }
678 int yuv_adj_location() const { return yuv_adj_location_; }
680 private:
681 int y_texture_location_;
682 int u_texture_location_;
683 int v_texture_location_;
684 int alpha_location_;
685 int yuv_matrix_location_;
686 int yuv_adj_location_;
688 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
691 class FragmentShaderYUVAVideo : public FragmentTexBlendMode {
692 public:
693 FragmentShaderYUVAVideo();
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);
701 int y_texture_location() const { return y_texture_location_; }
702 int u_texture_location() const { return u_texture_location_; }
703 int v_texture_location() const { return v_texture_location_; }
704 int a_texture_location() const { return a_texture_location_; }
705 int alpha_location() const { return alpha_location_; }
706 int yuv_matrix_location() const { return yuv_matrix_location_; }
707 int yuv_adj_location() const { return yuv_adj_location_; }
709 private:
710 int y_texture_location_;
711 int u_texture_location_;
712 int v_texture_location_;
713 int a_texture_location_;
714 int alpha_location_;
715 int yuv_matrix_location_;
716 int yuv_adj_location_;
718 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVAVideo);
721 class FragmentShaderColor : public FragmentTexBlendMode {
722 public:
723 FragmentShaderColor();
724 std::string GetShaderString(
725 TexCoordPrecision precision, SamplerType sampler) const;
727 void Init(gpu::gles2::GLES2Interface* context,
728 unsigned program,
729 int* base_uniform_index);
730 int color_location() const { return color_location_; }
732 private:
733 int color_location_;
735 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
738 class FragmentShaderColorAA : public FragmentTexBlendMode {
739 public:
740 FragmentShaderColorAA();
741 std::string GetShaderString(
742 TexCoordPrecision precision, SamplerType sampler) const;
744 void Init(gpu::gles2::GLES2Interface* context,
745 unsigned program,
746 int* base_uniform_index);
747 int color_location() const { return color_location_; }
749 private:
750 int color_location_;
752 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA);
755 class FragmentShaderCheckerboard : public FragmentTexBlendMode {
756 public:
757 FragmentShaderCheckerboard();
758 std::string GetShaderString(
759 TexCoordPrecision precision, SamplerType sampler) const;
761 void Init(gpu::gles2::GLES2Interface* context,
762 unsigned program,
763 int* base_uniform_index);
764 int alpha_location() const { return alpha_location_; }
765 int tex_transform_location() const { return tex_transform_location_; }
766 int frequency_location() const { return frequency_location_; }
767 int color_location() const { return color_location_; }
769 private:
770 int alpha_location_;
771 int tex_transform_location_;
772 int frequency_location_;
773 int color_location_;
775 DISALLOW_COPY_AND_ASSIGN(FragmentShaderCheckerboard);
778 } // namespace cc
780 #endif // CC_OUTPUT_SHADER_H_