Skip to content

Commit 1673b5b

Browse files
committed
feat: support video elements in drawImage, texImage2D, texSubImage2D, texImage3D & texSubImage3D
1 parent 18ffa23 commit 1673b5b

File tree

81 files changed

+9291
-5849
lines changed

Some content is hidden

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

81 files changed

+9291
-5849
lines changed

.github/workflows/publish.yml

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
name: Publish Packages
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
npm_tag:
10+
description: 'NPM tag to publish as (overrides default)'
11+
required: false
12+
default: 'latest'
13+
dry_run:
14+
description: 'Set to "true" to skip publishing and release upload (dry run)'
15+
required: false
16+
default: 'false'
17+
18+
env:
19+
NPM_TAG: "latest"
20+
NPM_PACKAGES: canvas,canvas-babylon,canvas-media,canvas-phaser,canvas-phaser-ce,canvas-pixi,canvas-polyfill,canvas-three,canvas-svg
21+
22+
jobs:
23+
build-linux:
24+
name: Build Linux native artifacts
25+
runs-on: ubuntu-22.04
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Setup Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 22
32+
33+
- name: Cache node modules
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
~/.npm
38+
~/.cache
39+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
40+
restore-keys: |
41+
${{ runner.os }}-node-
42+
43+
- name: Install Rust
44+
run: |
45+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
46+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
47+
48+
- name: Use Rust nightly
49+
run: rustup default nightly
50+
- name: Install deps (root)
51+
run: npm ci
52+
53+
- name: Cache cargo
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
~/.cargo/registry
58+
~/.cargo/git
59+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
60+
restore-keys: |
61+
${{ runner.os }}-cargo-
62+
63+
- name: Build Android (make android)
64+
run: |
65+
set -e
66+
make android
67+
68+
- name: Copy AAR into package
69+
run: |
70+
set -e
71+
./tools/scripts/copy-android.sh
72+
73+
- name: Upload Android platforms
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: android-platforms
77+
path: packages/canvas/platforms/android
78+
79+
build-macos:
80+
name: Build macOS native artifacts
81+
runs-on: macos-14
82+
steps:
83+
- uses: actions/checkout@v4
84+
- name: Setup Node
85+
uses: actions/setup-node@v4
86+
with:
87+
node-version: 22
88+
89+
- name: Cache node modules
90+
uses: actions/cache@v4
91+
with:
92+
path: |
93+
~/.npm
94+
~/.cache
95+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
96+
restore-keys: |
97+
${{ runner.os }}-node-
98+
99+
- name: Install Rust
100+
run: |
101+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
102+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
103+
104+
- name: Use Rust nightly
105+
run: rustup default nightly
106+
- name: Install root deps
107+
run: npm ci
108+
109+
- name: Cache cargo
110+
uses: actions/cache@v4
111+
with:
112+
path: |
113+
~/.cargo/registry
114+
~/.cargo/git
115+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
116+
restore-keys: |
117+
${{ runner.os }}-cargo-
118+
119+
- name: Build iOS (make ios)
120+
run: |
121+
set -e
122+
make ios
123+
124+
- name: Build and copy iOS XCFramework
125+
run: |
126+
set -e
127+
./tools/scripts/canvas-build.sh
128+
129+
- name: Upload iOS platforms
130+
uses: actions/upload-artifact@v4
131+
with:
132+
name: ios-platforms
133+
path: packages/canvas/platforms/ios
134+
135+
publish:
136+
name: Publish to npm
137+
runs-on: ubuntu-22.04
138+
needs: [ build-linux, build-macos ]
139+
steps:
140+
- uses: actions/checkout@v4
141+
142+
- name: Download linux artifacts
143+
uses: actions/download-artifact@v4
144+
with:
145+
name: napi-linux-artifacts
146+
path: ./artifacts/linux
147+
148+
- name: Cache cargo
149+
uses: actions/cache@v4
150+
with:
151+
path: |
152+
~/.cargo/registry
153+
~/.cargo/git
154+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
155+
restore-keys: |
156+
${{ runner.os }}-cargo-
157+
158+
- name: Download mac artifacts
159+
uses: actions/download-artifact@v4
160+
with:
161+
name: napi-macos-artifacts
162+
path: ./artifacts/macos
163+
164+
- name: Setup Node
165+
uses: actions/setup-node@v4
166+
with:
167+
node-version: 22
168+
169+
- name: Install root deps
170+
run: npm ci
171+
172+
- name: Compute NPM_VERSION
173+
run: |
174+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
175+
TAG=${GITHUB_REF#refs/tags/}
176+
echo "Detected tag $TAG"
177+
echo "NPM_VERSION=$TAG" >> $GITHUB_ENV
178+
# set NPM_TAG to prefix of tag (e.g. rc/, beta) or the tag itself
179+
echo "NPM_TAG=${TAG%%-*}" >> $GITHUB_ENV
180+
else
181+
if [ -n "${{ github.event.inputs.npm_tag }}" ]; then
182+
NT="${{ github.event.inputs.npm_tag }}"
183+
else
184+
NT="$NPM_TAG"
185+
fi
186+
echo "NPM_TAG=$NT" >> $GITHUB_ENV
187+
echo "NPM_VERSION=$(node -e \"console.log(require('./packages/canvas/package.json').version)\")-$NT-$(date +\"%Y%m%d\")-$GITHUB_RUN_ID" >> $GITHUB_ENV
188+
fi
189+
190+
- name: Bump packages (no git tags)
191+
run: |
192+
for pkg in packages/canvas packages/canvas-babylon packages/canvas-media packages/canvas-phaser packages/canvas-phaser-ce packages/canvas-pixi packages/canvas-polyfill packages/canvas-three packages/canvas-svg; do
193+
if [ -f "$pkg/package.json" ]; then
194+
(cd "$pkg" && npm --no-git-tag-version version "$NPM_VERSION")
195+
fi
196+
done
197+
198+
- name: Create project .npmrc (in-repo)
199+
if: ${{ secrets.NPM_PUBLISH_TOKEN != '' }}
200+
run: |
201+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > .npmrc
202+
203+
- name: Build all packages
204+
run: |
205+
npx nx run canvas:build.all
206+
207+
- name: Publish packages
208+
if: ${{ github.event.inputs.dry_run != 'true' }}
209+
env:
210+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
211+
run: |
212+
if [ -z "$NPM_TOKEN" ]; then
213+
echo "NPM token missing. Set secrets.NPM_PUBLISH_TOKEN to proceed." && exit 1
214+
fi
215+
echo "Publishing packages with version $NPM_VERSION and tag $NPM_TAG"
216+
npm run publish-packages --name "$NPM_PACKAGES" --verify true --version "$NPM_VERSION" --tag "$NPM_TAG"
217+
218+
- name: Clean up .npmrc
219+
if: always()
220+
run: rm -f .npmrc || true
221+
222+
- name: Create release tarball
223+
if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true'
224+
run: |
225+
set -e
226+
TAR_NAME=release-${NPM_VERSION}.tar.gz
227+
tar -czf ${TAR_NAME} dist packages/canvas/platforms || true
228+
echo "Created ${TAR_NAME}"
229+
230+
- name: Create GitHub release and upload assets
231+
if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true'
232+
uses: softprops/action-gh-release@v1
233+
with:
234+
files: release-${NPM_VERSION}.tar.gz
235+
env:
236+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pull-request.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
env:
1010
NPM_TAG: "pr"
1111
EMULATOR_NAME: "runtime-emu"
12-
NDK_VERSION: r23c
12+
NDK_VERSION: r27d
1313
ANDROID_API: 29
1414
ANDROID_ABI: x86_64
1515
NDK_ARCH: linux
@@ -24,6 +24,24 @@ jobs:
2424
runs-on: ubuntu-22.04
2525
steps:
2626
- uses: actions/checkout@v4
27+
- name: Cache node modules
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.npm
32+
~/.cache
33+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
34+
restore-keys: |
35+
${{ runner.os }}-node-
36+
- name: Cache cargo
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cargo/registry
41+
~/.cargo/git
42+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-cargo-
2745
- name: Install Rust
2846
run: |
2947
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
@@ -137,6 +155,24 @@ jobs:
137155
runs-on: macos-14
138156
steps:
139157
- uses: actions/checkout@v4
158+
- name: Cache node modules
159+
uses: actions/cache@v4
160+
with:
161+
path: |
162+
~/.npm
163+
~/.cache
164+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
165+
restore-keys: |
166+
${{ runner.os }}-node-
167+
- name: Cache cargo
168+
uses: actions/cache@v4
169+
with:
170+
path: |
171+
~/.cargo/registry
172+
~/.cargo/git
173+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
174+
restore-keys: |
175+
${{ runner.os }}-cargo-
140176
- name: Install Rust
141177
run: |
142178
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
@@ -190,6 +226,7 @@ jobs:
190226
npm run build.canvas.ios.framework.release
191227
npm:
192228
name: Npm Build
229+
if: ${{ github.event_name != 'pull_request' }}
193230
runs-on: ubuntu-22.04
194231
needs: [android, ios]
195232
outputs:
@@ -251,4 +288,20 @@ jobs:
251288
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ../../.npmrc
252289
echo "Publishing @nativescript/canvas@$NPM_VERSION to NPM with tag $NPM_TAG..."
253290
npm run publish-packages --name $NPM_PACKAGES --verify true --version $NPM_VERSION
291+
pr-notice:
292+
name: PR Publish Notice
293+
if: ${{ github.event_name == 'pull_request' }}
294+
runs-on: ubuntu-latest
295+
needs: [ android, ios ]
296+
steps:
297+
- uses: actions/checkout@v4
298+
- name: Post PR comment about publishing
299+
uses: peter-evans/create-or-update-comment@v4
300+
with:
301+
token: ${{ secrets.GITHUB_TOKEN }}
302+
issue-number: ${{ github.event.pull_request.number }}
303+
body: |
304+
:information_source: Note: npm publishing is disabled for pull requests.
305+
Publishing is performed only from tag pushes via the `Publish Packages` workflow.
306+
If you need a test publish, create a tag `v0.0.0-rc.test` and push it to trigger a release run.
254307

crates/canvas-android/src/lib.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::utils::{
3030
nativeResizeCustomSurface, nativeResizeCustomSurfaceNormal,
3131
};
3232
use crate::utils::gl::st::{SURFACE_TEXTURE, SurfaceTexture};
33-
use crate::utils::gl::texture_render::nativeDrawFrame;
33+
use crate::utils::gl::texture_render::{nativeDrawFrame, nativeDrawFrameTexImage3D, nativeDrawFrameTexSubImage3D};
3434

3535
mod jni_compat;
3636
pub mod utils;
@@ -250,13 +250,38 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
250250
"!(Landroid/graphics/SurfaceTexture;ZIIIIIII[FIIIIIIII)V"
251251
};
252252

