@shopify/react-native-skia 1.5.2 → 1.5.4

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.
Files changed (87) hide show
  1. package/android/CMakeLists.txt +52 -13
  2. package/android/build.gradle +3 -0
  3. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +18 -1
  4. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +12 -1
  5. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +13 -0
  6. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -1
  7. package/cpp/api/JsiSkImage.h +15 -2
  8. package/cpp/api/JsiSkSurface.h +18 -3
  9. package/cpp/rnskia/DawnContext.h +241 -0
  10. package/cpp/rnskia/DawnUtils.h +127 -0
  11. package/cpp/rnskia/DawnWindowContext.cpp +19 -0
  12. package/cpp/rnskia/DawnWindowContext.h +77 -0
  13. package/cpp/rnskia/ImageProvider.h +100 -0
  14. package/cpp/rnskia/RNSkView.h +6 -0
  15. package/cpp/skia/include/android/SkAnimatedImage.h +14 -0
  16. package/cpp/skia/include/codec/SkAvifDecoder.h +39 -3
  17. package/cpp/skia/include/codec/SkCodec.h +16 -0
  18. package/cpp/skia/include/config/SkUserConfig.h +3 -2
  19. package/cpp/skia/include/core/SkCanvas.h +55 -10
  20. package/cpp/skia/include/core/SkContourMeasure.h +76 -0
  21. package/cpp/skia/include/core/SkFontScanner.h +48 -0
  22. package/cpp/skia/include/core/SkMilestone.h +1 -1
  23. package/cpp/skia/include/core/SkPath.h +11 -0
  24. package/cpp/skia/include/core/SkPathEffect.h +0 -23
  25. package/cpp/skia/include/core/SkRect.h +2 -0
  26. package/cpp/skia/include/core/SkString.h +4 -0
  27. package/cpp/skia/include/core/SkTypeface.h +5 -0
  28. package/cpp/skia/include/core/SkTypes.h +8 -3
  29. package/cpp/skia/include/docs/SkPDFDocument.h +3 -3
  30. package/cpp/skia/include/effects/SkOverdrawColorFilter.h +1 -0
  31. package/cpp/skia/include/effects/SkRuntimeEffect.h +2 -1
  32. package/cpp/skia/include/encode/SkJpegEncoder.h +4 -0
  33. package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +8 -1
  34. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +18 -3
  35. package/cpp/skia/include/gpu/ganesh/GrTypes.h +11 -0
  36. package/cpp/skia/include/gpu/ganesh/gl/GrGLFunctions.h +5 -1
  37. package/cpp/skia/include/gpu/ganesh/gl/GrGLInterface.h +0 -1
  38. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +8 -0
  39. package/cpp/skia/include/gpu/graphite/Recorder.h +0 -2
  40. package/cpp/skia/include/gpu/graphite/precompile/PaintOptions.h +7 -4
  41. package/cpp/skia/include/gpu/graphite/precompile/PrecompileImageFilter.h +2 -0
  42. package/cpp/skia/include/gpu/graphite/precompile/PrecompileMaskFilter.h +2 -0
  43. package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +25 -0
  44. package/cpp/skia/include/ports/SkFontMgr_fontconfig.h +4 -2
  45. package/cpp/skia/include/ports/SkFontScanner_Fontations.h +15 -0
  46. package/cpp/skia/include/ports/SkFontScanner_FreeType.h +15 -0
  47. package/cpp/skia/include/private/SkExif.h +14 -0
  48. package/cpp/skia/include/private/SkPathRef.h +36 -0
  49. package/cpp/skia/include/private/base/SkFeatures.h +4 -0
  50. package/cpp/skia/include/private/base/SkSpan_impl.h +1 -3
  51. package/cpp/skia/modules/skcms/src/skcms_internals.h +3 -0
  52. package/cpp/skia/src/base/SkMathPriv.h +1 -8
  53. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +1 -2
  54. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +25 -19
  55. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +23 -0
  56. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +23 -9
  57. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +0 -20
  58. package/libs/android/arm64-v8a/libskia.a +0 -0
  59. package/libs/android/arm64-v8a/libskottie.a +0 -0
  60. package/libs/android/armeabi-v7a/libskia.a +0 -0
  61. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  62. package/libs/android/x86/libskia.a +0 -0
  63. package/libs/android/x86/libskottie.a +0 -0
  64. package/libs/android/x86_64/libskia.a +0 -0
  65. package/libs/android/x86_64/libskottie.a +0 -0
  66. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  67. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  68. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  69. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  70. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  71. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  72. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  73. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  74. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  75. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  76. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  77. package/libs/ios/libskunicode_core.xcframework/Info.plist +5 -5
  78. package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
  79. package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  80. package/libs/ios/libskunicode_libgrapheme.xcframework/Info.plist +5 -5
  81. package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  82. package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  83. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  84. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  85. package/package.json +1 -1
  86. package/react-native-skia.podspec +35 -9
  87. package/src/renderer/__tests__/e2e/SVG.spec.tsx +2 -1
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright 2024 Google Inc.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #ifndef SKFONTSCANNER_FREETYPE_H_
9
+ #define SKFONTSCANNER_FREETYPE_H_
10
+
11
+ #include "include/core/SkFontScanner.h"
12
+
13
+ SK_API std::unique_ptr<SkFontScanner> SkFontScanner_Make_FreeType();
14
+
15
+ #endif // SKFONTSCANNER_FREETYPE_H_
@@ -9,6 +9,7 @@
9
9
  #define SkExif_DEFINED
10
10
 
11
11
  #include "include/codec/SkEncodedOrigin.h"
12
+ #include "include/core/SkRefCnt.h"
12
13
  #include "include/private/base/SkAPI.h"
13
14
 
14
15
  #include <cstdint>
@@ -50,6 +51,19 @@ struct Metadata {
50
51
  */
51
52
  void SK_API Parse(Metadata& metadata, const SkData* data);
52
53
 
54
+ /*
55
+ * Write exif data that includes the values in |metadata| and returns it as SkData
56
+ * untruncated. Return nullptr if a write to the data stream fails or if
57
+ * |metadata.fHdrHeadroom| has value.
58
+ * This function cannot write an IFD entry based on the HdrHeadroom value because
59
+ * the information of maker33 and maker48 are lost in decoding.
60
+ * For metadata that belongs in a subIFD the function will write it to one and
61
+ * store it after the root IFD.
62
+ * Data that does not fit within kSizeEntry, is appended to the end of the data,
63
+ * after the subIFD if it exists.
64
+ */
65
+ sk_sp<SkData> WriteExif(Metadata& metadata);
66
+
53
67
  } // namespace SkExif
54
68
 
55
69
  #endif
@@ -8,6 +8,7 @@
8
8
  #ifndef SkPathRef_DEFINED
9
9
  #define SkPathRef_DEFINED
10
10
 
11
+ #include "include/core/SkArc.h"
11
12
  #include "include/core/SkPoint.h"
12
13
  #include "include/core/SkRect.h"
13
14
  #include "include/core/SkRefCnt.h"
@@ -63,6 +64,7 @@ public:
63
64
  kGeneral,
64
65
  kOval,
65
66
  kRRect,
67
+ kArc,
66
68
  };
67
69
 
68
70
  SkPathRef(SkSpan<const SkPoint> points, SkSpan<const uint8_t> verbs,
@@ -78,6 +80,9 @@ public:
78
80
  // The next two values don't matter unless fType is kOval or kRRect
79
81
  fRRectOrOvalIsCCW = false;
80
82
  fRRectOrOvalStartIdx = 0xAC;
83
+ fArcOval.setEmpty();
84
+ fArcStartAngle = fArcSweepAngle = 0.0f;
85
+ fArcType = SkArc::Type::kArc;
81
86
  SkDEBUGCODE(fEditorsAttached.store(0);)
82
87
 
83
88
  this->computeBounds(); // do this now, before we worry about multiple owners/threads
@@ -160,6 +165,10 @@ public:
160
165
  fPathRef->setIsRRect(isCCW, start);
161
166
  }
162
167
 
168
+ void setIsArc(const SkArc& arc) {
169
+ fPathRef->setIsArc(arc);
170
+ }
171
+
163
172
  void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); }
164
173
 
165
174
  private:
@@ -249,6 +258,16 @@ public:
249
258
 
250
259
  bool isRRect(SkRRect* rrect, bool* isCCW, unsigned* start) const;
251
260
 
261
+ bool isArc(SkArc* arc) const {
262
+ if (fType == PathType::kArc) {
263
+ if (arc) {
264
+ *arc = SkArc::Make(fArcOval, fArcStartAngle, fArcSweepAngle, fArcType);
265
+ }
266
+ }
267
+
268
+ return fType == PathType::kArc;
269
+ }
270
+
252
271
  bool hasComputedBounds() const {
253
272
  return !fBoundsIsDirty;
254
273
  }
@@ -365,6 +384,9 @@ private:
365
384
  // The next two values don't matter unless fType is kOval or kRRect
366
385
  fRRectOrOvalIsCCW = false;
367
386
  fRRectOrOvalStartIdx = 0xAC;
387
+ fArcOval.setEmpty();
388
+ fArcStartAngle = fArcSweepAngle = 0.0f;
389
+ fArcType = SkArc::Type::kArc;
368
390
  if (numPoints > 0) {
369
391
  fPoints.reserve_exact(numPoints);
370
392
  }
@@ -497,6 +519,14 @@ private:
497
519
  fRRectOrOvalStartIdx = SkToU8(start);
498
520
  }
499
521
 
522
+ void setIsArc(const SkArc& arc) {
523
+ fType = PathType::kArc;
524
+ fArcOval = arc.fOval;
525
+ fArcStartAngle = arc.fStartAngle;
526
+ fArcSweepAngle = arc.fSweepAngle;
527
+ fArcType = arc.fType;
528
+ }
529
+
500
530
  // called only by the editor. Note that this is not a const function.
501
531
  SkPoint* getWritablePoints() {
502
532
  SkDEBUGCODE(this->validate();)
@@ -534,6 +564,12 @@ private:
534
564
  bool fRRectOrOvalIsCCW;
535
565
  uint8_t fRRectOrOvalStartIdx;
536
566
  uint8_t fSegmentMask;
567
+ // If the path is an arc, these four variables store that information.
568
+ // We should just store an SkArc, but alignment would cost us 8 more bytes.
569
+ SkArc::Type fArcType;
570
+ SkRect fArcOval;
571
+ SkScalar fArcStartAngle;
572
+ SkScalar fArcSweepAngle;
537
573
 
538
574
  friend class PathRefTest_Private;
539
575
  friend class ForceIsRRect_Private; // unit test isRRect
@@ -69,6 +69,10 @@
69
69
  #define SK_CPU_LOONGARCH 1
70
70
  #endif
71
71
 
72
+ #if defined(__powerpc__) || defined (__powerpc64__)
73
+ #define SK_CPU_PPC 1
74
+ #endif
75
+
72
76
  /**
73
77
  * SK_CPU_SSE_LEVEL
74
78
  *
@@ -69,7 +69,7 @@ public:
69
69
  template <typename Integer, std::enable_if_t<std::is_integral_v<Integer>, bool> = true>
70
70
  constexpr SkSpan(T* ptr, Integer size) : fPtr{ptr}, fSize{SkToSizeT(size)} {
71
71
  SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size
72
- SkASSERT(fSize < kMaxSize);
72
+ SkASSERT(fSize < (std::numeric_limits<size_t>::max() / sizeof(T)));
73
73
  }
74
74
  template <typename U, typename = std::enable_if_t<std::is_same_v<const U, T>>>
75
75
  constexpr SkSpan(const SkSpan<U>& that) : fPtr(std::data(that)), fSize(std::size(that)) {}
@@ -118,8 +118,6 @@ public:
118
118
  }
119
119
 
120
120
  private:
121
- static constexpr size_t kMaxSize = std::numeric_limits<size_t>::max() / sizeof(T);
122
-
123
121
  T* fPtr;
124
122
  size_t fSize;
125
123
  };
@@ -39,6 +39,8 @@ extern "C" {
39
39
  // - Clang 18 runs into an ICE on armv7/androideabi with [[clang::musttail]].
40
40
  // (http://crbug.com/1504548)
41
41
  // - Android RISC-V also runs into an ICE (b/314692534)
42
+ // - So does Linux ppc64le (https://github.com/llvm/llvm-project/issues/108014,
43
+ // https://github.com/llvm/llvm-project/issues/98859)
42
44
  // - LoongArch developers indicate they had to turn it off
43
45
  // - Windows builds generate incorrect code with [[clang::musttail]] and crash mysteriously.
44
46
  // (http://crbug.com/1505442)
@@ -47,6 +49,7 @@ extern "C" {
47
49
  && !defined(__EMSCRIPTEN__) \
48
50
  && !defined(__arm__) \
49
51
  && !defined(__riscv) \
52
+ && !defined(__powerpc__) \
50
53
  && !defined(__loongarch__) \
51
54
  && !defined(_WIN32) && !defined(__SYMBIAN32__)
52
55
  #define SKCMS_HAS_MUSTTAIL 1
@@ -300,17 +300,10 @@ constexpr int SkPrevPow2_portable(int value) {
300
300
 
301
301
  ///////////////////////////////////////////////////////////////////////////////
302
302
 
303
- /**
304
- * Return the smallest power-of-2 >= n.
305
- */
306
- static inline uint32_t GrNextPow2(uint32_t n) {
307
- return n ? (1 << (32 - SkCLZ(n - 1))) : 1;
308
- }
309
-
310
303
  /**
311
304
  * Returns the next power of 2 >= n or n if the next power of 2 can't be represented by size_t.
312
305
  */
313
- static inline size_t GrNextSizePow2(size_t n) {
306
+ constexpr size_t SkNextSizePow2(size_t n) {
314
307
  constexpr int kNumSizeTBits = 8 * sizeof(size_t);
315
308
  constexpr size_t kHighBitSet = size_t(1) << (kNumSizeTBits - 1);
316
309
 
@@ -30,8 +30,7 @@ public:
30
30
 
31
31
  private:
32
32
  std::shared_ptr<RNSkia::RNSkPlatformContext> _context;
33
- float _width = -1;
34
- float _height = -1;
33
+ std::unique_ptr<RNSkia::WindowContext> _ctx = nullptr;
35
34
  #pragma clang diagnostic push
36
35
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
37
36
  CAMetalLayer *_layer;
@@ -1,7 +1,13 @@
1
1
  #import "RNSkMetalCanvasProvider.h"
2
- #include "MetalContext.h"
2
+
3
3
  #import "RNSkLog.h"
4
4
 
5
+ #if defined(SK_GRAPHITE)
6
+ #import "DawnContext.h"
7
+ #else
8
+ #import "MetalContext.h"
9
+ #endif
10
+
5
11
  #pragma clang diagnostic push
6
12
  #pragma clang diagnostic ignored "-Wdocumentation"
7
13
 
@@ -30,19 +36,23 @@ RNSkMetalCanvasProvider::~RNSkMetalCanvasProvider() {}
30
36
  /**
31
37
  Returns the scaled width of the view
32
38
  */
33
- float RNSkMetalCanvasProvider::getScaledWidth() { return _width; };
39
+ float RNSkMetalCanvasProvider::getScaledWidth() {
40
+ return _ctx ? _ctx->getWidth() : -1;
41
+ };
34
42
 
35
43
  /**
36
44
  Returns the scaled height of the view
37
45
  */
38
- float RNSkMetalCanvasProvider::getScaledHeight() { return _height; };
46
+ float RNSkMetalCanvasProvider::getScaledHeight() {
47
+ return _ctx ? _ctx->getHeight() : -1;
48
+ };
39
49
 
40
50
  /**
41
51
  Render to a canvas
42
52
  */
43
53
  bool RNSkMetalCanvasProvider::renderToCanvas(
44
54
  const std::function<void(SkCanvas *)> &cb) {
45
- if (_width <= 0 || _height <= 0) {
55
+ if (!_ctx) {
46
56
  return false;
47
57
  }
48
58
 
@@ -66,28 +76,24 @@ bool RNSkMetalCanvasProvider::renderToCanvas(
66
76
  // rendering and not wait until later - we've seen some example of memory
67
77
  // usage growing very fast in the simulator without this.
68
78
  @autoreleasepool {
69
- id<CAMetalDrawable> currentDrawable = [_layer nextDrawable];
70
- if (currentDrawable == nullptr) {
71
- return false;
72
- }
73
- auto ctx = MetalContext::getInstance().MakeWindow(_layer, _width, _height);
74
- auto skSurface = ctx->getSurface();
75
- SkCanvas *canvas = skSurface->getCanvas();
79
+ auto surface = _ctx->getSurface();
80
+ auto canvas = surface->getCanvas();
76
81
  cb(canvas);
77
-
78
- if (auto dContext = GrAsDirectContext(skSurface->recordingContext())) {
79
- dContext->flushAndSubmit();
80
- }
81
-
82
- ctx->present();
82
+ _ctx->present();
83
83
  }
84
84
  return true;
85
85
  };
86
86
 
87
87
  void RNSkMetalCanvasProvider::setSize(int width, int height) {
88
88
  _layer.frame = CGRectMake(0, 0, width, height);
89
- _width = width * _context->getPixelDensity();
90
- _height = height * _context->getPixelDensity();
89
+ auto w = width * _context->getPixelDensity();
90
+ auto h = height * _context->getPixelDensity();
91
+ #if defined(SK_GRAPHITE)
92
+ _ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
93
+ w, h);
94
+ #else
95
+ _ctx = MetalContext::getInstance().MakeWindow(_layer, w, h);
96
+ #endif
91
97
  _requestRedraw();
92
98
  }
93
99
 
@@ -5,7 +5,11 @@
5
5
  #include <thread>
6
6
  #include <utility>
7
7
 
8
+ #if defined(SK_GRAPHITE)
9
+ #include "DawnContext.h"
10
+ #else
8
11
  #include "MetalContext.h"
12
+ #endif
9
13
  #include "RNSkiOSVideo.h"
10
14
 
11
15
  #pragma clang diagnostic push
@@ -69,10 +73,17 @@ void RNSkiOSPlatformContext::releaseNativeBuffer(uint64_t pointer) {
69
73
  uint64_t RNSkiOSPlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
70
74
  // 0. If Image is not in BGRA, convert to BGRA as only BGRA is supported.
71
75
  if (image->colorType() != kBGRA_8888_SkColorType) {
76
+ #if defined(SK_GRAPHITE)
77
+ SkImage::RequiredProperties requiredProps;
78
+ image = image->makeColorTypeAndColorSpace(
79
+ DawnContext::getInstance().getRecorder(), kBGRA_8888_SkColorType,
80
+ SkColorSpace::MakeSRGB(), requiredProps);
81
+ #else
72
82
  // on iOS, 32_BGRA is the only supported RGB format for CVPixelBuffers.
73
83
  image = image->makeColorTypeAndColorSpace(
74
84
  MetalContext::getInstance()._context.skContext.get(),
75
85
  kBGRA_8888_SkColorType, SkColorSpace::MakeSRGB());
86
+ #endif
76
87
  if (image == nullptr) {
77
88
  throw std::runtime_error(
78
89
  "Failed to convert image to BGRA_8888 colortype! Only BGRA_8888 "
@@ -152,8 +163,12 @@ RNSkiOSPlatformContext::createVideo(const std::string &url) {
152
163
  std::shared_ptr<WindowContext>
153
164
  RNSkiOSPlatformContext::makeContextFromNativeSurface(void *surface, int width,
154
165
  int height) {
166
+ #if defined(SK_GRAPHITE)
167
+ return DawnContext::getInstance().MakeWindow(surface, width, height);
168
+ #else
155
169
  return MetalContext::getInstance().MakeWindow((__bridge CALayer *)surface,
156
170
  width, height);
171
+ #endif
157
172
  }
158
173
 
159
174
  void RNSkiOSPlatformContext::raiseError(const std::exception &err) {
@@ -162,11 +177,19 @@ void RNSkiOSPlatformContext::raiseError(const std::exception &err) {
162
177
 
163
178
  sk_sp<SkSurface> RNSkiOSPlatformContext::makeOffscreenSurface(int width,
164
179
  int height) {
180
+ #if defined(SK_GRAPHITE)
181
+ return DawnContext::getInstance().MakeOffscreen(width, height);
182
+ #else
165
183
  return MetalContext::getInstance().MakeOffscreen(width, height);
184
+ #endif
166
185
  }
167
186
 
168
187
  sk_sp<SkImage> RNSkiOSPlatformContext::makeImageFromNativeBuffer(void *buffer) {
188
+ #if defined(SK_GRAPHITE)
189
+ return DawnContext::getInstance().MakeImageFromBuffer(buffer);
190
+ #else
169
191
  return MetalContext::getInstance().MakeImageFromBuffer(buffer);
192
+ #endif
170
193
  }
171
194
 
172
195
  sk_sp<SkFontMgr> RNSkiOSPlatformContext::createFontMgr() {
@@ -11,9 +11,19 @@
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
12
12
 
13
13
  #import "include/core/SkCanvas.h"
14
+ #import "include/core/SkColorSpace.h"
15
+
14
16
  #import <CoreMedia/CMSampleBuffer.h>
15
17
  #import <CoreVideo/CVMetalTextureCache.h>
18
+
19
+ #import <include/gpu/ganesh/GrBackendSurface.h>
16
20
  #import <include/gpu/ganesh/GrDirectContext.h>
21
+ #import <include/gpu/ganesh/SkImageGanesh.h>
22
+ #import <include/gpu/ganesh/SkSurfaceGanesh.h>
23
+ #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
24
+ #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
25
+ #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
26
+ #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
17
27
 
18
28
  #pragma clang diagnostic pop
19
29
 
@@ -26,9 +36,6 @@ class SkiaMetalSurfaceFactory {
26
36
  friend class IOSSkiaContext;
27
37
 
28
38
  public:
29
- static sk_sp<SkSurface> makeWindowedSurface(SkiaMetalContext *context,
30
- id<MTLTexture> texture, int width,
31
- int height);
32
39
  static sk_sp<SkSurface> makeOffscreenSurface(id<MTLDevice> device,
33
40
  SkiaMetalContext *context,
34
41
  int width, int height);
@@ -54,7 +61,7 @@ public:
54
61
  _layer.framebufferOnly = NO;
55
62
  _layer.device = MTLCreateSystemDefaultDevice();
56
63
  _layer.opaque = false;
57
- _layer.contentsScale = 3;
64
+ _layer.contentsScale = [UIScreen mainScreen].scale;
58
65
  _layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
59
66
  _layer.contentsGravity = kCAGravityBottomLeft;
60
67
  _layer.drawableSize = CGSizeMake(width, height);
@@ -76,9 +83,16 @@ public:
76
83
  }
77
84
 
78
85
  // Get the texture from the drawable
79
- _skSurface = SkiaMetalSurfaceFactory::makeWindowedSurface(
80
- _context, _currentDrawable.texture, _layer.drawableSize.width,
81
- _layer.drawableSize.height);
86
+ GrMtlTextureInfo fbInfo;
87
+ fbInfo.fTexture.retain((__bridge void *)_currentDrawable.texture);
88
+
89
+ GrBackendRenderTarget backendRT = GrBackendRenderTargets::MakeMtl(
90
+ _layer.drawableSize.width, _layer.drawableSize.height, fbInfo);
91
+
92
+ _skSurface = SkSurfaces::WrapBackendRenderTarget(
93
+ _context->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
94
+ kBGRA_8888_SkColorType, nullptr, nullptr);
95
+
82
96
  return _skSurface;
83
97
  }
84
98
 
@@ -95,9 +109,9 @@ public:
95
109
 
96
110
  void resize(int width, int height) override { _skSurface = nullptr; }
97
111
 
98
- int getWidth() override { return _layer.frame.size.width; };
112
+ int getWidth() override { return _layer.frame.size.width * _layer.contentsScale; };
99
113
 
100
- int getHeight() override { return _layer.frame.size.height; };
114
+ int getHeight() override { return _layer.frame.size.height * _layer.contentsScale; };
101
115
 
102
116
  private:
103
117
  SkiaMetalContext *_context;
@@ -46,26 +46,6 @@ SkiaMetalSurfaceFactory::makeContext(SkiaMetalContext *context,
46
46
  return std::make_unique<IOSSkiaContext>(context, texture, width, height);
47
47
  }
48
48
 
49
- sk_sp<SkSurface> SkiaMetalSurfaceFactory::makeWindowedSurface(
50
- SkiaMetalContext *context, id<MTLTexture> texture, int width, int height) {
51
- GrMtlTextureInfo fbInfo;
52
- fbInfo.fTexture.retain((__bridge void *)texture);
53
-
54
- GrBackendRenderTarget backendRT =
55
- GrBackendRenderTargets::MakeMtl(width, height, fbInfo);
56
-
57
- auto skSurface = SkSurfaces::WrapBackendRenderTarget(
58
- context->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
59
- kBGRA_8888_SkColorType, nullptr, nullptr);
60
-
61
- if (skSurface == nullptr || skSurface->getCanvas() == nullptr) {
62
- RNSkia::RNSkLogger::logToConsole(
63
- "Skia surface could not be created from parameters.");
64
- return nullptr;
65
- }
66
- return skSurface;
67
- }
68
-
69
49
  sk_sp<SkSurface> SkiaMetalSurfaceFactory::makeOffscreenSurface(
70
50
  id<MTLDevice> device, SkiaMetalContext *context, int width, int height) {
71
51
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -8,34 +8,34 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>libskshaper.a</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64_arm64e</string>
11
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>libskshaper.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
17
  <string>arm64e</string>
18
+ <string>x86_64</string>
18
19
  </array>
19
20
  <key>SupportedPlatform</key>
20
21
  <string>ios</string>
22
+ <key>SupportedPlatformVariant</key>
23
+ <string>simulator</string>
21
24
  </dict>
22
25
  <dict>
23
26
  <key>BinaryPath</key>
24
27
  <string>libskshaper.a</string>
25
28
  <key>LibraryIdentifier</key>
26
- <string>ios-arm64_arm64e_x86_64-simulator</string>
29
+ <string>ios-arm64_arm64e</string>
27
30
  <key>LibraryPath</key>
28
31
  <string>libskshaper.a</string>
29
32
  <key>SupportedArchitectures</key>
30
33
  <array>
31
34
  <string>arm64</string>
32
35
  <string>arm64e</string>
33
- <string>x86_64</string>
34
36
  </array>
35
37
  <key>SupportedPlatform</key>
36
38
  <string>ios</string>
37
- <key>SupportedPlatformVariant</key>
38
- <string>simulator</string>
39
39
  </dict>
40
40
  </array>
41
41
  <key>CFBundlePackageType</key>
@@ -8,34 +8,34 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>libskunicode_core.a</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64_arm64e</string>
11
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>libskunicode_core.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
17
  <string>arm64e</string>
18
+ <string>x86_64</string>
18
19
  </array>
19
20
  <key>SupportedPlatform</key>
20
21
  <string>ios</string>
22
+ <key>SupportedPlatformVariant</key>
23
+ <string>simulator</string>
21
24
  </dict>
22
25
  <dict>
23
26
  <key>BinaryPath</key>
24
27
  <string>libskunicode_core.a</string>
25
28
  <key>LibraryIdentifier</key>
26
- <string>ios-arm64_arm64e_x86_64-simulator</string>
29
+ <string>ios-arm64_arm64e</string>
27
30
  <key>LibraryPath</key>
28
31
  <string>libskunicode_core.a</string>
29
32
  <key>SupportedArchitectures</key>
30
33
  <array>
31
34
  <string>arm64</string>
32
35
  <string>arm64e</string>
33
- <string>x86_64</string>
34
36
  </array>
35
37
  <key>SupportedPlatform</key>
36
38
  <string>ios</string>
37
- <key>SupportedPlatformVariant</key>
38
- <string>simulator</string>
39
39
  </dict>
40
40
  </array>
41
41
  <key>CFBundlePackageType</key>
@@ -8,34 +8,34 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>libskunicode_libgrapheme.a</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64_arm64e</string>
11
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>libskunicode_libgrapheme.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
17
  <string>arm64e</string>
18
+ <string>x86_64</string>
18
19
  </array>
19
20
  <key>SupportedPlatform</key>
20
21
  <string>ios</string>
22
+ <key>SupportedPlatformVariant</key>
23
+ <string>simulator</string>
21
24
  </dict>
22
25
  <dict>
23
26
  <key>BinaryPath</key>
24
27
  <string>libskunicode_libgrapheme.a</string>
25
28
  <key>LibraryIdentifier</key>
26
- <string>ios-arm64_arm64e_x86_64-simulator</string>
29
+ <string>ios-arm64_arm64e</string>
27
30
  <key>LibraryPath</key>
28
31
  <string>libskunicode_libgrapheme.a</string>
29
32
  <key>SupportedArchitectures</key>
30
33
  <array>
31
34
  <string>arm64</string>
32
35
  <string>arm64e</string>
33
- <string>x86_64</string>
34
36
  </array>
35
37
  <key>SupportedPlatform</key>
36
38
  <string>ios</string>
37
- <key>SupportedPlatformVariant</key>
38
- <string>simulator</string>
39
39
  </dict>
40
40
  </array>
41
41
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "1.5.2",
10
+ "version": "1.5.4",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",