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 25 // TODO: rename SkScalerContextEffects -> SkStrikeEffects 26 struct SkScalerContextEffects { SkScalerContextEffectsSkScalerContextEffects27 SkScalerContextEffects() : fPathEffect(nullptr), fMaskFilter(nullptr) {} SkScalerContextEffectsSkScalerContextEffects28 SkScalerContextEffects(SkPathEffect* pe, SkMaskFilter* mf) 29 : fPathEffect(pe), fMaskFilter(mf) {} SkScalerContextEffectsSkScalerContextEffects30 explicit SkScalerContextEffects(const SkPaint& paint) 31 : fPathEffect(paint.getPathEffect()) 32 , fMaskFilter(paint.getMaskFilter()) {} 33 34 SkPathEffect* fPathEffect; 35 SkMaskFilter* fMaskFilter; 36 }; 37 38 struct SkGlyphPos { 39 size_t index; 40 const SkGlyph* glyph; 41 SkPoint position; 42 }; 43 44 struct SkPathPos { 45 const SkPath* path; 46 SkPoint position; 47 }; 48 49 class SkStrikeInterface { 50 public: 51 virtual ~SkStrikeInterface() = default; 52 virtual const SkDescriptor& getDescriptor() const = 0; 53 54 enum PreparationDetail { 55 kBoundsOnly, 56 kImageIfNeeded, 57 }; 58 59 // prepareForDrawingRemoveEmpty takes glyphIDs, and position, and returns a list of SkGlyphs 60 // and positions where all the data to draw the glyph has been created. The maxDimension 61 // parameter determines if the mask/SDF version will be created, or an alternate drawing 62 // format should be used. For path-only drawing set maxDimension to 0, and for bitmap-device 63 // drawing (where there is no upper limit to the glyph in the cache) use INT_MAX. 64 // * PreparationDetail determines, in the mask case, if the mask/SDF should be generated. 65 // This does not affect the path or fallback cases. 66 // prepareForDrawingRemoveEmpty should remove all empty glyphs from the returned span. 67 virtual SkSpan<const SkGlyphPos> 68 prepareForDrawingRemoveEmpty(const SkPackedGlyphID packedGlyphIDs[], 69 const SkPoint positions[], 70 size_t n, 71 int maxDimension, 72 PreparationDetail detail, 73 SkGlyphPos results[]) = 0; 74 75 // rounding() and subpixelMask are used to calculate the subpixel position of a glyph. 76 // The per component (x or y) calculation is: 77 // 78 // subpixelOffset = (floor((viewportPosition + rounding) & mask) >> 14) & 3 79 // 80 // where mask is either 0 or ~0, and rounding is either 81 // 1/2 for non-subpixel or 1/8 for subpixel. 82 virtual SkVector rounding() const = 0; 83 virtual SkIPoint subpixelMask() const = 0; 84 85 // Used with SkScopedStrike to take action at the end of a scope. 86 virtual void onAboutToExitScope() = 0; 87 88 struct Deleter { operatorDeleter89 void operator()(SkStrikeInterface* ptr) const { 90 ptr->onAboutToExitScope(); 91 } 92 }; 93 }; 94 95 using SkScopedStrike = std::unique_ptr<SkStrikeInterface, SkStrikeInterface::Deleter>; 96 97 class SkStrikeCacheInterface { 98 public: 99 virtual ~SkStrikeCacheInterface() = default; 100 virtual SkScopedStrike findOrCreateScopedStrike(const SkDescriptor& desc, 101 const SkScalerContextEffects& effects, 102 const SkTypeface& typeface) = 0; 103 }; 104 #endif //SkStrikeInterface_DEFINED 105