| 1 | use smithay::backend::renderer::element::{Element, Id, RenderElement}; |
| 2 | use smithay::backend::renderer::utils::CommitCounter; |
| 3 | use smithay::backend::renderer::Renderer; |
| 4 | use smithay::utils::user_data::UserDataMap; |
| 5 | use smithay::utils::{Buffer, Logical, Physical, Rectangle, Scale, Size}; |
| 6 | |
| 7 | #[derive(Debug, Clone)] |
| 8 | pub struct ExtraDamage { |
| 9 | id: Id, |
| 10 | commit: CommitCounter, |
| 11 | geometry: Rectangle<f64, Logical>, |
| 12 | } |
| 13 | |
| 14 | impl ExtraDamage { |
| 15 | pub fn new() -> Self { |
| 16 | Self { |
| 17 | id: Id::new(), |
| 18 | commit: Default::default(), |
| 19 | geometry: Default::default(), |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | pub fn damage_all(&mut self) { |
| 24 | self.commit.increment(); |
| 25 | } |
| 26 | |
| 27 | pub fn render(&self, geometry: Rectangle<f64, Logical>) -> Self { |
| 28 | let mut this = self.clone(); |
| 29 | this.geometry = geometry; |
| 30 | this |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl Default for ExtraDamage { |
| 35 | fn default() -> Self { |
| 36 | Self::new() |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl Element for ExtraDamage { |
| 41 | fn id(&self) -> &Id { |
| 42 | &self.id |
| 43 | } |
| 44 | |
| 45 | fn current_commit(&self) -> CommitCounter { |
| 46 | self.commit |
| 47 | } |
| 48 | |
| 49 | fn src(&self) -> Rectangle<f64, Buffer> { |
| 50 | Rectangle::from_size(Size::from((1., 1.))) |
| 51 | } |
| 52 | |
| 53 | fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> { |
| 54 | self.geometry.to_physical_precise_up(scale) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl<R: Renderer> RenderElement<R> for ExtraDamage { |
| 59 | fn draw( |
| 60 | &self, |
| 61 | _frame: &mut R::Frame<'_, '_>, |
| 62 | _src: Rectangle<f64, Buffer>, |
| 63 | _dst: Rectangle<i32, Physical>, |
| 64 | _damage: &[Rectangle<i32, Physical>], |
| 65 | _opaque_regions: &[Rectangle<i32, Physical>], |
| 66 | _cache: Option<&UserDataMap>, |
| 67 | ) -> Result<(), R::Error> { |
| 68 | Ok(()) |
| 69 | } |
| 70 | } |