Skip to content
Permalink
Browse files
[iOS] WebProcess::initializeWebProcess spends ~150ms spinning up AVSy…
…stemController on some devices

https://bugs.webkit.org/show_bug.cgi?id=178640
<rdar://problem/35113105>

Reviewed by Youenn Fablet.

In r213933, we added a mechanism to allow the web process to drive media capture, by setting an attribute on the
shared AVSystemController. This requires us to fault in the Celestial framework, which is a slight performance
hit on some hardware. Instead of doing this at the start of every web process launch, we can just do this work
lazily, the first time the web process requests permissions for user media access.

* WebProcess/WebCoreSupport/WebUserMediaClient.cpp:
(WebKit::WebUserMediaClient::requestUserMediaAccess):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):


Canonical link: https://commits.webkit.org/194825@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223827 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Oct 23, 2017
1 parent 0cce7d7 commit a8be5ff8ab933e111762f229b6f0bd730f5af230
Showing 6 changed files with 57 additions and 22 deletions.
@@ -1,3 +1,26 @@
2017-10-22 Wenson Hsieh <wenson_hsieh@apple.com>

[iOS] WebProcess::initializeWebProcess spends ~150ms spinning up AVSystemController on some devices
https://bugs.webkit.org/show_bug.cgi?id=178640
<rdar://problem/35113105>

Reviewed by Youenn Fablet.

In r213933, we added a mechanism to allow the web process to drive media capture, by setting an attribute on the
shared AVSystemController. This requires us to fault in the Celestial framework, which is a slight performance
hit on some hardware. Instead of doing this at the start of every web process launch, we can just do this work
lazily, the first time the web process requests permissions for user media access.

* WebProcess/WebCoreSupport/WebUserMediaClient.cpp:
(WebKit::WebUserMediaClient::requestUserMediaAccess):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

2017-10-21 Michael Catanzaro <mcatanzaro@igalia.com>

Unreviewed, silence a -Wunused-but-set-variable warning
@@ -43,6 +43,7 @@ void WebUserMediaClient::pageDestroyed()

void WebUserMediaClient::requestUserMediaAccess(UserMediaRequest& request)
{
m_page.prepareToSendUserMediaPermissionRequest();
m_page.userMediaPermissionRequestManager().startUserMediaRequest(request);
}

@@ -3898,6 +3898,13 @@ void WebPage::didReceiveNotificationPermissionDecision(uint64_t notificationID,
}

#if ENABLE(MEDIA_STREAM)

#if !PLATFORM(IOS)
void WebPage::prepareToSendUserMediaPermissionRequest()
{
}
#endif

void WebPage::userMediaAccessWasGranted(uint64_t userMediaID, String&& audioDeviceUID, String&& videoDeviceUID, String&& mediaDeviceIdentifierHashSalt)
{
m_userMediaPermissionRequestManager->userMediaAccessWasGranted(userMediaID, WTFMove(audioDeviceUID), WTFMove(videoDeviceUID), WTFMove(mediaDeviceIdentifierHashSalt));
@@ -511,6 +511,7 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP

#if ENABLE(MEDIA_STREAM)
UserMediaPermissionRequestManager& userMediaPermissionRequestManager() { return *m_userMediaPermissionRequestManager; }
void prepareToSendUserMediaPermissionRequest();
#endif

void elementDidFocus(WebCore::Node*);
@@ -99,6 +99,7 @@
#import <WebCore/RenderImage.h>
#import <WebCore/RenderThemeIOS.h>
#import <WebCore/RenderView.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/Settings.h>
#import <WebCore/SharedBuffer.h>
#import <WebCore/StyleProperties.h>
@@ -110,8 +111,16 @@
#import <wtf/MathExtras.h>
#import <wtf/MemoryPressureHandler.h>
#import <wtf/SetForScope.h>
#import <wtf/SoftLinking.h>
#import <wtf/text/TextStream.h>

#if ENABLE(MEDIA_STREAM)
#import "CelestialSPI.h"
SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Celestial)
SOFT_LINK_CLASS_OPTIONAL(Celestial, AVSystemController)
SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_PIDToInheritApplicationStateFrom, NSString *)
#endif

using namespace WebCore;

namespace WebKit {
@@ -3411,6 +3420,22 @@ static bool selectionIsInsideFixedPositionContainer(Frame& frame)
}
#endif

#if ENABLE(MEDIA_STREAM)
void WebPage::prepareToSendUserMediaPermissionRequest()
{
static std::once_flag once;
std::call_once(once, [] {
if (!canLoadAVSystemController_PIDToInheritApplicationStateFrom())
return;

NSError *error = nil;
[[getAVSystemControllerClass() sharedAVSystemController] setAttribute:@(WebCore::presentingApplicationPID()) forKey:getAVSystemController_PIDToInheritApplicationStateFrom() error:&error];
if (error)
WTFLogAlways("Failed to set up PID proxying: %s", error.localizedDescription.UTF8String);
});
}
#endif

} // namespace WebKit

#endif // PLATFORM(IOS)
@@ -70,25 +70,13 @@
#import <stdio.h>

#if PLATFORM(IOS)
#import "CelestialSPI.h"
#import <pal/spi/ios/GraphicsServicesSPI.h>
#import <wtf/SoftLinking.h>
#endif

#if USE(OS_STATE)
#import <os/state_private.h>
#endif

#if PLATFORM(IOS)
SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Celestial)

SOFT_LINK_CLASS_OPTIONAL(Celestial, AVSystemController)

SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_PIDToInheritApplicationStateFrom, NSString *)

#define AVSystemController_PIDToInheritApplicationStateFrom getAVSystemController_PIDToInheritApplicationStateFrom()
#endif

using namespace WebCore;

namespace WebKit {
@@ -175,16 +163,6 @@ static id NSApplicationAccessibilityFocusedUIElement(NSApplication*, SEL)
// Priority decay on iOS 9 is impacting page load time so we fix the priority of the WebProcess' main thread (rdar://problem/22003112).
pthread_set_fixedpriority_self();
#endif

#if PLATFORM(IOS)
if (canLoadAVSystemController_PIDToInheritApplicationStateFrom()) {
pid_t pid = WebCore::presentingApplicationPID();
NSError *error = nil;
[[getAVSystemControllerClass() sharedAVSystemController] setAttribute:@(pid) forKey:AVSystemController_PIDToInheritApplicationStateFrom error:&error];
if (error)
WTFLogAlways("Failed to set up PID proxying: %s", [[error localizedDescription] UTF8String]);
}
#endif
}

void WebProcess::initializeProcessName(const ChildProcessInitializationParameters& parameters)

0 comments on commit a8be5ff

Please sign in to comment.