Skip to content

Commit

Permalink
feat: upgrade skia to chrome/122
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Feb 4, 2024
1 parent c0be5da commit 943989b
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "link-args=/NODEFAULTLIB:libcmt.lib"]
rustflags = ["-C", "link-args=/NODEFAULTLIB:libcmt.lib", "-C", "target-feature=+crt-static"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "target-cpu=apple-a14"]
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ on:

jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"

strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
- host: macos-14
target: 'x86_64-apple-darwin'
setup: brew install nasm
build: |
Expand Down Expand Up @@ -56,7 +54,7 @@ jobs:
export LIB_AOM_PKG_CONFIG_PATH=/usr/lib/pkgconfig &&
yarn build --target x86_64-unknown-linux-musl &&
strip skia.linux-x64-musl.node
- host: macos-latest
- host: macos-14
downloadTarget: 'aarch64-apple-darwin'
target: 'aarch64-apple-darwin'
build: |
Expand Down Expand Up @@ -210,7 +208,7 @@ jobs:
fail-fast: false
matrix:
settings:
- host: macos-latest
- host: macos-14
target: 'x86_64-apple-darwin'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
Expand Down
38 changes: 30 additions & 8 deletions .github/workflows/skia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ on:
- release
tags-ignore:
- '**'

env:
MACOSX_DEPLOYMENT_TARGET: '10.13'

jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip skia')"

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-14, windows-latest]

name: stable - ${{ matrix.os }} - build skia
runs-on: ${{ matrix.os }}
Expand All @@ -23,6 +27,11 @@ jobs:
with:
submodules: true

- name: List llvm dir
if: matrix.os == 'windows-latest'
run: ls -R "C:\Program Files\LLVM"
shell: bash

- name: Setup node
uses: actions/setup-node@v4
with:
Expand All @@ -40,12 +49,13 @@ jobs:

- name: Install tools on macOS
run: brew install ninja
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-14'

- name: Install tools on Windows
if: matrix.os == 'windows-latest'
run: |
choco install llvm ninja -y
choco upgrade llvm
pip install certifi
- name: Login to GitHub Container Registry
Expand All @@ -56,17 +66,20 @@ jobs:
username: ${{ secrets.GH_CONTAINER_UNAME }}
password: ${{ secrets.GH_TOKEN }}

- name: Sync deps on host
run: python ./tools/git-sync-deps
if: matrix.os == 'ubuntu-latest'
working-directory: skia

- name: Compile skia
if: matrix.os == 'ubuntu-latest'
run: |
docker pull ghcr.io/brooooooklyn/canvas/ubuntu-builder:jammy
docker tag ghcr.io/brooooooklyn/canvas/ubuntu-builder:jammy builder
docker run --user "$(id -u):$(id -g)" --rm -v $(pwd):/canvas -w /canvas builder node ./scripts/build-skia.js
env:
PYTHONHTTPSVERIFY: 0
docker run --user "$(id -u):$(id -g)" -e PYTHONHTTPSVERIFY=0 -e SKIP_SYNC_SK_DEPS=0 --rm -v $(pwd):/canvas -w /canvas builder node ./scripts/build-skia.js
- name: Compile skia
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-14'
env:
PYTHONHTTPSVERIFY: 0
run: |
Expand All @@ -92,7 +105,7 @@ jobs:
if: "!contains(github.event.head_commit.message, 'skip skia')"

name: stable - apple-silicon - build skia
runs-on: macos-latest
runs-on: macos-14

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -185,11 +198,20 @@ jobs:
node-version: 18
cache: 'yarn'

- uses: actions/setup-python@v5
with:
python-version: '3.x'
architecture: 'x64'

- name: Sync deps on host
run: python ./tools/git-sync-deps
working-directory: skia

