aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sk_tool_utils.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-08-04 09:03:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-04 09:03:20 -0700
commit276d3286b32900d8b7e895c5224ceba1922d2391 (patch)
treeff4bdbe68e8d4106a9c9ba939d61ebd000ca6272 /tools/sk_tool_utils.cpp
parent15c42ca310e8b9785eab38b3dd36265948e85b0e (diff)
Add new bench for occluded blurmaskfilter draws
w/ occluders 44/44 MB 6 497us 500us 500us 502us 0% .oOOooooOO gpu bluroccludedrrect w/o occluders 41/41 MB 5 1.08ms 1.09ms 1.12ms 1.47ms 11% .........O gpu bluroccludedrrect GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2203153002 Review-Url: https://codereview.chromium.org/2203153002
Diffstat (limited to 'tools/sk_tool_utils.cpp')
-rw-r--r--tools/sk_tool_utils.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 9f398e2fc0..38880f8204 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -463,4 +463,54 @@ SkBitmap slow_blur(const SkBitmap& src, float sigma) {
return dst;
}
+// compute the intersection point between the diagonal and the ellipse in the
+// lower right corner
+static SkPoint intersection(SkScalar w, SkScalar h) {
+ SkASSERT(w > 0.0f || h > 0.0f);
+
+ return SkPoint::Make(w / SK_ScalarSqrt2, h / SK_ScalarSqrt2);
+}
+
+// Use the intersection of the corners' diagonals with their ellipses to shrink
+// the bounding rect
+SkRect compute_central_occluder(const SkRRect& rr) {
+ const SkRect r = rr.getBounds();
+
+ SkScalar newL = r.fLeft, newT = r.fTop, newR = r.fRight, newB = r.fBottom;
+
+ SkVector radii = rr.radii(SkRRect::kUpperLeft_Corner);
+ if (!radii.isZero()) {
+ SkPoint p = intersection(radii.fX, radii.fY);
+
+ newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
+ newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
+ }
+
+ radii = rr.radii(SkRRect::kUpperRight_Corner);
+ if (!radii.isZero()) {
+ SkPoint p = intersection(radii.fX, radii.fY);
+
+ newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
+ newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
+ }
+
+ radii = rr.radii(SkRRect::kLowerRight_Corner);
+ if (!radii.isZero()) {
+ SkPoint p = intersection(radii.fX, radii.fY);
+
+ newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
+ newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
+ }
+
+ radii = rr.radii(SkRRect::kLowerLeft_Corner);
+ if (!radii.isZero()) {
+ SkPoint p = intersection(radii.fX, radii.fY);
+
+ newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
+ newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
+ }
+
+ return SkRect::MakeLTRB(newL, newT, newR, newB);
+}
+
} // namespace sk_tool_utils