Flutter Impeller
impeller::ContentContextOptions Struct Reference

#include <content_context.h>

Classes

struct  Equal
 
struct  Hash
 

Public Types

enum  StencilMode : uint8_t {
  StencilMode::kIgnore,
  StencilMode::kStencilNonZeroFill,
  StencilMode::kStencilEvenOddFill,
  StencilMode::kCoverCompare,
  StencilMode::kCoverCompareInverted,
  StencilMode::kLegacyClipRestore,
  StencilMode::kLegacyClipIncrement,
  StencilMode::kLegacyClipDecrement,
  StencilMode::kLegacyClipCompare
}
 

Public Member Functions

void ApplyToPipelineDescriptor (PipelineDescriptor &desc) const
 

Public Attributes

SampleCount sample_count = SampleCount::kCount1
 
BlendMode blend_mode = BlendMode::kSourceOver
 
CompareFunction depth_compare = CompareFunction::kAlways
 
StencilMode stencil_mode
 
PrimitiveType primitive_type = PrimitiveType::kTriangle
 
PixelFormat color_attachment_pixel_format = PixelFormat::kUnknown
 
bool has_depth_stencil_attachments = true
 
bool depth_write_enabled = false
 
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 288 of file content_context.h.

Member Enumeration Documentation

◆ StencilMode

Enumerator
kIgnore 

Turn the stencil test off. Used when drawing without stencil-then-cover.

kStencilNonZeroFill 

Draw the stencil for the NonZero fill path rule.

The stencil ref should always be 0 on commands using this mode. 
kStencilEvenOddFill 

Draw the stencil for the EvenOdd fill path rule.

The stencil ref should always be 0 on commands using this mode. 
kCoverCompare 

Used for draw calls which fill in the stenciled area. Intended to be used after kStencilNonZeroFill or kStencilEvenOddFill is used to set up the stencil buffer. Also cleans up the stencil buffer by resetting everything to zero.

The stencil ref should always be 0 on commands using this mode.

kCoverCompareInverted 

The opposite of kCoverCompare. Used for draw calls which fill in the non-stenciled area (intersection clips). Intended to be used after kStencilNonZeroFill or kStencilEvenOddFill is used to set up the stencil buffer. Also cleans up the stencil buffer by resetting everything to zero.

The stencil ref should always be 0 on commands using this mode.

kLegacyClipRestore 

Slice the clip heightmap to a new maximum height.

kLegacyClipIncrement 

Increment the stencil heightmap.

kLegacyClipDecrement 

Decrement the stencil heightmap (used for difference clipping only).

kLegacyClipCompare 

Used for applying clips to all non-clip draw calls.

Definition at line 289 of file content_context.h.

289  : uint8_t {
290  /// Turn the stencil test off. Used when drawing without stencil-then-cover.
291  kIgnore,
292 
293  // Operations used for stencil-then-cover
294 
295  /// Draw the stencil for the NonZero fill path rule.
296  ///
297  /// The stencil ref should always be 0 on commands using this mode.
298  kStencilNonZeroFill,
299  /// Draw the stencil for the EvenOdd fill path rule.
300  ///
301  /// The stencil ref should always be 0 on commands using this mode.
302  kStencilEvenOddFill,
303  /// Used for draw calls which fill in the stenciled area. Intended to be
304  /// used after `kStencilNonZeroFill` or `kStencilEvenOddFill` is used to set
305  /// up the stencil buffer. Also cleans up the stencil buffer by resetting
306  /// everything to zero.
307  ///
308  /// The stencil ref should always be 0 on commands using this mode.
309  kCoverCompare,
310  /// The opposite of `kCoverCompare`. Used for draw calls which fill in the
311  /// non-stenciled area (intersection clips). Intended to be used after
312  /// `kStencilNonZeroFill` or `kStencilEvenOddFill` is used to set up the
313  /// stencil buffer. Also cleans up the stencil buffer by resetting
314  /// everything to zero.
315  ///
316  /// The stencil ref should always be 0 on commands using this mode.
317  kCoverCompareInverted,
318 
319  // Operations to control the legacy clip implementation, which forms a
320  // heightmap on the stencil buffer.
321 
322  /// Slice the clip heightmap to a new maximum height.
323  kLegacyClipRestore,
324  /// Increment the stencil heightmap.
325  kLegacyClipIncrement,
326  /// Decrement the stencil heightmap (used for difference clipping only).
327  kLegacyClipDecrement,
328  /// Used for applying clips to all non-clip draw calls.
329  kLegacyClipCompare,
330  };

