Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
impeller::ContentContextOptions Struct Reference

#include <content_context.h>

Classes

struct  Equal
 
struct  Hash
 

Public Types

enum class  StencilMode : uint8_t {
  kIgnore , kStencilNonZeroFill , kStencilEvenOddFill , kCoverCompare ,
  kCoverCompareInverted , kOverdrawPreventionIncrement , kOverdrawPreventionRestore
}
 

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 = ContentContextOptions::StencilMode::kIgnore
 
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 263 of file content_context.h.

Member Enumeration Documentation

◆ StencilMode

enum class impeller::ContentContextOptions::StencilMode : uint8_t
strong
Enumerator
kIgnore 

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

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.

kOverdrawPreventionIncrement 

For each fragment, increment the stencil value if it's currently zero. Discard fragments when the value is non-zero. This prevents self-overlapping strokes from drawing over themselves.

Note that this is done for rendering correctness, not performance. If a stroke is drawn with a backdrop-reliant blend and self-intersects, then the intersected geometry will render incorrectly when overdrawn because we don't adjust the geometry prevent self-intersection.

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

kOverdrawPreventionRestore 

Reset the stencil to a new maximum value specified by the ref (currently always 0).

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

Definition at line 264 of file content_context.h.

264 : uint8_t {
265 /// Turn the stencil test off. Used when drawing without stencil-then-cover
266 /// or overdraw prevention.
267 kIgnore,
268
269 // Operations used for stencil-then-cover.
270
271 /// Draw the stencil for the NonZero fill path rule.
272 ///
273 /// The stencil ref should always be 0 on commands using this mode.
275 /// Draw the stencil for the EvenOdd fill path rule.
276 ///
277 /// The stencil ref should always be 0 on commands using this mode.
279 /// Used for draw calls which fill in the stenciled area. Intended to be
280 /// used after `kStencilNonZeroFill` or `kStencilEvenOddFill` is used to set
281 /// up the stencil buffer. Also cleans up the stencil buffer by resetting
282 /// everything to zero.
283 ///
284 /// The stencil ref should always be 0 on commands using this mode.
286 /// The opposite of `kCoverCompare`. Used for draw calls which fill in the
287 /// non-stenciled area (intersection clips). Intended to be used after
288 /// `kStencilNonZeroFill` or `kStencilEvenOddFill` is used to set up the
289 /// stencil buffer. Also cleans up the stencil buffer by resetting
290 /// everything to zero.
291 ///
292 /// The stencil ref should always be 0 on commands using this mode.
294
295 // Operations used for the "overdraw prevention" mechanism. This is used for
296 // drawing strokes.
297
298 /// For each fragment, increment the stencil value if it's currently zero.
299 /// Discard fragments when the value is non-zero. This prevents
300 /// self-overlapping strokes from drawing over themselves.
301 ///
302 /// Note that this is done for rendering correctness, not performance. If a
303 /// stroke is drawn with a backdrop-reliant blend and self-intersects, then
304 /// the intersected geometry will render incorrectly when overdrawn because
305 /// we don't adjust the geometry prevent self-intersection.
306 ///
307 /// The stencil ref should always be 0 on commands using this mode.
309 /// Reset the stencil to a new maximum value specified by the ref (currently
310 /// always 0).
311 ///
312 /// The stencil ref should always be 0 on commands using this mode.
314 };

Member Function Documentation

◆ ApplyToPipelineDescriptor()

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

Definition at line 28 of file content_context.cc.

