Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
impeller::FramebufferBlendContents Class Referencefinal

#include <framebuffer_blend_contents.h>

Inheritance diagram for impeller::FramebufferBlendContents:
impeller::ColorSourceContents impeller::Contents

Public Member Functions

 FramebufferBlendContents ()
 
 ~FramebufferBlendContents () override
 
void SetBlendMode (BlendMode blend_mode)
 
void SetChildContents (std::shared_ptr< Contents > child_contents)
 
- Public Member Functions inherited from impeller::ColorSourceContents
 ColorSourceContents ()
 
 ~ColorSourceContents () override
 
void SetGeometry (std::shared_ptr< Geometry > geometry)
 Set the geometry that this contents will use to render.
 
const std::shared_ptr< Geometry > & GetGeometry () const
 Get the geometry that this contents will use to render.
 
void SetEffectTransform (Matrix matrix)
 Set the effect transform for this color source.
 
const MatrixGetInverseEffectTransform () const
 Set the inverted effect transform for this color source.
 
void SetOpacityFactor (Scalar opacity)
 Set the opacity factor for this color source.
 
Scalar GetOpacityFactor () const
 Get the opacity factor for this color source.
 
virtual bool IsSolidColor () const
 
bool CanInheritOpacity (const Entity &entity) const override
 Whether or not this contents can accept the opacity peephole optimization.
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
virtual void PopulateGlyphAtlas (const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
 Add any text data to the specified lazy atlas. The scale parameter must be used again later when drawing the text.
 
void SetCoverageHint (std::optional< Rect > coverage_hint)
 Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of GetCoverage().
 
const std::optional< Rect > & GetCoverageHint () const
 
virtual bool IsOpaque () const
 Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity.
 
virtual ClipCoverage GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
 Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer.
 
virtual std::optional< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Snapshot") const
 Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of GetCoverage(entity).
 
virtual bool ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) const
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 
virtual std::optional< ColorAsBackgroundColor (const Entity &entity, ISize target_size) const
 Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation.
 
virtual const FilterContentsAsFilter () const
 Cast to a filter. Returns nullptr if this Contents is not a filter.
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU.
 

Private Member Functions

std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 

Additional Inherited Members

- Public Types inherited from impeller::Contents
using ColorFilterProc = std::function< Color(Color)>
 
using RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
 
using CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>
 
- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 
- Protected Types inherited from impeller::ColorSourceContents
using BindFragmentCallback = std::function< bool(RenderPass &pass)>
 
using PipelineBuilderMethod = std::shared_ptr< Pipeline< PipelineDescriptor > >(impeller::ContentContext::*)(ContentContextOptions) const
 
using PipelineBuilderCallback = std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)>
 
- Protected Member Functions inherited from impeller::ColorSourceContents
template<typename VertexShaderT >
bool DrawGeometry (const ContentContext &renderer, const Entity &entity, RenderPass &pass, const PipelineBuilderCallback &pipeline_callback, typename VertexShaderT::FrameInfo frame_info, const BindFragmentCallback &bind_fragment_callback) const
 

Detailed Description

Definition at line 33 of file framebuffer_blend_contents.h.

Constructor & Destructor Documentation

◆ FramebufferBlendContents()

impeller::FramebufferBlendContents::FramebufferBlendContents ( )
default

◆ ~FramebufferBlendContents()

impeller::FramebufferBlendContents::~FramebufferBlendContents ( )
overridedefault

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::FramebufferBlendContents::GetCoverage ( const Entity entity) const
overrideprivatevirtual

Get the area of the render pass that will be affected when this contents is rendered.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Returns
The coverage rectangle. An std::nullopt result means that rendering this contents has no effect on the output color.

Reimplemented from impeller::ColorSourceContents.

Definition at line 26 of file framebuffer_blend_contents.cc.

27 {
28 return child_contents_->GetCoverage(entity);
29}

◆ Render()

bool impeller::FramebufferBlendContents::Render ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overrideprivatevirtual

Implements impeller::Contents.

Definition at line 31 of file framebuffer_blend_contents.cc.

