| 1 |
/* |
| 2 |
* Copyright 2023 Google LLC |
| 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 SkBlurMaskFilterImpl_DEFINED |
| 9 |
#define SkBlurMaskFilterImpl_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkFlattenable.h" |
| 12 |
#include "include/core/SkScalar.h" |
| 13 |
#include "include/core/SkSpan.h" |
| 14 |
#include "src/core/SkMask.h" |
| 15 |
#include "src/core/SkMaskFilterBase.h" |
| 16 |
|
| 17 |
#include <optional> |
| 18 |
#include <utility> |
| 19 |
|
| 20 |
class SkImageFilter; |
| 21 |
class SkMatrix; |
| 22 |
class SkPaint; |
| 23 |
class SkRRect; |
| 24 |
class SkReadBuffer; |
| 25 |
class SkResourceCache; |
| 26 |
class SkWriteBuffer; |
| 27 |
enum SkBlurStyle : int; |
| 28 |
struct SkIPoint; |
| 29 |
struct SkIRect; |
| 30 |
struct SkRect; |
| 31 |
template <typename T> class sk_sp; |
| 32 |
|
| 33 |
class SkBlurMaskFilterImpl : public SkMaskFilterBase { |
| 34 |
public: |
| 35 |
SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, bool respectCTM); |
| 36 |
|
| 37 |
// From SkMaskFilterBase.h |
| 38 |
SkMask::Format getFormat() const override; |
| 39 |
bool filterMask(SkMaskBuilder* dst, const SkMask& src, const SkMatrix&, |
| 40 |
SkIPoint* margin) const override; |
| 41 |
SkMaskFilterBase::Type type() const override { return SkMaskFilterBase::Type::kBlur; } |
| 42 |
|
| 43 |
void computeFastBounds(const SkRect&, SkRect*) const override; |
| 44 |
bool asABlur(BlurRec*) const override; |
| 45 |
std::pair<sk_sp<SkImageFilter>, bool> asImageFilter(const SkMatrix& ctm, |
| 46 |
const SkPaint&) const override; |
| 47 |
|
| 48 |
SkScalar computeXformedSigma(const SkMatrix& ctm) const; |
| 49 |
SkBlurStyle blurStyle() const {return fBlurStyle;} |
| 50 |
SkScalar sigma() const {return fSigma;} |
| 51 |
bool ignoreXform() const { return !fRespectCTM; } |
| 52 |
|
| 53 |
private: |
| 54 |
FilterReturn filterRectsToNine(SkSpan<const SkRect>, |
| 55 |
const SkMatrix&, |
| 56 |
const SkIRect& clipBounds, |
| 57 |
std::optional<NinePatch>*, |
| 58 |
SkResourceCache*) const override; |
| 59 |
|
| 60 |
std::optional<NinePatch> filterRRectToNine(const SkRRect&, |
| 61 |
const SkMatrix&, |
| 62 |
const SkIRect& clipBounds, |
| 63 |
SkResourceCache*) const override; |
| 64 |
|
| 65 |
bool filterRectMask(SkMaskBuilder* dstM, |
| 66 |
const SkRect& r, |
| 67 |
const SkMatrix& matrix, |
| 68 |
SkIPoint* margin, |
| 69 |
SkMaskBuilder::CreateMode createMode) const; |
| 70 |
|
| 71 |
SK_FLATTENABLE_HOOKS(SkBlurMaskFilterImpl) |
| 72 |
|
| 73 |
SkScalar fSigma; |
| 74 |
SkBlurStyle fBlurStyle; |
| 75 |
bool fRespectCTM; |
| 76 |
|
| 77 |
SkBlurMaskFilterImpl(SkReadBuffer&); |
| 78 |
void flatten(SkWriteBuffer&) const override; |
| 79 |
|
| 80 |
friend class SkBlurMaskFilter; |
| 81 |
|
| 82 |
friend void sk_register_blur_maskfilter_createproc(); |
| 83 |
}; |
| 84 |
|
| 85 |
#endif |