@hxa-rn/react-native-gcanvas 6.0.24-beta.1 → 6.0.26

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 (86) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/LICENSE +203 -21
  3. package/README.md +207 -207
  4. package/harmony/gcanvas/LICENSE +203 -21
  5. package/harmony/gcanvas/NOTICE +32 -32
  6. package/harmony/gcanvas/OAT.xml +37 -37
  7. package/harmony/gcanvas/build-profile.json5 +16 -16
  8. package/harmony/gcanvas/hvigorfile.ts +1 -1
  9. package/harmony/gcanvas/index.ets +1 -1
  10. package/harmony/gcanvas/oh-package.json5 +14 -14
  11. package/harmony/gcanvas/src/main/cpp/CMakeLists.txt +126 -126
  12. package/harmony/gcanvas/src/main/cpp/GCanvasNapi.cpp +485 -485
  13. package/harmony/gcanvas/src/main/cpp/GCanvasXComponent.cpp +106 -106
  14. package/harmony/gcanvas/src/main/cpp/GcanvasPackage.h +24 -24
  15. package/harmony/gcanvas/src/main/ets/GCanvasModuleTurboModule.ts +448 -448
  16. package/harmony/gcanvas/src/main/ets/GCanvasNativeEngine.ts +206 -206
  17. package/harmony/gcanvas/src/main/ets/components/GCanvasView.ets +64 -64
  18. package/harmony/gcanvas/src/main/module.json5 +21 -21
  19. package/harmony/gcanvas/src/main/resources/base/element/string.json +12 -12
  20. package/harmony/gcanvas/src/main/resources/en_US/element/string.json +8 -8
  21. package/harmony/gcanvas/src/main/resources/zh_CN/element/string.json +12 -12
  22. package/harmony/gcanvas.har +0 -0
  23. package/package.json +4 -4
  24. package/packages/gcanvas/.babelrc +4 -4
  25. package/packages/gcanvas/.eslintrc.js +133 -133
  26. package/packages/gcanvas/package.json +19 -19
  27. package/packages/gcanvas/rollup.config.js +13 -13
  28. package/packages/gcanvas/src/bridge/react-native.js +286 -286
  29. package/packages/gcanvas/src/bridge/weex.js +210 -210
  30. package/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
  31. package/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
  32. package/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
  33. package/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
  34. package/packages/gcanvas/src/context/2d/RenderingContext.js +787 -787
  35. package/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
  36. package/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
  37. package/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
  38. package/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
  39. package/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
  40. package/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
  41. package/packages/gcanvas/src/context/webgl/Program.js +20 -20
  42. package/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
  43. package/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
  44. package/packages/gcanvas/src/context/webgl/Shader.js +21 -21
  45. package/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
  46. package/packages/gcanvas/src/context/webgl/Texture.js +21 -21
  47. package/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
  48. package/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
  49. package/packages/gcanvas/src/env/canvas.js +210 -210
  50. package/packages/gcanvas/src/env/image.js +76 -76
  51. package/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
  52. package/packages/gcanvas/src/index.js +56 -56
  53. package/src/components/CanvasView.js +20 -20
  54. package/src/components/GCanvasComponent.js +408 -408
  55. package/src/index.js +69 -69
  56. package/src/packages/gcanvas/.babelrc +4 -4
  57. package/src/packages/gcanvas/.eslintrc.js +133 -133
  58. package/src/packages/gcanvas/package.json +19 -19
  59. package/src/packages/gcanvas/rollup.config.js +13 -13
  60. package/src/packages/gcanvas/src/bridge/react-native.js +288 -288
  61. package/src/packages/gcanvas/src/bridge/weex.js +210 -210
  62. package/src/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
  63. package/src/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
  64. package/src/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
  65. package/src/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
  66. package/src/packages/gcanvas/src/context/2d/RenderingContext.js +801 -801
  67. package/src/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
  68. package/src/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
  69. package/src/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
  70. package/src/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
  71. package/src/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
  72. package/src/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
  73. package/src/packages/gcanvas/src/context/webgl/Program.js +20 -20
  74. package/src/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
  75. package/src/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
  76. package/src/packages/gcanvas/src/context/webgl/Shader.js +21 -21
  77. package/src/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
  78. package/src/packages/gcanvas/src/context/webgl/Texture.js +21 -21
  79. package/src/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
  80. package/src/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
  81. package/src/packages/gcanvas/src/env/canvas.js +210 -210
  82. package/src/packages/gcanvas/src/env/image.js +76 -76
  83. package/src/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
  84. package/src/packages/gcanvas/src/index.js +56 -56
  85. package/src/specs/v1/GCanvasViewNativeComponent.ts +42 -42
  86. package/src/specs/v1/NativeGCanvasModule.ts +140 -140
