Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 92bc476

Browse files
herbderbySkia Commit-Bot
authored andcommitted
Rearrange templates to get ios to compile
Change-Id: I95f44adc5cc61fdb9b78b60327e0e5ccdeceaf4a Reviewed-on: https://skia-review.googlesource.com/149290 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
1 parent 83988ed commit 92bc476

File tree

4 files changed

+113
-113
lines changed

4 files changed

+113
-113
lines changed

src/core/SkGlyphRun.cpp

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -141,33 +141,6 @@ SkGlyphRunListPainter::SkGlyphRunListPainter(
141141
SkGlyphRunListPainter::SkGlyphRunListPainter(const GrRenderTargetContext& rtc)
142142
: SkGlyphRunListPainter{rtc.surfaceProps(), rtc.colorSpaceInfo()} {}
143143

144-
// forEachMappedDrawableGlyph handles positioning for mask type glyph handling for both sub-pixel
145-
// and full pixel positioning.
146-
template <typename EachGlyph>
147-
void SkGlyphRunListPainter::forEachMappedDrawableGlyph(
148-
const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& deviceMatrix,
149-
SkGlyphCacheInterface* cache, EachGlyph eachGlyph) {
150-
SkMatrix mapping = deviceMatrix;
151-
mapping.preTranslate(origin.x(), origin.y());
152-
SkVector rounding = cache->rounding();
153-
mapping.postTranslate(rounding.x(), rounding.y());
154-
155-
auto runSize = glyphRun.runSize();
156-
if (this->ensureBitmapBuffers(runSize)) {
157-
mapping.mapPoints(fPositions, glyphRun.positions().data(), runSize);
158-
const SkPoint* mappedPtCursor = fPositions;
159-
const SkPoint* ptCursor = glyphRun.positions().data();
160-
for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
161-
auto mappedPt = *mappedPtCursor++;
162-
auto pt = origin + *ptCursor++;
163-
if (SkScalarsAreFinite(mappedPt.x(), mappedPt.y())) {
164-
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, mappedPt);
165-
eachGlyph(glyph, pt, mappedPt);
166-
}
167-
}
168-
}
169-
}
170-
171144
#endif
172145

