Embed SkPath in SkGlyph::PathData

Change-Id: Ibc99172dfccbfdfaa6ff14060becc64df206104f
Reviewed-on: https://skia-review.googlesource.com/c/173768
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herbert Derby 2018-11-30 15:40:55 -05:00 committed by Skia Commit-Bot
parent 6d59568196
commit 9bd83463e5
4 changed files with 27 additions and 28 deletions

View File

@ -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<SkGlyph::PathData>();
fPathData = pathData;
pathData->fIntercept = nullptr;
auto path = skstd::make_unique<SkPath>();
if (scalerContext->getPath(this->getPackedID(), path.get())) {
path->updateBoundsCache();
path->getGenerationID();
pathData->fPath = std::move(path);
fPathData = alloc->make<SkGlyph::PathData>();
if (scalerContext->getPath(this->getPackedID(), &fPathData->fPath)) {
fPathData->fPath.updateBoundsCache();
fPathData->fPath.getGenerationID();
fPathData->fHasPath = true;
}
}
}

View File

@ -8,16 +8,14 @@
#ifndef SkGlyph_DEFINED
#define SkGlyph_DEFINED
#include <memory>
#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<SkPath> fPath;
Intercept* fIntercept{nullptr};
SkPath fPath;
bool fHasPath{false};
};
// TODO(herb) remove friend statement after SkGlyphCache cleanup.

View File

@ -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<SkGlyph&>(glyph).addPath(fScalerContext.get(), &fAlloc)) {
fMemoryUsed += compute_path_size(*path);
return path;
const_cast<SkGlyph&>(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<SkGlyph::PathData>();
glyph->fPathData = pathData;
pathData->fIntercept = nullptr;
auto path = skstd::make_unique<SkPath>();
if (!path->readFromMemory(const_cast<const void*>(data), size)) {
if (!pathData->fPath.readFromMemory(const_cast<const void*>(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);

View File

@ -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;
}
}