Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ actual open class SkiaLayer internal constructor(
private val analytics: SkiaLayerAnalytics = SkiaLayerAnalytics.Empty,
actual val pixelGeometry: PixelGeometry = PixelGeometry.UNKNOWN,
) : JPanel() {
actual val clearColor: Int = properties.clearColor

internal companion object {
init {
Expand Down
5 changes: 5 additions & 0 deletions skiko/src/commonMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ expect open class SkiaLayer {
*/
var renderDelegate: SkikoRenderDelegate?

/**
* Clear color for the canvas.
*/
val clearColor: Int

/**
* Attach this [SkikoRenderDelegate] to platform container.
* Actual type of attach container is platform-specific.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal abstract class ContextHandler(
}
initCanvas()
canvas?.apply {
clear(if (isTransparentBackground()) Color.TRANSPARENT else Color.WHITE)
clear(if (isTransparentBackground()) Color.TRANSPARENT else layer.clearColor)
drawContent()
}
flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ actual open class SkiaLayer {
if (value) throw Exception("Transparency is not supported!")
}

/**
* Clear color for the canvas.
*/
actual val clearColor: Int = org.jetbrains.skia.Color.WHITE

/**
* Schedules a drawFrame to the appropriate moment.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class SkiaLayerProperties(
val renderApi: GraphicsApi = SkikoProperties.renderApi,
val adapterPriority: GpuPriority = SkikoProperties.gpuPriority,
) {
val clearColor: Int = clearColorFromSystem()

override fun equals(other: Any?): Boolean {
if (this === other) return true

Expand Down Expand Up @@ -56,4 +58,21 @@ class SkiaLayerProperties(
result = 31 * result + adapterPriority.hashCode()
return result
}

companion object {
var defaultClearColor: Int = org.jetbrains.skia.Color.WHITE

fun clearColorFromSystem(): Int {
val colorFromEnv = System.getProperty("SKIKO_CLEAR_COLOR")?.let {
try {
if (it[0] == '#') {
it.drop(1).toInt(16)
} else {
it.toInt()
}
} catch (_: Exception) { null }
}
return colorFromEnv ?: defaultClearColor
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ actual open class SkiaLayer {
actual var transparency: Boolean
get() = TODO("Not yet implemented")
set(value) {}
actual val clearColor: Int
get() = TODO("Not yet implemented")
actual val component: Any?
get() = TODO("Not yet implemented")
actual fun needRedraw() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ actual open class SkiaLayer {
field = value
}

actual val clearColor: Int = Color.WHITE

/**
* The scale factor of [NSWindow]
* https://developer.apple.com/documentation/appkit/nswindow/1419459-backingscalefactor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.skiko

import kotlinx.cinterop.useContents
import org.jetbrains.skia.Canvas
import org.jetbrains.skia.Color
import org.jetbrains.skia.PixelGeometry
import org.jetbrains.skia.Surface
import platform.UIKit.*
Expand All @@ -25,6 +26,8 @@ actual open class SkiaLayer {
get() = false
set(_) { throw UnsupportedOperationException() }

actual val clearColor: Int = Color.WHITE

actual fun needRedraw() {
needRedrawCallback.invoke()
}
Expand Down