Pause framebuffer updates when app is in background
This commit is contained in:
parent
425e25d10f
commit
505abaa0b1
5 changed files with 44 additions and 4 deletions
|
|
@ -412,7 +412,16 @@ extern "C"
|
|||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_gaurav_avnc_vnc_VncClient_nativeRefreshFrameBuffer(JNIEnv *env, jobject thiz, jlong clientPtr) {
|
||||
auto client = (rfbClient *) clientPtr;
|
||||
return (jboolean) SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, FALSE);
|
||||
return (jboolean) SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, TRUE);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_gaurav_avnc_vnc_VncClient_nativeSetAutomaticFramebufferUpdates(JNIEnv *env, jobject thiz, jlong client_ptr,
|
||||
jboolean enabled) {
|
||||
auto client = ((rfbClient *) client_ptr);
|
||||
client->automaticUpdateRequests = enabled ? TRUE : FALSE;
|
||||
if (enabled) SendIncrementalFramebufferUpdateRequest(client);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
|
|
|||
|
|
@ -121,12 +121,14 @@ class VncActivity : AppCompatActivity() {
|
|||
override fun onStart() {
|
||||
super.onStart()
|
||||
binding.frameView.onResume()
|
||||
viewModel.resumeFrameBufferUpdates()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
virtualKeys.releaseMetaKeys()
|
||||
binding.frameView.onPause()
|
||||
viewModel.pauseFrameBufferUpdates()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
|
|
|||
|
|
@ -343,6 +343,14 @@ class VncViewModel(val profile: ServerProfile, app: Application) : BaseViewModel
|
|||
}
|
||||
}
|
||||
|
||||
fun pauseFrameBufferUpdates() {
|
||||
client.setAutomaticFrameBufferUpdates(false)
|
||||
}
|
||||
|
||||
fun resumeFrameBufferUpdates() {
|
||||
client.setAutomaticFrameBufferUpdates(true)
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* [VncClient.Observer] Implementation
|
||||
**************************************************************************/
|
||||
|
|
|
|||
|
|
@ -99,6 +99,11 @@ class VncClient(private val observer: Observer) {
|
|||
@Volatile
|
||||
var ignorePointerMovesByServer = false
|
||||
|
||||
|
||||
@Volatile
|
||||
private var autoFBRequestsQueued = true
|
||||
private var autoFBRequests = autoFBRequestsQueued
|
||||
|
||||
/**
|
||||
* Setup different properties for this client.
|
||||
*
|
||||
|
|
@ -134,6 +139,11 @@ class VncClient(private val observer: Observer) {
|
|||
connected = false
|
||||
throw IOException(nativeGetLastErrorStr())
|
||||
}
|
||||
|
||||
if (autoFBRequests != autoFBRequestsQueued) {
|
||||
autoFBRequests = autoFBRequestsQueued
|
||||
nativeSetAutomaticFramebufferUpdates(nativePtr, autoFBRequests)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,9 +208,19 @@ class VncClient(private val observer: Observer) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sends a request for full frame buffer update to remote server.
|
||||
* Sends frame buffer update request to remote server.
|
||||
*/
|
||||
fun refreshFrameBuffer() = nativeRefreshFrameBuffer(nativePtr)
|
||||
fun refreshFrameBuffer() = ifConnected {
|
||||
nativeRefreshFrameBuffer(nativePtr)
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether framebuffer update requests are sent automatically.
|
||||
* It takes effect after the next call to [processServerMessage].
|
||||
*/
|
||||
fun setAutomaticFrameBufferUpdates(enabled: Boolean) = ifConnected {
|
||||
autoFBRequestsQueued = enabled
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts framebuffer contents in currently active OpenGL texture.
|
||||
|
|
@ -242,6 +262,7 @@ class VncClient(private val observer: Observer) {
|
|||
private external fun nativeSendCutText(clientPtr: Long, bytes: ByteArray, isUTF8: Boolean): Boolean
|
||||
private external fun nativeSetDesktopSize(clientPtr: Long, width: Int, height: Int): Boolean
|
||||
private external fun nativeRefreshFrameBuffer(clientPtr: Long): Boolean
|
||||
private external fun nativeSetAutomaticFramebufferUpdates(clientPtr: Long, enabled: Boolean)
|
||||
private external fun nativeGetDesktopName(clientPtr: Long): String
|
||||
private external fun nativeGetWidth(clientPtr: Long): Int
|
||||
private external fun nativeGetHeight(clientPtr: Long): Int
|
||||
|
|
|
|||
2
extern/libvncserver
vendored
2
extern/libvncserver
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 7e0cdac4391dc6fea46c0552479c3a461d8811a6
|
||||
Subproject commit ea809211332c435877fd1a3a2de1d8c4fefb4d5b
|
||||
Loading…
Add table
Reference in a new issue