Skip to content

Commit 892ac1c

Browse files
authored
Merge pull request #2849 from iced-rs/pre-present-notify
Notify `window` before presentation
2 parents 363b0e9 + 31b98ee commit 892ac1c

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

graphics/src/compositor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub trait Compositor: Sized {
8080
viewport: &Viewport,
8181
background_color: Color,
8282
overlay: &[T],
83+
on_pre_present: impl FnOnce(),
8384
) -> Result<(), SurfaceError>;
8485

8586
/// Screenshots the current [`Renderer`] primitives to an offscreen texture, and returns the bytes of
@@ -193,6 +194,7 @@ impl Compositor for () {
193194
_viewport: &Viewport,
194195
_background_color: Color,
195196
_overlay: &[T],
197+
_on_pre_present: impl FnOnce(),
196198
) -> Result<(), SurfaceError> {
197199
Ok(())
198200
}

renderer/src/fallback.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ where
322322
viewport: &graphics::Viewport,
323323
background_color: Color,
324324
overlay: &[T],
325+
on_pre_present: impl FnOnce(),
325326
) -> Result<(), compositor::SurfaceError> {
326327
match (self, renderer, surface) {
327328
(
@@ -334,6 +335,7 @@ where
334335
viewport,
335336
background_color,
336337
overlay,
338+
on_pre_present,
337339
),
338340
(
339341
Self::Secondary(compositor),
@@ -345,6 +347,7 @@ where
345347
viewport,
346348
background_color,
347349
overlay,
350+
on_pre_present,
348351
),
349352
_ => unreachable!(),
350353
}

tiny_skia/src/window/compositor.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,16 @@ impl crate::graphics::Compositor for Compositor {
114114
viewport: &Viewport,
115115
background_color: Color,
116116
overlay: &[T],
117+
on_pre_present: impl FnOnce(),
117118
) -> Result<(), compositor::SurfaceError> {
118-
present(renderer, surface, viewport, background_color, overlay)
119+
present(
120+
renderer,
121+
surface,
122+
viewport,
123+
background_color,
124+
overlay,
125+
on_pre_present,
126+
)
119127
}
120128

121129
fn screenshot<T: AsRef<str>>(
@@ -146,6 +154,7 @@ pub fn present<T: AsRef<str>>(
146154
viewport: &Viewport,
147155
background_color: Color,
148156
overlay: &[T],
157+
on_pre_present: impl FnOnce(),
149158
) -> Result<(), compositor::SurfaceError> {
150159
let physical_size = viewport.physical_size();
151160

@@ -206,6 +215,7 @@ pub fn present<T: AsRef<str>>(
206215
overlay,
207216
);
208217

218+
on_pre_present();
209219
buffer.present().map_err(|_| compositor::SurfaceError::Lost)
210220
}
211221

wgpu/src/window/compositor.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub fn present<T: AsRef<str>>(
221221
viewport: &Viewport,
222222
background_color: Color,
223223
overlay: &[T],
224+
on_pre_present: impl FnOnce(),
224225
) -> Result<(), compositor::SurfaceError> {
225226
match surface.get_current_texture() {
226227
Ok(frame) => {
@@ -249,6 +250,7 @@ pub fn present<T: AsRef<str>>(
249250
let _ = compositor.engine.submit(&compositor.queue, encoder);
250251

251252
// Present the frame
253+
on_pre_present();
252254
frame.present();
253255

254256
Ok(())
@@ -365,8 +367,17 @@ impl graphics::Compositor for Compositor {
365367
viewport: &Viewport,
366368
background_color: Color,
367369
overlay: &[T],
370+
on_pre_present: impl FnOnce(),
368371
) -> Result<(), compositor::SurfaceError> {
369-
present(self, renderer, surface, viewport, background_color, overlay)
372+
present(
373+
self,
374+
renderer,
375+
surface,
376+
viewport,
377+
background_color,
378+
overlay,
379+
on_pre_present,
380+
)
370381
}
371382

372383
fn screenshot<T: AsRef<str>>(

winit/src/program.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ async fn run_instance<P, C>(
892892
window.state.viewport(),
893893
window.state.background_color(),
894894
&debug.overlay(),
895+
|| window.raw.pre_present_notify(),
895896
) {
896897
Ok(()) => {
897898
debug.render_finished();

0 commit comments

Comments
 (0)