/* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #include"src/text/gpu/StrikeCache.h"
sk_sp<TextStrike> StrikeCache::internalFindStrikeOrNull(const SkDescriptor& desc) { // Check head because it is likely the strike we are looking for. if (fHead != nullptr && fHead->getDescriptor() == desc) { return sk_ref_sp(fHead); }
// Do the heavy search looking for the strike.
sk_sp<TextStrike>* strikeHandle = fCache.find(desc); if (strikeHandle == nullptr) { return nullptr; }
TextStrike* strikePtr = strikeHandle->get();
SkASSERT(strikePtr != nullptr); if (fHead != strikePtr) { // Make most recently used
strikePtr->fPrev->fNext = strikePtr->fNext; if (strikePtr->fNext != nullptr) {
strikePtr->fNext->fPrev = strikePtr->fPrev;
} else {
fTail = strikePtr->fPrev;
}
fHead->fPrev = strikePtr;
strikePtr->fNext = fHead;
strikePtr->fPrev = nullptr;
fHead = strikePtr;
} return sk_ref_sp(strikePtr);
}
size_t StrikeCache::internalPurge(size_t minBytesNeeded) {
size_t bytesNeeded = 0; if (fTotalMemoryUsed > fCacheSizeLimit) {
bytesNeeded = fTotalMemoryUsed - fCacheSizeLimit;
}
bytesNeeded = std::max(bytesNeeded, minBytesNeeded); if (bytesNeeded) { // no small purges!
bytesNeeded = std::max(bytesNeeded, fTotalMemoryUsed >> 2);
}
int countNeeded = 0; if (fCacheCount > fCacheCountLimit) {
countNeeded = fCacheCount - fCacheCountLimit; // no small purges!
countNeeded = std::max(countNeeded, fCacheCount >> 2);
}
// early exit if (!countNeeded && !bytesNeeded) { return 0;
}
size_t bytesFreed = 0; int countFreed = 0;
// Start at the tail and proceed backwards deleting; the list is in LRU // order, with unimportant entries at the tail.
TextStrike* strike = fTail; while (strike != nullptr && (bytesFreed < bytesNeeded || countFreed < countNeeded)) {
TextStrike* prev = strike->fPrev;
// If there is a client, then this from a different process. Translate the SkTypefaceID from // the strike server (Renderer) process to strike client (GPU) process. if (client != nullptr) { if (!client->translateTypefaceID(&descriptor.value())) { return std::nullopt;
}
}
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.