Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
SkScalerContextRec Struct Reference

#include <SkScalerContext.h>

Public Types

enum class  PreMatrixScale { kFull , kVertical , kVerticalInteger }
 

Public Member Functions

void setDeviceGamma (SkScalar g)
 
void setContrast (SkScalar c)
 
const SkMaskGammacachedMaskGamma () const
 
void ignoreGamma ()
 
void ignorePreBlend ()
 
SkString dump () const
 
void getMatrixFrom2x2 (SkMatrix *) const
 
void getLocalMatrix (SkMatrix *) const
 
void getSingleMatrix (SkMatrix *) const
 
bool computeMatrices (PreMatrixScale preMatrixScale, SkVector *scale, SkMatrix *remaining, SkMatrix *remainingWithoutRotation=nullptr, SkMatrix *remainingRotation=nullptr, SkMatrix *total=nullptr)
 
SkAxisAlignment computeAxisAlignmentForHText () const
 
SkFontHinting getHinting () const
 
void setHinting (SkFontHinting)
 
SkMask::Format getFormat () const
 
SkColor getLuminanceColor () const
 
void setLuminanceColor (SkColor c)
 

Static Public Member Functions

static const SkMaskGammaCachedMaskGamma (uint8_t contrast, uint8_t gamma)
 

Public Attributes

SkTypefaceID fTypefaceID
 
SkScalar fTextSize
 
SkScalar fPreScaleX
 
SkScalar fPreSkewX
 
SkScalar fPost2x2 [2][2]
 
SkScalar fFrameWidth
 
SkScalar fMiterLimit
 
uint32_t fForegroundColor {SK_ColorBLACK}
 
SkMask::Format fMaskFormat
 
uint16_t fFlags
 

Friends

class SkScalerContext
 

Detailed Description

Definition at line 68 of file SkScalerContext.h.

Member Enumeration Documentation

◆ PreMatrixScale

The kind of scale which will be applied by the underlying port (pre-matrix).

Enumerator
kFull 
kVertical 
kVerticalInteger 

Definition at line 172 of file SkScalerContext.h.

172 {
173 kFull, // The underlying port can apply both x and y scale.
174 kVertical, // The underlying port can only apply a y scale.
175 kVerticalInteger // The underlying port can only apply an integer y scale.
176 };

Member Function Documentation

◆ cachedMaskGamma()

const SkMaskGamma & SkScalerContextRec::cachedMaskGamma ( ) const
inline

Definition at line 117 of file SkScalerContext.h.

117 {
118 return CachedMaskGamma(fContrast, fDeviceGamma);
119 }
static const SkMaskGamma & CachedMaskGamma(uint8_t contrast, uint8_t gamma)

◆ CachedMaskGamma()

const SkMaskGamma & SkScalerContextRec::CachedMaskGamma ( uint8_t  contrast,
uint8_t  gamma 
)
static

The caller must hold the mask_gamma_cache_mutex() and continue to hold it until the returned SkMaskGamma pointer is refed or forgotten.

Definition at line 129 of file SkScalerContext.cpp.

