| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, SkGlyphCache** cache, |
| 146 SkTypeface** typeface, GrFontScaler** scaler, | 146 SkTypeface** typeface, |
| 147 const SkDescriptor** desc, | 147 const SkDescriptor** desc, |
| 148 int glyphCount, size_t vertexStride, | 148 int glyphCount, size_t vertexStride, |
| 149 GrColor color, SkScalar transX, | 149 GrColor color, SkScalar transX, |
| 150 SkScalar transY) const { | 150 SkScalar transY) const { |
| 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 // We can reuse if we have a valid strike and our descriptors / typeface
are the |
| 157 // same. The override descriptor is only for the non distance field tex
t within | 157 // same. The override descriptor is only for the non distance field tex
t within |
| 158 // a run | 158 // a run |
| 159 const SkDescriptor* newDesc = (run->fOverrideDescriptor && !info->drawAs
DistanceFields()) ? | 159 const SkDescriptor* newDesc = (run->fOverrideDescriptor && !info->drawAs
DistanceFields()) ? |
| 160 run->fOverrideDescriptor->getDesc() : | 160 run->fOverrideDescriptor->getDesc() : |
| 161 run->fDescriptor.getDesc(); | 161 run->fDescriptor.getDesc(); |
| 162 if (!*cache || !SkTypeface::Equal(*typeface, run->fTypeface) || | 162 if (!*cache || !SkTypeface::Equal(*typeface, run->fTypeface) || |
| 163 !(**desc == *newDesc)) { | 163 !(**desc == *newDesc)) { |
| 164 if (*cache) { | 164 if (*cache) { |
| 165 SkGlyphCache::AttachCache(*cache); | 165 SkGlyphCache::AttachCache(*cache); |
| 166 } | 166 } |
| 167 *desc = newDesc; | 167 *desc = newDesc; |
| 168 *cache = SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, *d
esc); | 168 *cache = SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, *d
esc); |
| 169 *scaler = GrTextUtils::GetGrFontScaler(*cache); | |
| 170 *typeface = run->fTypeface; | 169 *typeface = run->fTypeface; |
| 171 } | 170 } |
| 172 | 171 |
| 173 if (regenGlyphs) { | 172 if (regenGlyphs) { |
| 174 strike = fontCache->getStrike(*scaler); | 173 strike = fontCache->getStrike(*cache); |
| 175 } else { | 174 } else { |
| 176 strike = info->strike(); | 175 strike = info->strike(); |
| 177 } | 176 } |
| 178 } | 177 } |
| 179 | 178 |
| 180 bool brokenRun = false; | 179 bool brokenRun = false; |
| 181 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 180 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
| 182 GrGlyph* glyph = nullptr; | 181 GrGlyph* glyph = nullptr; |
| 183 int log2Width = 0, log2Height = 0; | 182 int log2Width = 0, log2Height = 0; |
| 184 if (regenTexCoords) { | 183 if (regenTexCoords) { |
| 185 size_t glyphOffset = glyphIdx + info->glyphStartIndex(); | 184 size_t glyphOffset = glyphIdx + info->glyphStartIndex(); |
| 186 | 185 |
| 187 if (regenGlyphs) { | 186 if (regenGlyphs) { |
| 188 // Get the id from the old glyph, and use the new strike to look
up | 187 // Get the id from the old glyph, and use the new strike to look
up |
| 189 // the glyph. | 188 // the glyph. |
| 190 GrGlyph::PackedID id = fGlyphs[glyphOffset]->fPackedID; | 189 GrGlyph::PackedID id = fGlyphs[glyphOffset]->fPackedID; |
| 191 fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(),
*scaler); | 190 fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(),
*cache); |
| 192 SkASSERT(id == fGlyphs[glyphOffset]->fPackedID); | 191 SkASSERT(id == fGlyphs[glyphOffset]->fPackedID); |
| 193 } | 192 } |
| 194 glyph = fGlyphs[glyphOffset]; | 193 glyph = fGlyphs[glyphOffset]; |
| 195 SkASSERT(glyph && glyph->fMaskFormat == info->maskFormat()); | 194 SkASSERT(glyph && glyph->fMaskFormat == info->maskFormat()); |
| 196 | 195 |
| 197 if (!fontCache->hasGlyph(glyph) && | 196 if (!fontCache->hasGlyph(glyph) && |
| 198 !strike->addGlyphToAtlas(target, glyph, *scaler, info->maskForma
t())) { | 197 !strike->addGlyphToAtlas(target, glyph, *cache, info->maskFormat
())) { |
| 199 helper->flush(); | 198 helper->flush(); |
| 200 brokenRun = glyphIdx > 0; | 199 brokenRun = glyphIdx > 0; |
| 201 | 200 |
| 202 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(target, | 201 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(target, |
| 203 glyph, | 202 glyph, |
| 204 *scaler, | 203 *cache, |
| 205 info->maskFo
rmat()); | 204 info->maskFo
rmat()); |
| 206 SkASSERT(success); | 205 SkASSERT(success); |
| 207 } | 206 } |
| 208 fontCache->addGlyphToBulkAndSetUseToken(info->bulkUseToken(), glyph, | 207 fontCache->addGlyphToBulkAndSetUseToken(info->bulkUseToken(), glyph, |
| 209 target->nextDrawToken()); | 208 target->nextDrawToken()); |
| 210 log2Width = fontCache->log2Width(info->maskFormat()); | 209 log2Width = fontCache->log2Width(info->maskFormat()); |
| 211 log2Height = fontCache->log2Height(info->maskFormat()); | 210 log2Height = fontCache->log2Height(info->maskFormat()); |
| 212 } | 211 } |
| 213 | 212 |
| 214 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices); | 213 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 241 // combinations | 240 // combinations |
| 242 kRegenPosCol = kRegenPos | kRegenCol, | 241 kRegenPosCol = kRegenPos | kRegenCol, |
| 243 kRegenPosTex = kRegenPos | kRegenTex, | 242 kRegenPosTex = kRegenPos | kRegenTex, |
| 244 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, | 243 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, |
| 245 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, | 244 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, |
| 246 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, | 245 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, |
| 247 kRegenColTex = kRegenCol | kRegenTex, | 246 kRegenColTex = kRegenCol | kRegenTex, |
| 248 kRegenColTexGlyph = kRegenCol | kRegenGlyph, | 247 kRegenColTexGlyph = kRegenCol | kRegenGlyph, |
| 249 }; | 248 }; |
| 250 | 249 |
| 251 #define REGEN_ARGS target, fontCache, helper, &run, &info, cache, typeface, scal
er, desc, \ | 250 #define REGEN_ARGS target, fontCache, helper, &run, &info, cache, typeface, desc
, \ |
| 252 *glyphCount, vertexStride, color, transX, transY | 251 *glyphCount, vertexStride, color, transX, transY |
| 253 | 252 |
| 254 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, | 253 void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
| 255 GrBatchFontCache* fontCache, | 254 GrBatchFontCache* fontCache, |
| 256 GrBlobRegenHelper *helper, | 255 GrBlobRegenHelper *helper, |
| 257 int runIndex, int subRunIndex, SkGlyphCache**
cache, | 256 int runIndex, int subRunIndex, SkGlyphCache**
cache, |
| 258 SkTypeface** typeface, GrFontScaler** scaler, | 257 SkTypeface** typeface, const SkDescriptor** d
esc, |
| 259 const SkDescriptor** desc, size_t vertexStrid
e, | 258 size_t vertexStride, const SkMatrix& viewMatr
ix, |
| 260 const SkMatrix& viewMatrix, SkScalar x, SkSca
lar y, | 259 SkScalar x, SkScalar y, GrColor color, |
| 261 GrColor color, | |
| 262 void** vertices, size_t* byteCount, int* glyp
hCount) { | 260 void** vertices, size_t* byteCount, int* glyp
hCount) { |
| 263 Run& run = fRuns[runIndex]; | 261 Run& run = fRuns[runIndex]; |
| 264 Run::SubRunInfo& info = run.fSubRunInfo[subRunIndex]; | 262 Run::SubRunInfo& info = run.fSubRunInfo[subRunIndex]; |
| 265 | 263 |
| 266 uint64_t currentAtlasGen = fontCache->atlasGeneration(info.maskFormat()); | 264 uint64_t currentAtlasGen = fontCache->atlasGeneration(info.maskFormat()); |
| 267 | 265 |
| 268 // Compute translation if any | 266 // Compute translation if any |
| 269 SkScalar transX, transY; | 267 SkScalar transX, transY; |
| 270 info.computeTranslation(viewMatrix, x, y, &transX, &transY); | 268 info.computeTranslation(viewMatrix, x, y, &transX, &transY); |
| 271 | 269 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // set use tokens for all of the glyphs in our subrun. This is only
valid if we | 310 // set use tokens for all of the glyphs in our subrun. This is only
valid if we |
| 313 // have a valid atlas generation | 311 // have a valid atlas generation |
| 314 fontCache->setUseTokenBulk(*info.bulkUseToken(), target->nextDrawTok
en(), | 312 fontCache->setUseTokenBulk(*info.bulkUseToken(), target->nextDrawTok
en(), |
| 315 info.maskFormat()); | 313 info.maskFormat()); |
| 316 break; | 314 break; |
| 317 } | 315 } |
| 318 | 316 |
| 319 *byteCount = info.byteCount(); | 317 *byteCount = info.byteCount(); |
| 320 *vertices = fVertices + info.vertexStartIndex(); | 318 *vertices = fVertices + info.vertexStartIndex(); |
| 321 } | 319 } |
| OLD | NEW |