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

Unified Diff: cc/gl_renderer.cc

Issue 12086036: cc: Clamp texture coordinates in all tile shaders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snowscale
Patch Set: Created 7 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/gl_renderer.h ('k') | cc/shader.h » ('j') | cc/shader.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « cc/gl_renderer.h ('k') | cc/shader.h » ('j') | cc/shader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698