Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: src/ports/SkFontHost_fontconfig.cpp

Issue 1919183002: Store null font lookup result into font cache (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_fontconfig.cpp
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index 1394efdda3c25f77132da87a3d164be028ad1d7e..600b0e5a87ebf0e64ba581df549209300bcc7b16 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -131,6 +131,11 @@ private:
SkAutoTUnref<SkTypeface> fFace;
};
+ struct LookUpContext {
+ bool found;
+ SkTypeface* face;
+ };
+
SkResourceCache fCachedResults;
public:
@@ -141,16 +146,18 @@ public:
fCachedResults.add(new Result(request, face));
}
/** Does not take ownership of request. */
- SkTypeface* findAndRef(Request* request) {
- SkTypeface* face = nullptr;
+ bool findAndRef(Request* request, SkTypeface** face) {
+ LookUpContext lookup_context = {false, nullptr};
fCachedResults.find(*request, [](const SkResourceCache::Rec& rec, void* context) -> bool {
const Result& result = static_cast<const Result&>(rec);
- SkTypeface** face = static_cast<SkTypeface**>(context);
+ LookUpContext* lookup_context = static_cast<LookUpContext*>(context);
- *face = result.fFace;
+ lookup_context->found = true;
+ lookup_context->face = result.fFace;
return true;
- }, &face);
- return SkSafeRef(face);
+ }, &lookup_context);
+ *face = SkSafeRef(lookup_context.face);
+ return lookup_context.found;
}
/** Takes ownership of request. It will be deleted when no longer needed. */
@@ -160,9 +167,9 @@ public:
}
/** Does not take ownership of request. */
- static SkTypeface* FindAndRef(Request* request) {
+ static bool FindAndRef(Request* request, SkTypeface** face) {
SkAutoMutexAcquire ama(gSkFontHostRequestCacheMutex);
- return Get().findAndRef(request);
+ return Get().findAndRef(request, face);
}
};
@@ -177,8 +184,8 @@ SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char requestedFamilyN
// Check if this request is already in the request cache.
using Request = SkFontHostRequestCache::Request;
SkAutoTDelete<Request> request(Request::Create(requestedFamilyName, requestedStyle));
- SkTypeface* face = SkFontHostRequestCache::FindAndRef(request);
- if (face) {
+ SkTypeface* face;
+ if (SkFontHostRequestCache::FindAndRef(request, &face)) {
return face;
}
@@ -188,6 +195,7 @@ SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char requestedFamilyN
if (!fci->matchFamilyName(requestedFamilyName, requestedStyle,
&identity, &outFamilyName, &outStyle))
{
+ SkFontHostRequestCache::Add(nullptr, request.release());
return nullptr;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698