33 {
34 if (!renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
35 return false;
36 }
37
40
41 auto& host_buffer = renderer.GetTransientsBuffer();
42
43 auto src_snapshot = child_contents_->RenderToSnapshot(
44 renderer, // renderer
45 entity, // entity
46 Rect::MakeSize(pass.GetRenderTargetSize()), // coverage_limit
47 std::nullopt, // sampler_descriptor
48 true, // msaa_enabled
49 /*mip_count=*/1,
50 "FramebufferBlendContents Snapshot"); // label
51
52 if (!src_snapshot.has_value()) {
53 return true;
54 }
55 auto coverage = src_snapshot->GetCoverage();
56 if (!coverage.has_value()) {
57 return true;
58 }
59 Rect src_coverage = coverage.value();
60
61 auto size = src_coverage.GetSize();
62 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
63 vtx_builder.AddVertices({
64 {Point(0, 0), Point(0, 0)},
65 {Point(size.width, 0), Point(1, 0)},
66 {Point(0, size.height), Point(0, 1)},
67 {Point(size.width, size.height), Point(1, 1)},
68 });
69
70 auto options = OptionsFromPass(pass);
71 options.blend_mode = BlendMode::kSource;
73
74 pass.SetCommandLabel("Framebuffer Advanced Blend Filter");
75 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
76
77 switch (blend_mode_) {
79 pass.SetPipeline(renderer.GetFramebufferBlendScreenPipeline(options));
80 break;
82 pass.SetPipeline(renderer.GetFramebufferBlendOverlayPipeline(options));
83 break;
85 pass.SetPipeline(renderer.GetFramebufferBlendDarkenPipeline(options));
86 break;
88 pass.SetPipeline(renderer.GetFramebufferBlendLightenPipeline(options));
89 break;
91 pass.SetPipeline(renderer.GetFramebufferBlendColorDodgePipeline(options));
92 break;
94 pass.SetPipeline(renderer.GetFramebufferBlendColorBurnPipeline(options));
95 break;
97 pass.SetPipeline(renderer.GetFramebufferBlendHardLightPipeline(options));
98 break;
100 pass.SetPipeline(renderer.GetFramebufferBlendSoftLightPipeline(options));
101 break;
103 pass.SetPipeline(renderer.GetFramebufferBlendDifferencePipeline(options));
104 break;
106 pass.SetPipeline(renderer.GetFramebufferBlendExclusionPipeline(options));
107 break;
109 pass.SetPipeline(renderer.GetFramebufferBlendMultiplyPipeline(options));
110 break;
111 case BlendMode::kHue:
112 pass.SetPipeline(renderer.GetFramebufferBlendHuePipeline(options));
113 break;
115 pass.SetPipeline(renderer.GetFramebufferBlendSaturationPipeline(options));
116 break;
118 pass.SetPipeline(renderer.GetFramebufferBlendColorPipeline(options));
119 break;
121 pass.SetPipeline(renderer.GetFramebufferBlendLuminosityPipeline(options));
122 break;
123 default:
124 return false;
125 }
126
127 VS::FrameInfo frame_info;
128 FS::FragInfo frag_info;
129
130 auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
131 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
132 src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
133 src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
134 }
135 const std::unique_ptr<const Sampler>& src_sampler =
136 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
137 src_sampler_descriptor);
138 FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);
139
140 frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(), pass,
141 src_snapshot->transform);
142 frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
143 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
144
145 frag_info.src_input_alpha = src_snapshot->opacity;
146 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
147
148 return pass.Draw().ok();
149}
const char * options
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition entity.cc:50
FragmentShader_ FragmentShader
Definition pipeline.h:106
it will be possible to load the file into Perfetto s trace viewer 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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
TRect< Scalar > Rect
Definition rect.h:746
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition point.h:316
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition contents.cc:20
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

◆ SetBlendMode()

void impeller::FramebufferBlendContents::SetBlendMode ( BlendMode  blend_mode)

Definition at line 16 of file framebuffer_blend_contents.cc.

16 {
17 blend_mode_ = blend_mode;
18}

◆ SetChildContents()

void impeller::FramebufferBlendContents::SetChildContents ( std::shared_ptr< Contents child_contents)

Definition at line 20 of file framebuffer_blend_contents.cc.

21 {
22 child_contents_ = std::move(child_contents);
23}

The documentation for this class was generated from the following files: