824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 1 | use crate::Error; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 2 | use crate::image::{VulkanTarget, VulkanTexture}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 3 | use crate::pipeline::{Kind, Push}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 4 | use crate::renderer::VulkanRenderer; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 5 | use crate::transform::{rect_to_framebuffer, texture_uvs, to_framebuffer}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 6 | use ash::vk; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 7 | use smithay::backend::renderer::sync::SyncPoint; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 8 | use smithay::backend::renderer::{Color32F, ContextId, Frame, Texture}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 9 | use smithay::utils::{Buffer, Physical, Rectangle, Size, Transform}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 10 | use std::sync::Arc; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 11 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 12 | pub(crate) enum Op { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 13 | Clear { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 14 | color: [f32; 4], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 15 | rects: Vec<vk::Rect2D>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 16 | }, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 17 | Draw { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 18 | kind: Kind, |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 19 | opaque: bool, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 20 | texture: Option<VulkanTexture>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 21 | push: Push, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 22 | scissors: Vec<vk::Rect2D>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 23 | }, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 24 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 25 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 26 | /// A frame in progress. Draws are recorded and submitted together by [`Frame::finish`]. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 27 | pub struct VulkanFrame<'frame, 'buffer> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 28 | renderer: &'frame mut VulkanRenderer, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 29 | target: &'frame mut VulkanTarget<'buffer>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 30 | output: Size<i32, Physical>, |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 31 | /// The output rotated into the space draws are given in, which differs |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 32 | /// from `output` for 90 and 270 degree transforms. |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 33 | area: Size<i32, Physical>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 34 | transform: Transform, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 35 | ops: Vec<Op>, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 36 | clip: Option<Clip>, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 37 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 38 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 39 | /// A rounded rect in output space that later draws are cut to, until |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 40 | /// [`VulkanFrame::set_clip`] changes it. A nonzero `ring` keeps only a band |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 41 | /// that wide inside the edge. |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 42 | #[derive(Clone, Copy, Debug, PartialEq)] |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 43 | pub struct Clip { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 44 | pub rect: Rectangle<i32, Physical>, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 45 | /// Top left, top right, bottom right and bottom left, in pixels. |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 46 | pub radii: [f32; 4], |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 47 | pub ring: f32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 48 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 49 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 50 | impl std::fmt::Debug for VulkanFrame<'_, '_> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 51 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 52 | f.debug_struct("VulkanFrame") |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 53 | .field("output", &self.output) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 54 | .field("ops", &self.ops.len()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 55 | .finish() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 56 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 57 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 58 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 59 | impl<'frame, 'buffer> VulkanFrame<'frame, 'buffer> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 60 | pub(crate) fn new( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 61 | renderer: &'frame mut VulkanRenderer, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 62 | target: &'frame mut VulkanTarget<'buffer>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 63 | output: Size<i32, Physical>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 64 | transform: Transform, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 65 | ) -> Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 66 | Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 67 | renderer, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 68 | target, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 69 | output, |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 70 | area: transform.transform_size(output), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 71 | transform, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 72 | ops: Vec::new(), |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 73 | clip: None, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 74 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 75 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 76 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 77 | pub fn set_clip(&mut self, clip: Option<Clip>) { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 78 | self.clip = clip; |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 79 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 80 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 81 | /// The clip's push constants in framebuffer space, where an output |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 82 | /// transform moves each radius to another corner. |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 83 | fn clip_push(&self) -> ([f32; 4], [f32; 4], [f32; 4]) { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 84 | let Some(c) = self.clip else { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 85 | return ([0.0; 4], [0.0; 4], [0.0; 4]); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 86 | }; |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 87 | let [tl, tr, br, bl] = c.radii; |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 88 | let corners = [[tl, 0.0], [tr, 0.0], [bl, 0.0], [br, 0.0]]; |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 89 | let (fb, r) = to_framebuffer(c.rect, corners, self.area, self.transform); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 90 | let rect = [ |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 91 | fb.loc.x as f32, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 92 | fb.loc.y as f32, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 93 | fb.size.w as f32, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 94 | fb.size.h as f32, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 95 | ]; |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 96 | let most = fb.size.w.min(fb.size.h) as f32 / 2.0; |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 97 | let radii = [r[0][0], r[1][0], r[3][0], r[2][0]].map(|r| r.min(most)); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 98 | (rect, radii, [c.ring, 0.0, 0.0, 0.0]) |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 99 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 100 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 101 | fn fb_size(&self) -> Size<i32, Physical> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 102 | (self.target.width() as i32, self.target.height() as i32).into() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 103 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 104 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 105 | fn fb_rect(&self, r: Rectangle<i32, Physical>) -> Option<vk::Rect2D> { |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 106 | let r = rect_to_framebuffer(r, self.area, self.transform) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 107 | .intersection(Rectangle::from_size(self.fb_size()))?; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 108 | Some(vk::Rect2D { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 109 | offset: vk::Offset2D { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 110 | x: r.loc.x, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 111 | y: r.loc.y, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 112 | }, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 113 | extent: vk::Extent2D { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 114 | width: r.size.w as u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 115 | height: r.size.h as u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 116 | }, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 117 | }) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 118 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 119 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 120 | fn scissors( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 121 | &self, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 122 | dst: Rectangle<i32, Physical>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 123 | damage: &[Rectangle<i32, Physical>], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 124 | ) -> Vec<vk::Rect2D> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 125 | damage |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 126 | .iter() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 127 | .filter_map(|d| d.intersection(Rectangle::from_size(dst.size))) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 128 | .filter_map(|mut d| { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 129 | d.loc += dst.loc; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 130 | self.fb_rect(d) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 131 | }) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 132 | .collect() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 133 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 134 | |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 135 | /// Draws a texture through the transition hook in `shaders/effect.frag`. |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 136 | #[expect(clippy::too_many_arguments)] |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 137 | pub fn render_effect( |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 138 | &mut self, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 139 | texture: &VulkanTexture, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 140 | src: Rectangle<f64, Buffer>, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 141 | dst: Rectangle<i32, Physical>, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 142 | damage: &[Rectangle<i32, Physical>], |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 143 | src_transform: Transform, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 144 | alpha: f32, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 145 | effect: Effect, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 146 | ) -> Result<(), Error> { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 147 | let params = [effect.progress, effect.kind as u32 as f32, 0.0, 0.0]; |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 148 | self.draw_texture( |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 149 | texture, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 150 | src, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 151 | dst, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 152 | damage, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 153 | src_transform, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 154 | alpha, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 155 | Kind::Effect, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 156 | params, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 157 | ) |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 158 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 159 | |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 160 | #[expect(clippy::too_many_arguments)] |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 161 | fn draw_texture( |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 162 | &mut self, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 163 | texture: &VulkanTexture, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 164 | src: Rectangle<f64, Buffer>, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 165 | dst: Rectangle<i32, Physical>, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 166 | damage: &[Rectangle<i32, Physical>], |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 167 | src_transform: Transform, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 168 | alpha: f32, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 169 | kind: Kind, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 170 | effect: [f32; 4], |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 171 | ) -> Result<(), Error> { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 172 | if !Arc::ptr_eq(&texture.0.shared, self.renderer.shared()) { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 173 | return Err(Error::ForeignTexture); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 174 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 175 | if dst.size.w <= 0 || dst.size.h <= 0 || Arc::ptr_eq(&texture.0, &self.target.0) { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 176 | return Ok(()); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 177 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 178 | let scissors = self.scissors(dst, damage); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 179 | if scissors.is_empty() { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 180 | return Ok(()); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 181 | } |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 182 | let mut uvs = texture_uvs(src, dst.size, texture.size(), src_transform); |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 183 | if texture.0.y_inverted { |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 184 | for uv in &mut uvs { |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 185 | uv[1] = 1.0 - uv[1]; |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 186 | } |
b03e3b32603a | atagen | 2026-10-19 07:40 UTC | 187 | } |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 188 | let (fb, uv) = to_framebuffer(dst, uvs, self.area, self.transform); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 189 | let (clip, radii, ring) = self.clip_push(); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 190 | let push = Push { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 191 | dst: self.ndc(fb), |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 192 | uv, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 193 | color: [1.0, 1.0, 1.0, alpha], |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 194 | effect, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 195 | clip, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 196 | radii, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 197 | ring, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 198 | }; |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 199 | self.ops.push(Op::Draw { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 200 | kind, |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 201 | opaque: kind == Kind::Texture |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 202 | && alpha >= 1.0 |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 203 | && self.clip.is_none() |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 204 | && texture.0.opaque(), |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 205 | texture: Some(texture.clone()), |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 206 | push, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 207 | scissors, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 208 | }); |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 209 | Ok(()) |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 210 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 211 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 212 | fn ndc(&self, r: Rectangle<i32, Physical>) -> [f32; 4] { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 213 | let fb = self.fb_size(); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 214 | let (w, h) = (fb.w as f32, fb.h as f32); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 215 | [ |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 216 | r.loc.x as f32 / w * 2.0 - 1.0, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 217 | r.loc.y as f32 / h * 2.0 - 1.0, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 218 | r.size.w as f32 / w * 2.0, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 219 | r.size.h as f32 / h * 2.0, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 220 | ] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 221 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 222 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 223 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 224 | impl Frame for VulkanFrame<'_, '_> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 225 | type Error = Error; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 226 | type TextureId = VulkanTexture; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 227 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 228 | fn context_id(&self) -> ContextId<VulkanTexture> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 229 | self.renderer.context_id_ref().clone() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 230 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 231 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 232 | fn clear(&mut self, color: Color32F, at: &[Rectangle<i32, Physical>]) -> Result<(), Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 233 | let rects: Vec<_> = at.iter().filter_map(|r| self.fb_rect(*r)).collect(); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 234 | if !rects.is_empty() { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 235 | self.ops.push(Op::Clear { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 236 | color: color.components(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 237 | rects, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 238 | }); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 239 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 240 | Ok(()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 241 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 242 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 243 | fn draw_solid( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 244 | &mut self, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 245 | dst: Rectangle<i32, Physical>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 246 | damage: &[Rectangle<i32, Physical>], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 247 | color: Color32F, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 248 | ) -> Result<(), Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 249 | let scissors = self.scissors(dst, damage); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 250 | if scissors.is_empty() { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 251 | return Ok(()); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 252 | } |
0b68ce424a32 | atagen | 2026-10-18 03:17 UTC | 253 | let (fb, _) = to_framebuffer(dst, [[0.0; 2]; 4], self.area, self.transform); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 254 | let (clip, radii, ring) = self.clip_push(); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 255 | let push = Push { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 256 | dst: self.ndc(fb), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 257 | uv: [[0.0; 2]; 4], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 258 | color: color.components(), |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 259 | effect: [0.0; 4], |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 260 | clip, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 261 | radii, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 262 | ring, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 263 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 264 | self.ops.push(Op::Draw { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 265 | kind: Kind::Solid, |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 266 | opaque: color.a() >= 1.0 && self.clip.is_none(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 267 | texture: None, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 268 | push, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 269 | scissors, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 270 | }); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 271 | Ok(()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 272 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 273 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 274 | fn render_texture_from_to( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 275 | &mut self, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 276 | texture: &VulkanTexture, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 277 | src: Rectangle<f64, Buffer>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 278 | dst: Rectangle<i32, Physical>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 279 | damage: &[Rectangle<i32, Physical>], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 280 | _opaque_regions: &[Rectangle<i32, Physical>], |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 281 | src_transform: Transform, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 282 | alpha: f32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 283 | ) -> Result<(), Error> { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 284 | self.draw_texture( |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 285 | texture, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 286 | src, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 287 | dst, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 288 | damage, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 289 | src_transform, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 290 | alpha, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 291 | Kind::Texture, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 292 | [0.0; 4], |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 293 | ) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 294 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 295 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 296 | fn transformation(&self) -> Transform { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 297 | self.transform |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 298 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 299 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 300 | fn output_size(&self) -> Size<i32, Physical> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 301 | self.output |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 302 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 303 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 304 | fn wait(&mut self, sync: &SyncPoint) -> Result<(), Error> { |
6dfb54e27e7f | atagen | 2026-10-19 07:53 UTC | 305 | sync.wait().map_err(|_| crate::error::wait_error()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 306 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 307 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 308 | fn finish(mut self) -> Result<SyncPoint, Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 309 | let ops = std::mem::take(&mut self.ops); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 310 | self.renderer.submit(self.target, ops) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 311 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 312 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 313 | |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 314 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 315 | pub enum Transition { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 316 | Move = 0, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 317 | Spawn = 1, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 318 | Close = 2, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 319 | } |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 320 | |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 321 | /// A window transition for the effect shader, with `progress` in [0, 1]. |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 322 | #[derive(Clone, Copy, Debug, PartialEq)] |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 323 | pub struct Effect { |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 324 | pub kind: Transition, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 325 | pub progress: f32, |
96db497859dc | atagen | 2026-10-16 11:27 UTC | 326 | } |