• Igor Demin's avatar
    DirectXOffscreenContext to allow drawing into offscreen texture (#1016) · 1af72c1c
    Igor Demin authored
    Needed to run benchmarks without vsync interference.
    
    The code extracted from Direct3DSwingRedrawer with minimal changes.
    
    - implementation for other API will be added when it is needed (Metal is
    considered later)
    - there are no plans to make commonMain abstraction in `skiko` as it is
    not needed at the moment
    
    ## Testing
    - manually in benchmarks with this code:
    ```
    @OptIn(ExperimentalSkikoApi::class)
    class DirectXGraphicsContext() : DesktopGraphicsContext {
        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()
        }
    
        override fun close() {
            texture?.close()
            context.close()
        }
    }
    
    interface DesktopGraphicsContext : GraphicsContext, AutoCloseable
    ```
    - new test for SkiaSwingLayer
    - new test for DirectXOffscreenContext
    1af72c1c
Name
Last commit
Last update
.github Loading commit data...
.run Loading commit data...
gradle/wrapper Loading commit data...
samples Loading commit data...
skiko Loading commit data...
.gitignore Loading commit data...
DEVELOPMENT.md Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
gradle.properties Loading commit data...
gradlew Loading commit data...
gradlew.bat Loading commit data...
settings.gradle.kts Loading commit data...