| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | use super::*; |
| 5 | |
| 6 | pub use crate::graphics::{CompositionMode, TexturePixelFormat}; |
| 7 | |
| 8 | /// This structure describes the properties of a texture for blending with [`TargetPixelBuffer::draw_texture`]. |
| 9 | #[allow (dead_code)] |
| 10 | #[non_exhaustive ] |
| 11 | pub struct Texture<'a> { |
| 12 | /// A reference to the pixel bytes of the texture. These bytes are in the format specified by `pixel_format`. |
| 13 | pub bytes: &'a [u8], |
| 14 | /// The pixel format of the texture. |
| 15 | pub pixel_format: TexturePixelFormat, |
| 16 | /// The number of pixels per horizontal line of the texture. |
| 17 | pub pixel_stride: u16, |
| 18 | /// The width of the texture in pixels. |
| 19 | pub width: u16, |
| 20 | /// The height of the texture in pixels. |
| 21 | pub height: u16, |
| 22 | /// The delta to apply to the source x coordinate between pixels when drawing the texture. |
| 23 | /// This is used when scaling the texture. The delta is specified in 8:8 fixed point format. |
| 24 | pub delta_x: u16, |
| 25 | /// The delta to apply to the source y coordinate between pixels when drawing the texture. |
| 26 | /// This is used when scaling the texture. The delta is specified in 8:8 fixed point format. |
| 27 | pub delta_y: u16, |
| 28 | /// The offset within the texture to start reading pixels from in the x direction. The |
| 29 | /// offset is specified in 12:4 fixed point format. |
| 30 | pub source_offset_x: u16, |
| 31 | /// The offset within the texture to start reading pixels from in the y direction. The |
| 32 | /// offset is specified in 12:4 fixed point format. |
| 33 | pub source_offset_y: u16, |
| 34 | } |
| 35 | |
| 36 | /// This trait represents access to a buffer of pixels the software renderer can render into, as well |
| 37 | /// as certain operations that the renderer will try to delegate to this trait. Implement these functions |
| 38 | /// to delegate rendering further to hardware-provided 2D acceleration units, such as DMA2D or PXP. |
| 39 | pub trait TargetPixelBuffer { |
| 40 | /// The pixel type the buffer represents. |
| 41 | type TargetPixel: TargetPixel; |
| 42 | |
| 43 | /// Returns a slice of pixels for the given line. |
| 44 | fn line_slice(&mut self, line_numer: usize) -> &mut [Self::TargetPixel]; |
| 45 | |
| 46 | /// Returns the number of lines the buffer has. This is typically the height in pixels. |
| 47 | fn num_lines(&self) -> usize; |
| 48 | |
| 49 | /// Fills the buffer with a rectangle at the specified position with the given size and the |
| 50 | /// provided color. Returns true if the operation was successful; false if it could not be |
| 51 | /// implemented and instead the software renderer needs to draw the rectangle. |
| 52 | fn fill_rectangle( |
| 53 | &mut self, |
| 54 | _x: i16, |
| 55 | _y: i16, |
| 56 | _width: i16, |
| 57 | _height: i16, |
| 58 | _color: PremultipliedRgbaColor, |
| 59 | _composition_mode: CompositionMode, |
| 60 | ) -> bool { |
| 61 | false |
| 62 | } |
| 63 | |
| 64 | /// Draw a texture into the buffer at the specified position with the given size and |
| 65 | /// colorized if needed. Returns true if the operation was successful; false if it could not be |
| 66 | /// implemented and instead the software renderer needs to draw the texture |
| 67 | fn draw_texture( |
| 68 | &mut self, |
| 69 | _x: i16, |
| 70 | _y: i16, |
| 71 | _width: i16, |
| 72 | _height: i16, |
| 73 | _src_texture: Texture<'_>, |
| 74 | _colorize: u32, |
| 75 | _alpha: u8, |
| 76 | _rotation: RenderingRotation, |
| 77 | _composition_mode: CompositionMode, |
| 78 | ) -> bool { |
| 79 | false |
| 80 | } |
| 81 | } |
| 82 | |