Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: d8266c6d0ba999557510ce09aa76750affcfc4cd
https://github.com/WebKit/WebKit/commit/d8266c6d0ba999557510ce09aa76750affcfc4cd
Author: Eric Carlson <[email protected]>
Date: 2026-06-25 (Thu, 25 Jun 2026)
Changed paths:
M
Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.h
M
Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm
M Source/WebCore/platform/mediastream/RealtimeMediaSourceSettings.cpp
M Source/WebCore/platform/mediastream/cocoa/AVVideoCaptureSource.mm
M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
A
Tools/TestWebKitAPI/Tests/WebCore/cocoa/LocalSampleBufferDisplayLayerTests.mm
Log Message:
-----------
[Cocoa] Transient device rotation can result in incorrect video frame
orientation
https://bugs.webkit.org/show_bug.cgi?id=317671
rdar://180429147
Reviewed by Youenn
Fablet.
When a WKWebView is created (e.g. for a new tab or background page),
_setupScrollAndContentViews
calls _dispatchSetOrientationForMediaCapture before the view has been placed in
a window. At
that point windowScene is nil, so _deviceOrientationIgnoringOverrides returns
UIInterfaceOrientationUnknown (mapped to 0°).
GPUProcess::setOrientationForMediaCapture
broadcasts this value to every connection, overwriting the correct landscape
orientation of
any camera source running on a different page. The camera then produces
permanently rotated
frames until the user physically rotates the device.
Guard _dispatchSetOrientationForMediaCapture against dispatching orientation=0
when windowScene
is nil: in that state 0 means Unknown rather than Portrait, so there is nothing
useful to send.
didMoveToWindow fires with a valid scene once the view is placed in a window,
at which point the
correct orientation is dispatched.
Also fix a secondary issue in
LocalSampleBufferDisplayLayer: when enqueueVideoFrame detects a
rotation change it calls updateSampleLayerBoundsAndPosition without explicit
bounds. Previously
this swapped the stale root-layer bounds on the sample buffer display layer
immediately, producing
a transient wrong-sized frame. Now only the affine transform is applied in the
no-bounds path;
the caller provides correct bounds via updateBoundsAndPosition once the
rotation change has
propagated through the media pipeline.
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _dispatchSetOrientationForMediaCapture:]): Skip dispatch when
orientation is 0
and windowScene is nil.
*
Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.h:
(LocalSampleBufferDisplayLayer::setVideoFrameRotationForTesting):
*
Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm:
(LocalSampleBufferDisplayLayer::sampleLayerBoundsForTesting):
(LocalSampleBufferDisplayLayer::updateSampleLayerBoundsAndPosition): Apply
transform but
skip bounds update when called without explicit bounds.
(LocalSampleBufferDisplayLayer::enqueueVideoFrame): Restore call to
updateSampleLayerBoundsAndPosition when rotation changes so the transform is
applied promptly.
* Source/WebCore/platform/mediastream/cocoa/AVVideoCaptureSource.mm:
(AVVideoCaptureSource::orientationChanged): Log incoming orientation before
computing rotation.
(AVVideoCaptureSource::rotationAngleForHorizonLevelDisplayChanged): Fix log to
record the
previous rotation before the update.
(AVVideoCaptureSource::computeVideoFrameRotation): Log the rotation transition.
* Source/WebCore/platform/mediastream/RealtimeMediaSourceSettings.cpp:
(WebCore::RealtimeMediaSourceSettings::convertFlagsToString): Fix empty-prefix
check.
*
Tools/TestWebKitAPI/Tests/WebCore/cocoa/LocalSampleBufferDisplayLayerTests.mm:
Added.
(TestWebKitAPI::TEST(LocalSampleBufferDisplayLayer,
RotationChangeShouldNotSwapStaleBounds)):
Canonical link:
https://flagged.apple.com:443/proxy?t2=DW4n4S5ib0&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzE1ODIxQG1haW4=&emid=82c0bd4e-c375-46a4-9866-1cc0d094a1a9&c=11
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications