Skip to content

Commit d2d90a2

Browse files
committed
Android: native: lock framebuffer during resize and free
Most importantly, lock out the GLThread that using VncCanvas.OnDrawFrame() and calls into prepareTexture(), accessing the native framebuffer.
1 parent 985a900 commit d2d90a2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

android/app/src/main/cpp/vncconn.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,22 @@ static rfbBool onNewFBSize(rfbClient *client)
363363
}
364364

365365
jclass cls = (*env)->GetObjectClass(env, obj);
366-
jmethodID mid = (*env)->GetMethodID(env, cls, "onNewFramebufferSize", "(II)V");
367-
(*env)->CallVoidMethod(env, obj, mid, client->width, client->height);
368366

369-
return defaultMallocFramebuffer(client);
367+
// lock out other framebuffer accessors
368+
jmethodID mid_lockFramebuffer = (*env)->GetMethodID(env, cls, "lockFramebuffer", "()V");
369+
(*env)->CallVoidMethod(env, obj, mid_lockFramebuffer);
370+
371+
// tell the managed VNCConn about the new framebuffer size
372+
jmethodID mid_onNewFramebufferSize = (*env)->GetMethodID(env, cls, "onNewFramebufferSize", "(II)V");
373+
(*env)->CallVoidMethod(env, obj, mid_onNewFramebufferSize, client->width, client->height);
374+
// alloc new framebuffer
375+
rfbBool status = defaultMallocFramebuffer(client);
376+
377+
// allow framebuffer access again
378+
jmethodID mid_unlockFramebuffer = (*env)->GetMethodID(env, cls, "unlockFramebuffer", "()V");
379+
(*env)->CallVoidMethod(env, obj, mid_unlockFramebuffer);
380+
381+
return status;
370382
}
371383

372384
static void onSshError(void *client, ssh_tunnel_error_t error_code, const char *error_message) {
@@ -547,11 +559,20 @@ JNIEXPORT void JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbShutdow
547559

548560
ssh_tunnel_close(rfbClientGetClientData(cl, VNCCONN_SSH_ID));
549561

562+
jclass cls = (*env)->GetObjectClass(env, obj);
563+
// lock out other framebuffer accessors
564+
jmethodID mid_lockFramebuffer = (*env)->GetMethodID(env, cls, "lockFramebuffer", "()V");
565+
(*env)->CallVoidMethod(env, obj, mid_lockFramebuffer);
566+
550567
if(cl->frameBuffer) {
551568
free(cl->frameBuffer);
552569
cl->frameBuffer = 0;
553570
}
554571

572+
// allow framebuffer access again
573+
jmethodID mid_unlockFramebuffer = (*env)->GetMethodID(env, cls, "unlockFramebuffer", "()V");
574+
(*env)->CallVoidMethod(env, obj, mid_unlockFramebuffer);
575+
555576
rfbClientCleanup(cl);
556577
// rfbClientCleanup does not zero the pointer
557578
setRfbClient(env, obj, 0);

0 commit comments

Comments
 (0)