Skip to content

Commit

Permalink
REGRESSION (iOS 17 Beta): The camera preview is with a wrong resoluti…
Browse files Browse the repository at this point in the history
…on for a short time when the iOS User enables/disables the camera

https://bugs.webkit.org/show_bug.cgi?id=259364
rdar://112621697

Reviewed by Jer Noble.

The fencing mechanism to synchronize UIProcess and GPUProcess layering works properly only on main thread.
We therefore need to process the WebProcess to GPUProcess message in main thread and not in a queue.
We thus introduce a new GPUConnectionToWebProcess message that will be processed in main thread.
We then get the SampleBufferDisplayLayer (via a lock) to call updateSampleLayerBoundsAndPosition which synchronously updates the bounds.

* Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm:
(WebCore::LocalSampleBufferDisplayLayer::updateSampleLayerBoundsAndPosition):
* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::updateSampleBufferDisplayLayerBoundsAndPosition):
* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h:
* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in:
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.h:
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.messages.in:
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.cpp:
(WebKit::RemoteSampleBufferDisplayLayerManager::close):
(WebKit::RemoteSampleBufferDisplayLayerManager::dispatchMessage):
(WebKit::RemoteSampleBufferDisplayLayerManager::createLayer):
(WebKit::RemoteSampleBufferDisplayLayerManager::releaseLayer):
(WebKit::RemoteSampleBufferDisplayLayerManager::allowsExitUnderMemoryPressure const):
(WebKit::RemoteSampleBufferDisplayLayerManager::updateSampleBufferDisplayLayerBoundsAndPosition):
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h:
* Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp:
(WebKit::SampleBufferDisplayLayer::updateBoundsAndPosition):

Canonical link: https://commits.webkit.org/270548@main
  • Loading branch information
youennf committed Nov 10, 2023
1 parent 9e3021a commit 57afaa9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void runWithoutAnimations(const WTF::Function<void()>& function)