129 {
130 mask_gamma_cache_mutex().assertHeld();
131
132 constexpr uint8_t contrast0 = InternalContrastFromExternal(0);
133 constexpr uint8_t gamma1 = InternalGammaFromExternal(1);
134 if (contrast0 == contrast && gamma1 == gamma) {
135 if (nullptr == gLinearMaskGamma) {
137 }
138 return *gLinearMaskGamma;
139 }
140 constexpr uint8_t defaultContrast = InternalContrastFromExternal(SK_GAMMA_CONTRAST);
141 constexpr uint8_t defaultGamma = InternalGammaFromExternal(SK_GAMMA_EXPONENT);
142 if (defaultContrast == contrast && defaultGamma == gamma) {
143 if (!gDefaultMaskGamma) {
144 gDefaultMaskGamma = new SkMaskGamma(ExternalContrastFromInternal(contrast),
145 ExternalGammaFromInternal(gamma));
146 }
147 return *gDefaultMaskGamma;
148 }
149 if (!gMaskGamma || gContrast != contrast || gGamma != gamma) {
151 gMaskGamma = new SkMaskGamma(ExternalContrastFromInternal(contrast),
152 ExternalGammaFromInternal(gamma));
153 gContrast = contrast;
154 gGamma = gamma;
155 }
156 return *gMaskGamma;
157}
static void SkSafeUnref(T *obj)
Definition: SkRefCnt.h:149
static uint8_t gGamma
static uint8_t gContrast
static SkMaskGamma * gDefaultMaskGamma
static SkMutex & mask_gamma_cache_mutex()
static SkMaskGamma * gLinearMaskGamma
static SkMaskGamma * gMaskGamma
SkTMaskGamma< 3, 3, 3 > SkMaskGamma
#define SK_GAMMA_CONTRAST
Definition: SkTypes.h:94
#define SK_GAMMA_EXPONENT
Definition: SkTypes.h:86

◆ computeAxisAlignmentForHText()

SkAxisAlignment SkScalerContextRec::computeAxisAlignmentForHText ( ) const

Definition at line 981 of file SkScalerContext.cpp.

981 {
982 // Why fPost2x2 can be used here.
983 // getSingleMatrix multiplies in getLocalMatrix, which consists of
984 // * fTextSize (a scale, which has no effect)
985 // * fPreScaleX (a scale in x, which has no effect)
986 // * fPreSkewX (has no effect, but would on vertical text alignment).
987 // In other words, making the text bigger, stretching it along the
988 // horizontal axis, or fake italicizing it does not move the baseline.
991 }
992
993 if (0 == fPost2x2[1][0]) {
994 // The x axis is mapped onto the x axis.
995 return SkAxisAlignment::kX;
996 }
997 if (0 == fPost2x2[0][0]) {
998 // The x axis is mapped onto the y axis.
999 return SkAxisAlignment::kY;
1000 }
1002}
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
SkScalar fPost2x2[2][2]

◆ computeMatrices()

bool SkScalerContextRec::computeMatrices ( PreMatrixScale  preMatrixScale,
SkVector scale,
SkMatrix remaining,
SkMatrix remainingWithoutRotation = nullptr,
SkMatrix remainingRotation = nullptr,
SkMatrix total = nullptr 
)

Compute useful matrices for use with sizing in underlying libraries.

There are two kinds of text size, a 'requested/logical size' which is like asking for size '12' and a 'real' size which is the size after the matrix is applied. The matrices produced by this method are based on the 'real' size. This method effectively finds the total device matrix and decomposes it in various ways.

The most useful decomposition is into 'scale' and 'remaining'. The 'scale' is applied first and then the 'remaining' to fully apply the total matrix. This decomposition is useful when the text size ('scale') may have meaning apart from the total matrix. This is true when hinting, and sometimes true for other properties as well.

The second (optional) decomposition is of 'remaining' into a non-rotational part 'remainingWithoutRotation' and a rotational part 'remainingRotation'. The 'scale' is applied first, then 'remainingWithoutRotation', then 'remainingRotation' to fully apply the total matrix. This decomposition is helpful when only horizontal metrics can be trusted, so the 'scale' and 'remainingWithoutRotation' will be handled by the underlying library, but the final rotation 'remainingRotation' will be handled manually.

The 'total' matrix is also (optionally) available. This is useful in cases where the underlying library will not be used, often when working directly with font data.

The parameters 'scale' and 'remaining' are required, the other pointers may be nullptr.

Parameters
preMatrixScalethe kind of scale to extract from the total matrix.
scalethe scale extracted from the total matrix (both values positive).
remainingapply after scale to apply the total matrix.
remainingWithoutRotationapply after scale to apply the total matrix sans rotation.
remainingRotationapply after remainingWithoutRotation to apply the total matrix.
totalthe total matrix.
Returns
false if the matrix was singular. The output will be valid but not invertible.

