SkMaskFilter.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  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 SkMaskFilter_DEFINED
  8. #define SkMaskFilter_DEFINED
  9. #include "include/core/SkBlurTypes.h"
  10. #include "include/core/SkCoverageMode.h"
  11. #include "include/core/SkFlattenable.h"
  12. #include "include/core/SkScalar.h"
  13. class SkMatrix;
  14. struct SkRect;
  15. class SkString;
  16. /** \class SkMaskFilter
  17. SkMaskFilter is the base class for object that perform transformations on
  18. the mask before drawing it. An example subclass is Blur.
  19. */
  20. class SK_API SkMaskFilter : public SkFlattenable {
  21. public:
  22. /** Create a blur maskfilter.
  23. * @param style The SkBlurStyle to use
  24. * @param sigma Standard deviation of the Gaussian blur to apply. Must be > 0.
  25. * @param respectCTM if true the blur's sigma is modified by the CTM.
  26. * @return The new blur maskfilter
  27. */
  28. static sk_sp<SkMaskFilter> MakeBlur(SkBlurStyle style, SkScalar sigma,
  29. bool respectCTM = true);
  30. /**
  31. * Construct a maskfilter whose effect is to first apply the inner filter and then apply
  32. * the outer filter to the result of the inner's. Returns nullptr on failure.
  33. */
  34. static sk_sp<SkMaskFilter> MakeCompose(sk_sp<SkMaskFilter> outer, sk_sp<SkMaskFilter> inner);
  35. /**
  36. * Compose two maskfilters together using a coverage mode. Returns nullptr on failure.
  37. */
  38. static sk_sp<SkMaskFilter> MakeCombine(sk_sp<SkMaskFilter> filterA, sk_sp<SkMaskFilter> filterB,
  39. SkCoverageMode mode);
  40. /**
  41. * Construct a maskfilter with an additional transform.
  42. *
  43. * Note: unlike shader local matrices, this transform composes next to the CTM.
  44. *
  45. * TotalMatrix = CTM x MaskFilterMatrix x (optional/downstream) ShaderLocalMatrix
  46. */
  47. sk_sp<SkMaskFilter> makeWithMatrix(const SkMatrix&) const;
  48. static SkFlattenable::Type GetFlattenableType() {
  49. return kSkMaskFilter_Type;
  50. }
  51. SkFlattenable::Type getFlattenableType() const override {
  52. return kSkMaskFilter_Type;
  53. }
  54. static sk_sp<SkMaskFilter> Deserialize(const void* data, size_t size,
  55. const SkDeserialProcs* procs = nullptr) {
  56. return sk_sp<SkMaskFilter>(static_cast<SkMaskFilter*>(
  57. SkFlattenable::Deserialize(
  58. kSkMaskFilter_Type, data, size, procs).release()));
  59. }
  60. private:
  61. static void RegisterFlattenables();
  62. friend class SkFlattenable;
  63. };
  64. #endif