Skip to content

Commit 45fe2e8

Browse files
herbderbySkia Commit-Bot
authored andcommitted
move methods to options class
Change-Id: I5e4abcec1b9f99997cd68b433490e13eaa76f3f9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296123 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
1 parent 2d41186 commit 45fe2e8

File tree

5 files changed

+29
-40
lines changed

5 files changed

+29
-40
lines changed

src/core/SkGlyphRunPainter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
153153
const SkFont& runFont = glyphRun.font();
154154

155155

156-
bool useSDFT = GrTextContext::CanDrawAsDistanceFields(
157-
runPaint, runFont, drawMatrix, props, contextSupportsDistanceFieldText, options);
156+
bool useSDFT = options.canDrawAsDistanceFields(
157+
runPaint, runFont, drawMatrix, props, contextSupportsDistanceFieldText);
158158

159159
bool usePaths =
160160
useSDFT ? false : SkStrikeSpec::ShouldDrawAsPath(runPaint, runFont, drawMatrix);

src/core/SkStrikeSpec.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,14 @@ SkStrikeSpec::MakeSDFT(const SkFont& font, const SkPaint& paint,
190190
SkStrikeSpec storage;
191191

192192
SkPaint dfPaint = GrTextContext::InitDistanceFieldPaint(paint);
193-
SkFont dfFont = GrTextContext::InitDistanceFieldFont(
194-
font, deviceMatrix, options, &storage.fStrikeToSourceRatio);
193+
SkFont dfFont = options.getSDFFont(font, deviceMatrix, &storage.fStrikeToSourceRatio);
195194

196195
// Fake-gamma and subpixel antialiasing are applied in the shader, so we ignore the
197196
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
198197
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
199198

200199
SkScalar minScale, maxScale;
201-
std::tie(minScale, maxScale) = GrTextContext::InitDistanceFieldMinMaxScale(
202-
font.getSize(), deviceMatrix, options);
200+
std::tie(minScale, maxScale) = options.computeSDFMinMaxScale(font.getSize(), deviceMatrix);
203201

204202
storage.commonSetup(dfFont, dfPaint, surfaceProps, flags, SkMatrix::I());
205203

src/gpu/text/GrTextContext.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ std::unique_ptr<GrTextContext> GrTextContext::Make(const Options& options) {
4242
return std::unique_ptr<GrTextContext>(new GrTextContext(options));
4343
}
4444

45-
bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
46-
const SkMatrix& viewMatrix,
47-
const SkSurfaceProps& props,
48-
bool contextSupportsDistanceFieldText,
49-
const Options& options) {
45+
bool GrTextContext::Options::canDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
46+
const SkMatrix& viewMatrix,
47+
const SkSurfaceProps& props,
48+
bool contextSupportsDistanceFieldText) const {
5049
// mask filters modify alpha, which doesn't translate well to distance
5150
if (paint.getMaskFilter() || !contextSupportsDistanceFieldText) {
5251
return false;
@@ -65,8 +64,8 @@ bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont&
6564
SkScalar scaledTextSize = maxScale * font.getSize();
6665
// Hinted text looks far better at small resolutions
6766
// Scaling up beyond 2x yields undesirable artifacts
68-
if (scaledTextSize < options.fMinDistanceFieldFontSize ||
69-
scaledTextSize > options.fMaxDistanceFieldFontSize) {
67+
if (scaledTextSize < fMinDistanceFieldFontSize ||
68+
scaledTextSize > fMaxDistanceFieldFontSize) {
7069
return false;
7170
}
7271

@@ -103,10 +102,9 @@ SkScalar scaled_text_size(const SkScalar textSize, const SkMatrix& viewMatrix) {
103102
return scaledTextSize;
104103
}
105104

106-
SkFont GrTextContext::InitDistanceFieldFont(const SkFont& font,
107-
const SkMatrix& viewMatrix,
108-
const Options& options,
109-
SkScalar* textRatio) {
105+
SkFont GrTextContext::Options::getSDFFont(const SkFont& font,
106+
const SkMatrix& viewMatrix,
107+
SkScalar* textRatio) const {
110108
SkScalar textSize = font.getSize();
111109
SkScalar scaledTextSize = scaled_text_size(textSize, viewMatrix);
112110

@@ -142,10 +140,8 @@ SkFont GrTextContext::InitDistanceFieldFont(const SkFont& font,
142140
return dfFont;
143141
}
144142

145-
std::pair<SkScalar, SkScalar> GrTextContext::InitDistanceFieldMinMaxScale(
146-
SkScalar textSize,
147-
const SkMatrix& viewMatrix,
148-
const GrTextContext::Options& options) {
143+
std::pair<SkScalar, SkScalar> GrTextContext::Options::computeSDFMinMaxScale(
144+
SkScalar textSize, const SkMatrix& viewMatrix) const {
149145

150146
SkScalar scaledTextSize = scaled_text_size(textSize, viewMatrix);
151147

@@ -154,14 +150,14 @@ std::pair<SkScalar, SkScalar> GrTextContext::InitDistanceFieldMinMaxScale(
154150
SkScalar dfMaskScaleFloor;
155151
SkScalar dfMaskScaleCeil;
156152
if (scaledTextSize <= kSmallDFFontLimit) {
157-
dfMaskScaleFloor = options.fMinDistanceFieldFontSize;
153+
dfMaskScaleFloor = fMinDistanceFieldFontSize;
158154
dfMaskScaleCeil = kSmallDFFontLimit;
159155
} else if (scaledTextSize <= kMediumDFFontLimit) {
160156
dfMaskScaleFloor = kSmallDFFontLimit;
161157
dfMaskScaleCeil = kMediumDFFontLimit;
162158
} else {
163159
dfMaskScaleFloor = kMediumDFFontLimit;
164-
dfMaskScaleCeil = options.fMaxDistanceFieldFontSize;
160+
dfMaskScaleCeil = fMaxDistanceFieldFontSize;
165161
}
166162

167163
// Because there can be multiple runs in the blob, we want the overall maxMinScale, and

src/gpu/text/GrTextContext.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class GrTextContext {
3535
, fMaxDistanceFieldFontSize{max} {
3636
SkASSERT_RELEASE(min > 0 && max >= min);
3737
}
38+
39+
bool canDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix,
40+
const SkSurfaceProps& props,
41+
bool contextSupportsDistanceFieldText) const;
42+
SkFont getSDFFont(const SkFont& font,
43+
const SkMatrix& viewMatrix,
44+
SkScalar* textRatio) const;
45+
std::pair<SkScalar, SkScalar> computeSDFMinMaxScale(
46+
SkScalar textSize, const SkMatrix& viewMatrix) const;
47+
private:
3848
// Below this size (in device space) distance field text will not be used.
3949
const SkScalar fMinDistanceFieldFontSize;
4050

@@ -45,23 +55,8 @@ class GrTextContext {
4555

4656
static std::unique_ptr<GrTextContext> Make(const Options& options);
4757

48-
static bool CanDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix,
49-
const SkSurfaceProps& props,
50-
bool contextSupportsDistanceFieldText,
51-
const Options& options);
52-
53-
static SkFont InitDistanceFieldFont(const SkFont& font,
54-
const SkMatrix& viewMatrix,
55-
const Options& options,
56-
SkScalar* textRatio);
57-
5858
static SkPaint InitDistanceFieldPaint(const SkPaint& paint);
5959

60-
static std::pair<SkScalar, SkScalar> InitDistanceFieldMinMaxScale(SkScalar textSize,
61-
const SkMatrix& viewMatrix,
62-
const Options& options);
63-
Options options() const { return fOptions; }
64-
6560
private:
6661
GrTextContext(const Options& options);
6762

tests/SkRemoteGlyphCacheTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, c
692692
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
693693
GrTextContext::Options options =
694694
ctxInfo.grContext()->priv().asRecordingContext()->priv().SDFTOptions();
695-
REPORTER_ASSERT(reporter, GrTextContext::CanDrawAsDistanceFields(
696-
paint, font, matrix, surfaceProps, true, options));
695+
REPORTER_ASSERT(reporter,
696+
options.canDrawAsDistanceFields(paint, font, matrix, surfaceProps, true));
697697

698698
// Server.
699699
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());

0 commit comments

Comments
 (0)