Skip to content

Eliminate background flash on first window show - #1237

Merged
Alexander Maryanovsky (m-sasha) merged 13 commits into
masterfrom
m-sasha/fix-flash-on-first-window-show
Aug 7, 2026
Merged

Eliminate background flash on first window show#1237
Alexander Maryanovsky (m-sasha) merged 13 commits into
masterfrom
m-sasha/fix-flash-on-first-window-show

Conversation

@m-sasha

@m-sasha Alexander Maryanovsky (m-sasha) commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Comment thread skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt Outdated
Comment thread skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm Outdated
Comment thread skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt Outdated
* Only called when [supportsRenderingBeforeShown] is `true`. Implementations must present the frame in a
* way that the window's first on-screen composite reflects it rather than the background.
*/
protected open fun renderBeforeShown() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also perform a force render inside Compose. How is it coordinated with this change? Do you plan to remove it, call conditionally, or just keep the double call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to remove the workaround from Compose.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it should be removed when we implement all the renderers, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how Metal-specific this PR is, really. It's possible that supportsRenderingBeforeShown is not needed and we can, as a default, call renderImmediately (which is what we do from Compose anyway). If this turns out to be true, then we're just moving the current workaround from Compose into Skiko while allowing some renderers to do it even better, by writing their own renderer-specific code.

I will know better when I implement it for Direct3D.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, before merging this, create a PR in Compose to remove the render in Compose, to be sure that you can implement it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a PR because skiko needs to be published first, but here's the branch:
https://github.com/JetBrains/compose-multiplatform-core/tree/m-sasha/integrate-skiko-fixes

Comment thread skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a macOS Metal-specific visual artifact where the window background briefly flashes on the very first window show in a fresh process, by ensuring a first frame is rendered/presented while the window is displayable but not yet visible.

Changes:

  • Add an AWT redrawer hook to render/present a frame before the component is shown, and implement it for Metal.
  • Split Metal present paths into async vs sync JNI entrypoints to support “render-before-shown” and live-resize transactional presentation.
  • Add an AWT test that spawns a fresh JVM harness and samples screen pixels to detect first-show flashes.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt Adds a regression test that spawns a fresh JVM and samples pixels to detect first-show flashes; adds a window-open await helper.
skiko/src/awtTest/kotlin/org/jetbrains/skiko/FirstWindowShowFlashHelper.kt Adds a standalone child-process harness that renders an expensive first frame for flash detection.
skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm Renames/splits JNI entrypoints into async vs sync frame finishing and expands sync present rationale.
skiko/src/awtMain/kotlin/org/jetbrains/skiko/SkiaLayer.awt.kt Minor import/formatting adjustments (not behavior-changing).
skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.kt Implements “render before shown” for Metal and routes presentation through async/sync finish methods.
skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/AWTRedrawer.kt Renders eagerly on resize when displayable-but-not-showing for redrawers that support it.
skiko/src/awtMain/kotlin/org/jetbrains/skiko/context/MetalContextHandler.kt Renames/splits finishFrame API into async vs sync to match native entrypoints.
Comments suppressed due to low confidence (1)

skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt:56

  • Unused import: Duration.Companion.nanoseconds is imported but not referenced in this file.
import kotlin.time.Duration.Companion.nanoseconds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread skiko/src/awtMain/kotlin/org/jetbrains/skiko/redrawer/AWTRedrawer.kt Outdated
Comment thread skiko/src/awtMain/objectiveC/macos/MetalContextHandler.mm Outdated
Comment thread skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt Outdated
Comment thread skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt
Comment thread skiko/src/awtTest/kotlin/org/jetbrains/skiko/SkiaLayerTest.kt Outdated
@m-sasha
Alexander Maryanovsky (m-sasha) force-pushed the m-sasha/fix-flash-on-first-window-show branch from d92e682 to 46cec4c Compare August 6, 2026 15:27
@m-sasha
Alexander Maryanovsky (m-sasha) force-pushed the m-sasha/fix-flash-on-first-window-show branch from ff66954 to 310b526 Compare August 6, 2026 15:29
@m-sasha Alexander Maryanovsky (m-sasha) changed the title [Metal] Eliminate background flash on first window show Eliminate background flash on first window show Aug 6, 2026

@igordmn Igor Demin (igordmn) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please coordinate with Ivan Matkov (@MatkovIvan) what should be merged first and what should be adapted:
#1234

Comment thread skiko/src/awtMain/kotlin/org/jetbrains/skiko/SkiaLayer.awt.kt Outdated
@m-sasha
Alexander Maryanovsky (m-sasha) force-pushed the m-sasha/fix-flash-on-first-window-show branch from 0d3816a to 257f270 Compare August 6, 2026 20:24
@m-sasha
Alexander Maryanovsky (m-sasha) deleted the m-sasha/fix-flash-on-first-window-show branch August 7, 2026 10:26
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