summaryrefslogtreecommitdiffstats
path: root/cc/output
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 03:39:05 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-09 03:39:05 +0000
commit59bb8a3ea04a518bf907881d3d10e2f070416dbe (patch)
treea778df3e689b83e2cd0580f88171e183643a2434 /cc/output
parent6fd3b3f810a20b4a257eee9eb5ff32b23aebd758 (diff)
downloadchromium_src-59bb8a3ea04a518bf907881d3d10e2f070416dbe.zip
chromium_src-59bb8a3ea04a518bf907881d3d10e2f070416dbe.tar.gz
chromium_src-59bb8a3ea04a518bf907881d3d10e2f070416dbe.tar.bz2
Re-land: cc: Cleanup vertex shaders used for anti-aliasing.
Splits VertexShaderQuad into VertexShaderQuad and VertexShaderQuadTex. VertexShaderQuadTex is used for drawing textures and VertexShaderQuad is used for solid color. Use array indexing in VertexShaderQuad program. BUG=238644 TEST=cc_unittests --gtest_filter=GLRendererPixelTest.AntiAliasing R=enne@chromium.org Review URL: https://chromiumcodereview.appspot.com/12720017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/output')
-rw-r--r--cc/output/gl_renderer.cc43
-rw-r--r--cc/output/gl_renderer.h8
-rw-r--r--cc/output/shader.cc91
-rw-r--r--cc/output/shader.h30
4 files changed, 112 insertions, 60 deletions
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index f492b10d..34807ff 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -794,7 +794,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
GLC(Context(),
Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
- shader_quad_location = program->vertex_shader().point_location();
+ shader_quad_location = program->vertex_shader().quad_location();
shader_edge_location = program->fragment_shader().edge_location();
shader_mask_sampler_location =
program->fragment_shader().mask_sampler_location();
@@ -829,7 +829,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
GLC(Context(),
Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
- shader_quad_location = program->vertex_shader().point_location();
+ shader_quad_location = program->vertex_shader().quad_location();
shader_edge_location = program->fragment_shader().edge_location();
shader_matrix_location = program->vertex_shader().matrix_location();
shader_alpha_location = program->fragment_shader().alpha_location();
@@ -842,7 +842,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
shader_matrix_location = program->vertex_shader().matrix_location();
- shader_quad_location = program->vertex_shader().point_location();
+ shader_quad_location = program->vertex_shader().quad_location();
shader_tex_scale_location = program->vertex_shader().tex_scale_location();
shader_edge_location = program->fragment_shader().edge_location();
shader_alpha_location = program->fragment_shader().alpha_location();
@@ -864,7 +864,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
shader_matrix_location = program->vertex_shader().matrix_location();
- shader_quad_location = program->vertex_shader().point_location();
+ shader_quad_location = program->vertex_shader().quad_location();
shader_tex_scale_location = program->vertex_shader().tex_scale_location();
shader_edge_location = program->fragment_shader().edge_location();
shader_alpha_location = program->fragment_shader().alpha_location();
@@ -1009,8 +1009,7 @@ struct SolidColorProgramUniforms {
unsigned program;
unsigned matrix_location;
unsigned color_location;
- unsigned point_location;
- unsigned tex_scale_location;
+ unsigned quad_location;
unsigned edge_location;
};
@@ -1020,8 +1019,7 @@ static void SolidColorUniformLocation(T program,
uniforms->program = program->program();
uniforms->matrix_location = program->vertex_shader().matrix_location();
uniforms->color_location = program->fragment_shader().color_location();
- uniforms->point_location = program->vertex_shader().point_location();
- uniforms->tex_scale_location = program->vertex_shader().tex_scale_location();
+ uniforms->quad_location = program->vertex_shader().quad_location();
uniforms->edge_location = program->fragment_shader().edge_location();
}
@@ -1112,7 +1110,6 @@ bool GLRenderer::SetupQuadForAntialiasing(
void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
const SolidColorDrawQuad* quad) {
- SetBlendEnabled(quad->ShouldDrawWithBlending());
gfx::Rect tile_rect = quad->visible_rect;
SkColor color = quad->color;
@@ -1159,7 +1156,7 @@ void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
// Normalize to tile_rect.
local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
- SetShaderQuadF(local_quad, uniforms.point_location);
+ SetShaderQuadF(local_quad, uniforms.quad_location);
// The transform and vertex data are used to figure out the extents that the
// un-antialiased quad should have and which vertex this is and the float
@@ -1180,7 +1177,7 @@ struct TileProgramUniforms {
unsigned edge_location;
unsigned matrix_location;
unsigned alpha_location;
- unsigned point_location;
+ unsigned quad_location;
};
template <class T>
@@ -1189,7 +1186,7 @@ static void TileUniformLocation(T program, TileProgramUniforms* uniforms) {
uniforms->vertex_tex_transform_location =
program->vertex_shader().vertex_tex_transform_location();
uniforms->matrix_location = program->vertex_shader().matrix_location();
- uniforms->point_location = program->vertex_shader().point_location();
+ uniforms->quad_location = program->vertex_shader().quad_location();
uniforms->sampler_location = program->fragment_shader().sampler_location();
uniforms->alpha_location = program->fragment_shader().alpha_location();
@@ -1353,7 +1350,7 @@ void GLRenderer::DrawContentQuad(const DrawingFrame* frame,
local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
SetShaderOpacity(quad->opacity(), uniforms.alpha_location);
- SetShaderQuadF(local_quad, uniforms.point_location);
+ SetShaderQuadF(local_quad, uniforms.quad_location);
// The transform and vertex data are used to figure out the extents that the
// un-antialiased quad should have and which vertex this is and the float
@@ -1820,16 +1817,16 @@ void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad, int quad_location) {
if (quad_location == -1)
return;
- float point[8];
- point[0] = quad.p1().x();
- point[1] = quad.p1().y();
- point[2] = quad.p2().x();
- point[3] = quad.p2().y();
- point[4] = quad.p3().x();
- point[5] = quad.p3().y();
- point[6] = quad.p4().x();
- point[7] = quad.p4().y();
- GLC(context_, context_->uniform2fv(quad_location, 4, point));
+ float gl_quad[8];
+ gl_quad[0] = quad.p1().x();
+ gl_quad[1] = quad.p1().y();
+ gl_quad[2] = quad.p2().x();
+ gl_quad[3] = quad.p2().y();
+ gl_quad[4] = quad.p3().x();
+ gl_quad[5] = quad.p3().y();
+ gl_quad[6] = quad.p4().x();
+ gl_quad[7] = quad.p4().y();
+ GLC(context_, context_->uniform2fv(quad_location, 4, gl_quad));
}
void GLRenderer::SetShaderOpacity(float opacity, int alpha_location) {
diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h
index 1c1ecb8..c83169d 100644
--- a/cc/output/gl_renderer.h
+++ b/cc/output/gl_renderer.h
@@ -256,17 +256,17 @@ class CC_EXPORT GLRenderer
FragmentShaderRGBATexAlpha> RenderPassProgram;
typedef ProgramBinding<VertexShaderPosTexTransform,
FragmentShaderRGBATexAlphaMask> RenderPassMaskProgram;
- typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaAA>
+ typedef ProgramBinding<VertexShaderQuadTex, FragmentShaderRGBATexAlphaAA>
RenderPassProgramAA;
- typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA>
+ typedef ProgramBinding<VertexShaderQuadTex, FragmentShaderRGBATexAlphaMaskAA>
RenderPassMaskProgramAA;
typedef ProgramBinding<VertexShaderPosTexTransform,
FragmentShaderRGBATexColorMatrixAlpha>
RenderPassColorMatrixProgram;
- typedef ProgramBinding<VertexShaderQuad,
+ typedef ProgramBinding<VertexShaderQuadTex,
FragmentShaderRGBATexAlphaMaskColorMatrixAA>
RenderPassMaskColorMatrixProgramAA;
- typedef ProgramBinding<VertexShaderQuad,
+ typedef ProgramBinding<VertexShaderQuadTex,
FragmentShaderRGBATexAlphaColorMatrixAA>
RenderPassColorMatrixProgramAA;
typedef ProgramBinding<VertexShaderPosTexTransform,
diff --git a/cc/output/shader.cc b/cc/output/shader.cc
index aaaeefb..c4ffd0e 100644
--- a/cc/output/shader.cc
+++ b/cc/output/shader.cc
@@ -323,8 +323,7 @@ std::string VertexShaderPosTexIdentity::GetShaderString() const {
VertexShaderQuad::VertexShaderQuad()
: matrix_location_(-1),
- point_location_(-1),
- tex_scale_location_(-1) {}
+ quad_location_(-1) {}
void VertexShaderQuad::Init(WebGraphicsContext3D* context,
unsigned program,
@@ -332,7 +331,51 @@ void VertexShaderQuad::Init(WebGraphicsContext3D* context,
int* base_uniform_index) {
static const char* shader_uniforms[] = {
"matrix",
- "point",
+ "quad",
+ };
+ int locations[2];
+
+ GetProgramUniformLocations(context,
+ program,
+ shader_uniforms,
+ arraysize(shader_uniforms),
+ arraysize(locations),
+ locations,
+ using_bind_uniform,
+ base_uniform_index);
+
+ matrix_location_ = locations[0];
+ quad_location_ = locations[1];
+ DCHECK_NE(matrix_location_, -1);
+ DCHECK_NE(quad_location_, -1);
+}
+
+std::string VertexShaderQuad::GetShaderString() const {
+ return VERTEX_SHADER(
+ attribute TexCoordPrecision vec4 a_position;
+ attribute float a_index;
+ uniform mat4 matrix;
+ uniform TexCoordPrecision vec2 quad[4];
+ void main() {
+ vec2 pos = quad[int(a_index)]; // NOLINT
+ gl_Position = matrix * vec4(
+ pos.x, pos.y, a_position.z, a_position.w);
+ }
+ ); // NOLINT(whitespace/parens)
+}
+
+VertexShaderQuadTex::VertexShaderQuadTex()
+ : matrix_location_(-1),
+ quad_location_(-1),
+ tex_scale_location_(-1) {}
+
+void VertexShaderQuadTex::Init(WebGraphicsContext3D* context,
+ unsigned program,
+ bool using_bind_uniform,
+ int* base_uniform_index) {
+ static const char* shader_uniforms[] = {
+ "matrix",
+ "quad",
"texScale",
};
int locations[3];
@@ -347,29 +390,25 @@ void VertexShaderQuad::Init(WebGraphicsContext3D* context,
base_uniform_index);
matrix_location_ = locations[0];
- point_location_ = locations[1];
+ quad_location_ = locations[1];
tex_scale_location_ = locations[2];
DCHECK_NE(matrix_location_, -1);
- DCHECK_NE(point_location_, -1);
+ DCHECK_NE(quad_location_, -1);
DCHECK_NE(tex_scale_location_, -1);
}
-std::string VertexShaderQuad::GetShaderString() const {
+std::string VertexShaderQuadTex::GetShaderString() const {
return VERTEX_SHADER(
attribute TexCoordPrecision vec4 a_position;
- attribute TexCoordPrecision vec2 a_texCoord;
+ attribute float a_index;
uniform mat4 matrix;
- uniform TexCoordPrecision vec2 point[4];
+ uniform TexCoordPrecision vec2 quad[4];
uniform TexCoordPrecision vec2 texScale;
varying TexCoordPrecision vec2 v_texCoord;
void main() {
- TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0);
- TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
- pos.xy += (complement.x * complement.y) * point[0];
- pos.xy += (a_texCoord.x * complement.y) * point[1];
- pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
- pos.xy += (complement.x * a_texCoord.y) * point[3];
- gl_Position = matrix * pos;
+ vec2 pos = quad[int(a_index)]; // NOLINT
+ gl_Position = matrix * vec4(
+ pos.x, pos.y, a_position.z, a_position.w);
v_texCoord = (pos.xy + vec2(0.5)) * texScale;
}
); // NOLINT(whitespace/parens)
@@ -377,7 +416,7 @@ std::string VertexShaderQuad::GetShaderString() const {
VertexShaderTile::VertexShaderTile()
: matrix_location_(-1),
- point_location_(-1),
+ quad_location_(-1),
vertex_tex_transform_location_(-1) {}
void VertexShaderTile::Init(WebGraphicsContext3D* context,
@@ -386,7 +425,7 @@ void VertexShaderTile::Init(WebGraphicsContext3D* context,
int* base_uniform_index) {
static const char* shader_uniforms[] = {
"matrix",
- "point",
+ "quad",
"vertexTexTransform",
};
int locations[3];
@@ -401,28 +440,24 @@ void VertexShaderTile::Init(WebGraphicsContext3D* context,
base_uniform_index);
matrix_location_ = locations[0];
- point_location_ = locations[1];
+ quad_location_ = locations[1];
vertex_tex_transform_location_ = locations[2];
- DCHECK(matrix_location_ != -1 && point_location_ != -1 &&
+ DCHECK(matrix_location_ != -1 && quad_location_ != -1 &&
vertex_tex_transform_location_ != -1);
}
std::string VertexShaderTile::GetShaderString() const {
return VERTEX_SHADER(
attribute TexCoordPrecision vec4 a_position;
- attribute TexCoordPrecision vec2 a_texCoord;
+ attribute float a_index;
uniform mat4 matrix;
- uniform TexCoordPrecision vec2 point[4];
+ uniform TexCoordPrecision vec2 quad[4];
uniform TexCoordPrecision vec4 vertexTexTransform;
varying TexCoordPrecision vec2 v_texCoord;
void main() {
- TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0);
- TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
- pos.xy += (complement.x * complement.y) * point[0];
- pos.xy += (a_texCoord.x * complement.y) * point[1];
- pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
- pos.xy += (complement.x * a_texCoord.y) * point[3];
- gl_Position = matrix * pos;
+ vec2 pos = quad[int(a_index)]; // NOLINT
+ gl_Position = matrix * vec4(
+ pos.x, pos.y, a_position.z, a_position.w);
v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
}
); // NOLINT(whitespace/parens)
diff --git a/cc/output/shader.h b/cc/output/shader.h
index 155efce..9b76ca2c 100644
--- a/cc/output/shader.h
+++ b/cc/output/shader.h
@@ -147,15 +147,35 @@ class VertexShaderQuad {
std::string GetShaderString() const;
int matrix_location() const { return matrix_location_; }
- int point_location() const { return point_location_; }
+ int quad_location() const { return quad_location_; }
+
+ private:
+ int matrix_location_;
+ int quad_location_;
+
+ DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
+};
+
+class VertexShaderQuadTex {
+ public:
+ VertexShaderQuadTex();
+
+ void Init(WebKit::WebGraphicsContext3D* context,
+ unsigned program,
+ bool using_bind_uniform,
+ int* base_uniform_index);
+ std::string GetShaderString() const;
+
+ int matrix_location() const { return matrix_location_; }
+ int quad_location() const { return quad_location_; }
int tex_scale_location() const { return tex_scale_location_; }
private:
int matrix_location_;
- int point_location_;
+ int quad_location_;
int tex_scale_location_;
- DISALLOW_COPY_AND_ASSIGN(VertexShaderQuad);
+ DISALLOW_COPY_AND_ASSIGN(VertexShaderQuadTex);
};
class VertexShaderTile {
@@ -169,14 +189,14 @@ class VertexShaderTile {
std::string GetShaderString() const;
int matrix_location() const { return matrix_location_; }
- int point_location() const { return point_location_; }
+ int quad_location() const { return quad_location_; }
int vertex_tex_transform_location() const {
return vertex_tex_transform_location_;
}
private:
int matrix_location_;
- int point_location_;
+ int quad_location_;
int vertex_tex_transform_location_;
DISALLOW_COPY_AND_ASSIGN(VertexShaderTile);