Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
image_filter.cc
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
6
18
19namespace flutter {
20
22
23void ImageFilter::Create(Dart_Handle wrapper) {
25 auto res = fml::MakeRefCounted<ImageFilter>();
26 res->AssociateWithDartWrapper(wrapper);
27}
28
35
37 if (filterQualityIndex < 0) {
38 return kFilterQualities.front();
39 } else if (static_cast<size_t>(filterQualityIndex) >=
40 kFilterQualities.size()) {
41 return kFilterQualities.back();
42 } else {
43 return kFilterQualities[filterQualityIndex];
44 }
45}
46
48 if (filterQualityIndex <= 0) {
50 }
52}
53
54ImageFilter::ImageFilter() {}
55
57
58const std::shared_ptr<DlImageFilter> ImageFilter::filter(
59 DlTileMode mode) const {
60 if (is_dynamic_tile_mode_) {
61 FML_DCHECK(filter_.get() != nullptr);
62 const DlBlurImageFilter* blur_filter = filter_->asBlur();
63 FML_DCHECK(blur_filter != nullptr);
64 if (blur_filter->tile_mode() != mode) {
65 return DlBlurImageFilter::Make(blur_filter->sigma_x(),
66 blur_filter->sigma_y(), mode);
67 }
68 }
69 return filter_;
70}
71
72void ImageFilter::initBlur(double sigma_x,
73 double sigma_y,
74 int tile_mode_index,
75 bool bounded,
76 double bounds_left,
77 double bounds_top,
78 double bounds_right,
79 double bounds_bottom) {
80 DlTileMode tile_mode;
81 bool is_dynamic;
82 if (tile_mode_index < 0) {
83 is_dynamic = true;
84 tile_mode = DlTileMode::kClamp;
85 } else {
86 is_dynamic = false;
87 tile_mode = static_cast<DlTileMode>(tile_mode_index);
88 }
89 std::optional<DlRect> bounds;
90 if (bounded) {
91 bounds =
92 DlRect::MakeLTRB(SafeNarrow(bounds_left), SafeNarrow(bounds_top),
93 SafeNarrow(bounds_right), SafeNarrow(bounds_bottom));
94 }
95 filter_ = DlBlurImageFilter::Make(SafeNarrow(sigma_x), SafeNarrow(sigma_y),
96 tile_mode, bounds);
97 // If it was a NOP filter, don't bother processing dynamic substitutions
98 // (They'd fail the FML_DCHECK anyway)
99 is_dynamic_tile_mode_ = is_dynamic && filter_;
100}
101
102void ImageFilter::initDilate(double radius_x, double radius_y) {
103 is_dynamic_tile_mode_ = false;
104 filter_ =
105 DlDilateImageFilter::Make(SafeNarrow(radius_x), SafeNarrow(radius_y));
106}
107
108void ImageFilter::initErode(double radius_x, double radius_y) {
109 is_dynamic_tile_mode_ = false;
110 filter_ =
111 DlErodeImageFilter::Make(SafeNarrow(radius_x), SafeNarrow(radius_y));
112}
113
114void ImageFilter::initMatrix(const tonic::Float64List& matrix4,
115 int filterQualityIndex) {
116 is_dynamic_tile_mode_ = false;
117 auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex);
118 filter_ = DlMatrixImageFilter::Make(ToDlMatrix(matrix4), sampling);
119}
120
122 FML_DCHECK(colorFilter);
123 is_dynamic_tile_mode_ = false;
124 filter_ = DlColorFilterImageFilter::Make(colorFilter->filter());
125}
126
128 FML_DCHECK(outer && inner);
129 is_dynamic_tile_mode_ = false;
131 inner->filter(DlTileMode::kClamp));
132}
133
135 FML_DCHECK(shader);
136 filter_ = shader->as_image_filter();
137}
138
140 return a->filter_ == b->filter_;
141}
142
143} // namespace flutter
const std::shared_ptr< const DlColorFilter > filter() const
static std::shared_ptr< DlImageFilter > Make(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode, std::optional< DlRect > bounds=std::nullopt)
static std::shared_ptr< DlImageFilter > Make(const std::shared_ptr< const DlColorFilter > &filter)
static std::shared_ptr< DlImageFilter > Make(const std::shared_ptr< DlImageFilter > &outer, const std::shared_ptr< DlImageFilter > &inner)
static std::shared_ptr< DlImageFilter > Make(DlScalar radius_x, DlScalar radius_y)
static std::shared_ptr< DlImageFilter > Make(DlScalar radius_x, DlScalar radius_y)
static std::shared_ptr< DlImageFilter > Make(const DlMatrix &matrix, DlImageSampling sampling)
void initMatrix(const tonic::Float64List &matrix4, int filter_quality_index)
void initBlur(double sigma_x, double sigma_y, int tile_mode_index, bool bounded, double bounds_left, double bounds_top, double bounds_right, double bounds_bottom)
void initComposeFilter(ImageFilter *outer, ImageFilter *inner)
void initColorFilter(ColorFilter *colorFilter)
void initErode(double radius_x, double radius_y)
static void Create(Dart_Handle wrapper)
void initShader(ReusableFragmentShader *shader)
void initDilate(double radius_x, double radius_y)
static bool equals(ImageFilter *a, ImageFilter *b)
static DlImageSampling SamplingFromIndex(int filterQualityIndex)
static DlFilterMode FilterModeFromIndex(int index)
const std::shared_ptr< DlImageFilter > filter(DlTileMode mode) const
std::shared_ptr< DlImageFilter > as_image_filter() const
static void ThrowIfUIOperationsProhibited()
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
#define FML_DCHECK(condition)
Definition logging.h:122
static float SafeNarrow(double value)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
DlMatrix ToDlMatrix(const SkMatrix &matrix)
static const std::array< DlImageSampling, 4 > kFilterQualities
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129