SkStrikeInterface.h 3.4 KB

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