diff --git a/.cargo/config.toml b/.cargo/config.toml index fccc48ee..1d637b8d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,18 +1,37 @@ +[target.x86_64-apple-darwin] +# ivybridge provided by Github Actions +rustflags = ["-C", "target-cpu=ivybridge"] + [target.x86_64-pc-windows-msvc] -rustflags = ["-C", "link-args=/NODEFAULTLIB:libcmt.lib"] +rustflags = ["-C", "link-args=/NODEFAULTLIB:libcmt.lib", "-C", "target-cpu=haswell"] + +[target.x86_64-unknown-linux-gnu] +rustflags = ["-C", "target-cpu=haswell"] + +[target.aarch64-apple-darwin] +rustflags = ["-C", "target-cpu=apple-a14"] [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" +rustflags = ["-C", "target-cpu=cortex-a57"] [target.armv7-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" +rustflags = ["-C", "target-cpu=cortex-a7"] [target.x86_64-unknown-linux-musl] rustflags = [ "-C", "target-feature=-crt-static", + "-C", + "target-cpu=haswell", ] [target.aarch64-unknown-linux-musl] linker = "aarch64-linux-musl-gcc" -rustflags = ["-C", "target-feature=-crt-static"] +rustflags = [ + "-C", + "target-feature=-crt-static", + "-C", + "target-cpu=cortex-a57", +] diff --git a/.eslintrc.yml b/.eslintrc.yml index 0176dc11..7e9f4f5b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -26,7 +26,7 @@ rules: 'space-before-function-paren': 0 'no-useless-constructor': 0 'no-undef': 2 - 'no-console': [2, { allow: ['error', 'warn', 'info', 'assert'] }] + 'no-console': [2, { allow: ['error', 'warn', 'info', 'assert', 'time', 'timeEnd'] }] 'comma-dangle': ['error', 'only-multiline'] 'no-unused-vars': 0 'no-var': 2 diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index f47bfb82..3c4a30c1 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -23,7 +23,9 @@ jobs: settings: - host: macos-latest target: 'x86_64-apple-darwin' - build: pnpm build + build: | + rustc --print target-cpus + pnpm build downloadTarget: '' - host: windows-latest build: pnpm build diff --git a/__test__/canvas-class.spec.ts b/__test__/canvas-class.spec.ts index 01bb9183..d56c4465 100644 --- a/__test__/canvas-class.spec.ts +++ b/__test__/canvas-class.spec.ts @@ -1,7 +1,8 @@ import test from 'ava' +import { omit } from 'lodash' import { createCanvas, Canvas } from '../index' test('Canvas constructor should be equal to createCanvas', (t) => { - t.deepEqual(createCanvas(200, 100), new Canvas(200, 100)) + t.deepEqual(omit(createCanvas(200, 100), 'getContext'), omit(new Canvas(200, 100), 'getContext')) }) diff --git a/__test__/regression.spec.ts b/__test__/regression.spec.ts index 7ff15290..5643e8d9 100644 --- a/__test__/regression.spec.ts +++ b/__test__/regression.spec.ts @@ -1,19 +1,8 @@ -import ava, { TestInterface } from 'ava' +import test from 'ava' -import { createCanvas, Canvas, SKRSContext2D } from '../index' +import { createCanvas } from '../index' import { snapshotImage } from './image-snapshot' -const test = ava as TestInterface<{ - canvas: Canvas - ctx: SKRSContext2D -}> - -test.beforeEach((t) => { - const canvas = createCanvas(512, 512) - t.context.canvas = canvas - t.context.ctx = canvas.getContext('2d')! -}) - test('transform-with-state', async (t) => { const canvas = createCanvas(256, 256) const ctx = canvas.getContext('2d') @@ -40,3 +29,49 @@ test('transform-with-state', async (t) => { ctx.restore() await snapshotImage(t, { canvas, ctx }) }) + +test('transform-with-radial-gradient', async (t) => { + const canvas = createCanvas(256, 256) + const ctx = canvas.getContext('2d') + ctx.translate(128.5, 128.5) + ctx.scale(1, 1) + ctx.clearRect(-128, -128, 256, 256) + ctx.beginPath() + ctx.save() + ctx.transform(1, 0, 0, 0.9090909090909091, 0, 0) + ctx.arc(0, 0, 110, 0, 6.283185307179586, false) + ctx.restore() + ctx.save() + const p = ctx.createRadialGradient(0.5, 0.5, 0, 0.2, 0.4, 0.5) + p.addColorStop(1, 'rgba(0, 0, 255, 1)') + p.addColorStop(0, 'rgba(200, 200, 200, 0)') + ctx.fillStyle = p + ctx.transform(220, 0, 0, 200, -110, -100) + ctx.transform(1, 0, 0, 1, 0, 0) + ctx.fill() + ctx.restore() + await snapshotImage(t, { canvas, ctx }) +}) + +test('transform-with-radial-gradient-x', async (t) => { + const canvas = createCanvas(400, 282) + const ctx = canvas.getContext('2d') + ctx.translate(200.5, 141.5) + ctx.scale(1, 1) + ctx.clearRect(-181.5, -128, 363, 256) + ctx.beginPath() + ctx.save() + ctx.transform(1, 0, 0, 0.5555555555555556, 0, 0) + ctx.arc(0, 0, 180, 0, 6.283185307179586, false) + ctx.restore() + ctx.save() + const p = ctx.createRadialGradient(0.5, 0.5, 0, 0.5, 0.5, 0.5) + p.addColorStop(1, 'rgba(0, 0, 255, 1)') + p.addColorStop(0, 'rgba(200, 200, 200, 0)') + ctx.fillStyle = p + ctx.transform(360, 0, 0, 200, -180, -100) + ctx.transform(1, 0, 0, 1, 0, 0) + ctx.fill() + ctx.restore() + await snapshotImage(t, { canvas, ctx }) +}) diff --git a/__test__/snapshots/transform-with-radial-gradient-x.png b/__test__/snapshots/transform-with-radial-gradient-x.png new file mode 100644 index 00000000..00ba3a6f Binary files /dev/null and b/__test__/snapshots/transform-with-radial-gradient-x.png differ diff --git a/__test__/snapshots/transform-with-radial-gradient.png b/__test__/snapshots/transform-with-radial-gradient.png new file mode 100644 index 00000000..87c53e2f Binary files /dev/null and b/__test__/snapshots/transform-with-radial-gradient.png differ diff --git a/depot_tools b/depot_tools index 74ef838a..984ce942 160000 --- a/depot_tools +++ b/depot_tools @@ -1 +1 @@ -Subproject commit 74ef838a40d8fecac485416f1a1fb07f9aeb6fd1 +Subproject commit 984ce942a4b1a5a559a5b07b9c0b29b228cd070d diff --git a/index.html b/index.html index 2da4b37f..dc345e77 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ +