• 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 sktext_gpu_SDFTControl_DEFINED
9 #define sktext_gpu_SDFTControl_DEFINED
10 
11 #include "include/core/SkFlattenable.h"
12 #include "include/core/SkFont.h"
13 #include "include/core/SkScalar.h"
14 
15 #include <tuple>
16 
17 class SkMatrix;
18 class SkSurfaceProps;
19 
20 namespace sktext::gpu {
21 
22 #if !defined(SK_DISABLE_SDF_TEXT)
23 // Two numbers fMatrixMin and fMatrixMax such that if viewMatrix.getMaxScale() is between them then
24 // this SDFT size can be reused.
25 class SDFTMatrixRange {
26 public:
SDFTMatrixRange(SkScalar min,SkScalar max)27     SDFTMatrixRange(SkScalar min, SkScalar max) : fMatrixMin{min}, fMatrixMax{max} {}
28     bool matrixInRange(const SkMatrix& matrix) const;
29     void flatten(SkWriteBuffer& buffer) const;
30     static SDFTMatrixRange MakeFromBuffer(SkReadBuffer& buffer);
31 
32 private:
33     const SkScalar fMatrixMin,
34                    fMatrixMax;
35 };
36 #endif
37 
38 class SDFTControl {
39 public:
40 #if !defined(SK_DISABLE_SDF_TEXT)
41     SDFTControl(bool ableToUseSDFT, bool useSDFTForSmallText, bool useSDFTForPerspectiveText,
42                 SkScalar min, SkScalar max);
43 
44     // Produce a font, a scale factor from the nominal size to the source space size, and matrix
45     // range where this font can be reused.
46     std::tuple<SkFont, SkScalar, SDFTMatrixRange>
47     getSDFFont(const SkFont& font, const SkMatrix& viewMatrix, const SkPoint& textLocation) const;
48 
49     bool isSDFT(SkScalar approximateDeviceTextSize, const SkPaint& paint,
50                 const SkMatrix& matrix) const;
maxSize()51     SkScalar maxSize() const { return fMaxDistanceFieldFontSize; }
52 #else
53     SDFTControl() {}
54 #endif
55     bool isDirect(SkScalar approximateDeviceTextSize, const SkPaint& paint,
56                   const SkMatrix& matrix) const;
57 
58 
59 private:
60 #if !defined(SK_DISABLE_SDF_TEXT)
61     static SkScalar MinSDFTRange(bool useSDFTForSmallText, SkScalar min);
62 
63     // Below this size (in device space) distance field text will not be used.
64     const SkScalar fMinDistanceFieldFontSize;
65 
66     // Above this size (in device space) distance field text will not be used and glyphs will
67     // be rendered from outline as individual paths.
68     const SkScalar fMaxDistanceFieldFontSize;
69 
70     const bool fAbleToUseSDFT;
71     const bool fAbleToUsePerspectiveSDFT;
72 #endif
73 };
74 
75 }  // namespace sktext::gpu
76 
77 #endif  // sktext_SDFTControl_DEFINED
78