10 #include "fml/trace_event.h"
32 <<
" as a pipeline blend.";
44 switch (pipeline_blend) {
153 <<
"Depth attachment doesn't match expected pipeline state. "
154 "has_depth_stencil_attachments="
157 <<
"Stencil attachment doesn't match expected pipeline state. "
158 "has_depth_stencil_attachments="
160 if (maybe_stencil.has_value()) {
211 if (maybe_depth.has_value()) {
224 bool supports_decal) {
225 Scalar x = supports_decal ? 1 : 0;
238 {
x, 1, -1, 1, -1, 0},
245 template <
typename PipelineT>
248 auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
249 if (!desc.has_value()) {
253 const auto default_color_format =
257 .color_attachment_pixel_format = default_color_format}
258 .ApplyToPipelineDescriptor(*desc);
259 return std::make_unique<PipelineT>(context, desc);
263 std::shared_ptr<Context> context,
264 std::shared_ptr<TypographerContext> typographer_context,
265 std::shared_ptr<RenderTargetAllocator> render_target_allocator)
266 : context_(
std::move(context)),
270 render_target_cache_(render_target_allocator == nullptr
272 context_->GetResourceAllocator())
273 :
std::move(render_target_allocator)),
275 context_->GetIdleWaiter())) {
276 if (!context_ || !context_->IsValid()) {
285 empty_texture_ =
GetContext()->GetResourceAllocator()->CreateTexture(desc);
287 auto cmd_buffer =
GetContext()->CreateCommandBuffer();
288 auto blit_pass = cmd_buffer->CreateBlitPass();
293 if (!blit_pass->EncodeCommands() || !
GetContext()
295 ->Submit({std::move(cmd_buffer)})
303 .color_attachment_pixel_format =
304 context_->GetCapabilities()->GetDefaultColorFormat()};
308 .color_attachment_pixel_format =
309 context_->GetCapabilities()->GetDefaultColorFormat()};
310 const auto supports_decal =
static_cast<Scalar>(
311 context_->GetCapabilities()->SupportsDecalSamplerAddressMode());
317 glyph_atlas_pipelines_.CreateDefault(
320 GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
322 solid_fill_pipelines_.CreateDefault(*context_, options);
323 texture_pipelines_.CreateDefault(*context_, options);
324 fast_gradient_pipelines_.CreateDefault(*context_, options);
326 if (context_->GetCapabilities()->SupportsSSBO()) {
327 linear_gradient_ssbo_fill_pipelines_.CreateDefault(*context_, options);
328 radial_gradient_ssbo_fill_pipelines_.CreateDefault(*context_, options);
329 conical_gradient_ssbo_fill_pipelines_.CreateDefault(*context_, options);
330 sweep_gradient_ssbo_fill_pipelines_.CreateDefault(*context_, options);
332 linear_gradient_uniform_fill_pipelines_.CreateDefault(*context_, options);
333 radial_gradient_uniform_fill_pipelines_.CreateDefault(*context_, options);
334 conical_gradient_uniform_fill_pipelines_.CreateDefault(*context_,
336 sweep_gradient_uniform_fill_pipelines_.CreateDefault(*context_, options);
338 linear_gradient_fill_pipelines_.CreateDefault(*context_, options);
339 radial_gradient_fill_pipelines_.CreateDefault(*context_, options);
340 conical_gradient_fill_pipelines_.CreateDefault(*context_, options);
341 sweep_gradient_fill_pipelines_.CreateDefault(*context_, options);
345 auto clip_pipeline_descriptor =
347 if (!clip_pipeline_descriptor.has_value()) {
352 .color_attachment_pixel_format =
353 context_->GetCapabilities()->GetDefaultColorFormat()}
354 .ApplyToPipelineDescriptor(*clip_pipeline_descriptor);
356 auto clip_color_attachments =
357 clip_pipeline_descriptor->GetColorAttachmentDescriptors();
358 for (
auto& color_attachment : clip_color_attachments) {
361 clip_pipeline_descriptor->SetColorAttachmentDescriptors(
362 std::move(clip_color_attachments));
363 clip_pipelines_.SetDefault(
365 std::make_unique<ClipPipeline>(*context_, clip_pipeline_descriptor));
366 texture_downsample_pipelines_.CreateDefault(*context_,
367 options_trianglestrip);
368 rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
369 texture_strict_src_pipelines_.CreateDefault(*context_, options);
370 tiled_texture_pipelines_.CreateDefault(*context_, options,
372 gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip,
374 border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
375 color_matrix_color_filter_pipelines_.CreateDefault(*context_,
376 options_trianglestrip);
377 vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal});
379 const std::array<std::vector<Scalar>, 15> porter_duff_constants =
381 clear_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
382 porter_duff_constants[0]);
383 source_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
384 porter_duff_constants[1]);
385 destination_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
386 porter_duff_constants[2]);
387 source_over_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
388 porter_duff_constants[3]);
389 destination_over_blend_pipelines_.CreateDefault(
390 *context_, options_trianglestrip, porter_duff_constants[4]);
391 source_in_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
392 porter_duff_constants[5]);
393 destination_in_blend_pipelines_.CreateDefault(
394 *context_, options_trianglestrip, porter_duff_constants[6]);
395 source_out_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
396 porter_duff_constants[7]);
397 destination_out_blend_pipelines_.CreateDefault(
398 *context_, options_trianglestrip, porter_duff_constants[8]);
399 source_a_top_blend_pipelines_.CreateDefault(
400 *context_, options_trianglestrip, porter_duff_constants[9]);
401 destination_a_top_blend_pipelines_.CreateDefault(
402 *context_, options_trianglestrip, porter_duff_constants[10]);
403 xor_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
404 porter_duff_constants[11]);
405 plus_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
406 porter_duff_constants[12]);
407 modulate_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
408 porter_duff_constants[13]);
409 screen_blend_pipelines_.CreateDefault(*context_, options_trianglestrip,
410 porter_duff_constants[14]);
413 if (context_->GetCapabilities()->SupportsFramebufferFetch()) {
414 framebuffer_blend_color_pipelines_.CreateDefault(
415 *context_, options_trianglestrip,
417 framebuffer_blend_colorburn_pipelines_.CreateDefault(
418 *context_, options_trianglestrip,
420 framebuffer_blend_colordodge_pipelines_.CreateDefault(
421 *context_, options_trianglestrip,
423 framebuffer_blend_darken_pipelines_.CreateDefault(
424 *context_, options_trianglestrip,
426 framebuffer_blend_difference_pipelines_.CreateDefault(
427 *context_, options_trianglestrip,
429 framebuffer_blend_exclusion_pipelines_.CreateDefault(
430 *context_, options_trianglestrip,
432 framebuffer_blend_hardlight_pipelines_.CreateDefault(
433 *context_, options_trianglestrip,
435 framebuffer_blend_hue_pipelines_.CreateDefault(
436 *context_, options_trianglestrip,
438 framebuffer_blend_lighten_pipelines_.CreateDefault(
439 *context_, options_trianglestrip,
441 framebuffer_blend_luminosity_pipelines_.CreateDefault(
442 *context_, options_trianglestrip,
444 framebuffer_blend_multiply_pipelines_.CreateDefault(
445 *context_, options_trianglestrip,
447 framebuffer_blend_overlay_pipelines_.CreateDefault(
448 *context_, options_trianglestrip,
450 framebuffer_blend_saturation_pipelines_.CreateDefault(
451 *context_, options_trianglestrip,
453 framebuffer_blend_screen_pipelines_.CreateDefault(
454 *context_, options_trianglestrip,
456 framebuffer_blend_softlight_pipelines_.CreateDefault(
457 *context_, options_trianglestrip,
460 blend_color_pipelines_.CreateDefault(
461 *context_, options_trianglestrip,
463 blend_colorburn_pipelines_.CreateDefault(
464 *context_, options_trianglestrip,
466 blend_colordodge_pipelines_.CreateDefault(
467 *context_, options_trianglestrip,
469 blend_darken_pipelines_.CreateDefault(
470 *context_, options_trianglestrip,
472 blend_difference_pipelines_.CreateDefault(
473 *context_, options_trianglestrip,
475 blend_exclusion_pipelines_.CreateDefault(
476 *context_, options_trianglestrip,
478 blend_hardlight_pipelines_.CreateDefault(
479 *context_, options_trianglestrip,
481 blend_hue_pipelines_.CreateDefault(
482 *context_, options_trianglestrip,
484 blend_lighten_pipelines_.CreateDefault(
485 *context_, options_trianglestrip,
487 blend_luminosity_pipelines_.CreateDefault(
488 *context_, options_trianglestrip,
490 blend_multiply_pipelines_.CreateDefault(
491 *context_, options_trianglestrip,
493 blend_overlay_pipelines_.CreateDefault(
494 *context_, options_trianglestrip,
496 blend_saturation_pipelines_.CreateDefault(
497 *context_, options_trianglestrip,
499 blend_screen_pipelines_.CreateDefault(
500 *context_, options_trianglestrip,
502 blend_softlight_pipelines_.CreateDefault(
503 *context_, options_trianglestrip,
507 morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip,
509 linear_to_srgb_filter_pipelines_.CreateDefault(*context_,
510 options_trianglestrip);
511 srgb_to_linear_filter_pipelines_.CreateDefault(*context_,
512 options_trianglestrip);
513 yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip);
515 #if defined(IMPELLER_ENABLE_OPENGLES)
517 #if !defined(FML_OS_MACOSX)
519 tiled_texture_external_pipelines_.CreateDefault(*context_, options);
520 tiled_texture_uv_external_pipelines_.CreateDefault(*context_, options);
522 texture_downsample_gles_pipelines_.CreateDefault(*context_,
523 options_trianglestrip);
528 InitializeCommonlyUsedShadersIfNeeded();
538 return empty_texture_;
542 std::string_view label,
544 const std::shared_ptr<CommandBuffer>& command_buffer,
547 bool depth_stencil_enabled,
548 int32_t mip_count)
const {
549 const std::shared_ptr<Context>& context =
GetContext();
552 std::optional<RenderTarget::AttachmentConfig> depth_stencil_config =
554 : std::optional<RenderTarget::AttachmentConfig>();
556 if (context->GetCapabilities()->SupportsOffscreenMSAA() && msaa_enabled) {
558 *context, texture_size,
563 *context, texture_size,
567 return MakeSubpass(label, subpass_target, command_buffer, subpass_callback);
571 std::string_view label,
573 const std::shared_ptr<CommandBuffer>& command_buffer,
575 const std::shared_ptr<Context>& context =
GetContext();
578 if (!subpass_texture) {
579 return fml::Status(fml::StatusCode::kUnknown,
"");
582 auto sub_renderpass = command_buffer->CreateRenderPass(subpass_target);
583 if (!sub_renderpass) {
584 return fml::Status(fml::StatusCode::kUnknown,
"");
586 sub_renderpass->SetLabel(label);
588 if (!subpass_callback(*
this, *sub_renderpass)) {
589 return fml::Status(fml::StatusCode::kUnknown,
"");
592 if (!sub_renderpass->EncodeCommands()) {
593 return fml::Status(fml::StatusCode::kUnknown,
"");
596 const std::shared_ptr<Texture>& target_texture =
598 if (target_texture->GetMipCount() > 1) {
599 fml::Status mipmap_status =
601 if (!mipmap_status.ok()) {
602 return mipmap_status;
606 return subpass_target;
610 return *tessellator_;
618 return *context_->GetCapabilities();
622 wireframe_ = wireframe;
626 const std::string& unique_entrypoint_name,
629 create_callback)
const {
630 RuntimeEffectPipelineKey key{unique_entrypoint_name, options};
631 auto it = runtime_effect_pipelines_.find(key);
632 if (it == runtime_effect_pipelines_.end()) {
633 it = runtime_effect_pipelines_.insert(it, {key, create_callback()});
639 const std::string& unique_entrypoint_name)
const {
640 for (
auto it = runtime_effect_pipelines_.begin();
641 it != runtime_effect_pipelines_.end();) {
642 if (it->first.unique_entrypoint_name == unique_entrypoint_name) {
643 it = runtime_effect_pipelines_.erase(it);
650 void ContentContext::InitializeCommonlyUsedShadersIfNeeded()
const {
651 TRACE_EVENT0(
"flutter",
"InitializeCommonlyUsedShadersIfNeeded");
652 GetContext()->InitializeCommonlyUsedShadersIfNeeded();
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
void ClearCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name) const
std::shared_ptr< Texture > GetEmptyTexture() const
ContentContext(std::shared_ptr< Context > context, std::shared_ptr< TypographerContext > typographer_context, std::shared_ptr< RenderTargetAllocator > render_target_allocator=nullptr)
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 GetCachedRuntimeEffectPipeline(const std::string &unique_entrypoint_name, const ContentContextOptions &options, const std::function< std::shared_ptr< Pipeline< PipelineDescriptor >>()> &create_callback) const
void SetWireframe(bool wireframe)
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
Tessellator & GetTessellator() const
std::shared_ptr< Context > GetContext() const
To do anything rendering related with Impeller, you need a context.
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
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
void ClearStencilAttachments()
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)
void ClearDepthAttachment()
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
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...
ScopedObject< Object > Create(CtorArgs &&... args)
@ kOneMinusDestinationAlpha
static std::unique_ptr< PipelineT > CreateDefaultPipeline(const Context &context)
@ 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.
std::array< std::vector< Scalar >, 15 > GetPorterDuffSpecConstants(bool supports_decal)
Describe the color attachment that will be used with this pipeline.
BlendOperation color_blend_op
BlendFactor dst_color_blend_factor
ColorWriteMask write_mask
BlendFactor src_alpha_blend_factor
BlendOperation alpha_blend_op
BlendFactor src_color_blend_factor
BlendFactor dst_alpha_blend_factor
constexpr std::array< uint8_t, 4 > ToR8G8B8A8() const
Convert to R8G8B8A8 representation.
static constexpr Color BlackTransparent()
PrimitiveType primitive_type
bool has_depth_stencil_attachments
void ApplyToPipelineDescriptor(PipelineDescriptor &desc) const
PixelFormat color_attachment_pixel_format
@ kOverdrawPreventionRestore
@ kOverdrawPreventionIncrement
bool is_for_rrect_blur_clear
CompareFunction depth_compare
CompareFunction depth_compare
static std::optional< PipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context, const std::vector< Scalar > &constants={})
Create a default pipeline descriptor using the combination reflected shader information....
StencilOperation stencil_failure
CompareFunction stencil_compare
StencilOperation depth_stencil_pass
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