Skip to content

Commit 23dbec7

Browse files
committed
Merge branch 'master' into v3-v8
Brings in #144-#149. Conflict resolution notes: * #147 (V8 14 native bridge) overlapped almost entirely with the V8 14 migration this branch already carries. Both sides fix the same API break; master does it with dual-version shims (canvas::GetAlignedPointer, canvas::Receiver, CANVAS_FAST_FUNCTION, #if V8_MAJOR_VERSION >= 14) so one tree can build against V8 10.3 and 14, while this branch targets a single vendored V8 14.9 (tools/scripts/download-v8.sh) and calls the native APIs directly. 118 of the 127 conflicting sources were that difference alone -- after rewriting master's shims into this branch's idiom, 112 compared byte-identical -- so those keep this branch's spelling and the now-unused shim block is dropped from Common.h. * Master's shims also compile fast API calls out on V8 >= 14 (CANVAS_FAST_FUNCTION -> v8::CFunction{}, c_function -> nullptr). V8 14.9 still declares both FunctionTemplate::New(..., const CFunction*) and NewWithCFunctionOverloads, and this branch's fast paths are built against it, so taking that would have silently disabled every fast call in the binding layer. Helpers.h keeps this branch's version; the four CANVAS_FAST_FUNCTION call sites that auto-merged into OES_vertex_array_objectImpl and WEBGL_draw_buffersImpl -- no conflict was raised for those -- are restored to v8::CFunction::Make. * Master's *Array fast overloads are all guarded #if V8_MAJOR_VERSION < 14, so they are dead on 14 and equivalent to this branch having removed them. * #149 (ImageData double free) applies unchanged. canvas_native_image_data_get_data borrows its argument and returns a U8Buffer holding a second refcounted handle to the same pixels, so ImageDataBuffer must release only the buffer -- ~ImageDataImpl already releases the ImageData. The comment is reworded from master's, which described the buffer as owning a clone of the pixel storage; it is a shared handle, and that is what makes the JS data view live. * Package versions stay on the 3.0.0-alpha line. * canvas-release.aar keeps this branch's binary; it predates the Android render fixes in 638a265 and needs rebuilding from the merged sources.
2 parents 61b69db + db60569 commit 23dbec7

51 files changed

Lines changed: 622 additions & 101 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CanvasNative.podspec‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313

1414
s.author = { "Osei Fortune" => "fortune.osei@yahoo.com" }
1515

16-
s.platforms = { :ios => "13.0", :visionos => "1.0" }
16+
s.platforms = { :ios => "13.0", :tvos => "13.0", :visionos => "1.0" }
1717

1818
s.source = { :git => "https://github.com/nativescript/canvas.git", :tag => "#{s.version}" }
1919

‎Makefile‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
22
ARCHS_VISIONOS = aarch64-apple-visionos aarch64-apple-visionos-sim
3+
ARCHS_TVOS = aarch64-apple-tvos aarch64-apple-tvos-sim
34
ARCHS_ANDROID = i686-linux-android x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
45

56
XCFRAMEWORK = CanvasNative.xcframework
@@ -11,6 +12,8 @@ ios: $(XCFRAMEWORK)
1112

1213
visionos: $(ARCHS_VISIONOS)
1314

15+
tvos: $(ARCHS_TVOS)
16+
1417
android: GENERATE_ANDROID
1518

1619
ios-svg: GENERATE_IOS_SVG
@@ -47,6 +50,12 @@ $(ARCHS_VISIONOS): %:
4750
cargo +nightly build -Z build-std='std,panic_abort' \
4851
--target $@ --release -p canvas-ios
4952

53+
.PHONY: $(ARCHS_TVOS)
54+
$(ARCHS_TVOS): %:
55+
RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \
56+
cargo +nightly build -Z build-std='std,panic_abort' \
57+
--target $@ --release -p canvas-ios
58+
5059
.PHONY: $(ARCHS_ANDROID)
5160
$(ARCHS_ANDROID): %:
5261
./tools/scripts/build-android.sh $@

‎Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import PackageDescription
1717

