aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkFindAndPlaceGlyph.h
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2015-11-11 11:30:11 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-11 11:30:11 -0800
commit9be5ff6f9871ef22740094e7c25dd67329a73d20 (patch)
treec5242a25bdd92f010abf3b04d80a71fbd5b27d4e /src/core/SkFindAndPlaceGlyph.h
parent0b2a18922146c6134515d42baf5935b71bba03c3 (diff)
Replace glyph find and position with common code for the gpu bitmap case.
Diffstat (limited to 'src/core/SkFindAndPlaceGlyph.h')
-rw-r--r--src/core/SkFindAndPlaceGlyph.h74
1 files changed, 26 insertions, 48 deletions
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h
index 320caf44f7..0280e90c82 100644
--- a/src/core/SkFindAndPlaceGlyph.h
+++ b/src/core/SkFindAndPlaceGlyph.h
@@ -53,21 +53,6 @@ public:
SkPaint::Align textAlignment, SkDrawCacheProc& glyphCacheProc,
SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph);
- // SpecializedProcessPosText is a version of ProcessPosText that de-virtualizes the
- // different components used. It returns true if it can handle the situation, otherwise it
- // returns false. This allows greater inlining freedom to the compiler. Currently, there is
- // only one specialized variant: sub-pixel position, left-aligned, x-axis-aligned,
- // translation, and one scalar per position entry.
- // * This is by far the most common type of text Blink draws.
- template<typename ProcessOneGlyph>
- static bool SpecializedProcessPosText(const char* const text, size_t byteLength,
- const SkPoint& offset, const SkMatrix& matrix,
- const SkScalar pos[], int scalarsPerPosition,
- SkPaint::Align textAlignment,
- SkDrawCacheProc& glyphCacheProc,
- SkGlyphCache* cache,
- ProcessOneGlyph&& processOneGlyph);
-
private:
// UntaggedVariant is a pile of memory that can hold one of the Ts. It provides a way
// to initialize that memory in a typesafe way.
@@ -417,6 +402,32 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
const SkScalar pos[], int scalarsPerPosition, SkPaint::Align textAlignment,
SkDrawCacheProc& glyphCacheProc, SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph) {
+ SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(matrix);
+ uint32_t mtype = matrix.getType();
+
+ // Specialized code for handling the most common case for blink. The while loop is totally
+ // de-virtualized.
+ if (scalarsPerPosition == 1
+ && textAlignment == SkPaint::kLeft_Align
+ && axisAlignment == kX_SkAxisAlignment
+ && cache->isSubpixel()
+ && mtype <= SkMatrix::kTranslate_Mask) {
+ typedef GlyphFindAndPlaceSubpixel<
+ ProcessOneGlyph, SkPaint::kLeft_Align, kX_SkAxisAlignment> Positioner;
+ HorizontalPositions positions{pos};
+ TranslationMapper mapper{matrix, offset};
+ Positioner positioner(cache, glyphCacheProc);
+ const char* cursor = text;
+ const char* stop = text + byteLength;
+ while (cursor < stop) {
+ SkPoint mappedPoint = mapper.TranslationMapper::map(
+ positions.HorizontalPositions::nextPoint());
+ positioner.Positioner::findAndPositionGlyph(
+ &cursor, mappedPoint, skstd::forward<ProcessOneGlyph>(processOneGlyph));
+ }
+ return;
+ }
+
PositionReader positionReader{
[&](PositionReader::Variants* to_init) {
if (2 == scalarsPerPosition) {
@@ -429,7 +440,6 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
Mapper mapper{
[&](Mapper::Variants* to_init) {
- uint32_t mtype = matrix.getType();
if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)
|| scalarsPerPosition == 2) {
to_init->initialize<GeneralMapper>(matrix, offset);
@@ -444,7 +454,6 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
GlyphFindAndPlace<ProcessOneGlyph> findAndPosition{
[&](typename GlyphFindAndPlace<ProcessOneGlyph>::Variants* to_init) {
if (cache->isSubpixel()) {
- SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(matrix);
switch (textAlignment) {
case SkPaint::kLeft_Align:
InitSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>(
@@ -489,35 +498,4 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
}
}
-template<typename ProcessOneGlyph>
-inline bool SkFindAndPlaceGlyph::SpecializedProcessPosText(
- const char* const text, size_t byteLength, const SkPoint& offset, const SkMatrix& matrix,
- const SkScalar pos[], int scalarsPerPosition, SkPaint::Align textAlignment,
- SkDrawCacheProc& glyphCacheProc, SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph) {
- SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(matrix);
- uint32_t mtype = matrix.getType();
- if (scalarsPerPosition == 1
- && textAlignment == SkPaint::kLeft_Align
- && axisAlignment == kX_SkAxisAlignment
- && cache->isSubpixel()
- && mtype <= SkMatrix::kTranslate_Mask) {
- typedef GlyphFindAndPlaceSubpixel<
- ProcessOneGlyph, SkPaint::kLeft_Align, kX_SkAxisAlignment> Positioner;
- HorizontalPositions positions{pos};
- TranslationMapper mapper{matrix, offset};
- Positioner positioner(cache, glyphCacheProc);
- const char* cursor = text;
- const char* stop = text + byteLength;
- while (cursor < stop) {
- SkPoint mappedPoint = mapper.TranslationMapper::map(
- positions.HorizontalPositions::nextPoint());
- positioner.Positioner::findAndPositionGlyph(
- &cursor, mappedPoint, skstd::forward<ProcessOneGlyph>(processOneGlyph));
- }
- return true;
- }
- return false;
-}
-
-
#endif // SkFindAndPositionGlyph_DEFINED