Widen the set of nested rects that can be drawn natively on the GPU
GrAARectRenderer::fillAANestedRects only handles thin stroked rects correctly if the margins are all the same. It is also correct if all the margins are >= 1.0f. This CL allows such cases to use the fillAANestedRects fast path.
This seems to halve the gpu rendering time of the picture in bug crbug.com/425427.
Review URL: https://codereview.chromium.org/672473002
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index 2db42cc..edc8f71 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -858,7 +858,7 @@
#ifndef SK_IGNORE_THIN_STROKED_RECT_FIX
// TODO: this only really works if the X & Y margins are the same all around
- // the rect
+ // the rect (or if they are all >= 1.0).
SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRight);
inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 6ad98ff..b4bcfd3 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1082,15 +1082,22 @@
const SkScalar* outer = rects[0].asScalars();
const SkScalar* inner = rects[1].asScalars();
+ bool allEq = true;
+
SkScalar margin = SkScalarAbs(outer[0] - inner[0]);
+ bool allGoE1 = margin >= SK_Scalar1;
+
for (int i = 1; i < 4; ++i) {
SkScalar temp = SkScalarAbs(outer[i] - inner[i]);
+ if (temp < SK_Scalar1) {
+ allGoE1 = false;
+ }
if (!SkScalarNearlyEqual(margin, temp)) {
- return false;
+ allEq = false;
}
}
- return true;
+ return allEq || allGoE1;
}
void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo) {