tessera_ui/renderer/drawer/
command.rs

1//! Draw command traits and barrier requirements.
2//!
3//! This module defines the core traits and types for graphics rendering commands
4//! in the unified command system.
5
6use crate::{dyn_eq::DynPartialEqDraw, renderer::command::BarrierRequirement};
7
8/// Trait for graphics rendering commands that can be processed by draw pipelines.
9///
10/// Implement this trait for structs that represent graphics operations such as
11/// shape drawing, text rendering, image display, or custom visual effects.
12///
13/// # Example
14///
15/// ```
16/// use tessera_ui::{BarrierRequirement, DrawCommand};
17///
18/// #[derive(PartialEq, Clone)]
19/// struct RectangleCommand {
20///     color: [f32; 4],
21///     corner_radius: f32,
22/// }
23///
24/// impl DrawCommand for RectangleCommand {
25///     // Most commands don't need barriers
26///     fn barrier(&self) -> Option<BarrierRequirement> {
27///         None
28///     }
29/// }
30/// ```
31pub trait DrawCommand: DynPartialEqDraw + Send + Sync {
32    /// Specifies barrier requirements for this draw operation.
33    ///
34    /// Return `Some(BarrierRequirement::SampleBackground)` if your command needs
35    /// to sample from previously rendered content (e.g., for blur effects or
36    /// other post-processing operations).
37    ///
38    /// # Returns
39    ///
40    /// - `None` for standard rendering operations (default)
41    /// - `Some(BarrierRequirement::SampleBackground)` for operations that sample previous content
42    fn barrier(&self) -> Option<BarrierRequirement> {
43        None
44    }
45}