1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "napi/native_api.h"
17 #include <EGL/egl.h>
18 #include <EGL/eglext.h>
19 #include <GLES3/gl32.h>
20 #include <bits/alltypes.h>
21 #include <cstring>
22 #include <native_buffer/native_buffer.h>
23 #include <native_image/native_image.h>
24 #include <native_window/external_window.h>
25 #include <sys/mman.h>
26 #include <chrono>
27
28 #define SUCCESS 0
29 #define PARAM_0 0
30 #define PARAM_8 8
31 #define PARAM_1 1
32 #define PARAM_16 16
33 #define PARAM_800 800
34 #define PARAM_600 600
35 #define FAIL (-1)
36 #define ONEVAL 1
37 #define NUMMAX 16
38 #define TWOVAL 2
39 #define ARR_NUMBER_0 0
40 #define ARR_NUMBER_1 1
41 #define ARR_NUMBER_2 2
42 #define ARR_NUMBER_3 3
43 #define ARR_NUMBER_4 4
44 #define NUMBER_99999 99999
45 #define NUMBER_500 500
46
47 using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
48 constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
49 constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
50 constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
51 constexpr char CHARACTER_WHITESPACE = ' ';
52 constexpr const char *CHARACTER_STRING_WHITESPACE = " ";
53 constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
54 EGLContext eglContext_ = EGL_NO_CONTEXT;
55 EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
56 static inline EGLConfig config_;
57
CheckEglExtension(const char *extensions, const char *extension)58 static bool CheckEglExtension(const char *extensions, const char *extension)
59 {
60 size_t extlen = strlen(extension);
61 const char *end = extensions + strlen(extensions);
62
63 while (extensions < end) {
64 size_t n = PARAM_0;
65 if (*extensions == CHARACTER_WHITESPACE) {
66 extensions++;
67 continue;
68 }
69 n = strcspn(extensions, CHARACTER_STRING_WHITESPACE);
70 if (n == extlen && strncmp(extension, extensions, n) == PARAM_0) {
71 return true;
72 }
73 extensions += n;
74 }
75 return false;
76 }
77
GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list)78 static EGLDisplay GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list)
79 {
80 static GetPlatformDisplayExt eglGetPlatformDisplayExt = nullptr;
81
82 if (!eglGetPlatformDisplayExt) {
83 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
84 if (extensions && (CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) ||
85 CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) {
86 eglGetPlatformDisplayExt = (GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT);
87 }
88 }
89
90 if (eglGetPlatformDisplayExt) {
91 return eglGetPlatformDisplayExt(platform, native_display, attrib_list);
92 }
93
94 return eglGetDisplay((EGLNativeDisplayType)native_display);
95 }
96
InitEGLEnv()97 static void InitEGLEnv()
98 {
99 eglDisplay_ = GetPlatformEglDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, nullptr);
100 EGLint major, minor;
101 eglInitialize(eglDisplay_, &major, &minor);
102 eglBindAPI(EGL_OPENGL_ES_API);
103 unsigned int ret;
104 EGLint count;
105 EGLint config_attribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, PARAM_8,
106 EGL_GREEN_SIZE, PARAM_8, EGL_BLUE_SIZE, PARAM_8,
107 EGL_ALPHA_SIZE, PARAM_8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
108 EGL_NONE};
109
110 ret = eglChooseConfig(eglDisplay_, config_attribs, &config_, PARAM_1, &count);
111 static const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE};
112 eglContext_ = eglCreateContext(eglDisplay_, config_, EGL_NO_CONTEXT, context_attribs);
113 eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext_);
114 }
115
getNativeImage()116 static OH_NativeImage *getNativeImage()
117 {
118 GLuint textureId = SUCCESS;
119 glGenTextures(ONEVAL, &textureId);
120 OH_NativeImage *image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
121 return image;
122 }
123
OHNativeImageCreate(napi_env env, napi_callback_info info)124 static napi_value OHNativeImageCreate(napi_env env, napi_callback_info info)
125 {
126 napi_value result = nullptr;
127 OH_NativeImage *image = getNativeImage();
128 int backInfo = FAIL;
129 if (image != nullptr) {
130 backInfo = SUCCESS;
131 OH_NativeImage_Destroy(&image);
132 }
133
134 napi_create_int32(env, backInfo, &result);
135 return result;
136 }
137
OHNativeImageAcquireNativeWindow(napi_env env, napi_callback_info info)138 static napi_value OHNativeImageAcquireNativeWindow(napi_env env, napi_callback_info info)
139 {
140 napi_value result = nullptr;
141 int backInfo = FAIL;
142 OH_NativeImage *image = getNativeImage();
143
144 if (image != nullptr) {
145 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
146 if (nativeWindow != nullptr) {
147 backInfo = SUCCESS;
148 }
149 OH_NativeImage_Destroy(&image);
150 }
151 napi_create_int32(env, backInfo, &result);
152 return result;
153 }
154
OHNativeImageAcquireNativeWindowAbnormal(napi_env env, napi_callback_info info)155 static napi_value OHNativeImageAcquireNativeWindowAbnormal(napi_env env, napi_callback_info info)
156 {
157 napi_value result = nullptr;
158 int backInfo = FAIL;
159 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(nullptr);
160 if (nativeWindow != nullptr) {
161 backInfo = SUCCESS;
162 }
163 napi_create_int32(env, backInfo, &result);
164 return result;
165 }
166
OHNativeImageAttachContext(napi_env env, napi_callback_info info)167 static napi_value OHNativeImageAttachContext(napi_env env, napi_callback_info info)
168 {
169 int backInfo = FAIL;
170 InitEGLEnv();
171 GLuint textureId;
172 glGenTextures(PARAM_1, &textureId);
173 OH_NativeImage *image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
174 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
175 int code = SET_BUFFER_GEOMETRY;
176 int32_t width = PARAM_800;
177 int32_t height = PARAM_600;
178 OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
179 OHNativeWindowBuffer *buffer = nullptr;
180 int fenceFd;
181 OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
182 BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
183 void *mappedAddr = mmap(handle->virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, PARAM_0);
184 static uint32_t value = 0x00;
185 value++;
186 uint32_t *pixel = static_cast<uint32_t *>(mappedAddr);
187 for (uint32_t x = PARAM_0; x < width; x++) {
188 for (uint32_t y = PARAM_0; y < height; y++) {
189 *pixel++ = value;
190 }
191 }
192 munmap(mappedAddr, handle->size);
193
194 Region region{nullptr, PARAM_0};
195 OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
196 OH_NativeImage_UpdateSurfaceImage(image);
197 OH_NativeImage_GetTimestamp(image);
198 float matrix[16];
199 OH_NativeImage_GetTransformMatrix(image, matrix);
200 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
201 OH_NativeImage_DetachContext(image);
202 GLuint textureId2;
203 glGenTextures(PARAM_1, &textureId2);
204 backInfo = OH_NativeImage_AttachContext(image, textureId2);
205 napi_value result = nullptr;
206 napi_create_int32(env, backInfo, &result);
207 OH_NativeImage_Destroy(&image);
208 return result;
209 }
210
OHNativeImageAttachContextAbnormal(napi_env env, napi_callback_info info)211 static napi_value OHNativeImageAttachContextAbnormal(napi_env env, napi_callback_info info)
212 {
213 GLuint textureId2;
214 glGenTextures(ONEVAL, &textureId2);
215 int backInfo = OH_NativeImage_AttachContext(nullptr, textureId2);
216 if (backInfo != SUCCESS) {
217 backInfo = FAIL;
218 }
219 napi_value result = nullptr;
220 napi_create_int32(env, backInfo, &result);
221 return result;
222 }
223
OHNativeImageDetachContext(napi_env env, napi_callback_info info)224 static napi_value OHNativeImageDetachContext(napi_env env, napi_callback_info info)
225 {
226 int backInfo = FAIL;
227 InitEGLEnv();
228 GLuint textureId;
229 glGenTextures(PARAM_1, &textureId);
230 OH_NativeImage *image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
231 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
232 int code = SET_BUFFER_GEOMETRY;
233 int32_t width = PARAM_800;
234 int32_t height = PARAM_600;
235 OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
236 OHNativeWindowBuffer *buffer = nullptr;
237 int fenceFd;
238 OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
239 BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
240 void *mappedAddr = mmap(handle->virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, PARAM_0);
241 static uint32_t value = 0x00;
242 value++;
243 uint32_t *pixel = static_cast<uint32_t *>(mappedAddr);
244 for (uint32_t x = PARAM_0; x < width; x++) {
245 for (uint32_t y = PARAM_0; y < height; y++) {
246 *pixel++ = value;
247 }
248 }
249 munmap(mappedAddr, handle->size);
250
251 Region region{nullptr, PARAM_0};
252 OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
253 OH_NativeImage_UpdateSurfaceImage(image);
254 OH_NativeImage_GetTimestamp(image);
255 float matrix[16];
256 OH_NativeImage_GetTransformMatrix(image, matrix);
257 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
258 backInfo = OH_NativeImage_DetachContext(image);
259 GLuint textureId2;
260 glGenTextures(PARAM_1, &textureId2);
261 OH_NativeImage_AttachContext(image, textureId2);
262 OH_NativeImage_Destroy(&image);
263 napi_value result = nullptr;
264 napi_create_int32(env, backInfo, &result);
265 return result;
266 }
267
OHNativeImageDetachContextAbnormal(napi_env env, napi_callback_info info)268 static napi_value OHNativeImageDetachContextAbnormal(napi_env env, napi_callback_info info)
269 {
270 int backInfo = OH_NativeImage_DetachContext(nullptr);
271 if (backInfo != SUCCESS) {
272 backInfo = FAIL;
273 }
274 napi_value result = nullptr;
275 napi_create_int32(env, backInfo, &result);
276 return result;
277 }
278
OHNativeImageUpdateSurfaceImage(napi_env env, napi_callback_info info)279 static napi_value OHNativeImageUpdateSurfaceImage(napi_env env, napi_callback_info info)
280 {
281 InitEGLEnv();
282 GLuint textureId;
283 glGenTextures(PARAM_1, &textureId);
284 OH_NativeImage *image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
285 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
286 int code = SET_BUFFER_GEOMETRY;
287 int32_t width = PARAM_800;
288 int32_t height = PARAM_600;
289 OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
290 OHNativeWindowBuffer *buffer = nullptr;
291 int fenceFd;
292 OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
293 BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
294 void *mappedAddr = mmap(handle->virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, PARAM_0);
295 static uint32_t value = 0x00;
296 value++;
297 uint32_t *pixel = static_cast<uint32_t *>(mappedAddr);
298 for (uint32_t x = PARAM_0; x < width; x++) {
299 for (uint32_t y = PARAM_0; y < height; y++) {
300 *pixel++ = value;
301 }
302 }
303 munmap(mappedAddr, handle->size);
304 Region region{nullptr, PARAM_0};
305 OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
306 int backInfo = OH_NativeImage_UpdateSurfaceImage(image);
307 OH_NativeImage_GetTimestamp(image);
308 float matrix[16];
309 OH_NativeImage_GetTransformMatrix(image, matrix);
310 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
311 OH_NativeImage_DetachContext(image);
312 GLuint textureId2;
313 glGenTextures(PARAM_1, &textureId2);
314 OH_NativeImage_AttachContext(image, textureId2);
315 OH_NativeImage_Destroy(&image);
316 napi_value result = nullptr;
317 napi_create_int32(env, backInfo, &result);
318 return result;
319 }
320
OHNativeImageUpdateSurfaceImageBoundary(napi_env env, napi_callback_info info)321 static napi_value OHNativeImageUpdateSurfaceImageBoundary(napi_env env, napi_callback_info info)
322 {
323 InitEGLEnv();
324 GLuint textureId;
325 glGenTextures(PARAM_1, &textureId);
326 OH_NativeImage *image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
327 OHNativeWindow *nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
328 int code = SET_BUFFER_GEOMETRY;
329 int32_t width = 4096;
330 int32_t height = 2160;
331 OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
332 OHNativeWindowBuffer *buffer = nullptr;
333 int fenceFd;
334 OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
335 BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
336 void *mappedAddr = mmap(handle->virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, PARAM_0);
337 static uint32_t value = 0x00;
338 value++;
339 uint32_t *pixel = static_cast<uint32_t *>(mappedAddr);
340 for (uint32_t x = PARAM_0; x < width; x++) {
341 for (uint32_t y = PARAM_0; y < height; y++) {
342 *pixel++ = value;
343 }
344 }
345 munmap(mappedAddr, handle->size);
346 Region region{nullptr, PARAM_0};
347 OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
348 int backInfo = OH_NativeImage_UpdateSurfaceImage(image);
349 OH_NativeImage_GetTimestamp(image);
350 float matrix[16];
351 OH_NativeImage_GetTransformMatrix(image, matrix);
352 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
353 OH_NativeImage_DetachContext(image);
354 GLuint textureId2;
355 glGenTextures(PARAM_1, &textureId2);
356 OH_NativeImage_AttachContext(image, textureId2);
357 OH_NativeImage_Destroy(&image);
358 napi_value result = nullptr;
359 napi_create_int32(env, backInfo, &result);
360 return result;
361 }
362
OHNativeImageUpdateSurfaceImageAbnormal(napi_env env, napi_callback_info info)363 static napi_value OHNativeImageUpdateSurfaceImageAbnormal(napi_env env, napi_callback_info info)
364 {
365 int backInfo = OH_NativeImage_UpdateSurfaceImage(nullptr);
366 if (backInfo != SUCCESS) {
367 backInfo = FAIL;
368 }
369 napi_value result = nullptr;
370 napi_create_int32(env, backInfo, &result);
371 return result;
372 }
373
OHNativeImageGetTimestamp(napi_env env, napi_callback_info info)374 static napi_value OHNativeImageGetTimestamp(napi_env env, napi_callback_info info)
375 {
376 int backInfo = FAIL;
377 OH_NativeImage *image = getNativeImage();
378 if (image != nullptr) {
379 backInfo = OH_NativeImage_GetTimestamp(image);
380 OH_NativeImage_Destroy(&image);
381 }
382 napi_value result = nullptr;
383 napi_create_int32(env, backInfo, &result);
384 return result;
385 }
386
OHNativeImageGetTransformMatrix(napi_env env, napi_callback_info info)387 static napi_value OHNativeImageGetTransformMatrix(napi_env env, napi_callback_info info)
388 {
389 int backInfo = FAIL;
390 OH_NativeImage *image = getNativeImage();
391 if (image != nullptr) {
392 float matrix[NUMMAX];
393 backInfo = OH_NativeImage_GetTransformMatrix(image, matrix);
394 OH_NativeImage_Destroy(&image);
395 }
396 napi_value result = nullptr;
397 napi_create_int32(env, backInfo, &result);
398 return result;
399 }
400
OHNativeImageGetTransformMatrixAbnormal(napi_env env, napi_callback_info info)401 static napi_value OHNativeImageGetTransformMatrixAbnormal(napi_env env, napi_callback_info info)
402 {
403 int backInfo = FAIL;
404 float matrix[NUMMAX];
405 int ret = OH_NativeImage_GetTransformMatrix(nullptr, matrix);
406 if (ret != SUCCESS) {
407 backInfo = FAIL;
408 }
409
410 napi_value result = nullptr;
411 napi_create_int32(env, backInfo, &result);
412 return result;
413 }
414
OHNativeImageDestroy(napi_env env, napi_callback_info info)415 static napi_value OHNativeImageDestroy(napi_env env, napi_callback_info info)
416 {
417 int backInfo = FAIL;
418 OH_NativeImage *image = getNativeImage();
419 OH_NativeImage_Destroy(&image);
420 if (image == nullptr) {
421 backInfo = SUCCESS;
422 }
423
424 napi_value result = nullptr;
425 napi_create_int32(env, backInfo, &result);
426 return result;
427 }
428
OHNativeImageCreateNormal(napi_env env, napi_callback_info info)429 static napi_value OHNativeImageCreateNormal(napi_env env, napi_callback_info info)
430 {
431 int backInfo = FAIL;
432 OH_NativeImage *image = nullptr;
433 InitEGLEnv();
434 GLuint textureId;
435 glGenTextures(PARAM_1, &textureId);
436 GLuint textureTarget = GL_TEXTURE_2D;
437 image = OH_NativeImage_Create(textureId, textureTarget);
438 if (image != nullptr) {
439 backInfo = SUCCESS;
440 }
441 napi_value result = nullptr;
442 napi_create_int32(env, backInfo, &result);
443 OH_NativeImage_Destroy(&image);
444 return result;
445 }
446
OHNativeImageCreateAbnormal(napi_env env, napi_callback_info info)447 static napi_value OHNativeImageCreateAbnormal(napi_env env, napi_callback_info info)
448 {
449 int backInfo = FAIL;
450
451 OH_NativeImage *image = OH_NativeImage_Create(0, 1);
452 if (image != nullptr) {
453 backInfo = SUCCESS;
454 }
455 napi_value result = nullptr;
456 napi_create_int32(env, backInfo, &result);
457 OH_NativeImage_Destroy(&image);
458 return result;
459 }
460
OHNativeImageDestroy1(napi_env env, napi_callback_info info)461 static napi_value OHNativeImageDestroy1(napi_env env, napi_callback_info info)
462 {
463 int backInfo = FAIL;
464 OH_NativeImage *image = nullptr;
465 GLenum nativeImageTexId_;
466 GLuint GL_TEXTURE_EXTERNAL_OES;
467 glGenTextures(1, &nativeImageTexId_);
468 glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_);
469 image = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES);
470 if (image != nullptr) {
471 OH_NativeImage_Destroy(&image);
472 if (image == nullptr) {
473 backInfo = SUCCESS;
474 }
475 }
476 napi_value result = nullptr;
477 napi_create_int32(env, backInfo, &result);
478 return result;
479 }
480
OHNativeImageCreateMuch(napi_env env, napi_callback_info info)481 static napi_value OHNativeImageCreateMuch(napi_env env, napi_callback_info info)
482 {
483 int backInfo = SUCCESS;
484 const int count = NUMBER_500;
485 OH_NativeImage *imageArray[500] = {nullptr};
486 for (int i = 0; i < count; ++i) {
487 GLuint GL_TEXTURE_EXTERNAL_OES;
488 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 1);
489 imageArray[i] = OH_NativeImage_Create(1, GL_TEXTURE_EXTERNAL_OES);
490 if (imageArray[i] == nullptr) {
491 backInfo = FAIL;
492 break;
493 }
494 }
495
496 for (int i = 0; i < count; ++i) {
497 if (imageArray[i] != nullptr) {
498 OH_NativeImage_Destroy(&imageArray[i]); // 销毁单个图像
499 if (imageArray[i] != nullptr) {
500 backInfo = FAIL;
501 break;
502 }
503 }
504 }
505
506 napi_value result = nullptr;
507 if (backInfo == FAIL) {
508 napi_create_int32(env, backInfo, &result);
509 } else {
510 napi_create_int32(env, SUCCESS, &result);
511 }
512
513 return result;
514 }
515
OHNativeImageAcquireNativeWindowNullptr(napi_env env, napi_callback_info info)516 static napi_value OHNativeImageAcquireNativeWindowNullptr(napi_env env, napi_callback_info info)
517 {
518 OHNativeWindow *nativeWindow = nullptr;
519 nativeWindow = OH_NativeImage_AcquireNativeWindow(nullptr);
520 napi_value result = nullptr;
521 if (nativeWindow != nullptr) {
522 napi_create_int32(env, SUCCESS, &result);
523 } else {
524 napi_create_int32(env, FAIL, &result);
525 }
526 return result;
527 }
528
OHNativeImageAcquireNativeWindowNormal(napi_env env, napi_callback_info info)529 static napi_value OHNativeImageAcquireNativeWindowNormal(napi_env env, napi_callback_info info)
530 {
531 int backInfo = FAIL;
532 OHNativeWindow *nativeWindow1 = nullptr;
533 OHNativeWindow *nativeWindow2 = nullptr;
534 OH_NativeImage *nativeImage = getNativeImage();
535 nativeWindow1 = OH_NativeImage_AcquireNativeWindow(nativeImage);
536 if (nativeWindow1 != nullptr) {
537 nativeWindow2 = OH_NativeImage_AcquireNativeWindow(nativeImage);
538 if (nativeWindow1 == nativeWindow2) {
539 backInfo = SUCCESS;
540 }
541 }
542
543 napi_value result = nullptr;
544 napi_create_int32(env, backInfo, &result);
545 OH_NativeImage_Destroy(&nativeImage);
546 return result;
547 }
548
OHNativeImageAttachContextNullptr(napi_env env, napi_callback_info info)549 static napi_value OHNativeImageAttachContextNullptr(napi_env env, napi_callback_info info)
550 {
551 OH_NativeImage *nativeImage = getNativeImage();
552 InitEGLEnv();
553 GLuint textureId;
554 glGenTextures(PARAM_1, &textureId);
555 napi_value result = nullptr;
556 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
557 napi_value result1 = nullptr;
558 napi_value result2 = nullptr;
559 int res1 = OH_NativeImage_AttachContext(nullptr, textureId);
560 if (res1 != 0) {
561 napi_create_int32(env, FAIL, &result1);
562 } else {
563 napi_create_int32(env, SUCCESS, &result1);
564 }
565 napi_set_element(env, result, ARR_NUMBER_0, result1);
566
567 int res2 = OH_NativeImage_AttachContext(nativeImage, NULL);
568 if (res2 != 0) {
569 napi_create_int32(env, FAIL, &result2);
570 } else {
571 napi_create_int32(env, SUCCESS, &result2);
572 }
573 napi_set_element(env, result, ARR_NUMBER_1, result2);
574 OH_NativeImage_Destroy(&nativeImage);
575 return result;
576 }
577
OHNativeImageDetachContextNullptr(napi_env env, napi_callback_info info)578 static napi_value OHNativeImageDetachContextNullptr(napi_env env, napi_callback_info info)
579 {
580 OH_NativeImage *nativeImage = getNativeImage();
581 InitEGLEnv();
582 GLuint textureId;
583 glGenTextures(PARAM_1, &textureId);
584 napi_value result = nullptr;
585 int res = OH_NativeImage_DetachContext(nullptr);
586 if (res != 0) {
587 napi_create_int32(env, FAIL, &result);
588 } else {
589 napi_create_int32(env, SUCCESS, &result);
590 }
591 OH_NativeImage_Destroy(&nativeImage);
592 return result;
593 }
594
OHNativeImageAttachContextNormal(napi_env env, napi_callback_info info)595 static napi_value OHNativeImageAttachContextNormal(napi_env env, napi_callback_info info)
596 {
597 OH_NativeImage *nativeImage = getNativeImage();
598 InitEGLEnv();
599 GLuint textureId;
600 glGenTextures(PARAM_1, &textureId);
601 napi_value result = nullptr;
602 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
603 napi_value result1 = nullptr;
604 napi_value result2 = nullptr;
605 int res1 = OH_NativeImage_AttachContext(nativeImage, textureId);
606 if (res1 == 0) {
607 napi_create_int32(env, SUCCESS, &result1);
608 } else {
609 napi_create_int32(env, FAIL, &result1);
610 }
611 napi_set_element(env, result, ARR_NUMBER_0, result1);
612
613 int res2 = OH_NativeImage_AttachContext(nativeImage, textureId);
614 if (res2 == 0) {
615 napi_create_int32(env, SUCCESS, &result2);
616 } else {
617 napi_create_int32(env, FAIL, &result2);
618 }
619 napi_set_element(env, result, ARR_NUMBER_1, result2);
620
621 OH_NativeImage_Destroy(&nativeImage);
622 return result;
623 }
624
OHNativeImageDetachContextNormal(napi_env env, napi_callback_info info)625 static napi_value OHNativeImageDetachContextNormal(napi_env env, napi_callback_info info)
626 {
627 OH_NativeImage *nativeImage = getNativeImage();
628 InitEGLEnv();
629 GLuint textureId;
630 glGenTextures(PARAM_1, &textureId);
631 napi_value result = nullptr;
632 napi_create_array_with_length(env, ARR_NUMBER_3, &result);
633 napi_value result1 = nullptr;
634 napi_value result2 = nullptr;
635 napi_value result3 = nullptr;
636 int res1 = OH_NativeImage_DetachContext(nativeImage);
637 if (res1 != 0) {
638 napi_create_int32(env, FAIL, &result1);
639 } else {
640 napi_create_int32(env, SUCCESS, &result1);
641 }
642 napi_set_element(env, result, ARR_NUMBER_0, result1);
643
644 int res2 = OH_NativeImage_AttachContext(nativeImage, textureId);
645 if (res2 == 0) {
646 napi_create_int32(env, SUCCESS, &result2);
647 } else {
648 napi_create_int32(env, FAIL, &result2);
649 }
650 napi_set_element(env, result, ARR_NUMBER_1, result2);
651
652 int res3 = OH_NativeImage_DetachContext(nativeImage);
653 if (res3 == 0) {
654 napi_create_int32(env, SUCCESS, &result3);
655 } else {
656 napi_create_int32(env, FAIL, &result3);
657 }
658 napi_set_element(env, result, ARR_NUMBER_2, result3);
659
660 OH_NativeImage_Destroy(&nativeImage);
661 return result;
662 }
663
OHNativeImageGetSurfaceIdNullptr(napi_env env, napi_callback_info info)664 static napi_value OHNativeImageGetSurfaceIdNullptr(napi_env env, napi_callback_info info)
665 {
666 OH_NativeImage *nativeImage = getNativeImage();
667 napi_value result = nullptr;
668 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
669 napi_value result1 = nullptr;
670 napi_value result2 = nullptr;
671 uint64_t surfaceId = NUMBER_99999;
672 int res1 = OH_NativeImage_GetSurfaceId(nullptr, &surfaceId);
673 if (res1 != 0 && surfaceId == NUMBER_99999) {
674 napi_create_int32(env, FAIL, &result1);
675 } else {
676 napi_create_int32(env, SUCCESS, &result1);
677 }
678 napi_set_element(env, result, ARR_NUMBER_0, result1);
679
680 int res2 = OH_NativeImage_GetSurfaceId(nullptr, NULL);
681 if (res2 != 0 && surfaceId == NUMBER_99999) {
682 napi_create_int32(env, FAIL, &result2);
683 } else {
684 napi_create_int32(env, SUCCESS, &result2);
685 }
686 napi_set_element(env, result, ARR_NUMBER_1, result2);
687
688 OH_NativeImage_Destroy(&nativeImage);
689 return result;
690 }
691
OHNativeGetSurfaceIdNormal(napi_env env, napi_callback_info info)692 static napi_value OHNativeGetSurfaceIdNormal(napi_env env, napi_callback_info info)
693 {
694 OH_NativeImage *nativeImage = getNativeImage();
695 napi_value result = nullptr;
696 uint64_t surfaceId = NUMBER_99999;
697 int res = OH_NativeImage_GetSurfaceId(nativeImage, &surfaceId);
698 if (res == 0 && surfaceId != NUMBER_99999) {
699 napi_create_int32(env, SUCCESS, &result);
700 } else {
701 napi_create_int32(env, FAIL, &result);
702 }
703
704 return result;
705 }
706
OHNativeImageUpdateSurfaceImageNullptr(napi_env env, napi_callback_info info)707 static napi_value OHNativeImageUpdateSurfaceImageNullptr(napi_env env, napi_callback_info info)
708 {
709 OH_NativeImage *nativeImage = getNativeImage();
710 napi_value result = nullptr;
711 int res = OH_NativeImage_UpdateSurfaceImage(nullptr);
712 if (res != 0) {
713 napi_create_int32(env, FAIL, &result);
714 } else {
715 napi_create_int32(env, SUCCESS, &result);
716 }
717 OH_NativeImage_Destroy(&nativeImage);
718 return result;
719 }
720
OHNativeImageGetTimestampNullptr(napi_env env, napi_callback_info info)721 static napi_value OHNativeImageGetTimestampNullptr(napi_env env, napi_callback_info info)
722 {
723 OH_NativeImage *nativeImage = getNativeImage();
724 napi_value result = nullptr;
725 int64_t timestamp = 0;
726 timestamp = OH_NativeImage_GetTimestamp(nullptr);
727 if (timestamp == 0) {
728 napi_create_int32(env, FAIL, &result);
729 } else {
730 napi_create_int32(env, SUCCESS, &result);
731 }
732 OH_NativeImage_Destroy(&nativeImage);
733 return result;
734 }
735
OHNativeImageGetTransformMatrixNullptr(napi_env env, napi_callback_info info)736 static napi_value OHNativeImageGetTransformMatrixNullptr(napi_env env, napi_callback_info info)
737 {
738 OH_NativeImage *nativeImage = getNativeImage();
739 napi_value result = nullptr;
740 float matrix[16];
741 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
742 napi_value result1 = nullptr;
743 napi_value result2 = nullptr;
744 int res1 = OH_NativeImage_GetTransformMatrix(nullptr, matrix);
745 if (res1 == 0) {
746 napi_create_int32(env, SUCCESS, &result1);
747 } else {
748 napi_create_int32(env, FAIL, &result1);
749 }
750 napi_set_element(env, result, ARR_NUMBER_0, result1);
751
752 int res2 = OH_NativeImage_GetTransformMatrix(nativeImage, NULL);
753 if (res2 == 0) {
754 napi_create_int32(env, SUCCESS, &result2);
755 } else {
756 napi_create_int32(env, FAIL, &result2);
757 }
758 napi_set_element(env, result, ARR_NUMBER_1, result2);
759
760 OH_NativeImage_Destroy(&nativeImage);
761 return result;
762 }
763
OHNativeImageGetTransformMatrixV2Nullptr(napi_env env, napi_callback_info info)764 static napi_value OHNativeImageGetTransformMatrixV2Nullptr(napi_env env, napi_callback_info info)
765 {
766 OH_NativeImage *nativeImage = getNativeImage();
767 napi_value result = nullptr;
768 float matrix[16];
769 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
770 napi_value result1 = nullptr;
771 napi_value result2 = nullptr;
772 int res1 = OH_NativeImage_GetTransformMatrixV2(nullptr, matrix);
773 if (res1 == 0) {
774 napi_create_int32(env, SUCCESS, &result1);
775 } else {
776 napi_create_int32(env, FAIL, &result1);
777 }
778 napi_set_element(env, result, ARR_NUMBER_0, result1);
779
780 int res2 = OH_NativeImage_GetTransformMatrixV2(nativeImage, NULL);
781 if (res2 == 0) {
782 napi_create_int32(env, SUCCESS, &result2);
783 } else {
784 napi_create_int32(env, FAIL, &result2);
785 }
786 napi_set_element(env, result, ARR_NUMBER_1, result2);
787
788 OH_NativeImage_Destroy(&nativeImage);
789 return result;
790 }
791
OHNativeImageUpdateSurfaceImageNormal(napi_env env, napi_callback_info info)792 static napi_value OHNativeImageUpdateSurfaceImageNormal(napi_env env, napi_callback_info info)
793 {
794 OH_NativeImage *nativeImage = nullptr;
795 napi_value result = nullptr;
796 GLenum nativeImageTexId_;
797 GLuint GL_TEXTURE_EXTERNAL_OES;
798 glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_);
799 nativeImage = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES);
800 int res = OH_NativeImage_UpdateSurfaceImage(nativeImage);
801 if (res == 0) {
802 napi_create_int32(env, SUCCESS, &result);
803 } else {
804 napi_create_int32(env, FAIL, &result);
805 }
806 OH_NativeImage_Destroy(&nativeImage);
807 return result;
808 }
809
OHNativeImageGetTimestampNormal(napi_env env, napi_callback_info info)810 static napi_value OHNativeImageGetTimestampNormal(napi_env env, napi_callback_info info)
811 {
812 OH_NativeImage *nativeImage = nullptr;
813 napi_value result = nullptr;
814 napi_create_array_with_length(env, ARR_NUMBER_3, &result);
815 napi_value result1 = nullptr;
816 napi_value result2 = nullptr;
817 GLenum nativeImageTexId_;
818 GLuint GL_TEXTURE_EXTERNAL_OES;
819 glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_);
820 nativeImage = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES);
821 int res = OH_NativeImage_UpdateSurfaceImage(nativeImage);
822
823 // 使用chrono获取当前时间点
824 auto now = std::chrono::system_clock::now();
825 // 将当前时间点转换为自1970年1月1日以来的毫秒数
826 auto duration = now.time_since_epoch();
827 auto current_timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
828 // 将chrono库获取的时间戳存储在int64_t类型的变量中
829 int64_t time = static_cast<int64_t>(current_timestamp);
830
831 int64_t timestamp = 0;
832 timestamp = OH_NativeImage_GetTimestamp(nativeImage);
833
834 if (res == 0) {
835 napi_create_int32(env, SUCCESS, &result1);
836 } else {
837 napi_create_int32(env, FAIL, &result1);
838 }
839 napi_set_element(env, result, ARR_NUMBER_0, result1);
840
841 if (timestamp == time) {
842 napi_create_int32(env, SUCCESS, &result2);
843 } else {
844 napi_create_int32(env, FAIL, &result2);
845 }
846 napi_set_element(env, result, ARR_NUMBER_1, result2);
847
848 napi_value result3 = nullptr;
849 int res1 = OH_NativeImage_UpdateSurfaceImage(nativeImage);
850
851 auto now1 = std::chrono::system_clock::now();
852 auto duration1 = now1.time_since_epoch();
853 auto current_timestamp1 = std::chrono::duration_cast<std::chrono::milliseconds>(duration1).count();
854 int64_t time1 = static_cast<int64_t>(current_timestamp);
855
856 int64_t timestamp1 = 0;
857 timestamp1 = OH_NativeImage_GetTimestamp(nativeImage);
858
859 if (res1 == 0 && current_timestamp1 == time1) {
860 napi_create_int32(env, SUCCESS, &result3);
861 } else {
862 napi_create_int32(env, FAIL, &result3);
863 }
864 napi_set_element(env, result, ARR_NUMBER_2, result3);
865
866 OH_NativeImage_Destroy(&nativeImage);
867 return result;
868 }
869
OHNativeImageGetTransformMatrixNormal(napi_env env, napi_callback_info info)870 static napi_value OHNativeImageGetTransformMatrixNormal(napi_env env, napi_callback_info info)
871 {
872 OH_NativeImage *nativeImage = nullptr;
873 GLenum nativeImageTexId_;
874 GLuint GL_TEXTURE_EXTERNAL_OES;
875 glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_);
876 nativeImage = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES);
877 float matrix[16];
878 float matrixNull[16] = {};
879 napi_value result = nullptr;
880 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
881 napi_value result1 = nullptr;
882 napi_value result2 = nullptr;
883
884 int res1 = OH_NativeImage_UpdateSurfaceImage(nativeImage);
885 if (res1 == 0) {
886 napi_create_int32(env, SUCCESS, &result1);
887 } else {
888 napi_create_int32(env, FAIL, &result1);
889 }
890 napi_set_element(env, result, ARR_NUMBER_0, result1);
891
892 OH_NativeImage_GetTransformMatrix(nativeImage, matrix);
893 if (memcmp(matrix, matrixNull, sizeof(matrix)) == 0) {
894 napi_create_int32(env, FAIL, &result2);
895 } else {
896 napi_create_int32(env, SUCCESS, &result2);
897 }
898 napi_set_element(env, result, ARR_NUMBER_1, result2);
899
900 OH_NativeImage_Destroy(&nativeImage);
901 return result;
902 }
903
OHNativeImageGetTransformMatrixV2Normal(napi_env env, napi_callback_info info)904 static napi_value OHNativeImageGetTransformMatrixV2Normal(napi_env env, napi_callback_info info)
905 {
906 OH_NativeImage *nativeImage = nullptr;
907 GLenum nativeImageTexId_;
908 GLuint GL_TEXTURE_EXTERNAL_OES;
909 glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_);
910 nativeImage = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES);
911 float matrixV2[16];
912 float matrixNull[16] = {};
913 napi_value result = nullptr;
914 napi_create_array_with_length(env, ARR_NUMBER_2, &result);
915 napi_value result1 = nullptr;
916 napi_value result2 = nullptr;
917
918 int res1 = OH_NativeImage_UpdateSurfaceImage(nativeImage);
919 if (res1 == 0) {
920 napi_create_int32(env, SUCCESS, &result1);
921 } else {
922 napi_create_int32(env, FAIL, &result1);
923 }
924 napi_set_element(env, result, ARR_NUMBER_0, result1);
925
926 OH_NativeImage_GetTransformMatrixV2(nativeImage, matrixV2);
927 if (memcmp(matrixV2, matrixNull, sizeof(matrixV2)) == 0) {
928 napi_create_int32(env, FAIL, &result2);
929 } else {
930 napi_create_int32(env, SUCCESS, &result2);
931 }
932 napi_set_element(env, result, ARR_NUMBER_1, result2);
933
934 OH_NativeImage_Destroy(&nativeImage);
935 return result;
936 }
937
OHNativeImageSetOnFrameAvailableListenerNullptr(napi_env env, napi_callback_info info)938 static napi_value OHNativeImageSetOnFrameAvailableListenerNullptr(napi_env env, napi_callback_info info)
939 {
940 class NativeImageAdaptor {
941 public:
942 ~NativeImageAdaptor();
943 static NativeImageAdaptor *GetInstance();
944 static void OnFrameAvailable(void *context);
945 };
946 OH_NativeImage *nativeImage = nullptr;
947 napi_value result = nullptr;
948 OH_OnFrameAvailableListener listener;
949 int res = OH_NativeImage_SetOnFrameAvailableListener(nullptr, listener);
950 if (res == 0) {
951 napi_create_int32(env, SUCCESS, &result);
952 } else {
953 napi_create_int32(env, FAIL, &result);
954 }
955 return result;
956 }
957
OHNativeImageUnSetOnFrameAvailableListenerNullptr(napi_env env, napi_callback_info info)958 static napi_value OHNativeImageUnSetOnFrameAvailableListenerNullptr(napi_env env, napi_callback_info info)
959 {
960 napi_value result = nullptr;
961 int res = OH_NativeImage_UnsetOnFrameAvailableListener(nullptr);
962 if (res == 0) {
963 napi_create_int32(env, SUCCESS, &result);
964 } else {
965 napi_create_int32(env, FAIL, &result);
966 }
967
968 return result;
969 }
970
OHNativeImageSetOnFrameAvailableListenerNormal(napi_env env, napi_callback_info info)971 static napi_value OHNativeImageSetOnFrameAvailableListenerNormal(napi_env env, napi_callback_info info)
972 {
973 class NativeImageAdaptor {
974 public:
975 ~NativeImageAdaptor();
976 static NativeImageAdaptor *GetInstance();
977 static void OnFrameAvailable(void *context);
978 };
979
980 OH_NativeImage *nativeImage1 = getNativeImage();
981 OH_OnFrameAvailableListener listener1;
982 napi_value result = nullptr;
983 napi_create_array_with_length(env, ARR_NUMBER_4, &result);
984 napi_value result1 = nullptr;
985
986 int res1 = OH_NativeImage_SetOnFrameAvailableListener(nativeImage1, listener1);
987 if (res1 == 0) {
988 napi_create_int32(env, SUCCESS, &result1);
989 } else {
990 napi_create_int32(env, FAIL, &result1);
991 }
992 napi_set_element(env, result, ARR_NUMBER_0, result1);
993
994 napi_value result2 = nullptr;
995 int res2 = OH_NativeImage_SetOnFrameAvailableListener(nativeImage1, listener1);
996 if (res2 == 0) {
997 napi_create_int32(env, SUCCESS, &result2);
998 } else {
999 napi_create_int32(env, FAIL, &result2);
1000 }
1001 napi_set_element(env, result, ARR_NUMBER_1, result2);
1002
1003 OH_NativeImage *nativeImage2 = getNativeImage();
1004 OH_OnFrameAvailableListener listener2;
1005 napi_value result3 = nullptr;
1006 int res3 = OH_NativeImage_SetOnFrameAvailableListener(nativeImage1, listener2);
1007 if (res3 == 0) {
1008 napi_create_int32(env, SUCCESS, &result3);
1009 } else {
1010 napi_create_int32(env, FAIL, &result3);
1011 }
1012 napi_set_element(env, result, ARR_NUMBER_2, result3);
1013
1014 napi_value result4 = nullptr;
1015 int res4 = OH_NativeImage_SetOnFrameAvailableListener(nativeImage2, listener1);
1016 if (res4 == 0) {
1017 napi_create_int32(env, SUCCESS, &result4);
1018 } else {
1019 napi_create_int32(env, FAIL, &result4);
1020 }
1021 napi_set_element(env, result, ARR_NUMBER_3, result4);
1022 OH_NativeImage_Destroy(&nativeImage1);
1023 OH_NativeImage_Destroy(&nativeImage2);
1024 return result;
1025 }
1026
OHNativeImageUnsetOnFrameAvailableListenerNormal(napi_env env, napi_callback_info info)1027 static napi_value OHNativeImageUnsetOnFrameAvailableListenerNormal(napi_env env, napi_callback_info info)
1028 {
1029 class NativeImageAdaptor {
1030 public:
1031 ~NativeImageAdaptor();
1032 static NativeImageAdaptor *GetInstance();
1033 static void OnFrameAvailable(void *context);
1034 };
1035
1036 OH_NativeImage *nativeImage1 = getNativeImage();
1037 OH_OnFrameAvailableListener listener1;
1038 napi_value result = nullptr;
1039 napi_create_array_with_length(env, ARR_NUMBER_3, &result);
1040 napi_value result1 = nullptr;
1041
1042 int res1 = OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage1);
1043 if (res1 == 0) {
1044 napi_create_int32(env, SUCCESS, &result1);
1045 } else {
1046 napi_create_int32(env, FAIL, &result1);
1047 }
1048 napi_set_element(env, result, ARR_NUMBER_0, result1);
1049
1050 napi_value result2 = nullptr;
1051 int res2 = OH_NativeImage_SetOnFrameAvailableListener(nativeImage1, listener1);
1052 if (res2 == 0) {
1053 napi_create_int32(env, SUCCESS, &result2);
1054 } else {
1055 napi_create_int32(env, FAIL, &result2);
1056 }
1057 napi_set_element(env, result, ARR_NUMBER_1, result2);
1058
1059 napi_value result3 = nullptr;
1060 int res3 = OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage1);
1061 if (res3 == 0) {
1062 napi_create_int32(env, SUCCESS, &result3);
1063 } else {
1064 napi_create_int32(env, FAIL, &result3);
1065 }
1066 napi_set_element(env, result, ARR_NUMBER_2, result3);
1067 OH_NativeImage_Destroy(&nativeImage1);
1068 return result;
1069 }
1070
NativeImageInit(napi_env env, napi_value exports)1071 napi_value NativeImageInit(napi_env env, napi_value exports)
1072 {
1073 napi_property_descriptor desc[] = {
1074 {"oHNativeImageCreate", nullptr, OHNativeImageCreate, nullptr, nullptr, nullptr, napi_default, nullptr},
1075 {"oHNativeImageAcquireNativeWindow", nullptr, OHNativeImageAcquireNativeWindow, nullptr, nullptr, nullptr,
1076 napi_default, nullptr},
1077 {"oHNativeImageAcquireNativeWindowAbnormal", nullptr, OHNativeImageAcquireNativeWindowAbnormal, nullptr,
1078 nullptr, nullptr, napi_default, nullptr},
1079 {"oHNativeImageAttachContext", nullptr, OHNativeImageAttachContext, nullptr, nullptr, nullptr, napi_default,
1080 nullptr},
1081 {"oHNativeImageAttachContextAbnormal", nullptr, OHNativeImageAttachContextAbnormal, nullptr, nullptr, nullptr,
1082 napi_default, nullptr},
1083 {"oHNativeImageDetachContext", nullptr, OHNativeImageDetachContext, nullptr, nullptr, nullptr, napi_default,
1084 nullptr},
1085 {"oHNativeImageDetachContextAbnormal", nullptr, OHNativeImageDetachContextAbnormal, nullptr, nullptr, nullptr,
1086 napi_default, nullptr},
1087 {"oHNativeImageUpdateSurfaceImage", nullptr, OHNativeImageUpdateSurfaceImage, nullptr, nullptr, nullptr,
1088 napi_default, nullptr},
1089 {"oHNativeImageUpdateSurfaceImageBoundary", nullptr, OHNativeImageUpdateSurfaceImageBoundary, nullptr,
1090 nullptr, nullptr, napi_default, nullptr},
1091 {"oHNativeImageUpdateSurfaceImageAbnormal", nullptr, OHNativeImageUpdateSurfaceImageAbnormal, nullptr, nullptr,
1092 nullptr, napi_default, nullptr},
1093 {"oHNativeImageGetTimestamp", nullptr, OHNativeImageGetTimestamp, nullptr, nullptr, nullptr, napi_default,
1094 nullptr},
1095 {"oHNativeImageGetTransformMatrix", nullptr, OHNativeImageGetTransformMatrix, nullptr, nullptr, nullptr,
1096 napi_default, nullptr},
1097 {"oHNativeImageGetTransformMatrixAbnormal", nullptr, OHNativeImageGetTransformMatrixAbnormal, nullptr, nullptr,
1098 nullptr, napi_default, nullptr},
1099 {"oHNativeImageDestroy", nullptr, OHNativeImageDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
1100 {"oHNativeImageCreateNormal", nullptr, OHNativeImageCreateNormal, nullptr, nullptr, nullptr, napi_default,
1101 nullptr},
1102 {"oHNativeImageCreateAbnormal", nullptr, OHNativeImageCreateAbnormal, nullptr, nullptr, nullptr, napi_default,
1103 nullptr},
1104 {"oHNativeImageDestroy1", nullptr, OHNativeImageDestroy1, nullptr, nullptr, nullptr, napi_default, nullptr},
1105 {"oHNativeImageCreateMuch", nullptr, OHNativeImageCreateMuch, nullptr, nullptr, nullptr, napi_default, nullptr},
1106 };
1107 napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);
1108 return exports;
1109 }
1110
1111 EXTERN_C_START
Init(napi_env env, napi_value exports)1112 static napi_value Init(napi_env env, napi_value exports)
1113 {
1114 NativeImageInit(env, exports);
1115 napi_property_descriptor desc[] = {
1116 {"oHNativeImageAcquireNativeWindowNullptr", nullptr, OHNativeImageAcquireNativeWindowNullptr, nullptr, nullptr,
1117 nullptr, napi_default, nullptr},
1118 {"oHNativeImageAcquireNativeWindowNormal", nullptr, OHNativeImageAcquireNativeWindowNormal, nullptr, nullptr,
1119 nullptr, napi_default, nullptr},
1120 {"oHNativeImageAttachContextNullptr", nullptr, OHNativeImageAttachContextNullptr, nullptr, nullptr, nullptr,
1121 napi_default, nullptr},
1122 {"oHNativeImageDetachContextNullptr", nullptr, OHNativeImageDetachContextNullptr, nullptr, nullptr, nullptr,
1123 napi_default, nullptr},
1124 {"oHNativeImageAttachContextNormal", nullptr, OHNativeImageAttachContextNormal, nullptr, nullptr, nullptr,
1125 napi_default, nullptr},
1126 {"oHNativeImageDetachContextNormal", nullptr, OHNativeImageDetachContextNormal, nullptr, nullptr, nullptr,
1127 napi_default, nullptr},
1128 {"oHNativeImageGetSurfaceIdNullptr", nullptr, OHNativeImageGetSurfaceIdNullptr, nullptr, nullptr, nullptr,
1129 napi_default, nullptr},
1130 {"oHNativeGetSurfaceIdNormal", nullptr, OHNativeGetSurfaceIdNormal, nullptr, nullptr, nullptr, napi_default,
1131 nullptr},
1132 {"oHNativeImageUpdateSurfaceImageNullptr", nullptr, OHNativeImageUpdateSurfaceImageNullptr, nullptr, nullptr,
1133 nullptr, napi_default, nullptr},
1134 {"oHNativeImageGetTimestampNullptr", nullptr, OHNativeImageGetTimestampNullptr, nullptr, nullptr, nullptr,
1135 napi_default, nullptr},
1136 {"oHNativeImageGetTransformMatrixNullptr", nullptr, OHNativeImageGetTransformMatrixNullptr, nullptr, nullptr,
1137 nullptr, napi_default, nullptr},
1138 {"oHNativeImageGetTransformMatrixV2Nullptr", nullptr, OHNativeImageGetTransformMatrixV2Nullptr, nullptr,
1139 nullptr, nullptr, napi_default, nullptr},
1140 {"oHNativeImageUpdateSurfaceImageNormal", nullptr, OHNativeImageUpdateSurfaceImageNormal, nullptr, nullptr,
1141 nullptr, napi_default, nullptr},
1142 {"oHNativeImageGetTimestampNormal", nullptr, OHNativeImageGetTimestampNormal, nullptr, nullptr, nullptr,
1143 napi_default, nullptr},
1144 {"oHNativeImageGetTransformMatrixNormal", nullptr, OHNativeImageGetTransformMatrixNormal, nullptr, nullptr,
1145 nullptr, napi_default, nullptr},
1146 {"oHNativeImageGetTransformMatrixV2Normal", nullptr, OHNativeImageGetTransformMatrixV2Normal, nullptr, nullptr,
1147 nullptr, napi_default, nullptr},
1148 {"oHNativeImageSetOnFrameAvailableListenerNullptr", nullptr, OHNativeImageSetOnFrameAvailableListenerNullptr,
1149 nullptr, nullptr, nullptr, napi_default, nullptr},
1150 {"oHNativeImageUnSetOnFrameAvailableListenerNullptr", nullptr,
1151 OHNativeImageUnSetOnFrameAvailableListenerNullptr, nullptr, nullptr, nullptr, napi_default, nullptr},
1152 {"oHNativeImageSetOnFrameAvailableListenerNormal", nullptr, OHNativeImageSetOnFrameAvailableListenerNormal,
1153 nullptr, nullptr, nullptr, napi_default, nullptr},
1154 {"oHNativeImageUnsetOnFrameAvailableListenerNormal", nullptr, OHNativeImageUnsetOnFrameAvailableListenerNormal,
1155 nullptr, nullptr, nullptr, napi_default, nullptr},
1156 };
1157 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1158 return exports;
1159 }
1160 EXTERN_C_END
1161
1162 static napi_module demoModule = {
1163 .nm_version = 1,
1164 .nm_flags = 0,
1165 .nm_filename = nullptr,
1166 .nm_register_func = Init,
1167 .nm_modname = "nativeimage",
1168 .nm_priv = ((void *)0),
1169 .reserved = {0},
1170 };
1171
RegisterModule(void)1172 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); };
1173