- name: Compile skia
run: |
docker pull ghcr.io/brooooooklyn/canvas/ubuntu-builder:jammy-aarch64
docker tag ghcr.io/brooooooklyn/canvas/ubuntu-builder:jammy-aarch64 builder
docker run --user "$(id -u):$(id -g)" --rm -v $(pwd):/canvas -w /canvas builder node ./scripts/build-skia.js --target=aarch64-unknown-linux-gnu
docker run --user "$(id -u):$(id -g)" -e SKIP_SYNC_SK_DEPS=0 --rm -v $(pwd):/canvas -w /canvas builder node ./scripts/build-skia.js --target=aarch64-unknown-linux-gnu
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand Down
19 changes: 5 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
## [0.1.44](https://github.com/Brooooooklyn/canvas/compare/v0.1.43...v0.1.44) (2023-08-22)


### Bug Fixes

* file extensions in `loadFontsFromDir()` are no longer case-sensitive ([9342e33](https://github.com/Brooooooklyn/canvas/commit/9342e3386f575f3864c1bfa0036caa0956f1a914))


- file extensions in `loadFontsFromDir()` are no longer case-sensitive ([9342e33](https://github.com/Brooooooklyn/canvas/commit/9342e3386f575f3864c1bfa0036caa0956f1a914))

## [0.1.43](https://github.com/Brooooooklyn/canvas/compare/v0.1.42...v0.1.43) (2023-08-11)



## [0.1.42](https://github.com/Brooooooklyn/canvas/compare/v0.1.41...v0.1.42) (2023-08-08)


### Bug Fixes

* add `ctx.canvas` property on svg context ([#697](https://github.com/Brooooooklyn/canvas/issues/697)) ([968e501](https://github.com/Brooooooklyn/canvas/commit/968e501e5d09d5b11fb02829b6ba402ffc3575d1))
* **deps:** update rust crate infer to 0.15 ([376b19e](https://github.com/Brooooooklyn/canvas/commit/376b19ebc53640a89e1dad73b8281922675cf834))
* url is string type ([#671](https://github.com/Brooooooklyn/canvas/issues/671)) ([31a8ff9](https://github.com/Brooooooklyn/canvas/commit/31a8ff9a5295697b965ba4e48a19a30dc0f0b1d6))

- add `ctx.canvas` property on svg context ([#697](https://github.com/Brooooooklyn/canvas/issues/697)) ([968e501](https://github.com/Brooooooklyn/canvas/commit/968e501e5d09d5b11fb02829b6ba402ffc3575d1))
- **deps:** update rust crate infer to 0.15 ([376b19e](https://github.com/Brooooooklyn/canvas/commit/376b19ebc53640a89e1dad73b8281922675cf834))
- url is string type ([#671](https://github.com/Brooooooklyn/canvas/issues/671)) ([31a8ff9](https://github.com/Brooooooklyn/canvas/commit/31a8ff9a5295697b965ba4e48a19a30dc0f0b1d6))

### Features

* upgrade skia to m116 ([#702](https://github.com/Brooooooklyn/canvas/issues/702)) ([926c472](https://github.com/Brooooooklyn/canvas/commit/926c47249b77894eb96fd002755ad73e50e602d6))


- upgrade skia to m116 ([#702](https://github.com/Brooooooklyn/canvas/issues/702)) ([926c472](https://github.com/Brooooooklyn/canvas/commit/926c47249b77894eb96fd002755ad73e50e602d6))

## [0.1.41](https://github.com/Brooooooklyn/canvas/compare/v0.1.40...v0.1.41) (2023-05-22)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = "1"
base64 = "0.21"
cssparser = "0.29"
infer = "0.15"
libavif = { version = "0.11", default-features = false, features = [
libavif = { version = "0.12", default-features = false, features = [
"codec-aom",
] }
napi = { version = "2", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm116-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm118-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm116-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm118-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
Binary file modified __test__/snapshots/draw-image-svg-noto-emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/svg-transparent-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/transform-with-radial-gradient-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion npm/android-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"access": "public"
},
"repository": "https://github.com/Brooooooklyn/canvas.git"
}
}
45 changes: 31 additions & 14 deletions scripts/build-skia.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { execSync } = require('child_process')
const { readFileSync, writeFileSync } = require('fs')
const path = require('path')
const { platform, arch } = require('os')
const { execSync } = require('node:child_process')
const { readFileSync, writeFileSync, existsSync, readdirSync } = require('node:fs')
const path = require('node:path')
const { platform, arch } = require('node:os')

const PLATFORM_NAME = platform()
const HOST_ARCH = arch()
Expand All @@ -25,10 +25,12 @@ function exec(command) {
})
}

exec('python ./tools/git-sync-deps')
if (process.env.SKIP_SYNC_SK_DEPS !== 'false' && process.env.SKIP_SYNC_SK_DEPS !== '0') {
exec('python ./tools/git-sync-deps')
}

const CC = PLATFORM_NAME === 'win32' ? '\\"clang-cl\\"' : '"clang"'
const CXX = PLATFORM_NAME === 'win32' ? '\\"clang-cl\\"' : '"clang++"'
const CXX = PLATFORM_NAME === 'win32' ? '\\"clang-cpp\\"' : '"clang++"'
let ExtraCflagsCC = ''
let ExtraSkiaBuildFlag = ''
let ExtraCflags
Expand All @@ -51,7 +53,6 @@ const GN_ARGS = [
`skia_enable_tools=false`,
`skia_enable_svg=true`,
`skia_enable_skparagraph=true`,
`skia_enable_sktext=true`,
`skia_pdf_subset_harfbuzz=true`,
`skia_use_expat=true`,
`skia_use_system_expat=false`,
Expand Down Expand Up @@ -101,9 +102,13 @@ switch (PLATFORM_NAME) {
'\\"-DSK_CODEC_DECODES_JPEG\\",' +
'\\"-DSK_HAS_HEIF_LIBRARY\\",' +
'\\"-DSK_SHAPER_HARFBUZZ_AVAILABLE\\"'
ExtraSkiaBuildFlag = 'clang_win=\\"C:\\\\Program Files\\\\LLVM\\"'
const clangVersion = findClangWinVersion()
if (clangVersion) {
console.info(`Found clang version: ${clangVersion}`)
ExtraSkiaBuildFlag = `clang_win_version=\\"${clangVersion}\\"`
}
GN_ARGS.push(`clang_win=\\"C:\\\\Program Files\\\\LLVM\\"`)
GN_ARGS.push(`skia_enable_fontmgr_win=false`)
GN_ARGS.push(`skia_fontmgr_factory=\\":fontmgr_custom_directory_factory\\"`)
break
case 'linux':
case 'darwin':
Expand All @@ -126,11 +131,13 @@ switch (PLATFORM_NAME) {
PLATFORM_NAME === 'linux' &&
!TARGET_TRIPLE &&
HOST_LIBC === 'glibc' &&
(HOST_ARCH === 'x64' || HOST_ARCH === 'arm64')
HOST_ARCH === 'x64'
) {
ExtraCflagsCC += ',"-stdlib=libc++", "-static", "-I/usr/lib/llvm-16/include/c++/v1"'
ExtraCflagsCC += ',"-stdlib=libc++","-static","-I/usr/lib/llvm-16/include/c++/v1"'
}
if (PLATFORM_NAME === 'linux' && (!TARGET_TRIPLE || TARGET_TRIPLE.startsWith('x86_64'))) {
ExtraCflagsCC += ',"-Wno-psabi"'
}
GN_ARGS.push(`skia_fontmgr_factory=":fontmgr_custom_directory_factory"`)
break
default:
throw new TypeError(`Don't support ${PLATFORM_NAME} for now`)
Expand Down Expand Up @@ -161,8 +168,7 @@ switch (TARGET_TRIPLE) {
ExtraCflags = `"--target=aarch64-unknown-linux-musl", "-B/aarch64-linux-musl-cross/aarch64-linux-musl/bin", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/${gccVersion}", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/${gccVersion}/aarch64-linux-musl", "-march=armv8-a"`
ExtraCflagsCC += `, "--target=aarch64-unknown-linux-musl", "-B/aarch64-linux-musl-cross/aarch64-linux-musl/bin", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/${gccVersion}", "-I/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/${gccVersion}/aarch64-linux-musl", "-march=armv8-a"`
ExtraLdFlags = `"--target=aarch64-unknown-linux-musl", "-B/aarch64-linux-musl-cross/usr/aarch64-linux-musl/bin", "-L/aarch64-linux-musl-cross/usr/aarch64-linux-musl/lib", "-L/aarch64-linux-musl-cross/usr/lib/gcc/aarch64-linux-musl/${gccVersion}"`
ExtraAsmFlags =
'"--target=aarch64-unknown-linux-musl", "-march=armv8-a"'
ExtraAsmFlags = '"--target=aarch64-unknown-linux-musl", "-march=armv8-a"'
GN_ARGS.push(
`extra_ldflags=[${ExtraLdFlags}]`,
`ar="aarch64-linux-musl-ar"`,
Expand Down Expand Up @@ -268,3 +274,14 @@ console.time('Build Skia')
exec(`ninja -C ${OUTPUT_PATH}`)

console.timeEnd('Build Skia')

function findClangWinVersion() {
const stdout = execSync('clang --version', {
encoding: 'utf8',
})
const clangVersion = stdout.match(/clang version\s(\d+\.\d+\.\d+)/)
if (!clangVersion) {
return null
}
return clangVersion[1]?.split('.')?.at(0)
}
3 changes: 2 additions & 1 deletion scripts/release-skia-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (TARGET && TARGET.startsWith('--target=')) {
TARGET_TRIPLE = TARGET.replace('--target=', '')
}

const LIB = ['skia', 'skparagraph', 'skshaper', 'svg', 'sktext', 'skunicode']
const LIB = ['skia', 'skparagraph', 'skshaper', 'svg', 'skunicode']
const ICU_DAT = 'icudtl.dat'

const CLIENT = new Octokit({
Expand Down Expand Up @@ -119,6 +119,7 @@ async function download() {
})
for (const lib of LIB) {
const { downloadUrl, binary } = libPath(lib, PLATFORM_NAME, TARGET_TRIPLE)
console.info(`downloading ${downloadUrl} to ${binary}`)
execSync(`curl -J -L -H "Accept: application/octet-stream" ${downloadUrl} -o ${binary}`, {
stdio: 'inherit',
})
Expand Down
2 changes: 1 addition & 1 deletion skia
Submodule skia updated 5583 files
4 changes: 2 additions & 2 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,14 +1389,14 @@ extern "C"
}
}

skiac_image_filter *skiac_image_filter_make_blur(float sigma_x, float sigma_y, int tile_mode, skiac_image_filter *c_image_filter)
skiac_image_filter *skiac_image_filter_make_blur(float sigma_x, float sigma_y, skiac_image_filter *c_image_filter)
{
auto chained_filter = sk_sp(IMAGE_FILTER_CAST);
if (c_image_filter)
{
chained_filter->ref();
}
auto filter = SkImageFilters::Blur(sigma_x, sigma_y, (SkTileMode)tile_mode, chained_filter).release();
auto filter = SkImageFilters::Blur(sigma_x, sigma_y, chained_filter).release();
if (filter)
{
return reinterpret_cast<skiac_image_filter *>(filter);
Expand Down
Loading

1 comment on commit 943989b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 943989b Previous: c0be5da Ratio
Draw house#skia-canvas 29 ops/sec (±0.19%) 29.51 ops/sec (±0.36%) 1.02
Draw house#node-canvas 38 ops/sec (±0.59%) 37.26 ops/sec (±0.59%) 0.98
Draw house#@napi-rs/skia 30 ops/sec (±0.68%) 29.52 ops/sec (±0.8%) 0.98
Draw gradient#skia-canvas 28 ops/sec (±0.38%) 28.5 ops/sec (±0.25%) 1.02
Draw gradient#node-canvas 37 ops/sec (±0.56%) 36.3 ops/sec (±0.53%) 0.98
Draw gradient#@napi-rs/skia 29 ops/sec (±0.46%) 28.3 ops/sec (±0.64%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.