@@ -70,7 +70,7 @@ class GrTextBlob::SubRun {
7070 GrTextBlob* textBlob,
7171 const SkStrikeSpec& strikeSpec,
7272 GrMaskFormat format,
73- const SubRunBufferSpec& bufferSpec ,
73+ const SkSpan<GrGlyph*>& glyphs, const SkSpan< char >& vertexData ,
7474 sk_sp<GrTextStrike>&& grStrike);
7575
7676 // SubRun for paths
@@ -88,10 +88,6 @@ class GrTextBlob::SubRun {
8888 void setAtlasGeneration (uint64_t atlasGeneration);
8989 uint64_t atlasGeneration () const ;
9090
91- size_t vertexStartIndex () const ;
92- uint32_t glyphCount () const ;
93- uint32_t glyphStartIndex () const ;
94-
9591 void setColor (GrColor color);
9692 GrColor color () const ;
9793
@@ -123,10 +119,8 @@ class GrTextBlob::SubRun {
123119 const SubRunType fType ;
124120 GrTextBlob* const fBlob ;
125121 const GrMaskFormat fMaskFormat ;
126- const uint32_t fGlyphStartIndex ;
127- const uint32_t fGlyphEndIndex ;
128- const size_t fVertexStartIndex ;
129- const size_t fVertexEndIndex ;
122+ const SkSpan<GrGlyph*> fGlyphs ;
123+ const SkSpan<char > fVertexData ;
130124 const SkStrikeSpec fStrikeSpec ;
131125 sk_sp<GrTextStrike> fStrike ;
132126 struct {
@@ -144,15 +138,14 @@ class GrTextBlob::SubRun {
144138}; // SubRun
145139
146140GrTextBlob::SubRun::SubRun (SubRunType type, GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec,
147- GrMaskFormat format, const GrTextBlob::SubRunBufferSpec& bufferSpec,
141+ GrMaskFormat format,
142+ const SkSpan<GrGlyph*>& glyphs, const SkSpan<char >& vertexData,
148143 sk_sp<GrTextStrike>&& grStrike)
149144 : fType{type}
150145 , fBlob {textBlob}
151146 , fMaskFormat {format}
152- , fGlyphStartIndex {std::get<0 >(bufferSpec)}
153- , fGlyphEndIndex {std::get<1 >(bufferSpec)}
154- , fVertexStartIndex {std::get<2 >(bufferSpec)}
155- , fVertexEndIndex {std::get<3 >(bufferSpec)}
147+ , fGlyphs {glyphs}
148+ , fVertexData {vertexData}
156149 , fStrikeSpec {strikeSpec}
157150 , fStrike {grStrike}
158151 , fColor {textBlob->fColor }
@@ -167,10 +160,8 @@ GrTextBlob::SubRun::SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec)
167160 : fType{kTransformedPath }
168161 , fBlob {textBlob}
169162 , fMaskFormat {kA8_GrMaskFormat }
170- , fGlyphStartIndex {0 }
171- , fGlyphEndIndex {0 }
172- , fVertexStartIndex {0 }
173- , fVertexEndIndex {0 }
163+ , fGlyphs {SkSpan<GrGlyph*>{}}
164+ , fVertexData {SkSpan<char >{}}
174165 , fStrikeSpec {strikeSpec}
175166 , fStrike {nullptr }
176167 , fColor {textBlob->fColor }
@@ -181,8 +172,8 @@ GrTextBlob::SubRun::SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec)
181172void GrTextBlob::SubRun::appendGlyphs (const SkZip<SkGlyphVariant, SkPoint>& drawables) {
182173 GrTextStrike* grStrike = fStrike .get ();
183174 SkScalar strikeToSource = fStrikeSpec .strikeToSourceRatio ();
184- uint32_t glyphCursor = fGlyphStartIndex ;
185- size_t vertexCursor = fVertexStartIndex ;
175+ GrGlyph** glyphCursor = fGlyphs . data () ;
176+ char * vertexCursor = fVertexData . data () ;
186177 bool hasW = this ->hasW ();
187178 GrColor color = this ->color ();
188179 // glyphs drawn in perspective must always have a w coord.
@@ -206,32 +197,28 @@ void GrTextBlob::SubRun::appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& draw
206197
207198 this ->joinGlyphBounds (dstRect);
208199
209- intptr_t vertex = reinterpret_cast <intptr_t >(fBlob ->fVertices + vertexCursor);
210-
211200 // V0
212- *reinterpret_cast <SkPoint3*>(vertex ) = {dstRect.fLeft , dstRect.fTop , 1 .f };
213- *reinterpret_cast <GrColor*>(vertex + colorOffset) = color;
214- vertex += vertexStride;
201+ *reinterpret_cast <SkPoint3*>(vertexCursor ) = {dstRect.fLeft , dstRect.fTop , 1 .f };
202+ *reinterpret_cast <GrColor*>(vertexCursor + colorOffset) = color;
203+ vertexCursor += vertexStride;
215204
216205 // V1
217- *reinterpret_cast <SkPoint3*>(vertex ) = {dstRect.fLeft , dstRect.fBottom , 1 .f };
218- *reinterpret_cast <GrColor*>(vertex + colorOffset) = color;
219- vertex += vertexStride;
206+ *reinterpret_cast <SkPoint3*>(vertexCursor ) = {dstRect.fLeft , dstRect.fBottom , 1 .f };
207+ *reinterpret_cast <GrColor*>(vertexCursor + colorOffset) = color;
208+ vertexCursor += vertexStride;
220209
221210 // V2
222- *reinterpret_cast <SkPoint3*>(vertex ) = {dstRect.fRight , dstRect.fTop , 1 .f };
223- *reinterpret_cast <GrColor*>(vertex + colorOffset) = color;
224- vertex += vertexStride;
211+ *reinterpret_cast <SkPoint3*>(vertexCursor ) = {dstRect.fRight , dstRect.fTop , 1 .f };
212+ *reinterpret_cast <GrColor*>(vertexCursor + colorOffset) = color;
213+ vertexCursor += vertexStride;
225214
226215 // V3
227- *reinterpret_cast <SkPoint3*>(vertex) = {dstRect.fRight , dstRect.fBottom , 1 .f };
228- *reinterpret_cast <GrColor*>(vertex + colorOffset) = color;
216+ *reinterpret_cast <SkPoint3*>(vertexCursor) = {dstRect.fRight , dstRect.fBottom , 1 .f };
217+ *reinterpret_cast <GrColor*>(vertexCursor + colorOffset) = color;
218+ vertexCursor += vertexStride;
229219
230- vertexCursor += vertexStride * kVerticesPerGlyph ;
231- fBlob ->fGlyphs [glyphCursor++] = grGlyph;
220+ *glyphCursor++ = grGlyph;
232221 }
233- SkASSERT (glyphCursor == fGlyphEndIndex );
234- SkASSERT (vertexCursor == fVertexEndIndex );
235222}
236223
237224void GrTextBlob::SubRun::resetBulkUseToken () { fBulkUseToken .reset (); }
@@ -242,9 +229,6 @@ GrTextStrike* GrTextBlob::SubRun::strike() const { return fStrike.get(); }
242229sk_sp<GrTextStrike> GrTextBlob::SubRun::refStrike () const { return fStrike ; }
243230void GrTextBlob::SubRun::setAtlasGeneration (uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;}
244231uint64_t GrTextBlob::SubRun::atlasGeneration () const { return fAtlasGeneration ; }
245- size_t GrTextBlob::SubRun::vertexStartIndex () const { return fVertexStartIndex ; }
246- uint32_t GrTextBlob::SubRun::glyphCount () const { return fGlyphEndIndex - fGlyphStartIndex ; }
247- uint32_t GrTextBlob::SubRun::glyphStartIndex () const { return fGlyphStartIndex ; }
248232void GrTextBlob::SubRun::setColor (GrColor color) { fColor = color; }
249233GrColor GrTextBlob::SubRun::color () const { return fColor ; }
250234GrMaskFormat GrTextBlob::SubRun::maskFormat () const { return fMaskFormat ; }
@@ -314,26 +298,27 @@ sk_sp<GrTextBlob> GrTextBlob::Make(const SkGlyphRunList& glyphRunList,
314298
315299 // We can use the alignment of SDFT3DVertex as a proxy for all Vertex alignments.
316300 static_assert (alignof (SDFT3DVertex) >= alignof (Mask2DVertex));
317-
318- size_t subRunsOffset = sizeof (GrTextBlob);
319- size_t subRunsSize = glyphRunList.runCount () * sizeof (SubRun);
320- static_assert (alignof (SubRun) >= alignof (GrGlyph*));
321- size_t glyphsOffset = subRunsOffset + subRunsSize;
301+ // Assume there is no padding needed between glyph pointers and vertices.
322302 static_assert (alignof (GrGlyph*) >= alignof (SDFT3DVertex));
323- size_t vertexOffset = glyphsOffset + sizeof (GrGlyph*) * glyphRunList.totalGlyphCount ();
324- size_t allocationSize = vertexOffset + quadSize * glyphRunList.totalGlyphCount ();
303+
304+ // In the arena, the layout is GrGlyph*... | SDFT3DVertex... | SubRun, so there is no padding
305+ // between GrGlyph* and SDFT3DVertex, but padding is needed between the Mask2DVertex array
306+ // and the SubRun.
307+ size_t vertexToSubRunPadding = alignof (SDFT3DVertex) - alignof (SubRun);
308+ size_t arenaSize =
309+ sizeof (GrGlyph*) * glyphRunList.totalGlyphCount ()
310+ + quadSize * glyphRunList.totalGlyphCount ()
311+ + glyphRunList.runCount () * (sizeof (SubRun) + vertexToSubRunPadding);
312+
313+ size_t allocationSize = sizeof (GrTextBlob) + arenaSize;
325314
326315 void * allocation = ::operator new (allocationSize);
327316
328317 SkColor initialLuminance = SkPaintPriv::ComputeLuminanceColor (glyphRunList.paint ());
329318 sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{
330- subRunsSize , strikeCache, viewMatrix, glyphRunList.origin (),
319+ arenaSize , strikeCache, viewMatrix, glyphRunList.origin (),
331320 color, initialLuminance, forceWForDistanceFields}};
332321
333- // setup offsets for vertices / glyphs
334- blob->fVertices = SkTAddOffset<char >(blob.get (), vertexOffset);
335- blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get (), glyphsOffset);
336-
337322 return blob;
338323}
339324
@@ -516,7 +501,7 @@ void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props,
516501 target->drawShape (clip, runPaint, ctm, shape);
517502 }
518503 } else {
519- int glyphCount = subRun->glyphCount ();
504+ int glyphCount = subRun->fGlyphs . size ();
520505 if (0 == glyphCount) {
521506 continue ;
522507 }
@@ -625,21 +610,15 @@ GrTextBlob::SubRun* GrTextBlob::makeSubRun(SubRunType type,
625610 const SkZip<SkGlyphVariant, SkPoint>& drawables,
626611 const SkStrikeSpec& strikeSpec,
627612 GrMaskFormat format) {
613+ SkSpan<GrGlyph*> glyphs{fAlloc .makeArrayDefault <GrGlyph*>(drawables.size ()), drawables.size ()};
628614 bool hasW = this ->hasW (type);
629- uint32_t glyphsStart = fGlyphsCursor ;
630- fGlyphsCursor += drawables.size ();
631- uint32_t glyphsEnd = fGlyphsCursor ;
632- size_t verticesStart = fVerticesCursor ;
633- fVerticesCursor += drawables.size () * GetVertexStride (format, hasW) * kVerticesPerGlyph ;
634- size_t verticesEnd = fVerticesCursor ;
635-
636- SubRunBufferSpec bufferSpec = std::make_tuple (
637- glyphsStart, glyphsEnd, verticesStart, verticesEnd);
615+ size_t vertexDataSize = drawables.size () * GetVertexStride (format, hasW) * kVerticesPerGlyph ;
616+ SkSpan<char > vertexData{fAlloc .makeArrayDefault <char >(vertexDataSize), vertexDataSize};
638617
639618 sk_sp<GrTextStrike> grStrike = strikeSpec.findOrCreateGrStrike (fStrikeCache );
640619
641620 SubRun* subRun = fAlloc .make <SubRun>(
642- type, this , strikeSpec, format, bufferSpec , std::move (grStrike));
621+ type, this , strikeSpec, format, glyphs, vertexData , std::move (grStrike));
643622
644623 subRun->appendGlyphs (drawables);
645624
@@ -884,7 +863,6 @@ static void regen_texcoords(char* vertex, size_t vertexStride, const GrGlyph* gl
884863}
885864
886865GrTextBlob::VertexRegenerator::VertexRegenerator (GrResourceProvider* resourceProvider,
887- GrTextBlob* blob,
888866 GrTextBlob::SubRun* subRun,
889867 const SkMatrix& viewMatrix, SkScalar x, SkScalar y,
890868 GrColor color,
@@ -893,7 +871,6 @@ GrTextBlob::VertexRegenerator::VertexRegenerator(GrResourceProvider* resourcePro
893871 GrAtlasManager* fullAtlasManager)
894872 : fResourceProvider(resourceProvider)
895873 , fViewMatrix(viewMatrix)
896- , fBlob(blob)
897874 , fUploadTarget(uploadTarget)
898875 , fGrStrikeCache(grStrikeCache)
899876 , fFullAtlasManager(fullAtlasManager)
@@ -942,9 +919,7 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
942919
943920 // Start this batch at the start of the subRun plus any glyphs that were previously
944921 // processed.
945- size_t glyphStart = fSubRun ->glyphStartIndex () + fCurrGlyph ;
946- SkSpan<GrGlyph*> glyphs{&(fBlob ->fGlyphs [glyphStart]),
947- fSubRun ->glyphCount () - fCurrGlyph };
922+ SkSpan<GrGlyph*> glyphs = fSubRun ->fGlyphs .last (fSubRun ->fGlyphs .size () - fCurrGlyph );
948923
949924 // Convert old glyphs to newStrike.
950925 for (auto & glyph : glyphs) {
@@ -960,15 +935,13 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
960935 sk_sp<GrTextStrike> grStrike = fSubRun ->refStrike ();
961936 bool hasW = fSubRun ->hasW ();
962937 auto vertexStride = GetVertexStride (fSubRun ->maskFormat (), hasW);
963- char * currVertex = fBlob ->fVertices + fSubRun ->vertexStartIndex () +
964- fCurrGlyph * kVerticesPerGlyph * vertexStride;
938+ char * currVertex = fSubRun ->fVertexData .data () + fCurrGlyph * kVerticesPerGlyph * vertexStride;
965939 result->fFirstVertex = currVertex;
966940
967- for (int glyphIdx = fCurrGlyph ; glyphIdx < (int )fSubRun ->glyphCount (); glyphIdx++) {
941+ for (int glyphIdx = fCurrGlyph ; glyphIdx < (int )fSubRun ->fGlyphs . size (); glyphIdx++) {
968942 GrGlyph* glyph = nullptr ;
969943 if (regenTexCoords) {
970- size_t glyphOffset = glyphIdx + fSubRun ->glyphStartIndex ();
971- glyph = fBlob ->fGlyphs [glyphOffset];
944+ glyph = fSubRun ->fGlyphs [glyphIdx];
972945 SkASSERT (glyph && glyph->fMaskFormat == fSubRun ->maskFormat ());
973946
974947 if (!fFullAtlasManager ->hasGlyph (glyph)) {
@@ -1040,10 +1013,10 @@ bool GrTextBlob::VertexRegenerator::regenerate(GrTextBlob::VertexRegenerator::Re
10401013 bool hasW = fSubRun ->hasW ();
10411014 auto vertexStride = GetVertexStride (fSubRun ->maskFormat (), hasW);
10421015 result->fFinished = true ;
1043- result->fGlyphsRegenerated = fSubRun ->glyphCount () - fCurrGlyph ;
1044- result->fFirstVertex = fBlob -> fVertices + fSubRun ->vertexStartIndex () +
1045- fCurrGlyph * kVerticesPerGlyph * vertexStride;
1046- fCurrGlyph = fSubRun ->glyphCount ();
1016+ result->fGlyphsRegenerated = fSubRun ->fGlyphs . size () - fCurrGlyph ;
1017+ result->fFirstVertex = fSubRun ->fVertexData . data () +
1018+ fCurrGlyph * kVerticesPerGlyph * vertexStride;
1019+ fCurrGlyph = fSubRun ->fGlyphs . size ();
10471020
10481021 // set use tokens for all of the glyphs in our subrun. This is only valid if we
10491022 // have a valid atlas generation
0 commit comments