Skip to content

Commit

Permalink
Redraw immediately on panel size change (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed May 28, 2024
1 parent 82da8dd commit c66eebc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions skiko/src/awtMain/kotlin/org/jetbrains/skiko/SkiaLayer.awt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ actual open class SkiaLayer internal constructor(
jComponent.add(this)
}

private var keyEvent: KeyEvent? = null

val clipComponents = mutableListOf<ClipRectangle>()

@Volatile
Expand Down Expand Up @@ -312,13 +310,32 @@ actual open class SkiaLayer internal constructor(
override fun paint(g: java.awt.Graphics) {
Logger.debug { "Paint called on: $this" }
checkContentScale()
tryRedrawImmediately()
}

override fun setBounds(x: Int, y: Int, width: Int, height: Int) {
super.setBounds(x, y, width, height)

// 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) {
redrawer?.syncSize()
tryRedrawImmediately()
}
}

// `paint` can be called when we already inside `draw` method.
private fun tryRedrawImmediately() {
if (!isShowing) return

// It might be called inside `renderDelegate`,
// so to avoid recursive call (not supported) just schedule redrawing.
//
// For example if we call some AWT function inside renderer.onRender,
// such as `jframe.isEnabled = false` on Linux
//
// To avoid recursive call of `draw` (we don't support recursive calls) we just schedule redrawing.
if (isRendering) {
redrawer?.needRedraw()
} else {
Expand Down

0 comments on commit c66eebc

Please sign in to comment.