253+
// nativeDrawFrame — signature varies by API level (Android O+ uses direct buffers)
254+
let nativeDrawFrameTexImage3DMethod = if ret >= ANDROID_O {
255+
"(Landroid/graphics/SurfaceTexture;ZIIIIIII[FIIIIIIIIIIII)V"
256+
} else {
257+
"!(Landroid/graphics/SurfaceTexture;ZIIIIIII[FIIIIIIIIIIII)V"
258+
};
259+
260+
let nativeDrawFrameTexSubImage3DMethod = if ret >= ANDROID_O {
261+
"(Landroid/graphics/SurfaceTexture;ZIIIIIII[FIIIIIIIIIII)V"
262+
} else {
263+
"!(Landroid/graphics/SurfaceTexture;ZIIIIIII[FIIIIIIIIIII)V"
264+
};
265+
253266
let _ = env.register_native_methods(
254267
&text_render_class,
255-
&[NativeMethod {
256-
name: "nativeDrawFrame".into(),
257-
sig: nativeDrawFrameMethod.into(),
258-
fn_ptr: nativeDrawFrame as *mut c_void,
259-
}],
268+
&[
269+
NativeMethod {
270+
name: "nativeDrawFrame".into(),
271+
sig: nativeDrawFrameMethod.into(),
272+
fn_ptr: nativeDrawFrame as *mut c_void,
273+
},
274+
NativeMethod {
275+
name: "nativeDrawFrameTexImage3D".into(),
276+
sig: nativeDrawFrameTexImage3DMethod.into(),
277+
fn_ptr: nativeDrawFrameTexImage3D as *mut c_void,
278+
},
279+
NativeMethod {
280+
name: "nativeDrawFrameTexSubImage3D".into(),
281+
sig: nativeDrawFrameTexSubImage3DMethod.into(),
282+
fn_ptr: nativeDrawFrameTexSubImage3D as *mut c_void,
283+
},
284+
],
260285
);
261286

262287
let canvas_rendering_context_2d_class = env

0 commit comments

Comments
 (0)