Skip to content

Conversation

@m-sasha
Copy link
Contributor

@m-sasha m-sasha commented Dec 22, 2025

Changes:

  • Don't reset AWT SkiaLayer background when transparency is changed to fix https://youtrack.jetbrains.com/issue/CMP-8738
  • AWT SkiaLayer now subclasses JComponent instead of JPanel. One difference is that it's now not double-buffered at the Swing level, which should reduce the memory footprint somewhat.
  • [New] Clear layer with its background before calling the renderer. This means that if you want transparency, you will need to set the layer's background to a color with a non-opaque alpha component.

The CMP branch that uses these changes is https://github.com/JetBrains/compose-multiplatform-core/tree/m-sasha/fix-ComposePanel-background. To test, publish skiko to mavenLocal and change the version in libs.versions.toml.

Template for testing:

package org.jetbrains.skiko

import kotlinx.coroutines.delay
import org.jetbrains.skia.Canvas
import org.jetbrains.skia.Paint
import org.jetbrains.skia.Rect
import org.jetbrains.skiko.util.UiTestWindow
import org.jetbrains.skiko.util.uiTest
import org.junit.Before
import org.junit.Test
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.SystemColor.window
import java.awt.Window
import javax.swing.JFrame
import javax.swing.JLayeredPane
import kotlin.random.Random
import kotlin.time.Duration

class AdHocTest {

    @Before
    fun setup() {
        System.setProperty("skiko.test.ui.enabled", "true")
//        System.setProperty("skiko.test.ui.renderApi", "METAL")
    }

    @Test
    fun adHocTest() = uiTest {
        val panel = JLayeredPane()
        panel.layout = null
//        panel.background = java.awt.Color.BLUE

        fun UiTestWindow.setTransparency(transparency: Boolean) {
            isUndecorated = transparency
            background = if (transparency) java.awt.Color(255, 0, 0, 0) else java.awt.Color.WHITE
            rootPane.putClientProperty("Window.shadow", !transparency)
            layer.transparency = transparency
        }

        val window = UiTestWindow {
            size = Dimension(800, 800)

            layer.backgroundColor = 0x7f_ff_00_00U.toInt()
//            layer.background = null
            setTransparency(true)

            val circleColor = 0xff_00_ff_00U.toInt()
            layer.renderDelegate = SolidColorRenderer(Color(circleColor, true))

            layer.size = Dimension(300, 300)
            panel.add(layer)
            contentPane.add(panel, BorderLayout.CENTER)

        }

        window.isVisible = true
        delay(Duration.INFINITE)
    }


    private class SolidColorRenderer(color: Color) : SkikoRenderDelegate {

        val paint = Paint().also { it.color = color.rgb }

        override fun onRender(canvas: Canvas, width: Int, height: Int, nanoTime: Long) {
            canvas.drawCircle(width/2f, height/2f, width/2f, paint)
        }
    }

}

@m-sasha m-sasha force-pushed the m-sasha/fix-skialayer-background branch from 9319ae4 to 4dd20e9 Compare December 22, 2025 12:35
@m-sasha m-sasha force-pushed the m-sasha/fix-skialayer-background branch from 440af33 to 7da9af1 Compare January 6, 2026 13:27
@m-sasha m-sasha merged commit 9c3169a into master Jan 7, 2026
13 checks passed
@m-sasha m-sasha deleted the m-sasha/fix-skialayer-background branch January 7, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants