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

Unified Diff: cc/texture_layer_impl.cc

Issue 11418297: Clipping textured quads explicitly without scissoring (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/texture_layer_impl.cc
diff --git a/cc/texture_layer_impl.cc b/cc/texture_layer_impl.cc
index e8a68741855891ef8d8e1317942c96484d7994bc..149f9ac17f02ec90b9d3a0b168e0ad49858893cd 100644
--- a/cc/texture_layer_impl.cc
+++ b/cc/texture_layer_impl.cc
@@ -45,6 +45,61 @@ void TextureLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQu
gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, m_premultipliedAlpha, m_uvRect, m_flipped);
+
+ if (quad->quadTransform().IsScaleOrTranslation())
shawnsingh 2012/12/03 23:37:52 A few more thoughts: (1) Don't we need an isClipp
whunt 2012/12/04 00:01:24 I added the isClipped check. I can make it a help
+ {
+ // Grab the corners of our boxes.
+ float rect_min_x = quad->rect.x();
+ float rect_min_y = quad->rect.y();
+ float rect_max_x = rect_min_x + quad->rect.width();
+ float rect_max_y = rect_min_y + quad->rect.height();
+
+ // Grab the relevant values from our matrix.
+ float x_scale = quad->quadTransform().matrix().getDouble(0,0);
+ float y_scale = quad->quadTransform().matrix().getDouble(1,1);
+ float x_offset = quad->quadTransform().matrix().getDouble(0,3);
+ float y_offset = quad->quadTransform().matrix().getDouble(1,3);
+
+ // Transform the rect to the same space as the clip.
+ rect_min_x = x_scale * rect_min_x + x_offset;
+ rect_min_y = y_scale * rect_min_y + y_offset;
+ rect_max_x = x_scale * rect_max_x + x_offset;
+ rect_max_y = y_scale * rect_max_y + y_offset;
+
+ // Grab the clipped region.
+ float clip_min_x = quad->clipRect().x();
+ float clip_min_y = quad->clipRect().y();
+ float clip_max_x = clip_min_x + quad->clipRect().width();
+ float clip_max_y = clip_min_y + quad->clipRect().height();
+
+ // Perform clipping on the rect.
shawnsingh 2012/12/03 23:34:08 Unless there's some performance caveats, I think w
whunt 2012/12/04 00:01:24 There are certainly performance caveats to using g
jamesr 2012/12/04 00:15:42 Would you mind running cc_perftests on this with t
whunt 2012/12/04 19:35:04 Given that this code gets run ~8 times/frame in th
+ float min_x = std::max(rect_min_x, clip_min_x);
+ float min_y = std::max(rect_min_y, clip_min_y);
+ float max_x = std::min(rect_max_x, clip_max_x);
+ float max_y = std::min(rect_max_y, clip_max_y);
+
+ // Empty bounds mean that this is clipped completely away.
+ if (min_x > max_x || min_y > max_y)
+ return;
+
+ // Create a new uv-rect by clipping the old one to the new bounds.
+ quad->uv_rect = gfx::RectF(
+ quad->uv_rect.x() + quad->uv_rect.width () * (1.0f / (rect_max_x - rect_min_x)) * (min_x - rect_min_x),
shawnsingh 2012/12/03 23:34:08 how about (min_x - rect_min_x) / (rect_max_x - rec
whunt 2012/12/04 00:01:24 Ditto as previous comment. On 2012/12/03 23:34:08
+ quad->uv_rect.y() + quad->uv_rect.height() * (1.0f / (rect_max_y - rect_min_y)) * (min_y - rect_min_y),
+ quad->uv_rect.width () * (1.0f / (rect_max_x - rect_min_x)) * (max_x - min_x),
+ quad->uv_rect.height() * (1.0f / (rect_max_y - rect_min_y)) * (max_y - min_y));
+
+ // Move the clipped rectangle back into its space.
+ quad->rect = gfx::Rect(
shawnsingh 2012/12/03 23:34:08 Its likely that scaling and translation are operat
whunt 2012/12/04 00:01:24 Ditto again. On 2012/12/03 23:34:08, shawnsingh w
+ (int)((min_x - x_offset) * (1.0f / x_scale) + 0.5f),
jamesr 2012/12/04 00:15:42 we prefer c++ style casts to c-style cases in chro
+ (int)((min_y - y_offset) * (1.0f / y_scale) + 0.5f),
+ (int)((max_x - min_x) * (1.0f / x_scale) + 0.5f),
+ (int)((max_y - min_y) * (1.0f / y_scale) + 0.5f));
+
+ // Disable hardware clipping
+ sharedQuadState->is_clipped = false;
+ }
+
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698