@shopify/react-native-skia 1.8.2 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. package/android/cpp/rnskia-android/MainThreadDispatcher.h +1 -1
  2. package/android/cpp/rnskia-android/OpenGLContext.h +4 -4
  3. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +3 -3
  4. package/cpp/api/JsiSkCanvas.h +27 -25
  5. package/cpp/api/JsiSkImage.h +24 -0
  6. package/cpp/api/JsiSkPaint.h +1 -1
  7. package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +5 -1
  8. package/cpp/rnskia/dom/nodes/JsiImageNode.h +8 -4
  9. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +9 -38
  10. package/cpp/rnskia/dom/props/SamplingProp.h +54 -0
  11. package/ios/RNSkia-iOS/SkiaManager.mm +2 -4
  12. package/lib/commonjs/dom/types/Drawings.d.ts +3 -1
  13. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  14. package/lib/commonjs/dom/types/Shaders.d.ts +2 -3
  15. package/lib/commonjs/dom/types/Shaders.js.map +1 -1
  16. package/lib/commonjs/renderer/components/image/ImageShader.d.ts +1 -1
  17. package/lib/commonjs/renderer/components/image/ImageShader.js +0 -4
  18. package/lib/commonjs/renderer/components/image/ImageShader.js.map +1 -1
  19. package/lib/commonjs/skia/types/Canvas.d.ts +2 -2
  20. package/lib/commonjs/skia/types/Canvas.js.map +1 -1
  21. package/lib/commonjs/skia/types/Image/Image.d.ts +18 -0
  22. package/lib/commonjs/skia/types/Image/Image.js +24 -1
  23. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  24. package/lib/commonjs/skia/types/Picture/PictureRecorder.d.ts +2 -1
  25. package/lib/commonjs/skia/types/Picture/PictureRecorder.js.map +1 -1
  26. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +2 -2
  27. package/lib/commonjs/skia/web/JsiSkCanvas.js +15 -2
  28. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  29. package/lib/commonjs/sksg/Container.d.ts +17 -14
  30. package/lib/commonjs/sksg/Container.js +59 -62
  31. package/lib/commonjs/sksg/Container.js.map +1 -1
  32. package/lib/commonjs/sksg/HostConfig.js +4 -9
  33. package/lib/commonjs/sksg/HostConfig.js.map +1 -1
  34. package/lib/commonjs/sksg/Reconciler.js +1 -2
  35. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  36. package/lib/commonjs/sksg/Recorder/Core.d.ts +42 -37
  37. package/lib/commonjs/sksg/Recorder/Core.js +45 -38
  38. package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
  39. package/lib/commonjs/sksg/Recorder/Player.js +4 -0
  40. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  41. package/lib/commonjs/sksg/Recorder/Recorder.d.ts +15 -0
  42. package/lib/commonjs/sksg/Recorder/Recorder.js +23 -1
  43. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  44. package/lib/commonjs/sksg/Recorder/Visitor.js +6 -0
  45. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  46. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +11 -4
  47. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  48. package/lib/commonjs/sksg/Recorder/commands/Shaders.js +8 -3
  49. package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
  50. package/lib/module/dom/types/Drawings.d.ts +3 -1
  51. package/lib/module/dom/types/Drawings.js.map +1 -1
  52. package/lib/module/dom/types/Shaders.d.ts +2 -3
  53. package/lib/module/dom/types/Shaders.js.map +1 -1
  54. package/lib/module/renderer/components/image/ImageShader.d.ts +1 -1
  55. package/lib/module/renderer/components/image/ImageShader.js +0 -4
  56. package/lib/module/renderer/components/image/ImageShader.js.map +1 -1
  57. package/lib/module/skia/types/Canvas.d.ts +2 -2
  58. package/lib/module/skia/types/Canvas.js.map +1 -1
  59. package/lib/module/skia/types/Image/Image.d.ts +18 -0
  60. package/lib/module/skia/types/Image/Image.js +21 -0
  61. package/lib/module/skia/types/Image/Image.js.map +1 -1
  62. package/lib/module/skia/types/Picture/PictureRecorder.d.ts +2 -1
  63. package/lib/module/skia/types/Picture/PictureRecorder.js.map +1 -1
  64. package/lib/module/skia/web/JsiSkCanvas.d.ts +2 -2
  65. package/lib/module/skia/web/JsiSkCanvas.js +15 -2
  66. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  67. package/lib/module/sksg/Container.d.ts +17 -14
  68. package/lib/module/sksg/Container.js +56 -60
  69. package/lib/module/sksg/Container.js.map +1 -1
  70. package/lib/module/sksg/HostConfig.js +4 -9
  71. package/lib/module/sksg/HostConfig.js.map +1 -1
  72. package/lib/module/sksg/Reconciler.js +2 -3
  73. package/lib/module/sksg/Reconciler.js.map +1 -1
  74. package/lib/module/sksg/Recorder/Core.d.ts +42 -37
  75. package/lib/module/sksg/Recorder/Core.js +43 -37
  76. package/lib/module/sksg/Recorder/Core.js.map +1 -1
  77. package/lib/module/sksg/Recorder/Player.js +5 -1
  78. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  79. package/lib/module/sksg/Recorder/Recorder.d.ts +15 -0
  80. package/lib/module/sksg/Recorder/Recorder.js +23 -1
  81. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  82. package/lib/module/sksg/Recorder/Visitor.js +6 -0
  83. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  84. package/lib/module/sksg/Recorder/commands/Drawing.js +12 -5
  85. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  86. package/lib/module/sksg/Recorder/commands/Shaders.js +9 -4
  87. package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
  88. package/lib/typescript/lib/commonjs/renderer/components/image/ImageShader.d.ts +1 -3
  89. package/lib/typescript/lib/commonjs/skia/types/Image/Image.d.ts +21 -0
  90. package/lib/typescript/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  91. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +15 -10
  92. package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +4 -4
  93. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +21 -2
  94. package/lib/typescript/lib/commonjs/sksg/Recorder/Core.d.ts +1 -0
  95. package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +7 -0
  96. package/lib/typescript/lib/module/mock/index.d.ts +18 -3
  97. package/lib/typescript/lib/module/renderer/components/image/ImageShader.d.ts +1 -3
  98. package/lib/typescript/lib/module/skia/types/Image/Image.d.ts +21 -0
  99. package/lib/typescript/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  100. package/lib/typescript/lib/module/sksg/Container.d.ts +15 -10
  101. package/lib/typescript/lib/module/sksg/HostConfig.d.ts +4 -4
  102. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +21 -2
  103. package/lib/typescript/lib/module/sksg/Recorder/Core.d.ts +1 -0
  104. package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +7 -0
  105. package/lib/typescript/src/dom/types/Drawings.d.ts +3 -1
  106. package/lib/typescript/src/dom/types/Shaders.d.ts +2 -3
  107. package/lib/typescript/src/renderer/components/image/ImageShader.d.ts +1 -1
  108. package/lib/typescript/src/skia/types/Canvas.d.ts +2 -2
  109. package/lib/typescript/src/skia/types/Image/Image.d.ts +18 -0
  110. package/lib/typescript/src/skia/types/Picture/PictureRecorder.d.ts +2 -1
  111. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +2 -2
  112. package/lib/typescript/src/sksg/Container.d.ts +17 -14
  113. package/lib/typescript/src/sksg/Recorder/Core.d.ts +42 -37
  114. package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +15 -0
  115. package/libs/apple/libskia.xcframework/Info.plist +35 -2
  116. package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  117. package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  118. package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
  119. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
  120. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  121. package/libs/apple/libskottie.xcframework/Info.plist +36 -3
  122. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  123. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  124. package/libs/apple/libskottie.xcframework/macos-arm64_x86_64/libskottie.a +0 -0
  125. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e/libskottie.a +0 -0
  126. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  127. package/libs/apple/libskparagraph.xcframework/Info.plist +40 -7
  128. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  129. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  130. package/libs/apple/libskparagraph.xcframework/macos-arm64_x86_64/libskparagraph.a +0 -0
  131. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e/libskparagraph.a +0 -0
  132. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  133. package/libs/apple/libsksg.xcframework/Info.plist +35 -2
  134. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  135. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  136. package/libs/apple/libsksg.xcframework/macos-arm64_x86_64/libsksg.a +0 -0
  137. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e/libsksg.a +0 -0
  138. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  139. package/libs/apple/libskshaper.xcframework/Info.plist +33 -0
  140. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  141. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  142. package/libs/apple/libskshaper.xcframework/macos-arm64_x86_64/libskshaper.a +0 -0
  143. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e/libskshaper.a +0 -0
  144. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  145. package/libs/apple/libskunicode_core.xcframework/Info.plist +36 -3
  146. package/libs/apple/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
  147. package/libs/apple/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  148. package/libs/apple/libskunicode_core.xcframework/macos-arm64_x86_64/libskunicode_core.a +0 -0
  149. package/libs/apple/libskunicode_core.xcframework/tvos-arm64_arm64e/libskunicode_core.a +0 -0
  150. package/libs/apple/libskunicode_core.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  151. package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +35 -2
  152. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  153. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  154. package/libs/apple/libskunicode_libgrapheme.xcframework/macos-arm64_x86_64/libskunicode_libgrapheme.a +0 -0
  155. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  156. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  157. package/libs/apple/libsvg.xcframework/Info.plist +36 -3
  158. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  159. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  160. package/libs/apple/libsvg.xcframework/macos-arm64_x86_64/libsvg.a +0 -0
  161. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e/libsvg.a +0 -0
  162. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  163. package/package.json +3 -2
  164. package/react-native-skia.podspec +2 -2
  165. package/src/__tests__/snapshots/animated-images/bird.png +0 -0
  166. package/src/__tests__/snapshots/demos/product.png +0 -0
  167. package/src/__tests__/snapshots/demos/product2.png +0 -0
  168. package/src/__tests__/snapshots/images/bundle-android.png +0 -0
  169. package/src/__tests__/snapshots/images/bundle-ios.png +0 -0
  170. package/src/__tests__/snapshots/images/bundle-node.png +0 -0
  171. package/src/__tests__/snapshots/images/filter.png +0 -0
  172. package/src/dom/types/Drawings.ts +3 -0
  173. package/src/dom/types/Shaders.ts +2 -4
  174. package/src/renderer/__tests__/e2e/Text.spec.tsx +1 -1
  175. package/src/renderer/components/image/ImageShader.tsx +2 -15
  176. package/src/skia/types/Canvas.ts +2 -3
  177. package/src/skia/types/Image/Image.ts +14 -0
  178. package/src/skia/types/Picture/PictureRecorder.ts +2 -1
  179. package/src/skia/web/JsiSkCanvas.ts +50 -29
  180. package/src/sksg/Container.ts +64 -68
  181. package/src/sksg/HostConfig.ts +4 -9
  182. package/src/sksg/Reconciler.ts +3 -3
  183. package/src/sksg/Recorder/Core.ts +10 -0
  184. package/src/sksg/Recorder/Player.ts +5 -1
  185. package/src/sksg/Recorder/Recorder.ts +36 -1
  186. package/src/sksg/Recorder/Visitor.ts +6 -0
  187. package/src/sksg/Recorder/commands/Drawing.ts +33 -4
  188. package/src/sksg/Recorder/commands/Shaders.ts +21 -8
  189. package/lib/commonjs/sksg/Recorder/Recording.d.ts +0 -7
  190. package/lib/commonjs/sksg/Recorder/Recording.js +0 -12
  191. package/lib/commonjs/sksg/Recorder/Recording.js.map +0 -1
  192. package/lib/module/sksg/Recorder/Recording.d.ts +0 -7
  193. package/lib/module/sksg/Recorder/Recording.js +0 -5
  194. package/lib/module/sksg/Recorder/Recording.js.map +0 -1
  195. package/lib/typescript/lib/commonjs/sksg/Recorder/Recording.d.ts +0 -5
  196. package/lib/typescript/lib/module/sksg/Recorder/Recording.d.ts +0 -4
  197. package/lib/typescript/src/sksg/Recorder/Recording.d.ts +0 -7
  198. package/src/sksg/Recorder/Recording.ts +0 -13