void LocalSampleBufferDisplayLayer::updateSampleLayerBoundsAndPosition(std::optional<CGRect> bounds)
{
callOnMainThread([this, weakThis = ThreadSafeWeakPtr { *this }, bounds, rotation = m_videoFrameRotation, affineTransform = m_affineTransform]() mutable {
ensureOnMainThread([this, weakThis = ThreadSafeWeakPtr { *this }, bounds, rotation = m_videoFrameRotation, affineTransform = m_affineTransform]() mutable {
auto protectedThis = weakThis.get();
if (!protectedThis)
return;
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,13 @@ void GPUConnectionToWebProcess::enableMockMediaSource()
}
#endif

#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
void GPUConnectionToWebProcess::updateSampleBufferDisplayLayerBoundsAndPosition(SampleBufferDisplayLayerIdentifier identifier, WebCore::FloatRect bounds, std::optional<MachSendRight>&& fence)
{
m_sampleBufferDisplayLayerManager->updateSampleBufferDisplayLayerBoundsAndPosition(identifier, bounds, WTFMove(fence));
}
#endif

} // namespace WebKit

#undef MESSAGE_CHECK
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#include <wtf/MachSendRight.h>
#include <wtf/ThreadSafeRefCounted.h>

#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
#include "SampleBufferDisplayLayerIdentifier.h"
#endif

#if ENABLE(WEBGL)
#include "GraphicsContextGLIdentifier.h"
#include <WebCore/GraphicsContextGLAttributes.h>
Expand Down Expand Up @@ -277,6 +281,9 @@ class GPUConnectionToWebProcess
#if ENABLE(MEDIA_SOURCE)
void enableMockMediaSource();
#endif
#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
void updateSampleBufferDisplayLayerBoundsAndPosition(WebKit::SampleBufferDisplayLayerIdentifier, WebCore::FloatRect, std::optional<MachSendRight>&&);
#endif

#if HAVE(VISIBILITY_PROPAGATION_VIEW)
void createVisibilityPropagationContextForPage(WebPageProxyIdentifier, WebCore::PageIdentifier, bool canShowWhileLocked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ messages -> GPUConnectionToWebProcess WantsDispatchMessage {
#if ENABLE(MEDIA_SOURCE)
EnableMockMediaSource();
#endif

#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
UpdateSampleBufferDisplayLayerBoundsAndPosition(WebKit::SampleBufferDisplayLayerIdentifier identifier, WebCore::FloatRect bounds, std::optional<MachSendRight> fence);
#endif
}

#endif // ENABLE(GPU_PROCESS)
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class RemoteSampleBufferDisplayLayer : public WebCore::SampleBufferDisplayLayer:
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;

CGRect bounds() const;

void updateBoundsAndPosition(CGRect, std::optional<WTF::MachSendRight>&&);

private:
RemoteSampleBufferDisplayLayer(GPUConnectionToWebProcess&, SampleBufferDisplayLayerIdentifier, Ref<IPC::Connection>&&);

#if !RELEASE_LOG_DISABLED
void setLogIdentifier(String&&);
#endif
void updateDisplayMode(bool hideDisplayLayer, bool hideRootLayer);
void updateBoundsAndPosition(CGRect, std::optional<WTF::MachSendRight>&&);
void flush();
void flushAndRemoveImage();
void play();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ messages -> RemoteSampleBufferDisplayLayer NotRefCounted {
SetLogIdentifier(String logIdentifier)
#endif
UpdateDisplayMode(bool hideDisplayLayer, bool hideRootLayer)
UpdateBoundsAndPosition(CGRect bounds, std::optional<MachSendRight> fence)
Flush()
FlushAndRemoveImage()
EnqueueVideoFrame(struct WebKit::SharedVideoFrame frame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void RemoteSampleBufferDisplayLayerManager::close()
m_connectionToWebProcess.connection().removeWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayer::messageReceiverName());
m_connectionToWebProcess.connection().removeWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayerManager::messageReceiverName());
m_queue->dispatch([this, protectedThis = Ref { *this }] {
Locker lock(m_layersLock);
callOnMainRunLoop([layers = WTFMove(m_layers)] { });
});
}
Expand All @@ -68,6 +69,7 @@ bool RemoteSampleBufferDisplayLayerManager::dispatchMessage(IPC::Connection& con
return false;

auto identifier = ObjectIdentifier<SampleBufferDisplayLayerIdentifierType>(decoder.destinationID());
Locker lock(m_layersLock);
if (auto* layer = m_layers.get(identifier))
layer->didReceiveMessage(connection, decoder);
return true;
Expand All @@ -84,6 +86,7 @@ void RemoteSampleBufferDisplayLayerManager::createLayer(SampleBufferDisplayLayer
auto& layerReference = *layer;
layerReference.initialize(hideRootLayer, size, [this, protectedThis = Ref { *this }, callback = WTFMove(callback), identifier, layer = WTFMove(layer)](auto layerId) mutable {
m_queue->dispatch([this, protectedThis = WTFMove(protectedThis), callback = WTFMove(callback), identifier, layer = WTFMove(layer), layerId = WTFMove(layerId)]() mutable {
Locker lock(m_layersLock);
ASSERT(!m_layers.contains(identifier));
m_layers.add(identifier, WTFMove(layer));
callback(WTFMove(layerId));
Expand All @@ -96,6 +99,7 @@ void RemoteSampleBufferDisplayLayerManager::releaseLayer(SampleBufferDisplayLaye
{
callOnMainRunLoop([this, protectedThis = Ref { *this }, identifier]() mutable {
m_queue->dispatch([this, protectedThis = WTFMove(protectedThis), identifier] {
Locker lock(m_layersLock);
ASSERT(m_layers.contains(identifier));
callOnMainRunLoop([layer = m_layers.take(identifier)] { });
});
Expand All @@ -104,9 +108,17 @@ void RemoteSampleBufferDisplayLayerManager::releaseLayer(SampleBufferDisplayLaye

bool RemoteSampleBufferDisplayLayerManager::allowsExitUnderMemoryPressure() const
{
Locker lock(m_layersLock);
return m_layers.isEmpty();
}

void RemoteSampleBufferDisplayLayerManager::updateSampleBufferDisplayLayerBoundsAndPosition(SampleBufferDisplayLayerIdentifier identifier, WebCore::FloatRect bounds, std::optional<MachSendRight>&& sendRight)
{
Locker lock(m_layersLock);
if (auto* layer = m_layers.get(identifier))
layer->updateBoundsAndPosition(bounds, WTFMove(sendRight));
}

}

#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "LayerHostingContext.h"
#include "SampleBufferDisplayLayerIdentifier.h"
#include "WorkQueueMessageReceiver.h"
#include <WebCore/FloatRect.h>
#include <WebCore/IntSize.h>
#include <wtf/HashMap.h>

Expand Down Expand Up @@ -61,6 +62,7 @@ class RemoteSampleBufferDisplayLayerManager final : public IPC::WorkQueueMessage
void close();

bool allowsExitUnderMemoryPressure() const;
void updateSampleBufferDisplayLayerBoundsAndPosition(SampleBufferDisplayLayerIdentifier, WebCore::FloatRect, std::optional<MachSendRight>&&);

private:
explicit RemoteSampleBufferDisplayLayerManager(GPUConnectionToWebProcess&);
Expand All @@ -78,7 +80,8 @@ class RemoteSampleBufferDisplayLayerManager final : public IPC::WorkQueueMessage
GPUConnectionToWebProcess& m_connectionToWebProcess;
Ref<IPC::Connection> m_connection;
Ref<WorkQueue> m_queue;
HashMap<SampleBufferDisplayLayerIdentifier, std::unique_ptr<RemoteSampleBufferDisplayLayer>> m_layers;
mutable Lock m_layersLock;
HashMap<SampleBufferDisplayLayerIdentifier, std::unique_ptr<RemoteSampleBufferDisplayLayer>> m_layers WTF_GUARDED_BY_LOCK(m_layersLock);
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)

#include "GPUConnectionToWebProcessMessages.h"
#include "GPUProcessConnection.h"
#include "LayerHostingContext.h"
#include "Logging.h"
Expand Down Expand Up @@ -95,7 +96,7 @@ void SampleBufferDisplayLayer::updateDisplayMode(bool hideDisplayLayer, bool hid

void SampleBufferDisplayLayer::updateBoundsAndPosition(CGRect bounds, std::optional<WTF::MachSendRight>&& fence)
{
m_connection->send(Messages::RemoteSampleBufferDisplayLayer::UpdateBoundsAndPosition { bounds, WTFMove(fence) }, m_identifier);
m_connection->send(Messages::GPUConnectionToWebProcess::UpdateSampleBufferDisplayLayerBoundsAndPosition { m_identifier, bounds, WTFMove(fence) }, m_identifier);
}

void SampleBufferDisplayLayer::flush()
Expand Down

0 comments on commit 57afaa9

Please sign in to comment.