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

Unified Diff: cc/output/shader.h

Issue 2612823003: The great shader refactor: Delete all of the subclasses (Closed)
Patch Set: The great shader refactor: Delete all of the subclasses 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/output/program_binding.h ('k') | cc/output/shader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/shader.h
diff --git a/cc/output/shader.h b/cc/output/shader.h
index 804f9ad97dac66e1274bbe3fdec271ca3da43338..a028c3846478d0fc8af56ef4d6cbaed95487000a 100644
--- a/cc/output/shader.h
+++ b/cc/output/shader.h
@@ -62,6 +62,21 @@ enum PositionSource {
POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM,
};
+enum AAMode {
+ NO_AA = 0,
+ USE_AA = 1,
+};
+
+enum SwizzleMode {
+ NO_SWIZZLE = 0,
+ DO_SWIZZLE = 1,
+};
+
+enum PremultipliedAlphaMode {
+ PREMULTIPLIED_ALPHA = 0,
+ NON_PREMULTIPLIED_ALPHA = 1,
+};
+
enum SamplerType {
SAMPLER_TYPE_NA = 0,
SAMPLER_TYPE_2D = 1,
@@ -109,6 +124,11 @@ enum MaskMode {
LAST_MASK_VALUE = HAS_MASK
};
+enum OpacityMode {
+ NOT_OPAQUE = 0,
+ IS_OPAQUE = 1,
+};
+
struct ShaderLocations {
ShaderLocations();
@@ -175,6 +195,9 @@ class VertexShaderBase {
int quad_location() const { return quad_location_; }
protected:
+ template <class FragmentShader>
+ friend class ProgramBinding;
+
// Use arrays of uniforms for matrix, texTransform, and opacity.
bool use_uniform_arrays_ = false;
@@ -215,117 +238,14 @@ class VertexShaderBase {
int edge_location_ = -1;
};
-class VertexShaderPosTex : public VertexShaderBase {
- public:
- VertexShaderPosTex() {
- tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
- has_matrix_ = true;
- }
-};
-
-class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase {
- public:
- VertexShaderPosTexYUVStretchOffset() {
- tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
- has_matrix_ = true;
- is_ya_uv_ = true;
- }
-};
-
-class VertexShaderPos : public VertexShaderBase {
- public:
- VertexShaderPos() { has_matrix_ = true; }
-};
-
-class VertexShaderPosTexTransform : public VertexShaderBase {
- public:
- VertexShaderPosTexTransform() {
- tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
- tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
- has_matrix_ = true;
- has_vertex_opacity_ = true;
- use_uniform_arrays_ = true;
- }
-};
-
-class VertexShaderQuad : public VertexShaderBase {
- public:
- VertexShaderQuad() {
- position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
- has_matrix_ = true;
-#if defined(OS_ANDROID)
- has_dummy_variables_ = true;
-#endif
- }
-};
-
-class VertexShaderQuadAA : public VertexShaderBase {
- public:
- VertexShaderQuadAA() {
- position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
- has_matrix_ = true;
- has_aa_ = true;
- }
-};
-
-class VertexShaderQuadTexTransformAA : public VertexShaderBase {
- public:
- VertexShaderQuadTexTransformAA() {
- position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
- tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
- tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4;
- has_matrix_ = true;
- has_aa_ = true;
- }
-};
-
-class VertexShaderTile : public VertexShaderBase {
- public:
- VertexShaderTile() {
- position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
- tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
- tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
- has_matrix_ = true;
- }
-};
-
-class VertexShaderTileAA : public VertexShaderBase {
- public:
- VertexShaderTileAA() {
- position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
- tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
- tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
- has_matrix_ = true;
- has_aa_ = true;
- }
-};
-
-class VertexShaderVideoTransform : public VertexShaderBase {
- public:
- VertexShaderVideoTransform() {
- tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
- tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX;
- has_matrix_ = true;
- }
-};
-
class FragmentShaderBase {
public:
virtual void Init(gpu::gles2::GLES2Interface* context,
unsigned program,
int* base_uniform_index);
- std::string GetShaderString(TexCoordPrecision precision,
- SamplerType sampler) const;
+ std::string GetShaderString() const;
void FillLocations(ShaderLocations* locations) const;
- BlendMode blend_mode() const { return blend_mode_; }
- void set_blend_mode(BlendMode blend_mode) { blend_mode_ = blend_mode; }
- bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; }
- void set_mask_for_background(bool mask_for_background) {
- mask_for_background_ = mask_for_background;
- }
- bool mask_for_background() const { return mask_for_background_; }
-
int sampler_location() const { return sampler_location_; }
int alpha_location() const { return alpha_location_; }
int color_location() const { return color_location_; }
@@ -337,6 +257,7 @@ class FragmentShaderBase {
protected:
FragmentShaderBase();
virtual std::string GetShaderSource() const;
+ bool has_blend_mode() const { return blend_mode_ != BLEND_MODE_NONE; }
std::string SetBlendModeFunctions(const std::string& shader_string) const;
@@ -382,10 +303,15 @@ class FragmentShaderBase {
bool has_background_color_ = false;
int background_color_location_ = -1;
- private:
+ TexCoordPrecision tex_coord_precision_ = TEX_COORD_PRECISION_NA;
+ SamplerType sampler_type_ = SAMPLER_TYPE_NA;
BlendMode blend_mode_ = BLEND_MODE_NONE;
bool mask_for_background_ = false;
+ private:
+ template <class FragmentShader>
+ friend class ProgramBinding;
+
std::string GetHelperFunctions() const;
std::string GetBlendFunction() const;
std::string GetBlendFunctionBodyForRGB() const;
@@ -393,173 +319,6 @@ class FragmentShaderBase {
DISALLOW_COPY_AND_ASSIGN(FragmentShaderBase);
};
-class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexVaryingAlpha() {
- has_varying_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
- }
-};
-
-class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexPremultiplyAlpha() {
- has_varying_alpha_ = true;
- has_premultiply_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
- }
-};
-
-class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
- public:
- FragmentShaderTexBackgroundVaryingAlpha() {
- has_background_color_ = true;
- has_varying_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
- }
-};
-
-class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase {
- public:
- FragmentShaderTexBackgroundPremultiplyAlpha() {
- has_background_color_ = true;
- has_varying_alpha_ = true;
- has_premultiply_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
- }
-};
-
-class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlpha() {
- has_uniform_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- }
-};
-
-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 FragmentShaderBase {
- public:
- FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; }
-};
-
-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 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 FragmentShaderBase {
- public:
- FragmentShaderRGBATexSwizzleOpaque() {
- has_swizzle_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
- }
-};
-
-class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlphaAA() {
- has_aa_ = true;
- has_uniform_alpha_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- }
-};
-
-class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexClampAlphaAA() {
- has_aa_ = true;
- has_uniform_alpha_ = true;
- has_rgba_fragment_tex_transform_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
- }
-};
-
-// Swizzles the red and blue component of sampled texel.
-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_uniform_alpha_ = true;
- has_mask_sampler_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- ignore_sampler_type_ = true;
- }
-};
-
-class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlphaMaskAA() {
- has_aa_ = true;
- has_uniform_alpha_ = true;
- has_mask_sampler_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- ignore_sampler_type_ = true;
- }
-};
-
-class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlphaMaskColorMatrixAA() {
- has_aa_ = true;
- has_uniform_alpha_ = true;
- has_mask_sampler_ = true;
- has_color_matrix_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- ignore_sampler_type_ = true;
- }
-};
-
-class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlphaColorMatrixAA() {
- has_aa_ = true;
- has_uniform_alpha_ = true;
- has_color_matrix_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- }
-};
-
-class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
- public:
- FragmentShaderRGBATexAlphaMaskColorMatrix() {
- has_uniform_alpha_ = true;
- has_mask_sampler_ = true;
- has_color_matrix_ = true;
- frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
- ignore_sampler_type_ = true;
- }
-};
-
class FragmentShaderYUVVideo : public FragmentShaderBase {
public:
FragmentShaderYUVVideo();
« no previous file with comments | « cc/output/program_binding.h ('k') | cc/output/shader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698