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
24 changes: 22 additions & 2 deletions crates/canvas-core/src/gpu/gl/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,34 @@ impl EAGLContext {
}

/// Stores the bound renderbuffer in `layer` (a `CAEAGLLayer`), at the layer's size in pixels.
/// This sets the layer's `contents`, so see [`change_view_layer`].
pub fn renderbuffer_storage_from_drawable(&self, layer: &NSObject) -> bool {
let result: BOOL = unsafe {
let result: BOOL = change_view_layer(|| unsafe {
msg_send![&self.0, renderbufferStorage: 0x8d41 as NSUInteger, fromDrawable: layer]
};
});
result.into()
}
}

/// Modifies a UIView's backing layer from any thread. Off main, UIKit rejects the layer's action
/// lookup; disabling actions skips it, and the explicit commit applies the change.
pub fn change_view_layer<R>(change: impl FnOnce() -> R) -> R {
let is_main: bool = unsafe { msg_send![class!(NSThread), isMainThread] };
if is_main {
return change();
}
let transaction = class!(CATransaction);
unsafe {
let _: () = msg_send![transaction, begin];
let _: () = msg_send![transaction, setDisableActions: true];
}
let result = change();
unsafe {
let _: () = msg_send![transaction, commit];
}
result
}

type DiscardFramebuffer = unsafe extern "C" fn(target: u32, count: i32, attachments: *const u32);

/// `glDiscardFramebufferEXT`, for GLES2 contexts, which lack `glInvalidateFramebuffer`.
Expand Down
Binary file modified packages/canvas/platforms/android/canvas-release.aar
Binary file not shown.
20 changes: 10 additions & 10 deletions packages/canvas/platforms/ios/CanvasNative.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>xros-arm64</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<string>xros</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>CanvasNative.framework/CanvasNative</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>xros-arm64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>CanvasNative.framework/CanvasNative</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>tvos-arm64</string>
<string>xros-arm64-simulator</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>tvos</string>
<string>xros</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
Expand Down Expand Up @@ -97,15 +97,15 @@
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>xros-arm64</string>
<string>tvos-arm64</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>xros</string>
<string>tvos</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Loading