@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,206 +1,206 @@
1
- import hilog from '@ohos.hilog';
2
- import nativeModule from 'libgcanvas.so';
3
-
4
- const TAG = 'GCanvasNativeEngine';
5
- const DOMAIN = 0x0001;
6
-
7
- /**
8
- * GCanvas 原生引擎的 ArkTS 门面(单例)。
9
- *
10
- * 所有 GCanvasModuleTurboModule 的同步/绘制方法都经此转发到 C++ 原生引擎
11
- * (libgcanvas.so,由 NAPI 暴露),由 C++ 内部独立 GL 线程执行命令。
12
- *
13
- * 该门面职责单一:
14
- * 1. 维护 nativeModule 单例(懒加载,避免 HAR 加载期即初始化 .so);
15
- * 2. 将 ArkTS 参数透传给 C++,统一日志与异常隔离(不向 TurboModule 抛异常)。
16
- *
17
- * 真正的 OpenGL ES / EGL / XComponent / 字体 / 命令解析逻辑全部在 C++ 侧(复用 core/src)。
18
- */
19
- export class GCanvasNativeEngine {
20
- private static instance: GCanvasNativeEngine;
21
- private native: GCanvasNativeAPI | null = null;
22
-
23
- private constructor() {
24
- }
25
-
26
- public static getInstance(): GCanvasNativeEngine {
27
- if (!GCanvasNativeEngine.instance) {
28
- GCanvasNativeEngine.instance = new GCanvasNativeEngine();
29
- }
30
- return GCanvasNativeEngine.instance;
31
- }
32
-
33
- private api(): GCanvasNativeAPI {
34
- if (this.native === null) {
35
- const loaded = nativeModule as GCanvasNativeAPI;
36
- if (typeof loaded.enable !== 'function' || typeof loaded.render !== 'function' ||
37
- typeof loaded.extendCallNative !== 'function') {
38
- throw new Error('libgcanvas.so is missing enable/render/extendCallNative');
39
- }
40
- this.native = loaded;
41
- }
42
- return this.native;
43
- }
44
-
45
- /** 注册 XComponent 与 GL 表面(由 Fabric 组件创建后调用,绑定 componentId↔window)。 */
46
- public bindSurface(componentId: string, window: number, width: number, height: number): void {
47
- this.api().bindSurface(componentId, window, width, height);
48
- }
49
-
50
- /** surface 尺寸变化。 */
51
- public surfaceChanged(componentId: string, width: number, height: number): void {
52
- this.api().surfaceChanged(componentId, width, height);
53
- }
54
-
55
- /** surface 销毁。 */
56
- public surfaceDestroyed(componentId: string): void {
57
- this.api().surfaceDestroyed(componentId);
58
- }
59
-
60
- /** Apply native-only view options that are not part of the JS command protocol. */
61
- public configureView(componentId: string, enableFboMsaa: boolean): void {
62
- this.api().configureView(componentId, enableFboMsaa);
63
- }
64
-
65
- /** 启用画布(同步)。config 同 Android enable() 的 configArray。 */
66
- public enable(componentId: string, config: number[]): void {
67
- this.api().enable(componentId, config);
68
- }
69
-
70
- /** 禁用画布。 */
71
- public disable(refId: string): void {
72
- this.api().disable(refId);
73
- }
74
-
75
- /** 异步执行命令字符串(投递到 GL 线程后立即返回)。 */
76
- public render(canvasId: string, cmd: string, type: number): void {
77
- this.api().render(canvasId, cmd, type);
78
- }
79
-
80
- /** 同步执行命令字符串并返回结果(GL 线程阻塞等待)。 */
81
- public extendCallNative(contextId: string, args: string, type: number): string {
82
- return this.api().extendCallNative(contextId, args, type);
83
- }
84
-
85
- /** 设置上下文类型:0=2d, 1=webgl。 */
86
- public setContextType(contextType: number, refId: string): void {
87
- this.api().setContextType(contextType, refId);
88
- }
89
-
90
- public setDevicePixelRatio(refId: string, ratio: number): void {
91
- this.api().setDevicePixelRatio(refId, ratio);
92
- }
93
-
94
- public resetGlViewport(refId: string): void {
95
- this.api().resetGlViewport(refId);
96
- }
97
-
98
- /** 同步导出画布为 data URL。 */
99
- public toDataURL(refId: string, mimeType: string, quality: number): string {
100
- return this.api().toDataURL(refId, mimeType, quality);
101
- }
102
-
103
- public drawCanvas2Canvas(map: DrawCanvas2CanvasMap): void {
104
- this.api().drawCanvas2Canvas(map);
105
- }
106
-
107
- /** 绑定已解码的 RGBA 像素到纹理。 */
108
- public bindImageTexture(refId: string, imageId: number, pixels: ArrayBuffer,
109
- width: number, height: number): void {
110
- this.api().bindImageTexture(refId, imageId, pixels, width, height);
111
- }
112
-
113
- /** Rebind a preloaded native image without decoding it a second time. */
114
- public bindCachedImageTexture(refId: string, imageId: number): boolean {
115
- return this.api().bindCachedImageTexture(refId, imageId);
116
- }
117
-
118
- /** 缓存解码后的图片,供后续纹理上传复用。 */
119
- public cacheImage(id: number, pixels: ArrayBuffer, width: number, height: number): void {
120
- this.api().cacheImage(id, pixels, width, height);
121
- }
122
-
123
- public getDeviceInfo(args: string): string {
124
- return this.api().getDeviceInfo(args);
125
- }
126
-
127
- public addFontFamily(fontNames: string[], fontFiles: string[]): void {
128
- this.api().addFontFamily(fontNames, fontFiles);
129
- }
130
-
131
- public getFontNames(): string[] {
132
- return this.api().getFontNames();
133
- }
134
-
135
- public setExtraFontLocation(location: string): void {
136
- this.api().setExtraFontLocation(location);
137
- }
138
-
139
- public setLogLevel(level: number): void {
140
- this.api().setLogLevel(level);
141
- }
142
-
143
- public resetComponent(refId: string): void {
144
- this.api().resetComponent(refId);
145
- }
146
-
147
- public texImage2D(refId: string, target: number, level: number, internalformat: number,
148
- format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void {
149
- this.api().texImage2D(refId, target, level, internalformat, format, type, pixels, width, height);
150
- }
151
-
152
- public texSubImage2D(refId: string, target: number, level: number, xoffset: number, yoffset: number,
153
- format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void {
154
- this.api().texSubImage2D(refId, target, level, xoffset, yoffset, format, type, pixels, width, height);
155
- }
156
- }
157
-
158
- /**
159
- * C++ 原生引擎(libgcanvas.so)经 NAPI 暴露的接口契约。
160
- * C++ 侧(GCanvasNapi.cpp)须实现下列全部方法。
161
- */
162
- interface GCanvasNativeAPI {
163
- bindSurface(componentId: string, window: number, width: number, height: number): void;
164
- surfaceChanged(componentId: string, width: number, height: number): void;
165
- surfaceDestroyed(componentId: string): void;
166
- configureView(componentId: string, enableFboMsaa: boolean): void;
167
- enable(componentId: string, config: number[]): void;
168
- disable(refId: string): void;
169
- render(canvasId: string, cmd: string, type: number): void;
170
- extendCallNative(contextId: string, args: string, type: number): string;
171
- setContextType(contextType: number, refId: string): void;
172
- setDevicePixelRatio(refId: string, ratio: number): void;
173
- resetGlViewport(refId: string): void;
174
- toDataURL(refId: string, mimeType: string, quality: number): string;
175
- drawCanvas2Canvas(map: DrawCanvas2CanvasMap): void;
176
- bindImageTexture(refId: string, imageId: number, pixels: ArrayBuffer,
177
- width: number, height: number): void;
178
- bindCachedImageTexture(refId: string, imageId: number): boolean;
179
- cacheImage(id: number, pixels: ArrayBuffer, width: number, height: number): void;
180
- getDeviceInfo(args: string): string;
181
- addFontFamily(fontNames: string[], fontFiles: string[]): void;
182
- getFontNames(): string[];
183
- setExtraFontLocation(location: string): void;
184
- setLogLevel(level: number): void;
185
- resetComponent(refId: string): void;
186
- texImage2D(refId: string, target: number, level: number, internalformat: number,
187
- format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void;
188
- texSubImage2D(refId: string, target: number, level: number, xoffset: number, yoffset: number,
189
- format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void;
190
- }
191
-
192
- /** drawCanvas2Canvas 参数(与 GCanvasModuleTurboModule 一致)。 */
193
- interface DrawCanvas2CanvasMap {
194
- srcComponentId: string;
195
- dstComponentId: string;
196
- tw: number;
197
- th: number;
198
- sx: number;
199
- sy: number;
200
- sw: number;
201
- sh: number;
202
- dx: number;
203
- dy: number;
204
- dw: number;
205
- dh: number;
206
- }
1
+ import hilog from '@ohos.hilog';
2
+ import nativeModule from 'libgcanvas.so';
3
+
4
+ const TAG = 'GCanvasNativeEngine';
5
+ const DOMAIN = 0x0001;
6
+
7
+ /**
8
+ * GCanvas 原生引擎的 ArkTS 门面(单例)。
9
+ *
10
+ * 所有 GCanvasModuleTurboModule 的同步/绘制方法都经此转发到 C++ 原生引擎
11
+ * (libgcanvas.so,由 NAPI 暴露),由 C++ 内部独立 GL 线程执行命令。
12
+ *
13
+ * 该门面职责单一:
14
+ * 1. 维护 nativeModule 单例(懒加载,避免 HAR 加载期即初始化 .so);
15
+ * 2. 将 ArkTS 参数透传给 C++,统一日志与异常隔离(不向 TurboModule 抛异常)。
16
+ *
17
+ * 真正的 OpenGL ES / EGL / XComponent / 字体 / 命令解析逻辑全部在 C++ 侧(复用 core/src)。
18
+ */
19
+ export class GCanvasNativeEngine {
20
+ private static instance: GCanvasNativeEngine;
21
+ private native: GCanvasNativeAPI | null = null;
22
+
23
+ private constructor() {
24
+ }
25
+
26
+ public static getInstance(): GCanvasNativeEngine {
27
+ if (!GCanvasNativeEngine.instance) {
28
+ GCanvasNativeEngine.instance = new GCanvasNativeEngine();
29
+ }
30
+ return GCanvasNativeEngine.instance;
31
+ }
32
+
33
+ private api(): GCanvasNativeAPI {
34
+ if (this.native === null) {
35
+ const loaded = nativeModule as GCanvasNativeAPI;
36
+ if (typeof loaded.enable !== 'function' || typeof loaded.render !== 'function' ||
37
+ typeof loaded.extendCallNative !== 'function') {
38
+ throw new Error('libgcanvas.so is missing enable/render/extendCallNative');
39
+ }
40
+ this.native = loaded;
41
+ }
42
+ return this.native;
43
+ }
44
+
45
+ /** 注册 XComponent 与 GL 表面(由 Fabric 组件创建后调用,绑定 componentId↔window)。 */
46
+ public bindSurface(componentId: string, window: number, width: number, height: number): void {
47
+ this.api().bindSurface(componentId, window, width, height);
48
+ }
49
+
50
+ /** surface 尺寸变化。 */
51
+ public surfaceChanged(componentId: string, width: number, height: number): void {
52
+ this.api().surfaceChanged(componentId, width, height);
53
+ }
54
+
55
+ /** surface 销毁。 */
56
+ public surfaceDestroyed(componentId: string): void {
57
+ this.api().surfaceDestroyed(componentId);
58
+ }
59
+
60
+ /** Apply native-only view options that are not part of the JS command protocol. */
61
+ public configureView(componentId: string, enableFboMsaa: boolean): void {
62
+ this.api().configureView(componentId, enableFboMsaa);
63
+ }
64
+
65
+ /** 启用画布(同步)。config 同 Android enable() 的 configArray。 */
66
+ public enable(componentId: string, config: number[]): void {
67
+ this.api().enable(componentId, config);
68
+ }
69
+
70
+ /** 禁用画布。 */
71
+ public disable(refId: string): void {
72
+ this.api().disable(refId);
73
+ }
74
+
75
+ /** 异步执行命令字符串(投递到 GL 线程后立即返回)。 */
76
+ public render(canvasId: string, cmd: string, type: number): void {
77
+ this.api().render(canvasId, cmd, type);
78
+ }
79
+
80
+ /** 同步执行命令字符串并返回结果(GL 线程阻塞等待)。 */
81
+ public extendCallNative(contextId: string, args: string, type: number): string {
82
+ return this.api().extendCallNative(contextId, args, type);
83
+ }
84
+
85
+ /** 设置上下文类型:0=2d, 1=webgl。 */
86
+ public setContextType(contextType: number, refId: string): void {
87
+ this.api().setContextType(contextType, refId);
88
+ }
89
+
90
+ public setDevicePixelRatio(refId: string, ratio: number): void {
91
+ this.api().setDevicePixelRatio(refId, ratio);
92
+ }
93
+
94
+ public resetGlViewport(refId: string): void {
95
+ this.api().resetGlViewport(refId);
96
+ }
97
+
98
+ /** 同步导出画布为 data URL。 */
99
+ public toDataURL(refId: string, mimeType: string, quality: number): string {
100
+ return this.api().toDataURL(refId, mimeType, quality);
101
+ }
102
+
103
+ public drawCanvas2Canvas(map: DrawCanvas2CanvasMap): void {
104
+ this.api().drawCanvas2Canvas(map);
105
+ }
106
+
107
+ /** 绑定已解码的 RGBA 像素到纹理。 */
108
+ public bindImageTexture(refId: string, imageId: number, pixels: ArrayBuffer,
109
+ width: number, height: number): void {
110
+ this.api().bindImageTexture(refId, imageId, pixels, width, height);
111
+ }
112
+
113
+ /** Rebind a preloaded native image without decoding it a second time. */
114
+ public bindCachedImageTexture(refId: string, imageId: number): boolean {
115
+ return this.api().bindCachedImageTexture(refId, imageId);
116
+ }
117
+
118
+ /** 缓存解码后的图片,供后续纹理上传复用。 */
119
+ public cacheImage(id: number, pixels: ArrayBuffer, width: number, height: number): void {
120
+ this.api().cacheImage(id, pixels, width, height);
121
+ }
122
+
123
+ public getDeviceInfo(args: string): string {
124
+ return this.api().getDeviceInfo(args);
125
+ }
126
+
127
+ public addFontFamily(fontNames: string[], fontFiles: string[]): void {
128
+ this.api().addFontFamily(fontNames, fontFiles);
129
+ }
130
+
131
+ public getFontNames(): string[] {
132
+ return this.api().getFontNames();
133
+ }
134
+
135
+ public setExtraFontLocation(location: string): void {
136
+ this.api().setExtraFontLocation(location);
137
+ }
138
+
139
+ public setLogLevel(level: number): void {
140
+ this.api().setLogLevel(level);
141
+ }
142
+
143
+ public resetComponent(refId: string): void {
144
+ this.api().resetComponent(refId);
145
+ }
146
+
147
+ public texImage2D(refId: string, target: number, level: number, internalformat: number,
148
+ format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void {
149
+ this.api().texImage2D(refId, target, level, internalformat, format, type, pixels, width, height);
150
+ }
151
+
152
+ public texSubImage2D(refId: string, target: number, level: number, xoffset: number, yoffset: number,
153
+ format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void {
154
+ this.api().texSubImage2D(refId, target, level, xoffset, yoffset, format, type, pixels, width, height);
155
+ }
156
+ }
157
+
158
+ /**
159
+ * C++ 原生引擎(libgcanvas.so)经 NAPI 暴露的接口契约。
160
+ * C++ 侧(GCanvasNapi.cpp)须实现下列全部方法。
161
+ */
162
+ interface GCanvasNativeAPI {
163
+ bindSurface(componentId: string, window: number, width: number, height: number): void;
164
+ surfaceChanged(componentId: string, width: number, height: number): void;
165
+ surfaceDestroyed(componentId: string): void;
166
+ configureView(componentId: string, enableFboMsaa: boolean): void;
167
+ enable(componentId: string, config: number[]): void;
168
+ disable(refId: string): void;
169
+ render(canvasId: string, cmd: string, type: number): void;
170
+ extendCallNative(contextId: string, args: string, type: number): string;
171
+ setContextType(contextType: number, refId: string): void;
172
+ setDevicePixelRatio(refId: string, ratio: number): void;
173
+ resetGlViewport(refId: string): void;
174
+ toDataURL(refId: string, mimeType: string, quality: number): string;
175
+ drawCanvas2Canvas(map: DrawCanvas2CanvasMap): void;
176
+ bindImageTexture(refId: string, imageId: number, pixels: ArrayBuffer,
177
+ width: number, height: number): void;
178
+ bindCachedImageTexture(refId: string, imageId: number): boolean;
179
+ cacheImage(id: number, pixels: ArrayBuffer, width: number, height: number): void;
180
+ getDeviceInfo(args: string): string;
181
+ addFontFamily(fontNames: string[], fontFiles: string[]): void;
182
+ getFontNames(): string[];
183
+ setExtraFontLocation(location: string): void;
184
+ setLogLevel(level: number): void;
185
+ resetComponent(refId: string): void;
186
+ texImage2D(refId: string, target: number, level: number, internalformat: number,
187
+ format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void;
188
+ texSubImage2D(refId: string, target: number, level: number, xoffset: number, yoffset: number,
189
+ format: number, type: number, pixels: ArrayBuffer, width: number, height: number): void;
190
+ }
191
+
192
+ /** drawCanvas2Canvas 参数(与 GCanvasModuleTurboModule 一致)。 */
193
+ interface DrawCanvas2CanvasMap {
194
+ srcComponentId: string;
195
+ dstComponentId: string;
196
+ tw: number;
197
+ th: number;
198
+ sx: number;
199
+ sy: number;
200
+ sw: number;
201
+ sh: number;
202
+ dx: number;
203
+ dy: number;
204
+ dw: number;
205
+ dh: number;
206
+ }
@@ -1,39 +1,39 @@
1
1
  import { RNOHContext, RNViewBase } from '@rnoh/react-native-openharmony';
2
2
  import { GCanvasView as Spec } from '../generated/components/GCanvasView';
3
3
  import { GCanvasNativeEngine } from '../GCanvasNativeEngine';
4
-
5
- /**
6
- * GCanvasView — Fabric 组件(鸿蒙)。
7
- *
8
- * 对齐 Android GReactTextureView(GCanvasView)+ iOS RCTGCanvasView(GLKView)。
9
- * 内嵌 ArkUI XComponent(type: SURFACE, libraryname: 'gcanvas'),由 C++ 侧
10
- * GCanvasXComponent.cpp 的 OH_NativeXComponent 回调拿到 OHNativeWindow*,
11
- * 直接 eglCreateWindowSurface 建立 GL 表面并交 GCanvas 引擎渲染。
12
- *
13
- * 事件(与 codegen EventPayloadByName 一致):
14
- * - change:复刻 Android topChange,payload { value }。
15
- * - isReady:GL 表面就绪/销毁,payload { isReady },对齐 Android GReactViewEvent。
16
- *
4
+
5
+ /**
6
+ * GCanvasView — Fabric 组件(鸿蒙)。
7
+ *
8
+ * 对齐 Android GReactTextureView(GCanvasView)+ iOS RCTGCanvasView(GLKView)。
9
+ * 内嵌 ArkUI XComponent(type: SURFACE, libraryname: 'gcanvas'),由 C++ 侧
10
+ * GCanvasXComponent.cpp 的 OH_NativeXComponent 回调拿到 OHNativeWindow*,
11
+ * 直接 eglCreateWindowSurface 建立 GL 表面并交 GCanvas 引擎渲染。
12
+ *
13
+ * 事件(与 codegen EventPayloadByName 一致):
14
+ * - change:复刻 Android topChange,payload { value }。
15
+ * - isReady:GL 表面就绪/销毁,payload { isReady },对齐 Android GReactViewEvent。
16
+ *
17
17
  * props(subscribeToDescriptorChanges 订阅):
18
18
  * - isEnableFboMsaa / devicePixelRatio 透传至 C++ 引擎;
19
19
  * - isOffscreen / disableAutoSwap 保留给上游 JS 画布调度语义。
20
- *
21
- * 说明:XComponent 的 surface 生命周期回调在 C++(NDK)侧触发(因 libraryname),
20
+ *
21
+ * 说明:XComponent 的 surface 生命周期回调在 C++(NDK)侧触发(因 libraryname),
22
22
  * ArkTS 侧不需 XComponentController;就绪事件由 XComponent 生命周期上抛。
23
- */
24
- @Component
25
- export struct GCanvasView {
26
- public static readonly NAME = Spec.NAME;
27
- public ctx!: RNOHContext;
28
- public tag: number = 0;
29
-
30
- // @State:build() 中引用、驱动渲染的属性。
23
+ */
24
+ @Component
25
+ export struct GCanvasView {
26
+ public static readonly NAME = Spec.NAME;
27
+ public ctx!: RNOHContext;
28
+ public tag: number = 0;
29
+
30
+ // @State:build() 中引用、驱动渲染的属性。
31
31
  @State private isEnableFboMsaa: boolean = true;
32
- @State private isOffscreen: boolean = false;
33
- @State private devicePixelRatio: number = 1;
34
- @State private disableAutoSwap: boolean = false;
35
- @State private componentId: string = '';
36
-
32
+ @State private isOffscreen: boolean = false;
33
+ @State private devicePixelRatio: number = 1;
34
+ @State private disableAutoSwap: boolean = false;
35
+ @State private componentId: string = '';
36
+
37
37
  private eventEmitter: Spec.EventEmitter | undefined = undefined;
38
38
  private cleanUpCallbacks: (() => void)[] = [];
39
39
  private surfaceLoaded: boolean = false;
@@ -43,20 +43,20 @@ export struct GCanvasView {
43
43
  engine.configureView(this.componentId, this.isEnableFboMsaa);
44
44
  engine.setDevicePixelRatio(this.componentId, this.devicePixelRatio);
45
45
  }
46
-
47
- aboutToAppear(): void {
48
- // componentId 用 tag 字符串(与 JS 侧 findNodeHandle 一致),供 C++ surface 关联。
49
- this.componentId = this.tag.toString();
50
-
51
- this.eventEmitter = new Spec.EventEmitter(this.ctx.rnInstance, this.tag);
52
-
53
- // 订阅 props 变化(RNOH Fabric 唯一正确的 props 读取方式)。
54
- // listener 形参用 RNOH 通用 Descriptor 类型(见 RNSwitch.ets 写法),内部 as 转为本组件 Descriptor。
55
- this.cleanUpCallbacks.push(
56
- this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (newDescriptor) => {
57
- const descriptor = newDescriptor as Spec.Descriptor;
58
- const rawProps = descriptor.rawProps as Spec.RawProps;
59
- if (rawProps) {
46
+
47
+ aboutToAppear(): void {
48
+ // componentId 用 tag 字符串(与 JS 侧 findNodeHandle 一致),供 C++ surface 关联。
49
+ this.componentId = this.tag.toString();
50
+
51
+ this.eventEmitter = new Spec.EventEmitter(this.ctx.rnInstance, this.tag);
52
+
53
+ // 订阅 props 变化(RNOH Fabric 唯一正确的 props 读取方式)。
54
+ // listener 形参用 RNOH 通用 Descriptor 类型(见 RNSwitch.ets 写法),内部 as 转为本组件 Descriptor。
55
+ this.cleanUpCallbacks.push(
56
+ this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (newDescriptor) => {
57
+ const descriptor = newDescriptor as Spec.Descriptor;
58
+ const rawProps = descriptor.rawProps as Spec.RawProps;
59
+ if (rawProps) {
60
60
  this.isEnableFboMsaa = rawProps.isEnableFboMsaa ?? true;
61
61
  this.isOffscreen = rawProps.isOffscreen ?? false;
62
62
  this.devicePixelRatio = rawProps.devicePixelRatio ?? 1;
@@ -65,28 +65,28 @@ export struct GCanvasView {
65
65
  this.applyNativeConfiguration();
66
66
  }
67
67
  }
68
- })
69
- );
70
- }
71
-
72
- aboutToDisappear(): void {
68
+ })
69
+ );
70
+ }
71
+
72
+ aboutToDisappear(): void {
73
73
  // 清理所有订阅,避免内存泄漏与重复订阅。
74
74
  this.cleanUpCallbacks.forEach(cb => cb());
75
75
  this.cleanUpCallbacks = [];
76
76
  this.eventEmitter = undefined;
77
- }
78
-
79
- build() {
80
- // 叶子组件必须用 RNViewBase 包裹(RNOH 框架要求)。
81
- RNViewBase({ ctx: this.ctx, tag: this.tag }) {
82
- // XComponent(SURFACE) 由 libraryname='gcanvas' 加载 C++ .so,
83
- // OnSurfaceCreated 的 void* window 即 OHNativeWindow*,直接建 EGL surface。
84
- XComponent({
85
- id: this.componentId,
86
- type: XComponentType.SURFACE,
87
- libraryname: 'gcanvas',
88
- })
89
- .width('100%')
77
+ }
78
+
79
+ build() {
80
+ // 叶子组件必须用 RNViewBase 包裹(RNOH 框架要求)。
81
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
82
+ // XComponent(SURFACE) 由 libraryname='gcanvas' 加载 C++ .so,
83
+ // OnSurfaceCreated 的 void* window 即 OHNativeWindow*,直接建 EGL surface。
84
+ XComponent({
85
+ id: this.componentId,
86
+ type: XComponentType.SURFACE,
87
+ libraryname: 'gcanvas',
88
+ })
89
+ .width('100%')
90
90
  .height('100%')
91
91
  .onLoad(() => {
92
92
  this.surfaceLoaded = true;
@@ -103,7 +103,7 @@ export struct GCanvasView {
103
103
  this.eventEmitter.emit('change', { value: false });
104
104
  this.eventEmitter.emit('isReady', { isReady: false });
105
105
  }
106
- })
107
- }
108
- }
109
- }
106
+ })
107
+ }
108
+ }
109
+ }
@@ -1,21 +1,21 @@
1
- {
2
- "module": {
3
- "name": "gcanvas",
4
- "type": "har",
5
- "deviceTypes": [
6
- "default",
7
- "tablet",
8
- "2in1"
9
- ],
10
- "requestPermissions": [
11
- {
12
- "name": "ohos.permission.INTERNET",
13
- "reason": "$string:reason_internet",
14
- "usedScene": {
15
- "abilities": [],
16
- "when": "always"
17
- }
18
- }
19
- ]
20
- }
21
- }
1
+ {
2
+ "module": {
3
+ "name": "gcanvas",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ "default",
7
+ "tablet",
8
+ "2in1"
9
+ ],
10
+ "requestPermissions": [
11
+ {
12
+ "name": "ohos.permission.INTERNET",
13
+ "reason": "$string:reason_internet",
14
+ "usedScene": {
15
+ "abilities": [],
16
+ "when": "always"
17
+ }
18
+ }
19
+ ]
20
+ }
21
+ }
@@ -1,12 +1,12 @@
1
- {
2
- "string": [
3
- {
4
- "name": "page_show",
5
- "value": "page from npm package"
6
- },
7
- {
8
- "name": "reason_internet",
9
- "value": "Used to download remote images for canvas texture binding"
10
- }
11
- ]
12
- }
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ },
7
+ {
8
+ "name": "reason_internet",
9
+ "value": "Used to download remote images for canvas texture binding"
10
+ }
11
+ ]
12
+ }
@@ -1,8 +1,8 @@
1
- {
2
- "string": [
3
- {
4
- "name": "page_show",
5
- "value": "page from npm package"
6
- }
7
- ]
8
- }
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }