Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
srgb_to_linear_filter_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
13
14namespace impeller {
15
17
19
21 const FilterInput::Vector& inputs,
22 const ContentContext& renderer,
23 const Entity& entity,
24 const Matrix& effect_transform,
25 const Rect& coverage,
26 const std::optional<Rect>& coverage_hint) const {
27 if (inputs.empty()) {
28 return std::nullopt;
29 }
30
33
34 auto input_snapshot =
35 inputs[0]->GetSnapshot("SrgbToLinear", renderer, entity);
36 if (!input_snapshot.has_value()) {
37 return std::nullopt;
38 }
39
40 //----------------------------------------------------------------------------
41 /// Create AnonymousContents for rendering.
42 ///
43 RenderProc render_proc = [input_snapshot,
44 absorb_opacity = GetAbsorbOpacity()](
45 const ContentContext& renderer,
46 const Entity& entity, RenderPass& pass) -> bool {
47 pass.SetCommandLabel("sRGB to Linear Filter");
48
49 auto options = OptionsFromPassAndEntity(pass, entity);
51 pass.SetPipeline(renderer.GetSrgbToLinearFilterPipeline(options));
52
53 auto size = input_snapshot->texture->GetSize();
54
56 vtx_builder.AddVertices({
57 {Point(0, 0)},
58 {Point(1, 0)},
59 {Point(0, 1)},
60 {Point(1, 1)},
61 });
62
63 auto& host_buffer = renderer.GetTransientsBuffer();
64 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
65
66 VS::FrameInfo frame_info;
67 frame_info.mvp = Entity::GetShaderTransform(
68 entity.GetShaderClipDepth(), pass,
69 entity.GetTransform() * input_snapshot->transform *
71 frame_info.texture_sampler_y_coord_scale =
72 input_snapshot->texture->GetYCoordScale();
73
74 FS::FragInfo frag_info;
75 frag_info.input_alpha =
77 ? input_snapshot->opacity
78 : 1.0f;
79
80 const std::unique_ptr<const Sampler>& sampler =
81 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
82 FS::BindInputTexture(pass, input_snapshot->texture, sampler);
83 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
84 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
85
86 return pass.Draw().ok();
87 };
88
89 CoverageProc coverage_proc =
90 [coverage](const Entity& entity) -> std::optional<Rect> {
91 return coverage.TransformBounds(entity.GetTransform());
92 };
93
94 auto contents = AnonymousContents::Make(render_proc, coverage_proc);
95
96 Entity sub_entity;
97 sub_entity.SetContents(std::move(contents));
98 sub_entity.SetBlendMode(entity.GetBlendMode());
99 return sub_entity;
100}
101
102} // namespace impeller
const char * options
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)
std::function< std::optional< Rect >(const Entity &entity)> CoverageProc
Definition contents.h:50
std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> RenderProc
Definition contents.h:49
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition entity.cc:50
BlendMode GetBlendMode() const
Definition entity.cc:119
void SetContents(std::shared_ptr< Contents > contents)
Definition entity.cc:90
void SetBlendMode(BlendMode blend_mode)
Definition entity.cc:115
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
float GetShaderClipDepth() const
Definition entity.cc:106
std::vector< FilterInput::Ref > Vector
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:33
FragmentShader_ FragmentShader
Definition pipeline.h:106
std::optional< Entity > RenderFilter(const FilterInput::Vector &input_textures, const ContentContext &renderer, const Entity &entity, const Matrix &effect_transform, const Rect &coverage, const std::optional< Rect > &coverage_hint) const override
Converts zero or more filter inputs into a render instruction.
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition point.h:316
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition contents.cc:35
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakeScale(const Vector3 &s)
Definition matrix.h:104