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 <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2020-06-12 11:09:48 -04:00 committed by Skia Commit-Bot
parent 2af055b14d
commit 3d6bf04366
7 changed files with 27 additions and 48 deletions

View File

@ -392,8 +392,9 @@ public:
protected:
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override {
#if SK_SUPPORT_GPU
GrTextContext::Options options;
GrTextContext::SanitizeOptions(&options);
GrContextOptions ctxOptions;
GrTextContext::Options options =
{ctxOptions.fMinDistanceFieldFontSize, ctxOptions.fGlyphsAsPathsFontSize};
#ifdef SK_CAPTURE_DRAW_TEXT_BLOB
if (SkTextBlobTrace::Capture* capture = fStrikeServer->fCapture.get()) {

View File

@ -9,6 +9,7 @@
#define GrRecordingContextPriv_DEFINED
#include "include/private/GrRecordingContext.h"
#include "src/gpu/text/GrTextContext.h"
/** Class that exposes methods to GrRecordingContext that are only intended for use internal to
Skia. This class is purely a privileged window into GrRecordingContext. It should never have
@ -102,6 +103,10 @@ public:
return &fContext->fStats;
}
GrTextContext::Options SDFTOptions() const {
return {this->options().fMinDistanceFieldFontSize, this->options().fGlyphsAsPathsFontSize};
}
private:
explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl

View File

@ -485,12 +485,7 @@ void GrRenderTargetContext::drawGlyphRunList(const GrClip* clip,
return;
}
GrTextContext::Options options = {
fContext->priv().options().fMinDistanceFieldFontSize,
fContext->priv().options().fGlyphsAsPathsFontSize
};
GrTextContext::SanitizeOptions(&options);
GrTextContext::Options options = fContext->priv().SDFTOptions();
GrTextBlobCache* textBlobCache = fContext->priv().getTextBlobCache();
// Get the first paint to use as the key paint.

View File

@ -561,11 +561,7 @@ std::unique_ptr<GrDrawOp> GrAtlasTextOp::CreateOpTestingOnly(GrRenderTargetConte
auto glyphRunList = builder.useGlyphRunList();
const GrRecordingContextPriv& contextPriv = rtc->fContext->priv();
GrTextContext::Options SDFOptions = {
contextPriv.options().fMinDistanceFieldFontSize,
contextPriv.options().fGlyphsAsPathsFontSize
};
GrTextContext::SanitizeOptions(&SDFOptions);
GrTextContext::Options SDFOptions = rtc->fContext->priv().SDFTOptions();
if (glyphRunList.empty()) {
return nullptr;

View File

@ -36,32 +36,12 @@ static const int kLargeDFFontLimit = 162;
static const int kExtraLargeDFFontSize = 256;
#endif
static const int kDefaultMinDistanceFieldFontSize = 18;
#if defined(SK_BUILD_FOR_ANDROID)
static const int kDefaultMaxDistanceFieldFontSize = 384;
#elif defined(SK_BUILD_FOR_MAC)
static const int kDefaultMaxDistanceFieldFontSize = kExtraLargeDFFontSize;
#else
static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize;
#endif
GrTextContext::GrTextContext(const Options& options) : fOptions(options) {
SanitizeOptions(&fOptions);
}
GrTextContext::GrTextContext(const Options& options) : fOptions(options) { }
std::unique_ptr<GrTextContext> GrTextContext::Make(const Options& options) {
return std::unique_ptr<GrTextContext>(new GrTextContext(options));
}
void GrTextContext::SanitizeOptions(Options* options) {
if (options->fMaxDistanceFieldFontSize < 0.f) {
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;
}
if (options->fMinDistanceFieldFontSize < 0.f) {
options->fMinDistanceFieldFontSize = kDefaultMinDistanceFieldFontSize;
}
}
bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,

View File

@ -28,22 +28,23 @@ class GrTextBlob;
*/
class GrTextContext {
public:
struct Options {
/**
* Below this size (in device space) distance field text will not be used. Negative means
* use a default value.
*/
SkScalar fMinDistanceFieldFontSize = -1.f;
/**
* Above this size (in device space) distance field text will not be used and glyphs will
* be rendered from outline as individual paths. Negative means use a default value.
*/
SkScalar fMaxDistanceFieldFontSize = -1.f;
class Options {
public:
Options(SkScalar min, SkScalar max)
: fMinDistanceFieldFontSize{min}
, fMaxDistanceFieldFontSize{max} {
SkASSERT_RELEASE(min > 0 && max >= min);
}
// Below this size (in device space) distance field text will not be used.
const SkScalar fMinDistanceFieldFontSize;
// Above this size (in device space) distance field text will not be used and glyphs will
// be rendered from outline as individual paths.
const SkScalar fMaxDistanceFieldFontSize;
};
static std::unique_ptr<GrTextContext> Make(const Options& options);
static void SanitizeOptions(Options* options);
static bool CanDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,

View File

@ -21,6 +21,7 @@
#include "tools/ToolUtils.h"
#include "tools/fonts/TestEmptyTypeface.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/text/GrTextContext.h"
@ -689,8 +690,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, c
// A scale transform forces fallback to dft.
SkMatrix matrix = SkMatrix::Scale(16, 16);
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
GrTextContext::Options options;
GrTextContext::SanitizeOptions(&options);
GrTextContext::Options options =
ctxInfo.grContext()->priv().asRecordingContext()->priv().SDFTOptions();
REPORTER_ASSERT(reporter, GrTextContext::CanDrawAsDistanceFields(
paint, font, matrix, surfaceProps, true, options));