Flutter Engine
The Flutter Engine
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|
26std::optional<Rect> FramebufferBlendContents::GetCoverage(
27 const Entity& entity) const {
28 return child_contents_->GetCoverage(entity);
29}
30
31bool FramebufferBlendContents::Render(const ContentContext& renderer,
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
56 auto size = src_snapshot->texture->GetSize();
57 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
58 vtx_builder.AddVertices({
59 {Point(0, 0), Point(0, 0)},
60 {Point(size.width, 0), Point(1, 0)},
61 {Point(0, size.height), Point(0, 1)},
62 {Point(size.width, size.height), Point(1, 1)},
63 });
64
65 auto options = OptionsFromPass(pass);
66 options.blend_mode = BlendMode::kSource;
68
69 pass.SetCommandLabel("Framebuffer Advanced Blend Filter");
70 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
71
72 switch (blend_mode_) {
74 pass.SetPipeline(renderer.GetFramebufferBlendScreenPipeline(options));
75 break;
77 pass.SetPipeline(renderer.GetFramebufferBlendOverlayPipeline(options));
78 break;
80 pass.SetPipeline(renderer.GetFramebufferBlendDarkenPipeline(options));
81 break;
83 pass.SetPipeline(renderer.GetFramebufferBlendLightenPipeline(options));
84 break;
86 pass.SetPipeline(renderer.GetFramebufferBlendColorDodgePipeline(options));
87 break;
89 pass.SetPipeline(renderer.GetFramebufferBlendColorBurnPipeline(options));
90 break;
92 pass.SetPipeline(renderer.GetFramebufferBlendHardLightPipeline(options));
93 break;
95 pass.SetPipeline(renderer.GetFramebufferBlendSoftLightPipeline(options));
96 break;
98 pass.SetPipeline(renderer.GetFramebufferBlendDifferencePipeline(options));
99 break;
101 pass.SetPipeline(renderer.GetFramebufferBlendExclusionPipeline(options));
102 break;
104 pass.SetPipeline(renderer.GetFramebufferBlendMultiplyPipeline(options));
105 break;
106 case BlendMode::kHue:
107 pass.SetPipeline(renderer.GetFramebufferBlendHuePipeline(options));
108 break;
110 pass.SetPipeline(renderer.GetFramebufferBlendSaturationPipeline(options));
111 break;
113 pass.SetPipeline(renderer.GetFramebufferBlendColorPipeline(options));
114 break;
116 pass.SetPipeline(renderer.GetFramebufferBlendLuminosityPipeline(options));
117 break;
118 default:
119 return false;
120 }
121
122 VS::FrameInfo frame_info;
123 FS::FragInfo frag_info;
124
125 auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
126 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
127 src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
128 src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
129 }
130 const std::unique_ptr<const Sampler>& src_sampler =
131 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
132 src_sampler_descriptor);
133 FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);
134
135 frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(), pass,
136 src_snapshot->transform);
137 frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
138 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
139
140 frag_info.src_input_alpha = src_snapshot->opacity;
141 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
142
143 return pass.Draw().ok();
144}
145
146} // namespace impeller
const char * options
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:50
void SetChildContents(std::shared_ptr< Contents > child_contents)
FragmentShader_ FragmentShader
Definition: pipeline.h:107
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
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition: point.h:322
@ 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:19
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146