From 9bd83463e5078c49f3817e68ae6284fa1e3cb4b6 Mon Sep 17 00:00:00 2001 From: Herbert Derby Date: Fri, 30 Nov 2018 15:40:55 -0500 Subject: [PATCH] Embed SkPath in SkGlyph::PathData Change-Id: Ibc99172dfccbfdfaa6ff14060becc64df206104f Reviewed-on: https://skia-review.googlesource.com/c/173768 Reviewed-by: Ben Wagner Commit-Queue: Herb Derby --- src/core/SkGlyph.cpp | 13 +++++-------- src/core/SkGlyph.h | 11 +++++------ src/core/SkGlyphCache.cpp | 27 +++++++++++++++------------ src/core/SkStrikeCache.cpp | 4 ++-- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp index 0206afc3ff..69a40820d7 100644 --- a/src/core/SkGlyph.cpp +++ b/src/core/SkGlyph.cpp @@ -117,14 +117,11 @@ size_t SkGlyph::copyImageData(const SkGlyph& from, SkArenaAlloc* alloc) { SkPath* SkGlyph::addPath(SkScalerContext* scalerContext, SkArenaAlloc* alloc) { if (!this->isEmpty()) { if (fPathData == nullptr) { - SkGlyph::PathData* pathData = alloc->make(); - fPathData = pathData; - pathData->fIntercept = nullptr; - auto path = skstd::make_unique(); - if (scalerContext->getPath(this->getPackedID(), path.get())) { - path->updateBoundsCache(); - path->getGenerationID(); - pathData->fPath = std::move(path); + fPathData = alloc->make(); + if (scalerContext->getPath(this->getPackedID(), &fPathData->fPath)) { + fPathData->fPath.updateBoundsCache(); + fPathData->fPath.getGenerationID(); + fPathData->fHasPath = true; } } } diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h index 7ce0a7c8a9..c6151266ac 100644 --- a/src/core/SkGlyph.h +++ b/src/core/SkGlyph.h @@ -8,16 +8,14 @@ #ifndef SkGlyph_DEFINED #define SkGlyph_DEFINED -#include - #include "SkChecksum.h" #include "SkFixed.h" #include "SkMask.h" +#include "SkPath.h" #include "SkTo.h" #include "SkTypes.h" class SkArenaAlloc; -class SkPath; class SkGlyphCache; class SkScalerContext; @@ -167,7 +165,7 @@ public: SkPath* addPath(SkScalerContext*, SkArenaAlloc*); SkPath* path() const { - return fPathData ? fPathData->fPath.get() : nullptr; + return fPathData != nullptr && fPathData->fHasPath ? &fPathData->fPath : nullptr; } // Returns the size allocated on the arena. @@ -223,8 +221,9 @@ private: }; struct PathData { - Intercept* fIntercept; - std::unique_ptr fPath; + Intercept* fIntercept{nullptr}; + SkPath fPath; + bool fHasPath{false}; }; // TODO(herb) remove friend statement after SkGlyphCache cleanup. diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index d2e90fa67e..7b97f09f10 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -219,14 +219,18 @@ const SkPath* SkGlyphCache::findPath(const SkGlyph& glyph) { if (!glyph.isEmpty()) { // If the path already exists, return it. if (glyph.fPathData != nullptr) { - return glyph.fPathData->fPath.get(); + if (glyph.fPathData->fHasPath) { + return &glyph.fPathData->fPath; + } + return nullptr; } - // Add new path to the glyph, and add it's size to the glyph cache size. - if (SkPath* path = const_cast(glyph).addPath(fScalerContext.get(), &fAlloc)) { - fMemoryUsed += compute_path_size(*path); - return path; + const_cast(glyph).addPath(fScalerContext.get(), &fAlloc); + if (glyph.fPathData != nullptr) { + fMemoryUsed += compute_path_size(glyph.fPathData->fPath); } + + return glyph.path(); } return nullptr; @@ -240,13 +244,12 @@ bool SkGlyphCache::initializePath(SkGlyph* glyph, const volatile void* data, siz if (glyph->fWidth) { SkGlyph::PathData* pathData = fAlloc.make(); glyph->fPathData = pathData; - pathData->fIntercept = nullptr; auto path = skstd::make_unique(); - if (!path->readFromMemory(const_cast(data), size)) { + if (!pathData->fPath.readFromMemory(const_cast(data), size)) { return false; } - fMemoryUsed += compute_path_size(*path); - pathData->fPath = std::move(path); + fMemoryUsed += compute_path_size(glyph->fPathData->fPath); + pathData->fHasPath = true; } return true; @@ -405,7 +408,7 @@ void SkGlyphCache::findIntercepts(const SkScalar bounds[2], SkScalar scale, SkSc intercept->fInterval[0] = SK_ScalarMax; intercept->fInterval[1] = SK_ScalarMin; glyph->fPathData->fIntercept = intercept; - const SkPath* path = glyph->fPathData->fPath.get(); + const SkPath* path = &(glyph->fPathData->fPath); const SkRect& pathBounds = path->getBounds(); if (*(&pathBounds.fBottom - yAxis) < bounds[0] || bounds[1] < *(&pathBounds.fTop - yAxis)) { return; @@ -489,8 +492,8 @@ void SkGlyphCache::forceValidate() const { if (glyph.fImage) { memoryUsed += glyph.computeImageSize(); } - if (glyph.fPathData && glyph.fPathData->fPath) { - memoryUsed += compute_path_size(*glyph.fPathData->fPath); + if (glyph.fPathData) { + memoryUsed += compute_path_size(glyph.fPathData->fPath); } }); SkASSERT(fMemoryUsed == memoryUsed); diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp index 8206d947cc..4bbd16bb7b 100644 --- a/src/core/SkStrikeCache.cpp +++ b/src/core/SkStrikeCache.cpp @@ -392,10 +392,10 @@ bool SkStrikeCache::desperationSearchForPath( if (loose_compare(node->fCache.getDescriptor(), desc)) { if (node->fCache.isGlyphCached(glyphID, 0, 0)) { SkGlyph* from = node->fCache.getRawGlyphByID(SkPackedGlyphID(glyphID)); - if (from->fPathData != nullptr && from->fPathData->fPath != nullptr) { + if (from->fPathData != nullptr) { // We can just copy the path out by value here, so no need to worry // about the lifetime of this desperate-match node. - *path = *from->fPathData->fPath; + *path = from->fPathData->fPath; return true; } }