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,
26 0.0, -0.344, 1.772, 0.0,
27 1.402, -0.714, 0.0, 0.0,
37 yuv_color_space_ = yuv_color_space;
40 std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
44 const Matrix& effect_transform,
46 const std::optional<Rect>& coverage_hint)
const {
47 if (inputs.size() < 2) {
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()) {
62 if (y_input_snapshot->texture->GetTextureDescriptor().format !=
64 uv_input_snapshot->texture->GetTextureDescriptor().format !=
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 pass.SetStencilReference(entity.GetClipDepth());
81 pass.SetPipeline(renderer.GetYUVToRGBFilterPipeline(options));
83 auto size = y_input_snapshot->texture->GetSize();
85 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
86 vtx_builder.AddVertices({
93 auto& host_buffer = renderer.GetTransientsBuffer();
94 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
96 VS::FrameInfo frame_info;
98 entity.GetShaderClipDepth(), pass,
99 entity.GetTransform() * y_input_snapshot->transform *
101 frame_info.texture_sampler_y_coord_scale =
102 y_input_snapshot->texture->GetYCoordScale();
104 FS::FragInfo frag_info;
105 frag_info.yuv_color_space =
static_cast<Scalar>(yuv_color_space);
106 switch (yuv_color_space) {
115 const std::unique_ptr<const Sampler>& sampler =
116 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
117 FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
118 FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);
120 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
121 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
123 return pass.Draw().ok();
127 [coverage](
const Entity& entity) -> std::optional<Rect> {
134 sub_entity.SetContents(std::move(contents));
135 sub_entity.SetClipDepth(entity.GetClipDepth());
136 sub_entity.SetBlendMode(entity.GetBlendMode());
140 std::optional<Rect> YUVToRGBFilterContents::GetFilterSourceCoverage(
141 const Matrix& effect_transform,
142 const Rect& output_limit)
const {