Commit 9b9bea5f authored by Igor Demin's avatar Igor Demin

Schedule redraw on resize and initialization

We probably shouldn't perform frame rendering in init/setBounds.
Because in onRender we can call window.setBounds.
It will cause drawing onRender inside another onRender.

After the fix there is no increase in artifacts on start or resize.

"True" fix would be to call "repaint" instead of manual scheduling redrawing with "invokeLater", because paint events have higher priority than usual events.

But "repaint" doesn't work with Canvas. It is only works with Swing components.
We can extend JLayeredPane instead of HardwareLayer (and just add HardwareLayer to JLayeredPane).
But there are too much changes.

Anyway, system draws Window independently of AWT, so we probably can't get rid of artifacts if we use only AWT.
parent f1ce1d44
...@@ -7,13 +7,10 @@ import org.jetbrains.skija.PictureRecorder ...@@ -7,13 +7,10 @@ import org.jetbrains.skija.PictureRecorder
import org.jetbrains.skija.Rect import org.jetbrains.skija.Rect
import org.jetbrains.skiko.context.ContextHandler import org.jetbrains.skiko.context.ContextHandler
import org.jetbrains.skiko.context.createContextHandler import org.jetbrains.skiko.context.createContextHandler
import org.jetbrains.skiko.context.SoftwareContextHandler
import org.jetbrains.skiko.redrawer.SoftwareRedrawer
import org.jetbrains.skiko.redrawer.Redrawer import org.jetbrains.skiko.redrawer.Redrawer
import java.awt.Graphics import java.awt.Graphics
import javax.swing.SwingUtilities.invokeLater
import javax.swing.SwingUtilities.isEventDispatchThread import javax.swing.SwingUtilities.isEventDispatchThread
import kotlin.collections.MutableList
import kotlin.collections.toMutableList
interface SkiaRenderer { interface SkiaRenderer {
fun onRender(canvas: Canvas, width: Int, height: Int, nanoTime: Long) fun onRender(canvas: Canvas, width: Int, height: Int, nanoTime: Long)
...@@ -45,7 +42,7 @@ open class SkiaLayer( ...@@ -45,7 +42,7 @@ open class SkiaLayer(
contextHandler = createContextHandler(this, initialRenderApi) contextHandler = createContextHandler(this, initialRenderApi)
redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties) redrawer = platformOperations.createRedrawer(this, initialRenderApi, properties)
redrawer?.syncSize() redrawer?.syncSize()
redrawer?.redrawImmediately() redraw()
} }
override fun dispose() { override fun dispose() {
...@@ -62,15 +59,35 @@ open class SkiaLayer( ...@@ -62,15 +59,35 @@ open class SkiaLayer(
override fun setBounds(x: Int, y: Int, width: Int, height: Int) { override fun setBounds(x: Int, y: Int, width: Int, height: Int) {
super.setBounds(x, y, width, height) super.setBounds(x, y, width, height)
redrawer?.syncSize() redrawer?.syncSize()
redrawer?.redrawImmediately() redraw()
} }
override fun paint(g: Graphics) { override fun paint(g: Graphics) {
super.paint(g) super.paint(g)
redrawer?.syncSize() redrawer?.syncSize()
needRedraw() redrawer?.redrawImmediately()
}
private var redrawScheduled = false
/**
* Redraw as soon as possible (but not right now)
*/
fun redraw() {
if (!redrawScheduled) {
redrawScheduled = true
invokeLater {
redrawScheduled = false
if (!isDisposed) {
redrawer?.redrawImmediately()
}
}
}
} }
/**
* Redraw on the next animation Frame (on vsync signal if vsync is enabled).
*/
fun needRedraw() { fun needRedraw() {
check(!isDisposed) check(!isDisposed)
check(isEventDispatchThread()) check(isEventDispatchThread())
......
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