@@ -7,7 +7,7 @@
7
7
  class MainThreadDispatcher {
8
8
  private:
9
9
  ALooper *mainLooper = nullptr;
10
- int messagePipe[2] = { -1, -1 };
10
+ int messagePipe[2] = {-1, -1};
11
11
  std::queue<std::function<void()>> taskQueue;
12
12
  std::mutex queueMutex;
13
13
 
@@ -122,8 +122,8 @@ public:
122
122
  format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
123
123
  break;
124
124
  case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
125
- GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
126
- break;
125
+ GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
126
+ break;
127
127
  case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
128
128
  format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
129
129
  break;
@@ -146,8 +146,8 @@ public:
146
146
  auto height = static_cast<int>(description.height);
147
147
  auto backendTex = MakeGLBackendTexture(
148
148
  _directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
149
- width, height, &deleteImageProc,
150
- &updateImageProc, &deleteImageCtx, false, format, false);
149
+ width, height, &deleteImageProc, &updateImageProc, &deleteImageCtx,
150
+ false, format, false);
151
151
  if (!backendTex.isValid()) {
152
152
  RNSkLogger::logToConsole(
153
153
  "Failed to convert HardwareBuffer to OpenGL Texture!");
@@ -26,7 +26,8 @@ namespace RNSkia {
26
26
  RNSkOpenGLCanvasProvider::RNSkOpenGLCanvasProvider(
27
27
  std::function<void()> requestRedraw,
28
28
  std::shared_ptr<RNSkia::RNSkPlatformContext> platformContext)
29
- : RNSkCanvasProvider(std::move(requestRedraw)), _platformContext(std::move(platformContext)) {}
29
+ : RNSkCanvasProvider(std::move(requestRedraw)),
30
+ _platformContext(std::move(platformContext)) {}
30
31
 
31
32
  RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider() = default;
32
33
 
@@ -109,8 +110,7 @@ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject jSurfaceTexture,
109
110
  #if defined(SK_GRAPHITE)
110
111
  _surfaceHolder = DawnContext::getInstance().MakeWindow(window, width, height);
111
112
  #else
112
- _surfaceHolder =
113
- OpenGLContext::getInstance().MakeWindow(window);
113
+ _surfaceHolder = OpenGLContext::getInstance().MakeWindow(window);
114
114
  #endif
115
115
 
116
116
  // Post redraw request to ensure we paint in the next draw cycle.
@@ -525,32 +525,34 @@ public:
525
525
 
526
526
  std::vector<SkColor> colors;
527
527
  if (count > 5 && !arguments[5].isUndefined()) {
528
- auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
529
- int colorsSize = static_cast<int>(colorsArray.size(runtime));
530
- colors.reserve(colorsSize);
531
- for (int i = 0; i < colorsSize; i++) {
532
- // Convert from [r,g,b,a] in [0,1] to SkColor
533
- auto val = colorsArray.getValueAtIndex(runtime, i).asObject(runtime);
534
- float r = val.getProperty(runtime, "0").asNumber();
535
- float g = val.getProperty(runtime, "1").asNumber();
536
- float b = val.getProperty(runtime, "2").asNumber();
537
- float a = val.getProperty(runtime, "3").asNumber();
538
-
539
- // Convert to 8-bit color channels and pack into SkColor
540
- uint8_t r8 = static_cast<uint8_t>(r * 255);
541
- uint8_t g8 = static_cast<uint8_t>(g * 255);
542
- uint8_t b8 = static_cast<uint8_t>(b * 255);
543
- uint8_t a8 = static_cast<uint8_t>(a * 255);
544
-
545
- SkColor color = SkColorSetARGB(a8, r8, g8, b8);
546
- colors.push_back(color);
547
- }
528
+ auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
529
+ int colorsSize = static_cast<int>(colorsArray.size(runtime));
530
+ colors.reserve(colorsSize);
531
+ for (int i = 0; i < colorsSize; i++) {
532
+ // Convert from [r,g,b,a] in [0,1] to SkColor
533
+ auto val = colorsArray.getValueAtIndex(runtime, i).asObject(runtime);
534
+ float r = val.getProperty(runtime, "0").asNumber();
535
+ float g = val.getProperty(runtime, "1").asNumber();
536
+ float b = val.getProperty(runtime, "2").asNumber();
537
+ float a = val.getProperty(runtime, "3").asNumber();
538
+
539
+ // Convert to 8-bit color channels and pack into SkColor
540
+ uint8_t r8 = static_cast<uint8_t>(r * 255);
541
+ uint8_t g8 = static_cast<uint8_t>(g * 255);
542
+ uint8_t b8 = static_cast<uint8_t>(b * 255);
543
+ uint8_t a8 = static_cast<uint8_t>(a * 255);
544
+
545
+ SkColor color = SkColorSetARGB(a8, r8, g8, b8);
546
+ colors.push_back(color);
547
+ }
548
548
  }
549
-
550
- SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
551
- _canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(), colors.data(),
552
- skRects.size(), blendMode, sampling, nullptr,
553
- paint.get());
549
+ SkSamplingOptions sampling(SkFilterMode::kLinear);
550
+ if (count > 6) {
551
+ sampling = SamplingOptionsFromValue(runtime, arguments[6]);
552
+ }
553
+ _canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(),
554
+ colors.data(), skRects.size(), blendMode, sampling,
555
+ nullptr, paint.get());
554
556
 
