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