tessera_ui_basic_components/pipelines/image/
command.rs

1use std::{
2    hash::{Hash, Hasher},
3    sync::Arc,
4};
5
6use tessera_ui::DrawCommand;
7
8/// Image pixel data for rendering.
9///
10/// # Fields
11/// - `data`: Raw pixel data (RGBA).
12/// - `width`: Image width in pixels.
13/// - `height`: Image height in pixels.
14///
15/// # Example
16/// ```rust,ignore
17/// use tessera_ui_basic_components::pipelines::image::ImageData;
18/// let img = ImageData { data: Arc::new(vec![255, 0, 0, 255]), width: 1, height: 1 };
19/// ```
20#[derive(Debug, Clone)]
21pub struct ImageData {
22    pub data: Arc<Vec<u8>>,
23    pub width: u32,
24    pub height: u32,
25}
26
27impl Hash for ImageData {
28    fn hash<H: Hasher>(&self, state: &mut H) {
29        self.data.as_ref().hash(state);
30        self.width.hash(state);
31        self.height.hash(state);
32    }
33}
34
35impl PartialEq for ImageData {
36    fn eq(&self, other: &Self) -> bool {
37        self.width == other.width
38            && self.height == other.height
39            && self.data.as_ref() == other.data.as_ref()
40    }
41}
42
43impl Eq for ImageData {}
44
45/// Command for rendering an image in a UI component.
46///
47/// # Example
48/// ```rust,ignore
49/// use tessera_ui_basic_components::pipelines::image::{ImageCommand, ImageData};
50/// let cmd = ImageCommand { data: img_data };
51/// ```
52#[derive(Debug, Clone, Hash, PartialEq, Eq)]
53pub struct ImageCommand {
54    pub data: Arc<ImageData>,
55}
56
57impl DrawCommand for ImageCommand {
58    fn barrier(&self) -> Option<tessera_ui::BarrierRequirement> {
59        // This command does not require any specific barriers.
60        None
61    }
62}