Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
framebuffer_blend_contents.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
9
10namespace impeller {
11
13
15
17 blend_mode_ = blend_mode;
18}
19
21 std::shared_ptr<Contents> child_contents) {
22 child_contents_ = std::move(child_contents);
23}
24
25// |Contents|
27 const Entity& entity) const {
28 return child_contents_->GetCoverage(entity);
29}
30
32 const Entity& entity,
33 RenderPass& pass) const {
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();
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}
150
151} // namespace impeller
const char * options
bool ok() const
Definition status.h:71
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition entity.cc:50
float GetShaderClipDepth() const
Definition entity.cc:106
void SetChildContents(std::shared_ptr< Contents > child_contents)
std::optional< Rect > GetCoverage(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
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:33
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
ISize GetRenderTargetSize() const
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
FragmentShader_ FragmentShader
Definition pipeline.h:106
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition point.h:316
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
BlendMode
Definition color.h:59
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition contents.cc:20
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:294
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146