Unverified Commit e7c30e9e authored by Roman Sedaikin's avatar Roman Sedaikin Committed by GitHub

Fix crash when transparent window displayed on external display on linux. (#348)

* Fix crash when transparent window displayed on external display on linux.
parent 2bc9c86e
......@@ -88,9 +88,6 @@ actual open class SkiaLayer internal constructor(
if (it.changeFlags and HierarchyEvent.SHOWING_CHANGED.toLong() != 0L) {
checkShowing()
}
if (it.changeFlags and HierarchyEvent.DISPLAYABILITY_CHANGED.toLong() != 0L) {
checkInit()
}
}
}
......@@ -99,6 +96,14 @@ actual open class SkiaLayer internal constructor(
super.removeNotify()
}
override fun addNotify() {
super.addNotify()
backedLayer.defineContentScale()
checkShowing()
init(isInited)
}
actual fun detach() {
dispose()
}
......@@ -106,14 +111,6 @@ actual open class SkiaLayer internal constructor(
private var isInited = false
private var isRendering = false
private fun checkInit() {
if (!isInited && isDisplayable) {
backedLayer.defineContentScale()
checkShowing()
init()
}
}
private fun checkShowing() {
isShowingCached = super.isShowing()
if (isShowing) {
......@@ -229,7 +226,7 @@ actual open class SkiaLayer internal constructor(
@Volatile
private var picture: PictureHolder? = null
private val pictureRecorder = PictureRecorder()
private var pictureRecorder: PictureRecorder? = null
private val pictureLock = Any()
private fun findNextWorkingRenderApi() {
......@@ -254,8 +251,13 @@ actual open class SkiaLayer internal constructor(
}
}
protected open fun init() {
protected open fun init(recreation: Boolean = false) {
isDisposed = false
backedLayer.init()
pictureRecorder = PictureRecorder()
if (recreation) {
fallbackRenderApiQueue.add(0, renderApi)
}
findNextWorkingRenderApi()
isInited = true
}
......@@ -275,12 +277,16 @@ actual open class SkiaLayer internal constructor(
open fun dispose() {
check(isEventDispatchThread()) { "Method should be called from AWT event dispatch thread" }
if (isInited && !isDisposed) {
redrawer?.dispose() // we should dispose redrawer first (to cancel `draw` in rendering thread)
// we should dispose redrawer first (to cancel `draw` in rendering thread)
redrawer?.dispose()
redrawer = null
contextHandler?.dispose()
contextHandler = null
picture?.instance?.close()
pictureRecorder.close()
picture = null
pictureRecorder?.close()
pictureRecorder = null
backedLayer.dispose()
isDisposed = true
}
......@@ -413,7 +419,7 @@ actual open class SkiaLayer internal constructor(
val pictureHeight = (height * contentScale).toInt().coerceAtLeast(0)
val bounds = Rect.makeWH(pictureWidth.toFloat(), pictureHeight.toFloat())
val canvas = pictureRecorder.beginRecording(bounds)
val canvas = pictureRecorder!!.beginRecording(bounds)
// clipping
for (component in clipComponents) {
......@@ -431,7 +437,7 @@ actual open class SkiaLayer internal constructor(
if (!isDisposed) {
synchronized(pictureLock) {
picture?.instance?.close()
val picture = pictureRecorder.finishRecordingAsPicture()
val picture = pictureRecorder!!.finishRecordingAsPicture()
this.picture = PictureHolder(picture, pictureWidth, pictureHeight)
}
}
......
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