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