Member Function Documentation

◆ ApplyToPipelineDescriptor()

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

Definition at line 27 of file content_context.cc.

28  {
29  auto pipeline_blend = blend_mode;
31  VALIDATION_LOG << "Cannot use blend mode " << static_cast<int>(blend_mode)
32  << " as a pipeline blend.";
33  pipeline_blend = BlendMode::kSourceOver;
34  }
35 
36  desc.SetSampleCount(sample_count);
37 
38  ColorAttachmentDescriptor color0 = *desc.GetColorAttachmentDescriptor(0u);
39  color0.format = color_attachment_pixel_format;
40  color0.alpha_blend_op = BlendOperation::kAdd;
41  color0.color_blend_op = BlendOperation::kAdd;
42 
43  switch (pipeline_blend) {
44  case BlendMode::kClear:
46  color0.alpha_blend_op = BlendOperation::kReverseSubtract;
47  color0.color_blend_op = BlendOperation::kReverseSubtract;
48  color0.dst_alpha_blend_factor = BlendFactor::kOne;
49  color0.dst_color_blend_factor = BlendFactor::kOne;
50  color0.src_alpha_blend_factor = BlendFactor::kDestinationColor;
51  color0.src_color_blend_factor = BlendFactor::kDestinationColor;
52  } else {
53  color0.dst_alpha_blend_factor = BlendFactor::kZero;
54  color0.dst_color_blend_factor = BlendFactor::kZero;
55  color0.src_alpha_blend_factor = BlendFactor::kZero;
56  color0.src_color_blend_factor = BlendFactor::kZero;
57  }
58  break;
59  case BlendMode::kSource:
60  color0.blending_enabled = false;
61  color0.dst_alpha_blend_factor = BlendFactor::kZero;
62  color0.dst_color_blend_factor = BlendFactor::kZero;
63  color0.src_alpha_blend_factor = BlendFactor::kOne;
64  color0.src_color_blend_factor = BlendFactor::kOne;
65  break;
67  color0.dst_alpha_blend_factor = BlendFactor::kOne;
68  color0.dst_color_blend_factor = BlendFactor::kOne;
69  color0.src_alpha_blend_factor = BlendFactor::kZero;
70  color0.src_color_blend_factor = BlendFactor::kZero;
71  break;
73  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
74  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
75  color0.src_alpha_blend_factor = BlendFactor::kOne;
76  color0.src_color_blend_factor = BlendFactor::kOne;
77  break;
79  color0.dst_alpha_blend_factor = BlendFactor::kOne;
80  color0.dst_color_blend_factor = BlendFactor::kOne;
81  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
82  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
83  break;
85  color0.dst_alpha_blend_factor = BlendFactor::kZero;
86  color0.dst_color_blend_factor = BlendFactor::kZero;
87  color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
88  color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
89  break;
91  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
92  color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
93  color0.src_alpha_blend_factor = BlendFactor::kZero;
94  color0.src_color_blend_factor = BlendFactor::kZero;
95  break;
97  color0.dst_alpha_blend_factor = BlendFactor::kZero;
98  color0.dst_color_blend_factor = BlendFactor::kZero;
99  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
100  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
101  break;
103  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
104  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
105  color0.src_alpha_blend_factor = BlendFactor::kZero;
106  color0.src_color_blend_factor = BlendFactor::kZero;
107  break;
109  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
110  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
111  color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
112  color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
113  break;
115  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
116  color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
117  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
118  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
119  break;
120  case BlendMode::kXor:
121  color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
122  color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
123  color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
124  color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
125  break;
126  case BlendMode::kPlus:
127  color0.dst_alpha_blend_factor = BlendFactor::kOne;
128  color0.dst_color_blend_factor = BlendFactor::kOne;
129  color0.src_alpha_blend_factor = BlendFactor::kOne;
130  color0.src_color_blend_factor = BlendFactor::kOne;
131  break;
133  color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
134  color0.dst_color_blend_factor = BlendFactor::kSourceColor;
135  color0.src_alpha_blend_factor = BlendFactor::kZero;
136  color0.src_color_blend_factor = BlendFactor::kZero;
137  break;
138  default:
139  FML_UNREACHABLE();
140  }
141  desc.SetColorAttachmentDescriptor(0u, color0);
142 
144  desc.ClearDepthAttachment();
145  desc.ClearStencilAttachments();
146  }
147 
148  auto maybe_stencil = desc.GetFrontStencilAttachmentDescriptor();
149  auto maybe_depth = desc.GetDepthStencilAttachmentDescriptor();
150  FML_DCHECK(has_depth_stencil_attachments == maybe_depth.has_value())
151  << "Depth attachment doesn't match expected pipeline state. "
152  "has_depth_stencil_attachments="
154  FML_DCHECK(has_depth_stencil_attachments == maybe_stencil.has_value())
155  << "Stencil attachment doesn't match expected pipeline state. "
156  "has_depth_stencil_attachments="
158  if (maybe_stencil.has_value()) {
159  StencilAttachmentDescriptor front_stencil = maybe_stencil.value();
160  StencilAttachmentDescriptor back_stencil = front_stencil;
161 
162  switch (stencil_mode) {
164  front_stencil.stencil_compare = CompareFunction::kAlways;
165  front_stencil.depth_stencil_pass = StencilOperation::kKeep;
166  desc.SetStencilAttachmentDescriptors(front_stencil);
167  break;
169  // The stencil ref should be 0 on commands that use this mode.
170  front_stencil.stencil_compare = CompareFunction::kAlways;
171  front_stencil.depth_stencil_pass = StencilOperation::kIncrementWrap;
172  back_stencil.stencil_compare = CompareFunction::kAlways;
173  back_stencil.depth_stencil_pass = StencilOperation::kDecrementWrap;
174  desc.SetStencilAttachmentDescriptors(front_stencil, back_stencil);
175  break;
177  // The stencil ref should be 0 on commands that use this mode.
178  front_stencil.stencil_compare = CompareFunction::kEqual;
179  front_stencil.depth_stencil_pass = StencilOperation::kIncrementWrap;
180  front_stencil.stencil_failure = StencilOperation::kDecrementWrap;
181  desc.SetStencilAttachmentDescriptors(front_stencil);
182  break;
184  // The stencil ref should be 0 on commands that use this mode.
185  front_stencil.stencil_compare = CompareFunction::kNotEqual;
186  front_stencil.depth_stencil_pass =
188  desc.SetStencilAttachmentDescriptors(front_stencil);
189  break;
191  // The stencil ref should be 0 on commands that use this mode.
192  front_stencil.stencil_compare = CompareFunction::kEqual;
193  front_stencil.stencil_failure = StencilOperation::kSetToReferenceValue;
194  desc.SetStencilAttachmentDescriptors(front_stencil);
195  break;
197  front_stencil.stencil_compare = CompareFunction::kLess;
198  front_stencil.depth_stencil_pass =
200  desc.SetStencilAttachmentDescriptors(front_stencil);
201  break;
203  front_stencil.stencil_compare = CompareFunction::kEqual;
204  front_stencil.depth_stencil_pass = StencilOperation::kIncrementClamp;
205  desc.SetStencilAttachmentDescriptors(front_stencil);
206  break;
208  front_stencil.stencil_compare = CompareFunction::kEqual;
209  front_stencil.depth_stencil_pass = StencilOperation::kDecrementClamp;
210  desc.SetStencilAttachmentDescriptors(front_stencil);
211  break;
213  front_stencil.stencil_compare = CompareFunction::kEqual;
214  front_stencil.depth_stencil_pass = StencilOperation::kKeep;
215  desc.SetStencilAttachmentDescriptors(front_stencil);
216  break;
217  }
218  }
219  if (maybe_depth.has_value()) {
220  DepthAttachmentDescriptor depth = maybe_depth.value();
221  depth.depth_write_enabled = depth_write_enabled;
222  depth.depth_compare = depth_compare;
223  desc.SetDepthStencilAttachmentDescriptor(depth);
224  }
225 
226  desc.SetPrimitiveType(primitive_type);
227 
228  desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
229 }

