Index: cc/output/program_binding.h |
diff --git a/cc/output/program_binding.h b/cc/output/program_binding.h |
index 78a2ae0e4da7d585da7e841cebba7930cb837400..9dcd5a12864642970985011b68853fc0faf95a47 100644 |
--- a/cc/output/program_binding.h |
+++ b/cc/output/program_binding.h |
@@ -54,102 +54,181 @@ class ProgramBindingBase { |
DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); |
}; |
+enum ProgramType { |
+ PROGRAM_TYPE_DEBUG_BORDER, |
+ PROGRAM_TYPE_SOLID_COLOR, |
+ PROGRAM_TYPE_TILE, |
+ PROGRAM_TYPE_TEXTURE, |
+ PROGRAM_TYPE_RENDER_PASS, |
+ PROGRAM_TYPE_VIDEO_STREAM, |
+}; |
+ |
+class CC_EXPORT ProgramKey { |
+ public: |
+ ProgramKey(const ProgramKey& other); |
+ ~ProgramKey(); |
+ |
+ static ProgramKey DebugBorder(); |
+ static ProgramKey SolidColor(AAMode aa_mode); |
+ static ProgramKey Tile(TexCoordPrecision precision, |
+ SamplerType sampler, |
+ AAMode aa_mode, |
+ SwizzleMode swizzle_mode, |
+ OpacityMode opacity_mode); |
+ static ProgramKey Texture(TexCoordPrecision precision, |
+ SamplerType sampler, |
+ PremultipliedAlphaMode premultiplied_alpha, |
+ bool has_background_color); |
+ |
+ // TODO(ccameron): Merge |mask_for_background| into MaskMode. |
+ static ProgramKey RenderPass(TexCoordPrecision precision, |
+ SamplerType sampler, |
+ BlendMode blend_mode, |
+ AAMode aa_mode, |
+ MaskMode mask_mode, |
+ bool mask_for_background, |
+ bool has_color_matrix); |
+ static ProgramKey VideoStream(TexCoordPrecision precision); |
+ |
+ bool operator==(const ProgramKey& other) const; |
+ |
+ private: |
+ ProgramKey(); |
+ friend struct ProgramKeyHash; |
+ template <class FragmentShader> |
+ friend class ProgramBinding; |
+ |
+ ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER; |
+ TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA; |
+ SamplerType sampler_ = SAMPLER_TYPE_NA; |
+ BlendMode blend_mode_ = BLEND_MODE_NONE; |
+ AAMode aa_mode_ = NO_AA; |
+ SwizzleMode swizzle_mode_ = NO_SWIZZLE; |
+ OpacityMode opacity_mode_ = NOT_OPAQUE; |
+ |
+ PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; |
+ bool has_background_color_ = false; |
+ |
+ MaskMode mask_mode_ = NO_MASK; |
+ bool mask_for_background_ = false; |
+ bool has_color_matrix_ = false; |
+}; |
+ |
+struct ProgramKeyHash { |
+ size_t operator()(const ProgramKey& key) const { |
+ return (static_cast<size_t>(key.type_) << 0) ^ |
+ (static_cast<size_t>(key.precision_) << 3) ^ |
+ (static_cast<size_t>(key.sampler_) << 6) ^ |
+ (static_cast<size_t>(key.blend_mode_) << 9) ^ |
+ (static_cast<size_t>(key.aa_mode_) << 15) ^ |
+ (static_cast<size_t>(key.swizzle_mode_) << 16) ^ |
+ (static_cast<size_t>(key.opacity_mode_) << 17) ^ |
+ (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^ |
+ (static_cast<size_t>(key.has_background_color_) << 20) ^ |
+ (static_cast<size_t>(key.mask_mode_) << 21) ^ |
+ (static_cast<size_t>(key.mask_for_background_) << 22) ^ |
+ (static_cast<size_t>(key.has_color_matrix_) << 23); |
+ } |
+}; |
+ |
template <class FragmentShader> |
class ProgramBinding : public ProgramBindingBase { |
public: |
ProgramBinding() {} |
- void InitializeDebugBorderProgram(ContextProvider* context_provider) { |
- vertex_shader_.has_matrix_ = true; |
+ void Initialize(ContextProvider* context_provider, const ProgramKey& key) { |
+ switch (key.type_) { |
+ case PROGRAM_TYPE_DEBUG_BORDER: |
+ InitializeDebugBorderProgram(); |
+ break; |
+ case PROGRAM_TYPE_SOLID_COLOR: |
+ InitializeSolidColorProgram(key); |
+ break; |
+ case PROGRAM_TYPE_TILE: |
+ InitializeTileProgram(key); |
+ break; |
+ case PROGRAM_TYPE_TEXTURE: |
+ InitializeTextureProgram(key); |
+ break; |
+ case PROGRAM_TYPE_RENDER_PASS: |
+ InitializeRenderPassProgram(key); |
+ break; |
+ case PROGRAM_TYPE_VIDEO_STREAM: |
+ InitializeVideoStreamProgram(key); |
+ break; |
+ } |
+ InitializeInternal(context_provider); |
+ } |
+ private: |
ccameron
2017/01/05 10:32:27
This "public then private then public again" schem
|
+ void InitializeDebugBorderProgram() { |
+ 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) { |
+ void InitializeSolidColorProgram(const ProgramKey& key) { |
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); |
+ if (key.aa_mode_ == USE_AA) { |
+ vertex_shader_.has_aa_ = true; |
+ fragment_shader_.has_aa_ = true; |
+ } |
} |
- void InitializeTileProgram(ContextProvider* context_provider, |
- TexCoordPrecision precision, |
- SamplerType sampler, |
- AAMode aa_mode, |
- SwizzleMode swizzle_mode, |
- OpacityMode opacity_mode) { |
+ void InitializeTileProgram(const ProgramKey& key) { |
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_.tex_coord_precision_ = key.precision_; |
+ fragment_shader_.sampler_type_ = key.sampler_; |
+ if (key.swizzle_mode_ == DO_SWIZZLE) |
fragment_shader_.has_swizzle_ = true; |
- if (aa_mode == USE_AA) { |
+ if (key.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) { |
+ if (key.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) |
+ if (key.aa_mode_ == NO_AA && key.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 InitializeTextureProgram(ContextProvider* context_provider, |
- TexCoordPrecision precision, |
- SamplerType sampler, |
- PremultipliedAlphaMode premultiplied_alpha, |
- bool has_background_color) { |
+ void InitializeTextureProgram(const ProgramKey& key) { |
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_.tex_coord_precision_ = key.precision_; |
+ fragment_shader_.sampler_type_ = key.sampler_; |
fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
fragment_shader_.has_varying_alpha_ = true; |
- if (premultiplied_alpha == NON_PREMULTIPLIED_ALPHA) |
+ if (key.premultiplied_alpha_ == NON_PREMULTIPLIED_ALPHA) |
fragment_shader_.has_premultiply_alpha_ = true; |
- fragment_shader_.has_background_color_ = has_background_color; |
- InitializeInternal(context_provider); |
+ fragment_shader_.has_background_color_ = key.has_background_color_; |
} |
- // 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) { |
+ void InitializeRenderPassProgram(const ProgramKey& key) { |
vertex_shader_.has_matrix_ = true; |
- if (aa_mode == NO_AA) { |
+ if (key.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; |
@@ -163,36 +242,32 @@ class ProgramBinding : public ProgramBindingBase { |
fragment_shader_.has_aa_ = true; |
} |
- fragment_shader_.tex_coord_precision_ = precision; |
- fragment_shader_.sampler_type_ = sampler; |
- fragment_shader_.blend_mode_ = blend_mode; |
+ fragment_shader_.tex_coord_precision_ = key.precision_; |
+ fragment_shader_.sampler_type_ = key.sampler_; |
+ fragment_shader_.blend_mode_ = key.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_.mask_for_background_ = key.mask_for_background_; |
+ fragment_shader_.has_color_matrix_ = key.has_color_matrix_; |
+ if (key.mask_mode_ == HAS_MASK) { |
fragment_shader_.has_mask_sampler_ = true; |
fragment_shader_.ignore_sampler_type_ = true; |
} else { |
- DCHECK(!mask_for_background); |
+ DCHECK(!key.mask_for_background_); |
} |
- |
- InitializeInternal(context_provider); |
} |
- void InitializeVideoStreamProgram(ContextProvider* context_provider, |
- TexCoordPrecision precision) { |
+ void InitializeVideoStreamProgram(const ProgramKey& key) { |
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_.tex_coord_precision_ = key.precision_; |
fragment_shader_.sampler_type_ = SAMPLER_TYPE_EXTERNAL_OES; |
fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
- |
- InitializeInternal(context_provider); |
} |
+ public: |
void InitializeVideoYUVProgram(ContextProvider* context_provider, |
TexCoordPrecision precision, |
SamplerType sampler, |