Skip to content
Permalink
Browse files
[GPUP] Send GPU preferences in single IPC message
https://bugs.webkit.org/show_bug.cgi?id=241809
rdar://95636552

Patch by Youssef Soliman <youssefdevelops@gmail.com> on 2022-06-21
Reviewed by Eric Carlson.

Currently the `GPUProcessProxy::updatePreferences` method sends preferences
from the web process in multiple IPC messages to the GPU process. These messages
should be consolidated into one package and sent across in a single message.

* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::updateGPUProcessPreferences):
(WebKit::GPUProcess::updatePreference):
(WebKit::GPUProcess::setWebMParserEnabled): Deleted.
(WebKit::GPUProcess::setWebMFormatReaderEnabled): Deleted.
(WebKit::GPUProcess::setOpusDecoderEnabled): Deleted.
(WebKit::GPUProcess::setVorbisDecoderEnabled): Deleted.
(WebKit::GPUProcess::setMediaSourceInlinePaintingEnabled): Deleted.
(WebKit::GPUProcess::setSampleBufferContentKeySessionSupportEnabled): Deleted.
* Source/WebKit/GPUProcess/GPUProcess.h:
* Source/WebKit/GPUProcess/GPUProcess.messages.in:
* Source/WebKit/GPUProcess/GPUProcessPreferences.cpp: Added.
(WebKit::GPUProcessPreferences::encode const):
(WebKit::GPUProcessPreferences::decode):
* Source/WebKit/GPUProcess/GPUProcessPreferences.h: Added.
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::updatePreferences):
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/251713@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295708 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youssefsoli authored and webkit-commit-queue committed Jun 22, 2022
1 parent c7aa5b9 commit 187eb34
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 177 deletions.
@@ -35,6 +35,7 @@
#include "GPUConnectionToWebProcess.h"
#include "GPUProcessConnectionParameters.h"
#include "GPUProcessCreationParameters.h"
#include "GPUProcessPreferences.h"
#include "GPUProcessProxyMessages.h"
#include "GPUProcessSessionParameters.h"
#include "LogInitialization.h"
@@ -284,6 +285,54 @@ void GPUProcess::initializeGPUProcess(GPUProcessCreationParameters&& parameters)
#endif
}

void GPUProcess::updateGPUProcessPreferences(GPUProcessPreferences&& preferences)
{
#if ENABLE(MEDIA_SOURCE)
if (updatePreference(m_preferences.webMParserEnabled, preferences.webMParserEnabled))
WebCore::RuntimeEnabledFeatures::sharedFeatures().setWebMParserEnabled(*m_preferences.webMParserEnabled);
#endif

#if ENABLE(WEBM_FORMAT_READER)
if (updatePreference(m_preferences.webMFormatReaderEnabled, preferences.webMFormatReaderEnabled))
PlatformMediaSessionManager::setWebMFormatReaderEnabled(*m_preferences.webMFormatReaderEnabled);
#endif

#if ENABLE(OPUS)
if (updatePreference(m_preferences.opusDecoderEnabled, preferences.opusDecoderEnabled))
PlatformMediaSessionManager::setOpusDecoderEnabled(*m_preferences.opusDecoderEnabled);
#endif

#if ENABLE(VORBIS)
if (updatePreference(m_preferences.vorbisDecoderEnabled, preferences.vorbisDecoderEnabled))
PlatformMediaSessionManager::setVorbisDecoderEnabled(*m_preferences.vorbisDecoderEnabled);
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
if (updatePreference(m_preferences.mediaSourceInlinePaintingEnabled, preferences.mediaSourceInlinePaintingEnabled))
WebCore::RuntimeEnabledFeatures::sharedFeatures().setMediaSourceInlinePaintingEnabled(*m_preferences.mediaSourceInlinePaintingEnabled);
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
if (updatePreference(m_preferences.sampleBufferContentKeySessionSupportEnabled, preferences.sampleBufferContentKeySessionSupportEnabled))
MediaSessionManagerCocoa::setSampleBufferContentKeySessionSupportEnabled(*m_preferences.sampleBufferContentKeySessionSupportEnabled);
#endif
}

bool GPUProcess::updatePreference(std::optional<bool>& oldPreference, std::optional<bool>& newPreference)
{
if (newPreference.has_value() && oldPreference != newPreference) {
oldPreference = WTFMove(newPreference);
return true;
}

if (!oldPreference.has_value()) {
oldPreference = false;
return true;
}

return false;
}