References impeller::ColorAttachmentDescriptor::alpha_blend_op, blend_mode, impeller::ColorAttachmentDescriptor::blending_enabled, impeller::PipelineDescriptor::ClearDepthAttachment(), impeller::PipelineDescriptor::ClearStencilAttachments(), color_attachment_pixel_format, impeller::ColorAttachmentDescriptor::color_blend_op, depth_compare, impeller::DepthAttachmentDescriptor::depth_compare, impeller::StencilAttachmentDescriptor::depth_stencil_pass, depth_write_enabled, impeller::DepthAttachmentDescriptor::depth_write_enabled, impeller::ColorAttachmentDescriptor::dst_alpha_blend_factor, impeller::ColorAttachmentDescriptor::dst_color_blend_factor, impeller::ColorAttachmentDescriptor::format, impeller::PipelineDescriptor::GetColorAttachmentDescriptor(), impeller::PipelineDescriptor::GetDepthStencilAttachmentDescriptor(), impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor(), has_depth_stencil_attachments, is_for_rrect_blur_clear, impeller::kAdd, impeller::kAlways, impeller::kClear, kCoverCompare, kCoverCompareInverted, impeller::kDecrementClamp, impeller::kDecrementWrap, impeller::kDestination, impeller::kDestinationAlpha, impeller::kDestinationATop, impeller::kDestinationColor, impeller::kDestinationIn, impeller::kDestinationOut, impeller::kDestinationOver, impeller::kEqual, impeller::kFill, kIgnore, impeller::kIncrementClamp, impeller::kIncrementWrap, impeller::kKeep, impeller::Entity::kLastPipelineBlendMode, kLegacyClipCompare, kLegacyClipDecrement, kLegacyClipIncrement, kLegacyClipRestore, impeller::kLess, impeller::kLine, impeller::kModulate, impeller::kNotEqual, impeller::kOne, impeller::kOneMinusDestinationAlpha, impeller::kOneMinusSourceAlpha, impeller::kPlus, impeller::kReverseSubtract, impeller::kSetToReferenceValue, impeller::kSource, impeller::kSourceAlpha, impeller::kSourceATop, impeller::kSourceColor, impeller::kSourceIn, impeller::kSourceOut, impeller::kSourceOver, kStencilEvenOddFill, kStencilNonZeroFill, impeller::kXor, impeller::kZero, primitive_type, sample_count, impeller::PipelineDescriptor::SetColorAttachmentDescriptor(), impeller::PipelineDescriptor::SetDepthStencilAttachmentDescriptor(), impeller::PipelineDescriptor::SetPolygonMode(), impeller::PipelineDescriptor::SetPrimitiveType(), impeller::PipelineDescriptor::SetSampleCount(), impeller::PipelineDescriptor::SetStencilAttachmentDescriptors(), impeller::ColorAttachmentDescriptor::src_alpha_blend_factor, impeller::ColorAttachmentDescriptor::src_color_blend_factor, impeller::StencilAttachmentDescriptor::stencil_compare, impeller::StencilAttachmentDescriptor::stencil_failure, stencil_mode, VALIDATION_LOG, and wireframe.

