Unverified Commit 95f85e7a authored by Alexander Maryanovsky's avatar Alexander Maryanovsky Committed by GitHub

Don't persist cutout clip in ContextHandler (#1177)

parent 5d78bcc8
......@@ -1375,14 +1375,13 @@ class SkiaLayerTest {
}
swingComponent.bounds = Rectangle(0, 200, 300, 100)
layer.clipComponents.add(
ClipRectangle(
x = swingComponent.x.toFloat(),
y = swingComponent.y.toFloat(),
width = swingComponent.width.toFloat(),
height = swingComponent.height.toFloat()
)
val clipRect = ClipRectangle(
x = swingComponent.x.toFloat(),
y = swingComponent.y.toFloat(),
width = swingComponent.width.toFloat(),
height = swingComponent.height.toFloat()
)
layer.clipComponents.add(clipRect)
layeredPane.add(layer, BorderLayout.CENTER)
layeredPane.add(swingComponent, BorderLayout.CENTER, 0)
......@@ -1396,6 +1395,7 @@ class SkiaLayerTest {
window.isUndecorated = true
window.isVisible = true
delay(100)
withContext(Dispatchers.Default) {
Robot().waitForIdle()
}
......@@ -1404,7 +1404,21 @@ class SkiaLayerTest {
// - Red, from the layer content
// - Yellow, from the layer background
// - Green, from the Swing component
screenshots.assert(window.bounds, "frame")
screenshots.assert(window.bounds, "frame_1")
// Remove the swingComponent and its clip
layeredPane.remove(swingComponent)
layer.clipComponents.remove(clipRect)
delay(100)
withContext(Dispatchers.Default) {
Robot().waitForIdle()
}
// Expect to see two layers:
// - Red, from the layer content
// - Yellow, from the layer background (twice as tall as the Red)
screenshots.assert(window.bounds, "frame_2")
} finally {
window.close()
}
......
......@@ -40,7 +40,7 @@ internal abstract class ContextHandler(
throw RenderException("Cannot init graphic context")
}
initCanvas()
canvas?.apply {
canvas?.runRestoringState {
clear(Color.TRANSPARENT)
val scale = layer.contentScale
......@@ -83,4 +83,13 @@ internal inline fun Canvas.cutoutFromClip(rectangle: ClipRectangle, scale: Float
mode = ClipMode.DIFFERENCE,
antiAlias = true
)
}
private inline fun Canvas.runRestoringState(block: Canvas.() -> Unit) {
val restoreCount = save()
try {
block()
} finally {
restoreToCount(restoreCount)
}
}
\ No newline at end of file
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