173146
bool SkGlyphRunListPainter::ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix) {
@@ -779,59 +752,6 @@ size_t SkGlyphRunBuilder::simplifyDrawPosText(
779752

780753
#if SK_SUPPORT_GPU
781754

782-
static bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
783-
return glyph.fWidth >= 256 || glyph.fHeight >= 256;
784-
}
785-
786-
static SkRect rect_to_draw(
787-
const SkGlyph& glyph, SkPoint origin, SkScalar textScale, GrGlyph::MaskStyle maskStyle) {
788-
789-
SkScalar dx = SkIntToScalar(glyph.fLeft);
790-
SkScalar dy = SkIntToScalar(glyph.fTop);
791-
SkScalar width = SkIntToScalar(glyph.fWidth);
792-
SkScalar height = SkIntToScalar(glyph.fHeight);
793-
794-
if (maskStyle == GrGlyph::kDistance_MaskStyle) {
795-
dx += SK_DistanceFieldInset;
796-
dy += SK_DistanceFieldInset;
797-
width -= 2 * SK_DistanceFieldInset;
798-
height -= 2 * SK_DistanceFieldInset;
799-
}
800-
801-
dx *= textScale;
802-
dy *= textScale;
803-
width *= textScale;
804-
height *= textScale;
805-
806-
return SkRect::MakeXYWH(origin.x() + dx, origin.y() + dy, width, height);
807-
}
808-
809-
template <typename PerGlyphT, typename PerPathT>
810-
void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
811-
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
812-
SkPoint origin, const SkMatrix& deviceMatrix,
813-
PerGlyphT perGlyph, PerPathT perPath) {
814-
auto eachGlyph =
815-
[perGlyph{std::move(perGlyph)}, perPath{std::move(perPath)}]
816-
(const SkGlyph& glyph, SkPoint pt, SkPoint mappedPt) {
817-
if (glyph_too_big_for_atlas(glyph)) {
818-
SkScalar sx = SkScalarFloorToScalar(mappedPt.fX),
819-
sy = SkScalarFloorToScalar(mappedPt.fY);
820-
821-
SkRect glyphRect =
822-
rect_to_draw(glyph, {sx, sy}, SK_Scalar1, GrGlyph::kCoverage_MaskStyle);
823-
824-
if (!glyphRect.isEmpty()) {
825-
perPath(glyph, mappedPt);
826-
}
827-
} else {
828-
perGlyph(glyph, mappedPt);
829-
}
830-
};
831-
832-
this->forEachMappedDrawableGlyph(glyphRun, origin, deviceMatrix, cache, eachGlyph);
833-
}
834-
835755
template <typename PerSDFT, typename PerPathT, typename PerFallbackT>
836756
void SkGlyphRunListPainter::drawGlyphRunAsSDFWithFallback(
837757
SkGlyphCache* cache, const SkGlyphRun& glyphRun,
@@ -847,8 +767,7 @@ void SkGlyphRunListPainter::drawGlyphRunAsSDFWithFallback(
847767

848768
if (glyph_too_big_for_atlas(glyph)) {
849769
SkRect glyphRect =
850-
rect_to_draw(glyph, glyphPos, textRatio,
851-
GrGlyph::kDistance_MaskStyle);
770+
rect_to_draw(glyph, glyphPos, textRatio, true);
852771
if (!glyphRect.isEmpty()) {
853772
const SkPath* glyphPath = cache->findPath(glyph);
854773
if (glyphPath != nullptr) {
@@ -866,28 +785,6 @@ void SkGlyphRunListPainter::drawGlyphRunAsSDFWithFallback(
866785
}
867786
}
868787

869-
// -- TrackLayerDevice -----------------------------------------------------------------------------
870-
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForMask(
871-
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) {
872-
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForMask");
873-
const SkPaint& runPaint = glyphRun.paint();
874-
875-
SkScalerContextEffects effects;
876-
auto* glyphCacheState = fStrikeServer->getOrCreateCache(
877-
runPaint, &this->surfaceProps(), &runMatrix,
878-
SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
879-
SkASSERT(glyphCacheState);
880-
881-
auto perGlyph = [glyphCacheState] (const SkGlyph& glyph, SkPoint mappedPt) {
882-
glyphCacheState->addGlyph(glyph.getPackedID(), false);
883-
};
884-
885-
auto perPath = [](const SkGlyph& glyph, SkPoint position) {};
886-
887-
fPainter.drawGlyphRunAsBMPWithPathFallback(
888-
glyphCacheState, glyphRun, origin, runMatrix, perGlyph, perPath);
889-
}
890-
891788
// -- GrTextContext --------------------------------------------------------------------------------
892789
GrColor generate_filtered_color(const SkPaint& paint, const GrColorSpaceInfo& colorSpaceInfo) {
893790
GrColor4f filteredColor = SkColorToUnpremulGrColor4f(paint.getColor(), colorSpaceInfo);
@@ -1014,7 +911,9 @@ void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
1014911
SkASSERT(skGlyph.fWidth == glyph->width());
1015912
SkASSERT(skGlyph.fHeight == glyph->height());
1016913

1017-
SkRect glyphRect = rect_to_draw(skGlyph, {sx, sy}, textRatio, maskStyle);
914+
bool isDFT = maskStyle == GrGlyph::kDistance_MaskStyle;
915+
916+
SkRect glyphRect = rect_to_draw(skGlyph, {sx, sy}, textRatio, isDFT);
1018917

1019918
if (!glyphRect.isEmpty()) {
1020919
blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, !needsTransform);

src/core/SkGlyphRun.h

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <vector>
1414

1515
#include "SkDescriptor.h"
16+
#include "SkDistanceFieldGen.h"
1617
#include "SkMask.h"
1718
#include "SkPath.h"
1819
#include "SkPoint.h"
@@ -21,15 +22,17 @@
2122
#include "SkTemplates.h"
2223
#include "SkTextBlobPriv.h"
2324
#include "SkTypes.h"
24-
#if SK_SUPPORT_GPU
25-
class GrColorSpaceInfo;
26-
class GrRenderTargetContext;
27-
#endif
25+
2826
class SkArenaAlloc;
2927
class SkBaseDevice;
3028
class SkGlyphRunList;
3129
class SkRasterClip;
3230

31+
#if SK_SUPPORT_GPU
32+
class GrColorSpaceInfo;
33+
class GrRenderTargetContext;
34+
#endif
35+
3336
class SkGlyphCacheInterface {
3437
public:
3538
virtual ~SkGlyphCacheInterface() = default;
@@ -340,4 +343,85 @@ inline void SkGlyphRun::forEachGlyphAndPosition(PerGlyphPos perGlyph) const {
340343
}
341344
}
342345

346+
inline static bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
347+
return glyph.fWidth >= 256 || glyph.fHeight >= 256;
348+
}
349+
350+
inline static SkRect rect_to_draw(
351+
const SkGlyph& glyph, SkPoint origin, SkScalar textScale, bool isDFT) {
352+
353+
SkScalar dx = SkIntToScalar(glyph.fLeft);
354+
SkScalar dy = SkIntToScalar(glyph.fTop);
355+
SkScalar width = SkIntToScalar(glyph.fWidth);
356+
SkScalar height = SkIntToScalar(glyph.fHeight);
357+
358+
if (isDFT) {
359+
dx += SK_DistanceFieldInset;
360+
dy += SK_DistanceFieldInset;
361+
width -= 2 * SK_DistanceFieldInset;
362+
height -= 2 * SK_DistanceFieldInset;
363+
}
364+
365+
dx *= textScale;
366+
dy *= textScale;
367+
width *= textScale;
368+
height *= textScale;
369+
370+
return SkRect::MakeXYWH(origin.x() + dx, origin.y() + dy, width, height);
371+
}
372+
373+
// forEachMappedDrawableGlyph handles positioning for mask type glyph handling for both sub-pixel
374+
// and full pixel positioning.
375+
template <typename EachGlyph>
376+
void SkGlyphRunListPainter::forEachMappedDrawableGlyph(
377+
const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& deviceMatrix,
378+
SkGlyphCacheInterface* cache, EachGlyph eachGlyph) {
379+
SkMatrix mapping = deviceMatrix;
380+
mapping.preTranslate(origin.x(), origin.y());
381+
SkVector rounding = cache->rounding();
382+
mapping.postTranslate(rounding.x(), rounding.y());
383+
384+
auto runSize = glyphRun.runSize();
385+
if (this->ensureBitmapBuffers(runSize)) {
386+
mapping.mapPoints(fPositions, glyphRun.positions().data(), runSize);
387+
const SkPoint* mappedPtCursor = fPositions;
388+
const SkPoint* ptCursor = glyphRun.positions().data();
389+
for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
390+
auto mappedPt = *mappedPtCursor++;
391+
auto pt = origin + *ptCursor++;
392+
if (SkScalarsAreFinite(mappedPt.x(), mappedPt.y())) {
393+
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, mappedPt);
394+
eachGlyph(glyph, pt, mappedPt);
395+
}
396+
}
397+
}
398+
}
399+
400+
template <typename PerGlyphT, typename PerPathT>
401+
void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
402+
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
403+
SkPoint origin, const SkMatrix& deviceMatrix,
404+
PerGlyphT perGlyph, PerPathT perPath) {
405+
406+
auto eachGlyph =
407+
[perGlyph{std::move(perGlyph)}, perPath{std::move(perPath)}]
408+
(const SkGlyph& glyph, SkPoint pt, SkPoint mappedPt) {
409+
if (glyph_too_big_for_atlas(glyph)) {
410+
SkScalar sx = SkScalarFloorToScalar(mappedPt.fX),
411+
sy = SkScalarFloorToScalar(mappedPt.fY);
412+
413+
SkRect glyphRect =
414+
rect_to_draw(glyph, {sx, sy}, SK_Scalar1, false);
415+
416+
if (!glyphRect.isEmpty()) {
417+
perPath(glyph, mappedPt);
418+
}
419+
} else {
420+
perGlyph(glyph, mappedPt);
421+
}
422+
};
423+
424+
this->forEachMappedDrawableGlyph(glyphRun, origin, deviceMatrix, cache, eachGlyph);
425+
}
426+
343427
#endif // SkGlyphRunInfo_DEFINED

src/core/SkRemoteGlyphCache.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRun(
268268
}
269269
}
270270

271+
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForMask(
272+
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) {
273+
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForMask");
274+
const SkPaint& runPaint = glyphRun.paint();
275+
276+
SkScalerContextEffects effects;
277+
auto* glyphCacheState = fStrikeServer->getOrCreateCache(
278+
runPaint, &this->surfaceProps(), &runMatrix,
279+
SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
280+
SkASSERT(glyphCacheState);
281+
282+
auto perGlyph = [glyphCacheState] (const SkGlyph& glyph, SkPoint mappedPt) {
283+
glyphCacheState->addGlyph(glyph.getPackedID(), false);
284+
};
285+
286+
auto perPath = [](const SkGlyph& glyph, SkPoint position) {};
287+
288+
fPainter.drawGlyphRunAsBMPWithPathFallback(
289+
glyphCacheState, glyphRun, origin, runMatrix, perGlyph, perPath);
290+
}
291+
271292
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
272293
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix) {
273294
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths");

src/gpu/text/GrTextContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags(
8484
}
8585
}
8686

87-
bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
88-
return GrDrawOpAtlas::GlyphTooLargeForAtlas(glyph.fWidth, glyph.fHeight);
89-
}
90-
9187
void GrTextContext::SanitizeOptions(Options* options) {
9288
if (options->fMaxDistanceFieldFontSize < 0.f) {
9389
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;

0 commit comments

Comments
 (0)