Flutter Engine
 
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 DlTileMode tile_mode;
76 bool is_dynamic;
77 if (tile_mode_index < 0) {
78 is_dynamic = true;
79 tile_mode = DlTileMode::kClamp;
80 } else {
81 is_dynamic = false;
82 tile_mode = static_cast<DlTileMode>(tile_mode_index);
83 }
84 filter_ = DlBlurImageFilter::Make(SafeNarrow(sigma_x), SafeNarrow(sigma_y),
85 tile_mode);
86 // If it was a NOP filter, don't bother processing dynamic substitutions
87 // (They'd fail the FML_DCHECK anyway)
88 is_dynamic_tile_mode_ = is_dynamic && filter_;
89}
90
91void ImageFilter::initDilate(double radius_x, double radius_y) {
92 is_dynamic_tile_mode_ = false;
93 filter_ =
95}
96
97void ImageFilter::initErode(double radius_x, double radius_y) {
98 is_dynamic_tile_mode_ = false;
99 filter_ =
100 DlErodeImageFilter::Make(SafeNarrow(radius_x), SafeNarrow(radius_y));
101}
102
103void ImageFilter::initMatrix(const tonic::Float64List& matrix4,
104 int filterQualityIndex) {
105 is_dynamic_tile_mode_ = false;
106 auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex);
107 filter_ = DlMatrixImageFilter::Make(ToDlMatrix(matrix4), sampling);
108}
109
111 FML_DCHECK(colorFilter);
112 is_dynamic_tile_mode_ = false;
113 filter_ = DlColorFilterImageFilter::Make(colorFilter->filter());
114}
115
117 FML_DCHECK(outer && inner);
118 is_dynamic_tile_mode_ = false;
120 inner->filter(DlTileMode::kClamp));
121}
122
124 FML_DCHECK(shader);
125 filter_ = shader->as_image_filter();
126}
127
129 return a->filter_ == b->filter_;
130}
131
132} // 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)
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 initComposeFilter(ImageFilter *outer, ImageFilter *inner)
void initColorFilter(ColorFilter *colorFilter)
void initErode(double radius_x, double radius_y)
void initBlur(double sigma_x, double sigma_y, int tile_mode_index)
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