1818
let package = Package(
1919
name: "CanvasNative",
20-
platforms: [.iOS(.v12), .visionOS(.v1)],
20+
platforms: [.iOS(.v12), .tvOS(.v12), .visionOS(.v1)],
2121
products: [
2222
.library(name: "NativeScriptV8", targets: ["NativeScriptV8"]),
2323
],

‎crates/canvas-2d/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ raw-window-handle.workspace = true
2626
bitflags = "2.6.0"
2727
regex-lite = { workspace = true }
2828

29-
[target.'cfg(any(target_os = "ios", target_os="macos", target_os = "visionos"))'.dependencies]
29+
[target.'cfg(any(target_os = "ios", target_os="macos", target_os = "visionos", target_os = "tvos"))'.dependencies]
3030
foreign-types-shared = "0.3.1"
3131
objc2 = {workspace = true}
3232
objc2-foundation = { workspace = true }

‎crates/canvas-2d/src/context/drawing_images/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Context {
191191
}
192192

193193
pub fn draw_image_dx_dy(&mut self, image: &Image, x: f32, y: f32) {
194-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
194+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
195195
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
196196
#[cfg(feature = "gl")]
197197
{
@@ -221,7 +221,7 @@ impl Context {
221221
}
222222

223223
fn draw_image(&mut self, image: &Image, src_rect: impl Into<Rect>, dst_rect: impl Into<Rect>) {
224-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
224+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
225225
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
226226
#[cfg(feature = "gl")]
227227
{
@@ -259,7 +259,7 @@ impl Context {
259259
}
260260

261261
fn draw_image_with_rect(&mut self, image: &Image, dst_rect: impl Into<Rect>) {
262-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
262+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
263263
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
264264
#[cfg(feature = "gl")]
265265
{

‎crates/canvas-2d/src/context/drawing_paths/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Context {
1212
path: Option<&mut Path>,
1313
fill_rule: Option<FillRule>,
1414
) {
15-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
15+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
1616
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
1717

1818
#[cfg(feature = "gl")]

‎crates/canvas-2d/src/context/mod.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,23 @@ impl Context {
351351
self.surface_data.scale
352352
}
353353

354+
// Acquiring the next drawable during presentation can block the display-link
355+
// callback on tvOS. Keep the previous surface until the next operation needs
356+
// to draw, then retain its contents when swapping the backing texture.
357+
#[inline]
358+
fn ensure_metal_drawable(&mut self) {
359+
#[cfg(all(feature = "metal", target_os = "tvos"))]
360+
if self.metal_context.as_ref().is_some_and(|c| !c.has_current_drawable()) {
361+
Self::acquire_drawable(self);
362+
}
363+
}
364+
354365
#[inline]
355366
pub fn with_canvas<F>(&mut self, f: F)
356367
where
357368
F: FnOnce(&skia_safe::Canvas),
358369
{
370+
self.ensure_metal_drawable();
359371
f(self.surface.canvas());
360372
}
361373

@@ -364,6 +376,7 @@ impl Context {
364376
where
365377
F: FnOnce(&skia_safe::Canvas, &mut Path),
366378
{
379+
self.ensure_metal_drawable();
367380
f(self.surface.canvas(), &mut self.path);
368381
self.surface_state = self.surface_state | SurfaceState::Pending;
369382
}
@@ -373,6 +386,7 @@ impl Context {
373386
where
374387
F: FnOnce(&skia_safe::Canvas),
375388
{
389+
self.ensure_metal_drawable();
376390
f(self.surface.canvas());
377391
self.surface_state = self.surface_state | SurfaceState::Pending;
378392
}
@@ -382,6 +396,7 @@ impl Context {
382396
where
383397
F: FnOnce(&skia_safe::Canvas, &Paint),
384398
{
399+
self.ensure_metal_drawable();
385400
f(self.surface.canvas(), &self.state.paint);
386401
self.surface_state = self.surface_state | SurfaceState::Pending;
387402
}
@@ -398,6 +413,7 @@ impl Context {
398413
where
399414
F: FnOnce(&skia_safe::Canvas),
400415
{
416+
self.ensure_metal_drawable();
401417
f(self.surface.canvas());
402418
self.surface_state = self.surface_state | SurfaceState::Pending;
403419
}
@@ -555,6 +571,7 @@ impl Context {
555571
where
556572
F: Fn(&skia_safe::Canvas, &skia_safe::Paint, &mut Path),
557573
{
574+
self.ensure_metal_drawable();
558575
let blend = self.state.global_composite_operation.get_blend_mode();
559576
// Fast path: most draw calls use SrcOver (the default)
560577
if !matches!(
@@ -616,6 +633,7 @@ impl Context {
616633
where
617634
F: Fn(&skia_safe::Canvas, &skia_safe::Paint),
618635
{
636+
self.ensure_metal_drawable();
619637
let blend = self.state.global_composite_operation.get_blend_mode();
620638
// Fast path: most draw calls use SrcOver (the default)
621639
if !matches!(
@@ -673,6 +691,7 @@ impl Context {
673691
where
674692
F: Fn(&skia_safe::Canvas, &skia_safe::Paint, &Font),
675693
{
694+
self.ensure_metal_drawable();
676695
let blend = self.state.global_composite_operation.get_blend_mode();
677696
if !matches!(
678697
blend,

‎crates/canvas-2d/src/context/surface_metal.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,21 @@ impl Context {
349349

350350
pub fn present(context: &mut Context) {
351351
let _ = MetalContext::new_release_pool();
352-
let mut info: Option<TextureInfo> = None;
353-
let mut width = 0;
354-
let mut height = 0;
352+
355353
if let Some(context) = context.metal_context.as_mut() {
356354
context.present_drawable();
357355
}
358356

357+
#[cfg(not(target_os = "tvos"))]
358+
Self::acquire_drawable(context);
359+
}
360+
361+
pub(crate) fn acquire_drawable(context: &mut Context) {
362+
#[cfg(target_os = "tvos")]
363+
let _pool = MetalContext::new_release_pool();
364+
let mut info: Option<TextureInfo> = None;
365+
let mut width = 0;
366+
let mut height = 0;
359367
if let Some(context) = context.metal_context.as_mut() {
360368
if let Some(drawable) = context.next_drawable() {
361369
let texture = drawable.texture();

‎crates/canvas-2d/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn bytes_to_data_n32_url(
101101
encoded_prefix.push_str(format);
102102
encoded_prefix.push_str(";base64,");
103103

104-
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "visionos"))]
104+
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "visionos", target_os = "tvos"))]
105105
let fmt = ColorType::BGRA8888;
106106

107107
#[cfg(any(target_os = "android"))]

‎crates/canvas-c/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ objc2-metal = { workspace = true }
4444

4545
# visionOS: display-link 0.2 is gated to ios/macos only, so RAF uses a CADisplayLink
4646
# shim (see src/raf/visionos.rs) built directly on objc2-quartz-core instead.
47-
[target.'cfg(target_os="visionos")'.dependencies]
47+
[target.'cfg(any(target_os="visionos", target_os="tvos"))'.dependencies]
4848
wgpu-core = { workspace = true, features = ["wgsl", "metal"] }
4949
wgpu-hal = { workspace = true, features = ["metal"] }
5050
objc2 = { workspace = true, features = ["std"] }

0 commit comments

Comments
 (0)