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

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

Issue 2608863002: The great shader refactor: Merge fragment shaders into an uber-shader (Closed)
Patch Set: Set upstream branch... 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') | cc/output/shader.cc » ('J')
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 bool has_rgba_as_sampler_2d_ = false;
416 int sampler_location_ = -1;
417 int fragment_tex_transform_location_ = -1;
418
419 // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM.
420 int color_location_ = -1;
421
393 bool has_mask_sampler_ = false; 422 bool has_mask_sampler_ = false;
394 int mask_sampler_location_ = -1; 423 int mask_sampler_location_ = -1;
395 int mask_tex_coord_scale_location_ = -1; 424 int mask_tex_coord_scale_location_ = -1;
396 int mask_tex_coord_offset_location_ = -1; 425 int mask_tex_coord_offset_location_ = -1;
397 426
398 bool has_color_matrix_ = false; 427 bool has_color_matrix_ = false;
399 int color_matrix_location_ = -1; 428 int color_matrix_location_ = -1;
400 int color_offset_location_ = -1; 429 int color_offset_location_ = -1;
401 430
402 bool has_sampler_ = false;
403 int sampler_location_ = -1;
404
405 bool has_uniform_alpha_ = false; 431 bool has_uniform_alpha_ = false;
406 int alpha_location_ = -1; 432 int alpha_location_ = -1;
407 433
408 bool has_background_color_ = false; 434 bool has_background_color_ = false;
409 int background_color_location_ = -1; 435 int background_color_location_ = -1;
410 436
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: 437 private:
418 BlendMode blend_mode_ = BLEND_MODE_NONE; 438 BlendMode blend_mode_ = BLEND_MODE_NONE;
419 bool mask_for_background_ = false; 439 bool mask_for_background_ = false;
420 440
421 std::string GetHelperFunctions() const; 441 std::string GetHelperFunctions() const;
422 std::string GetBlendFunction() const; 442 std::string GetBlendFunction() const;
423 std::string GetBlendFunctionBodyForRGB() const; 443 std::string GetBlendFunctionBodyForRGB() const;
444
445 DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase);
424 }; 446 };
425 447
426 class FragmentTexAlphaBinding : public FragmentShaderBase { 448 class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
427 public: 449 public:
428 FragmentTexAlphaBinding() { 450 FragmentShaderRGBATexVaryingAlpha() {
429 has_sampler_ = true; 451 has_varying_alpha_ = true;
430 has_uniform_alpha_ = true; 452 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
431 } 453 }
432
433 private:
434 DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding);
435 }; 454 };
436 455
437 class FragmentTexColorMatrixAlphaBinding : public FragmentShaderBase { 456 class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase {
438 public: 457 public:
439 FragmentTexColorMatrixAlphaBinding() { 458 FragmentShaderRGBATexPremultiplyAlpha() {
440 has_sampler_ = true; 459 has_varying_alpha_ = true;
460 has_premultiply_alpha_ = true;
461 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
462 }
463 };
464
465 class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
466 public:
467 FragmentShaderTexBackgroundVaryingAlpha() {
468 has_background_color_ = true;
469 has_varying_alpha_ = true;
470 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
471 }
472 };
473
474 class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase {
475 public:
476 FragmentShaderTexBackgroundPremultiplyAlpha() {
477 has_background_color_ = true;
478 has_varying_alpha_ = true;
479 has_premultiply_alpha_ = true;
480 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
481 }
482 };
483
484 class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
485 public:
486 FragmentShaderRGBATexAlpha() {
487 has_uniform_alpha_ = true;
488 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
489 }
490 };
491
492 class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase {
493 public:
494 FragmentShaderRGBATexColorMatrixAlpha() {
441 has_uniform_alpha_ = true; 495 has_uniform_alpha_ = true;
442 has_color_matrix_ = true; 496 has_color_matrix_ = true;
497 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
443 } 498 }
444
445 private:
446 }; 499 };
447 500
448 class FragmentTexOpaqueBinding : public FragmentShaderBase { 501 class FragmentShaderRGBATexOpaque : public FragmentShaderBase {
449 public: 502 public:
450 FragmentTexOpaqueBinding() { has_sampler_ = true; } 503 FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; }
451
452 private:
453 DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding);
454 }; 504 };
455 505
456 class FragmentTexBackgroundBinding : public FragmentShaderBase { 506 class FragmentShaderRGBATex : public FragmentShaderBase {
457 public: 507 public:
458 FragmentTexBackgroundBinding() { 508 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 }; 509 };
509 510
510 // Swizzles the red and blue component of sampled texel with alpha. 511 // Swizzles the red and blue component of sampled texel with alpha.
511 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding { 512 class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase {
512 private: 513 public:
513 std::string GetShaderSource() const override; 514 FragmentShaderRGBATexSwizzleAlpha() {
515 has_uniform_alpha_ = true;
516 has_swizzle_ = true;
517 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
518 }
514 }; 519 };
515 520
516 // Swizzles the red and blue component of sampled texel without alpha. 521 // Swizzles the red and blue component of sampled texel without alpha.
517 class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding { 522 class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase {
518 private: 523 public:
519 std::string GetShaderSource() const override; 524 FragmentShaderRGBATexSwizzleOpaque() {
525 has_swizzle_ = true;
526 frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
527 }
520 }; 528 };
521 529
522 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { 530 class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
523 public: 531 public:
524 FragmentShaderRGBATexAlphaAA() { 532 FragmentShaderRGBATexAlphaAA() {
525 has_sampler_ = true; 533 has_aa_ = true;
526 has_uniform_alpha_ = true; 534 has_uniform_alpha_ = true;
535 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
527 } 536 }
528
529 private:
530 std::string GetShaderSource() const override;
531 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA);
532 }; 537 };
533 538
534 class FragmentTexClampAlphaAABinding : public FragmentShaderBase { 539 class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
535 public: 540 public:
536 FragmentTexClampAlphaAABinding() { 541 FragmentShaderRGBATexClampAlphaAA() {
537 has_sampler_ = true; 542 has_aa_ = true;
538 has_uniform_alpha_ = true; 543 has_uniform_alpha_ = true;
539 has_fragment_tex_transform_ = true; 544 has_rgba_fragment_tex_transform_ = true;
545 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
540 } 546 }
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 }; 547 };
550 548
551 // Swizzles the red and blue component of sampled texel. 549 // Swizzles the red and blue component of sampled texel.
552 class FragmentShaderRGBATexClampSwizzleAlphaAA 550 class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase {
553 : public FragmentTexClampAlphaAABinding { 551 public:
554 private: 552 FragmentShaderRGBATexClampSwizzleAlphaAA() {
555 std::string GetShaderSource() const override; 553 has_aa_ = true;
554 has_uniform_alpha_ = true;
555 has_rgba_fragment_tex_transform_ = true;
556 has_swizzle_ = true;
557 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
558 }
556 }; 559 };
557 560
558 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { 561 class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase {
559 public: 562 public:
560 FragmentShaderRGBATexAlphaMask() { 563 FragmentShaderRGBATexAlphaMask() {
561 has_sampler_ = true;
562 has_uniform_alpha_ = true; 564 has_uniform_alpha_ = true;
563 has_mask_sampler_ = true; 565 has_mask_sampler_ = true;
566 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
567 has_rgba_as_sampler_2d_ = true;
564 } 568 }
565 private:
566 std::string GetShaderSource() const override;
567 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask);
568 }; 569 };
569 570
570 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { 571 class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
571 public: 572 public:
572 FragmentShaderRGBATexAlphaMaskAA() { 573 FragmentShaderRGBATexAlphaMaskAA() {
573 has_sampler_ = true; 574 has_aa_ = true;
574 has_uniform_alpha_ = true; 575 has_uniform_alpha_ = true;
575 has_mask_sampler_ = true; 576 has_mask_sampler_ = true;
577 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
578 has_rgba_as_sampler_2d_ = true;
576 } 579 }
577 private:
578 std::string GetShaderSource() const override;
579 DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA);
580 }; 580 };
581 581
582 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { 582 class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
583 public: 583 public:
584 FragmentShaderRGBATexAlphaMaskColorMatrixAA() { 584 FragmentShaderRGBATexAlphaMaskColorMatrixAA() {
585 has_sampler_ = true; 585 has_aa_ = true;
586 has_uniform_alpha_ = true; 586 has_uniform_alpha_ = true;
587 has_mask_sampler_ = true; 587 has_mask_sampler_ = true;
588 has_color_matrix_ = true; 588 has_color_matrix_ = true;
589 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
590 has_rgba_as_sampler_2d_ = true;
589 } 591 }
590 private:
591 std::string GetShaderSource() const override;
592 }; 592 };
593 593
594 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { 594 class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
595 public: 595 public:
596 FragmentShaderRGBATexAlphaColorMatrixAA() { 596 FragmentShaderRGBATexAlphaColorMatrixAA() {
597 has_sampler_ = true; 597 has_aa_ = true;
598 has_uniform_alpha_ = true; 598 has_uniform_alpha_ = true;
599 has_color_matrix_ = true; 599 has_color_matrix_ = true;
600 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
600 } 601 }
601
602 private:
603 std::string GetShaderSource() const override;
604 }; 602 };
605 603
606 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { 604 class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
607 public: 605 public:
608 FragmentShaderRGBATexAlphaMaskColorMatrix() { 606 FragmentShaderRGBATexAlphaMaskColorMatrix() {
609 has_sampler_ = true;
610 has_uniform_alpha_ = true; 607 has_uniform_alpha_ = true;
611 has_mask_sampler_ = true; 608 has_mask_sampler_ = true;
612 has_color_matrix_ = true; 609 has_color_matrix_ = true;
610 frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
611 has_rgba_as_sampler_2d_ = true;
613 } 612 }
614 private:
615 std::string GetShaderSource() const override;
616 }; 613 };
617 614
618 class FragmentShaderYUVVideo : public FragmentShaderBase { 615 class FragmentShaderYUVVideo : public FragmentShaderBase {
619 public: 616 public:
620 FragmentShaderYUVVideo(); 617 FragmentShaderYUVVideo();
621 void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut); 618 void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut);
622 619
623 void Init(gpu::gles2::GLES2Interface* context, 620 void Init(gpu::gles2::GLES2Interface* context,
624 unsigned program, 621 unsigned program,
625 int* base_uniform_index) override; 622 int* base_uniform_index) override;
(...skipping 26 matching lines...) Expand all
652 int uv_texture_location_ = -1; 649 int uv_texture_location_ = -1;
653 int a_texture_location_ = -1; 650 int a_texture_location_ = -1;
654 int lut_texture_location_ = -1; 651 int lut_texture_location_ = -1;
655 int alpha_location_ = -1; 652 int alpha_location_ = -1;
656 int yuv_matrix_location_ = -1; 653 int yuv_matrix_location_ = -1;
657 int yuv_adj_location_ = -1; 654 int yuv_adj_location_ = -1;
658 int ya_clamp_rect_location_ = -1; 655 int ya_clamp_rect_location_ = -1;
659 int uv_clamp_rect_location_ = -1; 656 int uv_clamp_rect_location_ = -1;
660 int resource_multiplier_location_ = -1; 657 int resource_multiplier_location_ = -1;
661 int resource_offset_location_ = -1; 658 int resource_offset_location_ = -1;
662
663 DISALLOW_COPY_AND_ASSIGN(FragmentShaderYUVVideo);
664 }; 659 };
665 660
666 class FragmentShaderColor : public FragmentShaderBase { 661 class FragmentShaderColor : public FragmentShaderBase {
667 public: 662 public:
668 FragmentShaderColor() { has_uniform_color_ = true; } 663 FragmentShaderColor() {
669 664 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
670 private: 665 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
671 std::string GetShaderSource() const override; 666 }
672 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor);
673 }; 667 };
674 668
675 class FragmentShaderColorAA : public FragmentShaderBase { 669 class FragmentShaderColorAA : public FragmentShaderBase {
676 public: 670 public:
677 FragmentShaderColorAA() { has_uniform_color_ = true; } 671 FragmentShaderColorAA() {
678 672 input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
679 private: 673 has_aa_ = true;
680 std::string GetShaderSource() const override; 674 frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
681 DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA); 675 }
682 }; 676 };
683 677
684 } // namespace cc 678 } // namespace cc
685 679
686 #endif // CC_OUTPUT_SHADER_H_ 680 #endif // CC_OUTPUT_SHADER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/output/shader.cc » ('j') | cc/output/shader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698