|
31 | 31 | #include <cstddef>
|
32 | 32 | #include <new>
|
33 | 33 |
|
| 34 | +namespace { |
| 35 | +struct AtlasPt { |
| 36 | + uint16_t u; |
| 37 | + uint16_t v; |
| 38 | +}; |
| 39 | + |
| 40 | +// Normal text mask, SDFT, or color. |
| 41 | +struct Mask2DVertex { |
| 42 | + SkPoint devicePos; |
| 43 | + GrColor color; |
| 44 | + AtlasPt atlasPos; |
| 45 | +}; |
| 46 | + |
| 47 | +struct ARGB2DVertex { |
| 48 | + ARGB2DVertex(SkPoint d, GrColor, AtlasPt a) : devicePos{d}, atlasPos{a} {} |
| 49 | + |
| 50 | + SkPoint devicePos; |
| 51 | + AtlasPt atlasPos; |
| 52 | +}; |
| 53 | + |
| 54 | +// Perspective SDFT or SDFT forced to 3D or perspective color. |
| 55 | +struct Mask3DVertex { |
| 56 | + SkPoint3 devicePos; |
| 57 | + GrColor color; |
| 58 | + AtlasPt atlasPos; |
| 59 | +}; |
| 60 | + |
| 61 | +struct ARGB3DVertex { |
| 62 | + ARGB3DVertex(SkPoint3 d, GrColor, AtlasPt a) : devicePos{d}, atlasPos{a} {} |
| 63 | + |
| 64 | + SkPoint3 devicePos; |
| 65 | + AtlasPt atlasPos; |
| 66 | +}; |
| 67 | + |
| 68 | +GrAtlasTextOp::MaskType op_mask_type(GrMaskFormat grMaskFormat) { |
| 69 | + switch (grMaskFormat) { |
| 70 | + case kA8_GrMaskFormat: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType; |
| 71 | + case kA565_GrMaskFormat: return GrAtlasTextOp::kLCDCoverageMask_MaskType; |
| 72 | + case kARGB_GrMaskFormat: return GrAtlasTextOp::kColorBitmapMask_MaskType; |
| 73 | + // Needed to placate some compilers. |
| 74 | + default: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType; |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +SkPMColor4f calculate_colors(GrRenderTargetContext* rtc, |
| 79 | + const SkPaint& paint, |
| 80 | + const SkMatrixProvider& matrix, |
| 81 | + GrMaskFormat grMaskFormat, |
| 82 | + GrPaint* grPaint) { |
| 83 | + GrRecordingContext* rContext = rtc->priv().recordingContext(); |
| 84 | + const GrColorInfo& colorInfo = rtc->colorInfo(); |
| 85 | + if (grMaskFormat == kARGB_GrMaskFormat) { |
| 86 | + SkPaintToGrPaintWithPrimitiveColor(rContext, colorInfo, paint, matrix, grPaint); |
| 87 | + return SK_PMColor4fWHITE; |
| 88 | + } else { |
| 89 | + SkPaintToGrPaint(rContext, colorInfo, paint, matrix, grPaint); |
| 90 | + return grPaint->getColor4f(); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +template <typename Rect> |
| 95 | +auto ltbr(const Rect& r) { |
| 96 | + return std::make_tuple(r.left(), r.top(), r.right(), r.bottom()); |
| 97 | +} |
| 98 | + |
| 99 | +// The 99% case. No clip. Non-color only. |
| 100 | +void direct_2D(SkZip<Mask2DVertex[4], const GrGlyph*, const SkIPoint> quadData, |
| 101 | + GrColor color, |
| 102 | + SkIPoint deviceOrigin) { |
| 103 | + for (auto[quad, glyph, leftTop] : quadData) { |
| 104 | + auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
| 105 | + SkScalar dl = leftTop.x() + deviceOrigin.x(), |
| 106 | + dt = leftTop.y() + deviceOrigin.y(), |
| 107 | + dr = dl + (ar - al), |
| 108 | + db = dt + (ab - at); |
| 109 | + |
| 110 | + quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
| 111 | + quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
| 112 | + quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
| 113 | + quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +// Handle any combination of BW or color and clip or no clip. |
| 118 | +template<typename Quad, typename VertexData> |
| 119 | +void generalized_direct_2D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
| 120 | + GrColor color, |
| 121 | + SkIPoint deviceOrigin, |
| 122 | + SkIRect* clip = nullptr) { |
| 123 | + for (auto[quad, glyph, leftTop] : quadData) { |
| 124 | + auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
| 125 | + uint16_t w = ar - al, |
| 126 | + h = ab - at; |
| 127 | + auto[l, t] = leftTop + deviceOrigin; |
| 128 | + if (clip == nullptr) { |
| 129 | + auto[dl, dt, dr, db] = SkRect::MakeLTRB(l, t, l + w, t + h); |
| 130 | + quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
| 131 | + quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
| 132 | + quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
| 133 | + quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
| 134 | + } else { |
| 135 | + SkIRect devIRect = SkIRect::MakeLTRB(l, t, l + w, t + h); |
| 136 | + SkScalar dl, dt, dr, db; |
| 137 | + if (!clip->containsNoEmptyCheck(devIRect)) { |
| 138 | + if (SkIRect clipped; clipped.intersect(devIRect, *clip)) { |
| 139 | + al += clipped.left() - devIRect.left(); |
| 140 | + at += clipped.top() - devIRect.top(); |
| 141 | + ar += clipped.right() - devIRect.right(); |
| 142 | + ab += clipped.bottom() - devIRect.bottom(); |
| 143 | + std::tie(dl, dt, dr, db) = ltbr(clipped); |
| 144 | + } else { |
| 145 | + // TODO: omit generating any vertex data for fully clipped glyphs ? |
| 146 | + std::tie(dl, dt, dr, db) = std::make_tuple(0, 0, 0, 0); |
| 147 | + std::tie(al, at, ar, ab) = std::make_tuple(0, 0, 0, 0); |
| 148 | + } |
| 149 | + } else { |
| 150 | + std::tie(dl, dt, dr, db) = ltbr(devIRect); |
| 151 | + } |
| 152 | + quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
| 153 | + quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
| 154 | + quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
| 155 | + quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
| 156 | + } |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +template<typename Quad, typename VertexData> |
| 161 | +void fill_transformed_vertices_2D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
| 162 | + SkScalar dstPadding, |
| 163 | + SkScalar strikeToSource, |
| 164 | + GrColor color, |
| 165 | + const SkMatrix& matrix) { |
| 166 | + SkPoint inset = {dstPadding, dstPadding}; |
| 167 | + for (auto[quad, glyph, vertexData] : quadData) { |
| 168 | + auto[pos, rect] = vertexData; |
| 169 | + auto[l, t, r, b] = rect; |
| 170 | + SkPoint sLT = (SkPoint::Make(l, t) + inset) * strikeToSource + pos, |
| 171 | + sRB = (SkPoint::Make(r, b) - inset) * strikeToSource + pos; |
| 172 | + SkPoint lt = matrix.mapXY(sLT.x(), sLT.y()), |
| 173 | + lb = matrix.mapXY(sLT.x(), sRB.y()), |
| 174 | + rt = matrix.mapXY(sRB.x(), sLT.y()), |
| 175 | + rb = matrix.mapXY(sRB.x(), sRB.y()); |
| 176 | + auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
| 177 | + quad[0] = {lt, color, {al, at}}; // L,T |
| 178 | + quad[1] = {lb, color, {al, ab}}; // L,B |
| 179 | + quad[2] = {rt, color, {ar, at}}; // R,T |
| 180 | + quad[3] = {rb, color, {ar, ab}}; // R,B |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +template<typename Quad, typename VertexData> |
| 185 | +void fill_transformed_vertices_3D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
| 186 | + SkScalar dstPadding, |
| 187 | + SkScalar strikeToSource, |
| 188 | + GrColor color, |
| 189 | + const SkMatrix& matrix) { |
| 190 | + SkPoint inset = {dstPadding, dstPadding}; |
| 191 | + auto mapXYZ = [&](SkScalar x, SkScalar y) { |
| 192 | + SkPoint pt{x, y}; |
| 193 | + SkPoint3 result; |
| 194 | + matrix.mapHomogeneousPoints(&result, &pt, 1); |
| 195 | + return result; |
| 196 | + }; |
| 197 | + for (auto[quad, glyph, vertexData] : quadData) { |
| 198 | + auto[pos, rect] = vertexData; |
| 199 | + auto [l, t, r, b] = rect; |
| 200 | + SkPoint sLT = (SkPoint::Make(l, t) + inset) * strikeToSource + pos, |
| 201 | + sRB = (SkPoint::Make(r, b) - inset) * strikeToSource + pos; |
| 202 | + SkPoint3 lt = mapXYZ(sLT.x(), sLT.y()), |
| 203 | + lb = mapXYZ(sLT.x(), sRB.y()), |
| 204 | + rt = mapXYZ(sRB.x(), sLT.y()), |
| 205 | + rb = mapXYZ(sRB.x(), sRB.y()); |
| 206 | + auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
| 207 | + quad[0] = {lt, color, {al, at}}; // L,T |
| 208 | + quad[1] = {lb, color, {al, ab}}; // L,B |
| 209 | + quad[2] = {rt, color, {ar, at}}; // R,T |
| 210 | + quad[3] = {rb, color, {ar, ab}}; // R,B |
| 211 | + } |
| 212 | +} |
| 213 | +} // namespace |
| 214 | + |
34 | 215 | // -- GrTextBlob::Key ------------------------------------------------------------------------------
|
35 | 216 | GrTextBlob::Key::Key() { sk_bzero(this, sizeof(Key)); }
|
36 | 217 |
|
@@ -217,17 +398,6 @@ std::tuple<bool, int> GrGlyphVector::regenerateAtlas(int begin, int end,
|
217 | 398 | }
|
218 | 399 | }
|
219 | 400 |
|
220 |
| -// -- GrAtlasSubRun -------------------------------------------------------------------------------- |
221 |
| -static GrAtlasTextOp::MaskType op_mask_type(GrMaskFormat grMaskFormat) { |
222 |
| - switch (grMaskFormat) { |
223 |
| - case kA8_GrMaskFormat: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType; |
224 |
| - case kA565_GrMaskFormat: return GrAtlasTextOp::kLCDCoverageMask_MaskType; |
225 |
| - case kARGB_GrMaskFormat: return GrAtlasTextOp::kColorBitmapMask_MaskType; |
226 |
| - // Needed to placate some compilers. |
227 |
| - default: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType; |
228 |
| - } |
229 |
| -} |
230 |
| - |
231 | 401 | // -- GrDirectMaskSubRun ---------------------------------------------------------------------------
|
232 | 402 | GrDirectMaskSubRun::GrDirectMaskSubRun(GrMaskFormat format,
|
233 | 403 | SkPoint residual,
|
@@ -295,22 +465,6 @@ int GrDirectMaskSubRun::glyphCount() const {
|
295 | 465 | return fGlyphs.glyphs().count();
|
296 | 466 | }
|
297 | 467 |
|
298 |
| -static SkPMColor4f calculate_colors(GrRenderTargetContext* rtc, |
299 |
| - const SkPaint& paint, |
300 |
| - const SkMatrixProvider& matrix, |
301 |
| - GrMaskFormat grMaskFormat, |
302 |
| - GrPaint* grPaint) { |
303 |
| - GrRecordingContext* rContext = rtc->priv().recordingContext(); |
304 |
| - const GrColorInfo& colorInfo = rtc->colorInfo(); |
305 |
| - if (grMaskFormat == kARGB_GrMaskFormat) { |
306 |
| - SkPaintToGrPaintWithPrimitiveColor(rContext, colorInfo, paint, matrix, grPaint); |
307 |
| - return SK_PMColor4fWHITE; |
308 |
| - } else { |
309 |
| - SkPaintToGrPaint(rContext, colorInfo, paint, matrix, grPaint); |
310 |
| - return grPaint->getColor4f(); |
311 |
| - } |
312 |
| -} |
313 |
| - |
314 | 468 | std::tuple<const GrClip*, std::unique_ptr<GrDrawOp>>
|
315 | 469 | GrDirectMaskSubRun::makeAtlasTextOp(const GrClip* clip, const SkMatrixProvider& viewMatrix,
|
316 | 470 | const SkGlyphRunList& glyphRunList,
|
@@ -383,73 +537,6 @@ GrDirectMaskSubRun::regenerateAtlas(int begin, int end, GrMeshDrawOp::Target* ta
|
383 | 537 | return fGlyphs.regenerateAtlas(begin, end, fMaskFormat, 0, target);
|
384 | 538 | }
|
385 | 539 |
|
386 |
| -template <typename Rect> |
387 |
| -static auto ltbr(const Rect& r) { |
388 |
| - return std::make_tuple(r.left(), r.top(), r.right(), r.bottom()); |
389 |
| -} |
390 |
| - |
391 |
| -// The 99% case. No clip. Non-color only. |
392 |
| -template<typename Quad, typename VertexData> |
393 |
| -static void direct_2D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
394 |
| - GrColor color, |
395 |
| - SkIPoint deviceOrigin) { |
396 |
| - for (auto[quad, glyph, leftTop] : quadData) { |
397 |
| - auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
398 |
| - uint16_t w = ar - al, |
399 |
| - h = ab - at; |
400 |
| - auto[l, t] = leftTop + deviceOrigin; |
401 |
| - |
402 |
| - auto[dl, dt, dr, db] = SkRect::MakeLTRB(l, t, l + w, t + h); |
403 |
| - quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
404 |
| - quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
405 |
| - quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
406 |
| - quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
407 |
| - } |
408 |
| -} |
409 |
| - |
410 |
| -// Handle any combination of BW or color and clip or no clip. |
411 |
| -template<typename Quad, typename VertexData> |
412 |
| -void generalized_direct_2D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
413 |
| - GrColor color, |
414 |
| - SkIPoint deviceOrigin, |
415 |
| - SkIRect* clip = nullptr) { |
416 |
| - for (auto[quad, glyph, leftTop] : quadData) { |
417 |
| - auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
418 |
| - uint16_t w = ar - al, |
419 |
| - h = ab - at; |
420 |
| - auto[l, t] = leftTop + deviceOrigin; |
421 |
| - if (clip == nullptr) { |
422 |
| - auto[dl, dt, dr, db] = SkRect::MakeLTRB(l, t, l + w, t + h); |
423 |
| - quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
424 |
| - quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
425 |
| - quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
426 |
| - quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
427 |
| - } else { |
428 |
| - SkIRect devIRect = SkIRect::MakeLTRB(l, t, l + w, t + h); |
429 |
| - SkScalar dl, dt, dr, db; |
430 |
| - if (!clip->containsNoEmptyCheck(devIRect)) { |
431 |
| - if (SkIRect clipped; clipped.intersect(devIRect, *clip)) { |
432 |
| - al += clipped.left() - devIRect.left(); |
433 |
| - at += clipped.top() - devIRect.top(); |
434 |
| - ar += clipped.right() - devIRect.right(); |
435 |
| - ab += clipped.bottom() - devIRect.bottom(); |
436 |
| - std::tie(dl, dt, dr, db) = ltbr(clipped); |
437 |
| - } else { |
438 |
| - // TODO: omit generating any vertex data for fully clipped glyphs ? |
439 |
| - std::tie(dl, dt, dr, db) = std::make_tuple(0, 0, 0, 0); |
440 |
| - std::tie(al, at, ar, ab) = std::make_tuple(0, 0, 0, 0); |
441 |
| - } |
442 |
| - } else { |
443 |
| - std::tie(dl, dt, dr, db) = ltbr(devIRect); |
444 |
| - } |
445 |
| - quad[0] = {{dl, dt}, color, {al, at}}; // L,T |
446 |
| - quad[1] = {{dl, db}, color, {al, ab}}; // L,B |
447 |
| - quad[2] = {{dr, dt}, color, {ar, at}}; // R,T |
448 |
| - quad[3] = {{dr, db}, color, {ar, ab}}; // R,B |
449 |
| - } |
450 |
| - } |
451 |
| -} |
452 |
| - |
453 | 540 | void GrDirectMaskSubRun::fillVertexData(void* vertexDst, int offset, int count, GrColor color,
|
454 | 541 | const SkMatrix& drawMatrix, SkPoint drawOrigin,
|
455 | 542 | SkIRect clip) const {
|
@@ -600,60 +687,6 @@ std::tuple<bool, int> GrTransformedMaskSubRun::regenerateAtlas(int begin, int en
|
600 | 687 | return fGlyphs.regenerateAtlas(begin, end, fMaskFormat, 1, target, true);
|
601 | 688 | }
|
602 | 689 |
|
603 |
| -template<typename Quad, typename VertexData> |
604 |
| -static void fill_transformed_vertices_2D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
605 |
| - SkScalar dstPadding, |
606 |
| - SkScalar strikeToSource, |
607 |
| - GrColor color, |
608 |
| - const SkMatrix& matrix) { |
609 |
| - SkPoint inset = {dstPadding, dstPadding}; |
610 |
| - for (auto[quad, glyph, vertexData] : quadData) { |
611 |
| - auto[pos, rect] = vertexData; |
612 |
| - auto[l, t, r, b] = rect; |
613 |
| - SkPoint sLT = (SkPoint::Make(l, t) + inset) * strikeToSource + pos, |
614 |
| - sRB = (SkPoint::Make(r, b) - inset) * strikeToSource + pos; |
615 |
| - SkPoint lt = matrix.mapXY(sLT.x(), sLT.y()), |
616 |
| - lb = matrix.mapXY(sLT.x(), sRB.y()), |
617 |
| - rt = matrix.mapXY(sRB.x(), sLT.y()), |
618 |
| - rb = matrix.mapXY(sRB.x(), sRB.y()); |
619 |
| - auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
620 |
| - quad[0] = {lt, color, {al, at}}; // L,T |
621 |
| - quad[1] = {lb, color, {al, ab}}; // L,B |
622 |
| - quad[2] = {rt, color, {ar, at}}; // R,T |
623 |
| - quad[3] = {rb, color, {ar, ab}}; // R,B |
624 |
| - } |
625 |
| -} |
626 |
| - |
627 |
| -template<typename Quad, typename VertexData> |
628 |
| -static void fill_transformed_vertices_3D(SkZip<Quad, const GrGlyph*, const VertexData> quadData, |
629 |
| - SkScalar dstPadding, |
630 |
| - SkScalar strikeToSource, |
631 |
| - GrColor color, |
632 |
| - const SkMatrix& matrix) { |
633 |
| - SkPoint inset = {dstPadding, dstPadding}; |
634 |
| - auto mapXYZ = [&](SkScalar x, SkScalar y) { |
635 |
| - SkPoint pt{x, y}; |
636 |
| - SkPoint3 result; |
637 |
| - matrix.mapHomogeneousPoints(&result, &pt, 1); |
638 |
| - return result; |
639 |
| - }; |
640 |
| - for (auto[quad, glyph, vertexData] : quadData) { |
641 |
| - auto[pos, rect] = vertexData; |
642 |
| - auto [l, t, r, b] = rect; |
643 |
| - SkPoint sLT = (SkPoint::Make(l, t) + inset) * strikeToSource + pos, |
644 |
| - sRB = (SkPoint::Make(r, b) - inset) * strikeToSource + pos; |
645 |
| - SkPoint3 lt = mapXYZ(sLT.x(), sLT.y()), |
646 |
| - lb = mapXYZ(sLT.x(), sRB.y()), |
647 |
| - rt = mapXYZ(sRB.x(), sLT.y()), |
648 |
| - rb = mapXYZ(sRB.x(), sRB.y()); |
649 |
| - auto[al, at, ar, ab] = glyph->fAtlasLocator.getUVs(); |
650 |
| - quad[0] = {lt, color, {al, at}}; // L,T |
651 |
| - quad[1] = {lb, color, {al, ab}}; // L,B |
652 |
| - quad[2] = {rt, color, {ar, at}}; // R,T |
653 |
| - quad[3] = {rb, color, {ar, ab}}; // R,B |
654 |
| - } |
655 |
| -} |
656 |
| - |
657 | 690 | void GrTransformedMaskSubRun::fillVertexData(void* vertexDst,
|
658 | 691 | int offset, int count,
|
659 | 692 | GrColor color,
|
|
0 commit comments