Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
content_context.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
7#include <format>
8#include <memory>
9#include <utility>
10
11#include "fml/trace_event.h"
28
29namespace impeller {
30
31namespace {
32
33/// A generic version of `Variants` which mostly exists to reduce code size.
34class GenericVariants {
35 public:
36 void Set(const ContentContextOptions& options,
37 std::unique_ptr<GenericRenderPipelineHandle> pipeline) {
38 uint64_t p_key = options.ToKey();
39 for (const auto& [key, pipeline] : pipelines_) {
40 if (key == p_key) {
41 return;
42 }
43 }
44 pipelines_.push_back(std::make_pair(p_key, std::move(pipeline)));
45 }
46
47 void SetDefault(const ContentContextOptions& options,
48 std::unique_ptr<GenericRenderPipelineHandle> pipeline) {
49 default_options_ = options;
50 if (pipeline) {
51 Set(options, std::move(pipeline));
52 }
53 }
54
55 GenericRenderPipelineHandle* Get(const ContentContextOptions& options) const {
56 uint64_t p_key = options.ToKey();
57 for (const auto& [key, pipeline] : pipelines_) {
58 if (key == p_key) {
59 return pipeline.get();
60 }
61 }
62 return nullptr;
63 }
64
65 void SetDefaultDescriptor(std::optional<PipelineDescriptor> desc) {
66 desc_ = std::move(desc);
67 }
68
69 size_t GetPipelineCount() const { return pipelines_.size(); }
70
71 bool IsDefault(const ContentContextOptions& opts) {
72 return default_options_.has_value() &&
73 opts.ToKey() == default_options_.value().ToKey();
74 }
75
76 protected:
77 std::optional<PipelineDescriptor> desc_;
78 std::optional<ContentContextOptions> default_options_;
79 std::vector<std::pair<uint64_t, std::unique_ptr<GenericRenderPipelineHandle>>>
81};
82
83/// Holds multiple Pipelines associated with the same PipelineHandle types.
84///
85/// For example, it may have multiple
86/// RenderPipelineHandle<SolidFillVertexShader, SolidFillFragmentShader>
87/// instances for different blend modes. From them you can access the
88/// Pipeline.
89///
90/// See also:
91/// - impeller::ContentContextOptions - options from which variants are
92/// created.
93/// - impeller::Pipeline::CreateVariant
94/// - impeller::RenderPipelineHandle<> - The type of objects this typically
95/// contains.
96template <class PipelineHandleT>
97class Variants : public GenericVariants {
98 static_assert(
99 ShaderStageCompatibilityChecker<
100 typename PipelineHandleT::VertexShader,
101 typename PipelineHandleT::FragmentShader>::Check(),
102 "The output slots for the fragment shader don't have matches in the "
103 "vertex shader's output slots. This will result in a linker error.");
104
105 public:
106 Variants() = default;
107
108 void Set(const ContentContextOptions& options,
109 std::unique_ptr<PipelineHandleT> pipeline) {
110 GenericVariants::Set(options, std::move(pipeline));
111 }
112
113 void SetDefault(const ContentContextOptions& options,
114 std::unique_ptr<PipelineHandleT> pipeline) {
115 GenericVariants::SetDefault(options, std::move(pipeline));
116 }
117
118 void CreateDefault(const Context& context,
119 const ContentContextOptions& options,
120 const std::vector<Scalar>& constants = {}) {
121 std::optional<PipelineDescriptor> desc =
122 PipelineHandleT::Builder::MakeDefaultPipelineDescriptor(context,
123 constants);
124 if (!desc.has_value()) {
125 VALIDATION_LOG << "Failed to create default pipeline.";
126 return;
127 }
128 options.ApplyToPipelineDescriptor(*desc);
129 desc_ = desc;
130 if (context.GetFlags().lazy_shader_mode) {
131 SetDefault(options, nullptr);
132 } else {
133 SetDefault(options, std::make_unique<PipelineHandleT>(context, desc_,
134 /*async=*/true));
135 }
136 }
137
138 PipelineHandleT* Get(const ContentContextOptions& options) const {
139 return static_cast<PipelineHandleT*>(GenericVariants::Get(options));
140 }
141
142 PipelineHandleT* GetDefault(const Context& context) {
143 if (!default_options_.has_value()) {
144 return nullptr;
145 }
146 PipelineHandleT* result = Get(default_options_.value());
147 if (result != nullptr) {
148 return result;
149 }
150 SetDefault(default_options_.value(), std::make_unique<PipelineHandleT>(
151 context, desc_, /*async=*/false));
152 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
153 return Get(default_options_.value());
154 }
155
156 private:
157 Variants(const Variants&) = delete;
158
159 Variants& operator=(const Variants&) = delete;
160};
161
162template <class RenderPipelineHandleT>
163RenderPipelineHandleT* CreateIfNeeded(
164 const ContentContext* context,
165 Variants<RenderPipelineHandleT>& container,
166 ContentContextOptions opts) {
167 if (!context->IsValid()) {
168 return nullptr;
169 }
170
171 if (RenderPipelineHandleT* found = container.Get(opts)) {
172 return found;
173 }
174
175 RenderPipelineHandleT* default_handle =
176 container.GetDefault(*context->GetContext());
177 if (container.IsDefault(opts)) {
178 return default_handle;
179 }
180
181 // The default must always be initialized in the constructor.
182 FML_CHECK(default_handle != nullptr);
183
184 const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline =
185 default_handle->WaitAndGet();
186 if (!pipeline) {
187 return nullptr;
188 }
189
190 auto variant_future = pipeline->CreateVariant(
191 /*async=*/false, [&opts, variants_count = container.GetPipelineCount()](
192 PipelineDescriptor& desc) {
193 opts.ApplyToPipelineDescriptor(desc);
194 desc.SetLabel(std::format("{} V#{}", desc.GetLabel(), variants_count));
195 });
196 std::unique_ptr<RenderPipelineHandleT> variant =
197 std::make_unique<RenderPipelineHandleT>(std::move(variant_future));
198 container.Set(opts, std::move(variant));
199 return container.Get(opts);
200}
201
202template <class TypedPipeline>
203PipelineRef GetPipeline(const ContentContext* context,
204 Variants<TypedPipeline>& container,
205 ContentContextOptions opts) {
206 TypedPipeline* pipeline = CreateIfNeeded(context, container, opts);
207 if (!pipeline) {
208 return raw_ptr<Pipeline<PipelineDescriptor>>();
209 }
210 return raw_ptr(pipeline->WaitAndGet());
211}
212
213} // namespace
214
216 // clang-format off
217 Variants<BlendColorBurnPipeline> blend_colorburn;
218 Variants<BlendColorDodgePipeline> blend_colordodge;
219 Variants<BlendColorPipeline> blend_color;
220 Variants<BlendDarkenPipeline> blend_darken;
221 Variants<BlendDifferencePipeline> blend_difference;
222 Variants<BlendExclusionPipeline> blend_exclusion;
223 Variants<BlendHardLightPipeline> blend_hardlight;
224 Variants<BlendHuePipeline> blend_hue;
225 Variants<BlendLightenPipeline> blend_lighten;
226 Variants<BlendLuminosityPipeline> blend_luminosity;
227 Variants<BlendMultiplyPipeline> blend_multiply;
228 Variants<BlendOverlayPipeline> blend_overlay;
229 Variants<BlendSaturationPipeline> blend_saturation;
230 Variants<BlendScreenPipeline> blend_screen;
231 Variants<BlendSoftLightPipeline> blend_softlight;
232 Variants<BorderMaskBlurPipeline> border_mask_blur;
233 Variants<CirclePipeline> circle;
234 Variants<ClipPipeline> clip;
235 Variants<ColorMatrixColorFilterPipeline> color_matrix_color_filter;
236 Variants<ConicalGradientFillConicalPipeline> conical_gradient_fill;
237 Variants<ConicalGradientFillRadialPipeline> conical_gradient_fill_radial;
238 Variants<ConicalGradientFillStripPipeline> conical_gradient_fill_strip;
239 Variants<ConicalGradientFillStripRadialPipeline> conical_gradient_fill_strip_and_radial;
240 Variants<ConicalGradientSSBOFillPipeline> conical_gradient_ssbo_fill;
241 Variants<ConicalGradientSSBOFillPipeline> conical_gradient_ssbo_fill_radial;
242 Variants<ConicalGradientSSBOFillPipeline> conical_gradient_ssbo_fill_strip_and_radial;
243 Variants<ConicalGradientSSBOFillPipeline> conical_gradient_ssbo_fill_strip;
244 Variants<ConicalGradientUniformFillConicalPipeline> conical_gradient_uniform_fill;
245 Variants<ConicalGradientUniformFillRadialPipeline> conical_gradient_uniform_fill_radial;
246 Variants<ConicalGradientUniformFillStripPipeline> conical_gradient_uniform_fill_strip;
247 Variants<ConicalGradientUniformFillStripRadialPipeline> conical_gradient_uniform_fill_strip_and_radial;
248 Variants<FastGradientPipeline> fast_gradient;
249 Variants<FramebufferBlendColorBurnPipeline> framebuffer_blend_colorburn;
250 Variants<FramebufferBlendColorDodgePipeline> framebuffer_blend_colordodge;
251 Variants<FramebufferBlendColorPipeline> framebuffer_blend_color;
252 Variants<FramebufferBlendDarkenPipeline> framebuffer_blend_darken;
253 Variants<FramebufferBlendDifferencePipeline> framebuffer_blend_difference;
254 Variants<FramebufferBlendExclusionPipeline> framebuffer_blend_exclusion;
255 Variants<FramebufferBlendHardLightPipeline> framebuffer_blend_hardlight;
256 Variants<FramebufferBlendHuePipeline> framebuffer_blend_hue;
257 Variants<FramebufferBlendLightenPipeline> framebuffer_blend_lighten;
258 Variants<FramebufferBlendLuminosityPipeline> framebuffer_blend_luminosity;
259 Variants<FramebufferBlendMultiplyPipeline> framebuffer_blend_multiply;
260 Variants<FramebufferBlendOverlayPipeline> framebuffer_blend_overlay;
261 Variants<FramebufferBlendSaturationPipeline> framebuffer_blend_saturation;
262 Variants<FramebufferBlendScreenPipeline> framebuffer_blend_screen;
263 Variants<FramebufferBlendSoftLightPipeline> framebuffer_blend_softlight;
264 Variants<GaussianBlurPipeline> gaussian_blur;
265 Variants<GlyphAtlasPipeline> glyph_atlas;
266 Variants<LinePipeline> line;
267 Variants<LinearGradientFillPipeline> linear_gradient_fill;
268 Variants<LinearGradientSSBOFillPipeline> linear_gradient_ssbo_fill;
269 Variants<LinearGradientUniformFillPipeline> linear_gradient_uniform_fill;
270 Variants<LinearToSrgbFilterPipeline> linear_to_srgb_filter;
271 Variants<MorphologyFilterPipeline> morphology_filter;
272 Variants<PorterDuffBlendPipeline> clear_blend;
273 Variants<PorterDuffBlendPipeline> destination_a_top_blend;
274 Variants<PorterDuffBlendPipeline> destination_blend;
275 Variants<PorterDuffBlendPipeline> destination_in_blend;
276 Variants<PorterDuffBlendPipeline> destination_out_blend;
277 Variants<PorterDuffBlendPipeline> destination_over_blend;
278 Variants<PorterDuffBlendPipeline> modulate_blend;
279 Variants<PorterDuffBlendPipeline> plus_blend;
280 Variants<PorterDuffBlendPipeline> screen_blend;
281 Variants<PorterDuffBlendPipeline> source_a_top_blend;
282 Variants<PorterDuffBlendPipeline> source_blend;
283 Variants<PorterDuffBlendPipeline> source_in_blend;
284 Variants<PorterDuffBlendPipeline> source_out_blend;
285 Variants<PorterDuffBlendPipeline> source_over_blend;
286 Variants<PorterDuffBlendPipeline> xor_blend;
287 Variants<RadialGradientFillPipeline> radial_gradient_fill;
288 Variants<RadialGradientSSBOFillPipeline> radial_gradient_ssbo_fill;
289 Variants<RadialGradientUniformFillPipeline> radial_gradient_uniform_fill;
290 Variants<RRectBlurPipeline> rrect_blur;
291 Variants<RSuperellipseBlurPipeline> rsuperellipse_blur;
292 Variants<SolidFillPipeline> solid_fill;
293 Variants<SrgbToLinearFilterPipeline> srgb_to_linear_filter;
294 Variants<SweepGradientFillPipeline> sweep_gradient_fill;
295 Variants<SweepGradientSSBOFillPipeline> sweep_gradient_ssbo_fill;
296 Variants<SweepGradientUniformFillPipeline> sweep_gradient_uniform_fill;
297 Variants<TextureDownsamplePipeline> texture_downsample;
298 Variants<TexturePipeline> texture;
299 Variants<TextureStrictSrcPipeline> texture_strict_src;
300 Variants<TiledTexturePipeline> tiled_texture;
301 Variants<VerticesUber1Shader> vertices_uber_1_;
302 Variants<VerticesUber2Shader> vertices_uber_2_;
303 Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter;
304
305#ifdef IMPELLER_ENABLE_OPENGLES
306 Variants<TiledTextureExternalPipeline> tiled_texture_external;
307 Variants<TextureDownsampleGlesPipeline> texture_downsample_gles;
308 Variants<TiledTextureUvExternalPipeline> tiled_texture_uv_external;
309#endif // IMPELLER_ENABLE_OPENGLES
310 // clang-format on
311};
312
314 PipelineDescriptor& desc) const {
315 auto pipeline_blend = blend_mode;
317 VALIDATION_LOG << "Cannot use blend mode " << static_cast<int>(blend_mode)
318 << " as a pipeline blend.";
319 pipeline_blend = BlendMode::kSrcOver;
320 }
321
323
329
330 switch (pipeline_blend) {
339 } else {
344 }
345 break;
346 case BlendMode::kSrc:
347 color0.blending_enabled = false;
352 break;
353 case BlendMode::kDst:
359 break;
365 break;
371 break;
377 break;
383 break;
389 break;
395 break;
401 break;
407 break;
408 case BlendMode::kXor:
413 break;
414 case BlendMode::kPlus:
419 break;
425 break;
426 default:
428 }
429 desc.SetColorAttachmentDescriptor(0u, color0);
430
434 }
435
436 auto maybe_stencil = desc.GetFrontStencilAttachmentDescriptor();
437 auto maybe_depth = desc.GetDepthStencilAttachmentDescriptor();
438 FML_DCHECK(has_depth_stencil_attachments == maybe_depth.has_value())
439 << "Depth attachment doesn't match expected pipeline state. "
440 "has_depth_stencil_attachments="
442 FML_DCHECK(has_depth_stencil_attachments == maybe_stencil.has_value())
443 << "Stencil attachment doesn't match expected pipeline state. "
444 "has_depth_stencil_attachments="
446 if (maybe_stencil.has_value()) {
447 StencilAttachmentDescriptor front_stencil = maybe_stencil.value();
448 StencilAttachmentDescriptor back_stencil = front_stencil;
449
450 switch (stencil_mode) {
454 desc.SetStencilAttachmentDescriptors(front_stencil);
455 break;
457 // The stencil ref should be 0 on commands that use this mode.
462 desc.SetStencilAttachmentDescriptors(front_stencil, back_stencil);
463 break;
465 // The stencil ref should be 0 on commands that use this mode.
469 desc.SetStencilAttachmentDescriptors(front_stencil);
470 break;
472 // The stencil ref should be 0 on commands that use this mode.
474 front_stencil.depth_stencil_pass =
476 desc.SetStencilAttachmentDescriptors(front_stencil);
477 break;
479 // The stencil ref should be 0 on commands that use this mode.
482 desc.SetStencilAttachmentDescriptors(front_stencil);
483 break;
487 desc.SetStencilAttachmentDescriptors(front_stencil);
488 break;
491 front_stencil.depth_stencil_pass =
493 desc.SetStencilAttachmentDescriptors(front_stencil);
494 break;
495 }
496 }
497 if (maybe_depth.has_value()) {
498 DepthAttachmentDescriptor depth = maybe_depth.value();
502 }
503
506}
507
508std::array<std::vector<Scalar>, 15> GetPorterDuffSpecConstants(
509 bool supports_decal) {
510 Scalar x = supports_decal ? 1 : 0;
511 return {{
512 {x, 0, 0, 0, 0, 0}, // Clear
513 {x, 1, 0, 0, 0, 0}, // Source
514 {x, 0, 0, 1, 0, 0}, // Destination
515 {x, 1, 0, 1, -1, 0}, // SourceOver
516 {x, 1, -1, 1, 0, 0}, // DestinationOver
517 {x, 0, 1, 0, 0, 0}, // SourceIn
518 {x, 0, 0, 0, 1, 0}, // DestinationIn
519 {x, 1, -1, 0, 0, 0}, // SourceOut
520 {x, 0, 0, 1, -1, 0}, // DestinationOut
521 {x, 0, 1, 1, -1, 0}, // SourceATop
522 {x, 1, -1, 0, 1, 0}, // DestinationATop
523 {x, 1, -1, 1, -1, 0}, // Xor
524 {x, 1, 0, 1, 0, 0}, // Plus
525 {x, 0, 0, 0, 0, 1}, // Modulate
526 {x, 0, 0, 1, 0, -1}, // Screen
527 }};
528}
529
530template <typename PipelineT>
531static std::unique_ptr<PipelineT> CreateDefaultPipeline(
532 const Context& context) {
533 auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
534 if (!desc.has_value()) {
535 return nullptr;
536 }
537 // Apply default ContentContextOptions to the descriptor.
538 const auto default_color_format =
539 context.GetCapabilities()->GetDefaultColorFormat();
541 .primitive_type = PrimitiveType::kTriangleStrip,
542 .color_attachment_pixel_format = default_color_format}
543 .ApplyToPipelineDescriptor(*desc);
544 return std::make_unique<PipelineT>(context, desc);
545}
546
548 std::shared_ptr<Context> context,
549 std::shared_ptr<TypographerContext> typographer_context,
550 std::shared_ptr<RenderTargetAllocator> render_target_allocator)
551 : context_(std::move(context)),
552 lazy_glyph_atlas_(
553 std::make_shared<LazyGlyphAtlas>(std::move(typographer_context))),
554 pipelines_(new Pipelines()),
555 tessellator_(std::make_shared<Tessellator>(
556 context_->GetCapabilities()->Supports32BitPrimitiveIndices())),
557 render_target_cache_(render_target_allocator == nullptr
558 ? std::make_shared<RenderTargetCache>(
559 context_->GetResourceAllocator())
560 : std::move(render_target_allocator)),
561 data_host_buffer_(HostBuffer::Create(
562 context_->GetResourceAllocator(),
563 context_->GetIdleWaiter(),
564 context_->GetCapabilities()->GetMinimumUniformAlignment())),
565 text_shadow_cache_(std::make_unique<TextShadowCache>()) {
566 if (!context_ || !context_->IsValid()) {
567 return;
568 }
569
570 // On most backends, indexes and other data can be allocated into the same
571 // buffers. However, some backends (namely WebGL) require indexes used in
572 // indexed draws to be allocated separately from other data. For those
573 // backends, we allocate a separate host buffer just for indexes.
574 indexes_host_buffer_ =
575 context_->GetCapabilities()->NeedsPartitionedHostBuffer()
577 context_->GetResourceAllocator(), context_->GetIdleWaiter(),
578 context_->GetCapabilities()->GetMinimumUniformAlignment())
579 : data_host_buffer_;
580 {
584 desc.size = ISize{1, 1};
585 empty_texture_ = GetContext()->GetResourceAllocator()->CreateTexture(desc);
586
587 std::array<uint8_t, 4> data = Color::BlackTransparent().ToR8G8B8A8();
588 std::shared_ptr<CommandBuffer> cmd_buffer =
589 GetContext()->CreateCommandBuffer();
590 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
591 HostBuffer& data_host_buffer = GetTransientsDataBuffer();
592 BufferView buffer_view = data_host_buffer.Emplace(data);
593 blit_pass->AddCopy(buffer_view, empty_texture_);
594
595 if (!blit_pass->EncodeCommands() || !GetContext()
596 ->GetCommandQueue()
597 ->Submit({std::move(cmd_buffer)})
598 .ok()) {
599 VALIDATION_LOG << "Failed to create empty texture.";
600 }
601 }
602
603 auto options = ContentContextOptions{
605 .color_attachment_pixel_format =
606 context_->GetCapabilities()->GetDefaultColorFormat()};
607 auto options_trianglestrip = ContentContextOptions{
609 .primitive_type = PrimitiveType::kTriangleStrip,
610 .color_attachment_pixel_format =
611 context_->GetCapabilities()->GetDefaultColorFormat()};
612 auto options_no_msaa_no_depth_stencil = ContentContextOptions{
614 .primitive_type = PrimitiveType::kTriangleStrip,
615 .color_attachment_pixel_format =
616 context_->GetCapabilities()->GetDefaultColorFormat(),
617 .has_depth_stencil_attachments = false};
618 const auto supports_decal = static_cast<Scalar>(
619 context_->GetCapabilities()->SupportsDecalSamplerAddressMode());
620
621 // Futures for the following pipelines may block in case the first frame is
622 // rendered without the pipelines being ready. Put pipelines that are more
623 // likely to be used first.
624 {
625 pipelines_->glyph_atlas.CreateDefault(
626 *context_, options,
627 {static_cast<Scalar>(
628 GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
630 pipelines_->solid_fill.CreateDefault(*context_, options);
631 pipelines_->texture.CreateDefault(*context_, options);
632 pipelines_->fast_gradient.CreateDefault(*context_, options);
633 pipelines_->line.CreateDefault(*context_, options);
634 pipelines_->circle.CreateDefault(*context_, options);
635
636 if (context_->GetCapabilities()->SupportsSSBO()) {
637 pipelines_->linear_gradient_ssbo_fill.CreateDefault(*context_, options);
638 pipelines_->radial_gradient_ssbo_fill.CreateDefault(*context_, options);
639 pipelines_->conical_gradient_ssbo_fill.CreateDefault(*context_, options,
640 {3.0});
641 pipelines_->conical_gradient_ssbo_fill_radial.CreateDefault(
642 *context_, options, {1.0});
643 pipelines_->conical_gradient_ssbo_fill_strip.CreateDefault(
644 *context_, options, {2.0});
645 pipelines_->conical_gradient_ssbo_fill_strip_and_radial.CreateDefault(
646 *context_, options, {0.0});
647 pipelines_->sweep_gradient_ssbo_fill.CreateDefault(*context_, options);
648 } else {
649 pipelines_->linear_gradient_uniform_fill.CreateDefault(*context_,
650 options);
651 pipelines_->radial_gradient_uniform_fill.CreateDefault(*context_,
652 options);
653 pipelines_->conical_gradient_uniform_fill.CreateDefault(*context_,
654 options);
655 pipelines_->conical_gradient_uniform_fill_radial.CreateDefault(*context_,
656 options);
657 pipelines_->conical_gradient_uniform_fill_strip.CreateDefault(*context_,
658 options);
659 pipelines_->conical_gradient_uniform_fill_strip_and_radial.CreateDefault(
660 *context_, options);
661 pipelines_->sweep_gradient_uniform_fill.CreateDefault(*context_, options);
662
663 pipelines_->linear_gradient_fill.CreateDefault(*context_, options);
664 pipelines_->radial_gradient_fill.CreateDefault(*context_, options);
665 pipelines_->conical_gradient_fill.CreateDefault(*context_, options);
666 pipelines_->conical_gradient_fill_radial.CreateDefault(*context_,
667 options);
668 pipelines_->conical_gradient_fill_strip.CreateDefault(*context_, options);
669 pipelines_->conical_gradient_fill_strip_and_radial.CreateDefault(
670 *context_, options);
671 pipelines_->sweep_gradient_fill.CreateDefault(*context_, options);
672 }
673
674 /// Setup default clip pipeline.
675 auto clip_pipeline_descriptor =
676 ClipPipeline::Builder::MakeDefaultPipelineDescriptor(*context_);
677 if (!clip_pipeline_descriptor.has_value()) {
678 return;
679 }
682 .color_attachment_pixel_format =
683 context_->GetCapabilities()->GetDefaultColorFormat()}
684 .ApplyToPipelineDescriptor(*clip_pipeline_descriptor);
685 // Disable write to all color attachments.
686 auto clip_color_attachments =
687 clip_pipeline_descriptor->GetColorAttachmentDescriptors();
688 for (auto& color_attachment : clip_color_attachments) {
689 color_attachment.second.write_mask = ColorWriteMaskBits::kNone;
690 }
691 clip_pipeline_descriptor->SetColorAttachmentDescriptors(
692 std::move(clip_color_attachments));
693 if (GetContext()->GetFlags().lazy_shader_mode) {
694 pipelines_->clip.SetDefaultDescriptor(clip_pipeline_descriptor);
695 pipelines_->clip.SetDefault(options, nullptr);
696 } else {
697 pipelines_->clip.SetDefault(
698 options,
699 std::make_unique<ClipPipeline>(*context_, clip_pipeline_descriptor));
700 }
701 pipelines_->texture_downsample.CreateDefault(
702 *context_, options_no_msaa_no_depth_stencil);
703 pipelines_->rrect_blur.CreateDefault(*context_, options_trianglestrip);
704 pipelines_->rsuperellipse_blur.CreateDefault(*context_,
705 options_trianglestrip);
706 pipelines_->texture_strict_src.CreateDefault(*context_, options);
707 pipelines_->tiled_texture.CreateDefault(*context_, options,
708 {supports_decal});
709 pipelines_->gaussian_blur.CreateDefault(
710 *context_, options_no_msaa_no_depth_stencil, {supports_decal});
711 pipelines_->border_mask_blur.CreateDefault(*context_,
712 options_trianglestrip);
713 pipelines_->color_matrix_color_filter.CreateDefault(*context_,
714 options_trianglestrip);
715 pipelines_->vertices_uber_1_.CreateDefault(*context_, options,
716 {supports_decal});
717 pipelines_->vertices_uber_2_.CreateDefault(*context_, options,
718 {supports_decal});
719
720 const std::array<std::vector<Scalar>, 15> porter_duff_constants =
721 GetPorterDuffSpecConstants(supports_decal);
722 pipelines_->clear_blend.CreateDefault(*context_, options_trianglestrip,
723 porter_duff_constants[0]);
724 pipelines_->source_blend.CreateDefault(*context_, options_trianglestrip,
725 porter_duff_constants[1]);
726 pipelines_->destination_blend.CreateDefault(
727 *context_, options_trianglestrip, porter_duff_constants[2]);
728 pipelines_->source_over_blend.CreateDefault(
729 *context_, options_trianglestrip, porter_duff_constants[3]);
730 pipelines_->destination_over_blend.CreateDefault(
731 *context_, options_trianglestrip, porter_duff_constants[4]);
732 pipelines_->source_in_blend.CreateDefault(*context_, options_trianglestrip,
733 porter_duff_constants[5]);
734 pipelines_->destination_in_blend.CreateDefault(
735 *context_, options_trianglestrip, porter_duff_constants[6]);
736 pipelines_->source_out_blend.CreateDefault(*context_, options_trianglestrip,
737 porter_duff_constants[7]);
738 pipelines_->destination_out_blend.CreateDefault(
739 *context_, options_trianglestrip, porter_duff_constants[8]);
740 pipelines_->source_a_top_blend.CreateDefault(
741 *context_, options_trianglestrip, porter_duff_constants[9]);
742 pipelines_->destination_a_top_blend.CreateDefault(
743 *context_, options_trianglestrip, porter_duff_constants[10]);
744 pipelines_->xor_blend.CreateDefault(*context_, options_trianglestrip,
745 porter_duff_constants[11]);
746 pipelines_->plus_blend.CreateDefault(*context_, options_trianglestrip,
747 porter_duff_constants[12]);
748 pipelines_->modulate_blend.CreateDefault(*context_, options_trianglestrip,
749 porter_duff_constants[13]);
750 pipelines_->screen_blend.CreateDefault(*context_, options_trianglestrip,
751 porter_duff_constants[14]);
752 }
753
754 if (context_->GetCapabilities()->SupportsFramebufferFetch()) {
755 pipelines_->framebuffer_blend_color.CreateDefault(
756 *context_, options_trianglestrip,
757 {static_cast<Scalar>(BlendSelectValues::kColor), supports_decal});
758 pipelines_->framebuffer_blend_colorburn.CreateDefault(
759 *context_, options_trianglestrip,
760 {static_cast<Scalar>(BlendSelectValues::kColorBurn), supports_decal});
761 pipelines_->framebuffer_blend_colordodge.CreateDefault(
762 *context_, options_trianglestrip,
763 {static_cast<Scalar>(BlendSelectValues::kColorDodge), supports_decal});
764 pipelines_->framebuffer_blend_darken.CreateDefault(
765 *context_, options_trianglestrip,
766 {static_cast<Scalar>(BlendSelectValues::kDarken), supports_decal});
767 pipelines_->framebuffer_blend_difference.CreateDefault(
768 *context_, options_trianglestrip,
769 {static_cast<Scalar>(BlendSelectValues::kDifference), supports_decal});
770 pipelines_->framebuffer_blend_exclusion.CreateDefault(
771 *context_, options_trianglestrip,
772 {static_cast<Scalar>(BlendSelectValues::kExclusion), supports_decal});
773 pipelines_->framebuffer_blend_hardlight.CreateDefault(
774 *context_, options_trianglestrip,
775 {static_cast<Scalar>(BlendSelectValues::kHardLight), supports_decal});
776 pipelines_->framebuffer_blend_hue.CreateDefault(
777 *context_, options_trianglestrip,
778 {static_cast<Scalar>(BlendSelectValues::kHue), supports_decal});
779 pipelines_->framebuffer_blend_lighten.CreateDefault(
780 *context_, options_trianglestrip,
781 {static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
782 pipelines_->framebuffer_blend_luminosity.CreateDefault(
783 *context_, options_trianglestrip,
784 {static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});
785 pipelines_->framebuffer_blend_multiply.CreateDefault(
786 *context_, options_trianglestrip,
787 {static_cast<Scalar>(BlendSelectValues::kMultiply), supports_decal});
788 pipelines_->framebuffer_blend_overlay.CreateDefault(
789 *context_, options_trianglestrip,
790 {static_cast<Scalar>(BlendSelectValues::kOverlay), supports_decal});
791 pipelines_->framebuffer_blend_saturation.CreateDefault(
792 *context_, options_trianglestrip,
793 {static_cast<Scalar>(BlendSelectValues::kSaturation), supports_decal});
794 pipelines_->framebuffer_blend_screen.CreateDefault(
795 *context_, options_trianglestrip,
796 {static_cast<Scalar>(BlendSelectValues::kScreen), supports_decal});
797 pipelines_->framebuffer_blend_softlight.CreateDefault(
798 *context_, options_trianglestrip,
799 {static_cast<Scalar>(BlendSelectValues::kSoftLight), supports_decal});
800 } else {
801 pipelines_->blend_color.CreateDefault(
802 *context_, options_trianglestrip,
803 {static_cast<Scalar>(BlendSelectValues::kColor), supports_decal});
804 pipelines_->blend_colorburn.CreateDefault(
805 *context_, options_trianglestrip,
806 {static_cast<Scalar>(BlendSelectValues::kColorBurn), supports_decal});
807 pipelines_->blend_colordodge.CreateDefault(
808 *context_, options_trianglestrip,
809 {static_cast<Scalar>(BlendSelectValues::kColorDodge), supports_decal});
810 pipelines_->blend_darken.CreateDefault(
811 *context_, options_trianglestrip,
812 {static_cast<Scalar>(BlendSelectValues::kDarken), supports_decal});
813 pipelines_->blend_difference.CreateDefault(
814 *context_, options_trianglestrip,
815 {static_cast<Scalar>(BlendSelectValues::kDifference), supports_decal});
816 pipelines_->blend_exclusion.CreateDefault(
817 *context_, options_trianglestrip,
818 {static_cast<Scalar>(BlendSelectValues::kExclusion), supports_decal});
819 pipelines_->blend_hardlight.CreateDefault(
820 *context_, options_trianglestrip,
821 {static_cast<Scalar>(BlendSelectValues::kHardLight), supports_decal});
822 pipelines_->blend_hue.CreateDefault(
823 *context_, options_trianglestrip,
824 {static_cast<Scalar>(BlendSelectValues::kHue), supports_decal});
825 pipelines_->blend_lighten.CreateDefault(
826 *context_, options_trianglestrip,
827 {static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
828 pipelines_->blend_luminosity.CreateDefault(
829 *context_, options_trianglestrip,
830 {static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});
831 pipelines_->blend_multiply.CreateDefault(
832 *context_, options_trianglestrip,
833 {static_cast<Scalar>(BlendSelectValues::kMultiply), supports_decal});
834 pipelines_->blend_overlay.CreateDefault(
835 *context_, options_trianglestrip,
836 {static_cast<Scalar>(BlendSelectValues::kOverlay), supports_decal});
837 pipelines_->blend_saturation.CreateDefault(
838 *context_, options_trianglestrip,
839 {static_cast<Scalar>(BlendSelectValues::kSaturation), supports_decal});
840 pipelines_->blend_screen.CreateDefault(
841 *context_, options_trianglestrip,
842 {static_cast<Scalar>(BlendSelectValues::kScreen), supports_decal});
843 pipelines_->blend_softlight.CreateDefault(
844 *context_, options_trianglestrip,
845 {static_cast<Scalar>(BlendSelectValues::kSoftLight), supports_decal});
846 }
847
848 pipelines_->morphology_filter.CreateDefault(*context_, options_trianglestrip,
849 {supports_decal});
850 pipelines_->linear_to_srgb_filter.CreateDefault(*context_,
851 options_trianglestrip);
852 pipelines_->srgb_to_linear_filter.CreateDefault(*context_,
853 options_trianglestrip);
854 pipelines_->yuv_to_rgb_filter.CreateDefault(*context_, options_trianglestrip);
855
856#if defined(IMPELLER_ENABLE_OPENGLES)
857 if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) {
858#if !defined(FML_OS_MACOSX)
859 // GLES only shader that is unsupported on macOS.
860 pipelines_->tiled_texture_external.CreateDefault(*context_, options);
861 pipelines_->tiled_texture_uv_external.CreateDefault(*context_, options);
862#endif // !defined(FML_OS_MACOSX)
863 pipelines_->texture_downsample_gles.CreateDefault(*context_,
864 options_trianglestrip);
865 }
866#endif // IMPELLER_ENABLE_OPENGLES
867
868 is_valid_ = true;
869 InitializeCommonlyUsedShadersIfNeeded();
870}
871
873
875 return is_valid_;
876}
877
878std::shared_ptr<Texture> ContentContext::GetEmptyTexture() const {
879 return empty_texture_;
880}
881
883 std::string_view label,
884 ISize texture_size,
885 const std::shared_ptr<CommandBuffer>& command_buffer,
886 const SubpassCallback& subpass_callback,
887 bool msaa_enabled,
888 bool depth_stencil_enabled,
889 int32_t mip_count) const {
890 const std::shared_ptr<Context>& context = GetContext();
891 RenderTarget subpass_target;
892
893 std::optional<RenderTarget::AttachmentConfig> depth_stencil_config =
895 : std::optional<RenderTarget::AttachmentConfig>();
896
897 if (context->GetCapabilities()->SupportsOffscreenMSAA() && msaa_enabled) {
898 subpass_target = GetRenderTargetCache()->CreateOffscreenMSAA(
899 *context, texture_size,
900 /*mip_count=*/mip_count, label,
902 } else {
903 subpass_target = GetRenderTargetCache()->CreateOffscreen(
904 *context, texture_size,
905 /*mip_count=*/mip_count, label,
906 RenderTarget::kDefaultColorAttachmentConfig, depth_stencil_config);
907 }
908 return MakeSubpass(label, subpass_target, command_buffer, subpass_callback);
909}
910
912 std::string_view label,
913 const RenderTarget& subpass_target,
914 const std::shared_ptr<CommandBuffer>& command_buffer,
915 const SubpassCallback& subpass_callback) const {
916 const std::shared_ptr<Context>& context = GetContext();
917
918 auto subpass_texture = subpass_target.GetRenderTargetTexture();
919 if (!subpass_texture) {
921 }
922
923 auto sub_renderpass = command_buffer->CreateRenderPass(subpass_target);
924 if (!sub_renderpass) {
926 }
927 sub_renderpass->SetLabel(label);
928
929 if (!subpass_callback(*this, *sub_renderpass)) {
931 }
932
933 if (!sub_renderpass->EncodeCommands()) {
935 }
936
937 const std::shared_ptr<Texture>& target_texture =
938 subpass_target.GetRenderTargetTexture();
939 if (target_texture->GetMipCount() > 1) {
940 fml::Status mipmap_status =
941 AddMipmapGeneration(command_buffer, context, target_texture);
942 if (!mipmap_status.ok()) {
943 return mipmap_status;
944 }
945 }
946
947 return subpass_target;
948}
949
951 return *tessellator_;
952}
953
954std::shared_ptr<Context> ContentContext::GetContext() const {
955 return context_;
956}
957
959 return *context_->GetCapabilities();
960}
961
963 const std::string& unique_entrypoint_name,
964 const ContentContextOptions& options,
965 const std::function<std::shared_ptr<Pipeline<PipelineDescriptor>>()>&
966 create_callback) const {
967 RuntimeEffectPipelineKey key{unique_entrypoint_name, options};
968 auto it = runtime_effect_pipelines_.find(key);
969 if (it == runtime_effect_pipelines_.end()) {
970 it = runtime_effect_pipelines_.insert(it, {key, create_callback()});
971 }
972 return raw_ptr(it->second);
973}
974
976 const std::string& unique_entrypoint_name) const {
977#ifdef IMPELLER_DEBUG
978 // destroying in-use pipleines is a validation error.
979 const auto& idle_waiter = GetContext()->GetIdleWaiter();
980 if (idle_waiter) {
981 idle_waiter->WaitIdle();
982 }
983#endif // IMPELLER_DEBUG
984 for (auto it = runtime_effect_pipelines_.begin();
985 it != runtime_effect_pipelines_.end();) {
986 if (it->first.unique_entrypoint_name == unique_entrypoint_name) {
987 it = runtime_effect_pipelines_.erase(it);
988 } else {
989 it++;
990 }
991 }
992}
993
995 data_host_buffer_->Reset();
996
997 // We should only reset the indexes host buffer if it is actually different
998 // from the data host buffer. Otherwise we'll end up resetting the same host
999 // buffer twice.
1000 if (data_host_buffer_ != indexes_host_buffer_) {
1001 indexes_host_buffer_->Reset();
1002 }
1003}
1004
1005void ContentContext::InitializeCommonlyUsedShadersIfNeeded() const {
1006 if (GetContext()->GetFlags().lazy_shader_mode) {
1007 return;
1008 }
1009 GetContext()->InitializeCommonlyUsedShadersIfNeeded();
1010}
1011
1013 ContentContextOptions opts) const {
1014 return GetPipeline(this, pipelines_->fast_gradient, opts);
1015}
1016
1018 ContentContextOptions opts) const {
1019 return GetPipeline(this, pipelines_->linear_gradient_fill, opts);
1020}
1021
1023 ContentContextOptions opts) const {
1024 return GetPipeline(this, pipelines_->linear_gradient_uniform_fill, opts);
1025}
1026
1028 ContentContextOptions opts) const {
1029 return GetPipeline(this, pipelines_->radial_gradient_uniform_fill, opts);
1030}
1031
1033 ContentContextOptions opts) const {
1034 return GetPipeline(this, pipelines_->sweep_gradient_uniform_fill, opts);
1035}
1036
1038 ContentContextOptions opts) const {
1039 FML_DCHECK(GetDeviceCapabilities().SupportsSSBO());
1040 return GetPipeline(this, pipelines_->linear_gradient_ssbo_fill, opts);
1041}
1042
1044 ContentContextOptions opts) const {
1045 FML_DCHECK(GetDeviceCapabilities().SupportsSSBO());
1046 return GetPipeline(this, pipelines_->radial_gradient_ssbo_fill, opts);
1047}
1048
1051 ConicalKind kind) const {
1052 switch (kind) {
1054 return GetPipeline(this, pipelines_->conical_gradient_uniform_fill, opts);
1056 return GetPipeline(this, pipelines_->conical_gradient_uniform_fill_radial,
1057 opts);
1059 return GetPipeline(this, pipelines_->conical_gradient_uniform_fill_strip,
1060 opts);
1062 return GetPipeline(
1063 this, pipelines_->conical_gradient_uniform_fill_strip_and_radial,
1064 opts);
1065 }
1066}
1067
1070 ConicalKind kind) const {
1071 FML_DCHECK(GetDeviceCapabilities().SupportsSSBO());
1072 switch (kind) {
1074 return GetPipeline(this, pipelines_->conical_gradient_ssbo_fill, opts);
1076 return GetPipeline(this, pipelines_->conical_gradient_ssbo_fill_radial,
1077 opts);
1079 return GetPipeline(this, pipelines_->conical_gradient_ssbo_fill_strip,
1080 opts);
1082 return GetPipeline(
1083 this, pipelines_->conical_gradient_ssbo_fill_strip_and_radial, opts);
1084 }
1085}
1086
1088 ContentContextOptions opts) const {
1089 FML_DCHECK(GetDeviceCapabilities().SupportsSSBO());
1090 return GetPipeline(this, pipelines_->sweep_gradient_ssbo_fill, opts);
1091}
1092
1094 ContentContextOptions opts) const {
1095 return GetPipeline(this, pipelines_->radial_gradient_fill, opts);
1096}
1097
1100 ConicalKind kind) const {
1101 switch (kind) {
1103 return GetPipeline(this, pipelines_->conical_gradient_fill, opts);
1105 return GetPipeline(this, pipelines_->conical_gradient_fill_radial, opts);
1107 return GetPipeline(this, pipelines_->conical_gradient_fill_strip, opts);
1109 return GetPipeline(
1110 this, pipelines_->conical_gradient_fill_strip_and_radial, opts);
1111 }
1112}
1113
1115 ContentContextOptions opts) const {
1116 return GetPipeline(this, pipelines_->rrect_blur, opts);
1117}
1118
1120 ContentContextOptions opts) const {
1121 return GetPipeline(this, pipelines_->rsuperellipse_blur, opts);
1122}
1123
1125 ContentContextOptions opts) const {
1126 return GetPipeline(this, pipelines_->sweep_gradient_fill, opts);
1127}
1128
1130 ContentContextOptions opts) const {
1131 return GetPipeline(this, pipelines_->solid_fill, opts);
1132}
1133
1135 ContentContextOptions opts) const {
1136 return GetPipeline(this, pipelines_->texture, opts);
1137}
1138
1140 ContentContextOptions opts) const {
1141 return GetPipeline(this, pipelines_->texture_strict_src, opts);
1142}
1143
1145 ContentContextOptions opts) const {
1146 return GetPipeline(this, pipelines_->tiled_texture, opts);
1147}
1148
1150 ContentContextOptions opts) const {
1151 return GetPipeline(this, pipelines_->gaussian_blur, opts);
1152}
1153
1155 ContentContextOptions opts) const {
1156 return GetPipeline(this, pipelines_->border_mask_blur, opts);
1157}
1158
1160 ContentContextOptions opts) const {
1161 return GetPipeline(this, pipelines_->morphology_filter, opts);
1162}
1163
1165 ContentContextOptions opts) const {
1166 return GetPipeline(this, pipelines_->color_matrix_color_filter, opts);
1167}
1168
1170 ContentContextOptions opts) const {
1171 return GetPipeline(this, pipelines_->linear_to_srgb_filter, opts);
1172}
1173
1175 ContentContextOptions opts) const {
1176 return GetPipeline(this, pipelines_->srgb_to_linear_filter, opts);
1177}
1178
1180 return GetPipeline(this, pipelines_->clip, opts);
1181}
1182
1184 ContentContextOptions opts) const {
1185 return GetPipeline(this, pipelines_->glyph_atlas, opts);
1186}
1187
1189 ContentContextOptions opts) const {
1190 return GetPipeline(this, pipelines_->yuv_to_rgb_filter, opts);
1191}
1192
1194 BlendMode mode,
1195 ContentContextOptions opts) const {
1196 switch (mode) {
1197 case BlendMode::kClear:
1198 return GetClearBlendPipeline(opts);
1199 case BlendMode::kSrc:
1200 return GetSourceBlendPipeline(opts);
1201 case BlendMode::kDst:
1202 return GetDestinationBlendPipeline(opts);
1204 return GetSourceOverBlendPipeline(opts);
1207 case BlendMode::kSrcIn:
1208 return GetSourceInBlendPipeline(opts);
1209 case BlendMode::kDstIn:
1210 return GetDestinationInBlendPipeline(opts);
1211 case BlendMode::kSrcOut:
1212 return GetSourceOutBlendPipeline(opts);
1213 case BlendMode::kDstOut:
1214 return GetDestinationOutBlendPipeline(opts);
1216 return GetSourceATopBlendPipeline(opts);
1219 case BlendMode::kXor:
1220 return GetXorBlendPipeline(opts);
1221 case BlendMode::kPlus:
1222 return GetPlusBlendPipeline(opts);
1224 return GetModulateBlendPipeline(opts);
1225 case BlendMode::kScreen:
1226 return GetScreenBlendPipeline(opts);
1228 case BlendMode::kDarken:
1237 case BlendMode::kHue:
1239 case BlendMode::kColor:
1241 VALIDATION_LOG << "Invalid porter duff blend mode "
1242 << BlendModeToString(mode);
1243 return GetClearBlendPipeline(opts);
1244 break;
1245 }
1246}
1247
1249 ContentContextOptions opts) const {
1250 return GetPipeline(this, pipelines_->clear_blend, opts);
1251}
1252
1254 ContentContextOptions opts) const {
1255 return GetPipeline(this, pipelines_->source_blend, opts);
1256}
1257
1259 ContentContextOptions opts) const {
1260 return GetPipeline(this, pipelines_->destination_blend, opts);
1261}
1262
1264 ContentContextOptions opts) const {
1265 return GetPipeline(this, pipelines_->source_over_blend, opts);
1266}
1267
1269 ContentContextOptions opts) const {
1270 return GetPipeline(this, pipelines_->destination_over_blend, opts);
1271}
1272
1274 ContentContextOptions opts) const {
1275 return GetPipeline(this, pipelines_->source_in_blend, opts);
1276}
1277
1279 ContentContextOptions opts) const {
1280 return GetPipeline(this, pipelines_->destination_in_blend, opts);
1281}
1282
1284 ContentContextOptions opts) const {
1285 return GetPipeline(this, pipelines_->source_out_blend, opts);
1286}
1287
1289 ContentContextOptions opts) const {
1290 return GetPipeline(this, pipelines_->destination_out_blend, opts);
1291}
1292
1294 ContentContextOptions opts) const {
1295 return GetPipeline(this, pipelines_->source_a_top_blend, opts);
1296}
1297
1299 ContentContextOptions opts) const {
1300 return GetPipeline(this, pipelines_->destination_a_top_blend, opts);
1301}
1302
1304 ContentContextOptions opts) const {
1305 return GetPipeline(this, pipelines_->xor_blend, opts);
1306}
1307
1309 ContentContextOptions opts) const {
1310 return GetPipeline(this, pipelines_->plus_blend, opts);
1311}
1312
1314 ContentContextOptions opts) const {
1315 return GetPipeline(this, pipelines_->modulate_blend, opts);
1316}
1317
1319 ContentContextOptions opts) const {
1320 return GetPipeline(this, pipelines_->screen_blend, opts);
1321}
1322
1324 ContentContextOptions opts) const {
1325 return GetPipeline(this, pipelines_->blend_color, opts);
1326}
1327
1329 ContentContextOptions opts) const {
1330 return GetPipeline(this, pipelines_->blend_colorburn, opts);
1331}
1332
1334 ContentContextOptions opts) const {
1335 return GetPipeline(this, pipelines_->blend_colordodge, opts);
1336}
1337
1339 ContentContextOptions opts) const {
1340 return GetPipeline(this, pipelines_->blend_darken, opts);
1341}
1342
1344 ContentContextOptions opts) const {
1345 return GetPipeline(this, pipelines_->blend_difference, opts);
1346}
1347
1349 ContentContextOptions opts) const {
1350 return GetPipeline(this, pipelines_->blend_exclusion, opts);
1351}
1352
1354 ContentContextOptions opts) const {
1355 return GetPipeline(this, pipelines_->blend_hardlight, opts);
1356}
1357
1359 ContentContextOptions opts) const {
1360 return GetPipeline(this, pipelines_->blend_hue, opts);
1361}
1362
1364 ContentContextOptions opts) const {
1365 return GetPipeline(this, pipelines_->blend_lighten, opts);
1366}
1367
1369 ContentContextOptions opts) const {
1370 return GetPipeline(this, pipelines_->blend_luminosity, opts);
1371}
1372
1374 ContentContextOptions opts) const {
1375 return GetPipeline(this, pipelines_->blend_multiply, opts);
1376}
1377
1379 ContentContextOptions opts) const {
1380 return GetPipeline(this, pipelines_->blend_overlay, opts);
1381}
1382
1384 ContentContextOptions opts) const {
1385 return GetPipeline(this, pipelines_->blend_saturation, opts);
1386}
1387
1389 ContentContextOptions opts) const {
1390 return GetPipeline(this, pipelines_->blend_screen, opts);
1391}
1392
1394 ContentContextOptions opts) const {
1395 return GetPipeline(this, pipelines_->blend_softlight, opts);
1396}
1397
1399 ContentContextOptions opts) const {
1400 return GetPipeline(this, pipelines_->texture_downsample, opts);
1401}
1402
1404 ContentContextOptions opts) const {
1405 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1406 return GetPipeline(this, pipelines_->framebuffer_blend_color, opts);
1407}
1408
1410 ContentContextOptions opts) const {
1411 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1412 return GetPipeline(this, pipelines_->framebuffer_blend_colorburn, opts);
1413}
1414
1416 ContentContextOptions opts) const {
1417 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1418 return GetPipeline(this, pipelines_->framebuffer_blend_colordodge, opts);
1419}
1420
1422 ContentContextOptions opts) const {
1423 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1424 return GetPipeline(this, pipelines_->framebuffer_blend_darken, opts);
1425}
1426
1428 ContentContextOptions opts) const {
1429 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1430 return GetPipeline(this, pipelines_->framebuffer_blend_difference, opts);
1431}
1432
1434 ContentContextOptions opts) const {
1435 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1436 return GetPipeline(this, pipelines_->framebuffer_blend_exclusion, opts);
1437}
1438
1440 ContentContextOptions opts) const {
1441 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1442 return GetPipeline(this, pipelines_->framebuffer_blend_hardlight, opts);
1443}
1444
1446 ContentContextOptions opts) const {
1447 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1448 return GetPipeline(this, pipelines_->framebuffer_blend_hue, opts);
1449}
1450
1452 ContentContextOptions opts) const {
1453 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1454 return GetPipeline(this, pipelines_->framebuffer_blend_lighten, opts);
1455}
1456
1458 ContentContextOptions opts) const {
1459 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1460 return GetPipeline(this, pipelines_->framebuffer_blend_luminosity, opts);
1461}
1462
1464 ContentContextOptions opts) const {
1465 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1466 return GetPipeline(this, pipelines_->framebuffer_blend_multiply, opts);
1467}
1468
1470 ContentContextOptions opts) const {
1471 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1472 return GetPipeline(this, pipelines_->framebuffer_blend_overlay, opts);
1473}
1474
1476 ContentContextOptions opts) const {
1477 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1478 return GetPipeline(this, pipelines_->framebuffer_blend_saturation, opts);
1479}
1480
1482 ContentContextOptions opts) const {
1483 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1484 return GetPipeline(this, pipelines_->framebuffer_blend_screen, opts);
1485}
1486
1488 ContentContextOptions opts) const {
1489 FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
1490 return GetPipeline(this, pipelines_->framebuffer_blend_softlight, opts);
1491}
1492
1494 BlendMode blend_mode,
1495 ContentContextOptions opts) const {
1496 if (blend_mode <= BlendMode::kHardLight) {
1497 return GetPipeline(this, pipelines_->vertices_uber_1_, opts);
1498 } else {
1499 return GetPipeline(this, pipelines_->vertices_uber_2_, opts);
1500 }
1501}
1502
1504 ContentContextOptions opts) const {
1505 return GetPipeline(this, pipelines_->circle, opts);
1506}
1507
1509 return GetPipeline(this, pipelines_->line, opts);
1510}
1511
1512#ifdef IMPELLER_ENABLE_OPENGLES
1513PipelineRef ContentContext::GetDownsampleTextureGlesPipeline(
1514 ContentContextOptions opts) const {
1515 return GetPipeline(this, pipelines_->texture_downsample_gles, opts);
1516}
1517
1518PipelineRef ContentContext::GetTiledTextureExternalPipeline(
1519 ContentContextOptions opts) const {
1521 return GetPipeline(this, pipelines_->tiled_texture_external, opts);
1522}
1523
1524PipelineRef ContentContext::GetTiledTextureUvExternalPipeline(
1525 ContentContextOptions opts) const {
1527 return GetPipeline(this, pipelines_->tiled_texture_uv_external, opts);
1528}
1529#endif // IMPELLER_ENABLE_OPENGLES
1530
1531} // namespace impeller
BufferView buffer_view
bool ok() const
Definition status.h:71
PipelineRef GetBlendLuminosityPipeline(ContentContextOptions opts) const
PipelineRef GetTiledTexturePipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendColorPipeline(ContentContextOptions opts) const
PipelineRef GetDownsamplePipeline(ContentContextOptions opts) const
PipelineRef GetSourceInBlendPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
void ClearCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name) const
PipelineRef GetLinearGradientFillPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendOverlayPipeline(ContentContextOptions opts) const
PipelineRef GetBlendColorDodgePipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendColorBurnPipeline(ContentContextOptions opts) const
PipelineRef GetPorterDuffPipeline(BlendMode mode, ContentContextOptions opts) const
std::shared_ptr< Texture > GetEmptyTexture() const
PipelineRef GetSourceOutBlendPipeline(ContentContextOptions opts) const
PipelineRef GetScreenBlendPipeline(ContentContextOptions opts) const
PipelineRef GetBlendColorPipeline(ContentContextOptions opts) const
PipelineRef GetLinePipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendLuminosityPipeline(ContentContextOptions opts) const
PipelineRef GetPlusBlendPipeline(ContentContextOptions opts) const
PipelineRef GetFastGradientPipeline(ContentContextOptions opts) const
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
ContentContext(std::shared_ptr< Context > context, std::shared_ptr< TypographerContext > typographer_context, std::shared_ptr< RenderTargetAllocator > render_target_allocator=nullptr)
void ResetTransientsBuffers()
Resets the transients buffers held onto by the content context.
PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const
fml::StatusOr< RenderTarget > MakeSubpass(std::string_view label, ISize texture_size, const std::shared_ptr< CommandBuffer > &command_buffer, const SubpassCallback &subpass_callback, bool msaa_enabled=true, bool depth_stencil_enabled=false, int32_t mip_count=1) const
Creates a new texture of size texture_size and calls subpass_callback with a RenderPass for drawing t...
const Capabilities & GetDeviceCapabilities() const
PipelineRef GetModulateBlendPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendHardLightPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendColorDodgePipeline(ContentContextOptions opts) const
PipelineRef GetSweepGradientUniformFillPipeline(ContentContextOptions opts) const
PipelineRef GetBlendSoftLightPipeline(ContentContextOptions opts) const
PipelineRef GetDestinationATopBlendPipeline(ContentContextOptions opts) const
PipelineRef GetTextureStrictSrcPipeline(ContentContextOptions opts) const
PipelineRef GetRadialGradientSSBOFillPipeline(ContentContextOptions opts) const
PipelineRef GetBlendColorBurnPipeline(ContentContextOptions opts) const
PipelineRef GetSweepGradientSSBOFillPipeline(ContentContextOptions opts) const
PipelineRef GetLinearGradientUniformFillPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendScreenPipeline(ContentContextOptions opts) const
PipelineRef GetLinearGradientSSBOFillPipeline(ContentContextOptions opts) const
PipelineRef GetRadialGradientFillPipeline(ContentContextOptions opts) const
PipelineRef GetTexturePipeline(ContentContextOptions opts) const
PipelineRef GetBlendHardLightPipeline(ContentContextOptions opts) const
PipelineRef GetClearBlendPipeline(ContentContextOptions opts) const
PipelineRef GetCirclePipeline(ContentContextOptions opts) const
PipelineRef GetCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name, const ContentContextOptions &options, const std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >()> &create_callback) const
PipelineRef GetConicalGradientUniformFillPipeline(ContentContextOptions opts, ConicalKind kind) const
PipelineRef GetRadialGradientUniformFillPipeline(ContentContextOptions opts) const
PipelineRef GetSweepGradientFillPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendExclusionPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendDarkenPipeline(ContentContextOptions opts) const
PipelineRef GetBlendSaturationPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendSoftLightPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendLightenPipeline(ContentContextOptions opts) const
PipelineRef GetMorphologyFilterPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendSaturationPipeline(ContentContextOptions opts) const
PipelineRef GetBlendDifferencePipeline(ContentContextOptions opts) const
PipelineRef GetGaussianBlurPipeline(ContentContextOptions opts) const
PipelineRef GetBlendHuePipeline(ContentContextOptions opts) const
PipelineRef GetSrgbToLinearFilterPipeline(ContentContextOptions opts) const
PipelineRef GetDestinationOutBlendPipeline(ContentContextOptions opts) const
PipelineRef GetYUVToRGBFilterPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendDifferencePipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendHuePipeline(ContentContextOptions opts) const
PipelineRef GetSourceATopBlendPipeline(ContentContextOptions opts) const
PipelineRef GetXorBlendPipeline(ContentContextOptions opts) const
PipelineRef GetGlyphAtlasPipeline(ContentContextOptions opts) const
PipelineRef GetClipPipeline(ContentContextOptions opts) const
PipelineRef GetRRectBlurPipeline(ContentContextOptions opts) const
PipelineRef GetBlendScreenPipeline(ContentContextOptions opts) const
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
PipelineRef GetBlendDarkenPipeline(ContentContextOptions opts) const
PipelineRef GetSourceBlendPipeline(ContentContextOptions opts) const
PipelineRef GetLinearToSrgbFilterPipeline(ContentContextOptions opts) const
PipelineRef GetBlendOverlayPipeline(ContentContextOptions opts) const
PipelineRef GetDestinationBlendPipeline(ContentContextOptions opts) const
PipelineRef GetDestinationOverBlendPipeline(ContentContextOptions opts) const
PipelineRef GetFramebufferBlendMultiplyPipeline(ContentContextOptions opts) const
PipelineRef GetConicalGradientSSBOFillPipeline(ContentContextOptions opts, ConicalKind kind) const
Tessellator & GetTessellator() const
PipelineRef GetBlendLightenPipeline(ContentContextOptions opts) const
PipelineRef GetBlendMultiplyPipeline(ContentContextOptions opts) const
PipelineRef GetSourceOverBlendPipeline(ContentContextOptions opts) const
PipelineRef GetBlendExclusionPipeline(ContentContextOptions opts) const
PipelineRef GetColorMatrixColorFilterPipeline(ContentContextOptions opts) const
PipelineRef GetConicalGradientFillPipeline(ContentContextOptions opts, ConicalKind kind) const
std::shared_ptr< Context > GetContext() const
PipelineRef GetDestinationInBlendPipeline(ContentContextOptions opts) const
PipelineRef GetRSuperellipseBlurPipeline(ContentContextOptions opts) const
PipelineRef GetBorderMaskBlurPipeline(ContentContextOptions opts) const
PipelineRef GetDrawVerticesUberPipeline(BlendMode blend_mode, ContentContextOptions opts) const
To do anything rendering related with Impeller, you need a context.
Definition context.h:65
virtual const std::shared_ptr< const Capabilities > & GetCapabilities() const =0
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
static constexpr BlendMode kLastPipelineBlendMode
Definition entity.h:28
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition host_buffer.h:92
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
void SetPolygonMode(PolygonMode mode)
std::optional< DepthAttachmentDescriptor > GetDepthStencilAttachmentDescriptor() const
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
const ColorAttachmentDescriptor * GetColorAttachmentDescriptor(size_t index) const
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
PipelineDescriptor & SetSampleCount(SampleCount samples)
void SetPrimitiveType(PrimitiveType type)
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
Describes the fixed function and programmable aspects of rendering and compute operations performed b...
Definition pipeline.h:52
An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame...
std::shared_ptr< Texture > GetRenderTargetTexture() const
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
Definition tessellator.h:37
A cache for blurred text that re-uses these across frames.
std::optional< PipelineDescriptor > desc_
std::vector< std::pair< uint64_t, std::unique_ptr< GenericRenderPipelineHandle > > > pipelines_
std::optional< ContentContextOptions > default_options_
int32_t x
#define FML_CHECK(condition)
Definition logging.h:104
#define FML_UNREACHABLE()
Definition logging.h:128
#define FML_DCHECK(condition)
Definition logging.h:122
std::array< std::vector< Scalar >, 15 > GetPorterDuffSpecConstants(bool supports_decal)
float Scalar
Definition scalar.h:19
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition pipeline.h:88
const char * BlendModeToString(BlendMode blend_mode)
Definition color.cc:47
@ kEqual
Comparison test passes if new_value == current_value.
@ kAlways
Comparison test passes always passes.
@ kLess
Comparison test passes if new_value < current_value.
@ kNotEqual
Comparison test passes if new_value != current_value.
fml::Status AddMipmapGeneration(const std::shared_ptr< CommandBuffer > &command_buffer, const std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
Adds a blit command to the render pass.
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
@ kSetToReferenceValue
Reset the stencil value to the reference value.
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
@ kKeep
Don't modify the current stencil value.
BlendMode
Definition color.h:58
static std::unique_ptr< PipelineT > CreateDefaultPipeline(const Context &context)
Definition ref_ptr.h:261
Describe the color attachment that will be used with this pipeline.
Definition formats.h:522
static constexpr Color BlackTransparent()
Definition color.h:270
std::array< uint8_t, 4 > ToR8G8B8A8() const
Convert to R8G8B8A8 representation.
Definition color.h:246
Variants< SolidFillPipeline > solid_fill
Variants< PorterDuffBlendPipeline > destination_blend
Variants< SweepGradientSSBOFillPipeline > sweep_gradient_ssbo_fill
Variants< BlendScreenPipeline > blend_screen
Variants< PorterDuffBlendPipeline > modulate_blend
Variants< FramebufferBlendOverlayPipeline > framebuffer_blend_overlay
Variants< BlendSaturationPipeline > blend_saturation
Variants< TiledTexturePipeline > tiled_texture
Variants< PorterDuffBlendPipeline > destination_in_blend
Variants< BlendSoftLightPipeline > blend_softlight
Variants< BlendColorDodgePipeline > blend_colordodge
Variants< BlendMultiplyPipeline > blend_multiply
Variants< BlendColorPipeline > blend_color
Variants< BlendDifferencePipeline > blend_difference
Variants< BlendOverlayPipeline > blend_overlay
Variants< ConicalGradientFillStripPipeline > conical_gradient_fill_strip
Variants< FramebufferBlendExclusionPipeline > framebuffer_blend_exclusion
Variants< MorphologyFilterPipeline > morphology_filter
Variants< PorterDuffBlendPipeline > screen_blend
Variants< FramebufferBlendSaturationPipeline > framebuffer_blend_saturation
Variants< PorterDuffBlendPipeline > source_over_blend
Variants< LinearGradientFillPipeline > linear_gradient_fill
Variants< PorterDuffBlendPipeline > plus_blend
Variants< VerticesUber2Shader > vertices_uber_2_
Variants< FramebufferBlendHardLightPipeline > framebuffer_blend_hardlight
Variants< RadialGradientSSBOFillPipeline > radial_gradient_ssbo_fill
Variants< PorterDuffBlendPipeline > clear_blend
Variants< ConicalGradientUniformFillConicalPipeline > conical_gradient_uniform_fill
Variants< FramebufferBlendMultiplyPipeline > framebuffer_blend_multiply
Variants< ConicalGradientSSBOFillPipeline > conical_gradient_ssbo_fill
Variants< TextureDownsamplePipeline > texture_downsample
Variants< FramebufferBlendLuminosityPipeline > framebuffer_blend_luminosity
Variants< FramebufferBlendSoftLightPipeline > framebuffer_blend_softlight
Variants< SweepGradientUniformFillPipeline > sweep_gradient_uniform_fill
Variants< BlendColorBurnPipeline > blend_colorburn
Variants< ConicalGradientUniformFillStripRadialPipeline > conical_gradient_uniform_fill_strip_and_radial
Variants< PorterDuffBlendPipeline > source_in_blend
Variants< ConicalGradientFillConicalPipeline > conical_gradient_fill
Variants< CirclePipeline > circle
Variants< SweepGradientFillPipeline > sweep_gradient_fill
Variants< FramebufferBlendLightenPipeline > framebuffer_blend_lighten
Variants< PorterDuffBlendPipeline > source_a_top_blend
Variants< PorterDuffBlendPipeline > destination_a_top_blend
Variants< RadialGradientUniformFillPipeline > radial_gradient_uniform_fill
Variants< BlendLightenPipeline > blend_lighten
Variants< LinearGradientUniformFillPipeline > linear_gradient_uniform_fill
Variants< FramebufferBlendColorBurnPipeline > framebuffer_blend_colorburn
Variants< ConicalGradientFillRadialPipeline > conical_gradient_fill_radial
Variants< PorterDuffBlendPipeline > destination_over_blend
Variants< BlendExclusionPipeline > blend_exclusion
Variants< RSuperellipseBlurPipeline > rsuperellipse_blur
Variants< SrgbToLinearFilterPipeline > srgb_to_linear_filter
Variants< ColorMatrixColorFilterPipeline > color_matrix_color_filter
Variants< LinearToSrgbFilterPipeline > linear_to_srgb_filter
Variants< ConicalGradientUniformFillRadialPipeline > conical_gradient_uniform_fill_radial
Variants< ConicalGradientSSBOFillPipeline > conical_gradient_ssbo_fill_strip
Variants< RRectBlurPipeline > rrect_blur
Variants< BlendDarkenPipeline > blend_darken
Variants< TexturePipeline > texture
Variants< PorterDuffBlendPipeline > source_out_blend
Variants< FramebufferBlendHuePipeline > framebuffer_blend_hue
Variants< TextureStrictSrcPipeline > texture_strict_src
Variants< FramebufferBlendColorPipeline > framebuffer_blend_color
Variants< BlendHuePipeline > blend_hue
Variants< FramebufferBlendDarkenPipeline > framebuffer_blend_darken
Variants< FastGradientPipeline > fast_gradient
Variants< ConicalGradientUniformFillStripPipeline > conical_gradient_uniform_fill_strip
Variants< PorterDuffBlendPipeline > xor_blend
Variants< GaussianBlurPipeline > gaussian_blur
Variants< LinearGradientSSBOFillPipeline > linear_gradient_ssbo_fill
Variants< ConicalGradientSSBOFillPipeline > conical_gradient_ssbo_fill_strip_and_radial
Variants< GlyphAtlasPipeline > glyph_atlas
Variants< PorterDuffBlendPipeline > source_blend
Variants< BlendLuminosityPipeline > blend_luminosity
Variants< BorderMaskBlurPipeline > border_mask_blur
Variants< FramebufferBlendScreenPipeline > framebuffer_blend_screen
Variants< FramebufferBlendDifferencePipeline > framebuffer_blend_difference
Variants< YUVToRGBFilterPipeline > yuv_to_rgb_filter
Variants< RadialGradientFillPipeline > radial_gradient_fill
Variants< ConicalGradientSSBOFillPipeline > conical_gradient_ssbo_fill_radial
Variants< ConicalGradientFillStripRadialPipeline > conical_gradient_fill_strip_and_radial
Variants< BlendHardLightPipeline > blend_hardlight
Variants< FramebufferBlendColorDodgePipeline > framebuffer_blend_colordodge
Variants< PorterDuffBlendPipeline > destination_out_blend
Variants< VerticesUber1Shader > vertices_uber_1_
void ApplyToPipelineDescriptor(PipelineDescriptor &desc) const
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
#define VALIDATION_LOG
Definition validation.h:91