Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
igordmn committed Sep 16, 2024
1 parent 3d9124f commit 62394a4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions skiko/src/awtMain/kotlin/org/jetbrains/skiko/SkiaLayer.awt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import javax.swing.JPanel
import javax.swing.SwingUtilities
import javax.swing.SwingUtilities.isEventDispatchThread
import javax.swing.UIManager
import javax.swing.event.AncestorEvent
import javax.swing.event.AncestorListener

actual open class SkiaLayer internal constructor(
externalAccessibleFactory: ((Component) -> Accessible)? = null,
Expand Down Expand Up @@ -133,6 +135,16 @@ actual open class SkiaLayer internal constructor(
@Suppress("LeakingThis")
add(backedLayer)

addAncestorListener(object : AncestorListener {
override fun ancestorAdded(event: AncestorEvent?) = Unit

override fun ancestorRemoved(event: AncestorEvent?) = Unit

override fun ancestorMoved(event: AncestorEvent?) {
redrawer?.syncBounds()
}
})

backedLayer.addHierarchyListener {
if (it.changeFlags and HierarchyEvent.SHOWING_CHANGED.toLong() != 0L) {
checkShowing()
Expand Down Expand Up @@ -317,6 +329,12 @@ actual open class SkiaLayer internal constructor(
}
}

override fun doLayout() {
Logger.debug { "doLayout on $this" }
adjustBackedLayerSize()
redrawer?.syncBounds()
}

override fun paint(g: java.awt.Graphics) {
Logger.debug { "Paint called on: $this" }
checkContentScale()
Expand All @@ -326,17 +344,14 @@ actual open class SkiaLayer internal constructor(
override fun setBounds(x: Int, y: Int, width: Int, height: Int) {
super.setBounds(x, y, width, height)

Logger.debug { "setBounds on $this" }
adjustBackedLayerSize()
redrawer?.syncBounds()

// To avoid visual artifacts on Windows/Direct3D,
// redrawing should be performed immediately, without scheduling to "later".
// Subscribing to events instead of overriding this method won't help too.
//
// Please note that calling redraw during layout might break software renderers,
// so applying this fix only for Direct3D case.
if (renderApi == GraphicsApi.DIRECT3D && isShowing) {
redrawer?.syncBounds()
tryRedrawImmediately()
}
}
Expand Down

0 comments on commit 62394a4

Please sign in to comment.