Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] worklet-thread enabled scene graph #2511

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/node": "16.11.7",
"clang-format": "1.6.0",
"rimraf": "3.0.2",
"ts-morph": "^23.0.0",
"ts-node": "10.4.0",
"typescript": "5.3.3"
},
Expand All @@ -29,7 +30,8 @@
"clang-format-common": "find package/cpp/ -iname *.h -o -iname *.m -o -iname *.cpp | xargs clang-format -i",
"workflow-copy-libs": "yarn ts-node ./scripts/workflow-copy-libs.ts",
"bootstrap": "yarn && cd ./package && yarn && cd .. && cd ./example && yarn && cd .. && cd ./fabricexample && yarn && cd ..",
"cpplint": "cpplint --linelength=230 --filter=-legal/copyright,-whitespace/indent,-whitespace/comments,-whitespace/ending_newline,-build/include_order,-runtime/references,-readability/todo,-whitespace/blank_line,-whitespace/todo,-runtime/int,-build/c++11,-whitespace/parens --exclude=package/cpp/skia --exclude=package/ios --exclude=package/android/build --exclude=package/node_modules --recursive package"
"cpplint": "cpplint --linelength=230 --filter=-legal/copyright,-whitespace/indent,-whitespace/comments,-whitespace/ending_newline,-build/include_order,-runtime/references,-readability/todo,-whitespace/blank_line,-whitespace/todo,-runtime/int,-build/c++11,-whitespace/parens --exclude=package/cpp/skia --exclude=package/ios --exclude=package/android/build --exclude=package/node_modules --recursive package",
"codegen": "yarn ts-node ./scripts/codegen.ts"
},
"license": "MIT",
"licenseFilename": "LICENSE.md",
Expand Down
7 changes: 5 additions & 2 deletions package/src/dom/nodes/datatypes/Circle.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { Skia } from "../../../skia/types";
import type { CircleDef, ScalarCircleDef } from "../../types";

export const isCircleScalarDef = (def: CircleDef): def is ScalarCircleDef =>
export const isCircleScalarDef = (def: CircleDef): def is ScalarCircleDef => {
"worklet";
// We have an issue to check property existence on JSI backed instances
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(def as any).cx !== undefined;
return (def as any).cx !== undefined;
};

export const processCircle = (Skia: Skia, def: CircleDef) => {
"worklet";
if (isCircleScalarDef(def)) {
return { c: Skia.Point(def.cx, def.cy), r: def.r };
}
Expand Down
6 changes: 4 additions & 2 deletions package/src/dom/nodes/datatypes/Enum.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const enumKey = <K extends string>(k: K) =>
(k.charAt(0).toUpperCase() + k.slice(1)) as Capitalize<K>;
export const enumKey = <K extends string>(k: K) => {
"worklet";
return (k.charAt(0).toUpperCase() + k.slice(1)) as Capitalize<K>;
};
7 changes: 5 additions & 2 deletions package/src/dom/nodes/datatypes/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isPath } from "../../../skia/types";
import type { PathDef } from "../../types";

export const processPath = (Skia: Skia, rawPath: PathDef) => {
"worklet";
const path =
typeof rawPath === "string"
? Skia.Path.MakeFromSVGString(rawPath)
Expand All @@ -14,5 +15,7 @@ export const processPath = (Skia: Skia, rawPath: PathDef) => {
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const isPathDef = (def: any): def is PathDef =>
typeof def === "string" || isPath(def);
export const isPathDef = (def: any): def is PathDef => {
"worklet";
return typeof def === "string" || isPath(def);
};
15 changes: 11 additions & 4 deletions package/src/dom/nodes/datatypes/Rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export const isEdge = (pos: Vector, b: SkRect) => {
};

// We have an issue to check property existence on JSI backed instances
const isRRectCtor = (def: RRectDef): def is RRectCtor =>
(def as any).rect === undefined;
const isRRectCtor = (def: RRectDef): def is RRectCtor => {
"worklet";
return (def as any).rect === undefined;
};

// We have an issue to check property existence on JSI backed instances
const isRectCtor = (def: RectDef): def is RectCtor =>
(def as any).rect === undefined;
const isRectCtor = (def: RectDef): def is RectCtor => {
"worklet";
return (def as any).rect === undefined;
};

export const processRect = (Skia: Skia, def: RectDef) => {
"worklet";
if (isRectCtor(def)) {
return Skia.XYWHRect(def.x ?? 0, def.y ?? 0, def.width, def.height);
} else {
Expand All @@ -27,6 +33,7 @@ export const processRect = (Skia: Skia, def: RectDef) => {
};

export const processRRect = (Skia: Skia, def: RRectDef) => {
"worklet";
if (isRRectCtor(def)) {
const r = processRadius(Skia, def.r ?? 0);
return Skia.RRectXY(
Expand Down
48 changes: 48 additions & 0 deletions package/src/sg/ColorFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type {
BlendColorFilterProps,
ChildrenProps,
LerpColorFilterProps,
MatrixColorFilterProps,
} from "../dom/types";

import type { DrawingContext } from "./Context";

export const renderMatrixColorFilter = (
_ctx: DrawingContext,
_props: MatrixColorFilterProps
) => {
"worklet";
throw new Error("Not implemented");
};

export const renderBlendColorFilter = (
_ctx: DrawingContext,
_props: BlendColorFilterProps
) => {
"worklet";
throw new Error("Not implemented");
};

export const renderLinearToSRGBGammaColorFilter = (
_ctx: DrawingContext,
_props: ChildrenProps
) => {
"worklet";
throw new Error("Not implemented");
};

export const renderSRGBToLinearGammaColorFilter = (
_ctx: DrawingContext,
_props: ChildrenProps
) => {
"worklet";
throw new Error("Not implemented");
};

export const renderLerpColorFilter = (
_ctx: DrawingContext,
_props: LerpColorFilterProps
) => {
"worklet";
throw new Error("Not implemented");
};
45 changes: 45 additions & 0 deletions package/src/sg/Context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { GroupProps } from "../dom/types";
import {
processTransform3d,
type SkCanvas,
type SkPaint,
type Skia,
} from "../skia/types";

export interface PaintingContext {
paints: SkPaint[];
// maskFilters: SkMaskFilter[];
// shaders: SkShader[];
// pathEffects: SkPathEffect[];
// imageFilters: SkImageFilter[];
// colorFilters: SkColorFilter[];
}

export interface DrawingContext extends PaintingContext {
Skia: Skia;
canvas: SkCanvas;
}

export const getPaint = (ctx: DrawingContext) => {
"worklet";
return ctx.paints[ctx.paints.length - 1];
};

export const processContext = (ctx: DrawingContext, props: GroupProps) => {
"worklet";
let restore = false;
if (props.matrix) {
ctx.canvas.save();
ctx.canvas.concat(props.matrix);
restore = true;
} else if (props.transform) {
ctx.canvas.save();
ctx.canvas.concat(processTransform3d(props.transform));
restore = true;
}
if (props.color) {
const paint = getPaint(ctx);
paint.setColor(ctx.Skia.Color(props.color));
}
return { restore };
};
Loading
Loading