1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
use std::cell::OnceCell;
use niri_config::BlockOutFrom;
use smithay::backend::allocator::Fourcc;
use smithay::backend::renderer::element::{Kind, RenderElement};
use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size, Transform};
use super::{render_to_encompassing_texture, RenderTarget, ToRenderElement};
/// Snapshot of a render.
#[derive(Debug)]
pub struct RenderSnapshot<C, B> {
/// Contents for a normal render.
///
/// Relative to the geometry.
pub contents: Vec<C>,
/// Blocked-out contents.
///
/// Relative to the geometry.
pub blocked_out_contents: Vec<B>,
/// Where the contents were blocked out from at the time of the snapshot.
pub block_out_from: Option<BlockOutFrom>,
/// Visual size of the element at the point of the snapshot.
pub size: Size<f64, Logical>,
/// Contents rendered into a texture (lazily).
pub texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,
/// Blocked-out contents rendered into a texture (lazily).
pub blocked_out_texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,
}
impl<C, B, EC, EB> RenderSnapshot<C, B>
where
C: ToRenderElement<RenderElement = EC>,
B: ToRenderElement<RenderElement = EB>,
EC: RenderElement<GlesRenderer>,
EB: RenderElement<GlesRenderer>,
{
pub fn texture(
&self,
renderer: &mut GlesRenderer,
scale: Scale<f64>,
target: RenderTarget,
) -> Option<&(GlesTexture, Rectangle<i32, Physical>)> {
if target.should_block_out(self.block_out_from) {
self.blocked_out_texture.get_or_init(|| {
let _span = tracy_client::span!("RenderSnapshot::Texture");
let elements: Vec<_> = self
.blocked_out_contents
.iter()
.map(|baked| {
baked.to_render_element(Point::from((0., 0.)), scale, 1., Kind::Unspecified)
})
.collect();
match render_to_encompassing_texture(
renderer,
scale,
Transform::Normal,
Fourcc::Abgr8888,
&elements,
) {
Ok((texture, _sync_point, geo)) => Some((texture, geo)),
Err(err) => {
warn!("error rendering blocked-out contents to texture: {err:?}");
None
}
}
})
} else {
self.texture.get_or_init(|| {
let _span = tracy_client::span!("RenderSnapshot::Texture");
let elements: Vec<_> = self
.contents
.iter()
.map(|baked| {
baked.to_render_element(Point::from((0., 0.)), scale, 1., Kind::Unspecified)
})
.collect();
match render_to_encompassing_texture(
renderer,
scale,
Transform::Normal,
Fourcc::Abgr8888,
&elements,
) {
Ok((texture, _sync_point, geo)) => Some((texture, geo)),
Err(err) => {
warn!("error rendering contents to texture: {err:?}");
None
}
}
})
}
.as_ref()
}
}
|