Flutter Impeller
impeller::ContentContextOptions Struct Reference

#include <content_context.h>

Classes

struct  Equal
 
struct  Hash
 

Public Member Functions

void ApplyToPipelineDescriptor (PipelineDescriptor &desc) const
 

Public Attributes

SampleCount sample_count = SampleCount::kCount1
 
BlendMode blend_mode = BlendMode::kSourceOver
 
CompareFunction stencil_compare = CompareFunction::kEqual
 
StencilOperation stencil_operation = StencilOperation::kKeep
 
PrimitiveType primitive_type = PrimitiveType::kTriangle
 
PixelFormat color_attachment_pixel_format = PixelFormat::kUnknown
 
bool has_stencil_attachment = true
 
bool wireframe = false
 
bool is_for_rrect_blur_clear = false
 

Detailed Description

Pipeline state configuration.

Each unique combination of these options requires a different pipeline state object to be built. This struct is used as a key for the per-pipeline variant cache.

When adding fields to this key, reliant features should take care to limit the combinatorical explosion of variations. A sufficiently complicated Flutter application may easily require building hundreds of PSOs in total, but they shouldn't require e.g. 10s of thousands.

Definition at line 302 of file content_context.h.

Member Function Documentation

◆ ApplyToPipelineDescriptor()

void impeller::ContentContextOptions::ApplyToPipelineDescriptor ( PipelineDescriptor desc) const

Definition at line 23 of file content_context.cc.

24  {
25  auto pipeline_blend = blend_mode;
27  VALIDATION_LOG << "Cannot use blend mode " << static_cast<int>(blend_mode)
28  << " as a pipeline blend.";
29  pipeline_blend = BlendMode::kSourceOver;
30  }
31 
32  desc.SetSampleCount(sample_count);
33 
34  ColorAttachmentDescriptor color0 = *desc.GetColorAttachmentDescriptor(0u);
35  color0.format = color_attachment_pixel_format;
36  color0.alpha_blend_op = BlendOperation::kAdd;
37  color0.color_blend_op = BlendOperation::kAdd;
38 
39  switch (pipeline_blend) {
40  case BlendMode::kClear:
42  color0.alpha_blend_op = BlendOperation::kReverseSubtract;
43  color0.color_blend_op = BlendOperation::kReverseSubtract;
44  color0.dst_alpha_blend_factor = BlendFactor::kOne;
45  color0.dst_color_blend_factor = BlendFactor::kOne;
46  color0.src_alpha_blend_factor = BlendFactor::kDestinationColor;
47  color0.src_color_blend_factor = BlendFactor::kDestinationColor;
48  } else {
49  color0.dst_alpha_blend_factor = BlendFactor::kZero;
50  color0.dst_color_blend_factor = BlendFactor::kZero;
51  color0.src_alpha_blend_factor = BlendFactor::kZero;
52  color0.src_color_blend_factor = BlendFactor::kZero;
53  }
54  break;
55  case BlendMode::kSource:
56  color0.blending_enabled = false;
57  color0.dst_alpha_blend_factor = BlendFactor::kZero;
58  color0.dst_color_blend_factor = BlendFactor::kZero;
59  color0.src_alpha_blend_factor = BlendFactor::kOne;
60  color0.src_color_blend_factor = BlendFactor::kOne;
61  break;
63  color0.dst_alpha_blend_factor = BlendFactor::kOne;
64  color0.dst_color_blend_factor = BlendFactor::kOne;
65  color0.src_alpha_blend_factor = BlendFactor::kZero;
66  color0.src_color_blend_factor = BlendFactor::kZero;
67  break;
69  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
70  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
71  color0.src_alpha_blend_factor = BlendFactor::kOne;
72  color0.src_color_blend_factor = BlendFactor::kOne;
73  break;
75  color0.dst_alpha_blend_factor = BlendFactor::kOne;
76  color0.dst_color_blend_factor = BlendFactor::kOne;
77  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
78  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
79  break;
81  color0.dst_alpha_blend_factor = BlendFactor::kZero;
82  color0.dst_color_blend_factor = BlendFactor::kZero;
83  color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
84  color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
85  break;
87  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
88  color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
89  color0.src_alpha_blend_factor = BlendFactor::kZero;
90  color0.src_color_blend_factor = BlendFactor::kZero;
91  break;
93  color0.dst_alpha_blend_factor = BlendFactor::kZero;
94  color0.dst_color_blend_factor = BlendFactor::kZero;
95  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
96  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
97  break;
99  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
100  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
101  color0.src_alpha_blend_factor = BlendFactor::kZero;
102  color0.src_color_blend_factor = BlendFactor::kZero;
103  break;
105  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
106  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
107  color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
108  color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
109  break;
111  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
112  color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
113  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
114  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
115  break;
116  case BlendMode::kXor:
117  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
118  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
119  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
120  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
121  break;
122  case BlendMode::kPlus:
123  color0.dst_alpha_blend_factor = BlendFactor::kOne;
124  color0.dst_color_blend_factor = BlendFactor::kOne;
125  color0.src_alpha_blend_factor = BlendFactor::kOne;
126  color0.src_color_blend_factor = BlendFactor::kOne;
127  break;
129  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
130  color0.dst_color_blend_factor = BlendFactor::kSourceColor;
131  color0.src_alpha_blend_factor = BlendFactor::kZero;
132  color0.src_color_blend_factor = BlendFactor::kZero;
133  break;
134  default:
135  FML_UNREACHABLE();
136  }
137  desc.SetColorAttachmentDescriptor(0u, color0);
138 
139  if (!has_stencil_attachment) {
140  desc.ClearStencilAttachments();
141  }
142 
143  auto maybe_stencil = desc.GetFrontStencilAttachmentDescriptor();
144  if (maybe_stencil.has_value()) {
145  StencilAttachmentDescriptor stencil = maybe_stencil.value();
146  stencil.stencil_compare = stencil_compare;
147  stencil.depth_stencil_pass = stencil_operation;
148  desc.SetStencilAttachmentDescriptors(stencil);
149  }
150 
151  desc.SetPrimitiveType(primitive_type);
152 
153  desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
154 }

