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

Unified Diff: content/common/font_config_ipc_linux.cc

Issue 697383002: Fix for the font files being maped multiple times (Fontconfig). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 | « content/common/font_config_ipc_linux.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/font_config_ipc_linux.cc
diff --git a/content/common/font_config_ipc_linux.cc b/content/common/font_config_ipc_linux.cc
index fcb06ebac0def482978e79011532e8b59804bebd..ca3509a0ce4f750316f3c3654c5189ae2f2f332a 100644
--- a/content/common/font_config_ipc_linux.cc
+++ b/content/common/font_config_ipc_linux.cc
@@ -23,13 +23,21 @@
namespace content {
+class FontConfigIPC::FontMemoryStream
+ : public SkMemoryStream,
+ public base::SupportsWeakPtr<FontConfigIPC::FontMemoryStream> {
Daniel Erat 2014/11/06 20:33:55 do you actually need SupportsWeakPtr here and the
Krzysztof Olczyk 2014/11/07 11:38:00 Yes, there was also the problem with the fact that
+ public:
+ explicit FontMemoryStream(SkData* data) : SkMemoryStream(data) {}
+ ~FontMemoryStream() override {}
+};
+
// Return a stream from the file descriptor, or NULL on failure.
-SkStream* StreamFromFD(int fd) {
+FontConfigIPC::FontMemoryStream* FontConfigIPC::StreamFromFD(int fd) {
skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd));
if (!data) {
return NULL;
}
- return new SkMemoryStream(data.get());
+ return new FontMemoryStream(data.get());
}
void CloseFD(int fd) {
@@ -96,6 +104,13 @@ bool FontConfigIPC::matchFamilyName(const char familyName[],
SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream");
+
+ auto stream_cache_it = font_stream_cache_.find(identity.fID);
+ if (stream_cache_it != font_stream_cache_.end() && stream_cache_it->second)
+ return stream_cache_it->second.get();
+
+ PurgeFontStreamCache();
+
Pickle request;
request.WriteInt(METHOD_OPEN);
request.WriteUInt32(identity.fID);
@@ -119,10 +134,21 @@ SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
return NULL;
}
- SkStream* stream = StreamFromFD(result_fd);
+ FontMemoryStream* stream = StreamFromFD(result_fd);
CloseFD(result_fd);
+ font_stream_cache_[identity.fID] = base::AsWeakPtr(stream);
return stream;
}
+void FontConfigIPC::PurgeFontStreamCache() {
+ auto stream_cache_it = font_stream_cache_.begin();
+ while (stream_cache_it != font_stream_cache_.end()) {
+ if (!stream_cache_it->second)
+ font_stream_cache_.erase(stream_cache_it++);
+ else
+ ++stream_cache_it;
+ }
+}
+
} // namespace content
« no previous file with comments | « content/common/font_config_ipc_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698