summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-21 08:37:49 -0700
committerRaph Levien <raph@google.com>2014-05-27 15:39:33 +0000
commit4d4e6bc8118d15542f1f2a9218f0f7a91a29474f (patch)
treecdfd772d61a6eb71d7268f5d278e82202a247769 /include
parentd973b3926b3a34c19d3d6f309fae1138e782e4dc (diff)
downloadandroid_frameworks_minikin-4d4e6bc8118d15542f1f2a9218f0f7a91a29474f.tar.gz
android_frameworks_minikin-4d4e6bc8118d15542f1f2a9218f0f7a91a29474f.tar.bz2
android_frameworks_minikin-4d4e6bc8118d15542f1f2a9218f0f7a91a29474f.zip
Caching for layouts and harfbuzz faces
This patch adds caching for both layouts and for HarfBuzz face objects. The granularity of the cache for layouts is words, so it splits the input string at word boundaries (using a heuristic). There are is also some refactoring to reduce the amount of allocation and copying, and movement towards properly supporting contexts. The size of the caches is a fixed number of entries; thus, it is possible to consume a large amount of memory by filling the cache with lots of large strings. This should be refined towards a scheme that bounds the total memory used by the cache. This patch fixes bug 15237293 "Regression: Measure performance is significantly slower with minikin". Change-Id: Ie8176857e2d78656ce5479a7c04969819ef2718d
Diffstat (limited to 'include')
-rw-r--r--include/minikin/FontCollection.h11
-rw-r--r--include/minikin/FontFamily.h14
-rw-r--r--include/minikin/Layout.h41
-rw-r--r--include/minikin/MinikinFont.h1
4 files changed, 51 insertions, 16 deletions
diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h
index dc48f8e..c6c2ed0 100644
--- a/include/minikin/FontCollection.h
+++ b/include/minikin/FontCollection.h
@@ -54,9 +54,12 @@ public:
int start;
int end;
};
+
void itemize(const uint16_t *string, size_t string_length, FontStyle style,
std::vector<Run>* result) const;
- private:
+
+ uint32_t getId() const;
+private:
static const int kLogCharsPerPage = 8;
static const int kPageMask = (1 << kLogCharsPerPage) - 1;
@@ -70,6 +73,12 @@ public:
size_t end;
};
+ // static for allocating unique id's
+ static uint32_t sNextId;
+
+ // unique id for this font collection (suitable for cache key)
+ uint32_t mId;
+
// Highest UTF-32 code point that can be mapped
uint32_t mMaxChar;
diff --git a/include/minikin/FontFamily.h b/include/minikin/FontFamily.h
index 82fcfe9..a4fe9cb 100644
--- a/include/minikin/FontFamily.h
+++ b/include/minikin/FontFamily.h
@@ -19,6 +19,8 @@
#include <vector>
+#include <utils/TypeHelpers.h>
+
#include <minikin/MinikinRefCounted.h>
namespace android {
@@ -31,16 +33,22 @@ public:
FontStyle(int weight = 4, bool italic = false) {
bits = (weight & kWeightMask) | (italic ? kItalicMask : 0);
}
- int getWeight() { return bits & kWeightMask; }
- bool getItalic() { return (bits & kItalicMask) != 0; }
- bool operator==(const FontStyle other) { return bits == other.bits; }
+ int getWeight() const { return bits & kWeightMask; }
+ bool getItalic() const { return (bits & kItalicMask) != 0; }
+ bool operator==(const FontStyle other) const { return bits == other.bits; }
// TODO: language, variant
+
+ hash_t hash() const { return bits; }
private:
static const int kWeightMask = 0xf;
static const int kItalicMask = 16;
uint32_t bits;
};
+inline hash_t hash_type(const FontStyle &style) {
+ return style.hash();
+}
+
class FontFamily : public MinikinRefCounted {
public:
~FontFamily();
diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h
index 6c338db..a1ef0c1 100644
--- a/include/minikin/Layout.h
+++ b/include/minikin/Layout.h
@@ -55,6 +55,9 @@ struct LayoutGlyph {
float y;
};
+// Internal state used during layout operation
+class LayoutContext;
+
// Lifecycle and threading assumptions for Layout:
// The object is assumed to be owned by a single thread; multiple threads
// may not mutate it at the same time.
@@ -62,13 +65,19 @@ struct LayoutGlyph {
// extend through the lifetime of the Layout object.
class Layout {
public:
- ~Layout();
-
void dump() const;
void setFontCollection(const FontCollection* collection);
+
+ // deprecated - missing functionality
void doLayout(const uint16_t* buf, size_t nchars);
- void draw(Bitmap*, int x0, int y0) const;
- void setProperties(const std::string css);
+
+ void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
+ const std::string& css);
+
+ void draw(Bitmap*, int x0, int y0, float size) const;
+
+ // deprecated - pass as argument to doLayout instead
+ void setProperties(const std::string& css);
// This must be called before any invocations.
// TODO: probably have a factory instead
@@ -92,23 +101,31 @@ public:
private:
// Find a face in the mFaces vector, or create a new entry
- int findFace(MinikinFont* face, MinikinPaint* paint);
+ int findFace(MinikinFont* face, LayoutContext* ctx);
+
+ // Lay out a single bidi run
+ void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
+ bool isRtl, LayoutContext* ctx);
+
+ // Lay out a single word
+ void doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
+ bool isRtl, LayoutContext* ctx, size_t bufStart);
// Lay out a single bidi run
void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
- bool isRtl, FontStyle style, MinikinPaint& paint);
+ bool isRtl, LayoutContext* ctx);
+
+ // Append another layout (for example, cached value) into this one
+ void appendLayout(Layout* src, size_t start);
+
+ // deprecated - remove when setProperties is removed
+ std::string mCssString;
- CssProperties mProps; // TODO: want spans
std::vector<LayoutGlyph> mGlyphs;
std::vector<float> mAdvances;
- // In future, this will be some kind of mapping from the
- // identifier used to represent font-family to a font collection.
- // But for the time being, it should be ok to have just one
- // per layout.
const FontCollection* mCollection;
std::vector<MinikinFont *> mFaces;
- std::vector<hb_font_t *> mHbFonts;
float mAdvance;
MinikinRect mBounds;
};
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h
index 568f19d..dbb89f8 100644
--- a/include/minikin/MinikinFont.h
+++ b/include/minikin/MinikinFont.h
@@ -27,6 +27,7 @@ namespace android {
class MinikinFont;
// Possibly move into own .h file?
+// Note: if you add a field here, also update LayoutCacheKey
struct MinikinPaint {
MinikinFont *font;
float size;