diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 04:17:54 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 04:17:54 +0000 |
commit | 2990ff51b4d9c26f815911d92fd7814bb9e80949 (patch) | |
tree | c234cb9ab8b9a1f98b79968742c6bf6bfe2b84a1 /cc/gl_renderer.cc | |
parent | 9c91fc2b8a286096e2914a55305aff5a8ad53c3c (diff) | |
download | chromium_src-2990ff51b4d9c26f815911d92fd7814bb9e80949.zip chromium_src-2990ff51b4d9c26f815911d92fd7814bb9e80949.tar.gz chromium_src-2990ff51b4d9c26f815911d92fd7814bb9e80949.tar.bz2 |
cc: Make UV coords in TileDrawQuad a full RectF
Previously, TileDrawQuad assumed that texels were 1:1 with geometry, so it only
needed an offset into the texture to calculate the UVs. For impl-side painting
where multiple contents scales might be in play, a given texture rect isn't going
to be 1:1 with geometry rects and also will not be necessarily integer aligned.
Also, some things (like edge antialiasing) still need to know the texture size
so that it can do half-texel offsets, so this new texture rect needs to stay in
"texel space" rather than 0-1 "uv space".
R=danakj@chromium.org
BUG=155209
Review URL: https://chromiumcodereview.appspot.com/11348109
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/gl_renderer.cc')
-rw-r--r-- | cc/gl_renderer.cc | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc index fb5227b..916e9e1 100644 --- a/cc/gl_renderer.cc +++ b/cc/gl_renderer.cc @@ -10,6 +10,7 @@ #include "base/string_util.h" #include "build/build_config.h" #include "cc/damage_tracker.h" +#include "cc/geometry.h" #include "cc/geometry_binding.h" #include "cc/layer_quad.h" #include "cc/math_util.h" @@ -697,7 +698,23 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua { gfx::Rect tileRect = quad->visible_rect; - gfx::RectF clampRect(tileRect); + gfx::RectF texCoordRect = quad->texCoordRect(); + float texToGeomScaleX = quad->rect.width() / texCoordRect.width(); + float texToGeomScaleY = quad->rect.height() / texCoordRect.height(); + + // texCoordRect corresponds to quadRect, but quadVisibleRect may be + // smaller than quadRect due to occlusion or clipping. Adjust + // texCoordRect to match. + gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin(); + gfx::Vector2d bottomRightDiff = + BottomRight(tileRect) - BottomRight(quad->rect); + texCoordRect.Inset(topLeftDiff.x() / texToGeomScaleX, + topLeftDiff.y() / texToGeomScaleY, + -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 @@ -705,24 +722,27 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua // back to normalized texture coordinates by the fragment shader // after being clamped to 0-1 range. const float epsilon = 1 / 1024.0f; - float clampX = min(0.5, clampRect.width() / 2.0 - epsilon); - float clampY = min(0.5, clampRect.height() / 2.0 - epsilon); - clampRect.Inset(clampX, clampY, clampX, clampY); - - gfx::Vector2dF textureOffset = quad->textureOffset() + (clampRect.origin() - quad->rect.origin()); + 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 = -clampRect.x() / clampRect.width(); - float vertexTexTranslateY = -clampRect.y() / clampRect.height(); - float vertexTexScaleX = tileRect.width() / clampRect.width(); - float vertexTexScaleY = tileRect.height() / clampRect.height(); + 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->textureSize(); - float fragmentTexTranslateX = textureOffset.x() / textureSize.width(); - float fragmentTexTranslateY = textureOffset.y() / textureSize.height(); - float fragmentTexScaleX = clampRect.width() / textureSize.width(); - float fragmentTexScaleY = clampRect.height() / textureSize.height(); + float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); + float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); + float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); + float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); gfx::QuadF localQuad; |