Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/canvas-2d/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ impl Context {
self.surface_data.scale
}

// Acquiring the next drawable during presentation can block the display-link
// callback on tvOS. Keep the previous surface until the next operation needs
// to draw, then retain its contents when swapping the backing texture.
#[inline]
/// Runs before every draw. Skia uploads a raster image the moment a draw records it (a pattern
/// fill, say), so another canvas's GL context being current puts the texture in the wrong one.
Expand All @@ -397,8 +394,13 @@ impl Context {
if let Some(ref context) = self.gl_context {
context.make_current();
}
#[cfg(all(feature = "metal", target_os = "tvos"))]
if self.metal_context.as_ref().is_some_and(|c| !c.has_current_drawable()) {
// A drawable is taken only when the frame first draws; see `Context::present`.
#[cfg(feature = "metal")]
if self
.metal_context
.as_ref()
.is_some_and(|c| !c.is_offscreen() && !c.has_current_drawable())
{
Self::acquire_drawable(self);
}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/canvas-2d/src/context/surface_metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,17 @@ impl Context {
}
}

/// The next drawable is taken on the next draw (`bind_surface`), not here: holding one
/// between frames starves the layer's pool. `replace_backend_texture` keeps the contents.
pub fn present(context: &mut Context) {
let _ = MetalContext::new_release_pool();

if let Some(context) = context.metal_context.as_mut() {
context.present_drawable();
}

#[cfg(not(target_os = "tvos"))]
Self::acquire_drawable(context);
}

pub(crate) fn acquire_drawable(context: &mut Context) {
#[cfg(target_os = "tvos")]
let _pool = MetalContext::new_release_pool();
let mut info: Option<TextureInfo> = None;
let mut width = 0;
Expand Down
4 changes: 3 additions & 1 deletion crates/canvas-c/src/offscreen/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ fn set_drawable_properties(layer: &ObjRef, retained: bool) {
forKeys: keys.as_ptr(),
count: 2usize
];
let _: () = msg_send![&*layer.0, setDrawableProperties: properties];
canvas_core::gpu::gl::change_view_layer(|| {
let _: () = msg_send![&*layer.0, setDrawableProperties: properties];
});
});
}

Expand Down
Loading
Loading