Chromium Code Reviews| Index: cc/output/shader.h |
| diff --git a/cc/output/shader.h b/cc/output/shader.h |
| index a74a58fac456d013836b35f73e107f9bbf48d1ff..907db9c05e8617f16308d91d35a375f987c51ca2 100644 |
| --- a/cc/output/shader.h |
| +++ b/cc/output/shader.h |
| @@ -59,6 +59,18 @@ enum BlendMode { |
| LAST_BLEND_MODE = BLEND_MODE_LUMINOSITY |
| }; |
| +enum InputColorSource { |
| + INPUT_COLOR_SOURCE_RGBA_TEXTURE, |
| + INPUT_COLOR_SOURCE_UNIFORM, |
| +}; |
| + |
| +// TODO(ccameron): Merge this with BlendMode. |
| +enum FragColorMode { |
| + FRAG_COLOR_MODE_DEFAULT, |
| + FRAG_COLOR_MODE_OPAQUE, |
| + FRAG_COLOR_MODE_APPLY_BLEND_MODE, |
| +}; |
| + |
| enum MaskMode { |
| NO_MASK = 0, |
| HAS_MASK = 1, |
| @@ -381,15 +393,32 @@ class FragmentShaderBase { |
| protected: |
| FragmentShaderBase(); |
| - virtual std::string GetShaderSource() const = 0; |
| + virtual std::string GetShaderSource() const; |
| std::string SetBlendModeFunctions(const std::string& shader_string) const; |
| + // Settings that are modified by sub-classes. |
| + bool has_aa_ = false; |
| + bool has_varying_alpha_ = false; |
| + bool has_swizzle_ = false; |
| + bool has_premultiply_alpha_ = false; |
| + FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE; |
| + |
| // Used only if |blend_mode_| is not BLEND_MODE_NONE. |
| int backdrop_location_ = -1; |
| int original_backdrop_location_ = -1; |
| int backdrop_rect_location_ = -1; |
| + // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_RGBA_TEXTURE. |
| + bool has_rgba_fragment_tex_transform_ = false; |
| + bool has_rgba_as_sampler_2d_ = false; |
| + int sampler_location_ = -1; |
| + int fragment_tex_transform_location_ = -1; |
| + |
| + // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM. |
| + int color_location_ = -1; |
| + |
| bool has_mask_sampler_ = false; |
| int mask_sampler_location_ = -1; |
| int mask_tex_coord_scale_location_ = -1; |
| @@ -399,21 +428,12 @@ class FragmentShaderBase { |
| int color_matrix_location_ = -1; |
| int color_offset_location_ = -1; |
| - bool has_sampler_ = false; |
| - int sampler_location_ = -1; |
| - |
| bool has_uniform_alpha_ = false; |
| int alpha_location_ = -1; |
| bool has_background_color_ = false; |
| int background_color_location_ = -1; |
| - bool has_fragment_tex_transform_ = false; |
| - int fragment_tex_transform_location_ = -1; |
| - |
| - bool has_uniform_color_ = false; |
| - int color_location_ = -1; |
| - |
| private: |
| BlendMode blend_mode_ = BLEND_MODE_NONE; |
| bool mask_for_background_ = false; |
| @@ -423,196 +443,177 @@ class FragmentShaderBase { |
| std::string GetBlendFunctionBodyForRGB() const; |
| }; |
| -class FragmentTexAlphaBinding : public FragmentShaderBase { |
| +class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase { |
| public: |
| - FragmentTexAlphaBinding() { |
| - has_sampler_ = true; |
| - has_uniform_alpha_ = true; |
| + FragmentShaderRGBATexVaryingAlpha() { |
| + has_varying_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| } |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(FragmentTexAlphaBinding); |
| }; |
| -class FragmentTexColorMatrixAlphaBinding : public FragmentShaderBase { |
| +class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase { |
| public: |
| - FragmentTexColorMatrixAlphaBinding() { |
| - has_sampler_ = true; |
| - has_uniform_alpha_ = true; |
| - has_color_matrix_ = true; |
| + FragmentShaderRGBATexPremultiplyAlpha() { |
| + has_varying_alpha_ = true; |
| + has_premultiply_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| } |
| - |
| - private: |
| }; |
| -class FragmentTexOpaqueBinding : public FragmentShaderBase { |
| +class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase { |
| public: |
| - FragmentTexOpaqueBinding() { has_sampler_ = true; } |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(FragmentTexOpaqueBinding); |
| + FragmentShaderTexBackgroundVaryingAlpha() { |
| + has_background_color_ = true; |
| + has_varying_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + } |
| }; |
| -class FragmentTexBackgroundBinding : public FragmentShaderBase { |
| +class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase { |
| public: |
| - FragmentTexBackgroundBinding() { |
| - has_sampler_ = true; |
| + FragmentShaderTexBackgroundPremultiplyAlpha() { |
| has_background_color_ = true; |
| + has_varying_alpha_ = true; |
| + has_premultiply_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| } |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(FragmentTexBackgroundBinding); |
| -}; |
| - |
| -class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| -}; |
| - |
| -class FragmentShaderRGBATexPremultiplyAlpha : public FragmentTexOpaqueBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| -}; |
| - |
| -class FragmentShaderTexBackgroundVaryingAlpha |
| - : public FragmentTexBackgroundBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| -}; |
| - |
| -class FragmentShaderTexBackgroundPremultiplyAlpha |
| - : public FragmentTexBackgroundBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| }; |
| -class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexAlpha : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexAlpha() { |
| + has_uniform_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + } |
| }; |
| -class FragmentShaderRGBATexColorMatrixAlpha |
| - : public FragmentTexColorMatrixAlphaBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexColorMatrixAlpha() { |
| + has_uniform_alpha_ = true; |
| + has_color_matrix_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + } |
| }; |
| -class FragmentShaderRGBATexOpaque : public FragmentTexOpaqueBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexOpaque : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; } |
| }; |
| -class FragmentShaderRGBATex : public FragmentTexOpaqueBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATex : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATex() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; } |
| }; |
| // Swizzles the red and blue component of sampled texel with alpha. |
| -class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexSwizzleAlpha() { |
| + has_uniform_alpha_ = true; |
| + has_swizzle_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + } |
| }; |
| // Swizzles the red and blue component of sampled texel without alpha. |
| -class FragmentShaderRGBATexSwizzleOpaque : public FragmentTexOpaqueBinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexSwizzleOpaque() { |
| + has_swizzle_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; |
| + } |
| }; |
| class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaAA() { |
| - has_sampler_ = true; |
| + has_aa_ = true; |
| has_uniform_alpha_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| } |
| - |
| private: |
| - std::string GetShaderSource() const override; |
| DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaAA); |
| }; |
| -class FragmentTexClampAlphaAABinding : public FragmentShaderBase { |
| +class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase { |
| public: |
| - FragmentTexClampAlphaAABinding() { |
| - has_sampler_ = true; |
| + FragmentShaderRGBATexClampAlphaAA() { |
| + has_aa_ = true; |
| has_uniform_alpha_ = true; |
| - has_fragment_tex_transform_ = true; |
| + has_rgba_fragment_tex_transform_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| } |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(FragmentTexClampAlphaAABinding); |
| -}; |
| - |
| -class FragmentShaderRGBATexClampAlphaAA |
| - : public FragmentTexClampAlphaAABinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| }; |
| // Swizzles the red and blue component of sampled texel. |
| -class FragmentShaderRGBATexClampSwizzleAlphaAA |
| - : public FragmentTexClampAlphaAABinding { |
| - private: |
| - std::string GetShaderSource() const override; |
| +class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase { |
| + public: |
| + FragmentShaderRGBATexClampSwizzleAlphaAA() { |
| + has_aa_ = true; |
| + has_uniform_alpha_ = true; |
| + has_rgba_fragment_tex_transform_ = true; |
| + has_swizzle_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + } |
| }; |
| class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaMask() { |
| - has_sampler_ = true; |
| has_uniform_alpha_ = true; |
| has_mask_sampler_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + has_rgba_as_sampler_2d_ = true; |
| } |
| private: |
| - std::string GetShaderSource() const override; |
| DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMask); |
| }; |
| class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaMaskAA() { |
| - has_sampler_ = true; |
| + has_aa_ = true; |
| has_uniform_alpha_ = true; |
| has_mask_sampler_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + has_rgba_as_sampler_2d_ = true; |
| } |
| private: |
| - std::string GetShaderSource() const override; |
| DISALLOW_COPY_AND_ASSIGN(FragmentShaderRGBATexAlphaMaskAA); |
|
enne (OOO)
2017/01/03 21:42:58
Tiniest of nits: maybe all or none of these classe
ccameron
2017/01/03 22:12:27
Yeah, I was wondering what to do there. Updated to
|
| }; |
| class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaMaskColorMatrixAA() { |
| - has_sampler_ = true; |
| + has_aa_ = true; |
| has_uniform_alpha_ = true; |
| has_mask_sampler_ = true; |
| has_color_matrix_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + has_rgba_as_sampler_2d_ = true; |
| } |
| - private: |
| - std::string GetShaderSource() const override; |
| }; |
| class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaColorMatrixAA() { |
| - has_sampler_ = true; |
| + has_aa_ = true; |
| has_uniform_alpha_ = true; |
| has_color_matrix_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| } |
| - |
| - private: |
| - std::string GetShaderSource() const override; |
| }; |
| class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { |
| public: |
| FragmentShaderRGBATexAlphaMaskColorMatrix() { |
| - has_sampler_ = true; |
| has_uniform_alpha_ = true; |
| has_mask_sampler_ = true; |
| has_color_matrix_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
| + has_rgba_as_sampler_2d_ = true; |
| } |
| - private: |
| - std::string GetShaderSource() const override; |
| }; |
| class FragmentShaderYUVVideo : public FragmentShaderBase { |
| @@ -665,19 +666,24 @@ class FragmentShaderYUVVideo : public FragmentShaderBase { |
| class FragmentShaderColor : public FragmentShaderBase { |
| public: |
| - FragmentShaderColor() { has_uniform_color_ = true; } |
| + FragmentShaderColor() { |
| + input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + } |
| private: |
| - std::string GetShaderSource() const override; |
| DISALLOW_COPY_AND_ASSIGN(FragmentShaderColor); |
| }; |
| class FragmentShaderColorAA : public FragmentShaderBase { |
| public: |
| - FragmentShaderColorAA() { has_uniform_color_ = true; } |
| + FragmentShaderColorAA() { |
| + input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; |
| + has_aa_ = true; |
| + frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
| + } |
| private: |
| - std::string GetShaderSource() const override; |
| DISALLOW_COPY_AND_ASSIGN(FragmentShaderColorAA); |
| }; |