555
557
  return jsi::Value::undefined();
556
558
  }
@@ -36,6 +36,30 @@ namespace RNSkia {
36
36
 
37
37
  namespace jsi = facebook::jsi;
38
38
 
39
+ inline SkSamplingOptions SamplingOptionsFromValue(jsi::Runtime &runtime,
40
+ const jsi::Value &val) {
41
+ SkSamplingOptions samplingOptions(SkFilterMode::kLinear);
42
+ if (val.isObject()) {
43
+ auto object = val.asObject(runtime);
44
+ if (object.hasProperty(runtime, "B") && object.hasProperty(runtime, "C")) {
45
+ auto B = static_cast<float>(object.getProperty(runtime, "B").asNumber());
46
+ auto C = static_cast<float>(object.getProperty(runtime, "C").asNumber());
47
+ samplingOptions = SkSamplingOptions({B, C});
48
+ } else if (object.hasProperty(runtime, "filter")) {
49
+ auto filter = static_cast<SkFilterMode>(
50
+ object.getProperty(runtime, "filter").asNumber());
51
+ if (object.hasProperty(runtime, "mipmap")) {
52
+ auto mipmap = static_cast<SkMipmapMode>(
53
+ object.getProperty(runtime, "mipmap").asNumber());
54
+ samplingOptions = SkSamplingOptions(filter, mipmap);
55
+ } else {
56
+ samplingOptions = SkSamplingOptions(filter);
57
+ }
58
+ }
59
+ }
60
+ return samplingOptions;
61
+ }
62
+
39
63
  class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
40
64
  public:
41
65
  // TODO-API: Properties?
@@ -28,7 +28,7 @@ public:
28
28
  EXPORT_JSI_API_TYPENAME(JsiSkPaint, Paint)
29
29
 
30
30
  JSI_HOST_FUNCTION(assign) {
31
- SkPaint* paint = JsiSkPaint::fromValue(runtime, arguments[0]).get();
31
+ SkPaint *paint = JsiSkPaint::fromValue(runtime, arguments[0]).get();
32
32
  *getObject() = *paint;
33
33
  return jsi::Value::undefined();
34
34
  }
@@ -3,6 +3,7 @@
3
3
  #include "JsiDomDrawingNode.h"
4
4
  #include "RSXformProp.h"
5
5
  #include "RectProp.h"
6
+ #include "SamplingProp.h"
6
7
  #include "SkImageProps.h"
7
8
 
8
9
  #include <memory>
@@ -28,7 +29,8 @@ protected:
28
29
  ? *_blendModeProp->getDerivedValue()
29
30
  : SkBlendMode::kDstOver;
30
31
  auto paint = *context->getPaint();
31
- SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
32
+ auto sampling = _samplingProp->isSet() ? *_samplingProp->getDerivedValue()
33
+ : SkSamplingOptions(SkFilterMode::kLinear);
32
34
  context->getCanvas()->drawAtlas(
33
35
  image.get(), transforms->data(), sprites->data(),
34
36
  colors == nullptr ? nullptr : colors->data(), sprites->size(),
@@ -43,6 +45,7 @@ protected:
43
45
  _imageProp = container->defineProperty<ImageProp>("image");
44
46
  _colorsProp = container->defineProperty<ColorsProp>("colors");
45
47
  _blendModeProp = container->defineProperty<BlendModeProp>("blendMode");
48
+ _samplingProp = container->defineProperty<SamplingProp>("sampling");
46
49
 
47
50
  _rectsProp->require();
48
51
  _rsxFormsProp->require();
@@ -54,6 +57,7 @@ private:
54
57
  RSXFormsProp *_rsxFormsProp;
55
58
  ColorsProp *_colorsProp;
56
59
  BlendModeProp *_blendModeProp;
60
+ SamplingProp *_samplingProp;
57
61
  };
58
62
 
59
63
  } // namespace RNSkia
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include "JsiDomDrawingNode.h"
4
+ #include "SamplingProp.h"
4
5
  #include "SkImageProps.h"
