@shopify/react-native-skia 2.11.1 → 2.11.2-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/cpp/api/JsiSkFont.h +3 -2
  2. package/cpp/api/recorder/Paint.h +6 -2
  3. package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
  4. package/cpp/dawn/include/dawn/dawn_proc_table.h +330 -0
  5. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
  6. package/cpp/dawn/include/dawn/dawn_version.h +41 -0
  7. package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
  8. package/cpp/dawn/include/dawn/native/D3D12Backend.h +103 -0
  9. package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
  10. package/cpp/dawn/include/dawn/native/DawnNative.h +368 -0
  11. package/cpp/dawn/include/dawn/native/MetalBackend.h +56 -0
  12. package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
  13. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
  14. package/cpp/dawn/include/dawn/native/VulkanBackend.h +183 -0
  15. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
  16. package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
  17. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +207 -0
  18. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
  19. package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
  20. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
  21. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2856 -0
  22. package/cpp/dawn/include/tint/tint.h +91 -0
  23. package/cpp/dawn/include/webgpu/webgpu.h +5029 -0
  24. package/cpp/dawn/include/webgpu/webgpu_cpp.h +10353 -0
  25. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
  26. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +162 -0
  27. package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
  28. package/cpp/jsi/NativeObject.h +50 -32
  29. package/cpp/jsi/RuntimeAwareCache.cpp +1 -0
  30. package/cpp/jsi/RuntimeAwareCache.h +29 -0
  31. package/cpp/rnskia/RNSkManager.cpp +5 -0
  32. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +45 -0
  33. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +360 -0
  34. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +105 -0
  35. package/lib/commonjs/dom/nodes/datatypes/Rect.js +5 -1
  36. package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
  37. package/lib/commonjs/external/reanimated/useVideo.js +8 -2
  38. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  39. package/lib/commonjs/skia/types/JsiInstance.d.ts +1 -0
  40. package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
  41. package/lib/commonjs/sksg/Recorder/DrawingContext.js +10 -5
  42. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  43. package/lib/commonjs/views/SkiaPictureView.web.js +19 -14
  44. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  45. package/lib/module/dom/nodes/datatypes/Rect.js +5 -1
  46. package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
  47. package/lib/module/external/reanimated/useVideo.js +8 -2
  48. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  49. package/lib/module/skia/types/JsiInstance.d.ts +1 -0
  50. package/lib/module/skia/types/JsiInstance.js.map +1 -1
  51. package/lib/module/sksg/Recorder/DrawingContext.js +10 -5
  52. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  53. package/lib/module/views/SkiaPictureView.web.js +19 -14
  54. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  55. package/lib/typescript/src/skia/types/JsiInstance.d.ts +1 -0
  56. package/libs/.graphite +1 -0
  57. package/package.json +6 -6
  58. package/src/dom/nodes/datatypes/Rect.ts +6 -1
  59. package/src/external/reanimated/useVideo.ts +7 -2
  60. package/src/skia/types/JsiInstance.ts +2 -0
  61. package/src/sksg/Recorder/DrawingContext.ts +10 -5
  62. package/src/views/SkiaPictureView.web.tsx +17 -14
