/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
bool SkStrike::mergeFromBuffer(SkReadBuffer& buffer) { // Read glyphs with images for the current strike. constint imagesCount = buffer.readInt(); if (imagesCount == 0 && !buffer.isValid()) { returnfalse;
}
{
Monitor m{this}; for (int curImage = 0; curImage < imagesCount; ++curImage) { if (!this->mergeGlyphAndImageFromBuffer(buffer)) { returnfalse;
}
}
}
// Read glyphs with paths for the current strike. constint pathsCount = buffer.readInt(); if (pathsCount == 0 && !buffer.isValid()) { returnfalse;
}
{
Monitor m{this}; for (int curPath = 0; curPath < pathsCount; ++curPath) { if (!this->mergeGlyphAndPathFromBuffer(buffer)) { returnfalse;
}
}
}
// Read glyphs with drawables for the current strike. constint drawablesCount = buffer.readInt(); if (drawablesCount == 0 && !buffer.isValid()) { returnfalse;
}
{
Monitor m{this}; for (int curDrawable = 0; curDrawable < drawablesCount; ++curDrawable) { if (!this->mergeGlyphAndDrawableFromBuffer(buffer)) { returnfalse;
}
}
}
returntrue;
}
SkGlyph* SkStrike::mergeGlyphAndImage(SkPackedGlyphID toID, const SkGlyph& fromGlyph) {
Monitor m{this}; // TODO(herb): remove finding the glyph when setting the metrics and image are separated
SkGlyphDigest* digest = fDigestForPackedGlyphID.find(toID); if (digest != nullptr) {
SkGlyph* glyph = fGlyphForIndex[digest->index()]; if (fromGlyph.setImageHasBeenCalled()) { if (glyph->setImageHasBeenCalled()) { // Should never set an image on a glyph which already has an image.
SkDEBUGFAIL("Re-adding image to existing glyph. This should not happen.");
} // TODO: assert that any metrics on fromGlyph are the same.
fMemoryIncrease += glyph->setMetricsAndImage(&fAlloc, fromGlyph);
} return glyph;
} else {
SkGlyph* glyph = fAlloc.make<SkGlyph>(toID);
fMemoryIncrease += glyph->setMetricsAndImage(&fAlloc, fromGlyph) + sizeof(SkGlyph);
(void)this->addGlyphAndDigest(glyph); return glyph;
}
}
const SkPath* SkStrike::mergePath(SkGlyph* glyph, const SkPath* path, bool hairline, boolmodified) {
Monitor m{this}; if (glyph->setPathHasBeenCalled()) {
SkDEBUGFAIL("Re-adding path to existing glyph. This should not happen.");
} if (glyph->setPath(&fAlloc, path, hairline, modified)) {
fMemoryIncrease += glyph->path()->approximateBytesUsed();
}
return glyph->path();
}
const SkDrawable* SkStrike::mergeDrawable(SkGlyph* glyph, sk_sp<SkDrawable> drawable) {
Monitor m{this}; if (glyph->setDrawableHasBeenCalled()) {
SkDEBUGFAIL("Re-adding drawable to existing glyph. This should not happen.");
} if (glyph->setDrawable(&fAlloc, std::move(drawable))) {
fMemoryIncrease += glyph->drawable()->approximateBytesUsed();
SkASSERT(fMemoryIncrease > 0);
}
SkString fontName;
face->getFamilyName(&fontName); // Replace all special characters with '_'. for (size_t index = 0; index < fontName.size(); ++index) { if (!std::isalnum(fontName[index])) {
fontName[index] = '_';
}
}
// Check if this glyph has already been seen.
SkGlyphDigest* digestPtr = fDigestForPackedGlyphID.find(prototypeGlyph->getPackedID()); if (digestPtr != nullptr) { return fGlyphForIndex[digestPtr->index()];
}
// This is the first time. Allocate a new glyph.
SkGlyph* glyph = fAlloc.make<SkGlyph>(prototypeGlyph.value());
fMemoryIncrease += sizeof(SkGlyph);
this->addGlyphAndDigest(glyph); return glyph;
}
void SkStrike::updateMemoryUsage(size_t increase) { if (increase > 0) { // fRemoved and the cache's total memory are managed under the cache's lock. This allows // them to be accessed under LRU operation.
SkAutoMutexExclusive lock{fStrikeCache->fLock};
fMemoryUsed += increase; if (!fRemoved) {
fStrikeCache->fTotalMemoryUsed += increase;
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.