Flutter Impeller
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 
14 
15 namespace impeller {
16 
18 
20 
21 std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
22  const FilterInput::Vector& inputs,
23  const ContentContext& renderer,
24  const Entity& entity,
25  const Matrix& effect_transform,
26  const Rect& coverage,
27  const std::optional<Rect>& coverage_hint) const {
28  if (inputs.empty()) {
29  return std::nullopt;
30  }
31 
34 
35  auto input_snapshot =
36  inputs[0]->GetSnapshot("SrgbToLinear", renderer, entity);
37  if (!input_snapshot.has_value()) {
38  return std::nullopt;
39  }
40 
41  //----------------------------------------------------------------------------
42  /// Create AnonymousContents for rendering.
43  ///
44  RenderProc render_proc = [input_snapshot,
45  absorb_opacity = GetAbsorbOpacity()](
46  const ContentContext& renderer,
47  const Entity& entity, RenderPass& pass) -> bool {
48  Command cmd;
49  DEBUG_COMMAND_INFO(cmd, "sRGB to Linear Filter");
50  cmd.stencil_reference = entity.GetStencilDepth();
51 
52  auto options = OptionsFromPassAndEntity(pass, entity);
53  cmd.pipeline = renderer.GetSrgbToLinearFilterPipeline(options);
54 
55  auto size = input_snapshot->texture->GetSize();
56 
57  VertexBufferBuilder<VS::PerVertexData> vtx_builder;
58  vtx_builder.AddVertices({
59  {Point(0, 0)},
60  {Point(1, 0)},
61  {Point(1, 1)},
62  {Point(0, 0)},
63  {Point(1, 1)},
64  {Point(0, 1)},
65  });
66 
67  auto& host_buffer = pass.GetTransientsBuffer();
68  auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
69  cmd.BindVertices(vtx_buffer);
70 
71  VS::FrameInfo frame_info;
72  frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
73  entity.GetTransformation() * input_snapshot->transform *
75  frame_info.texture_sampler_y_coord_scale =
76  input_snapshot->texture->GetYCoordScale();
77 
78  FS::FragInfo frag_info;
79  frag_info.input_alpha =
81  ? input_snapshot->opacity
82  : 1.0f;
83 
84  auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
85  FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
86  FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
87  VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
88 
89  return pass.AddCommand(std::move(cmd));
90  };
91 
92  CoverageProc coverage_proc =
93  [coverage](const Entity& entity) -> std::optional<Rect> {
94  return coverage.TransformBounds(entity.GetTransformation());
95  };
96 
97  auto contents = AnonymousContents::Make(render_proc, coverage_proc);
98 
99  Entity sub_entity;
100  sub_entity.SetContents(std::move(contents));
101  sub_entity.SetStencilDepth(entity.GetStencilDepth());
102  sub_entity.SetBlendMode(entity.GetBlendMode());
103  return sub_entity;
104 }
105 
106 } // namespace impeller
impeller::SrgbToLinearFilterContents::~SrgbToLinearFilterContents
~SrgbToLinearFilterContents() override
DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:31
contents.h
point.h
sampler_library.h
impeller::Vector2
Point Vector2
Definition: point.h:310
impeller::RenderPipelineT::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:91
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:30
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
render_pass.h
impeller::ColorFilterContents::GetAbsorbOpacity
AbsorbOpacity GetAbsorbOpacity() const
Definition: color_filter_contents.cc:89
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:306
anonymous_contents.h
impeller::SrgbToLinearFilterContents::SrgbToLinearFilterContents
SrgbToLinearFilterContents()
content_context.h
impeller::Contents::RenderProc
std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> RenderProc
Definition: contents.h:48
vector.h
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:448
impeller::Contents::CoverageProc
std::function< std::optional< Rect >(const Entity &entity)> CoverageProc
Definition: contents.h:49
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
impeller::FilterInput::Vector
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:32
srgb_to_linear_filter_contents.h
impeller::RenderPipelineT::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:90
impeller
Definition: aiks_context.cc:10
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:103
impeller::AnonymousContents::Make
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)
Definition: anonymous_contents.cc:11