@shopify/react-native-skia 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +47 -21
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -5
- package/apple/MetalWindowContext.mm +4 -2
- package/apple/RNSkApplePlatformContext.h +7 -5
- package/apple/RNSkApplePlatformContext.mm +30 -29
- package/apple/SkiaCVPixelBufferUtils.mm +4 -8
- package/apple/SkiaManager.mm +0 -3
- package/cpp/api/JsiSkImageFactory.h +14 -1
- package/cpp/api/JsiSkSurface.h +7 -1
- package/cpp/api/recorder/DrawingCtx.h +19 -2
- package/cpp/api/recorder/Paint.h +1 -3
- package/cpp/api/recorder/RNRecorder.h +5 -13
- package/cpp/rnskia/DawnContext.h +11 -2
- package/cpp/rnskia/DawnUtils.h +97 -6
- package/cpp/rnskia/DawnWindowContext.h +18 -11
- package/cpp/rnskia/RNSkJsiViewApi.h +91 -71
- package/cpp/rnskia/RNSkManager.cpp +3 -18
- package/cpp/rnskia/RNSkManager.h +0 -6
- package/cpp/rnskia/RNSkPlatformContext.h +22 -5
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +4 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/sksg/HostConfig.js +1 -1
- package/lib/commonjs/sksg/HostConfig.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +14 -2
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +6 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/lib/commonjs/sksg/Recorder/commands/Paint.js +5 -4
- package/lib/commonjs/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.js +4 -0
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/module/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/module/skia/web/JsiSkSurface.js +4 -1
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/sksg/HostConfig.js +1 -1
- package/lib/module/sksg/HostConfig.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +14 -2
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +6 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/lib/module/sksg/Recorder/commands/Paint.js +5 -4
- package/lib/module/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +4 -0
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +1 -1
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/HostConfig.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Paint.d.ts +1 -1
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/src/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/package.json +1 -1
- package/react-native-skia.podspec +43 -12
- package/src/renderer/__tests__/e2e/DataEncoding.spec.tsx +6 -2
- package/src/renderer/__tests__/e2e/Paint.spec.tsx +44 -1
- package/src/skia/types/Image/ImageFactory.ts +3 -1
- package/src/skia/types/Surface/Surface.ts +1 -1
- package/src/skia/web/JsiSkImageFactory.ts +4 -0
- package/src/skia/web/JsiSkSurface.ts +4 -1
- package/src/sksg/HostConfig.ts +2 -4
- package/src/sksg/Recorder/DrawingContext.ts +15 -1
- package/src/sksg/Recorder/Player.ts +6 -2
- package/src/sksg/Recorder/commands/Paint.ts +6 -5
- package/src/views/SkiaBaseWebView.tsx +4 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createContext","DefaultEventPriority","shallowEq","NoEventPriority","DEBUG","debug","args","console","log","currentUpdatePriority","sksgHostConfig","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","propsWithChildren","_container","children","props","instance","appendInitialChild","parentInstance","child","push","finalizeInitialChildren","commitMount","prepareForCommit","resetAfterCommit","container","redraw","getPublicInstance","node","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","prepareUpdate","_instance","oldProps","newProps","propsAreEqual","preparePortalMount","cloneInstance","_oldProps","_updatePayload","keepChildren","_recyclableInstance","createContainerChildSet","appendChildToContainerChildSet","childSet","finalizeContainerChildren","newChildren","root","replaceContainerChildren","cloneHiddenInstance","cloneHiddenTextInstance","getCurrentEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","_node","getInstanceFromNode","prepareScopeUpdate","_scopeInstance","getInstanceFromScope","shouldAttemptEagerTransition","trackSchedulerEvent","resolveEventType","resolveEventTimeStamp","requestPostPaintCallback","maySuspendCommit","preloadInstance","startSuspendingCommit","suspendInstance","waitForCommitToBeReady","NotPendingTransition","HostTransitionContext","setCurrentUpdatePriority","newPriority","getCurrentUpdatePriority","resolveUpdatePriority","resetFormInstance"],"sources":["HostConfig.ts"],"sourcesContent":["/*global NodeJS*/\nimport { createContext } from \"react\";\nimport type { Fiber, HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType } from \"../dom/types\";\nimport { shallowEq } from \"../renderer/typeddash\";\n\nimport type { Node } from \"./Node\";\nimport type { Container } from \"./Container\";\n\ntype EventPriority = number;\nconst NoEventPriority = 0;\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ntype Instance = Node;\n\ntype Props = object;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = object;\ntype UpdatePayload = Container;\ntype ChildSet = Node[];\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\nlet currentUpdatePriority: EventPriority = NoEventPriority;\n\nexport const sksgHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n supportsMutation: false,\n isPrimaryRenderer: false,\n supportsPersistence: true,\n supportsHydration: false,\n //supportsMicrotask: true,\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n getRootHostContext: (_rootContainerInstance: Container) => {\n debug(\"getRootHostContext\");\n return {};\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return {};\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n propsWithChildren,\n _container,\n _hostContext,\n _internalInstanceHandle\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = propsWithChildren as any;\n debug(\"createInstance\", type);\n const instance = {\n type,\n props,\n children: [],\n };\n return instance;\n },\n\n appendInitialChild(parentInstance: Instance, child: Instance | TextInstance) {\n parentInstance.children.push(child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_container: Container) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n resetAfterCommit(container: Container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (_container) => {\n debug(\"clearContainer\");\n },\n\n prepareUpdate(\n _instance: Instance,\n _type: string,\n oldProps: Props,\n newProps: Props,\n container: Container,\n _hostContext: HostContext\n ) {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual) {\n return null;\n }\n return container;\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n cloneInstance(\n instance,\n _type,\n _oldProps,\n newProps,\n _updatePayload,\n _internalInstanceHandle,\n keepChildren: boolean,\n _recyclableInstance: null | Instance\n ) {\n debug(\"cloneInstance\");\n return {\n type: instance.type,\n props: { ...newProps },\n children: keepChildren ? [...instance.children] : [],\n };\n },\n\n createContainerChildSet(): ChildSet {\n debug(\"createContainerChildSet\");\n return [];\n },\n\n appendChildToContainerChildSet(\n childSet: ChildSet,\n child: Instance | TextInstance\n ): void {\n childSet.push(child);\n },\n\n finalizeContainerChildren(container: Container, newChildren: ChildSet) {\n debug(\"finalizeContainerChildren\");\n container.root = newChildren;\n },\n\n replaceContainerChildren(container: Container, newChildren: ChildSet) {\n container.root = newChildren;\n },\n\n cloneHiddenInstance(\n _instance: Instance,\n _type: string,\n _props: Props\n ): Instance {\n debug(\"cloneHiddenInstance\");\n throw new Error(\"Not yet implemented.\");\n },\n\n cloneHiddenTextInstance(_instance: Instance, _text: string): TextInstance {\n debug(\"cloneHiddenTextInstance\");\n throw new Error(\"Not yet implemented.\");\n },\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: (_node: Instance) => {},\n getInstanceFromNode: function (_node): Fiber | null | undefined {\n throw new Error(\"Function not implemented.\");\n },\n prepareScopeUpdate: function (_scopeInstance, _instance): void {\n throw new Error(\"Function not implemented.\");\n },\n getInstanceFromScope: function (_scopeInstance): Instance | null {\n throw new Error(\"Function not implemented.\");\n },\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shouldAttemptEagerTransition: () => false,\n trackSchedulerEvent: () => {},\n resolveEventType: () => null,\n resolveEventTimeStamp: () => -1.1,\n requestPostPaintCallback() {},\n maySuspendCommit: () => false,\n preloadInstance: () => true, // true indicates already loaded\n startSuspendingCommit() {},\n suspendInstance() {},\n waitForCommitToBeReady: () => null,\n NotPendingTransition: null,\n HostTransitionContext: createContext(null),\n setCurrentUpdatePriority(newPriority: number) {\n currentUpdatePriority = newPriority;\n },\n getCurrentUpdatePriority() {\n return currentUpdatePriority;\n },\n resolveUpdatePriority() {\n if (currentUpdatePriority !== NoEventPriority) {\n return currentUpdatePriority;\n }\n return DefaultEventPriority;\n },\n resetFormInstance() {},\n};\n"],"mappings":"AAAA;AACA,SAASA,aAAa,QAAQ,OAAO;AAErC,SAASC,oBAAoB,QAAQ,4BAA4B;AAGjE,SAASC,SAAS,QAAQ,uBAAuB;AAMjD,MAAMC,eAAe,GAAG,CAAC;AAEzB,MAAMC,KAAK,GAAG,KAAK;AACnB,OAAO,MAAMC,KAAK,GAAGA,CAAC,GAAGC,IAAoC,KAAK;EAChE,IAAIF,KAAK,EAAE;IACTG,OAAO,CAACC,GAAG,CAAC,GAAGF,IAAI,CAAC;EACtB;AACF,CAAC;AA8BD,IAAIG,qBAAoC,GAAGN,eAAe;AAE1D,OAAO,MAAMO,cAA8B,GAAG;EAC5C;AACF;AACA;EACEC,gBAAgB,EAAE,KAAK;EACvBC,iBAAiB,EAAE,KAAK;EACxBC,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AM,IAAI1B,KAAK,CAAC,2BAA2B,CAAC;EAC9C,CAAC;EACDqD,oBAAoB,EAAE,SAAAA,CAAUD,cAAc,EAAmB;IAC/D,MAAM,IAAIpD,KAAK,CAAC,2BAA2B,CAAC;EAC9C,CAAC;EACD;EACA;EACAsD,4BAA4B,EAAEA,CAAA,KAAM,KAAK;EACzCC,mBAAmB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC7BC,gBAAgB,EAAEA,CAAA,KAAM,IAAI;EAC5BC,qBAAqB,EAAEA,CAAA,KAAM,CAAC,GAAG;EACjCC,wBAAwBA,CAAA,EAAG,CAAC,CAAC;EAC7BC,gBAAgB,EAAEA,CAAA,KAAM,KAAK;EAC7BC,eAAe,EAAEA,CAAA,KAAM,IAAI;EAAE;EAC7BC,qBAAqBA,CAAA,EAAG,CAAC,CAAC;EAC1BC,eAAeA,CAAA,EAAG,CAAC,CAAC;EACpBC,sBAAsB,EAAEA,CAAA,KAAM,IAAI;EAClCC,oBAAoB,EAAE,IAAI;EAC1BC,qBAAqB,eAAEhG,aAAa,CAAC,IAAI,CAAC;EAC1CiG,wBAAwBA,CAACC,WAAmB,EAAE;IAC5CzF,qBAAqB,GAAGyF,WAAW;EACrC,CAAC;EACDC,wBAAwBA,CAAA,EAAG;IACzB,OAAO1F,qBAAqB;EAC9B,CAAC;EACD2F,qBAAqBA,CAAA,EAAG;IACtB,IAAI3F,qBAAqB,KAAKN,eAAe,EAAE;MAC7C,OAAOM,qBAAqB;IAC9B;IACA,OAAOR,oBAAoB;EAC7B,CAAC;EACDoG,iBAAiBA,CAAA,EAAG,CAAC;AACvB,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"names":["createContext","DefaultEventPriority","shallowEq","NoEventPriority","DEBUG","debug","args","console","log","currentUpdatePriority","sksgHostConfig","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","propsWithChildren","_container","children","props","instance","appendInitialChild","parentInstance","child","push","finalizeInitialChildren","commitMount","prepareForCommit","resetAfterCommit","container","redraw","getPublicInstance","node","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","prepareUpdate","_instance","oldProps","newProps","propsAreEqual","preparePortalMount","cloneInstance","_oldProps","keepChildren","_newChildSet","createContainerChildSet","appendChildToContainerChildSet","childSet","finalizeContainerChildren","newChildren","root","replaceContainerChildren","cloneHiddenInstance","cloneHiddenTextInstance","getCurrentEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","_node","getInstanceFromNode","prepareScopeUpdate","_scopeInstance","getInstanceFromScope","shouldAttemptEagerTransition","trackSchedulerEvent","resolveEventType","resolveEventTimeStamp","requestPostPaintCallback","maySuspendCommit","preloadInstance","startSuspendingCommit","suspendInstance","waitForCommitToBeReady","NotPendingTransition","HostTransitionContext","setCurrentUpdatePriority","newPriority","getCurrentUpdatePriority","resolveUpdatePriority","resetFormInstance"],"sources":["HostConfig.ts"],"sourcesContent":["/*global NodeJS*/\nimport { createContext } from \"react\";\nimport type { Fiber, HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType } from \"../dom/types\";\nimport { shallowEq } from \"../renderer/typeddash\";\n\nimport type { Node } from \"./Node\";\nimport type { Container } from \"./Container\";\n\ntype EventPriority = number;\nconst NoEventPriority = 0;\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ntype Instance = Node;\n\ntype Props = object;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = object;\ntype UpdatePayload = Container;\ntype ChildSet = Node[];\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\nlet currentUpdatePriority: EventPriority = NoEventPriority;\n\nexport const sksgHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n supportsMutation: false,\n isPrimaryRenderer: false,\n supportsPersistence: true,\n supportsHydration: false,\n //supportsMicrotask: true,\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n getRootHostContext: (_rootContainerInstance: Container) => {\n debug(\"getRootHostContext\");\n return {};\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return {};\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n propsWithChildren,\n _container,\n _hostContext,\n _internalInstanceHandle\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = propsWithChildren as any;\n debug(\"createInstance\", type);\n const instance = {\n type,\n props,\n children: [],\n };\n return instance;\n },\n\n appendInitialChild(parentInstance: Instance, child: Instance | TextInstance) {\n parentInstance.children.push(child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_container: Container) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n resetAfterCommit(container: Container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (_container) => {\n debug(\"clearContainer\");\n },\n\n prepareUpdate(\n _instance: Instance,\n _type: string,\n oldProps: Props,\n newProps: Props,\n container: Container,\n _hostContext: HostContext\n ) {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual) {\n return null;\n }\n return container;\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n cloneInstance(\n instance,\n _type,\n _oldProps,\n newProps,\n keepChildren,\n _newChildSet\n ) {\n debug(\"cloneInstance\");\n return {\n type: instance.type,\n props: { ...newProps },\n children: keepChildren ? [...instance.children] : [],\n };\n },\n\n createContainerChildSet(): ChildSet {\n debug(\"createContainerChildSet\");\n return [];\n },\n\n appendChildToContainerChildSet(\n childSet: ChildSet,\n child: Instance | TextInstance\n ): void {\n childSet.push(child);\n },\n\n finalizeContainerChildren(container: Container, newChildren: ChildSet) {\n debug(\"finalizeContainerChildren\");\n container.root = newChildren;\n },\n\n replaceContainerChildren(container: Container, newChildren: ChildSet) {\n container.root = newChildren;\n },\n\n cloneHiddenInstance(\n _instance: Instance,\n _type: string,\n _props: Props\n ): Instance {\n debug(\"cloneHiddenInstance\");\n throw new Error(\"Not yet implemented.\");\n },\n\n cloneHiddenTextInstance(_instance: Instance, _text: string): TextInstance {\n debug(\"cloneHiddenTextInstance\");\n throw new Error(\"Not yet implemented.\");\n },\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: (_node: Instance) => {},\n getInstanceFromNode: function (_node): Fiber | null | undefined {\n throw new Error(\"Function not implemented.\");\n },\n prepareScopeUpdate: function (_scopeInstance, _instance): void {\n throw new Error(\"Function not implemented.\");\n },\n getInstanceFromScope: function (_scopeInstance): Instance | null {\n throw new Error(\"Function not implemented.\");\n },\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shouldAttemptEagerTransition: () => false,\n trackSchedulerEvent: () => {},\n resolveEventType: () => null,\n resolveEventTimeStamp: () => -1.1,\n requestPostPaintCallback() {},\n maySuspendCommit: () => false,\n preloadInstance: () => true, // true indicates already loaded\n startSuspendingCommit() {},\n suspendInstance() {},\n waitForCommitToBeReady: () => null,\n NotPendingTransition: null,\n HostTransitionContext: createContext(null),\n setCurrentUpdatePriority(newPriority: number) {\n currentUpdatePriority = newPriority;\n },\n getCurrentUpdatePriority() {\n return currentUpdatePriority;\n },\n resolveUpdatePriority() {\n if (currentUpdatePriority !== NoEventPriority) {\n return currentUpdatePriority;\n }\n return DefaultEventPriority;\n },\n resetFormInstance() {},\n};\n"],"mappings":"AAAA;AACA,SAASA,aAAa,QAAQ,OAAO;AAErC,SAASC,oBAAoB,QAAQ,4BAA4B;AAGjE,SAASC,SAAS,QAAQ,uBAAuB;AAMjD,MAAMC,eAAe,GAAG,CAAC;AAEzB,MAAMC,KAAK,GAAG,KAAK;AACnB,OAAO,MAAMC,KAAK,GAAGA,CAAC,GAAGC,IAAoC,KAAK;EAChE,IAAIF,KAAK,EAAE;IACTG,OAAO,CAACC,GAAG,CAAC,GAAGF,IAAI,CAAC;EACtB;AACF,CAAC;AA8BD,IAAIG,qBAAoC,GAAGN,eAAe;AAE1D,OAAO,MAAMO,cAA8B,GAAG;EAC5C;AACF;AACA;EACEC,gBAAgB,EAAE,KAAK;EACvBC,iBAAiB,EAAE,KAAK;EACxBC,mBAAmB,EAAE,IAAI;EACzBC,iBAAiB,EAAE,KAAK;EACxB;EACAC,eAAe,EAAEC,UAAU;EAC3BC,aAAa,EAAEC,YAAY;EAC3BC,SAAS,EAAE,CAAC,CAAC;EAEbC,kBAAkB,EAAGC,sBAAiC,IAAK;IACzDhB,KAAK,CAAC,o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A,CAAA,KAAM,CAAC,CAAC;EAC7BC,gBAAgB,EAAEA,CAAA,KAAM,IAAI;EAC5BC,qBAAqB,EAAEA,CAAA,KAAM,CAAC,GAAG;EACjCC,wBAAwBA,CAAA,EAAG,CAAC,CAAC;EAC7BC,gBAAgB,EAAEA,CAAA,KAAM,KAAK;EAC7BC,eAAe,EAAEA,CAAA,KAAM,IAAI;EAAE;EAC7BC,qBAAqBA,CAAA,EAAG,CAAC,CAAC;EAC1BC,eAAeA,CAAA,EAAG,CAAC,CAAC;EACpBC,sBAAsB,EAAEA,CAAA,KAAM,IAAI;EAClCC,oBAAoB,EAAE,IAAI;EAC1BC,qBAAqB,eAAE/F,aAAa,CAAC,IAAI,CAAC;EAC1CgG,wBAAwBA,CAACC,WAAmB,EAAE;IAC5CxF,qBAAqB,GAAGwF,WAAW;EACrC,CAAC;EACDC,wBAAwBA,CAAA,EAAG;IACzB,OAAOzF,qBAAqB;EAC9B,CAAC;EACD0F,qBAAqBA,CAAA,EAAG;IACtB,IAAI1F,qBAAqB,KAAKN,eAAe,EAAE;MAC7C,OAAOM,qBAAqB;IAC9B;IACA,OAAOR,oBAAoB;EAC7B,CAAC;EACDmG,iBAAiBA,CAAA,EAAG,CAAC;AACvB,CAAC","ignoreList":[]}
|
@@ -14,5 +14,7 @@ export declare const createDrawingContext: (Skia: Skia, paintPool: SkPaint[], ca
|
|
14
14
|
readonly paint: SkPaint;
|
15
15
|
restorePaint: () => SkPaint | undefined;
|
16
16
|
materializePaint: () => void;
|
17
|
+
getOpacity: () => number;
|
18
|
+
setOpacity: (newOpacity: number) => void;
|
17
19
|
};
|
18
20
|
export type DrawingContext = ReturnType<typeof createDrawingContext>;
|
@@ -8,11 +8,13 @@ export const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
8
8
|
const imageFilters = [];
|
9
9
|
const pathEffects = [];
|
10
10
|
const paintDeclarations = [];
|
11
|
+
const opacities = [];
|
11
12
|
let nextPaintIndex = 1;
|
12
13
|
|
13
|
-
// Initialize first paint
|
14
|
+
// Initialize first paint and opacity
|
14
15
|
paintPool[0] = Skia.Paint();
|
15
16
|
paints.push(paintPool[0]);
|
17
|
+
opacities.push(1);
|
16
18
|
|
17
19
|
// Methods (formerly class methods)
|
18
20
|
const savePaint = () => {
|
@@ -23,8 +25,15 @@ export const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
23
25
|
const nextPaint = paintPool[nextPaintIndex];
|
24
26
|
nextPaint.assign(getCurrentPaint()); // Reuse allocation by copying properties
|
25
27
|
paints.push(nextPaint);
|
28
|
+
opacities.push(opacities[opacities.length - 1]);
|
26
29
|
nextPaintIndex++;
|
27
30
|
};
|
31
|
+
const getOpacity = () => {
|
32
|
+
return opacities[opacities.length - 1];
|
33
|
+
};
|
34
|
+
const setOpacity = newOpacity => {
|
35
|
+
opacities[opacities.length - 1] = Math.max(0, Math.min(1, newOpacity));
|
36
|
+
};
|
28
37
|
const saveBackdropFilter = () => {
|
29
38
|
let imageFilter = null;
|
30
39
|
const imgf = imageFilters.pop();
|
@@ -45,6 +54,7 @@ export const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
45
54
|
return paints[paints.length - 1];
|
46
55
|
};
|
47
56
|
const restorePaint = () => {
|
57
|
+
opacities.pop();
|
48
58
|
return paints.pop();
|
49
59
|
};
|
50
60
|
const materializePaint = () => {
|
@@ -93,7 +103,9 @@ export const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
93
103
|
},
|
94
104
|
// the "getter" for the current paint
|
95
105
|
restorePaint,
|
96
|
-
materializePaint
|
106
|
+
materializePaint,
|
107
|
+
getOpacity,
|
108
|
+
setOpacity
|
97
109
|
};
|
98
110
|
};
|
99
111
|
//# sourceMappingURL=DrawingContext.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createDrawingContext","Skia","paintPool","canvas","paints","colorFilters","shaders","imageFilters","pathEffects","paintDeclarations","nextPaintIndex","Paint","push","savePaint","length","nextPaint","assign","getCurrentPaint","saveBackdropFilter","imageFilter","imgf","pop","cf","ImageFilter","MakeColorFilter","saveLayer","undefined","restore","restorePaint","materializePaint","setColorFilter","reduceRight","inner","outer","ColorFilter","MakeCompose","setShader","setImageFilter","setPathEffect","PathEffect","paint"],"sources":["DrawingContext.ts"],"sourcesContent":["import type {\n Skia,\n SkCanvas,\n SkColorFilter,\n SkPaint,\n SkShader,\n SkImageFilter,\n SkPathEffect,\n} from \"../../skia/types\";\n\nexport const createDrawingContext = (\n Skia: Skia,\n paintPool: SkPaint[],\n canvas: SkCanvas\n) => {\n \"worklet\";\n\n // State (formerly class fields)\n const paints: SkPaint[] = [];\n const colorFilters: SkColorFilter[] = [];\n const shaders: SkShader[] = [];\n const imageFilters: SkImageFilter[] = [];\n const pathEffects: SkPathEffect[] = [];\n const paintDeclarations: SkPaint[] = [];\n\n let nextPaintIndex = 1;\n\n // Initialize first paint\n paintPool[0] = Skia.Paint();\n paints.push(paintPool[0]);\n\n // Methods (formerly class methods)\n const savePaint = () => {\n // Get next available paint from pool or create new one if needed\n if (nextPaintIndex >= paintPool.length) {\n paintPool.push(Skia.Paint());\n }\n\n const nextPaint = paintPool[nextPaintIndex];\n nextPaint.assign(getCurrentPaint()); // Reuse allocation by copying properties\n paints.push(nextPaint);\n nextPaintIndex++;\n };\n\n const saveBackdropFilter = () => {\n let imageFilter: SkImageFilter | null = null;\n const imgf = imageFilters.pop();\n if (imgf) {\n imageFilter = imgf;\n } else {\n const cf = colorFilters.pop();\n if (cf) {\n imageFilter = Skia.ImageFilter.MakeColorFilter(cf, null);\n }\n }\n canvas.saveLayer(undefined, null, imageFilter);\n canvas.restore();\n };\n\n // Equivalent to the `get paint()` getter in the original class\n const getCurrentPaint = () => {\n return paints[paints.length - 1];\n };\n\n const restorePaint = () => {\n return paints.pop();\n };\n\n const materializePaint = () => {\n // Color Filters\n if (colorFilters.length > 0) {\n getCurrentPaint().setColorFilter(\n colorFilters.reduceRight((inner, outer) =>\n inner ? Skia.ColorFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n // Shaders\n if (shaders.length > 0) {\n getCurrentPaint().setShader(shaders[shaders.length - 1]);\n }\n // Image Filters\n if (imageFilters.length > 0) {\n getCurrentPaint().setImageFilter(\n imageFilters.reduceRight((inner, outer) =>\n inner ? Skia.ImageFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Path Effects\n if (pathEffects.length > 0) {\n getCurrentPaint().setPathEffect(\n pathEffects.reduceRight((inner, outer) =>\n inner ? Skia.PathEffect.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Clear arrays\n colorFilters.length = 0;\n shaders.length = 0;\n imageFilters.length = 0;\n pathEffects.length = 0;\n };\n\n // Return an object containing the Skia reference, the canvas, and the methods\n return {\n // Public fields\n Skia,\n canvas,\n paints,\n colorFilters,\n shaders,\n imageFilters,\n pathEffects,\n paintDeclarations,\n paintPool,\n\n // Public methods\n savePaint,\n saveBackdropFilter,\n get paint() {\n return paints[paints.length - 1];\n }, // the \"getter\" for the current paint\n restorePaint,\n materializePaint,\n };\n};\n\nexport type DrawingContext = ReturnType<typeof createDrawingContext>;\n"],"mappings":"AAUA,OAAO,MAAMA,oBAAoB,GAAGA,CAClCC,IAAU,EACVC,SAAoB,EACpBC,MAAgB,KACb;EACH,SAAS;;EAET;EACA,MAAMC,MAAiB,GAAG,EAAE;EAC5B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,OAAmB,GAAG,EAAE;EAC9B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,WAA2B,GAAG,EAAE;EACtC,MAAMC,iBAA4B,GAAG,EAAE;
|
1
|
+
{"version":3,"names":["createDrawingContext","Skia","paintPool","canvas","paints","colorFilters","shaders","imageFilters","pathEffects","paintDeclarations","opacities","nextPaintIndex","Paint","push","savePaint","length","nextPaint","assign","getCurrentPaint","getOpacity","setOpacity","newOpacity","Math","max","min","saveBackdropFilter","imageFilter","imgf","pop","cf","ImageFilter","MakeColorFilter","saveLayer","undefined","restore","restorePaint","materializePaint","setColorFilter","reduceRight","inner","outer","ColorFilter","MakeCompose","setShader","setImageFilter","setPathEffect","PathEffect","paint"],"sources":["DrawingContext.ts"],"sourcesContent":["import type {\n Skia,\n SkCanvas,\n SkColorFilter,\n SkPaint,\n SkShader,\n SkImageFilter,\n SkPathEffect,\n} from \"../../skia/types\";\n\nexport const createDrawingContext = (\n Skia: Skia,\n paintPool: SkPaint[],\n canvas: SkCanvas\n) => {\n \"worklet\";\n\n // State (formerly class fields)\n const paints: SkPaint[] = [];\n const colorFilters: SkColorFilter[] = [];\n const shaders: SkShader[] = [];\n const imageFilters: SkImageFilter[] = [];\n const pathEffects: SkPathEffect[] = [];\n const paintDeclarations: SkPaint[] = [];\n const opacities: number[] = [];\n\n let nextPaintIndex = 1;\n\n // Initialize first paint and opacity\n paintPool[0] = Skia.Paint();\n paints.push(paintPool[0]);\n opacities.push(1);\n\n // Methods (formerly class methods)\n const savePaint = () => {\n // Get next available paint from pool or create new one if needed\n if (nextPaintIndex >= paintPool.length) {\n paintPool.push(Skia.Paint());\n }\n\n const nextPaint = paintPool[nextPaintIndex];\n nextPaint.assign(getCurrentPaint()); // Reuse allocation by copying properties\n paints.push(nextPaint);\n opacities.push(opacities[opacities.length - 1]);\n nextPaintIndex++;\n };\n\n const getOpacity = () => {\n return opacities[opacities.length - 1];\n };\n\n const setOpacity = (newOpacity: number) => {\n opacities[opacities.length - 1] = Math.max(0, Math.min(1, newOpacity));\n };\n\n const saveBackdropFilter = () => {\n let imageFilter: SkImageFilter | null = null;\n const imgf = imageFilters.pop();\n if (imgf) {\n imageFilter = imgf;\n } else {\n const cf = colorFilters.pop();\n if (cf) {\n imageFilter = Skia.ImageFilter.MakeColorFilter(cf, null);\n }\n }\n canvas.saveLayer(undefined, null, imageFilter);\n canvas.restore();\n };\n\n // Equivalent to the `get paint()` getter in the original class\n const getCurrentPaint = () => {\n return paints[paints.length - 1];\n };\n\n const restorePaint = () => {\n opacities.pop();\n return paints.pop();\n };\n\n const materializePaint = () => {\n // Color Filters\n if (colorFilters.length > 0) {\n getCurrentPaint().setColorFilter(\n colorFilters.reduceRight((inner, outer) =>\n inner ? Skia.ColorFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n // Shaders\n if (shaders.length > 0) {\n getCurrentPaint().setShader(shaders[shaders.length - 1]);\n }\n // Image Filters\n if (imageFilters.length > 0) {\n getCurrentPaint().setImageFilter(\n imageFilters.reduceRight((inner, outer) =>\n inner ? Skia.ImageFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Path Effects\n if (pathEffects.length > 0) {\n getCurrentPaint().setPathEffect(\n pathEffects.reduceRight((inner, outer) =>\n inner ? Skia.PathEffect.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Clear arrays\n colorFilters.length = 0;\n shaders.length = 0;\n imageFilters.length = 0;\n pathEffects.length = 0;\n };\n\n // Return an object containing the Skia reference, the canvas, and the methods\n return {\n // Public fields\n Skia,\n canvas,\n paints,\n colorFilters,\n shaders,\n imageFilters,\n pathEffects,\n paintDeclarations,\n paintPool,\n\n // Public methods\n savePaint,\n saveBackdropFilter,\n get paint() {\n return paints[paints.length - 1];\n }, // the \"getter\" for the current paint\n restorePaint,\n materializePaint,\n getOpacity,\n setOpacity,\n };\n};\n\nexport type DrawingContext = ReturnType<typeof createDrawingContext>;\n"],"mappings":"AAUA,OAAO,MAAMA,oBAAoB,GAAGA,CAClCC,IAAU,EACVC,SAAoB,EACpBC,MAAgB,KACb;EACH,SAAS;;EAET;EACA,MAAMC,MAAiB,GAAG,EAAE;EAC5B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,OAAmB,GAAG,EAAE;EAC9B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,WAA2B,GAAG,EAAE;EACtC,MAAMC,iBAA4B,GAAG,EAAE;EACvC,MAAMC,SAAmB,GAAG,EAAE;EAE9B,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACAT,SAAS,CAAC,CAAC,CAAC,GAAGD,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AE;MAC1BG,eAAe,CAAC,CAAC,CAAC2B,aAAa,CAC7BrC,WAAW,CAAC8B,WAAW,CAAC,CAACC,KAAK,EAAEC,KAAK,KACnCD,KAAK,GAAGtC,IAAI,CAAC6C,UAAU,CAACJ,WAAW,CAACF,KAAK,EAAED,KAAK,CAAC,GAAGC,KACtD,CACF,CAAC;IACH;;IAEA;IACAnC,YAAY,CAACU,MAAM,GAAG,CAAC;IACvBT,OAAO,CAACS,MAAM,GAAG,CAAC;IAClBR,YAAY,CAACQ,MAAM,GAAG,CAAC;IACvBP,WAAW,CAACO,MAAM,GAAG,CAAC;EACxB,CAAC;;EAED;EACA,OAAO;IACL;IACAd,IAAI;IACJE,MAAM;IACNC,MAAM;IACNC,YAAY;IACZC,OAAO;IACPC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBP,SAAS;IAET;IACAY,SAAS;IACTW,kBAAkB;IAClB,IAAIsB,KAAKA,CAAA,EAAG;MACV,OAAO3C,MAAM,CAACA,MAAM,CAACW,MAAM,GAAG,CAAC,CAAC;IAClC,CAAC;IAAE;IACHoB,YAAY;IACZC,gBAAgB;IAChBjB,UAAU;IACVC;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
@@ -26,7 +26,7 @@ function play(ctx, _command) {
|
|
26
26
|
ctx.paints.push(command.props.paint);
|
27
27
|
} else {
|
28
28
|
ctx.savePaint();
|
29
|
-
setPaintProperties(ctx.Skia, ctx
|
29
|
+
setPaintProperties(ctx.Skia, ctx, command.props);
|
30
30
|
}
|
31
31
|
} else if (isCommand(command, CommandType.RestorePaint)) {
|
32
32
|
ctx.restorePaint();
|
@@ -60,7 +60,11 @@ function play(ctx, _command) {
|
|
60
60
|
} else if (isCommand(command, CommandType.RestoreCTM)) {
|
61
61
|
ctx.canvas.restore();
|
62
62
|
} else {
|
63
|
-
|
63
|
+
// TODO: is a copy needed here?
|
64
|
+
// apply opacity to the current paint.
|
65
|
+
const paint = ctx.paint.copy();
|
66
|
+
paint.setAlphaf(paint.getAlphaf() * ctx.getOpacity());
|
67
|
+
const paints = [paint, ...ctx.paintDeclarations];
|
64
68
|
ctx.paintDeclarations = [];
|
65
69
|
paints.forEach(p => {
|
66
70
|
ctx.paints.push(p);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["drawCircle","drawImage","drawOval","drawPath","drawPoints","drawRect","drawRRect","drawLine","drawAtlas","drawParagraph","drawImageSVG","drawPicture","drawGlyphs","drawTextBlob","drawTextPath","drawText","drawDiffRect","drawVertices","drawPatch","drawBox","isBoxCommand","composeColorFilters","isPushColorFilter","pushColorFilter","saveCTM","setBlurMaskFilter","isPushImageFilter","pushImageFilter","composeImageFilters","setPaintProperties","composePathEffects","isPushPathEffect","pushPathEffect","isPushShader","pushShader","CommandType","isCommand","isDrawCommand","isGroup","materializeCommand","play","ctx","_command","children","forEach","child","command","SaveBackdropFilter","saveBackdropFilter","SaveLayer","materializePaint","paint","paintDeclarations","pop","canvas","saveLayer","SavePaint","props","paints","push","savePaint","Skia","RestorePaint","restorePaint","ComposeColorFilter","RestorePaintDeclaration","Error","MaterializePaint","ComposePathEffect","ComposeImageFilter","PushBlurMaskFilter","SaveCTM","RestoreCTM","restore","p","DrawPaint","drawPaint","DrawImage","DrawCircle","DrawPoints","DrawPath","DrawRect","DrawRRect","DrawOval","DrawLine","DrawPatch","DrawVertices","DrawDiffRect","DrawText","DrawTextPath","DrawTextBlob","DrawGlyphs","DrawPicture","DrawImageSVG","DrawParagraph","DrawAtlas","console","warn","type","replay","commands"],"sources":["Player.ts"],"sourcesContent":["import {\n drawCircle,\n drawImage,\n drawOval,\n drawPath,\n drawPoints,\n drawRect,\n drawRRect,\n drawLine,\n drawAtlas,\n drawParagraph,\n drawImageSVG,\n drawPicture,\n drawGlyphs,\n drawTextBlob,\n drawTextPath,\n drawText,\n drawDiffRect,\n drawVertices,\n drawPatch,\n} from \"./commands/Drawing\";\nimport { drawBox, isBoxCommand } from \"./commands/Box\";\nimport {\n composeColorFilters,\n isPushColorFilter,\n pushColorFilter,\n} from \"./commands/ColorFilters\";\nimport { saveCTM } from \"./commands/CTM\";\nimport {\n setBlurMaskFilter,\n isPushImageFilter,\n pushImageFilter,\n composeImageFilters,\n} from \"./commands/ImageFilters\";\nimport { setPaintProperties } from \"./commands/Paint\";\nimport {\n composePathEffects,\n isPushPathEffect,\n pushPathEffect,\n} from \"./commands/PathEffects\";\nimport { isPushShader, pushShader } from \"./commands/Shaders\";\nimport {\n CommandType,\n isCommand,\n isDrawCommand,\n isGroup,\n materializeCommand,\n} from \"./Core\";\nimport type { Command } from \"./Core\";\nimport type { DrawingContext } from \"./DrawingContext\";\n\nfunction play(ctx: DrawingContext, _command: Command) {\n \"worklet\";\n if (isGroup(_command)) {\n _command.children.forEach((child) => play(ctx, child));\n return;\n }\n const command = materializeCommand(_command);\n if (isCommand(command, CommandType.SaveBackdropFilter)) {\n ctx.saveBackdropFilter();\n } else if (isCommand(command, CommandType.SaveLayer)) {\n ctx.materializePaint();\n const paint = ctx.paintDeclarations.pop();\n ctx.canvas.saveLayer(paint);\n } else if (isDrawCommand(command, CommandType.SavePaint)) {\n if (command.props.paint) {\n ctx.paints.push(command.props.paint);\n } else {\n ctx.savePaint();\n setPaintProperties(ctx.Skia, ctx.paint, command.props);\n }\n } else if (isCommand(command, CommandType.RestorePaint)) {\n ctx.restorePaint();\n } else if (isCommand(command, CommandType.ComposeColorFilter)) {\n composeColorFilters(ctx);\n } else if (isCommand(command, CommandType.RestorePaintDeclaration)) {\n ctx.materializePaint();\n const paint = ctx.restorePaint();\n if (!paint) {\n throw new Error(\"No paint declaration to push\");\n }\n ctx.paintDeclarations.push(paint);\n } else if (isCommand(command, CommandType.MaterializePaint)) {\n ctx.materializePaint();\n } else if (isPushColorFilter(command)) {\n pushColorFilter(ctx, command);\n } else if (isPushShader(command)) {\n pushShader(ctx, command);\n } else if (isPushImageFilter(command)) {\n pushImageFilter(ctx, command);\n } else if (isPushPathEffect(command)) {\n pushPathEffect(ctx, command);\n } else if (isCommand(command, CommandType.ComposePathEffect)) {\n composePathEffects(ctx);\n } else if (isCommand(command, CommandType.ComposeImageFilter)) {\n composeImageFilters(ctx);\n } else if (isDrawCommand(command, CommandType.PushBlurMaskFilter)) {\n setBlurMaskFilter(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.SaveCTM)) {\n saveCTM(ctx, command.props);\n } else if (isCommand(command, CommandType.RestoreCTM)) {\n ctx.canvas.restore();\n } else {\n const paints = [ctx.paint, ...ctx.paintDeclarations];\n ctx.paintDeclarations = [];\n paints.forEach((p) => {\n ctx.paints.push(p);\n if (isBoxCommand(command)) {\n drawBox(ctx, command);\n } else if (isCommand(command, CommandType.DrawPaint)) {\n ctx.canvas.drawPaint(ctx.paint);\n } else if (isDrawCommand(command, CommandType.DrawImage)) {\n drawImage(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawCircle)) {\n drawCircle(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPoints)) {\n drawPoints(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPath)) {\n drawPath(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawRect)) {\n drawRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawRRect)) {\n drawRRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawOval)) {\n drawOval(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawLine)) {\n drawLine(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPatch)) {\n drawPatch(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawVertices)) {\n drawVertices(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawDiffRect)) {\n drawDiffRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawText)) {\n drawText(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawTextPath)) {\n drawTextPath(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawTextBlob)) {\n drawTextBlob(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawGlyphs)) {\n drawGlyphs(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPicture)) {\n drawPicture(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawImageSVG)) {\n drawImageSVG(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawParagraph)) {\n drawParagraph(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawAtlas)) {\n drawAtlas(ctx, command.props);\n } else {\n console.warn(`Unknown command: ${command.type}`);\n }\n ctx.paints.pop();\n });\n }\n}\n\nexport const replay = (ctx: DrawingContext, commands: Command[]) => {\n \"worklet\";\n commands.forEach((command) => {\n play(ctx, command);\n });\n};\n"],"mappings":"AAAA,SACEA,UAAU,EACVC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,QAAQ,EACRC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,aAAa,EACbC,YAAY,EACZC,WAAW,EACXC,UAAU,EACVC,YAAY,EACZC,YAAY,EACZC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,SAAS,QACJ,oBAAoB;AAC3B,SAASC,OAAO,EAAEC,YAAY,QAAQ,gBAAgB;AACtD,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,eAAe,QACV,yBAAyB;AAChC,SAASC,OAAO,QAAQ,gBAAgB;AACxC,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,eAAe,EACfC,mBAAmB,QACd,yBAAyB;AAChC,SAASC,kBAAkB,QAAQ,kBAAkB;AACrD,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,QACT,wBAAwB;AAC/B,SAASC,YAAY,EAAEC,UAAU,QAAQ,oBAAoB;AAC7D,SACEC,WAAW,EACXC,SAAS,EACTC,aAAa,EACbC,OAAO,EACPC,kBAAkB,QACb,QAAQ;AAIf,SAASC,IAAIA,CAACC,GAAmB,EAAEC,QAAiB,EAAE;EACpD,SAAS;;EACT,IAAIJ,OA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GAAGA,CAAC1D,GAAmB,EAAE2D,QAAmB,KAAK;EAClE,SAAS;;EACTA,QAAQ,CAACxD,OAAO,CAAEE,OAAO,IAAK;IAC5BN,IAAI,CAACC,GAAG,EAAEK,OAAO,CAAC;EACpB,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"names":["drawCircle","drawImage","drawOval","drawPath","drawPoints","drawRect","drawRRect","drawLine","drawAtlas","drawParagraph","drawImageSVG","drawPicture","drawGlyphs","drawTextBlob","drawTextPath","drawText","drawDiffRect","drawVertices","drawPatch","drawBox","isBoxCommand","composeColorFilters","isPushColorFilter","pushColorFilter","saveCTM","setBlurMaskFilter","isPushImageFilter","pushImageFilter","composeImageFilters","setPaintProperties","composePathEffects","isPushPathEffect","pushPathEffect","isPushShader","pushShader","CommandType","isCommand","isDrawCommand","isGroup","materializeCommand","play","ctx","_command","children","forEach","child","command","SaveBackdropFilter","saveBackdropFilter","SaveLayer","materializePaint","paint","paintDeclarations","pop","canvas","saveLayer","SavePaint","props","paints","push","savePaint","Skia","RestorePaint","restorePaint","ComposeColorFilter","RestorePaintDeclaration","Error","MaterializePaint","ComposePathEffect","ComposeImageFilter","PushBlurMaskFilter","SaveCTM","RestoreCTM","restore","copy","setAlphaf","getAlphaf","getOpacity","p","DrawPaint","drawPaint","DrawImage","DrawCircle","DrawPoints","DrawPath","DrawRect","DrawRRect","DrawOval","DrawLine","DrawPatch","DrawVertices","DrawDiffRect","DrawText","DrawTextPath","DrawTextBlob","DrawGlyphs","DrawPicture","DrawImageSVG","DrawParagraph","DrawAtlas","console","warn","type","replay","commands"],"sources":["Player.ts"],"sourcesContent":["import {\n drawCircle,\n drawImage,\n drawOval,\n drawPath,\n drawPoints,\n drawRect,\n drawRRect,\n drawLine,\n drawAtlas,\n drawParagraph,\n drawImageSVG,\n drawPicture,\n drawGlyphs,\n drawTextBlob,\n drawTextPath,\n drawText,\n drawDiffRect,\n drawVertices,\n drawPatch,\n} from \"./commands/Drawing\";\nimport { drawBox, isBoxCommand } from \"./commands/Box\";\nimport {\n composeColorFilters,\n isPushColorFilter,\n pushColorFilter,\n} from \"./commands/ColorFilters\";\nimport { saveCTM } from \"./commands/CTM\";\nimport {\n setBlurMaskFilter,\n isPushImageFilter,\n pushImageFilter,\n composeImageFilters,\n} from \"./commands/ImageFilters\";\nimport { setPaintProperties } from \"./commands/Paint\";\nimport {\n composePathEffects,\n isPushPathEffect,\n pushPathEffect,\n} from \"./commands/PathEffects\";\nimport { isPushShader, pushShader } from \"./commands/Shaders\";\nimport {\n CommandType,\n isCommand,\n isDrawCommand,\n isGroup,\n materializeCommand,\n} from \"./Core\";\nimport type { Command } from \"./Core\";\nimport type { DrawingContext } from \"./DrawingContext\";\n\nfunction play(ctx: DrawingContext, _command: Command) {\n \"worklet\";\n if (isGroup(_command)) {\n _command.children.forEach((child) => play(ctx, child));\n return;\n }\n const command = materializeCommand(_command);\n if (isCommand(command, CommandType.SaveBackdropFilter)) {\n ctx.saveBackdropFilter();\n } else if (isCommand(command, CommandType.SaveLayer)) {\n ctx.materializePaint();\n const paint = ctx.paintDeclarations.pop();\n ctx.canvas.saveLayer(paint);\n } else if (isDrawCommand(command, CommandType.SavePaint)) {\n if (command.props.paint) {\n ctx.paints.push(command.props.paint);\n } else {\n ctx.savePaint();\n setPaintProperties(ctx.Skia, ctx, command.props);\n }\n } else if (isCommand(command, CommandType.RestorePaint)) {\n ctx.restorePaint();\n } else if (isCommand(command, CommandType.ComposeColorFilter)) {\n composeColorFilters(ctx);\n } else if (isCommand(command, CommandType.RestorePaintDeclaration)) {\n ctx.materializePaint();\n const paint = ctx.restorePaint();\n if (!paint) {\n throw new Error(\"No paint declaration to push\");\n }\n ctx.paintDeclarations.push(paint);\n } else if (isCommand(command, CommandType.MaterializePaint)) {\n ctx.materializePaint();\n } else if (isPushColorFilter(command)) {\n pushColorFilter(ctx, command);\n } else if (isPushShader(command)) {\n pushShader(ctx, command);\n } else if (isPushImageFilter(command)) {\n pushImageFilter(ctx, command);\n } else if (isPushPathEffect(command)) {\n pushPathEffect(ctx, command);\n } else if (isCommand(command, CommandType.ComposePathEffect)) {\n composePathEffects(ctx);\n } else if (isCommand(command, CommandType.ComposeImageFilter)) {\n composeImageFilters(ctx);\n } else if (isDrawCommand(command, CommandType.PushBlurMaskFilter)) {\n setBlurMaskFilter(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.SaveCTM)) {\n saveCTM(ctx, command.props);\n } else if (isCommand(command, CommandType.RestoreCTM)) {\n ctx.canvas.restore();\n } else {\n // TODO: is a copy needed here?\n // apply opacity to the current paint.\n const paint = ctx.paint.copy();\n paint.setAlphaf(paint.getAlphaf() * ctx.getOpacity());\n const paints = [paint, ...ctx.paintDeclarations];\n ctx.paintDeclarations = [];\n paints.forEach((p) => {\n ctx.paints.push(p);\n if (isBoxCommand(command)) {\n drawBox(ctx, command);\n } else if (isCommand(command, CommandType.DrawPaint)) {\n ctx.canvas.drawPaint(ctx.paint);\n } else if (isDrawCommand(command, CommandType.DrawImage)) {\n drawImage(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawCircle)) {\n drawCircle(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPoints)) {\n drawPoints(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPath)) {\n drawPath(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawRect)) {\n drawRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawRRect)) {\n drawRRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawOval)) {\n drawOval(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawLine)) {\n drawLine(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPatch)) {\n drawPatch(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawVertices)) {\n drawVertices(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawDiffRect)) {\n drawDiffRect(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawText)) {\n drawText(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawTextPath)) {\n drawTextPath(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawTextBlob)) {\n drawTextBlob(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawGlyphs)) {\n drawGlyphs(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawPicture)) {\n drawPicture(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawImageSVG)) {\n drawImageSVG(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawParagraph)) {\n drawParagraph(ctx, command.props);\n } else if (isDrawCommand(command, CommandType.DrawAtlas)) {\n drawAtlas(ctx, command.props);\n } else {\n console.warn(`Unknown command: ${command.type}`);\n }\n ctx.paints.pop();\n });\n }\n}\n\nexport const replay = (ctx: DrawingContext, commands: Command[]) => {\n \"worklet\";\n commands.forEach((command) => {\n play(ctx, command);\n });\n};\n"],"mappings":"AAAA,SACEA,UAAU,EACVC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,QAAQ,EACRC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,aAAa,EACbC,YAAY,EACZC,WAAW,EACXC,UAAU,EACVC,YAAY,EACZC,YAAY,EACZC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,SAAS,QACJ,oBAAoB;AAC3B,SAASC,OAAO,EAAEC,YAAY,QAAQ,gBAAgB;AACtD,SACEC,mBAAmB,EACnBC,iBAAiB,EACjBC,eAAe,QACV,yBAAyB;AAChC,SAASC,OAAO,QAAQ,gBAAgB;AACxC,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,eAAe,EACfC,mBAAmB,QACd,yBAAyB;AAChC,SAASC,kBAAkB,QAAQ,kBAAkB;AACrD,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,QACT,wBAAwB;AAC/B,SAASC,YAAY,EAAEC,UAAU,QAAQ,oBAAoB;AAC7D,SACEC,WAAW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AAa,CAACS,OAAO,EAAEX,WAAW,CAACgE,SAAS,CAAC,EAAE;QACxD3F,SAAS,CAACiC,GAAG,EAAEK,OAAO,CAACW,KAAK,CAAC;MAC/B,CAAC,MAAM;QACL2C,OAAO,CAACC,IAAI,CAAC,oBAAoBvD,OAAO,CAACwD,IAAI,EAAE,CAAC;MAClD;MACA7D,GAAG,CAACiB,MAAM,CAACL,GAAG,CAAC,CAAC;IAClB,CAAC,CAAC;EACJ;AACF;AAEA,OAAO,MAAMkD,MAAM,GAAGA,CAAC9D,GAAmB,EAAE+D,QAAmB,KAAK;EAClE,SAAS;;EACTA,QAAQ,CAAC5D,OAAO,CAAEE,OAAO,IAAK;IAC5BN,IAAI,CAACC,GAAG,EAAEK,OAAO,CAAC;EACpB,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import type { PaintProps } from "../../../dom/types";
|
2
|
-
import type {
|
3
|
-
|
2
|
+
import type { Skia } from "../../../skia/types";
|
3
|
+
import type { DrawingContext } from "../DrawingContext";
|
4
|
+
export declare const setPaintProperties: (Skia: Skia, ctx: DrawingContext, { opacity, color, blendMode, strokeWidth, style, strokeJoin, strokeCap, strokeMiter, antiAlias, dither, }: PaintProps) => void;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { enumKey, processColor } from "../../../dom/nodes";
|
2
2
|
import { BlendMode, PaintStyle, StrokeCap, StrokeJoin } from "../../../skia/types";
|
3
|
-
export const setPaintProperties = (Skia,
|
3
|
+
export const setPaintProperties = (Skia, ctx, {
|
4
4
|
opacity,
|
5
5
|
color,
|
6
6
|
blendMode,
|
@@ -14,14 +14,15 @@ export const setPaintProperties = (Skia, paint, {
|
|
14
14
|
}) => {
|
15
15
|
"worklet";
|
16
16
|
|
17
|
+
const {
|
18
|
+
paint
|
19
|
+
} = ctx;
|
17
20
|
if (opacity !== undefined) {
|
18
|
-
|
21
|
+
ctx.setOpacity(ctx.getOpacity() * opacity);
|
19
22
|
}
|
20
23
|
if (color !== undefined) {
|
21
|
-
const currentOpacity = paint.getAlphaf();
|
22
24
|
paint.setShader(null);
|
23
25
|
paint.setColor(processColor(Skia, color));
|
24
|
-
paint.setAlphaf(currentOpacity * paint.getAlphaf());
|
25
26
|
}
|
26
27
|
if (blendMode !== undefined) {
|
27
28
|
paint.setBlendMode(BlendMode[enumKey(blendMode)]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["enumKey","processColor","BlendMode","PaintStyle","StrokeCap","StrokeJoin","setPaintProperties","Skia","
|
1
|
+
{"version":3,"names":["enumKey","processColor","BlendMode","PaintStyle","StrokeCap","StrokeJoin","setPaintProperties","Skia","ctx","opacity","color","blendMode","strokeWidth","style","strokeJoin","strokeCap","strokeMiter","antiAlias","dither","paint","undefined","setOpacity","getOpacity","setShader","setColor","setBlendMode","setStrokeWidth","setStyle","setStrokeJoin","setStrokeCap","setStrokeMiter","setAntiAlias","setDither"],"sources":["Paint.ts"],"sourcesContent":["import { enumKey, processColor } from \"../../../dom/nodes\";\nimport type { PaintProps } from \"../../../dom/types\";\nimport {\n BlendMode,\n PaintStyle,\n StrokeCap,\n StrokeJoin,\n} from \"../../../skia/types\";\nimport type { Skia } from \"../../../skia/types\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nexport const setPaintProperties = (\n Skia: Skia,\n ctx: DrawingContext,\n {\n opacity,\n color,\n blendMode,\n strokeWidth,\n style,\n strokeJoin,\n strokeCap,\n strokeMiter,\n antiAlias,\n dither,\n }: PaintProps\n) => {\n \"worklet\";\n const { paint } = ctx;\n\n if (opacity !== undefined) {\n ctx.setOpacity(ctx.getOpacity() * opacity);\n }\n if (color !== undefined) {\n paint.setShader(null);\n paint.setColor(processColor(Skia, color));\n }\n if (blendMode !== undefined) {\n paint.setBlendMode(BlendMode[enumKey(blendMode)]);\n }\n if (strokeWidth !== undefined) {\n paint.setStrokeWidth(strokeWidth);\n }\n if (style !== undefined) {\n paint.setStyle(PaintStyle[enumKey(style)]);\n }\n if (strokeJoin !== undefined) {\n paint.setStrokeJoin(StrokeJoin[enumKey(strokeJoin)]);\n }\n if (strokeCap !== undefined) {\n paint.setStrokeCap(StrokeCap[enumKey(strokeCap)]);\n }\n if (strokeMiter !== undefined) {\n paint.setStrokeMiter(strokeMiter);\n }\n if (antiAlias !== undefined) {\n paint.setAntiAlias(antiAlias);\n }\n if (dither !== undefined) {\n paint.setDither(dither);\n }\n};\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,YAAY,QAAQ,oBAAoB;AAE1D,SACEC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,UAAU,QACL,qBAAqB;AAI5B,OAAO,MAAMC,kBAAkB,GAAGA,CAChCC,IAAU,EACVC,GAAmB,EACnB;EACEC,OAAO;EACPC,KAAK;EACLC,SAAS;EACTC,WAAW;EACXC,KAAK;EACLC,UAAU;EACVC,SAAS;EACTC,WAAW;EACXC,SAAS;EACTC;AACU,CAAC,KACV;EACH,SAAS;;EACT,MAAM;IAAEC;EAAM,CAAC,GAAGX,GAAG;EAErB,IAAIC,OAAO,KAAKW,SAAS,EAAE;IACzBZ,GAAG,CAACa,UAAU,CAACb,GAAG,CAACc,UAAU,CAAC,CAAC,GAAGb,OAAO,CAAC;EAC5C;EACA,IAAIC,KAAK,KAAKU,SAAS,EAAE;IACvBD,KAAK,CAACI,SAAS,CAAC,IAAI,CAAC;IACrBJ,KAAK,CAACK,QAAQ,CAACvB,YAAY,CAACM,IAAI,EAAEG,KAAK,CAAC,CAAC;EAC3C;EACA,IAAIC,SAAS,KAAKS,SAAS,EAAE;IAC3BD,KAAK,CAACM,YAAY,CAACvB,SAAS,CAACF,OAAO,CAACW,SAAS,CAAC,CAAC,CAAC;EACnD;EACA,IAAIC,WAAW,KAAKQ,SAAS,EAAE;IAC7BD,KAAK,CAACO,cAAc,CAACd,WAAW,CAAC;EACnC;EACA,IAAIC,KAAK,KAAKO,SAAS,EAAE;IACvBD,KAAK,CAACQ,QAAQ,CAACxB,UAAU,CAACH,OAAO,CAACa,KAAK,CAAC,CAAC,CAAC;EAC5C;EACA,IAAIC,UAAU,KAAKM,SAAS,EAAE;IAC5BD,KAAK,CAACS,aAAa,CAACvB,UAAU,CAACL,OAAO,CAACc,UAAU,CAAC,CAAC,CAAC;EACtD;EACA,IAAIC,SAAS,KAAKK,SAAS,EAAE;IAC3BD,KAAK,CAACU,YAAY,CAACzB,SAAS,CAACJ,OAAO,CAACe,SAAS,CAAC,CAAC,CAAC;EACnD;EACA,IAAIC,WAAW,KAAKI,SAAS,EAAE;IAC7BD,KAAK,CAACW,cAAc,CAACd,WAAW,CAAC;EACnC;EACA,IAAIC,SAAS,KAAKG,SAAS,EAAE;IAC3BD,KAAK,CAACY,YAAY,CAACd,SAAS,CAAC;EAC/B;EACA,IAAIC,MAAM,KAAKE,SAAS,EAAE;IACxBD,KAAK,CAACa,SAAS,CAACd,MAAM,CAAC;EACzB;AACF,CAAC","ignoreList":[]}
|
@@ -36,6 +36,10 @@ export class SkiaBaseWebView extends React.Component {
|
|
36
36
|
canvas.width = this.width * pd;
|
37
37
|
canvas.height = this.height * pd;
|
38
38
|
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
|
39
|
+
const ctx = canvas.getContext("webgl2");
|
40
|
+
if (ctx) {
|
41
|
+
ctx.drawingBufferColorSpace = "display-p3";
|
42
|
+
}
|
39
43
|
if (!surface) {
|
40
44
|
throw new Error("Could not create surface");
|
41
45
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","JsiSkSurface","Platform","pd","PixelRatio","SkiaBaseWebView","Component","constructor","props","_defineProperty","createRef","onLayoutEvent","bind","unsubscribeAll","_unsubscriptions","forEach","u","evt","CanvasKit","global","canvas","_canvasRef","current","width","clientWidth","height","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","onLayout","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","_this$_canvasRef$curr","
|
1
|
+
{"version":3,"names":["React","JsiSkSurface","Platform","pd","PixelRatio","SkiaBaseWebView","Component","constructor","props","_defineProperty","createRef","onLayoutEvent","bind","unsubscribeAll","_unsubscriptions","forEach","u","evt","CanvasKit","global","canvas","_canvasRef","current","width","clientWidth","height","clientHeight","surface","MakeWebGLCanvasSurface","ctx","getContext","drawingBufferColorSpace","Error","_surface","_canvas","getCanvas","redraw","onLayout","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","_this$_canvasRef$curr","getExtension","loseContext","makeImageSnapshot","rect","_this$_surface","_this$_surface2","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","_this$_surface3","Float32Array","of","save","scale","restore","requestAnimationFrame","render","debug","viewProps","createElement","View","_extends","style","display","flex"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\n\nimport type { SkiaBaseViewProps } from \"./types\";\n\nconst pd = Platform.PixelRatio;\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayoutEvent(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n // Reset canvas / surface on layout change\n const canvas = this._canvasRef.current;\n if (canvas) {\n this.width = canvas.clientWidth;\n this.height = canvas.clientHeight;\n canvas.width = this.width * pd;\n canvas.height = this.height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // eslint-disable-next-line max-len\n // https://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n // We delete the context, only if the context has been intialized\n if (this._surface) {\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(canvas: SkCanvas): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n private onLayout = this.onLayoutEvent.bind(this);\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <Platform.View {...viewProps} onLayout={this.onLayout}>\n <canvas ref={this._canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n }\n}\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,MAAMC,EAAE,GAAGD,QAAQ,CAACE,UAAU;AAE9B,OAAO,MAAeC,eAAe,SAE3BL,KAAK,CAACM,SAAS,CAAS;EAChCC,WAAWA,CAACC,KAAa,EAAE;IACzB,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA,mBAGyB,IAAI;IAAAA,eAAA,2BACE,EAAE;IAAAA,eAAA,kBACb,IAAI;IAAAA,eAAA,kCAClBT,KAAK,CAACU,SAAS,CAAoB,CAAC;IAAAD,eAAA,0BAC/B,CAAC;IAAAA,eAAA,oBACP,CAAC;IAAAA,eAAA,gBAEH,CAAC;IAAAA,eAAA,iBACA,CAAC;IAAAA,eAAA,mBAsGD,IAAI,CAACE,aAAa,CAACC,IAAI,CAAC,IAAI,CAAC;EAhHhD;EAYQC,cAAcA,CAAA,EAAG;IACvB,IAAI,CAACC,gBAAgB,CAACC,OAAO,CAAEC,CAAC,IAAKA,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,CAACF,gBAAgB,GAAG,EAAE;EAC5B;EAEQH,aAAaA,CAACM,GAAsB,EAAE;IAC5C,MAAM;MAAEC;IAAU,CAAC,GAAGC,MAAM;IAC5B;IACA,MAAMC,MAAM,GAAG,IAAI,CAACC,UAAU,CAACC,OAAO;IACtC,IAAIF,MAAM,EAAE;MACV,IAAI,CAACG,KAAK,GAAGH,MAAM,CAACI,WAAW;MAC/B,IAAI,CAACC,MAAM,GAAGL,MAAM,CAACM,YAAY;MACjCN,MAAM,CAACG,KAAK,GAAG,IAAI,CA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AAAyB,eAAA,eAAbA,eAAA,CAAeH,GAAG,CAACC,KAAK,CAAC,CAAC;MAC5B;IACF;IACA,IAAI,CAACZ,SAAS,GAAGoB,qBAAqB,CAAC,IAAI,CAACxB,IAAI,CAAC5B,IAAI,CAAC,IAAI,CAAC,CAAC;EAC9D;EAEOwB,MAAMA,CAAA,EAAG;IACd,IAAI,CAACqB,eAAe,EAAE;EACxB;EAIAQ,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEC,KAAK,GAAG,KAAK;MAAE,GAAGC;IAAU,CAAC,GAAG,IAAI,CAAC3D,KAAK;IAClD,oBACER,KAAA,CAAAoE,aAAA,CAAClE,QAAQ,CAACmE,IAAI,EAAAC,QAAA,KAAKH,SAAS;MAAE9B,QAAQ,EAAE,IAAI,CAACA;IAAS,iBACpDrC,KAAA,CAAAoE,aAAA;MAAQb,GAAG,EAAE,IAAI,CAAClC,UAAW;MAACkD,KAAK,EAAE;QAAEC,OAAO,EAAE,MAAM;QAAEC,IAAI,EAAE;MAAE;IAAE,CAAE,CACvD,CAAC;EAEpB;AACF","ignoreList":[]}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
2
|
export class JsiSkImageFactory extends _Host.Host {
|
3
|
+
MakeNull(): _JsiSkImage.JsiSkImage;
|
3
4
|
MakeImageFromViewTag(viewTag: any): Promise<null>;
|
4
5
|
MakeImageFromNativeBuffer(buffer: any, surface: any, image: any): _JsiSkImage.JsiSkImage;
|
5
6
|
MakeImageFromEncoded(encoded: any): _JsiSkImage.JsiSkImage | null;
|
@@ -5,7 +5,7 @@ export class JsiSkSurface extends _Host.HostObject {
|
|
5
5
|
width(): any;
|
6
6
|
height(): any;
|
7
7
|
getCanvas(): _JsiSkCanvas.JsiSkCanvas;
|
8
|
-
makeImageSnapshot(bounds: any): _JsiSkImage.JsiSkImage;
|
8
|
+
makeImageSnapshot(bounds: any, outputImage: any): _JsiSkImage.JsiSkImage;
|
9
9
|
getNativeTextureUnstable(): null;
|
10
10
|
}
|
11
11
|
import _Host = require("./Host");
|
@@ -26,7 +26,7 @@ export namespace sksgHostConfig {
|
|
26
26
|
function clearContainer(_container: any): void;
|
27
27
|
function prepareUpdate(_instance: any, _type: any, oldProps: any, newProps: any, container: any, _hostContext: any): any;
|
28
28
|
function preparePortalMount(): void;
|
29
|
-
function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any,
|
29
|
+
function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any, keepChildren: any, _newChildSet: any): {
|
30
30
|
type: any;
|
31
31
|
props: any;
|
32
32
|
children: any[];
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export function setPaintProperties(Skia: any,
|
2
|
+
export function setPaintProperties(Skia: any, ctx: any, { opacity, color, blendMode, strokeWidth, style, strokeJoin, strokeCap, strokeMiter, antiAlias, dither }: {
|
3
3
|
opacity: any;
|
4
4
|
color: any;
|
5
5
|
blendMode: any;
|
@@ -4,7 +4,7 @@ export class JsiSkSurface extends HostObject {
|
|
4
4
|
width(): any;
|
5
5
|
height(): any;
|
6
6
|
getCanvas(): JsiSkCanvas;
|
7
|
-
makeImageSnapshot(bounds: any): JsiSkImage;
|
7
|
+
makeImageSnapshot(bounds: any, outputImage: any): JsiSkImage;
|
8
8
|
getNativeTextureUnstable(): null;
|
9
9
|
}
|
10
10
|
import { HostObject } from "./Host";
|
@@ -26,7 +26,7 @@ export namespace sksgHostConfig {
|
|
26
26
|
function clearContainer(_container: any): void;
|
27
27
|
function prepareUpdate(_instance: any, _type: any, oldProps: any, newProps: any, container: any, _hostContext: any): any;
|
28
28
|
function preparePortalMount(): void;
|
29
|
-
function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any,
|
29
|
+
function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any, keepChildren: any, _newChildSet: any): {
|
30
30
|
type: any;
|
31
31
|
props: any;
|
32
32
|
children: any[];
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export function setPaintProperties(Skia: any,
|
1
|
+
export function setPaintProperties(Skia: any, ctx: any, { opacity, color, blendMode, strokeWidth, style, strokeJoin, strokeCap, strokeMiter, antiAlias, dither }: {
|
2
2
|
opacity: any;
|
3
3
|
color: any;
|
4
4
|
blendMode: any;
|
@@ -15,6 +15,7 @@ export interface ImageInfo {
|
|
15
15
|
width: number;
|
16
16
|
}
|
17
17
|
export interface ImageFactory {
|
18
|
+
MakeNull: () => SkImage;
|
18
19
|
/**
|
19
20
|
* Return an Image backed by the encoded data, but attempt to defer decoding until the image
|
20
21
|
* is actually used/drawn. This deferral allows the system to cache the result, either on the
|
@@ -58,7 +59,7 @@ export interface ImageFactory {
|
|
58
59
|
*
|
59
60
|
* @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.
|
60
61
|
*/
|
61
|
-
MakeImageFromNativeTextureUnstable: (texture: unknown, width: number, height: number, mipmapped?: boolean) => SkImage;
|
62
|
+
MakeImageFromNativeTextureUnstable: (texture: unknown, width: number, height: number, mipmapped?: boolean, outputImage?: SkImage) => SkImage;
|
62
63
|
/**
|
63
64
|
* Returns an image that will be a screenshot of the view represented by
|
64
65
|
* the view tag
|
@@ -32,7 +32,7 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
32
32
|
|
33
33
|
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
|
34
34
|
*/
|
35
|
-
makeImageSnapshot(bounds?: SkRect): SkImage;
|
35
|
+
makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;
|
36
36
|
/**
|
37
37
|
* Make sure any queued draws are sent to the screen or the GPU.
|
38
38
|
*/
|
@@ -5,6 +5,7 @@ import { JsiSkImage } from "./JsiSkImage";
|
|
5
5
|
import type { JsiSkSurface } from "./JsiSkSurface";
|
6
6
|
export declare class JsiSkImageFactory extends Host implements ImageFactory {
|
7
7
|
constructor(CanvasKit: CanvasKit);
|
8
|
+
MakeNull(): JsiSkImage;
|
8
9
|
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
|
9
10
|
MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
|
10
11
|
MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { CanvasKit, Surface } from "canvaskit-wasm";
|
2
2
|
import type { SkCanvas, SkImage, SkRect, SkSurface } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
|
+
import { JsiSkImage } from "./JsiSkImage";
|
4
5
|
export declare class JsiSkSurface extends HostObject<Surface, "Surface"> implements SkSurface {
|
5
6
|
constructor(CanvasKit: CanvasKit, ref: Surface);
|
6
7
|
dispose: () => void;
|
@@ -8,6 +9,6 @@ export declare class JsiSkSurface extends HostObject<Surface, "Surface"> impleme
|
|
8
9
|
width(): number;
|
9
10
|
height(): number;
|
10
11
|
getCanvas(): SkCanvas;
|
11
|
-
makeImageSnapshot(bounds?: SkRect): SkImage;
|
12
|
+
makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage;
|
12
13
|
getNativeTextureUnstable(): unknown;
|
13
14
|
}
|
@@ -14,5 +14,7 @@ export declare const createDrawingContext: (Skia: Skia, paintPool: SkPaint[], ca
|
|
14
14
|
readonly paint: SkPaint;
|
15
15
|
restorePaint: () => SkPaint | undefined;
|
16
16
|
materializePaint: () => void;
|
17
|
+
getOpacity: () => number;
|
18
|
+
setOpacity: (newOpacity: number) => void;
|
17
19
|
};
|
18
20
|
export type DrawingContext = ReturnType<typeof createDrawingContext>;
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import type { PaintProps } from "../../../dom/types";
|
2
|
-
import type {
|
3
|
-
|
2
|
+
import type { Skia } from "../../../skia/types";
|
3
|
+
import type { DrawingContext } from "../DrawingContext";
|
4
|
+
export declare const setPaintProperties: (Skia: Skia, ctx: DrawingContext, { opacity, color, blendMode, strokeWidth, style, strokeJoin, strokeCap, strokeMiter, antiAlias, dither, }: PaintProps) => void;
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
9
9
|
},
|
10
10
|
"title": "React Native Skia",
|
11
|
-
"version": "2.0.
|
11
|
+
"version": "2.0.3",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|