Skip to content
Merged
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
@@ -0,0 +1,43 @@
import org.jetbrains.skia.ColorSpace
import org.jetbrains.skia.PixelGeometry
import org.jetbrains.skia.Surface
import org.jetbrains.skia.SurfaceColorFormat
import org.jetbrains.skia.SurfaceOrigin
import org.jetbrains.skia.SurfaceProps
import org.jetbrains.skiko.ExperimentalSkikoApi
import org.jetbrains.skiko.graphicapi.DirectXOffscreenContext
import org.jetbrains.skiko.hostOs

@OptIn(ExperimentalSkikoApi::class)
fun graphicsContext(): GraphicsContext? = when {
hostOs.isWindows -> DirectXGraphicsContext()
else -> {
println("Unsupported desktop host OS: $hostOs. Using non-GPU graphic context")
null
}
}

@OptIn(ExperimentalSkikoApi::class)
class DirectXGraphicsContext() : GraphicsContext {
// Note: we don't close `context` and `texture` after using,
// because it is created once in the main function
private val context = DirectXOffscreenContext()
private var texture: DirectXOffscreenContext.Texture? = null

override fun surface(width: Int, height: Int): Surface {
texture?.close()
texture = context.Texture(width, height)
return Surface.makeFromBackendRenderTarget(
context.directContext,
texture!!.backendRenderTarget,
SurfaceOrigin.TOP_LEFT,
SurfaceColorFormat.BGRA_8888,
ColorSpace.sRGB,
SurfaceProps(pixelGeometry = PixelGeometry.UNKNOWN)
) ?: throw IllegalStateException("Can't create Surface")
}

override suspend fun awaitGPUCompletion() {
texture?.waitForCompletion()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fun main(args: Array<String>) {
// Start the benchmark server to receive results from browsers
BenchmarksSaveServer.start()
} else {
runBlocking(Dispatchers.Main) { runBenchmarks() }
runBlocking(Dispatchers.Main) { runBenchmarks(graphicsContext = graphicsContext()) }
}
}