• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrSDFTControl_DEFINED
9 #define GrSDFTControl_DEFINED
10 
11 #include "include/core/SkFont.h"
12 #include "include/core/SkScalar.h"
13 
14 #include <tuple>
15 
16 class SkMatrix;
17 class SkSurfaceProps;
18 
19 // Two numbers fMatrixMin and fMatrixMax such that if viewMatrix.getMaxScale() is between them then
20 // this SDFT size can be reused.
21 class GrSDFTMatrixRange {
22 public:
GrSDFTMatrixRange(SkScalar min,SkScalar max)23     GrSDFTMatrixRange(SkScalar min, SkScalar max) : fMatrixMin{min}, fMatrixMax{max} {}
24     bool matrixInRange(const SkMatrix& matrix) const;
25 
26 private:
27     const SkScalar fMatrixMin,
28                    fMatrixMax;
29 };
30 
31 class GrSDFTControl {
32 public:
33     GrSDFTControl(bool ableToUseSDFT, bool useSDFTForSmallText, SkScalar min, SkScalar max);
34 
35     // Produce a font, a scale factor from the nominal size to the source space size, and matrix
36     // range where this font can be reused.
37     std::tuple<SkFont, SkScalar, GrSDFTMatrixRange>
38     getSDFFont(const SkFont& font, const SkMatrix& viewMatrix) const;
39 
40     bool isDirect(SkScalar approximateDeviceTextSize, const SkPaint& paint) const;
41     bool isSDFT(SkScalar approximateDeviceTextSize, const SkPaint& paint) const;
42 
43 private:
44     static SkScalar MinSDFTRange(bool useSDFTForSmallText, SkScalar min);
45 
46     // Below this size (in device space) distance field text will not be used.
47     const SkScalar fMinDistanceFieldFontSize;
48 
49     // Above this size (in device space) distance field text will not be used and glyphs will
50     // be rendered from outline as individual paths.
51     const SkScalar fMaxDistanceFieldFontSize;
52 
53     const bool fAbleToUseSDFT;
54 };
55 
56 #endif  // GrSDFTControl_DEFINED
57