Commit f76a39b9 authored by Daniele Castagna's avatar Daniele Castagna Committed by Commit Bot

viz: Optimize rounded corner shader usage

Rounded corner shader can be avoided every time that a quad does not
intersect any corner.
This is particularly useful in overview mode, where most of the tiles do
not need to be drawn using the rounded corner shader.

Bug: 903486
Change-Id: I673760b8ffbb8550d05752aab929e99d42c1ac9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1548734Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#647112}
parent 28536367
...@@ -73,6 +73,29 @@ static gfx::Transform window_matrix(int x, int y, int width, int height) { ...@@ -73,6 +73,29 @@ static gfx::Transform window_matrix(int x, int y, int width, int height) {
// been produced. // been produced.
constexpr int kNumberOfFramesBeforeDisablingDCLayers = 60; constexpr int kNumberOfFramesBeforeDisablingDCLayers = 60;
// Returns the bounding box that contains the specified rounded corner.
gfx::RectF ComputeRoundedCornerBoundingBox(const gfx::RRectF& rrect,
const gfx::RRectF::Corner corner) {
auto radii = rrect.GetCornerRadii(corner);
gfx::RectF bounding_box(radii.x(), radii.y());
switch (corner) {
case gfx::RRectF::Corner::kUpperLeft:
bounding_box.Offset(rrect.rect().x(), rrect.rect().bottom() - radii.y());
break;
case gfx::RRectF::Corner::kUpperRight:
bounding_box.Offset(rrect.rect().right() - radii.x(),
rrect.rect().bottom() - radii.y());
break;
case gfx::RRectF::Corner::kLowerRight:
bounding_box.Offset(rrect.rect().right() - radii.x(), rrect.rect().y());
break;
case gfx::RRectF::Corner::kLowerLeft:
bounding_box.Offset(rrect.rect().x(), rrect.rect().y());
break;
}
return bounding_box;
}
} // namespace } // namespace
namespace viz { namespace viz {
...@@ -804,21 +827,16 @@ bool DirectRenderer::ShouldApplyRoundedCorner(const DrawQuad* quad) const { ...@@ -804,21 +827,16 @@ bool DirectRenderer::ShouldApplyRoundedCorner(const DrawQuad* quad) const {
const gfx::RectF target_quad = cc::MathUtil::MapClippedRect( const gfx::RectF target_quad = cc::MathUtil::MapClippedRect(
sqs->quad_to_target_transform, gfx::RectF(quad->visible_rect)); sqs->quad_to_target_transform, gfx::RectF(quad->visible_rect));
// If the rounded corner rect intersects with the quad, then we should run the const gfx::RRectF::Corner corners[] = {
// fragment shader. gfx::RRectF::Corner::kUpperLeft, gfx::RRectF::Corner::kUpperRight,
if (rounded_corner_bounds.rect().Intersects(target_quad)) gfx::RRectF::Corner::kLowerRight, gfx::RRectF::Corner::kLowerLeft};
return true; for (auto c : corners) {
if (ComputeRoundedCornerBoundingBox(rounded_corner_bounds, c)
// If the quad is not within the rounded corner bounds, neither does it .Intersects(target_quad)) {
// intersect, we do not have to apply any rounded corner on it. return true;
if (!rounded_corner_bounds.rect().Contains(target_quad)) }
return false; }
return false;
// If the rounded corner bounding rect contains the quad but the rounded
// corner rrect does not, it means there is an intersection. Apply rounded
// corner on the quad.
SkRRect rrect = static_cast<SkRRect>(rounded_corner_bounds);
return !rrect.contains(gfx::RectFToSkRect(target_quad));
} }
} // namespace viz } // namespace viz
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment