OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTextBlob_DEFINED | 8 #ifndef SkTextBlob_DEFINED |
9 #define SkTextBlob_DEFINED | 9 #define SkTextBlob_DEFINED |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 */ | 46 */ |
47 static const SkTextBlob* CreateFromBuffer(SkReadBuffer&); | 47 static const SkTextBlob* CreateFromBuffer(SkReadBuffer&); |
48 | 48 |
49 private: | 49 private: |
50 enum GlyphPositioning { | 50 enum GlyphPositioning { |
51 kDefault_Positioning = 0, // Default glyph advances -- zero scalars
per glyph. | 51 kDefault_Positioning = 0, // Default glyph advances -- zero scalars
per glyph. |
52 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p
er glyph. | 52 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p
er glyph. |
53 kFull_Positioning = 2 // Point positioning -- two scalars per g
lyph. | 53 kFull_Positioning = 2 // Point positioning -- two scalars per g
lyph. |
54 }; | 54 }; |
55 | 55 |
56 class RunRecord; | |
57 | |
58 class RunIterator { | 56 class RunIterator { |
59 public: | 57 public: |
60 RunIterator(const SkTextBlob* blob); | 58 RunIterator(const SkTextBlob* blob); |
61 | 59 |
62 bool done() const; | 60 bool done() const; |
63 void next(); | 61 void next(); |
64 | 62 |
65 uint32_t glyphCount() const; | 63 uint32_t glyphCount() const; |
66 const uint16_t* glyphs() const; | 64 const uint16_t* glyphs() const; |
67 const SkScalar* pos() const; | 65 const SkScalar* pos() const; |
68 const SkPoint& offset() const; | 66 const SkPoint& offset() const; |
69 void applyFontToPaint(SkPaint*) const; | 67 void applyFontToPaint(SkPaint*) const; |
70 GlyphPositioning positioning() const; | 68 GlyphPositioning positioning() const; |
71 | 69 |
72 private: | 70 private: |
73 const RunRecord* fCurrentRun; | 71 const SkTextBlob* fBlob; |
74 int fRemainingRuns; | 72 int fIndex; |
75 | |
76 SkDEBUGCODE(uint8_t* fStorageTop;) | |
77 }; | 73 }; |
78 | 74 |
79 SkTextBlob(int runCount, const SkRect& bounds); | 75 // A run is a sequence of glyphs sharing the same font metrics and positioni
ng mode. |
| 76 struct Run { |
| 77 uint32_t count; |
| 78 uint32_t glyphStart; // index into fGlyphBuffer |
| 79 uint32_t posStart; // index into fPosBuffer |
| 80 SkPoint offset; // run offset (unsued for fully positioned
glyphs) |
| 81 SkPaint font; |
| 82 GlyphPositioning positioning; |
| 83 }; |
80 | 84 |
81 virtual ~SkTextBlob(); | 85 SkTextBlob(uint16_t* glyphs, SkScalar* pos, const SkTArray<Run>* runs, const
SkRect& bounds); |
82 virtual void internal_dispose() const SK_OVERRIDE; | |
83 | 86 |
84 static unsigned ScalarsPerGlyph(GlyphPositioning pos); | 87 static unsigned ScalarsPerGlyph(GlyphPositioning pos); |
85 | 88 |
86 friend class SkBaseDevice; | 89 friend class SkBaseDevice; |
87 friend class SkTextBlobBuilder; | 90 friend class SkTextBlobBuilder; |
88 friend class TextBlobTester; | 91 friend class TextBlobTester; |
89 | 92 |
90 const int fRunCount; | 93 const SkAutoTMalloc<uint16_t> fGlyphBuffer; |
91 const SkRect fBounds; | 94 const SkAutoTMalloc<SkScalar> fPosBuffer; |
92 mutable uint32_t fUniqueID; | |
93 | 95 |
94 SkDEBUGCODE(size_t fStorageSize;) | 96 // SkTArray required here for run font destruction. |
| 97 SkAutoTDelete<const SkTArray<Run> > fRuns; |
| 98 const SkRect fBounds; |
95 | 99 |
96 // The actual payload resides in externally-managed storage, following the o
bject. | 100 mutable uint32_t fUniqueID; |
97 // (see the .cpp for more details) | |
98 | 101 |
99 typedef SkRefCnt INHERITED; | 102 typedef SkRefCnt INHERITED; |
100 }; | 103 }; |
101 | 104 |
102 /** \class SkTextBlobBuilder | 105 /** \class SkTextBlobBuilder |
103 | 106 |
104 Helper class for constructing SkTextBlobs. | 107 Helper class for constructing SkTextBlobs. |
105 */ | 108 */ |
106 class SK_API SkTextBlobBuilder { | 109 class SK_API SkTextBlobBuilder { |
107 public: | 110 public: |
108 SkTextBlobBuilder(); | 111 /** |
| 112 * @param runs The number of runs to be added, if known. This is a storage
hint and |
| 113 * not a limit. |
| 114 */ |
| 115 SkTextBlobBuilder(unsigned runs = 0); |
109 | 116 |
110 ~SkTextBlobBuilder(); | 117 ~SkTextBlobBuilder(); |
111 | 118 |
112 /** | 119 /** |
113 * Returns an immutable SkTextBlob for the current runs/glyphs. The builder
is reset and | 120 * Returns an immutable SkTextBlob for the current runs/glyphs. The builder
is reset and |
114 * can be reused. | 121 * can be reused. |
115 */ | 122 */ |
116 const SkTextBlob* build(); | 123 const SkTextBlob* build(); |
117 | 124 |
118 /** | 125 /** |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 * @param bounds Optional run bounding box. If known in advance (!= NULL),
it will | 173 * @param bounds Optional run bounding box. If known in advance (!= NULL),
it will |
167 * be used when computing the blob bounds, to avoid re-measur
ing. | 174 * be used when computing the blob bounds, to avoid re-measur
ing. |
168 * | 175 * |
169 * @return Writable glyph and position buffers, valid until the next
allocRun() | 176 * @return Writable glyph and position buffers, valid until the next
allocRun() |
170 * or build() call. The glyph buffer and position buffer are | 177 * or build() call. The glyph buffer and position buffer are |
171 * guaranteed to hold @count@ and 2 * @count@ elements, respe
ctively. | 178 * guaranteed to hold @count@ and 2 * @count@ elements, respe
ctively. |
172 */ | 179 */ |
173 const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* b
ounds = NULL); | 180 const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* b
ounds = NULL); |
174 | 181 |
175 private: | 182 private: |
176 void reserve(size_t size); | |
177 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio
ning, | 183 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio
ning, |
178 int count, SkPoint offset, const SkRect* bounds); | 184 int count, SkPoint offset, const SkRect* bounds); |
179 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, | 185 void ensureRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning
, |
180 int count, SkPoint offset); | 186 const SkPoint& offset); |
181 void updateDeferredBounds(); | 187 void updateDeferredBounds(); |
182 | 188 |
183 SkAutoTMalloc<uint8_t> fStorage; | 189 SkTDArray<uint16_t> fGlyphBuffer; |
184 size_t fStorageSize; | 190 SkTDArray<SkScalar> fPosBuffer; |
185 size_t fStorageUsed; | 191 SkTArray<SkTextBlob::Run>* fRuns; |
186 | 192 |
187 SkRect fBounds; | 193 SkRect fBounds; |
188 int fRunCount; | 194 bool fDeferredBounds; |
189 bool fDeferredBounds; | |
190 size_t fLastRun; // index into fStorage | |
191 | 195 |
192 RunBuffer fCurrentRunBuffer; | 196 RunBuffer fCurrentRunBuffer; |
193 }; | 197 }; |
194 | 198 |
195 #endif // SkTextBlob_DEFINED | 199 #endif // SkTextBlob_DEFINED |
OLD | NEW |