@@ -1,16 +1,16 @@
1
- /**
2
- * GCanvasXComponent — XComponent(SURFACE) 与 C++ 引擎的桥接入口。
3
- *
4
- * 机制(已通过 SDK 文档核实):
5
- * - ArkTS 侧 XComponent({ id, type: XComponentType.SURFACE, libraryname: 'gcanvas' });
6
- * - 框架加载 libraryname 指向的 .so,调用其 nm_register_func(Init);
7
- * - Init 中从 exports 的 OH_NATIVE_XCOMPONENT_OBJ("__NATIVE_XCOMPONENT_OBJ__")属性
8
- * 经 napi_unwrap 取得 OH_NativeXComponent*;
9
- * - 注册 OH_NativeXComponent_Callback,OnSurfaceCreated 的 void* window 即
10
- * OHNativeWindow*(= EGLNativeWindowType),可直接 eglCreateWindowSurface。
11
- *
12
- * nm_modname 必须与 ArkTS libraryname('gcanvas')完全一致。
13
- */
1
+ /**
2
+ * GCanvasXComponent — XComponent(SURFACE) 与 C++ 引擎的桥接入口。
3
+ *
4
+ * 机制(已通过 SDK 文档核实):
5
+ * - ArkTS 侧 XComponent({ id, type: XComponentType.SURFACE, libraryname: 'gcanvas' });
6
+ * - 框架加载 libraryname 指向的 .so,调用其 nm_register_func(Init);
7
+ * - Init 中从 exports 的 OH_NATIVE_XCOMPONENT_OBJ("__NATIVE_XCOMPONENT_OBJ__")属性
8
+ * 经 napi_unwrap 取得 OH_NativeXComponent*;
9
+ * - 注册 OH_NativeXComponent_Callback,OnSurfaceCreated 的 void* window 即
10
+ * OHNativeWindow*(= EGLNativeWindowType),可直接 eglCreateWindowSurface。
11
+ *
12
+ * nm_modname 必须与 ArkTS libraryname('gcanvas')完全一致。
13
+ */
14
14
  #include "GCanvasEngine.h"
15
15
 
16
16
  #include <ace/xcomponent/native_interface_xcomponent.h>
@@ -18,31 +18,31 @@
18
18
  #include <napi/native_api.h>
19
19
  #include <native_buffer/native_buffer.h>
20
20
  #include <native_window/external_window.h>
21
-
22
- #include <cstring>
23
- #include <mutex>
24
- #include <string>
25
- #include <unordered_map>
26
-
21
+
22
+ #include <cstring>
23
+ #include <mutex>
24
+ #include <string>
25
+ #include <unordered_map>
26
+
27
27
  #define GC_LOGI(...) OH_LOG_INFO(LOG_APP, __VA_ARGS__)
28
28
  #define GC_LOGE(...) OH_LOG_ERROR(LOG_APP, __VA_ARGS__)
29
29
 
30
30
  extern "C" napi_value GCanvasNapi_Init(napi_env env, napi_value exports);
