Flutter Engine
The Flutter Engine
dl_mask_filter.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_DISPLAY_LIST_EFFECTS_DL_MASK_FILTER_H_
6#define FLUTTER_DISPLAY_LIST_EFFECTS_DL_MASK_FILTER_H_
7
8#include "flutter/display_list/dl_attributes.h"
9#include "flutter/fml/logging.h"
10
12
13namespace flutter {
14
15class DlBlurMaskFilter;
16
17// The DisplayList MaskFilter class. This class implements all of the
18// facilities and adheres to the design goals of the |DlAttribute| base
19// class.
20
21// An enumerated type for the supported MaskFilter operations.
22enum class DlMaskFilterType { kBlur };
23
24enum class DlBlurStyle {
25 kNormal, //!< fuzzy inside and outside
26 kSolid, //!< solid inside, fuzzy outside
27 kOuter, //!< nothing inside, fuzzy outside
28 kInner, //!< fuzzy inside, nothing outside
29};
30
31class DlMaskFilter : public DlAttribute<DlMaskFilter, DlMaskFilterType> {
32 public:
33 // Return a DlBlurMaskFilter pointer to this object iff it is a Blur
34 // type of MaskFilter, otherwise return nullptr.
35 virtual const DlBlurMaskFilter* asBlur() const { return nullptr; }
36};
37
38// The Blur type of MaskFilter which specifies modifying the
39// colors as if the color specified in the Blur filter is the
40// source color and the color drawn by the rendering operation
41// is the destination color. The mode parameter of the Blur
42// filter is then used to combine those colors.
43class DlBlurMaskFilter final : public DlMaskFilter {
44 public:
45 DlBlurMaskFilter(DlBlurStyle style, SkScalar sigma, bool respect_ctm = true)
46 : style_(style), sigma_(sigma), respect_ctm_(respect_ctm) {}
48 : DlBlurMaskFilter(filter.style_, filter.sigma_, filter.respect_ctm_) {}
49 explicit DlBlurMaskFilter(const DlBlurMaskFilter* filter)
50 : DlBlurMaskFilter(filter->style_, filter->sigma_, filter->respect_ctm_) {
51 }
52
53 static std::shared_ptr<DlMaskFilter> Make(DlBlurStyle style,
55 bool respect_ctm = true) {
56 if (std::isfinite(sigma) && sigma > 0) {
57 return std::make_shared<DlBlurMaskFilter>(style, sigma, respect_ctm);
58 }
59 return nullptr;
60 }
61
62 DlMaskFilterType type() const override { return DlMaskFilterType::kBlur; }
63 size_t size() const override { return sizeof(*this); }
64
65 std::shared_ptr<DlMaskFilter> shared() const override {
66 return std::make_shared<DlBlurMaskFilter>(this);
67 }
68
69 const DlBlurMaskFilter* asBlur() const override { return this; }
70
71 DlBlurStyle style() const { return style_; }
72 SkScalar sigma() const { return sigma_; }
73 bool respectCTM() const { return respect_ctm_; }
74
75 protected:
76 bool equals_(DlMaskFilter const& other) const override {
78 auto that = static_cast<DlBlurMaskFilter const*>(&other);
79 return style_ == that->style_ && sigma_ == that->sigma_ &&
80 respect_ctm_ == that->respect_ctm_;
81 }
82
83 private:
84 DlBlurStyle style_;
85 SkScalar sigma_;
86 // Added for backward compatibility with Flutter text shadow rendering which
87 // uses Skia blur filters with this flag set to false.
88 bool respect_ctm_;
89};
90
91} // namespace flutter
92
93#endif // FLUTTER_DISPLAY_LIST_EFFECTS_DL_MASK_FILTER_H_
@ kNormal
glyph outlines modified to improve constrast
virtual T type() const =0
DlBlurMaskFilter(const DlBlurMaskFilter *filter)
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
DlBlurMaskFilter(const DlBlurMaskFilter &filter)
bool equals_(DlMaskFilter const &other) const override
const DlBlurMaskFilter * asBlur() const override
DlMaskFilterType type() const override
DlBlurStyle style() const
std::shared_ptr< DlMaskFilter > shared() const override
SkScalar sigma() const
DlBlurMaskFilter(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
size_t size() const override
virtual const DlBlurMaskFilter * asBlur() const
float SkScalar
Definition: extension.cpp:12
#define FML_DCHECK(condition)
Definition: logging.h:103
@ kOuter
nothing inside, fuzzy outside
@ kInner
fuzzy inside, nothing outside
@ kBlur
Definition: paint.cc:59
SINT bool isfinite(const Vec< N, T > &v)
Definition: SkVx.h:1003