5
6
 
6
7
  #include <memory>
@@ -20,19 +21,22 @@ protected:
20
21
  if (image == nullptr) {
21
22
  return;
22
23
  }
23
-
24
- context->getCanvas()->drawImageRect(
25
- image, rects->src, rects->dst, SkSamplingOptions(),
26
- context->getPaint().get(), SkCanvas::kStrict_SrcRectConstraint);
24
+ auto sampling = _samplingProp->isSet() ? *_samplingProp->getDerivedValue()
25
+ : SkSamplingOptions(SkFilterMode::kLinear);
26
+ context->getCanvas()->drawImageRect(image, rects->src, rects->dst, sampling,
27
+ context->getPaint().get(),
28
+ SkCanvas::kStrict_SrcRectConstraint);
27
29
  }
28
30
 
29
31
  void defineProperties(NodePropsContainer *container) override {
30
32
  JsiDomDrawingNode::defineProperties(container);
31
33
  _imageProps = container->defineProperty<ImageProps>();
34
+ _samplingProp = container->defineProperty<SamplingProp>("sampling");
32
35
  }
33
36
 
34
37
  private:
35
38
  ImageProps *_imageProps;
39
+ SamplingProp *_samplingProp;
36
40
  };
37
41
 
38
42
  } // namespace RNSkia
@@ -6,6 +6,7 @@
6
6
  #include "ColorProp.h"
7
7
  #include "NodeProp.h"
8
8
  #include "NumbersProp.h"
9
+ #include "SamplingProp.h"
9
10
  #include "TileModeProp.h"
10
11
  #include "TransformsProps.h"
11
12
  #include "UniformsProp.h"
@@ -120,12 +121,12 @@ public:
120
121
  }
121
122
  }
122
123
 
123
- context->getShaders()->push(image->makeShader(
124
- *_txProp->getDerivedValue(), *_tyProp->getDerivedValue(),
125
- SkSamplingOptions(
126
- getFilterModeFromString(_filterModeProp->value().getAsString()),
127
- getMipmapModeFromString(_mipmapModeProp->value().getAsString())),
128
- &_matrix));
124
+ auto samplingOptions = _samplingProp->isSet()
125
+ ? *_samplingProp->getDerivedValue()
126
+ : SkSamplingOptions(SkFilterMode::kLinear);
127
+ context->getShaders()->push(image->makeShader(*_txProp->getDerivedValue(),
128
+ *_tyProp->getDerivedValue(),
129
+ samplingOptions, &_matrix));
129
130
  }
