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

Unified Diff: ui/gfx/font_render_params_linux.cc

Issue 639123005: linux: Cache families from FontRenderParams queries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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: ui/gfx/font_render_params_linux.cc
diff --git a/ui/gfx/font_render_params_linux.cc b/ui/gfx/font_render_params_linux.cc
index 4f9fbc98b857f59e6aadd1c91c066f3b5fbc4671..4b86f320f2a25bd9cdcfac91c64d127f46419b77 100644
--- a/ui/gfx/font_render_params_linux.cc
+++ b/ui/gfx/font_render_params_linux.cc
@@ -29,13 +29,25 @@ namespace {
float device_scale_factor_for_internal_display = 1.0f;
#endif
-// Keyed by hashes of FontRenderParamQuery structs from
-// HashFontRenderParamsQuery().
-typedef base::MRUCache<uint32, FontRenderParams> Cache;
-
// Number of recent GetFontRenderParams() results to cache.
const size_t kCacheSize = 20;
+// Cached result from a call to GetFontRenderParams().
+struct QueryResult {
+ QueryResult(const FontRenderParams& params, const std::string& family)
+ : params(params),
+ family(family) {
+ }
+ ~QueryResult() {}
+
+ FontRenderParams params;
+ std::string family;
+};
+
+// Keyed by hashes of FontRenderParamQuery structs from
+// HashFontRenderParamsQuery().
+typedef base::MRUCache<uint32, QueryResult> Cache;
+
// A cache and the lock that must be held while accessing it.
// GetFontRenderParams() is called by both the UI thread and the sandbox IPC
// thread.
@@ -168,21 +180,24 @@ uint32 HashFontRenderParamsQuery(const FontRenderParamsQuery& query) {
FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
std::string* family_out) {
const uint32 hash = HashFontRenderParamsQuery(query);
- if (!family_out) {
- // The family returned by Fontconfig isn't part of FontRenderParams, so we
- // can only return a value from the cache if it wasn't requested.
- SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
+ SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
+
+ {
+ // Try to find a cached result so Fontconfig doesn't need to be queried.
base::AutoLock lock(synchronized_cache->lock);
Cache::const_iterator it = synchronized_cache->cache.Get(hash);
if (it != synchronized_cache->cache.end()) {
DVLOG(1) << "Returning cached params for " << hash;
- return it->second;
+ const QueryResult& result = it->second;
+ if (family_out)
+ *family_out = result.family;
+ return result.params;
}
- } else {
- family_out->clear();
}
- DVLOG(1) << "Computing params for " << hash
- << (family_out ? " (family requested)" : "");
+
+ DVLOG(1) << "Computing params for " << hash;
+ if (family_out)
+ family_out->clear();
// Start with the delegate's settings, but let Fontconfig have the final say.
FontRenderParams params;
@@ -215,12 +230,13 @@ FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
if (family_out && family_out->empty() && !query.families.empty())
*family_out = query.families[0];
- // Store the computed struct. It's fine if this overwrites a struct that was
- // cached by a different thread in the meantime; the values should be
- // identical.
- SynchronizedCache* synchronized_cache = g_synchronized_cache.Pointer();
- base::AutoLock lock(synchronized_cache->lock);
- synchronized_cache->cache.Put(hash, params);
+ {
+ // Store the result. It's fine if this overwrites a result that was cached
+ // by a different thread in the meantime; the values should be identical.
+ base::AutoLock lock(synchronized_cache->lock);
+ synchronized_cache->cache.Put(hash,
+ QueryResult(params, family_out ? *family_out : std::string()));
+ }
return params;
}
« 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