Skip to content

Commit 8a39ce4

Browse files
bors[bot]scoopr
andcommitted
Merge #2174
2174: metal: Hack to fix the first frame of a swapchain r=kvark a=scoopr The freeing up of the drawable now checks if there is anything to free from the has_swapchain boolean. The boolean is totally a hack, and might have some edge-cases where it is wrong, but this happens to fix warnings and red-frame flashes (present of not drawn frame) from the quad example, with the resizing still working. Fixes #issue PR checklist: - [ ] `make` succeeds (on *nix) - [ ] `make reftests` succeeds - [ ] tested examples with the following backends: Co-authored-by: Mikko Lehtonen <[email protected]>
2 parents 58459fd + 9a2e825 commit 8a39ce4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/backend/metal/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl Instance {
144144
window::Surface {
145145
inner: Arc::new(self.create_from_nsview(nsview)),
146146
apply_pixel_scale: false,
147+
has_swapchain: false
147148
}
148149
}
149150

@@ -153,6 +154,7 @@ impl Instance {
153154
window::Surface {
154155
inner: Arc::new(self.create_from_nsview(window.get_nsview())),
155156
apply_pixel_scale: true,
157+
has_swapchain: false,
156158
}
157159
}
158160
}

src/backend/metal/src/window.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub type CAMetalLayer = *mut Object;
2222
pub struct Surface {
2323
pub(crate) inner: Arc<SurfaceInner>,
2424
pub(crate) apply_pixel_scale: bool,
25+
pub(crate) has_swapchain: bool
2526
}
2627

2728
#[derive(Debug)]
@@ -274,14 +275,20 @@ impl Device {
274275
let texture: &metal::TextureRef = msg_send![drawable, texture];
275276
(drawable, texture)
276277
};
277-
if index == 0 {
278+
trace!("\tframe[{}] = {:?}", index, texture);
279+
280+
let drawable = if index == 0 && surface.has_swapchain {
278281
// when resizing, this trick frees up the currently shown frame
282+
// HACK: the has_swapchain is unfortunate, and might not be
283+
// correct in all cases.
279284
drawable.present();
280-
}
281-
trace!("\tframe[{}] = {:?}", index, texture);
285+
None
286+
} else {
287+
Some(drawable.to_owned())
288+
};
282289
Frame {
283290
inner: Mutex::new(FrameInner {
284-
drawable: Some(drawable.to_owned()),
291+
drawable: drawable,
285292
available: true,
286293
last_frame: 0,
287294
}),
@@ -307,6 +314,8 @@ impl Device {
307314
})
308315
.collect();
309316

317+
surface.has_swapchain = true;
318+
310319
let swapchain = Swapchain {
311320
frames: Arc::new(frames),
312321
surface: surface.inner.clone(),
@@ -315,6 +324,7 @@ impl Device {
315324
image_ready_callbacks: Vec::new(),
316325
};
317326

327+
318328
(swapchain, Backbuffer::Images(images))
319329
}
320330
}

0 commit comments

Comments
 (0)