Flutter Impeller
paint.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 #pragma once
6 
7 #include <memory>
8 
9 #include "flutter/fml/macros.h"
19 #include "impeller/entity/entity.h"
22 
23 namespace impeller {
24 
25 struct Paint {
26  using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
28  const Matrix& effect_transform,
29  Entity::RenderingMode rendering_mode)>;
30  using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
32  bool is_solid_color,
33  const Matrix& effect_transform)>;
34  using ColorSourceProc = std::function<std::shared_ptr<ColorSourceContents>()>;
35 
36  enum class Style {
37  kFill,
38  kStroke,
39  };
40 
44 
45  std::shared_ptr<FilterContents> CreateMaskBlur(
46  std::shared_ptr<ColorSourceContents> color_source_contents,
47  const std::shared_ptr<ColorFilter>& color_filter) const;
48 
49  std::shared_ptr<FilterContents> CreateMaskBlur(
50  const FilterInput::Ref& input,
51  bool is_solid_color) const;
52  };
53 
56  bool dither = false;
57 
64  bool invert_colors = false;
65 
66  std::shared_ptr<ImageFilter> image_filter;
67  std::shared_ptr<ColorFilter> color_filter;
68  std::optional<MaskBlurDescriptor> mask_blur_descriptor;
69 
70  /// @brief Wrap this paint's configured filters to the given contents.
71  /// @param[in] input The contents to wrap with paint's filters.
72  /// @return The filter-wrapped contents. If there are no filters that need
73  /// to be wrapped for the current paint configuration, the
74  /// original contents is returned.
75  std::shared_ptr<Contents> WithFilters(std::shared_ptr<Contents> input) const;
76 
77  /// @brief Wrap this paint's configured filters to the given contents of
78  /// subpass target.
79  /// @param[in] input The contents of subpass target to wrap with paint's
80  /// filters.
81  ///
82  /// @return The filter-wrapped contents. If there are no filters that need
83  /// to be wrapped for the current paint configuration, the
84  /// original contents is returned.
85  std::shared_ptr<Contents> WithFiltersForSubpassTarget(
86  std::shared_ptr<Contents> input,
87  const Matrix& effect_transform = Matrix()) const;
88 
89  std::shared_ptr<Contents> CreateContentsForEntity(const Path& path = {},
90  bool cover = false) const;
91 
92  std::shared_ptr<Contents> CreateContentsForGeometry(
93  std::shared_ptr<Geometry> geometry) const;
94 
95  /// @brief Whether this paint has a color filter that can apply opacity
96  bool HasColorFilter() const;
97 
98  std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
99  bool is_solid_color) const;
100 
101  std::shared_ptr<FilterContents> WithImageFilter(
102  const FilterInput::Variant& input,
103  const Matrix& effect_transform,
104  Entity::RenderingMode rendering_mode) const;
105 
106  private:
107  std::shared_ptr<Contents> WithColorFilter(
108  std::shared_ptr<Contents> input,
109  ColorFilterContents::AbsorbOpacity absorb_opacity =
111 
112  std::shared_ptr<Contents> WithInvertFilter(
113  std::shared_ptr<Contents> input) const;
114 };
115 
116 } // namespace impeller
impeller::Paint::stroke_cap
Cap stroke_cap
Definition: paint.h:59
impeller::BlendMode
BlendMode
Definition: color.h:57
impeller::Paint::WithMaskBlur
std::shared_ptr< Contents > WithMaskBlur(std::shared_ptr< Contents > input, bool is_solid_color) const
Definition: paint.cc:83
contents.h
impeller::Scalar
float Scalar
Definition: scalar.h:15
image_filter.h
impeller::Paint::Style::kStroke
@ kStroke
entity.h
impeller::Paint
Definition: paint.h:25
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:21
impeller::Color
Definition: color.h:122
impeller::Paint::ImageFilterProc
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)> ImageFilterProc
Definition: paint.h:29
impeller::Paint::CreateContentsForEntity
std::shared_ptr< Contents > CreateContentsForEntity(const Path &path={}, bool cover=false) const
Definition: paint.cc:17
impeller::Paint::MaskBlurDescriptor::sigma
Sigma sigma
Definition: paint.h:43
impeller::Paint::color
Color color
Definition: paint.h:54
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:42
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:31
impeller::ColorFilterContents::AbsorbOpacity::kNo
@ kNo
impeller::Paint::MaskBlurDescriptor::CreateMaskBlur
std::shared_ptr< FilterContents > CreateMaskBlur(std::shared_ptr< ColorSourceContents > color_source_contents, const std::shared_ptr< ColorFilter > &color_filter) const
Definition: paint.cc:151
impeller::Paint::MaskBlurDescriptor
Definition: paint.h:41
sweep_gradient_contents.h
impeller::Cap::kButt
@ kButt
impeller::Paint::color_source
ColorSource color_source
Definition: paint.h:55
impeller::Join::kMiter
@ kMiter
impeller::Paint::stroke_miter
Scalar stroke_miter
Definition: paint.h:61
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:67
filter_contents.h
impeller::ColorSource
Definition: color_source.h:27
color_source.h
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:54
impeller::Paint::style
Style style
Definition: paint.h:62
impeller::Paint::Style::kFill
@ kFill
impeller::Paint::MaskFilterProc
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, bool is_solid_color, const Matrix &effect_transform)> MaskFilterProc
Definition: paint.h:33
geometry.h
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:31
impeller::FilterInput::Variant
std::variant< std::shared_ptr< FilterContents >, std::shared_ptr< Contents >, std::shared_ptr< Texture >, Rect > Variant
Definition: filter_input.h:36
color_filter_contents.h
impeller::Paint::WithImageFilter
std::shared_ptr< FilterContents > WithImageFilter(const FilterInput::Variant &input, const Matrix &effect_transform, Entity::RenderingMode rendering_mode) const
Definition: paint.cc:92
impeller::Paint::ColorSourceProc
std::function< std::shared_ptr< ColorSourceContents >()> ColorSourceProc
Definition: paint.h:34
impeller::Join
Join
Definition: path.h:23
impeller::Color::Black
static constexpr Color Black()
Definition: color.h:256
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:64
impeller::Paint::CreateContentsForGeometry
std::shared_ptr< Contents > CreateContentsForGeometry(std::shared_ptr< Geometry > geometry) const
Definition: paint.cc:34
color.h
impeller::Paint::HasColorFilter
bool HasColorFilter() const
Whether this paint has a color filter that can apply opacity.
Definition: paint.cc:211
color_filter.h
impeller::Paint::Style
Style
Definition: paint.h:36
radial_gradient_contents.h
impeller::Entity::RenderingMode
RenderingMode
Definition: entity.h:26
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:13
impeller
Definition: aiks_context.cc:10
impeller::Paint::dither
bool dither
Definition: paint.h:56
impeller::Paint::mask_blur_descriptor
std::optional< MaskBlurDescriptor > mask_blur_descriptor
Definition: paint.h:68
impeller::Paint::stroke_width
Scalar stroke_width
Definition: paint.h:58
impeller::Paint::WithFilters
std::shared_ptr< Contents > WithFilters(std::shared_ptr< Contents > input) const
Wrap this paint's configured filters to the given contents.
Definition: paint.cc:59
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::Paint::WithFiltersForSubpassTarget
std::shared_ptr< Contents > WithFiltersForSubpassTarget(std::shared_ptr< Contents > input, const Matrix &effect_transform=Matrix()) const
Wrap this paint's configured filters to the given contents of subpass target.
Definition: paint.cc:71
impeller::Paint::blend_mode
BlendMode blend_mode
Definition: paint.h:63
impeller::Cap
Cap
Definition: path.h:17
impeller::Paint::image_filter
std::shared_ptr< ImageFilter > image_filter
Definition: paint.h:66
linear_gradient_contents.h
impeller::Paint::stroke_join
Join stroke_join
Definition: paint.h:60