Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GPU Process and UI side compositing on macOS #12161

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Source/WTF/wtf/PlatformEnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,17 @@
#define ENABLE_PREDEFINED_COLOR_SPACE_DISPLAY_P3 0
#endif

#if !defined(ENABLE_GPU_PROCESS_DOM_RENDERING_BY_DEFAULT) && PLATFORM(IOS_FAMILY) && !PLATFORM(WATCHOS) && !HAVE(UIKIT_WEBKIT_INTERNALS)
#if !defined(ENABLE_GPU_PROCESS_DOM_RENDERING_BY_DEFAULT) && (PLATFORM(IOS_FAMILY) && !PLATFORM(WATCHOS) && !HAVE(UIKIT_WEBKIT_INTERNALS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000))
#define ENABLE_GPU_PROCESS_DOM_RENDERING_BY_DEFAULT 1
#endif

#if !defined(ENABLE_GPU_PROCESS_WEBGL_BY_DEFAULT) && (PLATFORM(IOS_FAMILY) || PLATFORM(MAC)) && !PLATFORM(WATCHOS) && !HAVE(UIKIT_WEBKIT_INTERNALS)
#define ENABLE_GPU_PROCESS_WEBGL_BY_DEFAULT 1
#endif


#if !defined(ENABLE_REMOTE_LAYER_TREE_ON_MAC_BY_DEFAULT) && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
#define ENABLE_REMOTE_LAYER_TREE_ON_MAC_BY_DEFAULT 1
#endif

/* Asserts, invariants for macro definitions */

Expand Down
13 changes: 11 additions & 2 deletions Source/WebKit/UIProcess/mac/WebViewImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,17 @@ static NSTrackingAreaOptions trackingAreaOptions()
ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
[NSApp registerServicesMenuSendTypes:PasteboardTypes::forSelection() returnTypes:PasteboardTypes::forEditing()];

