Chromium Code Reviews| Index: cc/gl_renderer.cc |
| diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc |
| index de6cfc169e3ee1571ba0c8f3119cc7d3354b15fa..a185f65ec0a3dd38f3303011b5da322af69f9c6c 100644 |
| --- a/cc/gl_renderer.cc |
| +++ b/cc/gl_renderer.cc |
| @@ -698,7 +698,7 @@ struct TileProgramUniforms { |
| unsigned program; |
| unsigned samplerLocation; |
| unsigned vertexTexTransformLocation; |
| - unsigned fragmentTexTransformLocation; |
| + unsigned fragmentTexClampLocation; |
| unsigned edgeLocation; |
| unsigned matrixLocation; |
| unsigned alphaLocation; |
| @@ -715,15 +715,16 @@ static void tileUniformLocation(T program, TileProgramUniforms& uniforms) |
| uniforms.samplerLocation = program->fragmentShader().samplerLocation(); |
| uniforms.alphaLocation = program->fragmentShader().alphaLocation(); |
| - uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTexTransformLocation(); |
| + uniforms.fragmentTexClampLocation = program->fragmentShader().fragmentTexClampLocation(); |
| uniforms.edgeLocation = program->fragmentShader().edgeLocation(); |
| } |
| void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* quad) |
| { |
| gfx::Rect tileRect = quad->visible_rect; |
| - |
| gfx::RectF texCoordRect = quad->tex_coord_rect; |
| + const gfx::Size& textureSize = quad->texture_size; |
| + |
| float texToGeomScaleX = quad->rect.width() / texCoordRect.width(); |
| float texToGeomScaleY = quad->rect.height() / texCoordRect.height(); |
| @@ -738,37 +739,17 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua |
| -bottomRightDiff.x() / texToGeomScaleX, |
| -bottomRightDiff.y() / texToGeomScaleY); |
| - gfx::RectF clampGeomRect(tileRect); |
| - gfx::RectF clampTexRect(texCoordRect); |
| - // Clamp texture coordinates to avoid sampling outside the layer |
| - // by deflating the tile region half a texel or half a texel |
| - // minus epsilon for one pixel layers. The resulting clamp region |
| - // is mapped to the unit square by the vertex shader and mapped |
| - // back to normalized texture coordinates by the fragment shader |
| - // after being clamped to 0-1 range. |
| - const float epsilon = 1 / 1024.0f; |
| - float texClampX = std::min(0.5f, 0.5f * clampTexRect.width() - epsilon); |
| - float texClampY = std::min(0.5f, 0.5f * clampTexRect.height() - epsilon); |
| - float geomClampX = std::min(texClampX * texToGeomScaleX, |
| - 0.5f * clampGeomRect.width() - epsilon); |
| - float geomClampY = std::min(texClampY * texToGeomScaleY, |
| - 0.5f * clampGeomRect.height() - epsilon); |
| - clampGeomRect.Inset(geomClampX, geomClampY, geomClampX, geomClampY); |
| - clampTexRect.Inset(texClampX, texClampY, texClampX, texClampY); |
| - |
| - // Map clamping rectangle to unit square. |
| - float vertexTexTranslateX = -clampGeomRect.x() / clampGeomRect.width(); |
| - float vertexTexTranslateY = -clampGeomRect.y() / clampGeomRect.height(); |
| - float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); |
| - float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); |
| - |
| - // Map to normalized texture coordinates. |
| - const gfx::Size& textureSize = quad->texture_size; |
| - float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); |
| - float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); |
| - float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); |
| - float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); |
| + // Map geometry to texture coordinates in the vertex shader. |
|
brianderson
2013/01/29 03:03:48
I combined the vertex and fragment shader "transfo
|
| + float vertexTexScaleX = texCoordRect.width() / textureSize.width(); |
| + float vertexTexScaleY = texCoordRect.height() / textureSize.height(); |
| + float vertexTexTranslateX = (texCoordRect.x() - (tileRect.x() / texToGeomScaleX)) / textureSize.width(); |
| + float vertexTexTranslateY = (texCoordRect.y() - (tileRect.y() / texToGeomScaleY)) / textureSize.height(); |
| + // Manually clamp in the fragment shader. |
|
brianderson
2013/01/29 03:03:48
This logic handles the clamping in the fragment sh
|
| + float fragmentTexClampXMin = (texCoordRect.x() + 0.5f) / textureSize.width(); |
| + float fragmentTexClampXMax = (texCoordRect.right() - 0.5f) / textureSize.width(); |
| + float fragmentTexClampYMin = (texCoordRect.y() + 0.5f) / textureSize.height(); |
| + float fragmentTexClampYMax = (texCoordRect.bottom() - 0.5f) / textureSize.height(); |
| gfx::QuadF localQuad; |
| gfx::Transform deviceTransform = frame.windowMatrix * frame.projectionMatrix * quad->quadTransform(); |
| @@ -822,7 +803,7 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua |
| GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); |
| GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
| - GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocation, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexScaleY)); |
| + GLC(context(), context()->uniform4f(uniforms.fragmentTexClampLocation, fragmentTexClampXMin, fragmentTexClampYMin, fragmentTexClampXMax, fragmentTexClampYMax)); |
| gfx::PointF bottomRight = tileRect.bottom_right(); |
| gfx::PointF bottomLeft = tileRect.bottom_left(); |
| @@ -873,19 +854,8 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua |
| // We should not DCHECK(!clipped) here, because anti-aliasing inflation may cause deviceQuad to become |
| // clipped. To our knowledge this scenario does not need to be handled differently than the unclipped case. |
| } else { |
| - // Move fragment shader transform to vertex shader. We can do this while |
| - // still producing correct results as fragmentTexTransformLocation |
| - // should always be non-negative when tiles are transformed in a way |
| - // that could result in sampling outside the layer. |
| - vertexTexScaleX *= fragmentTexScaleX; |
| - vertexTexScaleY *= fragmentTexScaleY; |
| - vertexTexTranslateX *= fragmentTexScaleX; |
| - vertexTexTranslateY *= fragmentTexScaleY; |
| - vertexTexTranslateX += fragmentTexTranslateX; |
| - vertexTexTranslateY += fragmentTexTranslateY; |
| - |
| GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
| - |
| + GLC(context(), context()->uniform4f(uniforms.fragmentTexClampLocation, fragmentTexClampXMin, fragmentTexClampYMin, fragmentTexClampXMax, fragmentTexClampYMax)); |
| localQuad = gfx::RectF(tileRect); |
| } |