Unverified Commit fb3de434 authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Fix cases where OpenGL init fails later (#129)

parent 1edf9a7d
......@@ -80,9 +80,13 @@ extern "C"
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_LinuxOpenGLRedrawerKt_createContext(JNIEnv *env, jobject redrawer, jlong displayPtr)
{
Display *display = fromJavaPointer<Display *>(displayPtr);
if (!display) return 0;
GLint att[] = {GLX_RGBA, GLX_DOUBLEBUFFER, True, None};
XVisualInfo *vi = glXChooseVisual(display, 0, att);
if (!vi) return 0;
GLXContext *context = new GLXContext(glXCreateContext(display, vi, NULL, GL_TRUE));
return toJavaPointer(context);
}
......@@ -92,7 +96,9 @@ extern "C"
Display *display = fromJavaPointer<Display *>(displayPtr);
GLXContext *context = fromJavaPointer<GLXContext *>(contextPtr);
if (display && context) {
glXDestroyContext(display, *context);
delete context;
}
}
}
......@@ -112,11 +112,27 @@ open class SkiaLayer(
private val pictureRecorder = PictureRecorder()
private val pictureLock = Any()
open fun init() {
backedLayer.init()
private fun findNextWorkingRenderApi(redraw: Boolean) {
var thrown: Boolean
do {
thrown = false
try {
renderApi = fallbackRenderApiQueue.removeAt(0)
println("Trying $renderApi rendering...")
contextHandler?.dispose()
redrawer?.dispose()
contextHandler = createContextHandler(this, renderApi)
redrawer = platformOperations.createRedrawer(this, renderApi, properties)
if (redraw) redrawer!!.redrawImmediately()
} catch (e: IllegalArgumentException) {
thrown = true
}
} while (thrown)
}
open fun init() {
backedLayer.init()
findNextWorkingRenderApi(false)
onInit.complete(Unit)
}
......@@ -270,7 +286,7 @@ open class SkiaLayer(
return withContext(Dispatchers.Swing) {
check(!isDisposed)
onInit.await()
redrawer!!.awaitRedraw()
redrawer?.awaitRedraw() != false
}
}
......@@ -315,7 +331,7 @@ open class SkiaLayer(
check(!isDisposed)
contextHandler?.apply {
if (!initContext()) {
fallbackToNextApi()
findNextWorkingRenderApi(true)
return false
}
initCanvas()
......@@ -373,16 +389,6 @@ open class SkiaLayer(
)
}
private fun fallbackToNextApi() {
renderApi = fallbackRenderApiQueue.removeAt(0)
println("Falling back to $renderApi rendering...")
contextHandler?.dispose()
redrawer?.dispose()
contextHandler = createContextHandler(this, renderApi)
redrawer = platformOperations.createRedrawer(this, renderApi, properties)
redrawer!!.redrawImmediately()
}
private fun roundSize(value: Int): Int {
var rounded = value * contentScale
val diff = rounded - rounded.toInt()
......
......@@ -16,7 +16,7 @@ internal class LinuxOpenGLRedrawer(
private val properties: SkiaLayerProperties
) : Redrawer {
private val context = layer.backedLayer.lockDrawingSurface {
it.createContext()
it.createContext().also { if (it == 0L) throw IllegalArgumentException("Cannot create Linux GL context") }
}
private var isDisposed = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment