Commit a94e1212 authored by ccameron's avatar ccameron Committed by Commit bot

The great shader refactor: Separate initialization from ctor

This moves initialization of parameters to SetSubclassProperties.
The next step is to clean up initialization to use a common program
descriptor. In that patch, I'll change these functions to
CheckSubclassProperties, so that I can DCHECK that I didn't change
anything.

BUG=667966
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2626823002
Cr-Commit-Position: refs/heads/master@{#442761}
parent c9f9c596
...@@ -3658,10 +3658,9 @@ const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( ...@@ -3658,10 +3658,9 @@ const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram(
[use_color_lut]; [use_color_lut];
if (!program->initialized()) { if (!program->initialized()) {
TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, program->InitializeVideoYUV(output_surface_->context_provider(), precision,
use_color_lut); sampler, use_alpha_plane, use_nv12,
program->Initialize(output_surface_->context_provider(), precision, use_color_lut);
sampler);
} }
return program; return program;
} }
......
...@@ -62,16 +62,26 @@ class ProgramBinding : public ProgramBindingBase { ...@@ -62,16 +62,26 @@ class ProgramBinding : public ProgramBindingBase {
void Initialize(ContextProvider* context_provider, void Initialize(ContextProvider* context_provider,
TexCoordPrecision precision, TexCoordPrecision precision,
SamplerType sampler) { SamplerType sampler) {
return Initialize( Initialize(context_provider, precision, sampler, BLEND_MODE_NONE, false);
context_provider, precision, sampler, BLEND_MODE_NONE, false);
} }
void Initialize(ContextProvider* context_provider, void Initialize(ContextProvider* context_provider,
TexCoordPrecision precision, TexCoordPrecision precision,
SamplerType sampler, SamplerType sampler,
BlendMode blend_mode) { BlendMode blend_mode) {
return Initialize( Initialize(context_provider, precision, sampler, blend_mode, false);
context_provider, precision, sampler, blend_mode, false); }
void InitializeVideoYUV(ContextProvider* context_provider,
TexCoordPrecision precision,
SamplerType sampler,
bool use_alpha_plane,
bool use_nv12,
bool use_color_lut) {
fragment_shader_.use_alpha_texture_ = use_alpha_plane;
fragment_shader_.use_nv12_ = use_nv12;
fragment_shader_.use_color_lut_ = use_color_lut;
Initialize(context_provider, precision, sampler);
} }
void Initialize(ContextProvider* context_provider, void Initialize(ContextProvider* context_provider,
...@@ -79,19 +89,29 @@ class ProgramBinding : public ProgramBindingBase { ...@@ -79,19 +89,29 @@ class ProgramBinding : public ProgramBindingBase {
SamplerType sampler, SamplerType sampler,
BlendMode blend_mode, BlendMode blend_mode,
bool mask_for_background) { bool mask_for_background) {
vertex_shader_.SetSubclassProperties();
fragment_shader_.SetSubclassProperties();
fragment_shader_.blend_mode_ = blend_mode;
fragment_shader_.mask_for_background_ = mask_for_background;
fragment_shader_.tex_coord_precision_ = precision;
fragment_shader_.sampler_type_ = sampler;
InitializeInternal(context_provider);
}
const VertexShader& vertex_shader() const { return vertex_shader_; }
const FragmentShader& fragment_shader() const { return fragment_shader_; }
private:
void InitializeInternal(ContextProvider* context_provider) {
DCHECK(context_provider); DCHECK(context_provider);
DCHECK(!initialized_); DCHECK(!initialized_);
if (IsContextLost(context_provider->ContextGL())) if (IsContextLost(context_provider->ContextGL()))
return; return;
fragment_shader_.set_blend_mode(blend_mode); if (!ProgramBindingBase::Init(context_provider->ContextGL(),
fragment_shader_.set_mask_for_background(mask_for_background); vertex_shader_.GetShaderString(),
fragment_shader_.GetShaderString())) {
if (!ProgramBindingBase::Init(
context_provider->ContextGL(),
vertex_shader_.GetShaderString(),
fragment_shader_.GetShaderString(precision, sampler))) {
DCHECK(IsContextLost(context_provider->ContextGL())); DCHECK(IsContextLost(context_provider->ContextGL()));
return; return;
} }
...@@ -111,11 +131,6 @@ class ProgramBinding : public ProgramBindingBase { ...@@ -111,11 +131,6 @@ class ProgramBinding : public ProgramBindingBase {
initialized_ = true; 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_; VertexShader vertex_shader_;
FragmentShader fragment_shader_; FragmentShader fragment_shader_;
......
...@@ -198,7 +198,7 @@ void VertexShaderBase::Init(GLES2Interface* context, ...@@ -198,7 +198,7 @@ void VertexShaderBase::Init(GLES2Interface* context,
uniforms.push_back("matrix"); uniforms.push_back("matrix");
if (has_vertex_opacity_) if (has_vertex_opacity_)
uniforms.push_back("opacity"); uniforms.push_back("opacity");
if (has_aa_) { if (aa_mode_ == USE_AA) {
uniforms.push_back("viewport"); uniforms.push_back("viewport");
uniforms.push_back("edge"); uniforms.push_back("edge");
} }
...@@ -232,7 +232,7 @@ void VertexShaderBase::Init(GLES2Interface* context, ...@@ -232,7 +232,7 @@ void VertexShaderBase::Init(GLES2Interface* context,
matrix_location_ = locations[index++]; matrix_location_ = locations[index++];
if (has_vertex_opacity_) if (has_vertex_opacity_)
vertex_opacity_location_ = locations[index++]; vertex_opacity_location_ = locations[index++];
if (has_aa_) { if (aa_mode_ == USE_AA) {
viewport_location_ = locations[index++]; viewport_location_ = locations[index++];
edge_location_ = locations[index++]; edge_location_ = locations[index++];
} }
...@@ -298,7 +298,7 @@ std::string VertexShaderBase::GetShaderString() const { ...@@ -298,7 +298,7 @@ std::string VertexShaderBase::GetShaderString() const {
} }
// Compute the anti-aliasing edge distances. // Compute the anti-aliasing edge distances.
if (has_aa_) { if (aa_mode_ == USE_AA) {
HDR("uniform TexCoordPrecision vec3 edge[8];"); HDR("uniform TexCoordPrecision vec3 edge[8];");
HDR("uniform vec4 viewport;"); HDR("uniform vec4 viewport;");
HDR("varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances."); HDR("varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.");
...@@ -395,14 +395,14 @@ std::string VertexShaderBase::GetShaderString() const { ...@@ -395,14 +395,14 @@ std::string VertexShaderBase::GetShaderString() const {
FragmentShaderBase::FragmentShaderBase() {} FragmentShaderBase::FragmentShaderBase() {}
std::string FragmentShaderBase::GetShaderString(TexCoordPrecision precision, std::string FragmentShaderBase::GetShaderString() const {
SamplerType sampler) const { TexCoordPrecision precision = tex_coord_precision_;
// The AA shader values will use TexCoordPrecision. // The AA shader values will use TexCoordPrecision.
if (has_aa_ && precision == TEX_COORD_PRECISION_NA) if (aa_mode_ == USE_AA && precision == TEX_COORD_PRECISION_NA)
precision = TEX_COORD_PRECISION_MEDIUM; precision = TEX_COORD_PRECISION_MEDIUM;
return SetFragmentTexCoordPrecision( return SetFragmentTexCoordPrecision(
precision, SetFragmentSamplerType( precision, SetFragmentSamplerType(
sampler, SetBlendModeFunctions(GetShaderSource()))); sampler_type_, SetBlendModeFunctions(GetShaderSource())));
} }
void FragmentShaderBase::Init(GLES2Interface* context, void FragmentShaderBase::Init(GLES2Interface* context,
...@@ -415,7 +415,7 @@ void FragmentShaderBase::Init(GLES2Interface* context, ...@@ -415,7 +415,7 @@ void FragmentShaderBase::Init(GLES2Interface* context,
uniforms.push_back("s_originalBackdropTexture"); uniforms.push_back("s_originalBackdropTexture");
uniforms.push_back("backdropRect"); uniforms.push_back("backdropRect");
} }
if (has_mask_sampler_) { if (mask_mode_ != NO_MASK) {
uniforms.push_back("s_mask"); uniforms.push_back("s_mask");
uniforms.push_back("maskTexCoordScale"); uniforms.push_back("maskTexCoordScale");
uniforms.push_back("maskTexCoordOffset"); uniforms.push_back("maskTexCoordOffset");
...@@ -450,7 +450,7 @@ void FragmentShaderBase::Init(GLES2Interface* context, ...@@ -450,7 +450,7 @@ void FragmentShaderBase::Init(GLES2Interface* context,
original_backdrop_location_ = locations[index++]; original_backdrop_location_ = locations[index++];
backdrop_rect_location_ = locations[index++]; backdrop_rect_location_ = locations[index++];
} }
if (has_mask_sampler_) { if (mask_mode_ != NO_MASK) {
mask_sampler_location_ = locations[index++]; mask_sampler_location_ = locations[index++];
mask_tex_coord_scale_location_ = locations[index++]; mask_tex_coord_scale_location_ = locations[index++];
mask_tex_coord_offset_location_ = locations[index++]; mask_tex_coord_offset_location_ = locations[index++];
...@@ -481,9 +481,9 @@ void FragmentShaderBase::FillLocations(ShaderLocations* locations) const { ...@@ -481,9 +481,9 @@ void FragmentShaderBase::FillLocations(ShaderLocations* locations) const {
locations->backdrop = backdrop_location_; locations->backdrop = backdrop_location_;
locations->backdrop_rect = backdrop_rect_location_; locations->backdrop_rect = backdrop_rect_location_;
} }
if (mask_for_background()) if (mask_for_background_)
locations->original_backdrop = original_backdrop_location_; locations->original_backdrop = original_backdrop_location_;
if (has_mask_sampler_) { if (mask_mode_ != NO_MASK) {
locations->mask_sampler = mask_sampler_location_; locations->mask_sampler = mask_sampler_location_;
locations->mask_tex_coord_scale = mask_tex_coord_scale_location_; locations->mask_tex_coord_scale = mask_tex_coord_scale_location_;
locations->mask_tex_coord_offset = mask_tex_coord_offset_location_; locations->mask_tex_coord_offset = mask_tex_coord_offset_location_;
...@@ -519,7 +519,7 @@ std::string FragmentShaderBase::SetBlendModeFunctions( ...@@ -519,7 +519,7 @@ std::string FragmentShaderBase::SetBlendModeFunctions(
}); });
std::string mixFunction; std::string mixFunction;
if (mask_for_background()) { if (mask_for_background_) {
mixFunction = SHADER0([]() { mixFunction = SHADER0([]() {
vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) { vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) {
vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord); vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord);
...@@ -847,7 +847,7 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -847,7 +847,7 @@ std::string FragmentShaderBase::GetShaderSource() const {
} }
// Read the mask texture. // Read the mask texture.
if (has_mask_sampler_) { if (mask_mode_ != NO_MASK) {
HDR("uniform SamplerType s_mask;"); HDR("uniform SamplerType s_mask;");
HDR("uniform vec2 maskTexCoordScale;"); HDR("uniform vec2 maskTexCoordScale;");
HDR("uniform vec2 maskTexCoordOffset;"); HDR("uniform vec2 maskTexCoordOffset;");
...@@ -859,7 +859,7 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -859,7 +859,7 @@ std::string FragmentShaderBase::GetShaderSource() const {
} }
// Compute AA. // Compute AA.
if (has_aa_) { if (aa_mode_ == USE_AA) {
HDR("varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances."); HDR("varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.");
SRC("// Compute AA"); SRC("// Compute AA");
SRC("vec4 d4 = min(edge_dist[0], edge_dist[1]);"); SRC("vec4 d4 = min(edge_dist[0], edge_dist[1]);");
...@@ -868,7 +868,7 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -868,7 +868,7 @@ std::string FragmentShaderBase::GetShaderSource() const {
} }
// Premultiply by alpha. // Premultiply by alpha.
if (has_premultiply_alpha_) { if (premultiply_alpha_mode_ == NON_PREMULTIPLIED_ALPHA) {
SRC("// Premultiply alpha"); SRC("// Premultiply alpha");
SRC("texColor.rgb *= texColor.a;"); SRC("texColor.rgb *= texColor.a;");
} }
...@@ -881,7 +881,7 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -881,7 +881,7 @@ std::string FragmentShaderBase::GetShaderSource() const {
} }
// Apply swizzle. // Apply swizzle.
if (has_swizzle_) { if (swizzle_mode_ == DO_SWIZZLE) {
SRC("// Apply swizzle"); SRC("// Apply swizzle");
SRC("texColor = texColor.bgra;\n"); SRC("texColor = texColor.bgra;\n");
} }
...@@ -895,17 +895,17 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -895,17 +895,17 @@ std::string FragmentShaderBase::GetShaderSource() const {
} }
// Apply uniform alpha, aa, varying alpha, and the mask. // Apply uniform alpha, aa, varying alpha, and the mask.
if (has_varying_alpha_ || has_aa_ || has_uniform_alpha_ || if (has_varying_alpha_ || aa_mode_ == USE_AA || has_uniform_alpha_ ||
has_mask_sampler_) { mask_mode_ != NO_MASK) {
SRC("// Apply alpha from uniform, varying, aa, and mask."); SRC("// Apply alpha from uniform, varying, aa, and mask.");
std::string line = " texColor = texColor"; std::string line = " texColor = texColor";
if (has_varying_alpha_) if (has_varying_alpha_)
line += " * v_alpha"; line += " * v_alpha";
if (has_uniform_alpha_) if (has_uniform_alpha_)
line += " * alpha"; line += " * alpha";
if (has_aa_) if (aa_mode_ == USE_AA)
line += " * aa"; line += " * aa";
if (has_mask_sampler_) if (mask_mode_ != NO_MASK)
line += " * maskColor.a"; line += " * maskColor.a";
line += ";\n"; line += ";\n";
source += line; source += line;
...@@ -923,7 +923,7 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -923,7 +923,7 @@ std::string FragmentShaderBase::GetShaderSource() const {
SRC("gl_FragColor = vec4(texColor.rgb, 1.0);"); SRC("gl_FragColor = vec4(texColor.rgb, 1.0);");
break; break;
case FRAG_COLOR_MODE_APPLY_BLEND_MODE: case FRAG_COLOR_MODE_APPLY_BLEND_MODE:
if (has_mask_sampler_) if (mask_mode_ != NO_MASK)
SRC("gl_FragColor = ApplyBlendMode(texColor, maskColor.w);"); SRC("gl_FragColor = ApplyBlendMode(texColor, maskColor.w);");
else else
SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);");
...@@ -936,14 +936,6 @@ std::string FragmentShaderBase::GetShaderSource() const { ...@@ -936,14 +936,6 @@ std::string FragmentShaderBase::GetShaderSource() const {
FragmentShaderYUVVideo::FragmentShaderYUVVideo() {} FragmentShaderYUVVideo::FragmentShaderYUVVideo() {}
void FragmentShaderYUVVideo::SetFeatures(bool use_alpha_texture,
bool use_nv12,
bool use_color_lut) {
use_alpha_texture_ = use_alpha_texture;
use_nv12_ = use_nv12;
use_color_lut_ = use_color_lut;
}
void FragmentShaderYUVVideo::Init(GLES2Interface* context, void FragmentShaderYUVVideo::Init(GLES2Interface* context,
unsigned program, unsigned program,
int* base_uniform_index) { int* base_uniform_index) {
......
...@@ -62,6 +62,21 @@ enum PositionSource { ...@@ -62,6 +62,21 @@ enum PositionSource {
POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM, 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 { enum SamplerType {
SAMPLER_TYPE_NA = 0, SAMPLER_TYPE_NA = 0,
SAMPLER_TYPE_2D = 1, SAMPLER_TYPE_2D = 1,
...@@ -175,6 +190,9 @@ class VertexShaderBase { ...@@ -175,6 +190,9 @@ class VertexShaderBase {
int quad_location() const { return quad_location_; } int quad_location() const { return quad_location_; }
protected: protected:
template <class VertexShader, class FragmentShader>
friend class ProgramBinding;
// Use arrays of uniforms for matrix, texTransform, and opacity. // Use arrays of uniforms for matrix, texTransform, and opacity.
bool use_uniform_arrays_ = false; bool use_uniform_arrays_ = false;
...@@ -210,14 +228,14 @@ class VertexShaderBase { ...@@ -210,14 +228,14 @@ class VertexShaderBase {
bool has_vertex_opacity_ = false; bool has_vertex_opacity_ = false;
int vertex_opacity_location_ = -1; int vertex_opacity_location_ = -1;
bool has_aa_ = false; AAMode aa_mode_ = NO_AA;
int viewport_location_ = -1; int viewport_location_ = -1;
int edge_location_ = -1; int edge_location_ = -1;
}; };
class VertexShaderPosTex : public VertexShaderBase { class VertexShaderPosTex : public VertexShaderBase {
public: public:
VertexShaderPosTex() { void SetSubclassProperties() {
tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
has_matrix_ = true; has_matrix_ = true;
} }
...@@ -225,7 +243,7 @@ class VertexShaderPosTex : public VertexShaderBase { ...@@ -225,7 +243,7 @@ class VertexShaderPosTex : public VertexShaderBase {
class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase { class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase {
public: public:
VertexShaderPosTexYUVStretchOffset() { void SetSubclassProperties() {
tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
has_matrix_ = true; has_matrix_ = true;
is_ya_uv_ = true; is_ya_uv_ = true;
...@@ -234,12 +252,12 @@ class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase { ...@@ -234,12 +252,12 @@ class VertexShaderPosTexYUVStretchOffset : public VertexShaderBase {
class VertexShaderPos : public VertexShaderBase { class VertexShaderPos : public VertexShaderBase {
public: public:
VertexShaderPos() { has_matrix_ = true; } void SetSubclassProperties() { has_matrix_ = true; }
}; };
class VertexShaderPosTexTransform : public VertexShaderBase { class VertexShaderPosTexTransform : public VertexShaderBase {
public: public:
VertexShaderPosTexTransform() { void SetSubclassProperties() {
tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
has_matrix_ = true; has_matrix_ = true;
...@@ -250,7 +268,7 @@ class VertexShaderPosTexTransform : public VertexShaderBase { ...@@ -250,7 +268,7 @@ class VertexShaderPosTexTransform : public VertexShaderBase {
class VertexShaderQuad : public VertexShaderBase { class VertexShaderQuad : public VertexShaderBase {
public: public:
VertexShaderQuad() { void SetSubclassProperties() {
position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
has_matrix_ = true; has_matrix_ = true;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -261,27 +279,27 @@ class VertexShaderQuad : public VertexShaderBase { ...@@ -261,27 +279,27 @@ class VertexShaderQuad : public VertexShaderBase {
class VertexShaderQuadAA : public VertexShaderBase { class VertexShaderQuadAA : public VertexShaderBase {
public: public:
VertexShaderQuadAA() { void SetSubclassProperties() {
position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
has_matrix_ = true; has_matrix_ = true;
has_aa_ = true; aa_mode_ = USE_AA;
} }
}; };
class VertexShaderQuadTexTransformAA : public VertexShaderBase { class VertexShaderQuadTexTransformAA : public VertexShaderBase {
public: public:
VertexShaderQuadTexTransformAA() { void SetSubclassProperties() {
position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
tex_coord_source_ = TEX_COORD_SOURCE_POSITION; tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4;
has_matrix_ = true; has_matrix_ = true;
has_aa_ = true; aa_mode_ = USE_AA;
} }
}; };
class VertexShaderTile : public VertexShaderBase { class VertexShaderTile : public VertexShaderBase {
public: public:
VertexShaderTile() { void SetSubclassProperties() {
position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
...@@ -291,18 +309,18 @@ class VertexShaderTile : public VertexShaderBase { ...@@ -291,18 +309,18 @@ class VertexShaderTile : public VertexShaderBase {
class VertexShaderTileAA : public VertexShaderBase { class VertexShaderTileAA : public VertexShaderBase {
public: public:
VertexShaderTileAA() { void SetSubclassProperties() {
position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
tex_coord_source_ = TEX_COORD_SOURCE_POSITION; tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4;
has_matrix_ = true; has_matrix_ = true;
has_aa_ = true; aa_mode_ = USE_AA;
} }
}; };
class VertexShaderVideoTransform : public VertexShaderBase { class VertexShaderVideoTransform : public VertexShaderBase {
public: public:
VertexShaderVideoTransform() { void SetSubclassProperties() {
tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX;
has_matrix_ = true; has_matrix_ = true;
...@@ -314,18 +332,9 @@ class FragmentShaderBase { ...@@ -314,18 +332,9 @@ class FragmentShaderBase {
virtual void Init(gpu::gles2::GLES2Interface* context, virtual void Init(gpu::gles2::GLES2Interface* context,
unsigned program, unsigned program,
int* base_uniform_index); int* base_uniform_index);
std::string GetShaderString(TexCoordPrecision precision, std::string GetShaderString() const;
SamplerType sampler) const;
void FillLocations(ShaderLocations* locations) 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 sampler_location() const { return sampler_location_; }
int alpha_location() const { return alpha_location_; } int alpha_location() const { return alpha_location_; }
int color_location() const { return color_location_; } int color_location() const { return color_location_; }
...@@ -337,14 +346,15 @@ class FragmentShaderBase { ...@@ -337,14 +346,15 @@ class FragmentShaderBase {
protected: protected:
FragmentShaderBase(); FragmentShaderBase();
virtual std::string GetShaderSource() const; 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; std::string SetBlendModeFunctions(const std::string& shader_string) const;
// Settings that are modified by sub-classes. // Settings that are modified by sub-classes.
bool has_aa_ = false; AAMode aa_mode_ = NO_AA;
bool has_varying_alpha_ = false; bool has_varying_alpha_ = false;
bool has_swizzle_ = false; SwizzleMode swizzle_mode_ = NO_SWIZZLE;
bool has_premultiply_alpha_ = false; PremultipliedAlphaMode premultiply_alpha_mode_ = PREMULTIPLIED_ALPHA;
FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; FragColorMode frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE; InputColorSource input_color_type_ = INPUT_COLOR_SOURCE_RGBA_TEXTURE;
...@@ -367,7 +377,7 @@ class FragmentShaderBase { ...@@ -367,7 +377,7 @@ class FragmentShaderBase {
// Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM. // Used only if |input_color_type_| is INPUT_COLOR_SOURCE_UNIFORM.
int color_location_ = -1; int color_location_ = -1;
bool has_mask_sampler_ = false; MaskMode mask_mode_ = NO_MASK;
int mask_sampler_location_ = -1; int mask_sampler_location_ = -1;
int mask_tex_coord_scale_location_ = -1; int mask_tex_coord_scale_location_ = -1;
int mask_tex_coord_offset_location_ = -1; int mask_tex_coord_offset_location_ = -1;
...@@ -382,10 +392,16 @@ class FragmentShaderBase { ...@@ -382,10 +392,16 @@ class FragmentShaderBase {
bool has_background_color_ = false; bool has_background_color_ = false;
int background_color_location_ = -1; 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; BlendMode blend_mode_ = BLEND_MODE_NONE;
bool mask_for_background_ = false; bool mask_for_background_ = false;
private:
template <class VertexShader, class FragmentShader>
friend class ProgramBinding;
std::string GetHelperFunctions() const; std::string GetHelperFunctions() const;
std::string GetBlendFunction() const; std::string GetBlendFunction() const;
std::string GetBlendFunctionBodyForRGB() const; std::string GetBlendFunctionBodyForRGB() const;
...@@ -395,7 +411,7 @@ class FragmentShaderBase { ...@@ -395,7 +411,7 @@ class FragmentShaderBase {
class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase { class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexVaryingAlpha() { void SetSubclassProperties() {
has_varying_alpha_ = true; has_varying_alpha_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
...@@ -403,16 +419,16 @@ class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase { ...@@ -403,16 +419,16 @@ class FragmentShaderRGBATexVaryingAlpha : public FragmentShaderBase {
class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase { class FragmentShaderRGBATexPremultiplyAlpha : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexPremultiplyAlpha() { void SetSubclassProperties() {
has_varying_alpha_ = true; has_varying_alpha_ = true;
has_premultiply_alpha_ = true; premultiply_alpha_mode_ = NON_PREMULTIPLIED_ALPHA;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
}; };
class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase { class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
public: public:
FragmentShaderTexBackgroundVaryingAlpha() { void SetSubclassProperties() {
has_background_color_ = true; has_background_color_ = true;
has_varying_alpha_ = true; has_varying_alpha_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
...@@ -421,17 +437,17 @@ class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase { ...@@ -421,17 +437,17 @@ class FragmentShaderTexBackgroundVaryingAlpha : public FragmentShaderBase {
class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase { class FragmentShaderTexBackgroundPremultiplyAlpha : public FragmentShaderBase {
public: public:
FragmentShaderTexBackgroundPremultiplyAlpha() { void SetSubclassProperties() {
has_background_color_ = true; has_background_color_ = true;
has_varying_alpha_ = true; has_varying_alpha_ = true;
has_premultiply_alpha_ = true; premultiply_alpha_mode_ = NON_PREMULTIPLIED_ALPHA;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
}; };
class FragmentShaderRGBATexAlpha : public FragmentShaderBase { class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlpha() { void SetSubclassProperties() {
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
} }
...@@ -439,7 +455,7 @@ class FragmentShaderRGBATexAlpha : public FragmentShaderBase { ...@@ -439,7 +455,7 @@ class FragmentShaderRGBATexAlpha : public FragmentShaderBase {
class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase { class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexColorMatrixAlpha() { void SetSubclassProperties() {
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_color_matrix_ = true; has_color_matrix_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
...@@ -448,20 +464,20 @@ class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase { ...@@ -448,20 +464,20 @@ class FragmentShaderRGBATexColorMatrixAlpha : public FragmentShaderBase {
class FragmentShaderRGBATexOpaque : public FragmentShaderBase { class FragmentShaderRGBATexOpaque : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexOpaque() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; } void SetSubclassProperties() { frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; }
}; };
class FragmentShaderRGBATex : public FragmentShaderBase { class FragmentShaderRGBATex : public FragmentShaderBase {
public: public:
FragmentShaderRGBATex() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; } void SetSubclassProperties() { frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; }
}; };
// Swizzles the red and blue component of sampled texel with alpha. // Swizzles the red and blue component of sampled texel with alpha.
class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase { class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexSwizzleAlpha() { void SetSubclassProperties() {
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_swizzle_ = true; swizzle_mode_ = DO_SWIZZLE;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
}; };
...@@ -469,16 +485,16 @@ class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase { ...@@ -469,16 +485,16 @@ class FragmentShaderRGBATexSwizzleAlpha : public FragmentShaderBase {
// Swizzles the red and blue component of sampled texel without alpha. // Swizzles the red and blue component of sampled texel without alpha.
class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase { class FragmentShaderRGBATexSwizzleOpaque : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexSwizzleOpaque() { void SetSubclassProperties() {
has_swizzle_ = true; swizzle_mode_ = DO_SWIZZLE;
frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE;
} }
}; };
class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
} }
...@@ -486,8 +502,8 @@ class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase { ...@@ -486,8 +502,8 @@ class FragmentShaderRGBATexAlphaAA : public FragmentShaderBase {
class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase { class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexClampAlphaAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_rgba_fragment_tex_transform_ = true; has_rgba_fragment_tex_transform_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
...@@ -497,20 +513,20 @@ class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase { ...@@ -497,20 +513,20 @@ class FragmentShaderRGBATexClampAlphaAA : public FragmentShaderBase {
// Swizzles the red and blue component of sampled texel. // Swizzles the red and blue component of sampled texel.
class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase { class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexClampSwizzleAlphaAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_rgba_fragment_tex_transform_ = true; has_rgba_fragment_tex_transform_ = true;
has_swizzle_ = true; swizzle_mode_ = DO_SWIZZLE;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
}; };
class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaMask() { void SetSubclassProperties() {
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_mask_sampler_ = true; mask_mode_ = HAS_MASK;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
ignore_sampler_type_ = true; ignore_sampler_type_ = true;
} }
...@@ -518,10 +534,10 @@ class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase { ...@@ -518,10 +534,10 @@ class FragmentShaderRGBATexAlphaMask : public FragmentShaderBase {
class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaMaskAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_mask_sampler_ = true; mask_mode_ = HAS_MASK;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
ignore_sampler_type_ = true; ignore_sampler_type_ = true;
} }
...@@ -529,10 +545,10 @@ class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase { ...@@ -529,10 +545,10 @@ class FragmentShaderRGBATexAlphaMaskAA : public FragmentShaderBase {
class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaMaskColorMatrixAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_mask_sampler_ = true; mask_mode_ = HAS_MASK;
has_color_matrix_ = true; has_color_matrix_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
ignore_sampler_type_ = true; ignore_sampler_type_ = true;
...@@ -541,8 +557,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase { ...@@ -541,8 +557,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrixAA : public FragmentShaderBase {
class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaColorMatrixAA() { void SetSubclassProperties() {
has_aa_ = true; aa_mode_ = USE_AA;
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_color_matrix_ = true; has_color_matrix_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
...@@ -551,9 +567,9 @@ class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase { ...@@ -551,9 +567,9 @@ class FragmentShaderRGBATexAlphaColorMatrixAA : public FragmentShaderBase {
class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
public: public:
FragmentShaderRGBATexAlphaMaskColorMatrix() { void SetSubclassProperties() {
has_uniform_alpha_ = true; has_uniform_alpha_ = true;
has_mask_sampler_ = true; mask_mode_ = HAS_MASK;
has_color_matrix_ = true; has_color_matrix_ = true;
frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
ignore_sampler_type_ = true; ignore_sampler_type_ = true;
...@@ -563,7 +579,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase { ...@@ -563,7 +579,8 @@ class FragmentShaderRGBATexAlphaMaskColorMatrix : public FragmentShaderBase {
class FragmentShaderYUVVideo : public FragmentShaderBase { class FragmentShaderYUVVideo : public FragmentShaderBase {
public: public:
FragmentShaderYUVVideo(); FragmentShaderYUVVideo();
void SetFeatures(bool use_alpha_texture, bool use_nv12, bool use_color_lut);
void SetSubclassProperties() {}
void Init(gpu::gles2::GLES2Interface* context, void Init(gpu::gles2::GLES2Interface* context,
unsigned program, unsigned program,
...@@ -585,6 +602,9 @@ class FragmentShaderYUVVideo : public FragmentShaderBase { ...@@ -585,6 +602,9 @@ class FragmentShaderYUVVideo : public FragmentShaderBase {
int resource_offset_location() const { return resource_offset_location_; } int resource_offset_location() const { return resource_offset_location_; }
private: private:
template <class VertexShader, class FragmentShader>
friend class ProgramBinding;
std::string GetShaderSource() const override; std::string GetShaderSource() const override;
bool use_alpha_texture_ = false; bool use_alpha_texture_ = false;
...@@ -608,7 +628,7 @@ class FragmentShaderYUVVideo : public FragmentShaderBase { ...@@ -608,7 +628,7 @@ class FragmentShaderYUVVideo : public FragmentShaderBase {
class FragmentShaderColor : public FragmentShaderBase { class FragmentShaderColor : public FragmentShaderBase {
public: public:
FragmentShaderColor() { void SetSubclassProperties() {
input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
...@@ -616,9 +636,9 @@ class FragmentShaderColor : public FragmentShaderBase { ...@@ -616,9 +636,9 @@ class FragmentShaderColor : public FragmentShaderBase {
class FragmentShaderColorAA : public FragmentShaderBase { class FragmentShaderColorAA : public FragmentShaderBase {
public: public:
FragmentShaderColorAA() { void SetSubclassProperties() {
input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM;
has_aa_ = true; aa_mode_ = USE_AA;
frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT;
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment