Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
sktext::gpu::SDFTControl Class Reference

#include <SDFTControl.h>

Public Member Functions

 SDFTControl (bool ableToUseSDFT, bool useSDFTForSmallText, bool useSDFTForPerspectiveText, SkScalar min, SkScalar max)
 
std::tuple< SkFont, SkScalar, SDFTMatrixRangegetSDFFont (const SkFont &font, const SkMatrix &viewMatrix, const SkPoint &textLocation) const
 
bool isSDFT (SkScalar approximateDeviceTextSize, const SkPaint &paint, const SkMatrix &matrix) const
 
SkScalar maxSize () const
 
bool isDirect (SkScalar approximateDeviceTextSize, const SkPaint &paint, const SkMatrix &matrix) const
 

Detailed Description

Definition at line 41 of file SDFTControl.h.

Constructor & Destructor Documentation

◆ SDFTControl()

sktext::gpu::SDFTControl::SDFTControl ( bool  ableToUseSDFT,
bool  useSDFTForSmallText,
bool  useSDFTForPerspectiveText,
SkScalar  min,
SkScalar  max 
)

Definition at line 44 of file SDFTControl.cpp.

47 : fMinDistanceFieldFontSize{MinSDFTRange(useSDFTForSmallText, min)}
48 , fMaxDistanceFieldFontSize{max}
49 , fAbleToUseSDFT{ableToUseSDFT}
50 , fAbleToUsePerspectiveSDFT{useSDFTForPerspectiveText} {
51 SkASSERT_RELEASE(0 < min && min <= max);
52}
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

Member Function Documentation

◆ getSDFFont()

std::tuple< SkFont, SkScalar, SDFTMatrixRange > sktext::gpu::SDFTControl::getSDFFont ( const SkFont font,
const SkMatrix viewMatrix,
const SkPoint textLocation 
) const

Definition at line 83 of file SDFTControl.cpp.

84 {
85 SkScalar textSize = font.getSize();
86 SkScalar scaledTextSize = SkFontPriv::ApproximateTransformedTextSize(font, viewMatrix, textLoc);
87 if (scaledTextSize <= 0 || SkScalarNearlyEqual(textSize, scaledTextSize)) {
88 scaledTextSize = textSize;
89 }
90
91 SkFont dfFont{font};
92
93 SkScalar dfMaskScaleFloor;
94 SkScalar dfMaskScaleCeil;
95 SkScalar dfMaskSize;
96 if (scaledTextSize <= kSmallDFFontLimit) {
97 dfMaskScaleFloor = fMinDistanceFieldFontSize;
98 dfMaskScaleCeil = kSmallDFFontLimit;
99 dfMaskSize = kSmallDFFontLimit;
100 } else if (scaledTextSize <= kMediumDFFontLimit) {
101 dfMaskScaleFloor = kSmallDFFontLimit;
102 dfMaskScaleCeil = kMediumDFFontLimit;
103 dfMaskSize = kMediumDFFontLimit;
104#ifdef SK_BUILD_FOR_MAC
105 } else if (scaledTextSize <= kLargeDFFontLimit) {
106 dfMaskScaleFloor = kMediumDFFontLimit;
107 dfMaskScaleCeil = kLargeDFFontLimit;
108 dfMaskSize = kLargeDFFontLimit;
109 } else {
110 dfMaskScaleFloor = kLargeDFFontLimit;
111 dfMaskScaleCeil = fMaxDistanceFieldFontSize;
112 dfMaskSize = kExtraLargeDFFontLimit;
113 }
114#else
115 } else {
116 dfMaskScaleFloor = kMediumDFFontLimit;
117 dfMaskScaleCeil = fMaxDistanceFieldFontSize;
118 dfMaskSize = kLargeDFFontLimit;
119 }
120#endif
121
122 dfFont.setSize(dfMaskSize);
123 dfFont.setEdging(SkFont::Edging::kAntiAlias);
124 dfFont.setForceAutoHinting(false);
125 dfFont.setHinting(SkFontHinting::kNormal);
126
127 // The sub-pixel position will always happen when transforming to the screen.
128 dfFont.setSubpixel(false);
129
130 SkScalar minMatrixScale = dfMaskScaleFloor / textSize,
131 maxMatrixScale = dfMaskScaleCeil / textSize;
132 return {dfFont, textSize / dfMaskSize, {minMatrixScale, maxMatrixScale}};
133}
@ kNormal
glyph outlines modified to improve constrast
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
static SkScalar ApproximateTransformedTextSize(const SkFont &font, const SkMatrix &matrix, const SkPoint &textLocation)
Definition: SkFont.cpp:366
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
float SkScalar
Definition: extension.cpp:12
font
Font Metadata and Metrics.
static const int kMediumDFFontLimit
Definition: SDFTControl.cpp:31
static const int kSmallDFFontLimit
Definition: SDFTControl.cpp:30
static const int kLargeDFFontLimit
Definition: SDFTControl.cpp:32

◆ isDirect()

bool sktext::gpu::SDFTControl::isDirect ( SkScalar  approximateDeviceTextSize,
const SkPaint paint,
const SkMatrix matrix 
) const

Definition at line 55 of file SDFTControl.cpp.

56 {
57#if !defined(SK_DISABLE_SDF_TEXT)
58 const bool isSDFT = this->isSDFT(approximateDeviceTextSize, paint, matrix);
59#else
60 const bool isSDFT = false;
61#endif
62 return !isSDFT &&
63 !matrix.hasPerspective() &&
64 0 < approximateDeviceTextSize &&
65 approximateDeviceTextSize < SkGlyphDigest::kSkSideTooBigForAtlas;
66}
static constexpr uint16_t kSkSideTooBigForAtlas
Definition: SkGlyph.h:333
bool isSDFT(SkScalar approximateDeviceTextSize, const SkPaint &paint, const SkMatrix &matrix) const
Definition: SDFTControl.cpp:69
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ isSDFT()

bool sktext::gpu::SDFTControl::isSDFT ( SkScalar  approximateDeviceTextSize,
const SkPaint paint,
const SkMatrix matrix 
) const

Definition at line 69 of file SDFTControl.cpp.

70 {
71 const bool wideStroke = paint.getStyle() == SkPaint::kStroke_Style &&
72 paint.getStrokeWidth() > 0;
73 return fAbleToUseSDFT &&
74 paint.getMaskFilter() == nullptr &&
75 (paint.getStyle() == SkPaint::kFill_Style || wideStroke) &&
76 0 < approximateDeviceTextSize &&
77 (fAbleToUsePerspectiveSDFT || !matrix.hasPerspective()) &&
78 (fMinDistanceFieldFontSize <= approximateDeviceTextSize || matrix.hasPerspective()) &&
79 approximateDeviceTextSize <= fMaxDistanceFieldFontSize;
80}
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193

◆ maxSize()

SkScalar sktext::gpu::SDFTControl::maxSize ( ) const
inline

Definition at line 54 of file SDFTControl.h.

54{ return fMaxDistanceFieldFontSize; }

The documentation for this class was generated from the following files: