Debian Codegraph @

src/core/SkStrikeSpec.h

raw
1 /*
2 * Copyright 2019 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 SkStrikeSpec_DEFINED
9 #define SkStrikeSpec_DEFINED
10
11 #include "include/core/SkMaskFilter.h"
12 #include "include/core/SkPathEffect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSpan.h"
16 #include "include/core/SkString.h"
17 #include "include/core/SkTypeface.h"
18 #include "include/core/SkTypes.h"
19 #include "include/private/base/SkTemplates.h"
20 #include "src/core/SkDescriptor.h"
21 #include "src/core/SkScalerContext.h"
22
23 #include <memory>
24 #include <tuple>
25
26 class SkFont;
27 class SkGlyph;
28 class SkMatrix;
29 class SkPaint;
30 class SkStrike;
31 class SkStrikeCache;
32 class SkSurfaceProps;
33 struct SkPackedGlyphID;
34 namespace sktext {
35 class StrikeForGPU;
36 class StrikeForGPUCacheInterface;
37 }
38
39 class SkStrikeSpec {
40 public:
41 SkStrikeSpec(const SkDescriptor& descriptor, sk_sp<SkTypeface> typeface);
42 SkStrikeSpec(const SkStrikeSpec&);
43 SkStrikeSpec& operator=(const SkStrikeSpec&) = delete;
44
45 SkStrikeSpec(SkStrikeSpec&&);
46 SkStrikeSpec& operator=(SkStrikeSpec&&) = delete;
47
48 ~SkStrikeSpec();
49
50 // Create a strike spec for mask style cache entries.
51 static SkStrikeSpec MakeMask(
52 const SkFont& font,
53 const SkPaint& paint,
54 const SkSurfaceProps& surfaceProps,
55 SkScalerContextFlags scalerContextFlags,
56 const SkMatrix& deviceMatrix);
57
58 // A strike for finding the max size for transforming masks. This is used to calculate the
59 // maximum dimension of a SubRun of text.
60 static SkStrikeSpec MakeTransformMask(
61 const SkFont& font,
62 const SkPaint& paint,
63 const SkSurfaceProps& surfaceProps,
64 SkScalerContextFlags scalerContextFlags,
65 const SkMatrix& deviceMatrix);
66
67 // Create a strike spec for path style cache entries.
68 static std::tuple<SkStrikeSpec, SkScalar> MakePath(
69 const SkFont& font,
70 const SkPaint& paint,
71 const SkSurfaceProps& surfaceProps,
72 SkScalerContextFlags scalerContextFlags);
73
74 // Create a canonical strike spec for device-less measurements.
75 static std::tuple<SkStrikeSpec, SkScalar> MakeCanonicalized(
76 const SkFont& font, const SkPaint* paint = nullptr);
77
78 // Create a strike spec without a device, and does not switch over to path for large sizes.
79 static SkStrikeSpec MakeWithNoDevice(
80 const SkFont& font, const SkPaint* paint = nullptr,
81 SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast);
82
83 sk_sp<sktext::StrikeForGPU> findOrCreateScopedStrike(
84 sktext::StrikeForGPUCacheInterface* cache) const;
85
86 sk_sp<SkStrike> findOrCreateStrike() const;
87
88 sk_sp<SkStrike> findOrCreateStrike(SkStrikeCache* cache) const;
89
90 std::unique_ptr<SkScalerContext> createScalerContext() const {
91 SkScalerContextEffects effects{fPathEffect.get(), fMaskFilter.get()};
92 return fTypeface->createScalerContext(effects, fAutoDescriptor.getDesc());
93 }
94
95 const SkDescriptor& descriptor() const { return *fAutoDescriptor.getDesc(); }
96 const SkTypeface& typeface() const { return *fTypeface; }
97 static bool ShouldDrawAsPath(const SkPaint& paint, const SkFont& font, const SkMatrix& matrix);
98 SkString dump() const;
99
100 private:
101 SkStrikeSpec(
102 const SkFont& font,
103 const SkPaint& paint,
104 const SkSurfaceProps& surfaceProps,
105 SkScalerContextFlags scalerContextFlags,
106 const SkMatrix& deviceMatrix);
107
108 SkAutoDescriptor fAutoDescriptor;
109 sk_sp<SkMaskFilter> fMaskFilter{nullptr};
110 sk_sp<SkPathEffect> fPathEffect{nullptr};
111 sk_sp<SkTypeface> fTypeface;
112 };
113
114 class SkBulkGlyphMetrics {
115 public:
116 explicit SkBulkGlyphMetrics(const SkStrikeSpec& spec);
117 ~SkBulkGlyphMetrics();
118 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkGlyphID> glyphIDs);
119 const SkGlyph* glyph(SkGlyphID glyphID);
120
121 private:
122 inline static constexpr int kTypicalGlyphCount = 20;
123 skia_private::AutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs;
124 sk_sp<SkStrike> fStrike;
125 };
126
127 class SkBulkGlyphMetricsAndPaths {
128 public:
129 explicit SkBulkGlyphMetricsAndPaths(const SkStrikeSpec& spec);
130 explicit SkBulkGlyphMetricsAndPaths(sk_sp<SkStrike>&& strike);
131 ~SkBulkGlyphMetricsAndPaths();
132 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkGlyphID> glyphIDs);
133 const SkGlyph* glyph(SkGlyphID glyphID);
134 void findIntercepts(const SkScalar bounds[2], SkScalar scale, SkScalar xPos,
135 const SkGlyph* glyph, SkScalar* array, int* count);
136
137 private:
138 inline static constexpr int kTypicalGlyphCount = 20;
139 skia_private::AutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs;
140 sk_sp<SkStrike> fStrike;
141 };
142
143 class SkBulkGlyphMetricsAndDrawables {
144 public:
145 explicit SkBulkGlyphMetricsAndDrawables(const SkStrikeSpec& spec);
146 explicit SkBulkGlyphMetricsAndDrawables(sk_sp<SkStrike>&& strike);
147 ~SkBulkGlyphMetricsAndDrawables();
148 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkGlyphID> glyphIDs);
149 const SkGlyph* glyph(SkGlyphID glyphID);
150
151 private:
152 inline static constexpr int kTypicalGlyphCount = 20;
153 skia_private::AutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs;
154 sk_sp<SkStrike> fStrike;
155 };
156
157 class SkBulkGlyphMetricsAndImages {
158 public:
159 explicit SkBulkGlyphMetricsAndImages(const SkStrikeSpec& spec);
160 explicit SkBulkGlyphMetricsAndImages(sk_sp<SkStrike>&& strike);
161 ~SkBulkGlyphMetricsAndImages();
162 SkSpan<const SkGlyph*> glyphs(SkSpan<const SkPackedGlyphID> packedIDs);
163 const SkGlyph* glyph(SkPackedGlyphID packedID);
164 const SkDescriptor& descriptor() const;
165
166 private:
167 inline static constexpr int kTypicalGlyphCount = 64;
168 skia_private::AutoSTArray<kTypicalGlyphCount, const SkGlyph*> fGlyphs;
169 sk_sp<SkStrike> fStrike;
170 };
171
172 #endif // SkStrikeSpec_DEFINED