WebView (macOS): don't promote WKWebView to layer-backed for bg colour (fixes secondary-monitor blur) - #34
Merged
Conversation
The background-colour path (withBackgroundColour, used to kill the first-paint white flash) promoted the WKWebView via setWantsLayer:YES plus a transparent layer.backgroundColor. That promotion pins the view's root-layer contentsScale at creation time, so moving the host window to a display with a different backingScaleFactor leaves high-DPI content composited into a stale backing — it reads as blurry on the secondary monitor. Drop the setWantsLayer/clear-layer block. Left layer-hosting (the WKWebView default, as used by CHOC/wry/Safari) WebKit keeps the backing scale in sync across display moves on its own. drawsBackground = NO plus setUnderPageBackgroundColor still suppress the first-paint flash without touching the layer. The viewDidChangeBackingProperties re-stamp added earlier to chase the pinning is left in place as a harmless backing-scale safety net. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some users report the player webview rendering blurry on a secondary monitor (Retina ↔ non-Retina, or two displays at different scales).
Root cause: the macOS background-colour path (
AppleWkWebView::withBackgroundColour, which we use to suppress the first-paint white flash) promoted theWKWebViewto a layer-backed view:That promotion pins the view's root-layer
contentsScaleat creation time. When the host window then moves to a display with a differentbackingScaleFactor, high-DPI content is composited into a stale backing and reads as pixelated/blurry. A plain (layer-hosting)WKWebView— what CHOC, wry and Safari use — lets WebKit keep the backing scale in sync across display moves automatically.Change
Drop the
setWantsLayer:YES+ transparentlayer.backgroundColorblock. The WKWebView stays layer-hosting (its default). First-paint flash suppression is unchanged — it relied ondrawsBackground = NOandsetUnderPageBackgroundColor, both kept. The under-page background now shows the chrome colour rather than a clear layer.The
viewDidChangeBackingPropertiesre-stamp (added in #32 to chase the pinning) is left in place as a harmless backing-scale safety net.Testing
🤖 Generated with Claude Code