Converts a drawPaint through a rrect clip to a drawRRect in GrDrawContext.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2271053004
Review-Url: https://codereview.chromium.org/2271053004
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp
index 8bab586..30f5a46 100644
--- a/src/core/SkClipStack.cpp
+++ b/src/core/SkClipStack.cpp
@@ -862,6 +862,50 @@
}
}
+bool SkClipStack::isRRect(const SkRect& bounds, SkRRect* rrect, bool* aa) const {
+ // We limit to 5 elements. This means the back element will be bounds checked at most 4 times if
+ // it is an rrect.
+ int cnt = fDeque.count();
+ if (!cnt || cnt > 5) {
+ return false;
+ }
+ const Element* back = static_cast<const Element*>(fDeque.back());
+ if (back->getType() != SkClipStack::Element::kRect_Type &&
+ back->getType() != SkClipStack::Element::kRRect_Type) {
+ return false;
+ }
+ if (back->getOp() == SkRegion::kReplace_Op) {
+ *rrect = back->asRRect();
+ *aa = back->isAA();
+ return true;
+ }
+
+ if (back->getOp() == SkRegion::kIntersect_Op) {
+ SkRect backBounds;
+ if (!backBounds.intersect(bounds, back->asRRect().rect())) {
+ return false;
+ }
+ if (cnt > 1) {
+ SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart);
+ SkAssertResult(static_cast<const Element*>(iter.prev()) == back);
+ while (const Element* prior = (const Element*)iter.prev()) {
+ if ((prior->getOp() != SkRegion::kIntersect_Op &&
+ prior->getOp() != SkRegion::kReplace_Op) ||
+ !prior->contains(backBounds)) {
+ return false;
+ }
+ if (prior->getOp() == SkRegion::kReplace_Op) {
+ break;
+ }
+ }
+ }
+ *rrect = back->asRRect();
+ *aa = back->isAA();
+ return true;
+ }
+ return false;
+}
+
int32_t SkClipStack::GetNextGenID() {
// TODO: handle overflow.
return sk_atomic_inc(&gGenID);
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 7138f4b..8233786 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -41,6 +41,27 @@
SkIntToScalar(fOrigin.fY)));
}
+bool GrClipStackClip::isRRect(const SkRect& origRTBounds, SkRRect* rr, bool* aa) const {
+ if (!fStack) {
+ return false;
+ }
+ const SkRect* rtBounds = &origRTBounds;
+ SkRect tempRTBounds;
+ bool origin = fOrigin.fX || fOrigin.fY;
+ if (origin) {
+ tempRTBounds = origRTBounds;
+ tempRTBounds.offset(SkIntToScalar(fOrigin.fX), SkIntToScalar(fOrigin.fY));
+ rtBounds = &tempRTBounds;
+ }
+ if (fStack->isRRect(*rtBounds, rr, aa)) {
+ if (origin) {
+ rr->offset(-SkIntToScalar(fOrigin.fX), -SkIntToScalar(fOrigin.fY));
+ }
+ return true;
+ }
+ return false;
+}
+
void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const {
if (!fStack) {
diff --git a/src/gpu/GrClipStackClip.h b/src/gpu/GrClipStackClip.h
index cb1f683..ad143d6 100644
--- a/src/gpu/GrClipStackClip.h
+++ b/src/gpu/GrClipStackClip.h
@@ -38,6 +38,8 @@
bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings,
GrAppliedClip* out) const final;
+ bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override;
+
private:
static bool PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings,
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 5afb2ea..2bb9caa 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -251,6 +251,20 @@
SkIntToScalar(fRenderTarget->height()));
SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
+ SkRRect rrect;
+ bool aaRRect;
+ // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We only do the
+ // transformation for non-rect rrects. Rects caused a performance regression on an Android
+ // test that needs investigation. We also skip cases where there are fragment processors
+ // because they may depend on having correct local coords and this path draws in device space
+ // without a local matrix.
+ if (!paint->numTotalFragmentProcessors() &&
+ clip.isRRect(r, &rrect, &aaRRect) && !rrect.isRect()) {
+ paint.writable()->setAntiAlias(aaRRect);
+ this->drawRRect(GrNoClip(), *paint, SkMatrix::I(), rrect, GrStyle::SimpleFill());
+ return;
+ }
+
// by definition this fills the entire clip, no need for AA
if (paint->isAntiAlias()) {
paint.writable()->setAntiAlias(false);
diff --git a/src/gpu/GrFixedClip.h b/src/gpu/GrFixedClip.h
index 01498c1..705b2ea 100644
--- a/src/gpu/GrFixedClip.h
+++ b/src/gpu/GrFixedClip.h
@@ -39,6 +39,22 @@
void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final;
+ bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override {
+ if (fHasStencilClip) {
+ return false;
+ }
+ if (fScissorState.enabled()) {
+ SkRect rect = SkRect::Make(fScissorState.rect());
+ if (!rect.intersects(rtBounds)) {
+ return false;
+ }
+ rr->setRect(rect);
+ *aa = false;
+ return true;
+ }
+ return false;
+ };
+
private:
bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings,
GrAppliedClip* out) const final;