29 {
30 auto pipeline_blend = blend_mode;
32 VALIDATION_LOG << "Cannot use blend mode " << static_cast<int>(blend_mode)
33 << " as a pipeline blend.";
34 pipeline_blend = BlendMode::kSourceOver;
35 }
36
37 desc.SetSampleCount(sample_count);
38
39 ColorAttachmentDescriptor color0 = *desc.GetColorAttachmentDescriptor(0u);
40 color0.format = color_attachment_pixel_format;
41 color0.alpha_blend_op = BlendOperation::kAdd;
42 color0.color_blend_op = BlendOperation::kAdd;
43
44 switch (pipeline_blend) {
47 color0.alpha_blend_op = BlendOperation::kReverseSubtract;
48 color0.color_blend_op = BlendOperation::kReverseSubtract;
49 color0.dst_alpha_blend_factor = BlendFactor::kOne;
50 color0.dst_color_blend_factor = BlendFactor::kOne;
51 color0.src_alpha_blend_factor = BlendFactor::kDestinationColor;
52 color0.src_color_blend_factor = BlendFactor::kDestinationColor;
53 } else {
54 color0.dst_alpha_blend_factor = BlendFactor::kZero;
55 color0.dst_color_blend_factor = BlendFactor::kZero;
56 color0.src_alpha_blend_factor = BlendFactor::kZero;
57 color0.src_color_blend_factor = BlendFactor::kZero;
58 }
59 break;
61 color0.blending_enabled = false;
62 color0.dst_alpha_blend_factor = BlendFactor::kZero;
63 color0.dst_color_blend_factor = BlendFactor::kZero;
64 color0.src_alpha_blend_factor = BlendFactor::kOne;
65 color0.src_color_blend_factor = BlendFactor::kOne;
66 break;
68 color0.dst_alpha_blend_factor = BlendFactor::kOne;
69 color0.dst_color_blend_factor = BlendFactor::kOne;
70 color0.src_alpha_blend_factor = BlendFactor::kZero;
71 color0.src_color_blend_factor = BlendFactor::kZero;
72 break;
74 color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
75 color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
76 color0.src_alpha_blend_factor = BlendFactor::kOne;
77 color0.src_color_blend_factor = BlendFactor::kOne;
78 break;
80 color0.dst_alpha_blend_factor = BlendFactor::kOne;
81 color0.dst_color_blend_factor = BlendFactor::kOne;
82 color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
83 color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
84 break;
86 color0.dst_alpha_blend_factor = BlendFactor::kZero;
87 color0.dst_color_blend_factor = BlendFactor::kZero;
88 color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
89 color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
90 break;
92 color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
93 color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
94 color0.src_alpha_blend_factor = BlendFactor::kZero;
95 color0.src_color_blend_factor = BlendFactor::kZero;
96 break;
98 color0.dst_alpha_blend_factor = BlendFactor::kZero;
99 color0.dst_color_blend_factor = BlendFactor::kZero;
100 color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
101 color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
102 break;
104 color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
105 color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
106 color0.src_alpha_blend_factor = BlendFactor::kZero;
107 color0.src_color_blend_factor = BlendFactor::kZero;
108 break;
110 color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
111 color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
112 color0.src_alpha_blend_factor = BlendFactor::kDestinationAlpha;
113 color0.src_color_blend_factor = BlendFactor::kDestinationAlpha;
114 break;
116 color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
117 color0.dst_color_blend_factor = BlendFactor::kSourceAlpha;
118 color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
119 color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
120 break;
121 case BlendMode::kXor:
122 color0.dst_alpha_blend_factor = BlendFactor::kOneMinusSourceAlpha;
123 color0.dst_color_blend_factor = BlendFactor::kOneMinusSourceAlpha;
124 color0.src_alpha_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
125 color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
126 break;
127 case BlendMode::kPlus:
128 color0.dst_alpha_blend_factor = BlendFactor::kOne;
129 color0.dst_color_blend_factor = BlendFactor::kOne;
130 color0.src_alpha_blend_factor = BlendFactor::kOne;
131 color0.src_color_blend_factor = BlendFactor::kOne;
132 break;
134 color0.dst_alpha_blend_factor = BlendFactor::kSourceAlpha;
135 color0.dst_color_blend_factor = BlendFactor::kSourceColor;
136 color0.src_alpha_blend_factor = BlendFactor::kZero;
137 color0.src_color_blend_factor = BlendFactor::kZero;
138 break;
139 default:
141 }
142 desc.SetColorAttachmentDescriptor(0u, color0);
143
145 desc.ClearDepthAttachment();
146 desc.ClearStencilAttachments();
147 }
148
149 auto maybe_stencil = desc.GetFrontStencilAttachmentDescriptor();
150 auto maybe_depth = desc.GetDepthStencilAttachmentDescriptor();
151 FML_DCHECK(has_depth_stencil_attachments == maybe_depth.has_value())
152 << "Depth attachment doesn't match expected pipeline state. "
153 "has_depth_stencil_attachments="
155 FML_DCHECK(has_depth_stencil_attachments == maybe_stencil.has_value())
156 << "Stencil attachment doesn't match expected pipeline state. "
157 "has_depth_stencil_attachments="
159 if (maybe_stencil.has_value()) {
160 StencilAttachmentDescriptor front_stencil = maybe_stencil.value();
161 StencilAttachmentDescriptor back_stencil = front_stencil;
162
163 switch (stencil_mode) {
165 front_stencil.stencil_compare = CompareFunction::kAlways;
166 front_stencil.depth_stencil_pass = StencilOperation::kKeep;
167 desc.SetStencilAttachmentDescriptors(front_stencil);
168 break;
170 // The stencil ref should be 0 on commands that use this mode.
171 front_stencil.stencil_compare = CompareFunction::kAlways;
172 front_stencil.depth_stencil_pass = StencilOperation::kIncrementWrap;
173 back_stencil.stencil_compare = CompareFunction::kAlways;
174 back_stencil.depth_stencil_pass = StencilOperation::kDecrementWrap;
175 desc.SetStencilAttachmentDescriptors(front_stencil, back_stencil);
176 break;
178 // The stencil ref should be 0 on commands that use this mode.
179 front_stencil.stencil_compare = CompareFunction::kEqual;
180 front_stencil.depth_stencil_pass = StencilOperation::kIncrementWrap;
181 front_stencil.stencil_failure = StencilOperation::kDecrementWrap;
182 desc.SetStencilAttachmentDescriptors(front_stencil);
183 break;
185 // The stencil ref should be 0 on commands that use this mode.
186 front_stencil.stencil_compare = CompareFunction::kNotEqual;
187 front_stencil.depth_stencil_pass =
189 desc.SetStencilAttachmentDescriptors(front_stencil);
190 break;
192 // The stencil ref should be 0 on commands that use this mode.
193 front_stencil.stencil_compare = CompareFunction::kEqual;
194 front_stencil.stencil_failure = StencilOperation::kSetToReferenceValue;
195 desc.SetStencilAttachmentDescriptors(front_stencil);
196 break;
198 front_stencil.stencil_compare = CompareFunction::kEqual;
199 front_stencil.depth_stencil_pass = StencilOperation::kIncrementClamp;
200 desc.SetStencilAttachmentDescriptors(front_stencil);
201 break;
203 front_stencil.stencil_compare = CompareFunction::kLess;
204 front_stencil.depth_stencil_pass =
206 desc.SetStencilAttachmentDescriptors(front_stencil);
207 break;
208 }
209 }
210 if (maybe_depth.has_value()) {
211 DepthAttachmentDescriptor depth = maybe_depth.value();
212 depth.depth_write_enabled = depth_write_enabled;
213 depth.depth_compare = depth_compare;
214 desc.SetDepthStencilAttachmentDescriptor(depth);
215 }
216
217 desc.SetPrimitiveType(primitive_type);
218
220}
static constexpr BlendMode kLastPipelineBlendMode
Definition entity.h:23
#define FML_UNREACHABLE()
Definition logging.h:109
#define FML_DCHECK(condition)
Definition logging.h:103
@ 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.
@ 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.
#define VALIDATION_LOG
Definition validation.h:73

