Unverified Commit 575edff1 authored by Roman Sedaikin's avatar Roman Sedaikin Committed by GitHub

Fix case when DirectSoftware on linux [getSurface] could throw [Can't wrap nullptr] (#253)

parent 375a3792
......@@ -46,7 +46,7 @@ public:
extern "C"
{
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_LinuxSoftwareRedrawer_createDevice(
JNIEnv *env, jobject redrawer, jlong displayPtr, jlong windowPtr)
JNIEnv *env, jobject redrawer, jlong displayPtr, jlong windowPtr, jint width, jint height)
{
Display *display = fromJavaPointer<Display *>(displayPtr);
Window window = fromJavaPointer<Window>(windowPtr);
......@@ -59,6 +59,13 @@ extern "C"
{
return 0L;
}
device->surface.reset();
SkImageInfo info = SkImageInfo::Make(
width, height, device->colorSpace, kPremul_SkAlphaType,
SkColorSpace::MakeSRGB());
device->surface = SkSurface::MakeRaster(info);
return toJavaPointer(device);
}
......
......@@ -5,6 +5,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.swing.Swing
import org.jetbrains.skiko.FrameDispatcher
import org.jetbrains.skiko.FrameLimiter
import org.jetbrains.skiko.RenderException
import org.jetbrains.skiko.SkiaLayer
import org.jetbrains.skiko.SkiaLayerProperties
......@@ -37,7 +38,13 @@ internal abstract class AbstractDirectSoftwareRedrawer(
}
open fun resize(width: Int, height: Int) = resize(device, width, height)
fun getSurface() = Surface(getSurface(device))
fun getSurface(): Surface {
val surface = getSurface(device)
if (surface == 0L) {
throw RenderException("Failed to create Surface")
}
return Surface(surface)
}
open fun finishFrame() = finishFrame(device)
override fun dispose() {
disposeDevice(device)
......
......@@ -8,8 +8,11 @@ internal class LinuxSoftwareRedrawer(
) : AbstractDirectSoftwareRedrawer(layer, properties) {
init {
val scale = layer.contentScale
val w = (layer.width * scale).toInt().coerceAtLeast(0)
val h = (layer.height * scale).toInt().coerceAtLeast(0)
layer.backedLayer.lockLinuxDrawingSurface {
device = createDevice(it.display, it.window).also {
device = createDevice(it.display, it.window, w, h).also {
if (it == 0L) {
throw RenderException("Failed to create Software device")
}
......@@ -29,5 +32,5 @@ internal class LinuxSoftwareRedrawer(
super.finishFrame()
}
private external fun createDevice(display: Long, window: Long): Long
private external fun createDevice(display: Long, window: Long, width: Int, height: Int): Long
}
\ No newline at end of file
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