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

Commit 3d6bf04

Browse files
herbderbySkia Commit-Bot
authored and
Skia Commit-Bot
committed
make options robust
Options used to rely on an external call to SanitizeOptions to ensure they were correct. Now that defaults are set directly, make sure that the values coming in make sense. Change-Id: If6cfc027722b6a7717a920b482ec5be8f7526367 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296040 Reviewed-by: Robert Phillips <[email protected]> Commit-Queue: Herb Derby <[email protected]>
1 parent 2af055b commit 3d6bf04

File tree

7 files changed

+27
-48
lines changed

7 files changed

+27
-48
lines changed

src/core/SkRemoteGlyphCache.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ class SkTextBlobCacheDiffCanvas::TrackLayerDevice final : public SkNoPixelsDevic
392392
protected:
393393
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override {
394394
#if SK_SUPPORT_GPU
395-
GrTextContext::Options options;
396-
GrTextContext::SanitizeOptions(&options);
395+
GrContextOptions ctxOptions;
396+
GrTextContext::Options options =
397+
{ctxOptions.fMinDistanceFieldFontSize, ctxOptions.fGlyphsAsPathsFontSize};
397398

398399
#ifdef SK_CAPTURE_DRAW_TEXT_BLOB
399400
if (SkTextBlobTrace::Capture* capture = fStrikeServer->fCapture.get()) {

src/gpu/GrRecordingContextPriv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define GrRecordingContextPriv_DEFINED
1010

1111
#include "include/private/GrRecordingContext.h"
12+
#include "src/gpu/text/GrTextContext.h"
1213

1314
/** Class that exposes methods to GrRecordingContext that are only intended for use internal to
1415
Skia. This class is purely a privileged window into GrRecordingContext. It should never have
@@ -102,6 +103,10 @@ class GrRecordingContextPriv {
102103
return &fContext->fStats;
103104
}
104105

106+
GrTextContext::Options SDFTOptions() const {
107+
return {this->options().fMinDistanceFieldFontSize, this->options().fGlyphsAsPathsFontSize};
108+
}
109+
105110
private:
106111
explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
107112
GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl

src/gpu/GrRenderTargetContext.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,7 @@ void GrRenderTargetContext::drawGlyphRunList(const GrClip* clip,
485485
return;
486486
}
487487

488-
GrTextContext::Options options = {
489-
fContext->priv().options().fMinDistanceFieldFontSize,
490-
fContext->priv().options().fGlyphsAsPathsFontSize
491-
};
492-
GrTextContext::SanitizeOptions(&options);
493-
488+
GrTextContext::Options options = fContext->priv().SDFTOptions();
494489
GrTextBlobCache* textBlobCache = fContext->priv().getTextBlobCache();
495490

496491
// Get the first paint to use as the key paint.

src/gpu/ops/GrAtlasTextOp.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,7 @@ std::unique_ptr<GrDrawOp> GrAtlasTextOp::CreateOpTestingOnly(GrRenderTargetConte
561561
auto glyphRunList = builder.useGlyphRunList();
562562

563563
const GrRecordingContextPriv& contextPriv = rtc->fContext->priv();
564-
GrTextContext::Options SDFOptions = {
565-
contextPriv.options().fMinDistanceFieldFontSize,
566-
contextPriv.options().fGlyphsAsPathsFontSize
567-
};
568-
GrTextContext::SanitizeOptions(&SDFOptions);
564+
GrTextContext::Options SDFOptions = rtc->fContext->priv().SDFTOptions();
569565

570566
if (glyphRunList.empty()) {
571567
return nullptr;

src/gpu/text/GrTextContext.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,12 @@ static const int kLargeDFFontLimit = 162;
3636
static const int kExtraLargeDFFontSize = 256;
3737
#endif
3838

39-
static const int kDefaultMinDistanceFieldFontSize = 18;
40-
#if defined(SK_BUILD_FOR_ANDROID)
41-
static const int kDefaultMaxDistanceFieldFontSize = 384;
42-
#elif defined(SK_BUILD_FOR_MAC)
43-
static const int kDefaultMaxDistanceFieldFontSize = kExtraLargeDFFontSize;
44-
#else
45-
static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize;
46-
#endif
47-
48-
GrTextContext::GrTextContext(const Options& options) : fOptions(options) {
49-
SanitizeOptions(&fOptions);
50-
}
39+
GrTextContext::GrTextContext(const Options& options) : fOptions(options) { }
5140

5241
std::unique_ptr<GrTextContext> GrTextContext::Make(const Options& options) {
5342
return std::unique_ptr<GrTextContext>(new GrTextContext(options));
5443
}
5544

56-
void GrTextContext::SanitizeOptions(Options* options) {
57-
if (options->fMaxDistanceFieldFontSize < 0.f) {
58-
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;
59-
}
60-
if (options->fMinDistanceFieldFontSize < 0.f) {
61-
options->fMinDistanceFieldFontSize = kDefaultMinDistanceFieldFontSize;
62-
}
63-
}
64-
6545
bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
6646
const SkMatrix& viewMatrix,
6747
const SkSurfaceProps& props,

src/gpu/text/GrTextContext.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ class GrTextBlob;
2828
*/
2929
class GrTextContext {
3030
public:
31-
struct Options {
32-
/**
33-
* Below this size (in device space) distance field text will not be used. Negative means
34-
* use a default value.
35-
*/
36-
SkScalar fMinDistanceFieldFontSize = -1.f;
37-
/**
38-
* Above this size (in device space) distance field text will not be used and glyphs will
39-
* be rendered from outline as individual paths. Negative means use a default value.
40-
*/
41-
SkScalar fMaxDistanceFieldFontSize = -1.f;
31+
class Options {
32+
public:
33+
Options(SkScalar min, SkScalar max)
34+
: fMinDistanceFieldFontSize{min}
35+
, fMaxDistanceFieldFontSize{max} {
36+
SkASSERT_RELEASE(min > 0 && max >= min);
37+
}
38+
// Below this size (in device space) distance field text will not be used.
39+
const SkScalar fMinDistanceFieldFontSize;
40+
41+
// Above this size (in device space) distance field text will not be used and glyphs will
42+
// be rendered from outline as individual paths.
43+
const SkScalar fMaxDistanceFieldFontSize;
4244
};
4345

4446
static std::unique_ptr<GrTextContext> Make(const Options& options);
4547

46-
static void SanitizeOptions(Options* options);
4748
static bool CanDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix,
4849
const SkSurfaceProps& props,
4950
bool contextSupportsDistanceFieldText,

tests/SkRemoteGlyphCacheTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "tools/ToolUtils.h"
2222
#include "tools/fonts/TestEmptyTypeface.h"
2323

24+
#include "src/gpu/GrContextPriv.h"
2425
#include "src/gpu/GrRecordingContextPriv.h"
2526
#include "src/gpu/text/GrTextContext.h"
2627

@@ -689,8 +690,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, c
689690
// A scale transform forces fallback to dft.
690691
SkMatrix matrix = SkMatrix::Scale(16, 16);
691692
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
692-
GrTextContext::Options options;
693-
GrTextContext::SanitizeOptions(&options);
693+
GrTextContext::Options options =
694+
ctxInfo.grContext()->priv().asRecordingContext()->priv().SDFTOptions();
694695
REPORTER_ASSERT(reporter, GrTextContext::CanDrawAsDistanceFields(
695696
paint, font, matrix, surfaceProps, true, options));
696697

0 commit comments

Comments
 (0)