From 0bc32f23f69e3ba865f665745d33a420676de319 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 19 Jan 2021 09:15:08 -0500 Subject: [PATCH] Add query to test our cached convexity Sometimes our cache of convexity is wrong -- still trying to figure out what do do about that. Change-Id: Ie36292b87c4d07fc18643cc91f93be00c577b2ca Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355616 Reviewed-by: Brian Salomon Commit-Queue: Mike Reed --- include/core/SkPath.h | 14 ++++++-------- src/core/SkPath.cpp | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/core/SkPath.h b/include/core/SkPath.h index e74c8683b5..178e4d22f2 100644 --- a/include/core/SkPath.h +++ b/include/core/SkPath.h @@ -1850,17 +1850,15 @@ private: /** Returns the comvexity type, computing if needed. Never returns kUnknown. @return path's convexity type (convex or concave) */ - SkPathConvexity getConvexity() const { - SkPathConvexity convexity = this->getConvexityOrUnknown(); - if (convexity == SkPathConvexity::kUnknown) { - convexity = this->computeConvexity(); - } - SkASSERT(convexity != SkPathConvexity::kUnknown); - return convexity; - } + SkPathConvexity getConvexity() const; + SkPathConvexity getConvexityOrUnknown() const { return (SkPathConvexity)fConvexity.load(std::memory_order_relaxed); } + + // Compares the cached value with a freshly computed one (computeConvexity()) + bool isConvexityAccurate() const; + /** Stores a convexity type for this path. This is what will be returned if * getConvexityOrUnknown() is called. If you pass kUnknown, then if getContexityType() * is called, the real convexity will be computed. diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 7f2101ad7c..0ac61dc6c2 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -580,6 +580,29 @@ SkPathFirstDirection SkPath::getFirstDirection() const { return (SkPathFirstDirection)fFirstDirection.load(std::memory_order_relaxed); } +bool SkPath::isConvexityAccurate() const { + SkPathConvexity convexity = this->getConvexityOrUnknown(); + if (convexity != SkPathConvexity::kUnknown) { + auto conv = this->computeConvexity(); + if (conv != convexity) { + SkASSERT(false); + return false; + } + } + return true; +} + +SkPathConvexity SkPath::getConvexity() const { +// Enable once we fix all the bugs +// SkDEBUGCODE(this->isConvexityAccurate()); + SkPathConvexity convexity = this->getConvexityOrUnknown(); + if (convexity == SkPathConvexity::kUnknown) { + convexity = this->computeConvexity(); + } + SkASSERT(convexity != SkPathConvexity::kUnknown); + return convexity; +} + ////////////////////////////////////////////////////////////////////////////// // Construction methods