Member Data Documentation

◆ blend_mode

BlendMode impeller::ContentContextOptions::blend_mode = BlendMode::kSourceOver

Definition at line 317 of file content_context.h.

◆ color_attachment_pixel_format

PixelFormat impeller::ContentContextOptions::color_attachment_pixel_format = PixelFormat::kUnknown

Definition at line 321 of file content_context.h.

◆ depth_compare

CompareFunction impeller::ContentContextOptions::depth_compare = CompareFunction::kAlways

Definition at line 318 of file content_context.h.

◆ depth_write_enabled

bool impeller::ContentContextOptions::depth_write_enabled = false

Definition at line 323 of file content_context.h.

◆ has_depth_stencil_attachments

bool impeller::ContentContextOptions::has_depth_stencil_attachments = true

Definition at line 322 of file content_context.h.

◆ is_for_rrect_blur_clear

bool impeller::ContentContextOptions::is_for_rrect_blur_clear = false

Definition at line 325 of file content_context.h.

◆ primitive_type

PrimitiveType impeller::ContentContextOptions::primitive_type = PrimitiveType::kTriangle

Definition at line 320 of file content_context.h.

◆ sample_count

SampleCount impeller::ContentContextOptions::sample_count = SampleCount::kCount1

Definition at line 316 of file content_context.h.

◆ stencil_mode

StencilMode impeller::ContentContextOptions::stencil_mode = ContentContextOptions::StencilMode::kIgnore

Definition at line 319 of file content_context.h.

◆ wireframe

bool impeller::ContentContextOptions::wireframe = false

Definition at line 324 of file content_context.h.


The documentation for this struct was generated from the following files: