-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Linux OpenGL renderer to another thread. #351
base: master
Are you sure you want to change the base?
Conversation
To avoid Swing thread to be wasted. It should reduce input lag from input events.
if (!isVideoCardSupported(layer.renderApi)) { | ||
throw RenderException("Cannot create Linux GL context") | ||
} | ||
it.setSwapIntervalFast(defaultSwapInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems here setSwapInterval
shall be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setSwapIntervalFast
implemented in a way, that it has uninitialized value -1
, so setSwapIntervalFast will work, and it is more consistent with the other code than simple setSwapInterval
@@ -95,6 +125,12 @@ internal class LinuxOpenGLRedrawer( | |||
.filterNot(LinuxOpenGLRedrawer::isDisposed) | |||
.filter { it.layer.isShowing } | |||
|
|||
private val drawDispatcher = Executors.newSingleThreadExecutor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So all drawing happens in this thread, no matter how many open windows we got?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe write comment, and also on how we ensure that no races on drawing context happen?
private fun draw() { | ||
layer.inDrawScope(layer::draw) | ||
private suspend fun draw(withVsync: Boolean) { | ||
layer.inDrawScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shalln't we swap the order and do
inDrawThread {
layer.inDrawScope {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, inDrawScope should be called in Swing thread, as it contain fallback
logic
it.swapBuffers() | ||
OpenGLApi.instance.glFinish() | ||
it.setSwapInterval(swapInterval) | ||
runBlocking { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we'll block AWT thread here? Shall we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the semantic of this method is to draw the content in a blocking way, but without vsync synchronization
With this patch VirtualBox with OpenGL hardware acceleration hard locks the VM when running JVM sample. |
I was afraid of it, but didn't reproduce on the real machine :(. It seems it is because of Will investigate, and if it is not simple, do it after Compose 1.0 |
To avoid Swing thread to be wasted.
It should reduce input lag from input events.