@@ -0,0 +1,57 @@
1
+ // Copyright 2023 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifdef __EMSCRIPTEN__
29
+ #error "Do not include this header. Use the headers provided by Emdawnwebgpu instead."
30
+ #endif
31
+
32
+ #ifndef WEBGPU_CPP_CHAINED_STRUCT_H_
33
+ #define WEBGPU_CPP_CHAINED_STRUCT_H_
34
+
35
+ #include <cstddef>
36
+ #include <cstdint>
37
+
38
+ // This header file declares the ChainedStruct structures separately from the WebGPU
39
+ // headers so that dependencies can directly extend structures without including the larger header
40
+ // which exposes capabilities that may require correctly set proc tables.
41
+ namespace wgpu {
42
+
43
+ enum class SType : uint32_t;
44
+
45
+ struct ChainedStruct {
46
+ ChainedStruct const * nextInChain = nullptr;
47
+ SType sType = SType(0u);
48
+ };
49
+
50
+ struct ChainedStructOut {
51
+ ChainedStructOut * nextInChain = nullptr;
52
+ SType sType = SType(0u);
53
+ };
54
+
55
+ } // namespace wgpu}
56
+
57
+ #endif // WEBGPU_CPP_CHAINED_STRUCT_H_
@@ -0,0 +1,162 @@
1
+ // Copyright 2017 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef WEBGPU_ENUM_CLASS_BITMASKS_H_
29
+ #define WEBGPU_ENUM_CLASS_BITMASKS_H_
30
+
31
+ #include <type_traits>
32
+
33
+ // The operators in wgpu:: namespace need be introduced into other namespaces with
34
+ // using-declarations for C++ Argument Dependent Lookup to work.
35
+ #define WGPU_IMPORT_BITMASK_OPERATORS \
36
+ using wgpu::operator|; \
37
+ using wgpu::operator&; \
38
+ using wgpu::operator^; \
39
+ using wgpu::operator~; \
40
+ using wgpu::operator&=; \
41
+ using wgpu::operator|=; \
42
+ using wgpu::operator^=; \
43
+ using wgpu::HasZeroOrOneBits;
44
+
45
+ namespace wgpu {
46
+
47
+ template <typename T>
48
+ struct IsWGPUBitmask {
49
+ static constexpr bool enable = false;
50
+ };
51
+
52
+ template <typename T, typename Enable = void>
53
+ struct LowerBitmask {
54
+ static constexpr bool enable = false;
55
+ };
56
+
57
+ template <typename T>
58
+ struct LowerBitmask<T, typename std::enable_if<IsWGPUBitmask<T>::enable>::type> {
59
+ static constexpr bool enable = true;
60
+ using type = T;
61
+ constexpr static T Lower(T t) { return t; }
62
+ };
63
+
64
+ template <typename T>
65
+ struct BoolConvertible {
66
+ using Integral = typename std::underlying_type<T>::type;
67
+
68
+ explicit constexpr BoolConvertible(Integral value) : value(value) {}
69
+ // NOLINTNEXTLINE(google-explicit-constructor)
70
+ constexpr operator bool() const { return value != 0; }
71
+ // NOLINTNEXTLINE(google-explicit-constructor)
72
+ constexpr operator T() const { return static_cast<T>(value); }
73
+
74
+ Integral value;
75
+ };
76
+
77
+ template <typename T>
78
+ struct LowerBitmask<BoolConvertible<T>> {
79
+ static constexpr bool enable = true;
80
+ using type = T;
81
+ static constexpr type Lower(BoolConvertible<T> t) { return t; }
82
+ };
83
+
84
+ template <
85
+ typename T1,
86
+ typename T2,
87
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
88
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
89
+ using T = typename LowerBitmask<T1>::type;
90
+ using Integral = typename std::underlying_type<T>::type;
91
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
92
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
93
+ }
94
+
95
+ template <
96
+ typename T1,
97
+ typename T2,
98
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
99
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
100
+ using T = typename LowerBitmask<T1>::type;
101
+ using Integral = typename std::underlying_type<T>::type;
102
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
103
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
104
+ }
105
+
106
+ template <
107
+ typename T1,
108
+ typename T2,
109
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
110
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
111
+ using T = typename LowerBitmask<T1>::type;
112
+ using Integral = typename std::underlying_type<T>::type;
113
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
114
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
115
+ }
116
+
117
+ template <typename T1>
118
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
119
+ using T = typename LowerBitmask<T1>::type;
120
+ using Integral = typename std::underlying_type<T>::type;
121
+ return BoolConvertible<T>(~static_cast<Integral>(LowerBitmask<T1>::Lower(t)));
122
+ }
123
+
124
+ template <
125
+ typename T,
126
+ typename T2,
127
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
128
+ constexpr T& operator&=(T& l, T2 right) {
129
+ T r = LowerBitmask<T2>::Lower(right);
130
+ l = l & r;
131
+ return l;
132
+ }
133
+
134
+ template <
135
+ typename T,
136
+ typename T2,
137
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
138
+ constexpr T& operator|=(T& l, T2 right) {
139
+ T r = LowerBitmask<T2>::Lower(right);
140
+ l = l | r;
141
+ return l;
142
+ }
143
+
144
+ template <
145
+ typename T,
146
+ typename T2,
147
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
148
+ constexpr T& operator^=(T& l, T2 right) {
149
+ T r = LowerBitmask<T2>::Lower(right);
150
+ l = l ^ r;
151
+ return l;
152
+ }
153
+
154
+ template <typename T>
155
+ constexpr bool HasZeroOrOneBits(T value) {
156
+ using Integral = typename std::underlying_type<T>::type;
157
+ return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
158
+ }
159
+
160
+ } // namespace wgpu
161
+
162
+ #endif // WEBGPU_ENUM_CLASS_BITMASKS_H_
@@ -0,0 +1,88 @@
1
+ // Copyright 2022 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_WEBGPU_WEBGPU_GLFW_H_
29
+ #define INCLUDE_WEBGPU_WEBGPU_GLFW_H_
30
+
31
+ #ifdef __cplusplus
32
+ #include <memory>
33
+
34
+ #include "webgpu/webgpu_cpp.h"
35
+ #else
36
+ #include "webgpu/webgpu.h"
37
+ #endif
38
+
39
+ #if defined(WGPU_GLFW_SHARED_LIBRARY)
40
+ #if defined(_WIN32)
41
+ #if defined(WGPU_GLFW_IMPLEMENTATION)
42
+ #define WGPU_GLFW_EXPORT __declspec(dllexport)
43
+ #else
44
+ #define WGPU_GLFW_EXPORT __declspec(dllimport)
45
+ #endif
46
+ #else // defined(_WIN32)
47
+ #if defined(WGPU_GLFW_IMPLEMENTATION)
48
+ #define WGPU_GLFW_EXPORT __attribute__((visibility("default")))
49
+ #else
50
+ #define WGPU_GLFW_EXPORT
51
+ #endif
52
+ #endif // defined(_WIN32)
53
+ #else // defined(WGPU_GLFW_SHARED_LIBRARY)
54
+ #define WGPU_GLFW_EXPORT
55
+ #endif // defined(WGPU_GLFW_SHARED_LIBRARY)
56
+
57
+ struct GLFWwindow;
58
+
59
+ #ifdef __cplusplus
60
+ extern "C" {
61
+ #endif
62
+
63
+ WGPU_GLFW_EXPORT WGPUSurface wgpuGlfwCreateSurfaceForWindow(const WGPUInstance instance,
64
+ struct GLFWwindow* window);
65
+
66
+ #ifdef __cplusplus
67
+ }
68
+
69
+ namespace wgpu::glfw {
70
+
71
+ // Does the necessary setup on the GLFWwindow to allow creating a wgpu::Surface with it and
72
+ // calls `instance.CreateSurface` with the correct descriptor for this window.
73
+ // Returns a null wgpu::Surface on failure.
74
+ WGPU_GLFW_EXPORT wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance,
75
+ GLFWwindow* window);
76
+
77
+ // Use for testing only. Does everything that CreateSurfaceForWindow does except the call to
78
+ // CreateSurface. Useful to be able to modify the descriptor for testing, or when trying to
79
+ // avoid using the global proc table.
80
+ // NOLINTNEXTLINE(build/include_what_you_use)
81
+ WGPU_GLFW_EXPORT std::unique_ptr<wgpu::ChainedStruct, void (*)(wgpu::ChainedStruct*)>
82
+ SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window);
83
+
84
+ } // namespace wgpu::glfw
85
+
86
+ #endif
87
+
88
+ #endif // INCLUDE_WEBGPU_WEBGPU_GLFW_H_
@@ -51,26 +51,32 @@ struct PrototypeCacheEntry {
51
51
  *
52
52
  * When used with static storage (like prototype caches), the cache persists
53
53
  * across hot reloads. But the JSI objects inside become invalid when the
54
- * runtime is destroyed. This wrapper tracks which runtime the cache was
55
- * created for and allocates a new cache when the runtime changes.
54
+ * runtime is destroyed. This wrapper tracks which main-runtime generation the
55
+ * cache was created for and allocates a new cache when the native module is
56
+ * reinstalled (RNSkManager construction bumps the generation).
57
+ *
58
+ * The generation is used instead of the runtime pointer on purpose: on an
59
+ * in-process runtime recreate (expo-updates reloadAsync, DevSettings.reload)
60
+ * Hermes frequently allocates the new runtime at the address of the freed
61
+ * one. A pointer comparison then sees "same runtime", keeps the stale cache,
62
+ * and create()/installConstructor() end up passing a jsi::Object owned by the
63
+ * dead runtime to the new one (use-after-free).
56
64
  *
57
65
  * The old cache is intentionally leaked - we cannot safely destroy JSI
58
66
  * objects after their runtime is gone.
59
67
  */
60
68
  template <typename T> struct StaticRuntimeAwareCache {
61
69
  RNJsi::RuntimeAwareCache<T> *cache = nullptr;
62
- jsi::Runtime *cacheRuntime = nullptr;
63
-
64
- RNJsi::RuntimeAwareCache<T> &get(jsi::Runtime &rt) {
65
- auto mainRuntime = RNJsi::BaseRuntimeAwareCache::getMainJsRuntime();
66
- if (&rt == mainRuntime && cacheRuntime != mainRuntime) {
67
- // Main runtime changed (hot reload) - allocate new cache, leak old one
68
- cache = new RNJsi::RuntimeAwareCache<T>();
69
- cacheRuntime = mainRuntime;
70
- }
71
- if (cache == nullptr) {
70
+ uint64_t cacheGeneration = 0;
71
+
72
+ RNJsi::RuntimeAwareCache<T> &get(jsi::Runtime & /*rt*/) {
73
+ auto generation =
74
+ RNJsi::BaseRuntimeAwareCache::getMainJsRuntimeGeneration();
75
+ if (cache == nullptr || cacheGeneration != generation) {
76
+ // First use, or the main runtime was reinstalled (hot reload / OTA):
77
+ // allocate a fresh cache and leak the old one.
72
78
  cache = new RNJsi::RuntimeAwareCache<T>();
73
- cacheRuntime = mainRuntime;
79
+ cacheGeneration = generation;
74
80
  }
75
81
  return *cache;
76
82
  }
@@ -143,9 +149,29 @@ public:
143
149
  */
144
150
  static void installPrototype(jsi::Runtime &runtime) {
145
151
  std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
152
+ ensurePrototypeLocked(runtime);
153
+ }
154
+
155
+ /**
156
+ * Look up (and install on first use) the prototype entry for this runtime.
157
+ *
158
+ * Callers must hold getPrototypeCacheMutex() and must consume the returned
159
+ * entry while still holding it: the lookup and the use of the prototype
160
+ * have to share one lock scope, because a reinstall of the native module
161
+ * (generation bump, see StaticRuntimeAwareCache) can swap the cache from
162
+ * any thread. A caller that released the lock in between would re-resolve
163
+ * a fresh cache with an empty entry and hand out an object without a
164
+ * prototype.
165
+ *
166
+ * The returned reference stays valid for the runtime's lifetime: the
167
+ * RuntimeAwareCache is heap-allocated and never freed, and
168
+ * std::unordered_map keeps references to its elements stable across
169
+ * rehashes.
170
+ */
171
+ static PrototypeCacheEntry &ensurePrototypeLocked(jsi::Runtime &runtime) {
146
172
  auto &entry = getPrototypeCache(runtime).get(runtime);
147
173
  if (entry.prototype.has_value()) {
148
- return; // Already installed
174
+ return entry; // Already installed
149
175
  }
150
176
 
151
177
  // Create prototype object
@@ -264,6 +290,7 @@ public:
264
290
 
265
291
  // Cache the prototype
266
292
  entry.prototype = std::move(prototype);
293
+ return entry;
267
294
  }
268
295
 
269
296
  /**
@@ -274,13 +301,8 @@ public:
274
301
  * created internally by the native code).
275
302
  */
276
303
  static void installConstructor(jsi::Runtime &runtime) {
277
- installPrototype(runtime);
278
-
279
304
  std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
280
- auto &entry = getPrototypeCache(runtime).get(runtime);
281
- if (!entry.prototype.has_value()) {
282
- return;
283
- }
305
+ auto &entry = ensurePrototypeLocked(runtime);
284
306
 
285
307
  // Create a constructor function that throws when called directly
286
308
  auto ctor = jsi::Function::createFromHostFunction(
@@ -308,8 +330,6 @@ public:
308
330
  */
309
331
  static jsi::Value create(jsi::Runtime &runtime,
310
332
  std::shared_ptr<Derived> instance) {
311
- installPrototype(runtime);
312
-
313
333
  // Store creation runtime for logging etc.
314
334
  instance->setCreationRuntime(&runtime);
315
335
 
@@ -319,18 +339,16 @@ public:
319
339
  // Attach native state
320
340
  obj.setNativeState(runtime, instance);
321
341
 
322
- // Set prototype
342
+ // Install (on first use) and apply the prototype in a single lock scope
343
+ // so a concurrent cache swap cannot slip in between the two steps.
323
344
  {
324
345
  std::lock_guard<std::mutex> lock(getPrototypeCacheMutex());
325
- auto &entry = getPrototypeCache(runtime).get(runtime);
326
- if (entry.prototype.has_value()) {
327
- // Use Object.setPrototypeOf to set the prototype
328
- auto objectCtor =
329
- runtime.global().getPropertyAsObject(runtime, "Object");
330
- auto setPrototypeOf =
331
- objectCtor.getPropertyAsFunction(runtime, "setPrototypeOf");
332
- setPrototypeOf.call(runtime, obj, *entry.prototype);
333
- }
346
+ auto &entry = ensurePrototypeLocked(runtime);
347
+ // Use Object.setPrototypeOf to set the prototype
348
+ auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
349
+ auto setPrototypeOf =
350
+ objectCtor.getPropertyAsFunction(runtime, "setPrototypeOf");
351
+ setPrototypeOf.call(runtime, obj, *entry.prototype);
334
352
  }
335
353
 
336
354
  // Set memory pressure hint for GC
@@ -3,5 +3,6 @@
3
3
  namespace RNJsi {
4
4
 
5
5
  std::atomic<jsi::Runtime *> BaseRuntimeAwareCache::_mainRuntime{nullptr};
6
+ std::atomic<uint64_t> BaseRuntimeAwareCache::_mainRuntimeGeneration{0};
6
7
 
7
8
  } // namespace RNJsi
@@ -3,6 +3,7 @@
3
3
  #include <jsi/jsi.h>
4
4
 
5
5
  #include <atomic>
6
+ #include <cstdint>
6
7
  #include <memory>
7
8
  #include <mutex>
8
9
  #include <unordered_map>
@@ -20,6 +21,33 @@ public:
20
21
  // Atomic: hot reload rewrites this from the JS thread while worklet
21
22
  // runtime threads read it concurrently.
22
23
  _mainRuntime.store(rt, std::memory_order_release);
24
+ // Every (re)installation of the native module starts a new generation.
25
+ // Callers that hold process-wide state derived from the main runtime
26
+ // (see StaticRuntimeAwareCache) must key their invalidation on this
27
+ // counter and NOT on the runtime pointer: when the JS runtime is
28
+ // destroyed and recreated in-process (expo-updates OTA apply,
29
+ // DevSettings.reload) the new jsi::Runtime is frequently allocated at
30
+ // the exact address of the freed one, so a pointer comparison cannot
31
+ // tell a reload from the steady state.
32
+ _mainRuntimeGeneration.fetch_add(1, std::memory_order_acq_rel);
33
+ }
34
+ static uint64_t getMainJsRuntimeGeneration() {
35
+ return _mainRuntimeGeneration.load(std::memory_order_acquire);
36
+ }
37
+ /**
38
+ * Called when the main runtime is about to go away (RNSkManager destruction).
39
+ * Bumps the generation so process-wide caches keyed on it
40
+ * (StaticRuntimeAwareCache) stop trusting their contents before the next
41
+ * install(). This closes the window where a runtime allocated at the dead
42
+ * runtime's address would otherwise be taken for the main runtime and be
43
+ * handed the stale jsi::Objects of the previous one.
44
+ *
45
+ * The pointer itself is intentionally left in place: worklet runtime
46
+ * threads may still call getMainJsRuntime() while teardown overlaps, and
47
+ * that accessor asserts on nullptr.
48
+ */
49
+ static void invalidateMainJsRuntime() {
50
+ _mainRuntimeGeneration.fetch_add(1, std::memory_order_acq_rel);
23
51
  }
24
52
  static jsi::Runtime *getMainJsRuntime() {
25
53
  auto *rt = _mainRuntime.load(std::memory_order_acquire);
@@ -31,6 +59,7 @@ public:
31
59
 
32
60
  private:
33
61
  static std::atomic<jsi::Runtime *> _mainRuntime;
62
+ static std::atomic<uint64_t> _mainRuntimeGeneration;
34
63
  };
35
64
 
36
65
  /**
@@ -30,6 +30,11 @@ RNSkManager::RNSkManager(
30
30
  }
31
31
 
32
32
  RNSkManager::~RNSkManager() {
33
+ // The main runtime is going away: key out the process-wide prototype
34
+ // caches now rather than at the next install(), so nothing allocated at
35
+ // this runtime's address in between can be mistaken for it.
36
+ RNJsi::BaseRuntimeAwareCache::invalidateMainJsRuntime();
37
+
33
38
  // Free up any references
34
39
  _viewApi = nullptr;
35
40
  _jsRuntime = nullptr;
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
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 skgpu_graphite_ContextOptionsPriv_DEFINED
9
+ #define skgpu_graphite_ContextOptionsPriv_DEFINED
10
+
11
+ #include "include/private/SkMath.h"
12
+
13
+ #include <optional>
14
+
15
+ namespace skgpu::graphite {
16
+
17
+ enum class PathRendererStrategy;
18
+
19
+ /**
20
+ * Private options that are only meant for testing within Skia's tools.
21
+ */
22
+ struct ContextOptionsPriv {
23
+
24
+ int fMaxTextureSizeOverride = SK_MaxS32;
25
+
26
+ /**
27
+ * If true, will store a pointer in Recorder that points back to the Context
28
+ * that created it. Used by readPixels() and other methods that normally require a Context.
29
+ */
30
+ bool fStoreContextRefInRecorder = false;
31
+
32
+ /**
33
+ * If true, enables layer based draw ordering.
34
+ */
35
+ bool fDrawListLayer = false;
36
+
37
+ /**
38
+ * Override Caps' default strategy heuristics to prioritize this one if set *and* is supported.
39
+ */
40
+ std::optional<PathRendererStrategy> fPathRendererStrategy;
41
+ };
42
+
43
+ } // namespace skgpu::graphite
44
+
45
+ #endif // skgpu_graphite_ContextOptionsPriv_DEFINED