References impeller::ColorAttachmentDescriptor::alpha_blend_op, blend_mode, impeller::ColorAttachmentDescriptor::blending_enabled, impeller::PipelineDescriptor::ClearStencilAttachments(), color_attachment_pixel_format, impeller::ColorAttachmentDescriptor::color_blend_op, impeller::StencilAttachmentDescriptor::depth_stencil_pass, impeller::ColorAttachmentDescriptor::dst_alpha_blend_factor, impeller::ColorAttachmentDescriptor::dst_color_blend_factor, impeller::ColorAttachmentDescriptor::format, impeller::PipelineDescriptor::GetColorAttachmentDescriptor(), impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor(), has_stencil_attachment, is_for_rrect_blur_clear, impeller::kAdd, impeller::kClear, impeller::kDestination, impeller::kDestinationAlpha, impeller::kDestinationATop, impeller::kDestinationColor, impeller::kDestinationIn, impeller::kDestinationOut, impeller::kDestinationOver, impeller::kFill, impeller::Entity::kLastPipelineBlendMode, impeller::kLine, impeller::kModulate, impeller::kOne, impeller::kOneMinusDestinationAlpha, impeller::kOneMinusSourceAlpha, impeller::kPlus, impeller::kReverseSubtract, impeller::kSource, impeller::kSourceAlpha, impeller::kSourceATop, impeller::kSourceColor, impeller::kSourceIn, impeller::kSourceOut, impeller::kSourceOver, impeller::kXor, impeller::kZero, primitive_type, sample_count, impeller::PipelineDescriptor::SetColorAttachmentDescriptor(), impeller::PipelineDescriptor::SetPolygonMode(), impeller::PipelineDescriptor::SetPrimitiveType(), impeller::PipelineDescriptor::SetSampleCount(), impeller::PipelineDescriptor::SetStencilAttachmentDescriptors(), impeller::ColorAttachmentDescriptor::src_alpha_blend_factor, impeller::ColorAttachmentDescriptor::src_color_blend_factor, stencil_compare, impeller::StencilAttachmentDescriptor::stencil_compare, stencil_operation, VALIDATION_LOG, and wireframe.

Member Data Documentation

◆ blend_mode

◆ color_attachment_pixel_format

◆ has_stencil_attachment

◆ is_for_rrect_blur_clear

◆ primitive_type

◆ sample_count

◆ stencil_compare

◆ stencil_operation

◆ wireframe

bool impeller::ContentContextOptions::wireframe = false

The documentation for this struct was generated from the following files:
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:23
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::ContentContextOptions::blend_mode
BlendMode blend_mode
Definition: content_context.h:304
impeller::BlendFactor::kDestinationAlpha
@ kDestinationAlpha
impeller::BlendMode::kDestinationIn
@ kDestinationIn
impeller::PolygonMode::kFill
@ kFill
impeller::ContentContextOptions::wireframe
bool wireframe
Definition: content_context.h:310
impeller::BlendFactor::kSourceColor
@ kSourceColor
impeller::BlendMode::kXor
@ kXor
impeller::BlendFactor::kDestinationColor
@ kDestinationColor
impeller::ContentContextOptions::stencil_compare
CompareFunction stencil_compare
Definition: content_context.h:305
impeller::BlendFactor::kZero
@ kZero
impeller::ContentContextOptions::color_attachment_pixel_format
PixelFormat color_attachment_pixel_format
Definition: content_context.h:308
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::BlendOperation::kReverseSubtract
@ kReverseSubtract
impeller::BlendMode::kPlus
@ kPlus
impeller::BlendMode::kDestination
@ kDestination
impeller::BlendOperation::kAdd
@ kAdd
impeller::BlendMode::kDestinationATop
@ kDestinationATop
impeller::ContentContextOptions::has_stencil_attachment
bool has_stencil_attachment
Definition: content_context.h:309
impeller::BlendFactor::kOne
@ kOne
impeller::ContentContextOptions::is_for_rrect_blur_clear
bool is_for_rrect_blur_clear
Definition: content_context.h:311
impeller::BlendMode::kDestinationOut
@ kDestinationOut
impeller::ContentContextOptions::primitive_type
PrimitiveType primitive_type
Definition: content_context.h:307
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::BlendMode::kDestinationOver
@ kDestinationOver
impeller::ContentContextOptions::sample_count
SampleCount sample_count
Definition: content_context.h:303
impeller::BlendMode::kClear
@ kClear
impeller::PolygonMode::kLine
@ kLine
impeller::BlendMode::kSourceATop
@ kSourceATop
impeller::BlendMode::kModulate
@ kModulate
impeller::BlendFactor::kSourceAlpha
@ kSourceAlpha
impeller::BlendMode::kSourceOut
@ kSourceOut
impeller::BlendMode::kSource
@ kSource
impeller::BlendFactor::kOneMinusDestinationAlpha
@ kOneMinusDestinationAlpha
impeller::ContentContextOptions::stencil_operation
StencilOperation stencil_operation
Definition: content_context.h:306