130
131
 
131
132
  protected:
@@ -133,17 +134,14 @@ protected:
133
134
  JsiDomDeclarationNode::defineProperties(container);
134
135
  _txProp = container->defineProperty<TileModeProp>("tx");
135
136
  _tyProp = container->defineProperty<TileModeProp>("ty");
136
- _filterModeProp = container->defineProperty<NodeProp>("fm");
137
- _mipmapModeProp = container->defineProperty<NodeProp>("mm");
138
137
 
138
+ _samplingProp = container->defineProperty<SamplingProp>("sampling");
139
139
  _imageProps = container->defineProperty<ImageProps>();
140
140
  _transformProp = container->defineProperty<TransformProp>("transform");
141
141
  _originProp = container->defineProperty<PointProp>("origin");
142
142
 
143
143
  _txProp->require();
144
144
  _tyProp->require();
145
- _filterModeProp->require();
146
- _mipmapModeProp->require();
147
145
 
148
146
  _transformProp->require();
149
147
 
@@ -152,41 +150,14 @@ protected:
152
150
  }
153
151
 
154
152
  private:
155
- SkFilterMode getFilterModeFromString(const std::string &value) {
156
- if (value == "last") {
157
- return SkFilterMode::kLast;
158
- } else if (value == "linear") {
159
- return SkFilterMode::kLinear;
160
- } else if (value == "nearest") {
161
- return SkFilterMode::kNearest;
162
- }
163
- throw std::runtime_error("The value \"" + value +
164
- "\" is not a valid Filter Mode.");
165
- }
166
-
167
- SkMipmapMode getMipmapModeFromString(const std::string &value) {
168
- if (value == "last") {
169
- return SkMipmapMode::kLast;
170
- } else if (value == "last") {
171
- return SkMipmapMode::kLast;
172
- } else if (value == "last") {
173
- return SkMipmapMode::kLast;
174
- } else if (value == "none") {
175
- return SkMipmapMode::kNone;
176
- }
177
- throw std::runtime_error("The value \"" + value +
178
- "\" is not a valid Mipmap Mode.");
179
- }
180
-
181
153
  SkMatrix _matrix;
182
154
 
183
155
  TileModeProp *_txProp;
184
156
  TileModeProp *_tyProp;
185
- NodeProp *_filterModeProp;
186
- NodeProp *_mipmapModeProp;
187
157
  ImageProps *_imageProps;
188
158
  TransformProp *_transformProp;
189
159
  PointProp *_originProp;
160
+ SamplingProp *_samplingProp;
190
161
  };
191
162
 
192
163
  class JsiColorShaderNode : public JsiDomDeclarationNode,
@@ -0,0 +1,54 @@
1
+ #pragma once
2
+
3
+ #include "include/core/SkSamplingOptions.h"
4
+
5
+ namespace RNSkia {
6
+
7
+ static PropId PropNameCubicB = JsiPropId::get("B");
8
+ static PropId PropNameCubicC = JsiPropId::get("C");
9
+ static PropId PropNameFilter = JsiPropId::get("filter");
10
+ static PropId PropNameMipmap = JsiPropId::get("mipmap");
11
+
12
+ class SamplingProp : public DerivedProp<SkSamplingOptions> {
13
+ public:
14
+ explicit SamplingProp(PropId name,
15
+ const std::function<void(BaseNodeProp *)> &onChange)
16
+ : DerivedProp(onChange) {
17
+ _prop = defineProperty<NodeProp>(name);
18
+ }
19
+
20
+ static SkSamplingOptions processSamplingOptions(const JsiValue &value) {
21
+ SkSamplingOptions samplingOptions(SkFilterMode::kLinear);
22
+ if (value.getType() == PropType::Object) {
23
+ if (value.hasValue(PropNameCubicB) && value.hasValue(PropNameCubicC)) {
24
+ auto B =
25
+ static_cast<float>(value.getValue(PropNameCubicB).getAsNumber());
26
+ auto C =
27
+ static_cast<float>(value.getValue(PropNameCubicC).getAsNumber());
28
+ samplingOptions = SkSamplingOptions({B, C});
29
+ } else if (value.hasValue(PropNameFilter)) {
30
+ auto filter = static_cast<SkFilterMode>(
31
+ value.getValue(PropNameFilter).getAsNumber());
32
+ if (value.hasValue(PropNameMipmap)) {
33
+ auto mipmap = static_cast<SkMipmapMode>(
34
+ value.getValue(PropNameMipmap).getAsNumber());
35
+ samplingOptions = SkSamplingOptions(filter, mipmap);
36
+ } else {
37
+ samplingOptions = SkSamplingOptions(filter);
38
+ }
39
+ }
40
+ }
41
+
42
+ return samplingOptions;
43
+ }
44
+
45
+ void updateDerivedValue() override {
46
+ if (_prop->isSet()) {
47
+ setDerivedValue(SamplingProp::processSamplingOptions(_prop->value()));
48
+ }
49
+ }
50
+
51
+ private:
52
+ NodeProp *_prop;
53
+ };
54
+ } // namespace RNSkia
@@ -47,14 +47,12 @@ static __weak SkiaManager *sharedInstance = nil;
47
47
  return self;
48
48
  }
49
49
 