31
-
32
- namespace {
33
-
34
- // 记录 OH_NativeXComponent* → componentId(由 OH_NativeXComponent_GetXComponentId 取得)。
35
- std::unordered_map<OH_NativeXComponent *, std::string> g_componentIds;
36
- std::mutex g_idMutex;
37
-
31
+
32
+ namespace {
33
+
34
+ // 记录 OH_NativeXComponent* → componentId(由 OH_NativeXComponent_GetXComponentId 取得)。
35
+ std::unordered_map<OH_NativeXComponent *, std::string> g_componentIds;
36
+ std::mutex g_idMutex;
37
+
38
38
  std::string GetId(OH_NativeXComponent *component) {
39
- char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'};
40
- uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
41
- int32_t ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
42
- if (ret != 0) {
43
- return "";
44
- }
45
- return std::string(idStr);
39
+ char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'};
40
+ uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
41
+ int32_t ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
42
+ if (ret != 0) {
43
+ return "";
44
+ }
45
+ return std::string(idStr);
46
46
  }
47
47
 
48
48
  bool GetSurfaceSize(OH_NativeXComponent *component, void *window, uint64_t &width, uint64_t &height) {
@@ -52,16 +52,16 @@ bool GetSurfaceSize(OH_NativeXComponent *component, void *window, uint64_t &widt
52
52
  OH_NativeXComponent_GetXComponentSize(component, window, &width, &height) ==
53
53
  OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
54
54
  }
55
-
56
- void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) {
57
- std::string id;
58
- {
59
- std::lock_guard<std::mutex> lock(g_idMutex);
60
- auto it = g_componentIds.find(component);
61
- id = it != g_componentIds.end() ? it->second : GetId(component);
62
- if (it == g_componentIds.end() && !id.empty()) {
63
- g_componentIds[component] = id;
64
- }
55
+
56
+ void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) {
57
+ std::string id;
58
+ {
59
+ std::lock_guard<std::mutex> lock(g_idMutex);
60
+ auto it = g_componentIds.find(component);
61
+ id = it != g_componentIds.end() ? it->second : GetId(component);
62
+ if (it == g_componentIds.end() && !id.empty()) {
63
+ g_componentIds[component] = id;
64
+ }
65
65
  }
66
66
  GC_LOGI("OnSurfaceCreatedCB id=%{public}s window=%{public}p", id.c_str(), window);
67
67
  uint64_t width = 0;
@@ -78,13 +78,13 @@ void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) {
78
78
  }
79
79
  gcanvas::GCanvasEngine::Instance().OnSurfaceCreated(id, window, width, height);
80
80
  }
81
-
82
- void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {
83
- std::string id;
84
- {
85
- std::lock_guard<std::mutex> lock(g_idMutex);
86
- auto it = g_componentIds.find(component);
87
- id = it != g_componentIds.end() ? it->second : GetId(component);
81
+
82
+ void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {
83
+ std::string id;
84
+ {
85
+ std::lock_guard<std::mutex> lock(g_idMutex);
86
+ auto it = g_componentIds.find(component);
87
+ id = it != g_componentIds.end() ? it->second : GetId(component);
88
88
  }
89
89
  GC_LOGI("OnSurfaceChangedCB id=%{public}s", id.c_str());
90
90
  uint64_t width = 0;
@@ -93,13 +93,13 @@ void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {
93
93
  gcanvas::GCanvasEngine::Instance().OnSurfaceChanged(id, window, width, height);
94
94
  }
95
95
  }
96
-
97
- void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {
98
- std::string id;
99
- {
100
- std::lock_guard<std::mutex> lock(g_idMutex);
101
- auto it = g_componentIds.find(component);
102
- id = it != g_componentIds.end() ? it->second : GetId(component);
96
+
97
+ void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {
98
+ std::string id;
99
+ {
100
+ std::lock_guard<std::mutex> lock(g_idMutex);
101
+ auto it = g_componentIds.find(component);
102
+ id = it != g_componentIds.end() ? it->second : GetId(component);
103
103
  }
104
104
  GC_LOGI("OnSurfaceDestroyedCB id=%{public}s", id.c_str());
105
105
  gcanvas::GCanvasEngine::Instance().OnSurfaceDestroyed(id);
@@ -107,38 +107,38 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {
107
107
  std::lock_guard<std::mutex> lock(g_idMutex);
108
108
  g_componentIds.erase(component);
109
109
  }
110
- (void)window;
111
- }
112
-
113
- void DispatchTouchEventCB(OH_NativeXComponent *component, void *window) {
114
- // 触摸事件:JS 侧 GCanvasComponent.js 的 PanResponder 已处理手势分发,
115
- // 底层 XComponent DispatchTouchEvent 在此透传(如需原生手势可扩展)。
116
- (void)component;
117
- (void)window;
118
- }
119
-
120
- void RegisterCallbackFor(OH_NativeXComponent *nativeXComponent) {
121
- std::string id = GetId(nativeXComponent);
122
- if (!id.empty()) {
123
- std::lock_guard<std::mutex> lock(g_idMutex);
124
- g_componentIds[nativeXComponent] = id;
125
- }
126
- static OH_NativeXComponent_Callback callback = {};
127
- callback.OnSurfaceCreated = OnSurfaceCreatedCB;
128
- callback.OnSurfaceChanged = OnSurfaceChangedCB;
129
- callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
130
- callback.DispatchTouchEvent = DispatchTouchEventCB;
131
- int32_t ret = OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback);
132
- GC_LOGI("RegisterCallback ret=%{public}d id=%{public}s", ret, id.c_str());
133
- }
134
-
135
- napi_value Init(napi_env env, napi_value exports) {
136
- GC_LOGI("GCanvasXComponent Init");
137
- napi_value exportInstance = nullptr;
138
- napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
139
-
140
- OH_NativeXComponent *nativeXComponent = nullptr;
141
- napi_unwrap(env, exportInstance, reinterpret_cast<void **>(&nativeXComponent));
110
+ (void)window;
111
+ }
112
+
113
+ void DispatchTouchEventCB(OH_NativeXComponent *component, void *window) {
114
+ // 触摸事件:JS 侧 GCanvasComponent.js 的 PanResponder 已处理手势分发,
115
+ // 底层 XComponent DispatchTouchEvent 在此透传(如需原生手势可扩展)。
116
+ (void)component;
117
+ (void)window;
118
+ }
119
+
120
+ void RegisterCallbackFor(OH_NativeXComponent *nativeXComponent) {
121
+ std::string id = GetId(nativeXComponent);
122
+ if (!id.empty()) {
123
+ std::lock_guard<std::mutex> lock(g_idMutex);
124
+ g_componentIds[nativeXComponent] = id;
125
+ }
126
+ static OH_NativeXComponent_Callback callback = {};
127
+ callback.OnSurfaceCreated = OnSurfaceCreatedCB;
128
+ callback.OnSurfaceChanged = OnSurfaceChangedCB;
129
+ callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
130
+ callback.DispatchTouchEvent = DispatchTouchEventCB;
131
+ int32_t ret = OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback);
132
+ GC_LOGI("RegisterCallback ret=%{public}d id=%{public}s", ret, id.c_str());
133
+ }
134
+
135
+ napi_value Init(napi_env env, napi_value exports) {
136
+ GC_LOGI("GCanvasXComponent Init");
137
+ napi_value exportInstance = nullptr;
138
+ napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
139
+
140
+ OH_NativeXComponent *nativeXComponent = nullptr;
141
+ napi_unwrap(env, exportInstance, reinterpret_cast<void **>(&nativeXComponent));
142
142
  if (nativeXComponent != nullptr) {
143
143
  RegisterCallbackFor(nativeXComponent);
144
144
  }
@@ -147,20 +147,20 @@ napi_value Init(napi_env env, napi_value exports) {
147
147
  // callable API for GCanvasNativeEngine.
148
148
  return GCanvasNapi_Init(env, exports);
149
149
  }
150
-
151
- } // namespace
152
-
153
- // .so 入口:nm_modname 必须等于 ArkTS libraryname 'gcanvas'。
154
- static napi_module gcanvasModule = {
155
- .nm_version = 1,
156
- .nm_flags = 0,
157
- .nm_filename = nullptr,
158
- .nm_register_func = Init,
159
- .nm_modname = "gcanvas",
160
- .nm_priv = nullptr,
161
- .reserved = {0},
162
- };
163
-
164
- extern "C" __attribute__((constructor)) void RegisterGCanvasModule(void) {
165
- napi_module_register(&gcanvasModule);
166
- }
150
+
151
+ } // namespace
152
+
153
+ // .so 入口:nm_modname 必须等于 ArkTS libraryname 'gcanvas'。
154
+ static napi_module gcanvasModule = {
155
+ .nm_version = 1,
156
+ .nm_flags = 0,
157
+ .nm_filename = nullptr,
158
+ .nm_register_func = Init,
159
+ .nm_modname = "gcanvas",
160
+ .nm_priv = nullptr,
161
+ .reserved = {0},
162
+ };
163
+
164
+ extern "C" __attribute__((constructor)) void RegisterGCanvasModule(void) {
165
+ napi_module_register(&gcanvasModule);
166
+ }
@@ -1,24 +1,24 @@
1
- #ifndef GCANVASPACKAGE_H
2
- #define GCANVASPACKAGE_H
3
- #pragma once
4
-
5
- // GCanvas 鸿蒙 C++ Package。
6
- //
7
- // 必须继承 BaseGcanvasPackage,才能把 GCanvasView 的 Fabric descriptor / JSIBinder
8
- // 注册进 UIManager;空 binder 会在 JS 侧变成
9
- // requireNativeComponent: "GCanvasView" was not found in the UIManager。
10
- //
11
- // 本头做成 header-only:构造在宿主 entry 的 rnoh_app(PackageProvider)里实例化,
12
- // Fabric 模板与 ViewProps/Yoga vtable 也在 rnoh_app 里解析。不要再写
13
- // GcanvasPackage.cpp 编进独立 libgcanvas.so,否则会因缺 Fabric 符号链接失败。
14
- #include "RNOH/generated/BaseGcanvasPackage.h"
15
-
16
- namespace rnoh {
17
-
18
- class GcanvasPackage : public BaseGcanvasPackage {
19
- public:
20
- explicit GcanvasPackage(Package::Context ctx) : BaseGcanvasPackage(ctx) {}
21
- };
22
-
23
- } // namespace rnoh
24
- #endif // GCANVASPACKAGE_H
1
+ #ifndef GCANVASPACKAGE_H
2
+ #define GCANVASPACKAGE_H
3
+ #pragma once
4
+
5
+ // GCanvas 鸿蒙 C++ Package。
6
+ //
7
+ // 必须继承 BaseGcanvasPackage,才能把 GCanvasView 的 Fabric descriptor / JSIBinder
8
+ // 注册进 UIManager;空 binder 会在 JS 侧变成
9
+ // requireNativeComponent: "GCanvasView" was not found in the UIManager。
10
+ //
11
+ // 本头做成 header-only:构造在宿主 entry 的 rnoh_app(PackageProvider)里实例化,
12
+ // Fabric 模板与 ViewProps/Yoga vtable 也在 rnoh_app 里解析。不要再写
13
+ // GcanvasPackage.cpp 编进独立 libgcanvas.so,否则会因缺 Fabric 符号链接失败。
14
+ #include "RNOH/generated/BaseGcanvasPackage.h"
15
+
16
+ namespace rnoh {
17
+
18
+ class GcanvasPackage : public BaseGcanvasPackage {
19
+ public:
20
+ explicit GcanvasPackage(Package::Context ctx) : BaseGcanvasPackage(ctx) {}
21
+ };
22
+
23
+ } // namespace rnoh
24
+ #endif // GCANVASPACKAGE_H