@@ -76,17 +76,6 @@ SkGlyphRunListPainter::SkGlyphRunListPainter(const GrRenderTargetContext& rtc)
7676
7777#endif
7878
79- static bool check_glyph_position (SkPoint position) {
80- // Prevent glyphs from being drawn outside of or straddling the edge of device space.
81- // Comparisons written a little weirdly so that NaN coordinates are treated safely.
82- auto gt = [](float a, int b) { return !(a <= (float )b); };
83- auto lt = [](float a, int b) { return !(a >= (float )b); };
84- return !(gt (position.fX , INT_MAX - (INT16_MAX + SkTo<int >(UINT16_MAX))) ||
85- lt (position.fX , INT_MIN - (INT16_MIN + 0 /* UINT16_MIN*/ )) ||
86- gt (position.fY , INT_MAX - (INT16_MAX + SkTo<int >(UINT16_MAX))) ||
87- lt (position.fY , INT_MIN - (INT16_MIN + 0 /* UINT16_MIN*/ )));
88- }
89-
9079SkSpan<const SkPackedGlyphID> SkGlyphRunListPainter::DeviceSpacePackedGlyphIDs (
9180 const SkGlyphPositionRoundingSpec& roundingSpec,
9281 const SkMatrix& viewMatrix,
@@ -148,7 +137,6 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
148137 SkPoint origin = glyphRunList.origin ();
149138 for (auto & glyphRun : glyphRunList) {
150139 const SkFont& runFont = glyphRun.font ();
151- auto runSize = glyphRun.runSize ();
152140
153141 if (SkStrikeSpec::ShouldDrawAsPath (runPaint, runFont, deviceMatrix)) {
154142
@@ -157,71 +145,24 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
157145
158146 auto strike = strikeSpec.findOrCreateExclusiveStrike ();
159147
160- // Used for the side effect for creating the right positions.
161- SourceSpacePackedGlyphIDs (
162- origin,
163- runSize,
164- glyphRun.glyphsIDs ().data (),
165- glyphRun.positions ().data (),
166- fPositions ,
167- fPackedGlyphIDs );
168-
169- SkBulkGlyphMetricsAndPaths glyphPaths{strikeSpec};
170- auto glyphs = glyphPaths.glyphs (glyphRun.glyphsIDs ());
171-
172- SkTDArray<SkPathPos> pathsAndPositions;
173- pathsAndPositions.setReserve (runSize);
174- for (size_t i = 0 ; i < runSize; i++) {
175- const SkGlyph& glyph = *glyphs[i];
176- SkPoint position = fPositions [i];
177- if (check_glyph_position (position) && !glyph.isEmpty () && glyph.path () != nullptr ) {
178- pathsAndPositions.push_back (SkPathPos{glyph.path (), position});
179- }
180- }
148+ fDrawable .startSource (glyphRun.source (), origin);
149+ strike->prepareForDrawingPathsCPU (&fDrawable );
181150
182151 // The paint we draw paths with must have the same anti-aliasing state as the runFont
183152 // allowing the paths to have the same edging as the glyph masks.
184153 SkPaint pathPaint = runPaint;
185154 pathPaint.setAntiAlias (runFont.hasSomeAntiAliasing ());
186155
187- bitmapDevice->paintPaths (
188- SkSpan<const SkPathPos>{pathsAndPositions.begin (), pathsAndPositions.size ()},
189- strikeSpec.strikeToSourceRatio (), pathPaint);
156+ bitmapDevice->paintPaths (&fDrawable , strikeSpec.strikeToSourceRatio (), pathPaint);
190157 } else {
191158 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeMask (
192159 runFont, runPaint, props, fScalerContextFlags , deviceMatrix);
193160
194161 auto strike = strikeSpec.findOrCreateExclusiveStrike ();
195162
196- auto packedGlyphIDs = DeviceSpacePackedGlyphIDs (
197- strike->roundingSpec (),
198- deviceMatrix,
199- origin,
200- runSize,
201- glyphRun.glyphsIDs ().data (),
202- glyphRun.positions ().data (),
203- fPositions ,
204- fPackedGlyphIDs );
205-
206- SkBulkGlyphMetricsAndImages glyphImages{strikeSpec};
207- SkSpan<const SkGlyph*> glyphs = glyphImages.glyphs (packedGlyphIDs);
208-
209- SkTDArray<SkMask> masks;
210- masks.setReserve (runSize);
211-
212- SkPoint* posCursor = fPositions .get ();
213- for (const SkGlyph* glyph : glyphs) {
214- SkPoint position = *posCursor++;
215- // The glyph could have dimensions (!isEmpty()), but still may have no bits if
216- // the width is too wide. So check that there really is an image.
217- if (check_glyph_position (position)
218- && !glyph->isEmpty ()
219- && glyph->image () != nullptr ) {
220- masks.push_back (glyph->mask (position));
221- }
222- }
223-
224- bitmapDevice->paintMasks (SkSpan<const SkMask>{masks.begin (), masks.size ()}, runPaint);
163+ fDrawable .startDevice (glyphRun.source (), origin, deviceMatrix, strike->roundingSpec ());
164+ strike->prepareForDrawingMasksCPU (&fDrawable );
165+ bitmapDevice->paintMasks (&fDrawable , runPaint);
225166 }
226167 }
227168}
@@ -930,9 +871,9 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrRecordingContext
930871#endif // GR_TEST_UTILS
931872#endif // SK_SUPPORT_GPU
932873
933- SkGlyphRunListPainter::ScopedBuffers::ScopedBuffers (SkGlyphRunListPainter* painter, int size)
874+ SkGlyphRunListPainter::ScopedBuffers::ScopedBuffers (SkGlyphRunListPainter* painter, size_t size)
934875 : fPainter{painter} {
935- SkASSERT (size >= 0 );
876+ fPainter -> fDrawable . ensureSize (size);
936877 if (fPainter ->fMaxRunSize < size) {
937878 fPainter ->fMaxRunSize = size;
938879
@@ -943,6 +884,7 @@ SkGlyphRunListPainter::ScopedBuffers::ScopedBuffers(SkGlyphRunListPainter* paint
943884}
944885
945886SkGlyphRunListPainter::ScopedBuffers::~ScopedBuffers () {
887+ fPainter ->fDrawable .reset ();
946888 fPainter ->fPaths .clear ();
947889 fPainter ->fARGBGlyphsIDs .clear ();
948890 fPainter ->fARGBPositions .clear ();
0 commit comments