if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseRemoteLayerTreeDrawingArea"] boolValue]
|| m_page->preferences().siteIsolationEnabled())
#if ENABLE(REMOTE_LAYER_TREE_ON_MAC_BY_DEFAULT)
bool useRemoteLayerTree = true;
#else
bool useRemoteLayerTree = false;
#endif
if (id useRemoteLayerTreeBoolean = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseRemoteLayerTreeDrawingArea"])
useRemoteLayerTree = [useRemoteLayerTreeBoolean boolValue];
if (m_page->preferences().siteIsolationEnabled())
useRemoteLayerTree = true;

if (useRemoteLayerTree)
m_drawingAreaType = DrawingAreaType::RemoteLayerTree;

[view addTrackingArea:m_primaryTrackingArea.get()];
Expand Down
10 changes: 9 additions & 1 deletion Tools/MiniBrowser/mac/SettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,15 @@ - (void)toggleUseUISideCompositing:(id)sender

- (BOOL)useUISideCompositing
{
return [[NSUserDefaults standardUserDefaults] boolForKey:UseRemoteLayerTreeDrawingAreaPreferenceKey];
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
bool useRemoteLayerTree = true;
#else
bool useRemoteLayerTree = false;
#endif
id useRemoteLayerTreeBoolean = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseRemoteLayerTreeDrawingArea"];
if (useRemoteLayerTreeBoolean)
useRemoteLayerTree = [useRemoteLayerTreeBoolean boolValue];
return useRemoteLayerTree;
}

- (void)togglePerWindowWebProcessesDisabled:(id)sender
Expand Down
9 changes: 9 additions & 0 deletions Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def parse_args(args):
help="Use accelerated drawing (OS X only)"),
optparse.make_option("--remote-layer-tree", action="store_true", default=False,
help="Use the remote layer tree drawing model (OS X WebKit2 only)"),
optparse.make_option("--no-remote-layer-tree", action="store_true", default=False,
help="Disable the remote layer tree drawing model (OS X WebKit2 only)"),
optparse.make_option("--internal-feature", type="string", action="append", default=[],
help="Enable (disable) an internal feature (--internal-feature FeatureName[=true|false])"),
optparse.make_option("--experimental-feature", type="string", action="append", default=[],
Expand Down Expand Up @@ -342,6 +344,9 @@ def parse_args(args):
optparse.make_option(
"--use-gpu-process", action="store_true", default=False,
help=("Enable all GPU process related features, also set additional expectations and the result report flavor.")),
optparse.make_option(
"--no-use-gpu-process", action="store_true", default=False,
help=("Disable GPU process for DOM rendering.")),
Copy link
Member

@JonWBedard JonWBedard Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to PR #12222, we should consider arguments.NoAction here:

from webkitcorepy import arguments
...
optparse.make_option(
    '--use-gpu-process', '--no-use-gpu-process',
    dest='use_gpu_process', default=None,
    help='...',
    action=arguments.NoAction,
)

Here I think the case for arguments.NoAction is much stronger because it looks like we convert these to a feature flag. That would mean use_gpu_process =True -> UseGPUProcessForDOMRenderingEnabled and use_gpu_process =False -> UseGPUProcessForDOMRenderingEnabled=0 and use_gpu_process =None would pass nothing (which would have a GPU process enabled in WebKit but disabled in WebKitLegacy if I'm understanding the code correctly?). It does mean that something like --no-gpu-process and --dump-render-tree is redundant, but I think that's true in the proposed implementation anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to work?

% ./Tools/Scripts/run-webkit-tests --debug --no-build --no-show-results fast/scrolling/scroll-animator-basic-events.htm
Traceback (most recent call last):
  File "/Volumes/Data/safari-2/OpenSource/./Tools/Scripts/run-webkit-tests", line 46, in <module>
    sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
  File "/Volumes/Data/safari-2/OpenSource/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py", line 57, in main
    options, args = parse_args(argv)
  File "/Volumes/Data/safari-2/OpenSource/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py", line 123, in parse_args
    optparse.make_option("--remote-layer-tree", "--no-remote-layer-tree", dest="remote_layer_tree", action=arguments.NoAction, default=None,
  File "/AppleInternal/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/optparse.py", line 581, in __init__
    checker(self)
  File "/AppleInternal/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/optparse.py", line 636, in _check_action
    raise OptionError("invalid action: %r" % self.action, self)
optparse.OptionError: option --remote-layer-tree/--no-remote-layer-tree: invalid action: <class 'webkitcorepy.arguments.NoAction'>

Copy link
Member

@JonWBedard JonWBedard Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to work?

...

Forgot that run-webkit-tests uses the older optparse instead of argparse. So never mind, this suggestion won't work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be a nice cleanup to migrate that over but it's probably outside the scope of this PR.

optparse.make_option(
"--prefer-integrated-gpu", action="store_true", default=False,
help=("Prefer using the lower-power integrated GPU on a dual-GPU system. Note that other running applications and the tests themselves can override this request.")),
Expand Down Expand Up @@ -388,6 +393,10 @@ def parse_args(args):
if options.result_report_flavor:
raise RuntimeError('--use-gpu-process implicitly sets the result flavor, this should not be overridden')
options.result_report_flavor = 'gpuprocess'
elif options.no_use_gpu_process:
if not options.experimental_feature:
options.experimental_feature = []
options.experimental_feature.append('UseGPUProcessForDOMRenderingEnabled=0')

if options.accessibility_isolated_tree:
host = Host()
Expand Down
2 changes: 2 additions & 0 deletions Tools/Scripts/webkitpy/port/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ def cmd_line(self, pixel_tests, per_test_args):
cmd.append('--accelerated-drawing')
if self._port.get_option('remote_layer_tree'):
cmd.append('--remote-layer-tree')
if self._port.get_option('no_remote_layer_tree'):
cmd.append('--no-remote-layer-tree')
if self._port.get_option('world_leaks'):
cmd.append('--world-leaks')
if self._port.get_option('threaded'):
Expand Down
7 changes: 7 additions & 0 deletions Tools/WebKitTestRunner/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ static bool handleOptionRemoteLayerTree(Options& options, const char*, const cha
return true;
}

static bool handleOptionNoRemoteLayerTree(Options& options, const char*, const char*)
{
options.features.boolTestRunnerFeatures.insert_or_assign("noUseRemoteLayerTree", true);
return true;
}

static bool handleOptionShowWindow(Options& options, const char*, const char*)
{
options.features.boolTestRunnerFeatures.insert_or_assign("shouldShowWindow", true);
Expand Down Expand Up @@ -181,6 +187,7 @@ OptionsHandler::OptionsHandler(Options& o)
optionList.append(Option("--complex-text", "Force complex tests.", handleOptionComplexText));
optionList.append(Option("--accelerated-drawing", "Use accelerated drawing.", handleOptionAcceleratedDrawing));
optionList.append(Option("--remote-layer-tree", "Use remote layer tree.", handleOptionRemoteLayerTree));
optionList.append(Option("--no-remote-layer-tree", "Disable remote layer tree.", handleOptionNoRemoteLayerTree));
optionList.append(Option("--allowed-host", "Allows access to the specified host from tests.", handleOptionAllowedHost, true));
optionList.append(Option("--localhost-alias", "Adds hostname alias to localhost if the port supports it.", handleOptionLocalhostAlias, true));
optionList.append(Option("--allow-any-certificate-for-allowed-hosts", "Allows any HTTPS certificate for an allowed host.", handleOptionAllowAnyHTTPSCertificateForAllowedHosts));
Expand Down
3 changes: 2 additions & 1 deletion Tools/WebKitTestRunner/TestOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static constexpr bool mediaSourceEnabledValue = true;
#endif

#if ENABLE(GPU_PROCESS)
#if PLATFORM(IOS_FAMILY)
#if ENABLE(GPU_PROCESS_DOM_RENDERING_BY_DEFAULT)
static constexpr bool fullGPUProcessEnabledValue = true;
#else
static constexpr bool fullGPUProcessEnabledValue = false;
Expand Down Expand Up @@ -181,6 +181,7 @@ const TestFeatures& TestOptions::defaults()
{ "useEphemeralSession", false },
{ "useFlexibleViewport", false },
{ "useRemoteLayerTree", false },
{ "noUseRemoteLayerTree", false },
{ "useThreadedScrolling", false },
};
features.doubleTestRunnerFeatures = {
Expand Down
1 change: 1 addition & 0 deletions Tools/WebKitTestRunner/TestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TestOptions {
bool useEphemeralSession() const { return boolTestRunnerFeatureValue("useEphemeralSession"); }
bool useFlexibleViewport() const { return boolTestRunnerFeatureValue("useFlexibleViewport"); }
bool useRemoteLayerTree() const { return boolTestRunnerFeatureValue("useRemoteLayerTree"); }
bool noUseRemoteLayerTree() const { return boolTestRunnerFeatureValue("noUseRemoteLayerTree"); }
bool useThreadedScrolling() const { return boolTestRunnerFeatureValue("useThreadedScrolling"); }
double contentInsetTop() const { return doubleTestRunnerFeatureValue("contentInset.top"); }
double horizontalSystemMinimumLayoutMargin() const { return doubleTestRunnerFeatureValue("horizontalSystemMinimumLayoutMargin"); }
Expand Down
2 changes: 2 additions & 0 deletions Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ - (void)_setWindowResolution:(CGFloat)resolution displayIfChanged:(BOOL)displayI
// FIXME: Not sure this is the best place for this; maybe we should have API to set this so we can do it from TestController?
if (m_options.useRemoteLayerTree())
[[NSUserDefaults standardUserDefaults] setValue:@YES forKey:@"WebKit2UseRemoteLayerTreeDrawingArea"];
if (m_options.noUseRemoteLayerTree())
[[NSUserDefaults standardUserDefaults] setValue:@NO forKey:@"WebKit2UseRemoteLayerTreeDrawingArea"];

auto copiedConfiguration = adoptNS([configuration copy]);
WKPreferencesSetThreadedScrollingEnabled((__bridge WKPreferencesRef)[copiedConfiguration preferences], m_options.useThreadedScrolling());
Expand Down
4 changes: 4 additions & 0 deletions Tools/WebKitTestRunner/mac/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ static void setDefaultsToConsistentValuesForTesting()
@"NSOverlayScrollersEnabled": @NO,
@"NSScrollAnimationEnabled" : @NO,
@"AppleShowScrollBars": @"Always",
#if ENABLE(REMOTE_LAYER_TREE_ON_MAC_BY_DEFAULT)
@"WebKit2UseRemoteLayerTreeDrawingArea": @YES,
#else
@"WebKit2UseRemoteLayerTreeDrawingArea": @NO,
#endif
};

[[NSUserDefaults standardUserDefaults] setValuesForKeysWithDictionary:dict];
Expand Down