void GPUProcess::prepareToSuspend(bool isSuspensionImminent, MonotonicTime, CompletionHandler<void()>&& completionHandler)
{
RELEASE_LOG(ProcessSuspension, "%p - GPUProcess::prepareToSuspend(), isSuspensionImminent: %d", this, isSuspensionImminent);
@@ -491,66 +540,6 @@ void GPUProcess::enableVP9Decoders(bool shouldEnableVP8Decoder, bool shouldEnabl
}
#endif

#if ENABLE(MEDIA_SOURCE)
void GPUProcess::setWebMParserEnabled(bool enabled)
{
if (m_webMParserEnabled == enabled)
return;
m_webMParserEnabled = enabled;
WebCore::RuntimeEnabledFeatures::sharedFeatures().setWebMParserEnabled(m_webMParserEnabled);
}
#endif

#if ENABLE(WEBM_FORMAT_READER)
void GPUProcess::setWebMFormatReaderEnabled(bool enabled)
{
if (m_webMFormatReaderEnabled == enabled)
return;
m_webMFormatReaderEnabled = enabled;
PlatformMediaSessionManager::setWebMFormatReaderEnabled(m_webMFormatReaderEnabled);
}
#endif

#if ENABLE(OPUS)
void GPUProcess::setOpusDecoderEnabled(bool enabled)
{
if (m_opusEnabled == enabled)
return;
m_opusEnabled = enabled;
PlatformMediaSessionManager::setOpusDecoderEnabled(m_opusEnabled);
}
#endif

#if ENABLE(VORBIS)
void GPUProcess::setVorbisDecoderEnabled(bool enabled)
{
if (m_vorbisEnabled == enabled)
return;
m_vorbisEnabled = enabled;
PlatformMediaSessionManager::setVorbisDecoderEnabled(m_vorbisEnabled);
}
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
void GPUProcess::setMediaSourceInlinePaintingEnabled(bool enabled)
{
if (m_mediaSourceInlinePaintingEnabled == enabled)
return;
m_mediaSourceInlinePaintingEnabled = enabled;
WebCore::RuntimeEnabledFeatures::sharedFeatures().setMediaSourceInlinePaintingEnabled(m_mediaSourceInlinePaintingEnabled);
}
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
void GPUProcess::setSampleBufferContentKeySessionSupportEnabled(bool enabled)
{
if (m_sampleBufferContentKeySessionSupportEnabled == enabled)
return;
m_sampleBufferContentKeySessionSupportEnabled = enabled;
MediaSessionManagerCocoa::setSampleBufferContentKeySessionSupportEnabled(enabled);
}
#endif

void GPUProcess::webProcessConnectionCountForTesting(CompletionHandler<void(uint64_t)>&& completionHandler)
{
completionHandler(GPUConnectionToWebProcess::objectCountForTesting());
@@ -28,6 +28,7 @@
#if ENABLE(GPU_PROCESS)

#include "AuxiliaryProcess.h"
#include "GPUProcessPreferences.h"
#include "SandboxExtension.h"
#include "ShareableBitmap.h"
#include "WebPageProxyIdentifier.h"
@@ -138,9 +139,12 @@ class GPUProcess : public AuxiliaryProcess, public ThreadSafeRefCounted<GPUProce

// Message Handlers
void initializeGPUProcess(GPUProcessCreationParameters&&);
void updateGPUProcessPreferences(GPUProcessPreferences&&);
void createGPUConnectionToWebProcess(WebCore::ProcessIdentifier, PAL::SessionID, IPC::Attachment&&, GPUProcessConnectionParameters&&, CompletionHandler<void()>&&);
void addSession(PAL::SessionID, GPUProcessSessionParameters&&);
void removeSession(PAL::SessionID);

bool updatePreference(std::optional<bool>& oldPreference, std::optional<bool>& newPreference);

#if ENABLE(MEDIA_STREAM)
void setMockCaptureDevicesEnabled(bool);
@@ -168,30 +172,6 @@ class GPUProcess : public AuxiliaryProcess, public ThreadSafeRefCounted<GPUProce
RetainPtr<NSDictionary> additionalStateForDiagnosticReport() const final;
#endif

#if ENABLE(MEDIA_SOURCE)
void setWebMParserEnabled(bool);
#endif

#if ENABLE(WEBM_FORMAT_READER)
void setWebMFormatReaderEnabled(bool);
#endif

#if ENABLE(OPUS)
void setOpusDecoderEnabled(bool);
#endif

#if ENABLE(VORBIS)
void setVorbisDecoderEnabled(bool);
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
void setMediaSourceInlinePaintingEnabled(bool);
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
void setSampleBufferContentKeySessionSupportEnabled(bool);
#endif

#if ENABLE(CFPREFS_DIRECT_MODE)
void notifyPreferencesChanged(const String& domain, const String& key, const std::optional<String>& encodedValue);
void dispatchSimulatedNotificationsForPreferenceChange(const String& key) final;
@@ -208,6 +188,8 @@ class GPUProcess : public AuxiliaryProcess, public ThreadSafeRefCounted<GPUProce
// Connections to WebProcesses.
HashMap<WebCore::ProcessIdentifier, Ref<GPUConnectionToWebProcess>> m_webProcessConnections;
MonotonicTime m_creationTime { MonotonicTime::now() };

GPUProcessPreferences m_preferences;

#if ENABLE(MEDIA_STREAM)
struct MediaCaptureAccess {
@@ -247,24 +229,6 @@ class GPUProcess : public AuxiliaryProcess, public ThreadSafeRefCounted<GPUProce
bool m_enableVP9Decoder { false };
bool m_enableVP9SWDecoder { false };
#endif
#if ENABLE(MEDIA_SOURCE)
bool m_webMParserEnabled { false };
#endif
#if ENABLE(WEBM_FORMAT_READER)
bool m_webMFormatReaderEnabled { false };
#endif
#if ENABLE(OPUS)
bool m_opusEnabled { false };
#endif
#if ENABLE(VORBIS)
bool m_vorbisEnabled { false };
#endif
#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
bool m_mediaSourceInlinePaintingEnabled { false };
#endif
#if HAVE(AVCONTENTKEYSPECIFIER)
bool m_sampleBufferContentKeySessionSupportEnabled { false };
#endif

};

@@ -26,6 +26,8 @@ messages -> GPUProcess LegacyReceiver {
InitializeGPUProcess(struct WebKit::GPUProcessCreationParameters processCreationParameters)

CreateGPUConnectionToWebProcess(WebCore::ProcessIdentifier processIdentifier, PAL::SessionID sessionID, IPC::Attachment connectionIdentifier, struct WebKit::GPUProcessConnectionParameters parameters) -> ()

UpdateGPUProcessPreferences(struct WebKit::GPUProcessPreferences preferences)

PrepareToSuspend(bool isSuspensionImminent, MonotonicTime estimatedSuspendTime) -> ()
ProcessDidResume()
@@ -57,30 +59,6 @@ messages -> GPUProcess LegacyReceiver {
ShowScreenPicker() -> (std::optional<WebCore::CaptureDevice> device)
#endif

#if ENABLE(MEDIA_SOURCE)
SetWebMParserEnabled(bool enabled);
#endif

#if ENABLE(WEBM_FORMAT_READER)
SetWebMFormatReaderEnabled(bool enabled);
#endif

#if ENABLE(OPUS)
SetOpusDecoderEnabled(bool enabled);
#endif

#if ENABLE(VORBIS)
SetVorbisDecoderEnabled(bool enabled);
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
SetMediaSourceInlinePaintingEnabled(bool enabled);
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
SetSampleBufferContentKeySessionSupportEnabled(bool enabled);
#endif

RequestBitmapImageForCurrentTime(WebCore::ProcessIdentifier processIdentifier, WebCore::MediaPlayerIdentifier playerIdentifier) -> (WebKit::ShareableBitmap::Handle handle)

#if ENABLE(CFPREFS_DIRECT_MODE)
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "GPUProcessPreferences.h"

#if ENABLE(GPU_PROCESS)

#include "ArgumentCoders.h"

#if PLATFORM(COCOA)
#include "ArgumentCodersCF.h"
#endif

namespace WebKit {

GPUProcessPreferences::GPUProcessPreferences() = default;

void GPUProcessPreferences::encode(IPC::Encoder& encoder) const
{
#if ENABLE(OPUS)
encoder << opusDecoderEnabled;
#endif

#if ENABLE(VORBIS)
encoder << vorbisDecoderEnabled;
#endif

#if ENABLE(WEBM_FORMAT_READER)
encoder << webMFormatReaderEnabled;
#endif

#if ENABLE(MEDIA_SOURCE) && ENABLE(VP9)
encoder << webMParserEnabled;
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
encoder << mediaSourceInlinePaintingEnabled;
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
encoder << sampleBufferContentKeySessionSupportEnabled;
#endif
}

bool GPUProcessPreferences::decode(IPC::Decoder& decoder, GPUProcessPreferences& result)
{
#if ENABLE(OPUS)
if (!decoder.decode(result.opusDecoderEnabled))
return false;
#endif

#if ENABLE(VORBIS)
if (!decoder.decode(result.vorbisDecoderEnabled))
return false;
#endif

#if ENABLE(WEBM_FORMAT_READER)
if (!decoder.decode(result.webMFormatReaderEnabled))
return false;
#endif

#if ENABLE(MEDIA_SOURCE) && ENABLE(VP9)
if (!decoder.decode(result.webMParserEnabled))
return false;
#endif

#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
if (!decoder.decode(result.mediaSourceInlinePaintingEnabled))
return false;
#endif

#if HAVE(AVCONTENTKEYSPECIFIER)
if (!decoder.decode(result.sampleBufferContentKeySessionSupportEnabled))
return false;
#endif
return true;
}

} // namespace WebKit

#endif // ENABLE(GPU_PROCESS)

0 comments on commit 187eb34

Please sign in to comment.