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 SkStrikeInterface_DEFINED
9 #define SkStrikeInterface_DEFINED
10 
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPoint.h"
13 #include "include/core/SkTypes.h"
14 #include "src/core/SkGlyph.h"
15 #include "src/core/SkSpan.h"
16 
17 #include <memory>
18 
19 class SkDescriptor;
20 class SkGlyph;
21 class SkMaskFilter;
22 class SkPathEffect;
23 class SkTypeface;
24 struct SkGlyphPositionRoundingSpec;
25 struct SkScalerContextEffects;
26 
27 struct SkGlyphPos {
28     size_t index;
29     const SkGlyph* glyph;
30     SkPoint position;
31 };
32 
33 struct SkPathPos {
34     const SkPath* path;
35     SkPoint position;
36 };
37 
38 class SkStrikeForGPU {
39 public:
40     virtual ~SkStrikeForGPU() = default;
41     virtual const SkDescriptor& getDescriptor() const = 0;
42 
43     // prepareForDrawingRemoveEmpty takes glyphIDs, and position, and returns a list of SkGlyphs
44     // and positions where all the data to draw the glyph has been created. The maxDimension
45     // parameter determines if the mask/SDF version will be created, or an alternate drawing
46     // format should be used. For path-only drawing set maxDimension to 0, and for bitmap-device
47     // drawing (where there is no upper limit to the glyph in the cache) use INT_MAX.
48     // prepareForDrawingRemoveEmpty should remove all empty glyphs from the returned span.
49     virtual SkSpan<const SkGlyphPos>
50     prepareForDrawingRemoveEmpty(const SkPackedGlyphID packedGlyphIDs[],
51                                  const SkPoint positions[],
52                                  size_t n,
53                                  int maxDimension,
54                                  SkGlyphPos results[]) = 0;
55 
56     virtual const SkGlyphPositionRoundingSpec& roundingSpec() const = 0;
57 
58     // Used with SkScopedStrikeForGPU to take action at the end of a scope.
59     virtual void onAboutToExitScope() = 0;
60 
61     // Common categories for glyph types used by GPU.
62     static bool CanDrawAsMask(const SkGlyph& glyph);
63     static bool CanDrawAsSDFT(const SkGlyph& glyph);
64     static bool CanDrawAsPath(const SkGlyph& glyph);
65 
66 
67     struct Deleter {
operatorDeleter68         void operator()(SkStrikeForGPU* ptr) const {
69             ptr->onAboutToExitScope();
70         }
71     };
72 };
73 
74 using SkScopedStrikeForGPU = std::unique_ptr<SkStrikeForGPU, SkStrikeForGPU::Deleter>;
75 
76 class SkStrikeForGPUCacheInterface {
77 public:
78     virtual ~SkStrikeForGPUCacheInterface() = default;
79     virtual SkScopedStrikeForGPU findOrCreateScopedStrike(const SkDescriptor& desc,
80                                                           const SkScalerContextEffects& effects,
81                                                           const SkTypeface& typeface) = 0;
82 };
83 #endif  //SkStrikeInterface_DEFINED
84