OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "GrAtlasTextBlob.h" | 8 #include "GrAtlasTextBlob.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 textureCoords[0] = (uint16_t)u1; | 135 textureCoords[0] = (uint16_t)u1; |
136 textureCoords[1] = (uint16_t)v0; | 136 textureCoords[1] = (uint16_t)v0; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> | 140 template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> |
141 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, | 141 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
142 GrBatchFontCache* fontCache, | 142 GrBatchFontCache* fontCache, |
143 GrBlobRegenHelper *helper, | 143 GrBlobRegenHelper *helper, |
144 Run* run, | 144 Run* run, |
145 Run::SubRunInfo* info, SkGlyphCache** cache, | 145 Run::SubRunInfo* info, |
146 SkTypeface** typeface, | 146 SkAutoGlyphCache* lazyCache, |
147 const SkDescriptor** desc, | |
148 int glyphCount, size_t vertexStride, | 147 int glyphCount, size_t vertexStride, |
149 GrColor color, SkScalar transX, | 148 GrColor color, SkScalar transX, |
150 SkScalar transY) const { | 149 SkScalar transY) const { |
| 150 SkASSERT(lazyCache); |
151 static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along reg
enGlyphs"); | 151 static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along reg
enGlyphs"); |
152 GrBatchTextStrike* strike = nullptr; | 152 GrBatchTextStrike* strike = nullptr; |
153 if (regenTexCoords) { | 153 if (regenTexCoords) { |
154 info->resetBulkUseToken(); | 154 info->resetBulkUseToken(); |
155 | 155 |
156 // We can reuse if we have a valid strike and our descriptors / typeface
are the | 156 const SkDescriptor* desc = (run->fOverrideDescriptor && !info->drawAsDis
tanceFields()) |
157 // same. The override descriptor is only for the non distance field tex
t within | 157 ? run->fOverrideDescriptor->getDesc() |
158 // a run | 158 : run->fDescriptor.getDesc(); |
159 const SkDescriptor* newDesc = (run->fOverrideDescriptor && !info->drawAs
DistanceFields()) ? | 159 |
160 run->fOverrideDescriptor->getDesc() : | 160 if (!*lazyCache || (*lazyCache)->getDescriptor() != *desc) { |
161 run->fDescriptor.getDesc(); | 161 lazyCache->reset(SkGlyphCache::DetachCache(run->fTypeface, run->fEff
ects, desc)); |
162 if (!*cache || !SkTypeface::Equal(*typeface, run->fTypeface) || | |
163 !(**desc == *newDesc)) { | |
164 if (*cache) { | |
165 SkGlyphCache::AttachCache(*cache); | |
166 } | |
167 *desc = newDesc; | |
168 *cache = SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, *d
esc); | |
169 *typeface = run->fTypeface; | |
170 } | 162 } |
171 | 163 |
172 if (regenGlyphs) { | 164 if (regenGlyphs) { |
173 strike = fontCache->getStrike(*cache); | 165 strike = fontCache->getStrike(lazyCache->get()); |
174 } else { | 166 } else { |
175 strike = info->strike(); | 167 strike = info->strike(); |
176 } | 168 } |
177 } | 169 } |
178 | 170 |
179 bool brokenRun = false; | 171 bool brokenRun = false; |
180 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 172 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
181 GrGlyph* glyph = nullptr; | 173 GrGlyph* glyph = nullptr; |
182 int log2Width = 0, log2Height = 0; | 174 int log2Width = 0, log2Height = 0; |
183 if (regenTexCoords) { | 175 if (regenTexCoords) { |
184 size_t glyphOffset = glyphIdx + info->glyphStartIndex(); | 176 size_t glyphOffset = glyphIdx + info->glyphStartIndex(); |
185 | 177 |
186 if (regenGlyphs) { | 178 if (regenGlyphs) { |
187 // Get the id from the old glyph, and use the new strike to look
up | 179 // Get the id from the old glyph, and use the new strike to look
up |
188 // the glyph. | 180 // the glyph. |
189 GrGlyph::PackedID id = fGlyphs[glyphOffset]->fPackedID; | 181 GrGlyph::PackedID id = fGlyphs[glyphOffset]->fPackedID; |
190 fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(),
*cache); | 182 fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(),
lazyCache->get()); |
191 SkASSERT(id == fGlyphs[glyphOffset]->fPackedID); | 183 SkASSERT(id == fGlyphs[glyphOffset]->fPackedID); |
192 } | 184 } |
193 glyph = fGlyphs[glyphOffset]; | 185 glyph = fGlyphs[glyphOffset]; |
194 SkASSERT(glyph && glyph->fMaskFormat == info->maskFormat()); | 186 SkASSERT(glyph && glyph->fMaskFormat == info->maskFormat()); |
195 | 187 |
196 if (!fontCache->hasGlyph(glyph) && | 188 if (!fontCache->hasGlyph(glyph) && |
197 !strike->addGlyphToAtlas(target, glyph, *cache, info->maskFormat
())) { | 189 !strike->addGlyphToAtlas(target, glyph, lazyCache->get(), info->
maskFormat())) { |
198 helper->flush(); | 190 helper->flush(); |
199 brokenRun = glyphIdx > 0; | 191 brokenRun = glyphIdx > 0; |
200 | 192 |
201 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(target, | 193 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(target, |
202 glyph, | 194 glyph, |
203 *cache, | 195 lazyCache->g
et(), |
204 info->maskFo
rmat()); | 196 info->maskFo
rmat()); |
205 SkASSERT(success); | 197 SkASSERT(success); |
206 } | 198 } |
207 fontCache->addGlyphToBulkAndSetUseToken(info->bulkUseToken(), glyph, | 199 fontCache->addGlyphToBulkAndSetUseToken(info->bulkUseToken(), glyph, |
208 target->nextDrawToken()); | 200 target->nextDrawToken()); |
209 log2Width = fontCache->log2Width(info->maskFormat()); | 201 log2Width = fontCache->log2Width(info->maskFormat()); |
210 log2Height = fontCache->log2Height(info->maskFormat()); | 202 log2Height = fontCache->log2Height(info->maskFormat()); |
211 } | 203 } |
212 | 204 |
213 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices); | 205 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices); |
(...skipping 17 matching lines...) Expand all Loading... |
231 } | 223 } |
232 | 224 |
233 enum RegenMask { | 225 enum RegenMask { |
234 kNoRegen = 0x0, | 226 kNoRegen = 0x0, |
235 kRegenPos = 0x1, | 227 kRegenPos = 0x1, |
236 kRegenCol = 0x2, | 228 kRegenCol = 0x2, |
237 kRegenTex = 0x4, | 229 kRegenTex = 0x4, |
238 kRegenGlyph = 0x8 | kRegenTex, // we have to regenerate the texture coords w
hen we regen glyphs | 230 kRegenGlyph = 0x8 | kRegenTex, // we have to regenerate the texture coords w
hen we regen glyphs |
239 | 231 |
240 // combinations | 232 // combinations |
241 kRegenPosCol = kRegenPos | kRegenCol, | 233 kRegenPosCol = kRegenPos | kRegenCol, |
242 kRegenPosTex = kRegenPos | kRegenTex, | 234 kRegenPosTex = kRegenPos | kRegenTex, |
243 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, | 235 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, |
244 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, | 236 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, |
245 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, | 237 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, |
246 kRegenColTex = kRegenCol | kRegenTex, | 238 kRegenColTex = kRegenCol | kRegenTex, |
247 kRegenColTexGlyph = kRegenCol | kRegenGlyph, | 239 kRegenColTexGlyph = kRegenCol | kRegenGlyph, |
248 }; | 240 }; |
249 | 241 |
250 #define REGEN_ARGS target, fontCache, helper, &run, &info, cache, typeface, desc
, \ | 242 #define REGEN_ARGS target, fontCache, helper, &run, &info, lazyCache, \ |
251 *glyphCount, vertexStride, color, transX, transY | 243 *glyphCount, vertexStride, color, transX, transY |
252 | 244 |
253 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, | 245 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
254 GrBatchFontCache* fontCache, | 246 GrBatchFontCache* fontCache, |
255 GrBlobRegenHelper *helper, | 247 GrBlobRegenHelper *helper, |
256 int runIndex, int subRunIndex, SkGlyphCache**
cache, | 248 int runIndex, int subRunIndex, SkAutoGlyphCac
he* lazyCache, |
257 SkTypeface** typeface, const SkDescriptor** d
esc, | |
258 size_t vertexStride, const SkMatrix& viewMatr
ix, | 249 size_t vertexStride, const SkMatrix& viewMatr
ix, |
259 SkScalar x, SkScalar y, GrColor color, | 250 SkScalar x, SkScalar y, GrColor color, |
260 void** vertices, size_t* byteCount, int* glyp
hCount) { | 251 void** vertices, size_t* byteCount, int* glyp
hCount) { |
261 Run& run = fRuns[runIndex]; | 252 Run& run = fRuns[runIndex]; |
262 Run::SubRunInfo& info = run.fSubRunInfo[subRunIndex]; | 253 Run::SubRunInfo& info = run.fSubRunInfo[subRunIndex]; |
263 | 254 |
264 uint64_t currentAtlasGen = fontCache->atlasGeneration(info.maskFormat()); | 255 uint64_t currentAtlasGen = fontCache->atlasGeneration(info.maskFormat()); |
265 | 256 |
266 // Compute translation if any | 257 // Compute translation if any |
267 SkScalar transX, transY; | 258 SkScalar transX, transY; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // set use tokens for all of the glyphs in our subrun. This is only
valid if we | 301 // set use tokens for all of the glyphs in our subrun. This is only
valid if we |
311 // have a valid atlas generation | 302 // have a valid atlas generation |
312 fontCache->setUseTokenBulk(*info.bulkUseToken(), target->nextDrawTok
en(), | 303 fontCache->setUseTokenBulk(*info.bulkUseToken(), target->nextDrawTok
en(), |
313 info.maskFormat()); | 304 info.maskFormat()); |
314 break; | 305 break; |
315 } | 306 } |
316 | 307 |
317 *byteCount = info.byteCount(); | 308 *byteCount = info.byteCount(); |
318 *vertices = fVertices + info.vertexStartIndex(); | 309 *vertices = fVertices + info.vertexStartIndex(); |
319 } | 310 } |
OLD | NEW |