@@ -18,7 +18,10 @@ import dev.silenium.compose.gl.context.GLContextProvider
18
18
import dev.silenium.compose.gl.context.GLContextProviderFactory
19
19
import dev.silenium.compose.gl.directContext
20
20
import dev.silenium.compose.gl.fbo.*
21
- import kotlinx.coroutines.*
21
+ import kotlinx.coroutines.CancellationException
22
+ import kotlinx.coroutines.Dispatchers
23
+ import kotlinx.coroutines.isActive
24
+ import kotlinx.coroutines.withContext
22
25
import org.jetbrains.skia.*
23
26
import org.lwjgl.opengl.GL
24
27
import org.lwjgl.opengl.GL30.GL_RGBA8
@@ -60,8 +63,8 @@ fun GLSurfaceView(
60
63
presentMode : GLSurfaceView .PresentMode = GLSurfaceView .PresentMode .FIFO ,
61
64
swapChainSize : Int = 10,
62
65
fboSizeOverride : FBOSizeOverride ? = null,
63
- cleanup : suspend () -> Unit = {},
64
- draw : suspend GLDrawScope .() -> Unit ,
66
+ cleanup : () -> Unit = {},
67
+ draw : GLDrawScope .() -> Unit ,
65
68
) {
66
69
var invalidations by remember { mutableStateOf(0 ) }
67
70
val surfaceView = remember {
@@ -139,8 +142,8 @@ fun GLSurfaceView(
139
142
class GLSurfaceView internal constructor(
140
143
private val state : GLSurfaceState ,
141
144
private val parentContext : GLContext <* >,
142
- private val drawBlock : suspend GLDrawScope .() -> Unit ,
143
- private val cleanupBlock : suspend () -> Unit = {},
145
+ private val drawBlock : GLDrawScope .() -> Unit ,
146
+ private val cleanupBlock : () -> Unit = {},
144
147
private val invalidate : () -> Unit = {},
145
148
private val paint : Paint = Paint (),
146
149
private val presentMode : PresentMode = PresentMode .MAILBOX ,
@@ -232,10 +235,8 @@ class GLSurfaceView internal constructor(
232
235
var lastFrame: Long? = null
233
236
while (! isInterrupted) {
234
237
val renderStart = System .nanoTime()
235
- val renderResult = runBlocking {
236
- val deltaTime = lastFrame?.let { renderStart - it } ? : 0
237
- fboPool!! .render(deltaTime.nanoseconds, drawBlock)
238
- }
238
+ val deltaTime = lastFrame?.let { renderStart - it } ? : 0
239
+ val renderResult = fboPool!! .render(deltaTime.nanoseconds, drawBlock)
239
240
val e = renderResult.exceptionOrNull()
240
241
if (e is NoRenderFBOAvailable ) {
241
242
logger.debug(" No FBO available, waiting for the next frame" )
@@ -266,7 +267,7 @@ class GLSurfaceView internal constructor(
266
267
}
267
268
}
268
269
logger.debug(" GLSurfaceView stopped" )
269
- runBlocking { cleanupBlock() }
270
+ cleanupBlock()
270
271
fboPool?.destroy()
271
272
fboPool = null
272
273
directContext?.close()
0 commit comments