@shopify/react-native-skia 2.11.0 → 2.11.1
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/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -10
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +9 -12
- package/apple/RNSkApplePlatformContext.h +0 -3
- package/apple/RNSkApplePlatformContext.mm +0 -11
- package/cpp/api/JsiSkApi.h +0 -6
- package/cpp/api/JsiSkFont.h +2 -8
- package/cpp/api/JsiSkMatrix.h +4 -2
- package/cpp/api/recorder/Convertor.h +5 -2
- package/cpp/api/recorder/Drawings.h +13 -3
- package/cpp/api/recorder/ImageFilters.h +15 -1
- package/cpp/api/recorder/Paint.h +5 -2
- package/cpp/rnskia/RNSkPlatformContext.h +0 -3
- package/lib/commonjs/renderer/components/Mask.js +3 -9
- package/lib/commonjs/renderer/components/Mask.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.js +7 -2
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -6
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +10 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js +6 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +10 -8
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +15 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/renderer/components/Mask.js +3 -9
- package/lib/module/renderer/components/Mask.js.map +1 -1
- package/lib/module/skia/types/Matrix4.js +7 -2
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -6
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -3
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +10 -0
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +1 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.js +6 -1
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +10 -8
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +15 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +0 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +0 -1
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +0 -1
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -6
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/components/Mask.tsx +10 -3
- package/src/skia/types/Matrix4.ts +6 -2
- package/src/skia/types/Skia.ts +1 -7
- package/src/skia/web/JsiSkia.ts +0 -4
- package/src/sksg/Recorder/DrawingContext.ts +10 -0
- package/src/sksg/Recorder/Player.ts +1 -1
- package/src/sksg/Recorder/Visitor.ts +9 -6
- package/src/sksg/Recorder/commands/Drawing.ts +10 -8
- package/src/sksg/Recorder/commands/ImageFilters.ts +20 -1
- package/src/sksg/Recorder/commands/Shaders.ts +1 -1
- package/cpp/api/JsiSkiaContext.h +0 -94
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["enumKey","fitRects","getRect","processColor","processGradientProps","processTransformProps","rect2rect","NodeType","BlendMode","FilterMode","isCubicSampling","MipmapMode","processUniforms","TileMode","composeDeclarations","CommandType","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","shader","track","makeShaderWithChildren","shaders","splice","push","declareColorShader","color","Shader","MakeColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","rects","width","height","sx","sy","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderCubic","B","C","_sampling$filter","_sampling$mipmap","filter","Linear","mipmap","None","declareBlend","blend","length","composer","MakeBlend","bind","isPushShader","command","type","PushShader","isShader","shaderType","pushShader","ImageShader","ColorShader","Turbulence","FractalNoise","LinearGradient","RadialGradient","SweepGradient","TwoPointConicalGradient","Blend","Error"],"sources":["Shaders.ts"],"sourcesContent":["import {\n enumKey,\n fitRects,\n getRect,\n processColor,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../../../dom/nodes\";\nimport { NodeType } from \"../../../dom/types\";\nimport type {\n BlendProps,\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../../dom/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport {\n BlendMode,\n FilterMode,\n isCubicSampling,\n MipmapMode,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nconst declareShader = (\n ctx: DrawingContext,\n props: ShaderProps,\n children: number\n) => {\n \"worklet\";\n const { source, uniforms, ...transform } = props;\n const m3 = ctx.Skia.Matrix();\n processTransformProps(m3, transform);\n const shader = ctx.track(\n source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n ctx.shaders.splice(0, children),\n m3\n )\n );\n ctx.shaders.push(shader);\n};\n\nconst declareColorShader = (ctx: DrawingContext, props: ColorProps) => {\n \"worklet\";\n const { color } = props;\n const shader = ctx.Skia.Shader.MakeColor(processColor(ctx.Skia, color));\n ctx.shaders.push(shader);\n};\n\nconst declareFractalNoiseShader = (\n ctx: DrawingContext,\n props: FractalNoiseProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTwoPointConicalGradientShader = (\n ctx: DrawingContext,\n props: TwoPointConicalGradientProps\n) => {\n \"worklet\";\n const { startR, endR, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareRadialGradientShader = (\n ctx: DrawingContext,\n props: RadialGradientProps\n) => {\n \"worklet\";\n const { c, r } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareSweepGradientShader = (\n ctx: DrawingContext,\n props: SweepGradientProps\n) => {\n \"worklet\";\n const { c, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n ctx.shaders.push(shader);\n};\n\nconst declareLinearGradientShader = (\n ctx: DrawingContext,\n props: LinearGradientProps\n) => {\n \"worklet\";\n const { start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTurbulenceShader = (\n ctx: DrawingContext,\n props: TurbulenceProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {\n \"worklet\";\n const { fit, image, tx, ty, sampling, ...imageShaderProps } = props;\n if (!image) {\n return;\n }\n\n const rct = getRect(ctx.Skia, imageShaderProps);\n const m3 = ctx.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = ctx.Skia.Matrix();\n lm.concat(m3);\n processTransformProps(lm, imageShaderProps);\n let shader: SkShader;\n if (sampling && isCubicSampling(sampling)) {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling.B,\n sampling.C,\n lm\n )\n );\n } else {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling?.filter ?? FilterMode.Linear,\n sampling?.mipmap ?? MipmapMode.None,\n lm\n )\n );\n }\n ctx.shaders.push(shader);\n};\n\nconst declareBlend = (ctx: DrawingContext, props: BlendProps) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode as BlendProps[\"mode\"])];\n const shaders = ctx.shaders.splice(0, ctx.shaders.length);\n if (shaders.length > 0) {\n const composer = ctx.Skia.Shader.MakeBlend.bind(ctx.Skia.Shader, blend);\n ctx.shaders.push(composeDeclarations(shaders, composer));\n }\n};\n\nexport const isPushShader = (\n command: Command\n): command is Command<CommandType.PushShader> => {\n \"worklet\";\n return command.type === CommandType.PushShader;\n};\n\ntype Props = {\n [NodeType.Shader]: ShaderProps;\n [NodeType.ImageShader]: ImageShaderProps;\n [NodeType.ColorShader]: ColorProps;\n [NodeType.Turbulence]: TurbulenceProps;\n [NodeType.FractalNoise]: FractalNoiseProps;\n [NodeType.LinearGradient]: LinearGradientProps;\n [NodeType.RadialGradient]: RadialGradientProps;\n [NodeType.SweepGradient]: SweepGradientProps;\n [NodeType.TwoPointConicalGradient]: TwoPointConicalGradientProps;\n [NodeType.Blend]: BlendProps;\n};\n\ninterface PushShader<\n T extends keyof Props,\n> extends Command<CommandType.PushShader> {\n shaderType: T;\n props: Props[T];\n children: number;\n}\n\nconst isShader = <T extends keyof Props>(\n command: Command<CommandType.PushShader>,\n type: T\n): command is PushShader<T> => {\n \"worklet\";\n return command.shaderType === type;\n};\n\nexport const pushShader = (\n ctx: DrawingContext,\n command: Command<CommandType.PushShader>\n) => {\n \"worklet\";\n if (isShader(command, NodeType.Shader)) {\n declareShader(ctx, command.props, command.children);\n } else if (isShader(command, NodeType.ImageShader)) {\n declareImageShader(ctx, command.props);\n } else if (isShader(command, NodeType.ColorShader)) {\n declareColorShader(ctx, command.props);\n } else if (isShader(command, NodeType.Turbulence)) {\n declareTurbulenceShader(ctx, command.props);\n } else if (isShader(command, NodeType.FractalNoise)) {\n declareFractalNoiseShader(ctx, command.props);\n } else if (isShader(command, NodeType.LinearGradient)) {\n declareLinearGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.RadialGradient)) {\n declareRadialGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.SweepGradient)) {\n declareSweepGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.TwoPointConicalGradient)) {\n declareTwoPointConicalGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.Blend)) {\n declareBlend(ctx, command.props);\n } else {\n throw new Error(`Unknown shader type: ${command.shaderType}`);\n }\n};\n"],"mappings":"AAAA,SACEA,OAAO,EACPC,QAAQ,EACRC,OAAO,EACPC,YAAY,EACZC,oBAAoB,EACpBC,qBAAqB,EACrBC,SAAS,QACJ,oBAAoB;AAC3B,SAASC,QAAQ,QAAQ,oBAAoB;AAc7C,SACEC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,UAAU,EACVC,eAAe,EACfC,QAAQ,QACH,qBAAqB;AAC5B,SAASC,mBAAmB,QAAQ,aAAa;AAEjD,SAASC,WAAW,QAAQ,SAAS;AAGrC,MAAMC,aAAa,GAAGA,CACpBC,GAAmB,EACnBC,KAAkB,EAClBC,QAAgB,KACb;EACH,SAAS;;EACT,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAE,GAAGC;EAAU,CAAC,GAAGJ,KAAK;EAChD,MAAMK,EAAE,GAAGN,GAAG,CAACO,IAAI,CAACC,MAAM,CA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AACnB,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAC/C,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAAC6G,cAAc,CAAC,EAAE;IACrDrD,2BAA2B,CAAC9C,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAAC8G,cAAc,CAAC,EAAE;IACrD9D,2BAA2B,CAACtC,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAAC+G,aAAa,CAAC,EAAE;IACpD3D,0BAA0B,CAAC1C,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAChD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAACgH,uBAAuB,CAAC,EAAE;IAC9D3E,oCAAoC,CAAC3B,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAC1D,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAACiH,KAAK,CAAC,EAAE;IAC5CrB,YAAY,CAAClF,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIuG,KAAK,CAAC,wBAAwBf,OAAO,CAACI,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["enumKey","fitRects","getRect","processColor","processGradientProps","processTransformProps","rect2rect","NodeType","BlendMode","FilterMode","isCubicSampling","MipmapMode","processUniforms","TileMode","composeDeclarations","CommandType","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","shader","track","makeShaderWithChildren","shaders","splice","push","declareColorShader","color","Shader","MakeColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","rects","width","height","sx","sy","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderCubic","B","C","_sampling$filter","_sampling$mipmap","makeShaderOptions","filter","Linear","mipmap","None","declareBlend","blend","length","composer","MakeBlend","bind","isPushShader","command","type","PushShader","isShader","shaderType","pushShader","ImageShader","ColorShader","Turbulence","FractalNoise","LinearGradient","RadialGradient","SweepGradient","TwoPointConicalGradient","Blend","Error"],"sources":["Shaders.ts"],"sourcesContent":["import {\n enumKey,\n fitRects,\n getRect,\n processColor,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../../../dom/nodes\";\nimport { NodeType } from \"../../../dom/types\";\nimport type {\n BlendProps,\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../../dom/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport {\n BlendMode,\n FilterMode,\n isCubicSampling,\n MipmapMode,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nconst declareShader = (\n ctx: DrawingContext,\n props: ShaderProps,\n children: number\n) => {\n \"worklet\";\n const { source, uniforms, ...transform } = props;\n const m3 = ctx.Skia.Matrix();\n processTransformProps(m3, transform);\n const shader = ctx.track(\n source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n ctx.shaders.splice(0, children),\n m3\n )\n );\n ctx.shaders.push(shader);\n};\n\nconst declareColorShader = (ctx: DrawingContext, props: ColorProps) => {\n \"worklet\";\n const { color } = props;\n const shader = ctx.Skia.Shader.MakeColor(processColor(ctx.Skia, color));\n ctx.shaders.push(shader);\n};\n\nconst declareFractalNoiseShader = (\n ctx: DrawingContext,\n props: FractalNoiseProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTwoPointConicalGradientShader = (\n ctx: DrawingContext,\n props: TwoPointConicalGradientProps\n) => {\n \"worklet\";\n const { startR, endR, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareRadialGradientShader = (\n ctx: DrawingContext,\n props: RadialGradientProps\n) => {\n \"worklet\";\n const { c, r } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareSweepGradientShader = (\n ctx: DrawingContext,\n props: SweepGradientProps\n) => {\n \"worklet\";\n const { c, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n ctx.shaders.push(shader);\n};\n\nconst declareLinearGradientShader = (\n ctx: DrawingContext,\n props: LinearGradientProps\n) => {\n \"worklet\";\n const { start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTurbulenceShader = (\n ctx: DrawingContext,\n props: TurbulenceProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {\n \"worklet\";\n const { fit, image, tx, ty, sampling, ...imageShaderProps } = props;\n if (!image) {\n return;\n }\n\n const rct = getRect(ctx.Skia, imageShaderProps);\n const m3 = ctx.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = ctx.Skia.Matrix();\n lm.concat(m3);\n processTransformProps(lm, imageShaderProps);\n let shader: SkShader;\n if (sampling && isCubicSampling(sampling)) {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling.B,\n sampling.C,\n lm\n )\n );\n } else {\n shader = ctx.track(\n image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling?.filter ?? FilterMode.Linear,\n sampling?.mipmap ?? MipmapMode.None,\n lm\n )\n );\n }\n ctx.shaders.push(shader);\n};\n\nconst declareBlend = (ctx: DrawingContext, props: BlendProps) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode as BlendProps[\"mode\"])];\n const shaders = ctx.shaders.splice(0, ctx.shaders.length);\n if (shaders.length > 0) {\n const composer = ctx.Skia.Shader.MakeBlend.bind(ctx.Skia.Shader, blend);\n ctx.shaders.push(composeDeclarations(shaders, composer));\n }\n};\n\nexport const isPushShader = (\n command: Command\n): command is Command<CommandType.PushShader> => {\n \"worklet\";\n return command.type === CommandType.PushShader;\n};\n\ntype Props = {\n [NodeType.Shader]: ShaderProps;\n [NodeType.ImageShader]: ImageShaderProps;\n [NodeType.ColorShader]: ColorProps;\n [NodeType.Turbulence]: TurbulenceProps;\n [NodeType.FractalNoise]: FractalNoiseProps;\n [NodeType.LinearGradient]: LinearGradientProps;\n [NodeType.RadialGradient]: RadialGradientProps;\n [NodeType.SweepGradient]: SweepGradientProps;\n [NodeType.TwoPointConicalGradient]: TwoPointConicalGradientProps;\n [NodeType.Blend]: BlendProps;\n};\n\ninterface PushShader<\n T extends keyof Props,\n> extends Command<CommandType.PushShader> {\n shaderType: T;\n props: Props[T];\n children: number;\n}\n\nconst isShader = <T extends keyof Props>(\n command: Command<CommandType.PushShader>,\n type: T\n): command is PushShader<T> => {\n \"worklet\";\n return command.shaderType === type;\n};\n\nexport const pushShader = (\n ctx: DrawingContext,\n command: Command<CommandType.PushShader>\n) => {\n \"worklet\";\n if (isShader(command, NodeType.Shader)) {\n declareShader(ctx, command.props, command.children);\n } else if (isShader(command, NodeType.ImageShader)) {\n declareImageShader(ctx, command.props);\n } else if (isShader(command, NodeType.ColorShader)) {\n declareColorShader(ctx, command.props);\n } else if (isShader(command, NodeType.Turbulence)) {\n declareTurbulenceShader(ctx, command.props);\n } else if (isShader(command, NodeType.FractalNoise)) {\n declareFractalNoiseShader(ctx, command.props);\n } else if (isShader(command, NodeType.LinearGradient)) {\n declareLinearGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.RadialGradient)) {\n declareRadialGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.SweepGradient)) {\n declareSweepGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.TwoPointConicalGradient)) {\n declareTwoPointConicalGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.Blend)) {\n declareBlend(ctx, command.props);\n } else {\n throw new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zF,KAAK,CAAC;EAC1D,CAAC,MAAM,IAAI4F,QAAQ,CAACH,OAAO,EAAEpG,QAAQ,CAACkH,KAAK,CAAC,EAAE;IAC5CrB,YAAY,CAACnF,GAAG,EAAE0F,OAAO,CAACzF,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIwG,KAAK,CAAC,wBAAwBf,OAAO,CAACI,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC","ignoreList":[]}
|
|
@@ -35,7 +35,6 @@ export function JsiSkApi(CanvasKit: any): {
|
|
|
35
35
|
NativeBuffer: _JsiSkNativeBufferFactory.JsiSkNativeBufferFactory;
|
|
36
36
|
Skottie: _JsiSkottieFactory.JsiSkottieFactory;
|
|
37
37
|
Video: (url?: any) => Promise<any>;
|
|
38
|
-
Context: (_surface: any, _width: any, _height: any) => jest.Mock<any, any, any>;
|
|
39
38
|
Recorder: () => jest.Mock<any, any, any>;
|
|
40
39
|
getNativeDevice: () => jest.Mock<any, any, any>;
|
|
41
40
|
};
|
|
@@ -12,6 +12,7 @@ export function createDrawingContext(Skia: any, paintPool: any, canvas: any): {
|
|
|
12
12
|
paintDeclarations: any[];
|
|
13
13
|
paintPool: any;
|
|
14
14
|
savePaint: () => void;
|
|
15
|
+
pushPaint: (paint: any) => void;
|
|
15
16
|
saveBackdropFilter: () => void;
|
|
16
17
|
readonly paint: any;
|
|
17
18
|
restorePaint: () => any;
|
|
@@ -34,7 +34,6 @@ export const Skia: {
|
|
|
34
34
|
NativeBuffer: import("./web/JsiSkNativeBufferFactory").JsiSkNativeBufferFactory;
|
|
35
35
|
Skottie: import("./web/JsiSkottieFactory").JsiSkottieFactory;
|
|
36
36
|
Video: (url?: any) => Promise<any>;
|
|
37
|
-
Context: (_surface: any, _width: any, _height: any) => jest.Mock<any, any, any>;
|
|
38
37
|
Recorder: () => jest.Mock<any, any, any>;
|
|
39
38
|
getNativeDevice: () => jest.Mock<any, any, any>;
|
|
40
39
|
};
|
|
@@ -34,7 +34,6 @@ export function JsiSkApi(CanvasKit: any): {
|
|
|
34
34
|
NativeBuffer: JsiSkNativeBufferFactory;
|
|
35
35
|
Skottie: JsiSkottieFactory;
|
|
36
36
|
Video: (url?: any) => Promise<any>;
|
|
37
|
-
Context: (_surface: any, _width: any, _height: any) => jest.Mock<any, any, any>;
|
|
38
37
|
Recorder: () => jest.Mock<any, any, any>;
|
|
39
38
|
getNativeDevice: () => jest.Mock<any, any, any>;
|
|
40
39
|
};
|
|
@@ -11,6 +11,7 @@ export function createDrawingContext(Skia: any, paintPool: any, canvas: any): {
|
|
|
11
11
|
paintDeclarations: any[];
|
|
12
12
|
paintPool: any;
|
|
13
13
|
savePaint: () => void;
|
|
14
|
+
pushPaint: (paint: any) => void;
|
|
14
15
|
saveBackdropFilter: () => void;
|
|
15
16
|
readonly paint: any;
|
|
16
17
|
restorePaint: () => any;
|
|
@@ -17,7 +17,7 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
|
17
17
|
import type { DataFactory } from "./Data";
|
|
18
18
|
import type { SVGFactory } from "./SVG";
|
|
19
19
|
import type { TextBlobFactory } from "./TextBlob";
|
|
20
|
-
import type {
|
|
20
|
+
import type { SurfaceFactory } from "./Surface";
|
|
21
21
|
import type { SkRSXform } from "./RSXform";
|
|
22
22
|
import type { SkPath } from "./Path/Path";
|
|
23
23
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
@@ -30,10 +30,6 @@ import type { Video } from "./Video";
|
|
|
30
30
|
import type { NativeBufferFactory } from "./NativeBuffer";
|
|
31
31
|
import type { JsiRecorder } from "./Recorder";
|
|
32
32
|
import type { SkottieFactory } from "./Skottie";
|
|
33
|
-
export interface SkiaContext {
|
|
34
|
-
getSurface(): SkSurface;
|
|
35
|
-
present(): void;
|
|
36
|
-
}
|
|
37
33
|
/**
|
|
38
34
|
* Declares the interface for the native Skia API
|
|
39
35
|
*/
|
|
@@ -82,7 +78,6 @@ export interface Skia {
|
|
|
82
78
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
83
79
|
Skottie: SkottieFactory;
|
|
84
80
|
Video: (url: string) => Promise<Video> | Video;
|
|
85
|
-
Context(surface: bigint, width: number, height: number): SkiaContext;
|
|
86
81
|
NativeBuffer: NativeBufferFactory;
|
|
87
82
|
Recorder(): JsiRecorder;
|
|
88
83
|
/**
|
|
@@ -12,6 +12,7 @@ export declare const createDrawingContext: (Skia: Skia, paintPool: SkPaint[], ca
|
|
|
12
12
|
paintDeclarations: SkPaint[];
|
|
13
13
|
paintPool: SkPaint[];
|
|
14
14
|
savePaint: () => void;
|
|
15
|
+
pushPaint: (paint: SkPaint) => void;
|
|
15
16
|
saveBackdropFilter: () => void;
|
|
16
17
|
readonly paint: SkPaint;
|
|
17
18
|
restorePaint: () => SkPaint | undefined;
|
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.11.
|
|
11
|
+
"version": "2.11.1",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
|
@@ -20,17 +20,24 @@ export const Mask = ({
|
|
|
20
20
|
}: MaskProps) => {
|
|
21
21
|
return (
|
|
22
22
|
<Group layer>
|
|
23
|
+
{children}
|
|
24
|
+
{/* The children composite against each other in the layer above; the
|
|
25
|
+
mask is then applied once, when its own layer is restored. A blend
|
|
26
|
+
mode attached to a <Group> without a layer would instead be applied
|
|
27
|
+
per draw call, compositing every child after the first against the
|
|
28
|
+
previous child rather than against the mask (issue #3254).
|
|
29
|
+
dstIn keeps the children where the mask is opaque and erases them
|
|
30
|
+
where it is transparent. Without clip, dstATop additionally keeps
|
|
31
|
+
the mask artwork itself wherever the children leave it uncovered. */}
|
|
23
32
|
<Group
|
|
24
33
|
layer={
|
|
25
|
-
<Paint blendMode="
|
|
34
|
+
<Paint blendMode={clip ? "dstIn" : "dstATop"}>
|
|
26
35
|
{mode === "luminance" && <LumaColorFilter />}
|
|
27
36
|
</Paint>
|
|
28
37
|
}
|
|
29
38
|
>
|
|
30
39
|
{mask}
|
|
31
|
-
{clip && <Group layer={<Paint blendMode="dstIn" />}>{children}</Group>}
|
|
32
40
|
</Group>
|
|
33
|
-
<Group blendMode="srcIn">{children}</Group>
|
|
34
41
|
</Group>
|
|
35
42
|
);
|
|
36
43
|
};
|
|
@@ -190,12 +190,16 @@ export const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
|
|
|
190
190
|
return result as unknown as Matrix4;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// These matrices are row-major, so the shear factor of skewX - which offsets x
|
|
194
|
+
// in proportion to y - belongs in row 0, column 1, and skewY's in row 1,
|
|
195
|
+
// column 0. React Native's MatrixMath stores the same transforms column-major,
|
|
196
|
+
// and porting its indices verbatim is what swapped the two axes here.
|
|
197
|
+
const skewX = (angle: number): Matrix4 => {
|
|
194
198
|
"worklet";
|
|
195
199
|
return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
196
200
|
};
|
|
197
201
|
|
|
198
|
-
const
|
|
202
|
+
const skewY = (angle: number): Matrix4 => {
|
|
199
203
|
"worklet";
|
|
200
204
|
return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
201
205
|
};
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
|
21
21
|
import type { DataFactory } from "./Data";
|
|
22
22
|
import type { SVGFactory } from "./SVG";
|
|
23
23
|
import type { TextBlobFactory } from "./TextBlob";
|
|
24
|
-
import type {
|
|
24
|
+
import type { SurfaceFactory } from "./Surface";
|
|
25
25
|
import type { SkRSXform } from "./RSXform";
|
|
26
26
|
import type { SkPath } from "./Path/Path";
|
|
27
27
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
@@ -35,11 +35,6 @@ import type { NativeBufferFactory } from "./NativeBuffer";
|
|
|
35
35
|
import type { JsiRecorder } from "./Recorder";
|
|
36
36
|
import type { SkottieFactory } from "./Skottie";
|
|
37
37
|
|
|
38
|
-
export interface SkiaContext {
|
|
39
|
-
getSurface(): SkSurface;
|
|
40
|
-
present(): void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
/**
|
|
44
39
|
* Declares the interface for the native Skia API
|
|
45
40
|
*/
|
|
@@ -106,7 +101,6 @@ export interface Skia {
|
|
|
106
101
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
107
102
|
Skottie: SkottieFactory;
|
|
108
103
|
Video: (url: string) => Promise<Video> | Video;
|
|
109
|
-
Context(surface: bigint, width: number, height: number): SkiaContext;
|
|
110
104
|
NativeBuffer: NativeBufferFactory;
|
|
111
105
|
Recorder(): JsiRecorder;
|
|
112
106
|
/**
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
JsiRecorder,
|
|
5
5
|
SkContourMeasureIter,
|
|
6
6
|
Skia,
|
|
7
|
-
SkiaContext,
|
|
8
7
|
SkPath,
|
|
9
8
|
SkRect,
|
|
10
9
|
SkRuntimeEffect,
|
|
@@ -137,9 +136,6 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
137
136
|
NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
|
|
138
137
|
Skottie: new JsiSkottieFactory(CanvasKit),
|
|
139
138
|
Video: createVideo.bind(null, CanvasKit),
|
|
140
|
-
Context: (_surface: bigint, _width: number, _height: number) => {
|
|
141
|
-
return throwNotImplementedOnRNWeb<SkiaContext>();
|
|
142
|
-
},
|
|
143
139
|
Recorder: () => {
|
|
144
140
|
return throwNotImplementedOnRNWeb<JsiRecorder>();
|
|
145
141
|
},
|
|
@@ -56,6 +56,15 @@ export const createDrawingContext = (
|
|
|
56
56
|
nextPaintIndex++;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
// Pushes an externally owned paint (the `paint` prop) onto the stack. It must
|
|
60
|
+
// push an opacity alongside it: restorePaint() pops both, so pushing only the
|
|
61
|
+
// paint would underflow the opacity stack and leak the enclosing group's
|
|
62
|
+
// opacity onto everything drawn afterwards.
|
|
63
|
+
const pushPaint = (paint: SkPaint) => {
|
|
64
|
+
paints.push(paint);
|
|
65
|
+
opacities.push(opacities[opacities.length - 1]);
|
|
66
|
+
};
|
|
67
|
+
|
|
59
68
|
const getOpacity = () => {
|
|
60
69
|
return opacities[opacities.length - 1];
|
|
61
70
|
};
|
|
@@ -144,6 +153,7 @@ export const createDrawingContext = (
|
|
|
144
153
|
|
|
145
154
|
// Public methods
|
|
146
155
|
savePaint,
|
|
156
|
+
pushPaint,
|
|
147
157
|
saveBackdropFilter,
|
|
148
158
|
get paint() {
|
|
149
159
|
return paints[paints.length - 1];
|
|
@@ -123,7 +123,7 @@ const play = (ctx: DrawingContext, _command: Command) => {
|
|
|
123
123
|
ctx.canvas.saveLayer(paint);
|
|
124
124
|
} else if (isDrawCommand(command, CommandType.SavePaint)) {
|
|
125
125
|
if (command.props.paint) {
|
|
126
|
-
ctx.
|
|
126
|
+
ctx.pushPaint(command.props.paint);
|
|
127
127
|
} else {
|
|
128
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
129
|
const { standalone } = command as any;
|
|
@@ -104,13 +104,16 @@ const processCTM = ({
|
|
|
104
104
|
if (layer) {
|
|
105
105
|
ctm.layer = layer;
|
|
106
106
|
}
|
|
107
|
+
// Only record a CTM command when saveCTM() will actually save the canvas.
|
|
108
|
+
// saveCTM() saves on transform/matrix, clip or layer; restoreCTM() always
|
|
109
|
+
// restores, so recording a CTM that saves nothing - `origin` with no
|
|
110
|
+
// transform, `clip={false}` from a conditional, a bare `invertClip` - pops
|
|
111
|
+
// an enclosing save that belongs to an ancestor.
|
|
107
112
|
if (
|
|
108
|
-
clip !== undefined ||
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
matrix !== undefined ||
|
|
113
|
-
layer !== undefined
|
|
113
|
+
ctm.clip !== undefined ||
|
|
114
|
+
ctm.transform !== undefined ||
|
|
115
|
+
ctm.matrix !== undefined ||
|
|
116
|
+
ctm.layer !== undefined
|
|
114
117
|
) {
|
|
115
118
|
return ctm;
|
|
116
119
|
}
|
|
@@ -217,6 +217,16 @@ export const drawPath = (ctx: DrawingContext, props: PathProps) => {
|
|
|
217
217
|
|
|
218
218
|
let path = processPath(ctx.Skia, pathProps.path);
|
|
219
219
|
|
|
220
|
+
// Trim runs first, so start/end address the path the caller drew. Stroking
|
|
221
|
+
// first would replace it with its outline and leave the offsets walking that
|
|
222
|
+
// outline's perimeter instead. The native recorder orders these the same way.
|
|
223
|
+
if (hasStartOffset || hasEndOffset) {
|
|
224
|
+
const trimmed = ctx.Skia.Path.Trim(path, start, end, false);
|
|
225
|
+
if (trimmed) {
|
|
226
|
+
path = trimmed;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
220
230
|
// Apply fill type using PathBuilder
|
|
221
231
|
if (hasFillType) {
|
|
222
232
|
const builder = ctx.Skia.PathBuilder.MakeFromPath(path);
|
|
@@ -232,14 +242,6 @@ export const drawPath = (ctx: DrawingContext, props: PathProps) => {
|
|
|
232
242
|
}
|
|
233
243
|
}
|
|
234
244
|
|
|
235
|
-
// Apply trim using static Path.Trim
|
|
236
|
-
if (hasStartOffset || hasEndOffset) {
|
|
237
|
-
const trimmed = ctx.Skia.Path.Trim(path, start, end, false);
|
|
238
|
-
if (trimmed) {
|
|
239
|
-
path = trimmed;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
245
|
ctx.canvas.drawPath(path, ctx.paint);
|
|
244
246
|
};
|
|
245
247
|
|
|
@@ -31,6 +31,14 @@ export enum MorphologyOperator {
|
|
|
31
31
|
|
|
32
32
|
const Black = Float32Array.of(0, 0, 0, 1);
|
|
33
33
|
|
|
34
|
+
// Turns the source graphic into a hard silhouette: alpha is multiplied by 255
|
|
35
|
+
// and clamped, so any pixel the shape covers at all becomes fully opaque, and
|
|
36
|
+
// the colour channels are dropped. 255 is the saturation point of an 8-bit
|
|
37
|
+
// alpha channel, so one unit of coverage is enough to reach 1.
|
|
38
|
+
const AlphaSaturate = [
|
|
39
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0,
|
|
40
|
+
];
|
|
41
|
+
|
|
34
42
|
const MakeInnerShadow = (
|
|
35
43
|
Skia: Skia,
|
|
36
44
|
shadowOnly: boolean | undefined,
|
|
@@ -50,9 +58,20 @@ const MakeInnerShadow = (
|
|
|
50
58
|
Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),
|
|
51
59
|
null
|
|
52
60
|
);
|
|
61
|
+
// The shadow is generated outside the shape and then clipped back into it, so
|
|
62
|
+
// "outside" has to be the complement of the shape's silhouette. Taking SrcOut
|
|
63
|
+
// against the source graphic itself makes it the complement of the source's
|
|
64
|
+
// *alpha*: inside a translucent shape 1 - alpha is non-zero, so the shadow is
|
|
65
|
+
// generated across the whole interior and tints it, no matter how small the
|
|
66
|
+
// blur and the offset are (issue #2990). Saturating alpha first keeps the
|
|
67
|
+
// shadow tied to the shape's outline instead of to its opacity.
|
|
68
|
+
const coverage = Skia.ImageFilter.MakeColorFilter(
|
|
69
|
+
Skia.ColorFilter.MakeMatrix(AlphaSaturate),
|
|
70
|
+
null
|
|
71
|
+
);
|
|
53
72
|
const f1 = Skia.ImageFilter.MakeColorFilter(
|
|
54
73
|
Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),
|
|
55
|
-
|
|
74
|
+
coverage
|
|
56
75
|
);
|
|
57
76
|
const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);
|
|
58
77
|
const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);
|
|
@@ -221,7 +221,7 @@ const declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {
|
|
|
221
221
|
);
|
|
222
222
|
} else {
|
|
223
223
|
shader = ctx.track(
|
|
224
|
-
image.
|
|
224
|
+
image.makeShaderOptions(
|
|
225
225
|
TileMode[enumKey(tx)],
|
|
226
226
|
TileMode[enumKey(ty)],
|
|
227
227
|
sampling?.filter ?? FilterMode.Linear,
|
package/cpp/api/JsiSkiaContext.h
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <numeric>
|
|
5
|
-
#include <utility>
|
|
6
|
-
#include <variant>
|
|
7
|
-
#include <vector>
|
|
8
|
-
|
|
9
|
-
#include "JsiSkConverters.h"
|
|
10
|
-
#include "JsiSkNativeObjects.h"
|
|
11
|
-
#include "utils/RNSkLog.h"
|
|
12
|
-
#include <jsi/jsi.h>
|
|
13
|
-
|
|
14
|
-
#include "JsiSkPaint.h"
|
|
15
|
-
#include "JsiSkPoint.h"
|
|
16
|
-
#include "JsiSkRect.h"
|
|
17
|
-
#include "JsiSkSurface.h"
|
|
18
|
-
#include "JsiSkTypeface.h"
|
|
19
|
-
|
|
20
|
-
#include "rnskia/RNWindowContext.h"
|
|
21
|
-
|
|
22
|
-
#pragma clang diagnostic push
|
|
23
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
24
|
-
|
|
25
|
-
#include "include/core/SkFont.h"
|
|
26
|
-
#include "include/core/SkFontMetrics.h"
|
|
27
|
-
|
|
28
|
-
#pragma clang diagnostic pop
|
|
29
|
-
|
|
30
|
-
namespace RNSkia {
|
|
31
|
-
|
|
32
|
-
namespace jsi = facebook::jsi;
|
|
33
|
-
|
|
34
|
-
class JsiSkiaContext
|
|
35
|
-
: public JsiSkWrappingSharedPtrNativeObject<JsiSkiaContext, WindowContext> {
|
|
36
|
-
public:
|
|
37
|
-
static constexpr const char *CLASS_NAME = "SkiaContext";
|
|
38
|
-
|
|
39
|
-
std::variant<std::nullptr_t, std::shared_ptr<JsiSkSurface>> getSurface() {
|
|
40
|
-
auto surface = getObject()->getSurface();
|
|
41
|
-
if (surface == nullptr) {
|
|
42
|
-
return nullptr;
|
|
43
|
-
}
|
|
44
|
-
return std::make_shared<JsiSkSurface>(getContext(), std::move(surface));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void present() { getObject()->present(); }
|
|
48
|
-
|
|
49
|
-
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
50
|
-
installCommon(runtime, prototype);
|
|
51
|
-
installMethod(runtime, prototype, "getSurface",
|
|
52
|
-
&JsiSkiaContext::getSurface);
|
|
53
|
-
installMethod(runtime, prototype, "present", &JsiSkiaContext::present);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
JsiSkiaContext(std::shared_ptr<RNSkPlatformContext> context,
|
|
57
|
-
std::shared_ptr<WindowContext> ctx)
|
|
58
|
-
: JsiSkWrappingSharedPtrNativeObject<JsiSkiaContext, WindowContext>(
|
|
59
|
-
std::move(context), std::move(ctx)) {}
|
|
60
|
-
|
|
61
|
-
size_t getMemoryPressure() override { return 10 * 1024 * 1024; }
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates the function for construction a new instance of the SkFont
|
|
65
|
-
* wrapper
|
|
66
|
-
* @param context Platform context
|
|
67
|
-
* @return A function for creating a new host object wrapper for the SkFont
|
|
68
|
-
* class
|
|
69
|
-
*/
|
|
70
|
-
static const jsi::HostFunctionType
|
|
71
|
-
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
|
72
|
-
return JSI_HOST_FUNCTION_LAMBDA {
|
|
73
|
-
jsi::BigInt pointer = arguments[0].asBigInt(runtime);
|
|
74
|
-
const uintptr_t nativeBufferPointer = pointer.asUint64(runtime);
|
|
75
|
-
void *surface = reinterpret_cast<void *>(nativeBufferPointer);
|
|
76
|
-
auto width = static_cast<int>(arguments[1].asNumber());
|
|
77
|
-
auto height = static_cast<int>(arguments[2].asNumber());
|
|
78
|
-
if (surface == nullptr) {
|
|
79
|
-
throw std::runtime_error("Surface is null");
|
|
80
|
-
}
|
|
81
|
-
auto result =
|
|
82
|
-
context->makeContextFromNativeSurface(surface, width, height);
|
|
83
|
-
if (result == nullptr) {
|
|
84
|
-
throw std::runtime_error(
|
|
85
|
-
"Couldn't create a Skia context from the native surface");
|
|
86
|
-
}
|
|
87
|
-
// Return the newly constructed object
|
|
88
|
-
return makeJsiObject(runtime, std::make_shared<JsiSkiaContext>(
|
|
89
|
-
context, std::move(result)));
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
} // namespace RNSkia
|