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