Definition at line 862 of file SkScalerContext.cpp.

864{
865 // A is the 'total' matrix.
866 SkMatrix A;
867 this->getSingleMatrix(&A);
868
869 // The caller may find the 'total' matrix useful when dealing directly with EM sizes.
870 if (A_out) {
871 *A_out = A;
872 }
873
874 // GA is the matrix A with rotation removed.
875 SkMatrix GA;
876 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0;
877 if (skewedOrFlipped) {
878 // QR by Givens rotations. G is Q^T and GA is R. G is rotational (no reflections).
879 // h is where A maps the horizontal baseline.
881 A.mapPoints(&h, 1);
882
883 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0).
884 SkMatrix G;
886
887 GA = G;
888 GA.preConcat(A);
889
890 // The 'remainingRotation' is G inverse, which is fairly simple since G is 2x2 rotational.
891 if (G_inv) {
892 G_inv->setAll(
896 }
897 } else {
898 GA = A;
899 if (G_inv) {
900 G_inv->reset();
901 }
902 }
903
904 // If the 'total' matrix is singular, set the 'scale' to something finite and zero the matrices.
905 // All underlying ports have issues with zero text size, so use the matricies to zero.
906 // If one of the scale factors is less than 1/256 then an EM filling square will
907 // never affect any pixels.
908 // If there are any nonfinite numbers in the matrix, bail out and set the matrices to zero.
911 !GA.isFinite())
912 {
913 s->fX = SK_Scalar1;
914 s->fY = SK_Scalar1;
915 sA->setScale(0, 0);
916 if (GsA) {
917 GsA->setScale(0, 0);
918 }
919 if (G_inv) {
920 G_inv->reset();
921 }
922 return false;
923 }
924
925 // At this point, given GA, create s.
926 switch (preMatrixScale) {
930 break;
933 s->fX = yScale;
934 s->fY = yScale;
935 break;
936 }
938 SkScalar realYScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
939 SkScalar intYScale = SkScalarRoundToScalar(realYScale);
940 if (intYScale == 0) {
941 intYScale = SK_Scalar1;
942 }
943 s->fX = intYScale;
944 s->fY = intYScale;
945 break;
946 }
947 }
948
949 // The 'remaining' matrix sA is the total matrix A without the scale.
950 if (!skewedOrFlipped && (
951 (PreMatrixScale::kFull == preMatrixScale) ||
952 (PreMatrixScale::kVertical == preMatrixScale && A.getScaleX() == A.getScaleY())))
953 {
954 // If GA == A and kFull, sA is identity.
955 // If GA == A and kVertical and A.scaleX == A.scaleY, sA is identity.
956 sA->reset();
957 } else if (!skewedOrFlipped && PreMatrixScale::kVertical == preMatrixScale) {
958 // If GA == A and kVertical, sA.scaleY is SK_Scalar1.
959 sA->reset();
960 sA->setScaleX(A.getScaleX() / s->fY);
961 } else {
962 // TODO: like kVertical, kVerticalInteger with int scales.
963 *sA = A;
964 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
965 }
966
967 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale.
968 if (GsA) {
969 *GsA = GA;
970 // G is rotational so reorders with the scale.
971 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
972 }
973
974 return true;
975}
void SkComputeGivensRotation(const SkVector &h, SkMatrix *G)
Definition: SkMatrix22.cpp:14
#define SkScalarInvert(x)
Definition: SkScalar.h:73
#define SK_Scalar1
Definition: SkScalar.h:18
#define SK_ScalarNearlyZero
Definition: SkScalar.h:99
#define SkScalarRoundToScalar(x)
Definition: SkScalar.h:32
#define SkScalarAbs(x)
Definition: SkScalar.h:39
static constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
static constexpr int kMTransY
vertical translation
Definition: SkMatrix.h:358
static constexpr int kMPersp1
input y perspective factor
Definition: SkMatrix.h:360
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
Definition: SkMatrix.h:562
SkMatrix & preConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:674
static constexpr int kMPersp0
input x perspective factor
Definition: SkMatrix.h:359
static constexpr int kMPersp2
perspective bias
Definition: SkMatrix.h:361
static constexpr int kMTransX
horizontal translation
Definition: SkMatrix.h:355
static constexpr int kMSkewY
vertical skew factor
Definition: SkMatrix.h:356
bool isFinite() const
Definition: SkMatrix.h:1834
SkScalar get(int index) const
Definition: SkMatrix.h:392
static constexpr int kMScaleY
vertical scale factor
Definition: SkMatrix.h:357
static constexpr int kMSkewX
horizontal skew factor
Definition: SkMatrix.h:354
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
SkScalar h
Definition: SkMD5.cpp:125
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
void getSingleMatrix(SkMatrix *) const

