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

Unified Diff: src/ports/SkFontHost_linux.cpp

Issue 729973004: add runtime config option to retain stream for custom typefaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: actually pass the path to the stream constructor 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 | « 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_linux.cpp
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index 6003c095c164ee23125a34ca5ed0eedc00005d65..69a88136d1cc52e8881b502465dc76ddd1c7d90b 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -12,6 +12,7 @@
#include "SkDescriptor.h"
#include "SkOSFile.h"
#include "SkPaint.h"
+#include "SkRTConf.h"
#include "SkString.h"
#include "SkStream.h"
#include "SkThread.h"
@@ -101,6 +102,13 @@ private:
typedef SkTypeface_Custom INHERITED;
};
+// This configuration option is useful if we need to open and hold handles to
+// all found system font data (e.g., for skfiddle, where the application can't
+// access the filesystem to read fonts on demand)
+
+SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false,
+ "Retain the open stream for each found font on the system.");
+
/** The file SkTypeface implementation for the custom font manager. */
class SkTypeface_File : public SkTypeface_Custom {
public:
@@ -108,7 +116,12 @@ public:
const SkString familyName, const char path[], int index)
: INHERITED(style, isFixedPitch, sysFont, familyName, index)
, fPath(path)
- { }
+ , fStream(NULL)
bungeman-skia 2014/11/19 15:14:13 I prefer the form , fStream(c_CustomTypefaceRetai
+ {
+ if (c_CustomTypefaceRetain) {
+ fStream = SkStream::NewFromFile(fPath.c_str());
+ }
+ }
virtual const char* getUniqueString() const SK_OVERRIDE {
const char* str = strrchr(fPath.c_str(), '/');
@@ -121,11 +134,16 @@ public:
protected:
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
*ttcIndex = this->getIndex();
- return SkStream::NewFromFile(fPath.c_str());
+ if (NULL != fStream) {
bungeman-skia 2014/11/19 15:14:14 I think we're just using if (fStream.get()) { th
+ return fStream->duplicate();
+ } else {
+ return SkStream::NewFromFile(fPath.c_str());
+ }
}
private:
SkString fPath;
+ SkAutoTUnref<SkStream> fStream;
bungeman-skia 2014/11/19 15:14:13 Above (in SkTypeface_Stream) this is const SkAuto
typedef SkTypeface_Custom INHERITED;
};
« 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