@@ -67,6 +67,8 @@ void OHOS_windowDataFill(SDL_Window *w)
67
67
w -> w = wid ;
68
68
w -> h = hei ;
69
69
w -> internal -> native_window = g_ohosNativeWindow ;
70
+
71
+ SDL_SetWindowSize (w , wid , hei );
70
72
71
73
SDL_VideoDevice * _this = SDL_GetVideoDevice ();
72
74
@@ -224,7 +226,7 @@ static napi_value sdlCallbackInit(napi_env env, napi_callback_info info)
224
226
data -> func = "test" ;
225
227
data -> argCount = 0 ;
226
228
227
- napi_call_threadsafe_function (napiEnv .func , data , napi_tsfn_blocking );
229
+ napi_call_threadsafe_function (napiEnv .func , data , napi_tsfn_nonblocking );
228
230
229
231
// SDL_free(data);
230
232
@@ -233,6 +235,26 @@ static napi_value sdlCallbackInit(napi_env env, napi_callback_info info)
233
235
return result ;
234
236
}
235
237
238
+ typedef struct entrypoint_info_ {
239
+ char * libname ;
240
+ char * func ;
241
+ } entrypoint_info ;
242
+ static int sdlLaunchMainInternal (void * reserved )
243
+ {
244
+ if (!reserved ) {
245
+ return -1 ;
246
+ }
247
+ entrypoint_info * data = (entrypoint_info * )reserved ;
248
+ void * lib = dlopen (data -> libname , RTLD_LAZY );
249
+ void * func = dlsym (lib , data -> func );
250
+ typedef int (* test )();
251
+ int d = ((test )func )();
252
+ dlclose (lib );
253
+ SDL_free (reserved );
254
+
255
+ return d ;
256
+ }
257
+
236
258
static napi_value sdlLaunchMain (napi_env env , napi_callback_info info )
237
259
{
238
260
size_t argc = 2 ;
@@ -248,12 +270,12 @@ static napi_value sdlLaunchMain(napi_env env, napi_callback_info info)
248
270
napi_get_value_string_utf8 (env , args [1 ], NULL , 0 , & fstringSize );
249
271
char * fname = SDL_malloc (fstringSize + 1 );
250
272
napi_get_value_string_utf8 (env , args [1 ], fname , fstringSize + 1 , & fstringSize );
251
-
252
- void * lib = dlopen ( libname , RTLD_LAZY );
253
- void * func = dlsym ( lib , fname ) ;
254
- typedef int ( * test )() ;
255
- (( test ) func )( );
256
- dlclose ( lib );
273
+
274
+ entrypoint_info * entry = ( entrypoint_info * ) SDL_malloc ( sizeof ( entrypoint_info ) );
275
+ entry -> func = fname ;
276
+ entry -> libname = libname ;
277
+ SDL_Thread * m = SDL_CreateThread ( sdlLaunchMainInternal , "SDL App Thread" , entry );
278
+ SDL_SetMainReady ( );
257
279
258
280
napi_value result ;
259
281
napi_create_int32 (env , 0 , & result );
@@ -278,6 +300,12 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
278
300
x = (int )offsetX ;
279
301
y = (int )offsetY ;
280
302
SDL_UnlockMutex (g_ohosPageMutex );
303
+
304
+ napiCallbackData * data = SDL_malloc (sizeof (napiCallbackData ));
305
+ data -> func = "onMainLaunch" ;
306
+ data -> argCount = 0 ;
307
+
308
+ napi_call_threadsafe_function (napiEnv .func , data , napi_tsfn_nonblocking );
281
309
}
282
310
static void OnSurfaceChangedCB (OH_NativeXComponent * component , void * window )
283
311
{
@@ -296,6 +324,13 @@ static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
296
324
x = (int )offsetX ;
297
325
y = (int )offsetY ;
298
326
SDL_UnlockMutex (g_ohosPageMutex );
327
+
328
+ SDL_VideoDevice * _this = SDL_GetVideoDevice ();
329
+ SDL_Window * win = _this -> windows ;
330
+ while (win != NULL ) {
331
+ OHOS_windowDataFill (win );
332
+ win = win -> next ;
333
+ }
299
334
}
300
335
static void OnSurfaceDestroyedCB (OH_NativeXComponent * component , void * window )
301
336
{
@@ -318,6 +353,7 @@ static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
318
353
static void onKeyEvent (OH_NativeXComponent * component , void * window )
319
354
{
320
355
OH_NativeXComponent_KeyEvent * keyEvent = NULL ;
356
+ SDL_Log ("key!" );
321
357
if (OH_NativeXComponent_GetKeyEvent (component , & keyEvent ) >= 0 ) {
322
358
OH_NativeXComponent_KeyAction action ;
323
359
OH_NativeXComponent_KeyCode code ;
@@ -349,7 +385,8 @@ static void onNativeTouch(OH_NativeXComponent *component, void *window)
349
385
for (int i = 0 ; i < touchEvent .numPoints ; i ++ ) {
350
386
SDL_OHOSTouchEvent e ;
351
387
e .timestamp = touchEvent .timeStamp ;
352
- e .deviceId = touchEvent .deviceId ;
388
+ // skip assertions
389
+ e .deviceId = touchEvent .deviceId + 1 ;
353
390
e .fingerId = touchEvent .touchPoints [i ].id ;
354
391
e .area = touchEvent .touchPoints [i ].size ;
355
392
e .x = touchEvent .touchPoints [i ].x / (float )wid ;
@@ -374,13 +411,13 @@ static void onNativeTouch(OH_NativeXComponent *component, void *window)
374
411
375
412
OHOS_OnTouch (e );
376
413
}
414
+
415
+ OHOS_UnlockPage ();
377
416
}
378
- static void OnDispatchTouchEventCB ( OH_NativeXComponent * component , void * window )
379
- {
417
+ // TODO mouse data
418
+ static void onNativeMouse ( OH_NativeXComponent * component , void * window ) {
380
419
onNativeTouch (component , window );
381
420
}
382
- // TODO
383
- static void onNativeMouse (OH_NativeXComponent * component , void * window ) {}
384
421
385
422
static napi_value SDL_OHOS_NAPI_Init (napi_env env , napi_value exports )
386
423
{
@@ -405,7 +442,6 @@ static napi_value SDL_OHOS_NAPI_Init(napi_env env, napi_value exports)
405
442
callback .DispatchTouchEvent = onNativeTouch ;
406
443
OH_NativeXComponent_RegisterCallback (nativeXComponent , & callback );
407
444
408
- mouseCallback .DispatchMouseEvent = OnDispatchTouchEventCB ;
409
445
mouseCallback .DispatchMouseEvent = onNativeMouse ;
410
446
OH_NativeXComponent_RegisterMouseEventCallback (nativeXComponent , & mouseCallback );
411
447
0 commit comments