◆ dump()

SkString SkScalerContextRec::dump ( ) const
inline

Definition at line 153 of file SkScalerContext.h.

153 {
154 SkString msg;
155 msg.appendf(" Rec\n");
156 msg.appendf(" textsize %a prescale %a preskew %a post [%a %a %a %a]\n",
158 fPost2x2[0][1], fPost2x2[1][0], fPost2x2[1][1]);
159 msg.appendf(" frame %g miter %g format %d join %d cap %d flags %#hx\n",
160 fFrameWidth, fMiterLimit, fMaskFormat, fStrokeJoin, fStrokeCap, fFlags);
161 msg.appendf(" lum bits %x, device gamma %d, contrast %d\n", fLumBits,
162 fDeviceGamma, fContrast);
163 msg.appendf(" foreground color %x\n", fForegroundColor);
164 return msg;
165 }
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
SkMask::Format fMaskFormat

◆ getFormat()

SkMask::Format SkScalerContextRec::getFormat ( ) const
inline

Definition at line 221 of file SkScalerContext.h.

221 {
222 return fMaskFormat;
223 }

◆ getHinting()

SkFontHinting SkScalerContextRec::getHinting ( ) const
inline

Definition at line 480 of file SkScalerContext.h.

480 {
481 unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >>
483 return static_cast<SkFontHinting>(hint);
484}
SkFontHinting
Definition: SkFontTypes.h:18

◆ getLocalMatrix()

void SkScalerContextRec::getLocalMatrix ( SkMatrix m) const

Definition at line 849 of file SkScalerContext.cpp.

849 {
851}
static SkMatrix MakeTextMatrix(SkScalar size, SkScalar scaleX, SkScalar skewX)
Definition: SkFontPriv.h:41

◆ getLuminanceColor()

SkColor SkScalerContextRec::getLuminanceColor ( ) const
inline

Definition at line 225 of file SkScalerContext.h.

225 {
226 return fLumBits;
227 }

◆ getMatrixFrom2x2()

void SkScalerContextRec::getMatrixFrom2x2 ( SkMatrix dst) const

Definition at line 843 of file SkScalerContext.cpp.

843 {
844 dst->setAll(fPost2x2[0][0], fPost2x2[0][1], 0,
845 fPost2x2[1][0], fPost2x2[1][1], 0,
846 0, 0, 1);
847}
dst
Definition: cp.py:12

◆ getSingleMatrix()

void SkScalerContextRec::getSingleMatrix ( SkMatrix m) const

Definition at line 853 of file SkScalerContext.cpp.

853 {
854 this->getLocalMatrix(m);
855
856 // now concat the device matrix
857 SkMatrix deviceMatrix;
858 this->getMatrixFrom2x2(&deviceMatrix);
859 m->postConcat(deviceMatrix);
860}
void getLocalMatrix(SkMatrix *) const
void getMatrixFrom2x2(SkMatrix *) const

◆ ignoreGamma()

void SkScalerContextRec::ignoreGamma ( )
inline

Causes the luminance color to be ignored, and the paint and device gamma to be effectively 1.0

Definition at line 125 of file SkScalerContext.h.

125 {
128 }
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
void setDeviceGamma(SkScalar g)
void setLuminanceColor(SkColor c)

◆ ignorePreBlend()

void SkScalerContextRec::ignorePreBlend ( )
inline

Causes the luminance color and contrast to be ignored, and the paint and device gamma to be effectively 1.0.

Definition at line 134 of file SkScalerContext.h.

134 {
135 ignoreGamma();
136 setContrast(0);
137 }
void setContrast(SkScalar c)

◆ setContrast()

void SkScalerContextRec::setContrast ( SkScalar  c)
inline

Definition at line 109 of file SkScalerContext.h.

109 {
110 sk_ignore_unused_variable(fReservedAlign);
113 fContrast = InternalContrastFromExternal(c);
114 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void sk_ignore_unused_variable(const T &)
Definition: SkTemplates.h:37
static constexpr SkScalar kMaxContrastInclusive
static constexpr SkScalar kMinContrastInclusive

◆ setDeviceGamma()

void SkScalerContextRec::setDeviceGamma ( SkScalar  g)
inline

Definition at line 102 of file SkScalerContext.h.

102 {
103 sk_ignore_unused_variable(fReservedAlign2);
106 fDeviceGamma = InternalGammaFromExternal(g);
107 }
static constexpr SkScalar kMaxGammaExclusive
static constexpr SkScalar kMinGammaInclusive

◆ setHinting()

void SkScalerContextRec::setHinting ( SkFontHinting  hinting)
inline

Definition at line 486 of file SkScalerContext.h.

486 {
487 fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) |
488 (static_cast<unsigned>(hinting) << SkScalerContext::kHinting_Shift);
489}

◆ setLuminanceColor()

void SkScalerContextRec::setLuminanceColor ( SkColor  c)

Definition at line 1004 of file SkScalerContext.cpp.

1004 {
1005 fLumBits = SkMaskGamma::CanonicalColor(
1007}
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
#define SkColorGetB(color)
Definition: SkColor.h:73
static SkColor CanonicalColor(SkColor color)
Definition: SkMaskGamma.h:124

Friends And Related Function Documentation

◆ SkScalerContext

friend class SkScalerContext
friend

Definition at line 235 of file SkScalerContext.h.

Member Data Documentation

◆ fFlags

uint16_t SkScalerContextRec::fFlags

Definition at line 146 of file SkScalerContext.h.

◆ fForegroundColor

uint32_t SkScalerContextRec::fForegroundColor {SK_ColorBLACK}

Definition at line 77 of file SkScalerContext.h.

◆ fFrameWidth

SkScalar SkScalerContextRec::fFrameWidth

Definition at line 72 of file SkScalerContext.h.

◆ fMaskFormat

SkMask::Format SkScalerContextRec::fMaskFormat

Definition at line 139 of file SkScalerContext.h.

◆ fMiterLimit

SkScalar SkScalerContextRec::fMiterLimit

Definition at line 72 of file SkScalerContext.h.

◆ fPost2x2

SkScalar SkScalerContextRec::fPost2x2[2][2]

Definition at line 71 of file SkScalerContext.h.

◆ fPreScaleX

SkScalar SkScalerContextRec::fPreScaleX

Definition at line 70 of file SkScalerContext.h.

◆ fPreSkewX

SkScalar SkScalerContextRec::fPreSkewX

Definition at line 70 of file SkScalerContext.h.

◆ fTextSize

SkScalar SkScalerContextRec::fTextSize

Definition at line 70 of file SkScalerContext.h.

◆ fTypefaceID

SkTypefaceID SkScalerContextRec::fTypefaceID

Definition at line 69 of file SkScalerContext.h.


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