Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
yuv_to_rgb_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
16// clang-format off
18 1.164, 1.164, 1.164, 0.0,
19 0.0, -0.392, 2.017, 0.0,
20 1.596, -0.813, 0.0, 0.0,
21 0.0, 0.0, 0.0, 1.0
22};
23
25 1.0, 1.0, 1.0, 0.0,
26 0.0, -0.344, 1.772, 0.0,
27 1.402, -0.714, 0.0, 0.0,
28 0.0, 0.0, 0.0, 1.0
29};
30// clang-format on
31
33
35
37 yuv_color_space_ = yuv_color_space;
38}
39
41 const FilterInput::Vector& inputs,
42 const ContentContext& renderer,
43 const Entity& entity,
44 const Matrix& effect_transform,
45 const Rect& coverage,
46 const std::optional<Rect>& coverage_hint) const {
47 if (inputs.size() < 2) {
48 return std::nullopt;
49 }
50
53
54 auto y_input_snapshot =
55 inputs[0]->GetSnapshot("YUVToRGB(Y)", renderer, entity);
56 auto uv_input_snapshot =
57 inputs[1]->GetSnapshot("YUVToRGB(UV)", renderer, entity);
58 if (!y_input_snapshot.has_value() || !uv_input_snapshot.has_value()) {
59 return std::nullopt;
60 }
61
62 if (y_input_snapshot->texture->GetTextureDescriptor().format !=
64 uv_input_snapshot->texture->GetTextureDescriptor().format !=
66 return std::nullopt;
67 }
68
69 //----------------------------------------------------------------------------
70 /// Create AnonymousContents for rendering.
71 ///
72 RenderProc render_proc = [y_input_snapshot, uv_input_snapshot,
73 yuv_color_space = yuv_color_space_](
74 const ContentContext& renderer,
75 const Entity& entity, RenderPass& pass) -> bool {
76 pass.SetCommandLabel("YUV to RGB Filter");
77
78 auto options = OptionsFromPassAndEntity(pass, entity);
80 pass.SetPipeline(renderer.GetYUVToRGBFilterPipeline(options));
81
82 auto size = y_input_snapshot->texture->GetSize();
83
85 vtx_builder.AddVertices({
86 {Point(0, 0)},
87 {Point(1, 0)},
88 {Point(0, 1)},
89 {Point(1, 1)},
90 });
91
92 auto& host_buffer = renderer.GetTransientsBuffer();
93 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
94
95 VS::FrameInfo frame_info;
96 frame_info.mvp = Entity::GetShaderTransform(
97 entity.GetShaderClipDepth(), pass,
98 entity.GetTransform() * y_input_snapshot->transform *
100 frame_info.texture_sampler_y_coord_scale =
101 y_input_snapshot->texture->GetYCoordScale();
102
103 FS::FragInfo frag_info;
104 frag_info.yuv_color_space = static_cast<Scalar>(yuv_color_space);
105 switch (yuv_color_space) {
107 frag_info.matrix = kMatrixBT601LimitedRange;
108 break;
110 frag_info.matrix = kMatrixBT601FullRange;
111 break;
112 }
113
114 const std::unique_ptr<const Sampler>& sampler =
115 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
116 FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
117 FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);
118
119 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
120 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
121
122 return pass.Draw().ok();
123 };
124
125 CoverageProc coverage_proc =
126 [coverage](const Entity& entity) -> std::optional<Rect> {
127 return coverage.TransformBounds(entity.GetTransform());
128 };
129
130 auto contents = AnonymousContents::Make(render_proc, coverage_proc);
131
132 Entity sub_entity;
133 sub_entity.SetContents(std::move(contents));
134 sub_entity.SetBlendMode(entity.GetBlendMode());
135 return sub_entity;
136}
137
139 const Matrix& effect_transform,
140 const Rect& output_limit) const {
141 return output_limit;
142}
143
144} // 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
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
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.
void SetYUVColorSpace(YUVColorSpace yuv_color_space)
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
YUVColorSpace
Definition color.h:55
constexpr Matrix kMatrixBT601LimitedRange
float Scalar
Definition scalar.h:18
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition point.h:316
constexpr Matrix kMatrixBT601FullRange
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