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