xref: /third_party/skia/src/gpu/text/GrSDFTControl.h (revision cb93a386)
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
14class SkMatrix;
15class SkSurfaceProps;
16
17class GrSDFTControl {
18public:
19    GrSDFTControl(bool ableToUseSDFT, bool useSDFTForSmallText, SkScalar min, SkScalar max);
20
21    enum DrawingType : uint8_t {
22        kDirect = 1,
23        kSDFT = 2,
24        kPath = 4
25    };
26
27    DrawingType drawingType(
28            const SkFont& font, const SkPaint& paint, const SkMatrix& viewMatrix) const;
29
30    SkFont getSDFFont(const SkFont& font,
31                      const SkMatrix& viewMatrix,
32                      SkScalar* textRatio) const;
33    std::pair<SkScalar, SkScalar> computeSDFMinMaxScale(
34            SkScalar textSize, const SkMatrix& viewMatrix) const;
35private:
36    static SkScalar MinSDFTRange(bool useSDFTForSmallText, SkScalar min);
37
38    // Below this size (in device space) distance field text will not be used.
39    const SkScalar fMinDistanceFieldFontSize;
40
41    // Above this size (in device space) distance field text will not be used and glyphs will
42    // be rendered from outline as individual paths.
43    const SkScalar fMaxDistanceFieldFontSize;
44
45    const bool fAbleToUseSDFT;
46};
47
48#endif  // GrSDFTControl_DEFINED
49