Member Data Documentation

◆ blend_mode

◆ color_attachment_pixel_format

◆ depth_compare

◆ depth_write_enabled

bool impeller::ContentContextOptions::depth_write_enabled = false

◆ has_depth_stencil_attachments

◆ is_for_rrect_blur_clear

◆ primitive_type

◆ sample_count

◆ stencil_mode

◆ wireframe

bool impeller::ContentContextOptions::wireframe = false

The documentation for this struct was generated from the following files:
impeller::ContentContextOptions::StencilMode::kIgnore
@ kIgnore
Turn the stencil test off. Used when drawing without stencil-then-cover.
impeller::Entity::kLastPipelineBlendMode
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:23
impeller::BlendMode::kDestinationATop
@ kDestinationATop
impeller::StencilOperation::kDecrementClamp
@ kDecrementClamp
Decrement the current stencil value by 1. Clamp it to zero.
impeller::ContentContextOptions::StencilMode::kLegacyClipCompare
@ kLegacyClipCompare
Used for applying clips to all non-clip draw calls.
impeller::CompareFunction::kEqual
@ kEqual
Comparison test passes if new_value == current_value.
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::BlendMode::kSource
@ kSource
impeller::BlendMode::kDestination
@ kDestination
impeller::StencilOperation::kIncrementClamp
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
impeller::ContentContextOptions::has_depth_stencil_attachments
bool has_depth_stencil_attachments
Definition: content_context.h:339
impeller::BlendMode::kDestinationOver
@ kDestinationOver
impeller::BlendMode::kPlus
@ kPlus
impeller::ContentContextOptions::blend_mode
BlendMode blend_mode
Definition: content_context.h:333
impeller::BlendFactor::kDestinationAlpha
@ kDestinationAlpha
impeller::ContentContextOptions::StencilMode::kStencilEvenOddFill
@ kStencilEvenOddFill
impeller::ContentContextOptions::StencilMode::kLegacyClipDecrement
@ kLegacyClipDecrement
Decrement the stencil heightmap (used for difference clipping only).
impeller::BlendMode::kModulate
@ kModulate
impeller::PolygonMode::kFill
@ kFill
impeller::ContentContextOptions::wireframe
bool wireframe
Definition: content_context.h:341
impeller::StencilOperation::kSetToReferenceValue
@ kSetToReferenceValue
Reset the stencil value to the reference value.
impeller::BlendFactor::kSourceColor
@ kSourceColor
impeller::BlendMode::kSourceOut
@ kSourceOut
impeller::BlendFactor::kDestinationColor
@ kDestinationColor
impeller::BlendFactor::kZero
@ kZero
impeller::StencilOperation::kDecrementWrap
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
impeller::ContentContextOptions::StencilMode::kLegacyClipIncrement
@ kLegacyClipIncrement
Increment the stencil heightmap.
impeller::ContentContextOptions::color_attachment_pixel_format
PixelFormat color_attachment_pixel_format
Definition: content_context.h:338
impeller::BlendOperation::kReverseSubtract
@ kReverseSubtract
impeller::BlendMode::kClear
@ kClear
impeller::BlendOperation::kAdd
@ kAdd
impeller::ContentContextOptions::StencilMode::kStencilNonZeroFill
@ kStencilNonZeroFill
impeller::StencilOperation::kIncrementWrap
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
impeller::BlendFactor::kOne
@ kOne
impeller::ContentContextOptions::is_for_rrect_blur_clear
bool is_for_rrect_blur_clear
Definition: content_context.h:342
impeller::ContentContextOptions::stencil_mode
StencilMode stencil_mode
Definition: content_context.h:335
impeller::ContentContextOptions::depth_write_enabled
bool depth_write_enabled
Definition: content_context.h:340
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::ContentContextOptions::primitive_type
PrimitiveType primitive_type
Definition: content_context.h:337
impeller::BlendMode::kDestinationIn
@ kDestinationIn
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::BlendMode::kDestinationOut
@ kDestinationOut
impeller::ContentContextOptions::depth_compare
CompareFunction depth_compare
Definition: content_context.h:334
impeller::ContentContextOptions::sample_count
SampleCount sample_count
Definition: content_context.h:332
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::PolygonMode::kLine
@ kLine
impeller::ContentContextOptions::StencilMode::kCoverCompareInverted
@ kCoverCompareInverted
impeller::ContentContextOptions::StencilMode::kCoverCompare
@ kCoverCompare
impeller::CompareFunction::kNotEqual
@ kNotEqual
Comparison test passes if new_value != current_value.
impeller::BlendMode::kXor
@ kXor
impeller::BlendFactor::kSourceAlpha
@ kSourceAlpha
impeller::ContentContextOptions::StencilMode::kLegacyClipRestore
@ kLegacyClipRestore
Slice the clip heightmap to a new maximum height.
impeller::CompareFunction::kLess
@ kLess
Comparison test passes if new_value < current_value.
impeller::BlendMode::kSourceATop
@ kSourceATop
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::BlendFactor::kOneMinusDestinationAlpha
@ kOneMinusDestinationAlpha