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 { ...@@ -1375,14 +1375,13 @@ class SkiaLayerTest {
} }
swingComponent.bounds = Rectangle(0, 200, 300, 100) swingComponent.bounds = Rectangle(0, 200, 300, 100)
layer.clipComponents.add( val clipRect = ClipRectangle(
ClipRectangle(
x = swingComponent.x.toFloat(), x = swingComponent.x.toFloat(),
y = swingComponent.y.toFloat(), y = swingComponent.y.toFloat(),
width = swingComponent.width.toFloat(), width = swingComponent.width.toFloat(),
height = swingComponent.height.toFloat() height = swingComponent.height.toFloat()
) )
) layer.clipComponents.add(clipRect)
layeredPane.add(layer, BorderLayout.CENTER) layeredPane.add(layer, BorderLayout.CENTER)
layeredPane.add(swingComponent, BorderLayout.CENTER, 0) layeredPane.add(swingComponent, BorderLayout.CENTER, 0)
...@@ -1396,6 +1395,7 @@ class SkiaLayerTest { ...@@ -1396,6 +1395,7 @@ class SkiaLayerTest {
window.isUndecorated = true window.isUndecorated = true
window.isVisible = true window.isVisible = true
delay(100)
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
Robot().waitForIdle() Robot().waitForIdle()
} }
...@@ -1404,7 +1404,21 @@ class SkiaLayerTest { ...@@ -1404,7 +1404,21 @@ class SkiaLayerTest {
// - Red, from the layer content // - Red, from the layer content
// - Yellow, from the layer background // - Yellow, from the layer background
// - Green, from the Swing component // - 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 { } finally {
window.close() window.close()
} }
......
...@@ -40,7 +40,7 @@ internal abstract class ContextHandler( ...@@ -40,7 +40,7 @@ internal abstract class ContextHandler(
throw RenderException("Cannot init graphic context") throw RenderException("Cannot init graphic context")
} }
initCanvas() initCanvas()
canvas?.apply { canvas?.runRestoringState {
clear(Color.TRANSPARENT) clear(Color.TRANSPARENT)
val scale = layer.contentScale val scale = layer.contentScale
...@@ -84,3 +84,12 @@ internal inline fun Canvas.cutoutFromClip(rectangle: ClipRectangle, scale: Float ...@@ -84,3 +84,12 @@ internal inline fun Canvas.cutoutFromClip(rectangle: ClipRectangle, scale: Float
antiAlias = true 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