Move path building logic to SkGlyph
This will allow the remote glyph cache to check for paths. Change-Id: I900a0aee294e800241d3ac749d5dd976e9364d41 Reviewed-on: https://skia-review.googlesource.com/c/172946 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
4eaf86289a
commit
f4958ce207
@ -8,6 +8,7 @@
|
||||
#include "SkGlyph.h"
|
||||
|
||||
#include "SkArenaAlloc.h"
|
||||
#include "SkScalerContext.h"
|
||||
|
||||
void SkGlyph::initWithGlyphID(SkPackedGlyphID glyph_id) {
|
||||
fID = glyph_id;
|
||||
@ -112,3 +113,23 @@ size_t SkGlyph::copyImageData(const SkGlyph& from, SkArenaAlloc* alloc) {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
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;
|
||||
SkPath* path = new SkPath;
|
||||
if (scalerContext->getPath(this->getPackedID(), path)) {
|
||||
path->updateBoundsCache();
|
||||
path->getGenerationID();
|
||||
pathData->fPath = path;
|
||||
} else {
|
||||
pathData->fPath = nullptr;
|
||||
delete path;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fPathData ? fPathData->fPath : nullptr;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
class SkArenaAlloc;
|
||||
class SkPath;
|
||||
class SkGlyphCache;
|
||||
class SkScalerContext;
|
||||
|
||||
// needs to be != to any valid SkMask::Format
|
||||
#define MASK_FORMAT_UNKNOWN (0xFF)
|
||||
@ -161,6 +162,8 @@ public:
|
||||
|
||||
void toMask(SkMask* mask) const;
|
||||
|
||||
SkPath* addPath(SkScalerContext*, SkArenaAlloc*);
|
||||
|
||||
// Returns the size allocated on the arena.
|
||||
size_t copyImageData(const SkGlyph& from, SkArenaAlloc* alloc);
|
||||
|
||||
@ -175,6 +178,10 @@ public:
|
||||
};
|
||||
|
||||
void* fImage = nullptr;
|
||||
|
||||
// Path data has tricky state. If the glyph isEmpty, then fPathData should always be nullptr,
|
||||
// else if fPathData is not null, then a path has been requested. The fPath field of fPathData
|
||||
// may still be null after the request meaning that there is no path for this glyph.
|
||||
PathData* fPathData = nullptr;
|
||||
|
||||
// The advance for this glyph.
|
||||
|
@ -220,24 +220,21 @@ void SkGlyphCache::initializeImage(const volatile void* data, size_t size, SkGly
|
||||
}
|
||||
|
||||
const SkPath* SkGlyphCache::findPath(const SkGlyph& glyph) {
|
||||
if (glyph.fWidth) {
|
||||
if (glyph.fPathData == nullptr) {
|
||||
SkGlyph::PathData* pathData = fAlloc.make<SkGlyph::PathData>();
|
||||
const_cast<SkGlyph&>(glyph).fPathData = pathData;
|
||||
pathData->fIntercept = nullptr;
|
||||
SkPath* path = new SkPath;
|
||||
if (fScalerContext->getPath(glyph.getPackedID(), path)) {
|
||||
path->updateBoundsCache();
|
||||
path->getGenerationID();
|
||||
pathData->fPath = path;
|
||||
fMemoryUsed += compute_path_size(*path);
|
||||
} else {
|
||||
pathData->fPath = nullptr;
|
||||
delete path;
|
||||
}
|
||||
|
||||
if (!glyph.isEmpty()) {
|
||||
// If the path already exists, return it.
|
||||
if (glyph.fPathData != nullptr) {
|
||||
return glyph.fPathData->fPath;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
return glyph.fPathData ? glyph.fPathData->fPath : nullptr;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SkGlyphCache::initializePath(SkGlyph* glyph, const volatile void* data, size_t size) {
|
||||
|
Loading…
Reference in New Issue
Block a user