OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrAtlasTextBlob_DEFINED | 8 #ifndef GrAtlasTextBlob_DEFINED |
9 #define GrAtlasTextBlob_DEFINED | 9 #define GrAtlasTextBlob_DEFINED |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // To ensure we always have one subrun, we push back a fresh run her
e | 70 // To ensure we always have one subrun, we push back a fresh run her
e |
71 fSubRunInfo.push_back(); | 71 fSubRunInfo.push_back(); |
72 } | 72 } |
73 struct SubRunInfo { | 73 struct SubRunInfo { |
74 SubRunInfo() | 74 SubRunInfo() |
75 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) | 75 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) |
76 , fVertexStartIndex(0) | 76 , fVertexStartIndex(0) |
77 , fVertexEndIndex(0) | 77 , fVertexEndIndex(0) |
78 , fGlyphStartIndex(0) | 78 , fGlyphStartIndex(0) |
79 , fGlyphEndIndex(0) | 79 , fGlyphEndIndex(0) |
80 , fTextRatio(1.0f) | |
81 , fMaskFormat(kA8_GrMaskFormat) | 80 , fMaskFormat(kA8_GrMaskFormat) |
82 , fDrawAsDistanceFields(false) | 81 , fDrawAsDistanceFields(false) |
83 , fUseLCDText(false) {} | 82 , fUseLCDText(false) {} |
84 SubRunInfo(const SubRunInfo& that) | 83 SubRunInfo(const SubRunInfo& that) |
85 : fBulkUseToken(that.fBulkUseToken) | 84 : fBulkUseToken(that.fBulkUseToken) |
86 , fStrike(SkSafeRef(that.fStrike.get())) | 85 , fStrike(SkSafeRef(that.fStrike.get())) |
87 , fAtlasGeneration(that.fAtlasGeneration) | 86 , fAtlasGeneration(that.fAtlasGeneration) |
88 , fVertexStartIndex(that.fVertexStartIndex) | 87 , fVertexStartIndex(that.fVertexStartIndex) |
89 , fVertexEndIndex(that.fVertexEndIndex) | 88 , fVertexEndIndex(that.fVertexEndIndex) |
90 , fGlyphStartIndex(that.fGlyphStartIndex) | 89 , fGlyphStartIndex(that.fGlyphStartIndex) |
91 , fGlyphEndIndex(that.fGlyphEndIndex) | 90 , fGlyphEndIndex(that.fGlyphEndIndex) |
92 , fTextRatio(that.fTextRatio) | |
93 , fMaskFormat(that.fMaskFormat) | 91 , fMaskFormat(that.fMaskFormat) |
94 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) | 92 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) |
95 , fUseLCDText(that.fUseLCDText) { | 93 , fUseLCDText(that.fUseLCDText) { |
96 } | 94 } |
97 // Distance field text cannot draw coloremoji, and so has to fall ba
ck. However, | 95 |
98 // though the distance field text and the coloremoji may share the s
ame run, they | 96 void resetBulkUseToken() { fBulkUseToken.reset(); } |
99 // will have different descriptors. If fOverrideDescriptor is non-n
ullptr, then it | 97 GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUse
Token; } |
100 // will be used in place of the run's descriptor to regen texture co
ords | 98 void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(stri
ke)); } |
101 // TODO we could have a descriptor cache, it would reduce the size o
f these blobs | 99 GrBatchTextStrike* strike() const { return fStrike.get(); } |
102 // significantly, and then the subrun could just have a refed pointe
r to the | 100 |
103 // correct descriptor. | 101 void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration
= atlasGeneration;} |
| 102 uint64_t atlasGeneration() const { return fAtlasGeneration; } |
| 103 |
| 104 size_t byteCount() const { return fVertexEndIndex - fVertexStartInde
x; } |
| 105 void setVertexStartIndex(size_t vertStartIndex) { fVertexStartIndex
= vertStartIndex;} |
| 106 size_t vertexStartIndex() const { return fVertexStartIndex; } |
| 107 void setVertexEndIndex(size_t vertEndIndex) { fVertexEndIndex = vert
EndIndex; } |
| 108 size_t vertexEndIndex() const { return fVertexEndIndex; } |
| 109 void appendVertices(size_t vertexStride) { |
| 110 fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
| 111 } |
| 112 |
| 113 uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartInd
ex; } |
| 114 void setGlyphStartIndex(uint32_t glyphStartIndex) { fGlyphStartIndex
= glyphStartIndex;} |
| 115 uint32_t glyphStartIndex() const { return fGlyphStartIndex; } |
| 116 void setGlyphEndIndex(uint32_t glyphEndIndex) { fGlyphEndIndex = gly
phEndIndex; } |
| 117 uint32_t glyphEndIndex() const { return fGlyphEndIndex; } |
| 118 void glyphAppended() { fGlyphEndIndex++; } |
| 119 void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; } |
| 120 GrMaskFormat maskFormat() const { return fMaskFormat; } |
| 121 |
| 122 // df properties |
| 123 void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } |
| 124 bool hasUseLCDText() const { return fUseLCDText; } |
| 125 void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; } |
| 126 bool drawAsDistanceFields() const { return fDrawAsDistanceFields; } |
| 127 |
| 128 private: |
104 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; | 129 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; |
105 SkAutoTUnref<GrBatchTextStrike> fStrike; | 130 SkAutoTUnref<GrBatchTextStrike> fStrike; |
106 uint64_t fAtlasGeneration; | 131 uint64_t fAtlasGeneration; |
107 size_t fVertexStartIndex; | 132 size_t fVertexStartIndex; |
108 size_t fVertexEndIndex; | 133 size_t fVertexEndIndex; |
109 uint32_t fGlyphStartIndex; | 134 uint32_t fGlyphStartIndex; |
110 uint32_t fGlyphEndIndex; | 135 uint32_t fGlyphEndIndex; |
111 SkScalar fTextRatio; // df property | |
112 GrMaskFormat fMaskFormat; | 136 GrMaskFormat fMaskFormat; |
113 bool fDrawAsDistanceFields; // df property | 137 bool fDrawAsDistanceFields; // df property |
114 bool fUseLCDText; // df property | 138 bool fUseLCDText; // df property |
115 }; | 139 }; |
116 | 140 |
117 SubRunInfo& push_back() { | 141 SubRunInfo& push_back() { |
118 // Forward glyph / vertex information to seed the new sub run | 142 // Forward glyph / vertex information to seed the new sub run |
119 SubRunInfo& newSubRun = fSubRunInfo.push_back(); | 143 SubRunInfo& newSubRun = fSubRunInfo.push_back(); |
120 SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); | 144 SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); |
121 | 145 |
122 newSubRun.fGlyphStartIndex = prevSubRun.fGlyphEndIndex; | 146 newSubRun.setGlyphStartIndex(prevSubRun.glyphEndIndex()); |
123 newSubRun.fGlyphEndIndex = prevSubRun.fGlyphEndIndex; | 147 newSubRun.setGlyphEndIndex(prevSubRun.glyphEndIndex()); |
124 | 148 |
125 newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex; | 149 newSubRun.setVertexStartIndex(prevSubRun.vertexEndIndex()); |
126 newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex; | 150 newSubRun.setVertexEndIndex(prevSubRun.vertexEndIndex()); |
127 return newSubRun; | 151 return newSubRun; |
128 } | 152 } |
129 static const int kMinSubRuns = 1; | 153 static const int kMinSubRuns = 1; |
130 SkAutoTUnref<SkTypeface> fTypeface; | 154 SkAutoTUnref<SkTypeface> fTypeface; |
131 SkRect fVertexBounds; | 155 SkRect fVertexBounds; |
132 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; | 156 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; |
133 SkAutoDescriptor fDescriptor; | 157 SkAutoDescriptor fDescriptor; |
| 158 |
| 159 // Distance field text cannot draw coloremoji, and so has to fall back.
However, |
| 160 // though the distance field text and the coloremoji may share the same
run, they |
| 161 // will have different descriptors. If fOverrideDescriptor is non-nullp
tr, then it |
| 162 // will be used in place of the run's descriptor to regen texture coords |
134 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties | 163 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties |
135 GrColor fColor; | 164 GrColor fColor; |
136 bool fInitialized; | 165 bool fInitialized; |
137 bool fDrawAsPaths; | 166 bool fDrawAsPaths; |
138 }; | 167 }; |
139 | 168 |
140 struct BigGlyph { | 169 struct BigGlyph { |
141 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, b
ool applyVM) | 170 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, b
ool applyVM) |
142 : fPath(path) | 171 : fPath(path) |
143 , fVx(vx) | 172 , fVx(vx) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 262 |
234 void* operator new(size_t, void* p) { return p; } | 263 void* operator new(size_t, void* p) { return p; } |
235 void operator delete(void* target, void* placement) { | 264 void operator delete(void* target, void* placement) { |
236 ::operator delete(target, placement); | 265 ::operator delete(target, placement); |
237 } | 266 } |
238 | 267 |
239 bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceFiel
d_TextType); } | 268 bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceFiel
d_TextType); } |
240 bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } | 269 bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } |
241 void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } | 270 void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } |
242 void setHasBitmap() { fTextType |= kHasBitmap_TextType; } | 271 void setHasBitmap() { fTextType |= kHasBitmap_TextType; } |
| 272 void appendGlyph(Run::SubRunInfo* subrun, GrGlyph* glyph) { |
| 273 this->fGlyphs[subrun->glyphEndIndex()] = glyph; |
| 274 subrun->glyphAppended(); |
| 275 } |
| 276 |
| 277 static const int kVerticesPerGlyph = 4; |
243 | 278 |
244 #ifdef CACHE_SANITY_CHECK | 279 #ifdef CACHE_SANITY_CHECK |
245 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 280 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); |
246 size_t fSize; | 281 size_t fSize; |
247 #endif | 282 #endif |
248 }; | 283 }; |
249 | 284 |
250 #endif | 285 #endif |
OLD | NEW |