50
- - (void)dealloc
51
- {
50
+ - (void)dealloc {
52
51
  sharedInstance = nil;
53
52
  }
54
53
 
55
54
  #ifdef RCT_NEW_ARCH_ENABLED
56
- + (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager
57
- {
55
+ + (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager {
58
56
  if (sharedInstance != nil) {
59
57
  return [sharedInstance skManager];
60
58
  }
@@ -1,4 +1,4 @@
1
- import type { FillType, SkImage, StrokeOpts, Vector, Color, SkPoint, BlendMode, PointMode, VertexMode, SkFont, SkRRect, SkTextBlob, SkPicture, SkSVG, SkPaint, SkRect, SkRSXform, SkColor } from "../../skia/types";
1
+ import type { FillType, SkImage, StrokeOpts, Vector, Color, SkPoint, BlendMode, PointMode, VertexMode, SkFont, SkRRect, SkTextBlob, SkPicture, SkSVG, SkPaint, SkRect, SkRSXform, SkColor, SamplingOptions } from "../../skia/types";
2
2
  import type { CircleDef, Fit, GroupProps, PathDef, RectDef, RRectDef, SkEnum } from "./Common";
3
3
  export interface DrawingNodeProps extends GroupProps {
4
4
  paint?: SkPaint;
@@ -6,6 +6,7 @@ export interface DrawingNodeProps extends GroupProps {
6
6
  export type ImageProps = DrawingNodeProps & RectDef & {
7
7
  fit?: Fit;
8
8
  image: SkImage | null;
9
+ sampling?: SamplingOptions;
9
10
  };
10
11
  export type CircleProps = CircleDef & DrawingNodeProps;
11
12
  export interface PathProps extends DrawingNodeProps {
@@ -27,6 +28,7 @@ export interface AtlasProps extends DrawingNodeProps {
27
28
  sprites: SkRect[];
28
29
  transforms: SkRSXform[];
29
30
  colors?: SkColor[];
31
+ sampling?: SamplingOptions;
30
32
  }
31
33
  export interface CubicBezierHandle {
32
34
  pos: Vector;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n SamplingOptions,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n sampling?: SamplingOptions;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n sampling?: SamplingOptions;\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { Color, FilterMode, MipmapMode, SkImage, SkRect, SkRuntimeEffect, TileMode, Uniforms, Vector } from "../../skia/types";
1
+ import type { Color, SamplingOptions, SkImage, SkRect, SkRuntimeEffect, TileMode, Uniforms, Vector } from "../../skia/types";
2
2
  import type { SkEnum, TransformProps, ChildrenProps, RectCtor, Fit } from "./Common";
3
3
  export interface ShaderProps extends TransformProps, ChildrenProps {
4
4
  source: SkRuntimeEffect;
@@ -7,11 +7,10 @@ export interface ShaderProps extends TransformProps, ChildrenProps {
7
7
  export interface ImageShaderProps extends TransformProps, Partial<RectCtor> {
8
8
  tx: SkEnum<typeof TileMode>;
9
9
  ty: SkEnum<typeof TileMode>;
10
- fm: SkEnum<typeof FilterMode>;
11
- mm: SkEnum<typeof MipmapMode>;
12
10
  fit: Fit;
13
11
  rect?: SkRect;
14
12
  image: SkImage | null;
13
+ sampling?: SamplingOptions;
15
14
  }
16
15
  export interface ColorProps {
17
16
  color: Color;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Shaders.ts"],"sourcesContent":["import type {\n Color,\n FilterMode,\n MipmapMode,\n SkImage,\n SkRect,\n SkRuntimeEffect,\n TileMode,\n Uniforms,\n Vector,\n} from \"../../skia/types\";\n\nimport type {\n SkEnum,\n TransformProps,\n ChildrenProps,\n RectCtor,\n Fit,\n} from \"./Common\";\n\nexport interface ShaderProps extends TransformProps, ChildrenProps {\n source: SkRuntimeEffect;\n uniforms: Uniforms;\n}\n\nexport interface ImageShaderProps extends TransformProps, Partial<RectCtor> {\n tx: SkEnum<typeof TileMode>;\n ty: SkEnum<typeof TileMode>;\n fm: SkEnum<typeof FilterMode>;\n mm: SkEnum<typeof MipmapMode>;\n fit: Fit;\n rect?: SkRect;\n image: SkImage | null;\n}\n\nexport interface ColorProps {\n color: Color;\n}\n\nexport interface TurbulenceProps {\n freqX: number;\n freqY: number;\n octaves: number;\n seed: number;\n tileWidth: number;\n tileHeight: number;\n}\n\nexport interface FractalNoiseProps {\n freqX: number;\n freqY: number;\n octaves: number;\n seed: number;\n tileWidth: number;\n tileHeight: number;\n}\n\nexport interface GradientProps extends TransformProps {\n colors: Color[];\n positions?: number[];\n mode?: SkEnum<typeof TileMode>;\n flags?: number;\n}\n\nexport interface LinearGradientProps extends GradientProps {\n start: Vector;\n end: Vector;\n}\n\nexport interface RadialGradientProps extends GradientProps {\n c: Vector;\n r: number;\n}\n\nexport interface SweepGradientProps extends GradientProps {\n c: Vector;\n start?: number;\n end?: number;\n}\n\nexport interface TwoPointConicalGradientProps extends GradientProps {\n start: Vector;\n startR: number;\n end: Vector;\n endR: number;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Shaders.ts"],"sourcesContent":["import type {\n Color,\n SamplingOptions,\n SkImage,\n SkRect,\n SkRuntimeEffect,\n TileMode,\n Uniforms,\n Vector,\n} from \"../../skia/types\";\n\nimport type {\n SkEnum,\n TransformProps,\n ChildrenProps,\n RectCtor,\n Fit,\n} from \"./Common\";\n\nexport interface ShaderProps extends TransformProps, ChildrenProps {\n source: SkRuntimeEffect;\n uniforms: Uniforms;\n}\n\nexport interface ImageShaderProps extends TransformProps, Partial<RectCtor> {\n tx: SkEnum<typeof TileMode>;\n ty: SkEnum<typeof TileMode>;\n fit: Fit;\n rect?: SkRect;\n image: SkImage | null;\n sampling?: SamplingOptions;\n}\n\nexport interface ColorProps {\n color: Color;\n}\n\nexport interface TurbulenceProps {\n freqX: number;\n freqY: number;\n octaves: number;\n seed: number;\n tileWidth: number;\n tileHeight: number;\n}\n\nexport interface FractalNoiseProps {\n freqX: number;\n freqY: number;\n octaves: number;\n seed: number;\n tileWidth: number;\n tileHeight: number;\n}\n\nexport interface GradientProps extends TransformProps {\n colors: Color[];\n positions?: number[];\n mode?: SkEnum<typeof TileMode>;\n flags?: number;\n}\n\nexport interface LinearGradientProps extends GradientProps {\n start: Vector;\n end: Vector;\n}\n\nexport interface RadialGradientProps extends GradientProps {\n c: Vector;\n r: number;\n}\n\nexport interface SweepGradientProps extends GradientProps {\n c: Vector;\n start?: number;\n end?: number;\n}\n\nexport interface TwoPointConicalGradientProps extends GradientProps {\n start: Vector;\n startR: number;\n end: Vector;\n endR: number;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import type { ImageShaderProps } from "../../../dom/types";
3
3
  import type { SkiaDefaultProps } from "../../processors";
4
- export declare const ImageShader: ({ tx, ty, fm, mm, fit, transform, ...props }: SkiaDefaultProps<ImageShaderProps, "tx" | "ty" | "fm" | "mm" | "fit" | "transform">) => React.JSX.Element;
4
+ export declare const ImageShader: ({ tx, ty, fit, transform, ...props }: SkiaDefaultProps<ImageShaderProps, "tx" | "ty" | "fit" | "transform">) => React.JSX.Element;
@@ -10,8 +10,6 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
10
10
  const ImageShader = ({
11
11
  tx = "decal",
12
12
  ty = "decal",
13
- fm = "nearest",
14
- mm = "none",
15
13
  fit = "none",
16
14
  transform = [],
17
15
  ...props
@@ -19,8 +17,6 @@ const ImageShader = ({
19
17
  return /*#__PURE__*/_react.default.createElement("skImageShader", _extends({
20
18
  tx: tx,
21
19
  ty: ty,
22
- fm: fm,
23
- mm: mm,
24
20
  fit: fit,
25
21
  transform: transform
26
22
  }, props));
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","ImageShader","tx","ty","fm","mm","fit","transform","props","createElement","exports"],"sources":["ImageShader.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { ImageShaderProps } from \"../../../dom/types\";\nimport type { SkiaDefaultProps } from \"../../processors\";\n\nexport const ImageShader = ({\n tx = \"decal\",\n ty = \"decal\",\n fm = \"nearest\",\n mm = \"none\",\n fit = \"none\",\n transform = [],\n ...props\n}: SkiaDefaultProps<\n ImageShaderProps,\n \"tx\" | \"ty\" | \"fm\" | \"mm\" | \"fit\" | \"transform\"\n>) => {\n return (\n <skImageShader\n tx={tx}\n ty={ty}\n fm={fm}\n mm={mm}\n fit={fit}\n transform={transform}\n {...props}\n />\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAKnB,MAAMO,WAAW,GAAGA,CAAC;EAC1BC,EAAE,GAAG,OAAO;EACZC,EAAE,GAAG,OAAO;EACZC,EAAE,GAAG,SAAS;EACdC,EAAE,GAAG,MAAM;EACXC,GAAG,GAAG,MAAM;EACZC,SAAS,GAAG,EAAE;EACd,GAAGC;AAIL,CAAC,KAAK;EACJ,oBACEzB,MAAA,CAAAK,OAAA,CAAAqB,aAAA,kBAAApB,QAAA;IACEa,EAAE,EAAEA,EAAG;IACPC,EAAE,EAAEA,EAAG;IACPC,EAAE,EAAEA,EAAG;IACPC,EAAE,EAAEA,EAAG;IACPC,GAAG,EAAEA,GAAI;IACTC,SAAS,EAAEA;EAAU,GACjBC,KAAK,CACV,CAAC;AAEN,CAAC;AAACE,OAAA,CAAAT,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","ImageShader","tx","ty","fit","transform","props","createElement","exports"],"sources":["ImageShader.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { ImageShaderProps } from \"../../../dom/types\";\nimport type { SkiaDefaultProps } from \"../../processors\";\n\nexport const ImageShader = ({\n tx = \"decal\",\n ty = \"decal\",\n fit = \"none\",\n transform = [],\n ...props\n}: SkiaDefaultProps<ImageShaderProps, \"tx\" | \"ty\" | \"fit\" | \"transform\">) => {\n return (\n <skImageShader tx={tx} ty={ty} fit={fit} transform={transform} {...props} />\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAKnB,MAAMO,WAAW,GAAGA,CAAC;EAC1BC,EAAE,GAAG,OAAO;EACZC,EAAE,GAAG,OAAO;EACZC,GAAG,GAAG,MAAM;EACZC,SAAS,GAAG,EAAE;EACd,GAAGC;AACkE,CAAC,KAAK;EAC3E,oBACEvB,MAAA,CAAAK,OAAA,CAAAmB,aAAA,kBAAAlB,QAAA;IAAea,EAAE,EAAEA,EAAG;IAACC,EAAE,EAAEA,EAAG;IAACC,GAAG,EAAEA,GAAI;IAACC,SAAS,EAAEA;EAAU,GAAKC,KAAK,CAAG,CAAC;AAEhF,CAAC;AAACE,OAAA,CAAAP,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -2,7 +2,7 @@ import type { SkPaint } from "./Paint";
2
2
  import type { SkRect } from "./Rect";
3
3
  import type { SkFont } from "./Font";
4
4
  import type { SkPath } from "./Path";
5
- import type { SkImage, MipmapMode, FilterMode, ImageInfo, CubicResampler, FilterOptions } from "./Image";
5
+ import type { SkImage, MipmapMode, FilterMode, ImageInfo, SamplingOptions } from "./Image";
6
6
  import type { SkSVG } from "./SVG";
7
7
  import type { SkColor } from "./Color";
8
8
  import type { InputRRect } from "./RRect";
@@ -392,7 +392,7 @@ export interface SkCanvas {
392
392
  * @param {CubicResampler | FilterOptions} [sampling] - The sampling options. Optional.
393
393
  * @returns {void} This method does not return anything.
394
394
  */
395
- drawAtlas(atlas: SkImage, srcs: SkRect[], dsts: SkRSXform[], paint: SkPaint, blendMode?: BlendMode, colors?: SkColor[], sampling?: CubicResampler | FilterOptions): void;
395
+ drawAtlas(atlas: SkImage, srcs: SkRect[], dsts: SkRSXform[], paint: SkPaint, blendMode?: BlendMode, colors?: SkColor[], sampling?: SamplingOptions): void;
396
396
  /** Read Image pixels
397
397
  *
398
398
  * @param srcX - x-axis upper left corner of the rectangle to read from
@@ -1 +1 @@
1
- {"version":3,"names":["ClipOp","exports","SaveLayerFlag"],"sources":["Canvas.ts"],"sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type {\n SkImage,\n MipmapMode,\n FilterMode,\n ImageInfo,\n CubicResampler,\n FilterOptions,\n} from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { InputRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { InputMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\nimport type { SkPicture } from \"./Picture\";\nimport type { SkRSXform } from \"./RSXform\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: InputRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: InputRRect, inner: InputRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: InputMatrix): void;\n\n /**\n * Draws the given picture using the current clip, current matrix, and the provided paint.\n * @param skp\n */\n drawPicture(skp: SkPicture): void;\n\n /**\n * This method is used to draw an atlas on the canvas.\n *\n * @method drawAtlas\n * @param {SkImage} atlas - The image to be drawn.\n * @param {SkRect[]} srcs - The source rectangles.\n * @param {SkRSXform[]} dsts - The destination transformations.\n * @param {SkPaint} paint - The paint used for drawing.\n * @param {BlendMode} [blendMode] - The blend mode used for drawing. Optional.\n * @param {SkColor[]} [colors] - The colors used for drawing. Optional.\n * @param {CubicResampler | FilterOptions} [sampling] - The sampling options. Optional.\n * @returns {void} This method does not return anything.\n */\n drawAtlas(\n atlas: SkImage,\n srcs: SkRect[],\n dsts: SkRSXform[],\n paint: SkPaint,\n blendMode?: BlendMode,\n colors?: SkColor[],\n sampling?: CubicResampler | FilterOptions\n ): void;\n\n /** Read Image pixels\n *\n * @param srcX - x-axis upper left corner of the rectangle to read from\n * @param srcY - y-axis upper left corner of the rectangle to read from\n * @param imageInfo - describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX: number,\n srcY: number,\n imageInfo: ImageInfo\n ): Float32Array | Uint8Array | null;\n}\n"],"mappings":";;;;;;IAwBYA,MAAM,GAAAC,OAAA,CAAAD,MAAA,0BAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAAA,IAKNE,aAAa,GAAAD,OAAA,CAAAC,aAAA,0BAAbA,aAAa;EAAbA,aAAa,CAAbA,aAAa;EAAbA,aAAa,CAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["ClipOp","exports","SaveLayerFlag"],"sources":["Canvas.ts"],"sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type {\n SkImage,\n MipmapMode,\n FilterMode,\n ImageInfo,\n SamplingOptions,\n} from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { InputRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { InputMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\nimport type { SkPicture } from \"./Picture\";\nimport type { SkRSXform } from \"./RSXform\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: InputRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: InputRRect, inner: InputRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: InputMatrix): void;\n\n /**\n * Draws the given picture using the current clip, current matrix, and the provided paint.\n * @param skp\n */\n drawPicture(skp: SkPicture): void;\n\n /**\n * This method is used to draw an atlas on the canvas.\n *\n * @method drawAtlas\n * @param {SkImage} atlas - The image to be drawn.\n * @param {SkRect[]} srcs - The source rectangles.\n * @param {SkRSXform[]} dsts - The destination transformations.\n * @param {SkPaint} paint - The paint used for drawing.\n * @param {BlendMode} [blendMode] - The blend mode used for drawing. Optional.\n * @param {SkColor[]} [colors] - The colors used for drawing. Optional.\n * @param {CubicResampler | FilterOptions} [sampling] - The sampling options. Optional.\n * @returns {void} This method does not return anything.\n */\n drawAtlas(\n atlas: SkImage,\n srcs: SkRect[],\n dsts: SkRSXform[],\n paint: SkPaint,\n blendMode?: BlendMode,\n colors?: SkColor[],\n sampling?: SamplingOptions\n ): void;\n\n /** Read Image pixels\n *\n * @param srcX - x-axis upper left corner of the rectangle to read from\n * @param srcY - y-axis upper left corner of the rectangle to read from\n * @param imageInfo - describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX: number,\n srcY: number,\n imageInfo: ImageInfo\n ): Float32Array | Uint8Array | null;\n}\n"],"mappings":";;;;;;IAuBYA,MAAM,GAAAC,OAAA,CAAAD,MAAA,0BAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAAA,IAKNE,aAAa,GAAAD,OAAA,CAAAC,aAAA,0BAAbA,aAAa;EAAbA,aAAa,CAAbA,aAAa;EAAbA,aAAa,CAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA","ignoreList":[]}
@@ -25,6 +25,24 @@ export declare enum ImageFormat {
25
25
  PNG = 4,
26
26
  WEBP = 6
27
27
  }
28
+ export type SamplingOptions = CubicResampler | FilterOptions;
29
+ export declare const isCubicSampling: (sampling: SamplingOptions) => sampling is CubicResampler;
30
+ export declare const MitchellCubicSampling: {
31
+ B: number;
32
+ C: number;
33
+ };
34
+ export declare const CatmullRomCubicSampling: {
35
+ B: number;
36
+ C: number;
37
+ };
38
+ export declare const CubicSampling: {
39
+ B: number;
40
+ C: number;
41
+ };
42
+ export declare const MakeCubic: (B: number, C: number) => {
43
+ B: number;
44
+ C: number;
45
+ };
28
46
  export interface SkImage extends SkJSIInstance<"Image"> {
29
47
  /**
30
48
  * Returns the possibly scaled height of the image.