| Flutter Impeller |

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
5 #include "impeller/toolkit/interop/image_filter.h"
6
7 #include "flutter/display_list/effects/dl_image_filters.h"
8 #include "flutter/display_list/effects/dl_runtime_effect.h"
9 #include "flutter/impeller/display_list/dl_runtime_effect_impeller.h"
10 #include "impeller/base/validation.h"
11
12 namespace impeller::interop {
13
14 ImageFilter::ImageFilter(std::shared_ptr<flutter::DlImageFilter> filter)
15 : filter_(std::move(filter)) {}
16
17 ImageFilter::~ImageFilter() = default;
18
19 ScopedObject<ImageFilter> ImageFilter::MakeBlur(Scalar x_sigma,
20 Scalar y_sigma,
21 flutter::DlTileMode tile_mode) {
22 auto filter = flutter::DlBlurImageFilter::Make(x_sigma, y_sigma, tile_mode);
23 if (!filter) {
24 return nullptr;
25 }
26 return Create<ImageFilter>(std::move(filter));
27 }
28
29 ScopedObject<ImageFilter> ImageFilter::MakeDilate(Scalar x_radius,
30 Scalar y_radius) {
31 auto filter = flutter::DlDilateImageFilter::Make(x_radius, y_radius);
32 if (!filter) {
33 return nullptr;
34 }
35 return Create<ImageFilter>(std::move(filter));
36 }
37
38 ScopedObject<ImageFilter> ImageFilter::MakeErode(Scalar x_radius,
39 Scalar y_radius) {
40 auto filter = flutter::DlErodeImageFilter::Make(x_radius, y_radius);
41 if (!filter) {
42 return nullptr;
43 }
44 return Create<ImageFilter>(std::move(filter));
45 }
46
47 ScopedObject<ImageFilter> ImageFilter::MakeMatrix(
48 const Matrix& matrix,
49 flutter::DlImageSampling sampling) {
50 auto filter = flutter::DlMatrixImageFilter::Make(matrix, sampling);
51 if (!filter) {
52 return nullptr;
53 }
54 return Create<ImageFilter>(std::move(filter));
55 }
56
57 ScopedObject<ImageFilter> ImageFilter::MakeFragmentProgram(
58 const Context& context,
59 const FragmentProgram& program,
60 std::vector<std::shared_ptr<flutter::DlColorSource>> samplers,
61 std::shared_ptr<std::vector<uint8_t>> uniform_data) {
62 auto runtime_stage =
63 program.FindRuntimeStage(context.GetContext()->GetRuntimeStageBackend());
64 if (!runtime_stage) {
65 VALIDATION_LOG << "Could not find runtime stage for backend.";
66 return nullptr;
67 }
68 auto runtime_effect =
69 flutter::DlRuntimeEffectImpeller::Make(std::move(runtime_stage));
70 if (!runtime_effect) {
71 VALIDATION_LOG << "Could not make runtime effect.";
72 return nullptr;
73 }
74 auto filter =
75 flutter::DlRuntimeEffectImageFilter::Make(std::move(runtime_effect), //
76 std::move(samplers), //
77 std::move(uniform_data) //
78 );
79 if (!filter) {
80 VALIDATION_LOG << "Could not create runtime effect image filter.";
81 return nullptr;
82 }
83 return Create<ImageFilter>(std::move(filter));
84 }
85
86 ScopedObject<ImageFilter> ImageFilter::MakeCompose(const ImageFilter& outer,
87 const ImageFilter& inner) {
88 auto filter = flutter::DlComposeImageFilter::Make(outer.GetImageFilter(),
89 inner.GetImageFilter());
90 if (!filter) {
91 return nullptr;
92 }
93 return Create<ImageFilter>(std::move(filter));
94 }
95
96 const std::shared_ptr<flutter::DlImageFilter>& ImageFilter::GetImageFilter()
97 const {
98 return filter_;
99 }
100
101 } // namespace impeller::interop
flutter::DlRuntimeEffectImpeller::Make
static sk_sp< DlRuntimeEffect > Make(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
Definition: dl_runtime_effect_impeller.cc:14
impeller::interop::Context
Definition: context.h:16
impeller::interop::Context::GetContext
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:20
impeller::interop::FragmentProgram
Definition: fragment_program.h:17
impeller::interop::FragmentProgram::FindRuntimeStage
std::shared_ptr< RuntimeStage > FindRuntimeStage(RuntimeStageBackend backend) const
Definition: fragment_program.cc:53
impeller::interop::ImageFilter
Definition: image_filter.h:18
impeller::interop::ImageFilter::MakeDilate
static ScopedObject< ImageFilter > MakeDilate(Scalar x_radius, Scalar y_radius)
Definition: image_filter.cc:29
impeller::interop::ImageFilter::~ImageFilter
~ImageFilter() override
impeller::interop::ImageFilter::ImageFilter
ImageFilter(std::shared_ptr< flutter::DlImageFilter > filter)
Definition: image_filter.cc:14
impeller::interop::ImageFilter::MakeFragmentProgram
static ScopedObject< ImageFilter > MakeFragmentProgram(const Context &context, const FragmentProgram &program, std::vector< std::shared_ptr< flutter::DlColorSource >> samplers, std::shared_ptr< std::vector< uint8_t >> uniform_data)
Definition: image_filter.cc:57
impeller::interop::ImageFilter::MakeErode
static ScopedObject< ImageFilter > MakeErode(Scalar x_radius, Scalar y_radius)
Definition: image_filter.cc:38
impeller::interop::ImageFilter::GetImageFilter
const std::shared_ptr< flutter::DlImageFilter > & GetImageFilter() const
Definition: image_filter.cc:96
impeller::interop::ImageFilter::MakeCompose
static ScopedObject< ImageFilter > MakeCompose(const ImageFilter &outer, const ImageFilter &inner)
Definition: image_filter.cc:86
impeller::interop::ImageFilter::MakeBlur
static ScopedObject< ImageFilter > MakeBlur(Scalar x_sigma, Scalar y_sigma, flutter::DlTileMode tile_mode)
Definition: image_filter.cc:19
impeller::interop::ImageFilter::MakeMatrix
static ScopedObject< ImageFilter > MakeMatrix(const Matrix &matrix, flutter::DlImageSampling sampling)
Definition: image_filter.cc:47
impeller::interop::ScopedObject
Definition: object.h:67
dl_runtime_effect_impeller.h
impeller::interop
Definition: context_gles.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
std
Definition: comparable.h:95
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
image_filter.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91