diff options
author | Chris Dalton <csmartdalton@google.com> | 2018-06-08 12:00:44 -0600 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-08 20:15:03 +0000 |
commit | afa11586d782c7cb3e83b8af48023ff227349516 (patch) | |
tree | 384b990836f0da6ecb3a00788fdb4e806d2daeb7 /src | |
parent | 1471df99f0c7b5d9df43e7462d68a6635c3c59be (diff) |
Make the SkPathRef GenIDChangeListener ref counted
Bug: skia:
Change-Id: I2780e3fc76153373b4efca6059ded82f4f749325
Reviewed-on: https://skia-review.googlesource.com/133502
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPathPriv.h | 5 | ||||
-rw-r--r-- | src/core/SkPathRef.cpp | 7 | ||||
-rw-r--r-- | src/gpu/GrShape.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrShape.h | 4 | ||||
-rw-r--r-- | src/gpu/GrSoftwarePathRenderer.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrTessellatingPathRenderer.cpp | 2 |
6 files changed, 12 insertions, 14 deletions
diff --git a/src/core/SkPathPriv.h b/src/core/SkPathPriv.h index 9190962962..bcf85a138d 100644 --- a/src/core/SkPathPriv.h +++ b/src/core/SkPathPriv.h @@ -86,8 +86,9 @@ public: return false; } - static void AddGenIDChangeListener(const SkPath& path, SkPathRef::GenIDChangeListener* listener) { - path.fPathRef->addGenIDChangeListener(listener); + static void AddGenIDChangeListener(const SkPath& path, + sk_sp<SkPathRef::GenIDChangeListener> listener) { + path.fPathRef->addGenIDChangeListener(std::move(listener)); } /** diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp index cc6152a93d..58782df260 100644 --- a/src/core/SkPathRef.cpp +++ b/src/core/SkPathRef.cpp @@ -669,12 +669,11 @@ uint32_t SkPathRef::genID() const { return fGenerationID; } -void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { +void SkPathRef::addGenIDChangeListener(sk_sp<GenIDChangeListener> listener) { if (nullptr == listener || this == gEmpty) { - delete listener; return; } - *fGenIDChangeListeners.append() = listener; + *fGenIDChangeListeners.append() = listener.release(); } // we need to be called *before* the genID gets changed or zerod @@ -684,7 +683,7 @@ void SkPathRef::callGenIDChangeListeners() { } // Listeners get at most one shot, so whether these triggered or not, blow them away. - fGenIDChangeListeners.deleteAll(); + fGenIDChangeListeners.unrefAll(); } SkRRect SkPathRef::getRRect() const { diff --git a/src/gpu/GrShape.cpp b/src/gpu/GrShape.cpp index 4cab0188d9..d74b144741 100644 --- a/src/gpu/GrShape.cpp +++ b/src/gpu/GrShape.cpp @@ -363,11 +363,9 @@ const SkPath* GrShape::originalPathForListeners() const { return nullptr; } -void GrShape::addGenIDChangeListener(SkPathRef::GenIDChangeListener* listener) const { +void GrShape::addGenIDChangeListener(sk_sp<SkPathRef::GenIDChangeListener> listener) const { if (const auto* lp = this->originalPathForListeners()) { - SkPathPriv::AddGenIDChangeListener(*lp, listener); - } else { - delete listener; + SkPathPriv::AddGenIDChangeListener(*lp, std::move(listener)); } } diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h index 36402330ce..c333168b53 100644 --- a/src/gpu/GrShape.h +++ b/src/gpu/GrShape.h @@ -396,9 +396,9 @@ public: /** * Adds a listener to the *original* path. Typically used to invalidate cached resources when * a path is no longer in-use. If the shape started out as something other than a path, this - * does nothing (but will delete the listener). + * does nothing. */ - void addGenIDChangeListener(SkPathRef::GenIDChangeListener* listener) const; + void addGenIDChangeListener(sk_sp<SkPathRef::GenIDChangeListener>) const; /** * Helpers that are only exposed for unit tests, to determine if the shape is a path, and get diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index 15ea55d4f2..bcd9874807 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -363,7 +363,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { if (useCache) { SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get()); - args.fShape->addGenIDChangeListener(new PathInvalidator(maskKey)); + args.fShape->addGenIDChangeListener(sk_make_sp<PathInvalidator>(maskKey)); } } if (inverseFilled) { diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp index 651d34fae7..1918f666c9 100644 --- a/src/gpu/ops/GrTessellatingPathRenderer.cpp +++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp @@ -284,7 +284,7 @@ private: info.fCount = count; key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info))); rp->assignUniqueKeyToResource(key, allocator.vertexBuffer()); - fShape.addGenIDChangeListener(new PathInvalidator(key)); + fShape.addGenIDChangeListener(sk_make_sp<PathInvalidator>(key)); } void drawAA(Target* target, const GrGeometryProcessor* gp) { |