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

Unified Diff: cc/output/program_binding.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/gl_renderer.cc ('k') | cc/output/shader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/program_binding.h
diff --git a/cc/output/program_binding.h b/cc/output/program_binding.h
index 6f0e818b5ed1b6d93ce5531e06ee32f35a222dcd..78a2ae0e4da7d585da7e841cebba7930cb837400 100644
--- a/cc/output/program_binding.h
+++ b/cc/output/program_binding.h
@@ -54,44 +54,176 @@ class ProgramBindingBase {
DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase);
};
-template <class VertexShader, class FragmentShader>
+template <class FragmentShader>
class ProgramBinding : public ProgramBindingBase {
public:
ProgramBinding() {}
- void Initialize(ContextProvider* context_provider,
- TexCoordPrecision precision,
- SamplerType sampler) {
- return Initialize(
- context_provider, precision, sampler, BLEND_MODE_NONE, false);
+ void InitializeDebugBorderProgram(ContextProvider* context_provider) {
+ vertex_shader_.has_matrix_ = true;
+
+ fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
+
+ InitializeInternal(context_provider);
+ }
+
+ void InitializeSolidColorProgram(ContextProvider* context_provider,
+ bool use_aa) {
+ vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
+ vertex_shader_.has_matrix_ = true;
+#if defined(OS_ANDROID)
+ vertex_shader_.has_dummy_variables_ = true;
+#endif
+ vertex_shader_.has_aa_ = use_aa;
+
+ fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
+ fragment_shader_.has_aa_ = use_aa;
+
+ InitializeInternal(context_provider);
+ }
+
+ void InitializeTileProgram(ContextProvider* context_provider,
+ TexCoordPrecision precision,
+ SamplerType sampler,
+ AAMode aa_mode,
+ SwizzleMode swizzle_mode,
+ OpacityMode opacity_mode) {
+ vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
+ vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
+ vertex_shader_.has_matrix_ = true;
+ fragment_shader_.tex_coord_precision_ = precision;
+ fragment_shader_.sampler_type_ = sampler;
+ if (swizzle_mode == DO_SWIZZLE)
+ fragment_shader_.has_swizzle_ = true;
+ if (aa_mode == USE_AA) {
+ vertex_shader_.has_aa_ = true;
+ fragment_shader_.has_aa_ = true;
+ fragment_shader_.has_rgba_fragment_tex_transform_ = true;
+ }
+
+ if (opacity_mode == IS_OPAQUE) {
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
+ } else {
+ fragment_shader_.has_uniform_alpha_ = true;
+ // TODO(ccameron): Determine if we can always use FRAG_COLOR_MODE_DEFAULT
+ // here.
+ if (aa_mode == NO_AA && swizzle_mode == NO_SWIZZLE)
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
+ else
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
+ }
+
+ InitializeInternal(context_provider);
}
- void Initialize(ContextProvider* context_provider,
- TexCoordPrecision precision,
- SamplerType sampler,
- BlendMode blend_mode) {
- return Initialize(
- context_provider, precision, sampler, blend_mode, false);
+ void InitializeTextureProgram(ContextProvider* context_provider,
+ TexCoordPrecision precision,
+ SamplerType sampler,
+ PremultipliedAlphaMode premultiplied_alpha,
+ bool has_background_color) {
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
+ vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
+ vertex_shader_.has_matrix_ = true;
+ vertex_shader_.has_vertex_opacity_ = true;
+ vertex_shader_.use_uniform_arrays_ = true;
+ fragment_shader_.tex_coord_precision_ = precision;
+ fragment_shader_.sampler_type_ = sampler;
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
+ fragment_shader_.has_varying_alpha_ = true;
+ if (premultiplied_alpha == NON_PREMULTIPLIED_ALPHA)
+ fragment_shader_.has_premultiply_alpha_ = true;
+ fragment_shader_.has_background_color_ = has_background_color;
+ InitializeInternal(context_provider);
}
- void Initialize(ContextProvider* context_provider,
- TexCoordPrecision precision,
- SamplerType sampler,
- BlendMode blend_mode,
- bool mask_for_background) {
+ // TODO(ccameron): Merge |mask_for_background| into MaskMode.
+ void InitializeRenderPassProgram(ContextProvider* context_provider,
+ TexCoordPrecision precision,
+ SamplerType sampler,
+ BlendMode blend_mode,
+ AAMode aa_mode,
+ MaskMode mask_mode,
+ bool mask_for_background,
+ bool has_color_matrix) {
+ vertex_shader_.has_matrix_ = true;
+ if (aa_mode == NO_AA) {
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
+ vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
+ vertex_shader_.has_vertex_opacity_ = true;
+ vertex_shader_.use_uniform_arrays_ = true;
+ } else {
+ vertex_shader_.position_source_ =
+ POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
+ vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4;
+ vertex_shader_.has_aa_ = true;
+ fragment_shader_.has_aa_ = true;
+ }
+
+ fragment_shader_.tex_coord_precision_ = precision;
+ fragment_shader_.sampler_type_ = sampler;
+ fragment_shader_.blend_mode_ = blend_mode;
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
+ fragment_shader_.has_uniform_alpha_ = true;
+ fragment_shader_.mask_for_background_ = mask_for_background;
+ fragment_shader_.has_color_matrix_ = has_color_matrix;
+ if (mask_mode == HAS_MASK) {
+ fragment_shader_.has_mask_sampler_ = true;
+ fragment_shader_.ignore_sampler_type_ = true;
+ } else {
+ DCHECK(!mask_for_background);
+ }
+
+ InitializeInternal(context_provider);
+ }
+
+ void InitializeVideoStreamProgram(ContextProvider* context_provider,
+ TexCoordPrecision precision) {
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
+ vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX;
+ vertex_shader_.has_matrix_ = true;
+
+ fragment_shader_.tex_coord_precision_ = precision;
+ fragment_shader_.sampler_type_ = SAMPLER_TYPE_EXTERNAL_OES;
+ fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
+
+ InitializeInternal(context_provider);
+ }
+
+ void InitializeVideoYUVProgram(ContextProvider* context_provider,
+ TexCoordPrecision precision,
+ SamplerType sampler,
+ bool use_alpha_plane,
+ bool use_nv12,
+ bool use_color_lut) {
+ vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
+ vertex_shader_.has_matrix_ = true;
+ vertex_shader_.is_ya_uv_ = true;
+
+ fragment_shader_.tex_coord_precision_ = precision;
+ fragment_shader_.sampler_type_ = sampler;
+ fragment_shader_.SetFeatures(use_alpha_plane, use_nv12, use_color_lut);
+
+ InitializeInternal(context_provider);
+ }
+
+ const VertexShaderBase& vertex_shader() const { return vertex_shader_; }
+ const FragmentShader& fragment_shader() const { return fragment_shader_; }
+
+ private:
+ void InitializeInternal(ContextProvider* context_provider) {
DCHECK(context_provider);
DCHECK(!initialized_);
if (IsContextLost(context_provider->ContextGL()))
return;
- fragment_shader_.set_blend_mode(blend_mode);
- fragment_shader_.set_mask_for_background(mask_for_background);
-
- if (!ProgramBindingBase::Init(
- context_provider->ContextGL(),
- vertex_shader_.GetShaderString(),
- fragment_shader_.GetShaderString(precision, sampler))) {
+ if (!ProgramBindingBase::Init(context_provider->ContextGL(),
+ vertex_shader_.GetShaderString(),
+ fragment_shader_.GetShaderString())) {
DCHECK(IsContextLost(context_provider->ContextGL()));
return;
}
@@ -111,12 +243,7 @@ class ProgramBinding : public ProgramBindingBase {
initialized_ = true;
}
- const VertexShader& vertex_shader() const { return vertex_shader_; }
- const FragmentShader& fragment_shader() const { return fragment_shader_; }
- FragmentShader* mutable_fragment_shader() { return &fragment_shader_; }
-
- private:
- VertexShader vertex_shader_;
+ VertexShaderBase vertex_shader_;
FragmentShader fragment_shader_;
DISALLOW_COPY_AND_ASSIGN(ProgramBinding);
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | cc/output/shader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698