Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: cc/output/shader.h

Issue 2608863002: The great shader refactor: Merge fragment shaders into an uber-shader (Closed)
Patch Set: Better variable name Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/output/shader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OUTPUT_SHADER_H_ 5 #ifndef CC_OUTPUT_SHADER_H_
6 #define CC_OUTPUT_SHADER_H_ 6 #define CC_OUTPUT_SHADER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 BLEND_MODE_DIFFERENCE, 52 BLEND_MODE_DIFFERENCE,
53 BLEND_MODE_EXCLUSION, 53 BLEND_MODE_EXCLUSION,
54 BLEND_MODE_MULTIPLY, 54 BLEND_MODE_MULTIPLY,
55 BLEND_MODE_HUE, 55 BLEND_MODE_HUE,
56 BLEND_MODE_SATURATION, 56 BLEND_MODE_SATURATION,
57 BLEND_MODE_COLOR, 57 BLEND_MODE_COLOR,
58 BLEND_MODE_LUMINOSITY, 58 BLEND_MODE_LUMINOSITY,
59 LAST_BLEND_MODE = BLEND_MODE_LUMINOSITY 59 LAST_BLEND_MODE = BLEND_MODE_LUMINOSITY
60 }; 60 };
61 61
62 enum InputColorSource {
63 INPUT_COLOR_SOURCE_RGBA_TEXTURE,
64 INPUT_COLOR_SOURCE_UNIFORM,
65 };
66
67 // TODO(ccameron): Merge this with BlendMode.
68 enum FragColorMode {
69 FRAG_COLOR_MODE_DEFAULT,
70 FRAG_COLOR_MODE_OPAQUE,
71 FRAG_COLOR_MODE_APPLY_BLEND_MODE,
72 };
73
62 enum MaskMode { 74 enum MaskMode {
63 NO_MASK = 0, 75 NO_MASK = 0,
64 HAS_MASK = 1, 76 HAS_MASK = 1,
65 LAST_MASK_VALUE = HAS_MASK 77 LAST_MASK_VALUE = HAS_MASK
66 }; 78 };
67 79
68 struct ShaderLocations { 80 struct ShaderLocations {
69 ShaderLocations(); 81 ShaderLocations();
70 82
71 int sampler = -1; 83 int sampler = -1;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 int sampler_location() const { return sampler_location_; } 386 int sampler_location() const { return sampler_location_; }
375 int alpha_location() const { return alpha_location_; } 387 int alpha_location() const { return alpha_location_; }
376 int color_location() const { return color_location_; } 388 int color_location() const { return color_location_; }
377 int background_color_location() const { return background_color_location_; } 389 int background_color_location() const { return background_color_location_; }
378 int fragment_tex_transform_location() const { 390 int fragment_tex_transform_location() const {
379 return fragment_tex_transform_location_; 391 return fragment_tex_transform_location_;
380 } 392 }
381 393
382 protected: 394 protected:
383 FragmentShaderBase(); 395 FragmentShaderBase();
384 virtual std::string GetShaderSource() const = 0; 396 virtual std::string GetShaderSource() const;
385 397
386 std::string SetBlendModeFunctions(const std::string& shader_string) const; 398 std::string SetBlendModeFunctions(const std::string& shader_string) const;
387 399
400 // Settings that are modified by sub-classes.
401 bool has_aa_ = false;
402 bool has_varying_alpha_ = false;
403 bool has_swizzle_ = false;
404 bool has_premultiply_alpha_ = false;
405 FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
406 InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE;
407
388 // Used only if |blend_mode_| is not BLEND_MODE_NONE. 408 // Used only if |blend_mode_| is not BLEND_MODE_NONE.
389 int backdrop_location_ = -1; 409 int backdrop_location_ = -1;
390 int original_backdrop_location_ = -1; 410 int original_backdrop_location_ = -1;
391 int backdrop_rect_location_ = -1; 411 int backdrop_rect_location_ = -1;
392 412
413 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_RGBA_TEXTURE.
414 bool has_rgba_fragment_tex_transform_ = false;
415 int sampler_location_ = -1;
416 int fragment_tex_transform_location_ = -1;
417
418 // Always use sampler2D and texture2D for the RGBA texture, regardless of the
419 // specified SamplerType.
420 // TODO(ccameron): Change GLRenderer to always specify the correct
421 // SamplerType.
422 bool ignore_sampler_type_ = false;
423
424 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM.
425 int color_location_ = -1;
426
393 bool has_mask_sampler_ = false; 427 bool has_mask_sampler_ = false;
394 int mask_sampler_location_ = -1; 428 int mask_sampler_location_ = -1;
395 int mask_tex_coord_scale_location_ = -1; 429 int mask_tex_coord_scale_location_ = -1;
396 int mask_tex_coord_offset_location_ = -1; 430 int mask_tex_coord_offset_location_ = -1;
397 431
398 bool has_color_matrix_ = false; 432 bool has_color_matrix_ = false;
399 int color_matrix_location_ = -1; 433 int color_matrix_location_ = -1;
400 int color_offset_location_ = -1; 434 int color_offset_location_ = -1;
401 435
402 bool has_sampler_ = false;
403 int sampler_location_ = -1;
404
405 bool has_uniform_alpha_ = false; 436 bool has_uniform_alpha_ = false;
406 int alpha_location_ = -1; 437 int alpha_location_ = -1;
407 438
408 bool has_background_color_ = false; 439 bool has_background_color_ = false;
409 int background_color_location_ = -1; 440 int background_color_location_ = -1;
410 441
411 bool has_fragment_tex_transform_ = false;
412 int fragment_tex_transform_location_ = -1;
413
414 bool has_uniform_color_ = false;
415 int color_location_ = -1;
416
417 private: 442 private:
418 BlendMode blend_mode_ = BLEND_MODE_NONE; 443 BlendMode blend_mode_ = BLEND_MODE_NONE;
419 bool mask_for_background_ = false; 444 bool mask_for_background_ = false;
420 445
421 std::string GetHelperFunctions() const; 446 std::string GetHelperFunctions() const;
422 std::string GetBlendFunction() const; 447 std::string GetBlendFunction() const;
423 std::string GetBlendFunctionBodyForRGB() const; 448 std::string GetBlendFunctionBodyForRGB() const;
449
450 DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase);
424 }; 451 };
425 452
426 class FragmentTexAlphaBinding : public FragmentShaderBase { 453 class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
427 public: 454 public:
428 FragmentTexAlphaBinding() { 455 FragmentShaderRGBATexVaryingAlpha() {
429 has_sampler_ = true; 456 has_varying_alpha_ = true;
430 has_uniform_alpha_ = true; 457 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
431 } 458 }
432
433 private:
434 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
435 }; 459 };
436 460
437 class FragmentTexColorMatrixAlphaBinding : public FragmentShaderBase { 461 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase {
438 public: 462 public:
439 FragmentTexColorMatrixAlphaBinding() { 463 FragmentShaderRGBATexPremultiplyAlpha() {
440 has_sampler_ = true; 464 has_varying_alpha_ = true;
465 has_premultiply_alpha_ = true;
466 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
467 }
468 };
469
470 class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
471 public:
472 FragmentShaderTexBackgroundVaryingAlpha() {
473 has_background_color_ = true;
474 has_varying_alpha_ = true;
475 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
476 }
477 };
478
479 class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase {
480 public:
481 FragmentShaderTexBackgroundPremultiplyAlpha() {
482 has_background_color_ = true;
483 has_varying_alpha_ = true;
484 has_premultiply_alpha_ = true;
485 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
486 }
487 };
488
489 class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
490 public:
491 FragmentShaderRGBATexAlpha() {
492 has_uniform_alpha_ = true;
493 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
494 }
495 };
496
497 class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase {
498 public:
499 FragmentShaderRGBATexColorMatrixAlpha() {
441 has_uniform_alpha_ = true; 500 has_uniform_alpha_ = true;
442 has_color_matrix_ = true; 501 has_color_matrix_ = true;
502 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
443 } 503 }
444
445 private:
446 }; 504 };
447 505
448 class FragmentTexOpaqueBinding : public FragmentShaderBase { 506 class FragmentShaderRGBATexOpaque : public FragmentShaderBase {
449 public: 507 public:
450 FragmentTexOpaqueBinding() { has_sampler_ = true; } 508 FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; }
451
452 private:
453 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
454 }; 509 };
455 510
456 class FragmentTexBackgroundBinding : public FragmentShaderBase { 511 class FragmentShaderRGBATex : public FragmentShaderBase {
457 public: 512 public:
458 FragmentTexBackgroundBinding() { 513 FragmentShaderRGBATex() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; }
459 has_sampler_ = true;
460 has_background_color_ = true;
461 }
462
463 private:
464 DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding);
465 };
466
467 class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
468 private:
469 std::string GetShaderSource() const override;
470 };
471
472 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding {
473 private:
474 std::string GetShaderSource() const override;
475 };
476
477 class FragmentShaderTexBackgroundVaryingAlpha
478 : public FragmentTexBackgroundBinding {
479 private:
480 std::string GetShaderSource() const override;
481 };
482
483 class FragmentShaderTexBackgroundPremultiplyAlpha
484 : public FragmentTexBackgroundBinding {
485 private:
486 std::string GetShaderSource() const override;
487 };
488
489 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
490 private:
491 std::string GetShaderSource() const override;
492 };
493
494 class FragmentShaderRGBATexColorMatrixAlpha
495 : public FragmentTexColorMatrixAlphaBinding {
496 private:
497 std::string GetShaderSource() const override;
498 };
499
500 class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding {
501 private:
502 std::string GetShaderSource() const override;
503 };
504
505 class FragmentShaderRGBATex : public FragmentTexOpaqueBinding {
506 private:
507 std::string GetShaderSource() const override;
508 }; 514 };
509 515
510 // Swizzles the red and blue component of sampled texel with alpha. 516 // Swizzles the red and blue component of sampled texel with alpha.
511 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding { 517 class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase {
512 private: 518 public:
513 std::string GetShaderSource() const override; 519 FragmentShaderRGBATexSwizzleAlpha() {
520 has_uniform_alpha_ = true;
521 has_swizzle_ = true;
522 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
523 }
514 }; 524 };
515 525
516 // Swizzles the red and blue component of sampled texel without alpha. 526 // Swizzles the red and blue component of sampled texel without alpha.
517 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding { 527 class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase {
518 private: 528 public:
519 std::string GetShaderSource() const override; 529 FragmentShaderRGBATexSwizzleOpaque() {
530 has_swizzle_ = true;
531 frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
532 }
520 }; 533 };
521 534
522 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { 535 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
523 public: 536 public:
524 FragmentShaderRGBATexAlphaAA() { 537 FragmentShaderRGBATexAlphaAA() {
525 has_sampler_ = true; 538 has_aa_ = true;
526 has_uniform_alpha_ = true; 539 has_uniform_alpha_ = true;
540 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
527 } 541 }
528
529 private:
530 std::string GetShaderSource() const override;
531 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
532 }; 542 };
533 543
534 class FragmentTexClampAlphaAABinding : public FragmentShaderBase { 544 class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
535 public: 545 public:
536 FragmentTexClampAlphaAABinding() { 546 FragmentShaderRGBATexClampAlphaAA() {
537 has_sampler_ = true; 547 has_aa_ = true;
538 has_uniform_alpha_ = true; 548 has_uniform_alpha_ = true;
539 has_fragment_tex_transform_ = true; 549 has_rgba_fragment_tex_transform_ = true;
550 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
540 } 551 }
541 private:
542 DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding);
543 };
544
545 class FragmentShaderRGBATexClampAlphaAA
546 : public FragmentTexClampAlphaAABinding {
547 private:
548 std::string GetShaderSource() const override;
549 }; 552 };
550 553
551 // Swizzles the red and blue component of sampled texel. 554 // Swizzles the red and blue component of sampled texel.
552 class FragmentShaderRGBATexClampSwizzleAlphaAA 555 class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase {
553 : public FragmentTexClampAlphaAABinding { 556 public:
554 private: 557 FragmentShaderRGBATexClampSwizzleAlphaAA() {
555 std::string GetShaderSource() const override; 558 has_aa_ = true;
559 has_uniform_alpha_ = true;
560 has_rgba_fragment_tex_transform_ = true;
561 has_swizzle_ = true;
562 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
563 }
556 }; 564 };
557 565
558 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { 566 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase {
559 public: 567 public:
560 FragmentShaderRGBATexAlphaMask() { 568 FragmentShaderRGBATexAlphaMask() {
561 has_sampler_ = true;
562 has_uniform_alpha_ = true; 569 has_uniform_alpha_ = true;
563 has_mask_sampler_ = true; 570 has_mask_sampler_ = true;
571 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
572 ignore_sampler_type_ = true;
564 } 573 }
565 private:
566 std::string GetShaderSource() const override;
567 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
568 }; 574 };
569 575
570 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { 576 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
571 public: 577 public:
572 FragmentShaderRGBATexAlphaMaskAA() { 578 FragmentShaderRGBATexAlphaMaskAA() {
573 has_sampler_ = true; 579 has_aa_ = true;
574 has_uniform_alpha_ = true; 580 has_uniform_alpha_ = true;
575 has_mask_sampler_ = true; 581 has_mask_sampler_ = true;
582 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
583 ignore_sampler_type_ = true;
576 } 584 }
577 private:
578 std::string GetShaderSource() const override;
579 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
580 }; 585 };
581 586
582 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { 587 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
583 public: 588 public:
584 FragmentShaderRGBATexAlphaMaskColorMatrixAA() { 589 FragmentShaderRGBATexAlphaMaskColorMatrixAA() {
585 has_sampler_ = true; 590 has_aa_ = true;
586 has_uniform_alpha_ = true; 591 has_uniform_alpha_ = true;
587 has_mask_sampler_ = true; 592 has_mask_sampler_ = true;
588 has_color_matrix_ = true; 593 has_color_matrix_ = true;
594 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
595 ignore_sampler_type_ = true;
589 } 596 }
590 private:
591 std::string GetShaderSource() const override;
592 }; 597 };
593 598
594 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { 599 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
595 public: 600 public:
596 FragmentShaderRGBATexAlphaColorMatrixAA() { 601 FragmentShaderRGBATexAlphaColorMatrixAA() {
597 has_sampler_ = true; 602 has_aa_ = true;
598 has_uniform_alpha_ = true; 603 has_uniform_alpha_ = true;
599 has_color_matrix_ = true; 604 has_color_matrix_ = true;
605 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
600 } 606 }
601
602 private:
603 std::string GetShaderSource() const override;
604 }; 607 };
605 608
606 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { 609 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
607 public: 610 public:
608 FragmentShaderRGBATexAlphaMaskColorMatrix() { 611 FragmentShaderRGBATexAlphaMaskColorMatrix() {
609 has_sampler_ = true;
610 has_uniform_alpha_ = true; 612 has_uniform_alpha_ = true;
611 has_mask_sampler_ = true; 613 has_mask_sampler_ = true;
612 has_color_matrix_ = true; 614 has_color_matrix_ = true;
615 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
616 ignore_sampler_type_ = true;
613 } 617 }
614 private:
615 std::string GetShaderSource() const override;
616 }; 618 };
617 619
618 class FragmentShaderYUVVideo : public FragmentShaderBase { 620 class FragmentShaderYUVVideo : public FragmentShaderBase {
619 public: 621 public:
620 FragmentShaderYUVVideo(); 622 FragmentShaderYUVVideo();
621 void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut); 623 void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut);
622 624
623 void Init(gpu::gles2::GLES2Interface* context, 625 void Init(gpu::gles2::GLES2Interface* context,
624 unsigned program, 626 unsigned program,
625 int* base_uniform_index) override; 627 int* base_uniform_index) override;
(...skipping 26 matching lines...) Expand all
652 int uv_texture_location_ = -1; 654 int uv_texture_location_ = -1;
653 int a_texture_location_ = -1; 655 int a_texture_location_ = -1;
654 int lut_texture_location_ = -1; 656 int lut_texture_location_ = -1;
655 int alpha_location_ = -1; 657 int alpha_location_ = -1;
656 int yuv_matrix_location_ = -1; 658 int yuv_matrix_location_ = -1;
657 int yuv_adj_location_ = -1; 659 int yuv_adj_location_ = -1;
658 int ya_clamp_rect_location_ = -1; 660 int ya_clamp_rect_location_ = -1;
659 int uv_clamp_rect_location_ = -1; 661 int uv_clamp_rect_location_ = -1;
660 int resource_multiplier_location_ = -1; 662 int resource_multiplier_location_ = -1;
661 int resource_offset_location_ = -1; 663 int resource_offset_location_ = -1;
662
663 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
664 }; 664 };
665 665
666 class FragmentShaderColor : public FragmentShaderBase { 666 class FragmentShaderColor : public FragmentShaderBase {
667 public: 667 public:
668 FragmentShaderColor() { has_uniform_color_ = true; } 668 FragmentShaderColor() {
669 669 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
670 private: 670 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
671 std::string GetShaderSource() const override; 671 }
672 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
673 }; 672 };
674 673
675 class FragmentShaderColorAA : public FragmentShaderBase { 674 class FragmentShaderColorAA : public FragmentShaderBase {
676 public: 675 public:
677 FragmentShaderColorAA() { has_uniform_color_ = true; } 676 FragmentShaderColorAA() {
678 677 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
679 private: 678 has_aa_ = true;
680 std::string GetShaderSource() const override; 679 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
681 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA); 680 }
682 }; 681 };
683 682
684 } // namespace cc 683 } // namespace cc
685 684
686 #endif // CC_OUTPUT_SHADER_H_ 685 #endif // CC_OUTPUT_SHADER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/output/shader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698