summaryrefslogtreecommitdiffstats
path: root/libs/hwui/font/Font.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2013-03-05 16:43:31 -0800
committerRomain Guy <romainguy@google.com>2013-03-05 18:12:35 -0800
commit624234f69b2a4781d24f3e4c6ae6450729e38397 (patch)
treed6ae0bfd751e0e59329cb678c1d9f1cec447ee3e /libs/hwui/font/Font.cpp
parent0b58a3deab66c30a8d35072e55aac6279dd367cc (diff)
downloadframeworks_base-624234f69b2a4781d24f3e4c6ae6450729e38397.zip
frameworks_base-624234f69b2a4781d24f3e4c6ae6450729e38397.tar.gz
frameworks_base-624234f69b2a4781d24f3e4c6ae6450729e38397.tar.bz2
Take only the scale params into account to rasterize text
This change extracts the scale parameters of the current transform to pass then to the font renderer. Rotation and perspective are applied to the generated mesh inside the vertex shader. This limits the number of glyphs we have to create in the font cache and thus reduces memory churn. Change-Id: Ic5b3bae2b2b0e0250a8ee723b071a1709725c749
Diffstat (limited to 'libs/hwui/font/Font.cpp')
-rw-r--r--libs/hwui/font/Font.cpp31
1 files changed, 6 insertions, 25 deletions
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp
index bf522b7..9307f11 100644
--- a/libs/hwui/font/Font.cpp
+++ b/libs/hwui/font/Font.cpp
@@ -53,10 +53,8 @@ Font::FontDescription::FontDescription(const SkPaint* paint, const mat4& matrix)
mStrokeWidth = paint->getStrokeWidth();
mAntiAliasing = paint->isAntiAlias();
mLookupTransform.reset();
- mLookupTransform[SkMatrix::kMScaleX] = matrix.data[mat4::kScaleX];
- mLookupTransform[SkMatrix::kMScaleY] = matrix.data[mat4::kScaleY];
- mLookupTransform[SkMatrix::kMSkewX] = matrix.data[mat4::kSkewX];
- mLookupTransform[SkMatrix::kMSkewY] = matrix.data[mat4::kSkewY];
+ mLookupTransform[SkMatrix::kMScaleX] = matrix[mat4::kScaleX];
+ mLookupTransform[SkMatrix::kMScaleY] = matrix[mat4::kScaleY];
if (!mLookupTransform.invert(&mInverseLookupTransform)) {
ALOGW("Could not query the inverse lookup transform for this font");
}
@@ -81,8 +79,6 @@ hash_t Font::FontDescription::hash() const {
hash = JenkinsHashMix(hash, int(mAntiAliasing));
hash = JenkinsHashMix(hash, android::hash_type(mLookupTransform[SkMatrix::kMScaleX]));
hash = JenkinsHashMix(hash, android::hash_type(mLookupTransform[SkMatrix::kMScaleY]));
- hash = JenkinsHashMix(hash, android::hash_type(mLookupTransform[SkMatrix::kMSkewX]));
- hash = JenkinsHashMix(hash, android::hash_type(mLookupTransform[SkMatrix::kMSkewY]));
return JenkinsHashWhiten(hash);
}
@@ -122,16 +118,6 @@ int Font::FontDescription::compare(const Font::FontDescription& lhs,
if (lhs.mLookupTransform[SkMatrix::kMScaleY] >
rhs.mLookupTransform[SkMatrix::kMScaleY]) return +1;
- if (lhs.mLookupTransform[SkMatrix::kMSkewX] <
- rhs.mLookupTransform[SkMatrix::kMSkewX]) return -1;
- if (lhs.mLookupTransform[SkMatrix::kMSkewX] >
- rhs.mLookupTransform[SkMatrix::kMSkewX]) return +1;
-
- if (lhs.mLookupTransform[SkMatrix::kMSkewY] <
- rhs.mLookupTransform[SkMatrix::kMSkewY]) return -1;
- if (lhs.mLookupTransform[SkMatrix::kMSkewY] >
- rhs.mLookupTransform[SkMatrix::kMSkewY]) return +1;
-
return 0;
}
@@ -185,7 +171,7 @@ void Font::drawCachedGlyph(CachedGlyphInfo* glyph, int x, int y,
nPenX, nPenY - height, u1, v1, glyph->mCacheTexture);
}
-void Font::drawCachedGlyphPerspective(CachedGlyphInfo* glyph, int x, int y,
+void Font::drawCachedGlyphTransformed(CachedGlyphInfo* glyph, int x, int y,
uint8_t* bitmap, uint32_t bitmapW, uint32_t bitmapH, Rect* bounds, const float* pos) {
SkPoint p[4];
p[0].iset(glyph->mBitmapLeft, glyph->mBitmapTop + glyph->mBitmapHeight);
@@ -388,18 +374,17 @@ void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len
static RenderGlyph gRenderGlyph[] = {
&android::uirenderer::Font::drawCachedGlyph,
- &android::uirenderer::Font::drawCachedGlyphPerspective,
+ &android::uirenderer::Font::drawCachedGlyphTransformed,
&android::uirenderer::Font::drawCachedGlyphBitmap,
&android::uirenderer::Font::drawCachedGlyphBitmap,
&android::uirenderer::Font::measureCachedGlyph,
&android::uirenderer::Font::measureCachedGlyph
};
- RenderGlyph render = gRenderGlyph[(mode << 1) + mTransform.isPerspective()];
+ RenderGlyph render = gRenderGlyph[(mode << 1) + !mIdentityTransform];
text += start;
int glyphsCount = 0;
- const bool applyTransform = !mTransform.isIdentity() && !mTransform.isPerspective();
const SkPaint::Align align = paint->getTextAlign();
while (glyphsCount < numGlyphs) {
@@ -418,10 +403,6 @@ void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len
float penX = x + positions[(glyphsCount << 1)];
float penY = y + positions[(glyphsCount << 1) + 1];
- if (applyTransform) {
- mTransform.mapPoint(penX, penY);
- }
-
(*this.*render)(cachedGlyph, roundf(penX), roundf(penY),
bitmap, bitmapW, bitmapH, bounds, positions);
}
@@ -495,7 +476,7 @@ Font* Font::create(FontRenderer* state, const SkPaint* paint, const mat4& matrix
font = new Font(state, description);
state->mActiveFonts.put(description, font);
}
- font->mTransform.load(matrix);
+ font->mIdentityTransform = matrix.isIdentity();
return font;
}