Diff
Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/ChangeLog 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-11-09 19:42:11 UTC (rev 285519)
@@ -1,5 +1,92 @@
2021-11-09 Alan Coon <alanc...@apple.com>
+ Apply patch. rdar://problem/83971417
+
+ 2021-10-26 Russell Epstein <repst...@apple.com>
+
+ Cherry-pick r284669. rdar://problem/83971417
+
+ WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
+ https://bugs.webkit.org/show_bug.cgi?id=231012
+ <rdar://problem/83971417>
+
+ Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2021-10-22
+ Reviewed by Dean Jackson.
+
+ Source/WebCore:
+
+ Use per-power preference EGLDisplay when creating Metal
+ contexts.
+
+ Adds a new API test.
+
+ * platform/RuntimeApplicationChecks.cpp:
+ (WebCore::setAuxiliaryProcessTypeForTesting):
+ * platform/RuntimeApplicationChecks.h:
+ Add a test function to reset the process type after test has set a specific type and then
+ run to completion. process for the duration of the test. The volatile context flag in
+ GraphicsContextGLOpenGL depends on condition isWebProcess || isGPUProcess.
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::releaseThreadResources):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::initializeEGLDisplay):
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+ (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
+ Tools:
+
+ Add a API test to test GraphicsContextGLOpenGL
+ Cocoa implementation regarding the bug where
+ the GraphicsContextGLOpenGL instances would use
+ the GPU that was selected by the first instance.
+
+ * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm: Added.
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::create):
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::TestedGraphicsContextGLOpenGL):
+ (TestWebKitAPI::hasMultipleGPUs):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/WebCoreUtilities.h: Added.
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::ScopedSetAuxiliaryProcessTypeForTesting):
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::~ScopedSetAuxiliaryProcessTypeForTesting):
+ Add a utility state setter to set the process type for the
+ duration of a test.
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-10-22 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
+ https://bugs.webkit.org/show_bug.cgi?id=231012
+ <rdar://problem/83971417>
+
+ Reviewed by Dean Jackson.
+
+ Use per-power preference EGLDisplay when creating Metal
+ contexts.
+
+ Adds a new API test.
+
+ * platform/RuntimeApplicationChecks.cpp:
+ (WebCore::setAuxiliaryProcessTypeForTesting):
+ * platform/RuntimeApplicationChecks.h:
+ Add a test function to reset the process type after test has set a specific type and then
+ run to completion. process for the duration of the test. The volatile context flag in
+ GraphicsContextGLOpenGL depends on condition isWebProcess || isGPUProcess.
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::releaseThreadResources):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::initializeEGLDisplay):
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+ (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
+2021-11-09 Alan Coon <alanc...@apple.com>
+
Apply patch. rdar://problem/83419159
2021-11-08 Kocsen Chung <kocsen_ch...@apple.com>
Modified: branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.cpp (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.cpp 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.cpp 2021-11-09 19:42:11 UTC (rev 285519)
@@ -75,6 +75,11 @@
auxiliaryProcessType() = type;
}
+void setAuxiliaryProcessTypeForTesting(std::optional<AuxiliaryProcessType> type)
+{
+ auxiliaryProcessType() = type;
+}
+
bool checkAuxiliaryProcessType(AuxiliaryProcessType type)
{
auto currentType = auxiliaryProcessType();
@@ -83,4 +88,9 @@
return *currentType == type;
}
+std::optional<AuxiliaryProcessType> processType()
+{
+ return auxiliaryProcessType();
+}
+
} // namespace WebCore
Modified: branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.h (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.h 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/platform/RuntimeApplicationChecks.h 2021-11-09 19:42:11 UTC (rev 285519)
@@ -25,6 +25,7 @@
#pragma once
+#include <optional>
#include <wtf/Forward.h>
namespace WebCore {
@@ -45,7 +46,9 @@
};
WEBCORE_EXPORT void setAuxiliaryProcessType(AuxiliaryProcessType);
+WEBCORE_EXPORT void setAuxiliaryProcessTypeForTesting(std::optional<AuxiliaryProcessType>);
WEBCORE_EXPORT bool checkAuxiliaryProcessType(AuxiliaryProcessType);
+WEBCORE_EXPORT std::optional<AuxiliaryProcessType> processType();
bool isInAuxiliaryProcess();
inline bool isInWebProcess() { return checkAuxiliaryProcessType(AuxiliaryProcessType::WebContent); }
Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-11-09 19:42:11 UTC (rev 285519)
@@ -85,7 +85,8 @@
// Unset the EGL current context, since the next access might be from another thread, and the
// context cannot be current on multiple threads.
if (releaseBehavior == ReleaseThreadResourceBehavior::ReleaseCurrentContext) {
- if (EGL_GetCurrentContext() == EGL_NO_CONTEXT)
+ EGLDisplay display = EGL_GetCurrentDisplay();
+ if (display == EGL_NO_DISPLAY)
return true;
// At the time of writing, ANGLE does not flush on MakeCurrent. Since we are
// potentially switching threads, we should flush.
@@ -92,20 +93,26 @@
// Note: Here we assume also that ANGLE has only one platform context -- otherwise
// we would need to flush each EGL context that has been used.
gl::Flush();
- EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
- if (display == EGL_NO_DISPLAY)
- return true;
return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
if (releaseBehavior == ReleaseThreadResourceBehavior::TerminateAndReleaseThreadResources) {
- EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
- if (display != EGL_NO_DISPLAY) {
- if (EGL_GetCurrentContext() != EGL_NO_CONTEXT) {
- ASSERT_NOT_REACHED(); // All resources must have been destroyed.
- EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- }
- EGL_Terminate(display);
+ EGLDisplay currentDisplay = EGL_GetCurrentDisplay();
+ if (currentDisplay != EGL_NO_DISPLAY) {
+ ASSERT_NOT_REACHED(); // All resources must have been destroyed.
+ EGL_MakeCurrent(currentDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
+ constexpr EGLNativeDisplayType nativeDisplays[] = {
+ defaultDisplay,
+#if PLATFORM(COCOA)
+ lowPowerDisplay,
+ highPerformanceDisplay
+#endif
+ };
+ for (auto nativeDisplay : nativeDisplays) {
+ EGLDisplay display = EGL_GetDisplay(nativeDisplay);
+ if (display != EGL_NO_DISPLAY)
+ EGL_Terminate(display);
+ }
}
// Called when we do not know if we will ever see another call from this thread again.
// Unset the EGL current context by releasing whole EGL thread state.
Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-11-09 19:42:11 UTC (rev 285519)
@@ -147,24 +147,25 @@
}
LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL");
+ EGLNativeDisplayType nativeDisplay = GraphicsContextGLOpenGL::defaultDisplay;
if (attrs.useMetal) {
displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
- }
-
- if (attrs.powerPreference != GraphicsContextGLAttributes::PowerPreference::Default || attrs.forceRequestForHighPerformanceGPU) {
- displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
- if (attrs.powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower && !attrs.forceRequestForHighPerformanceGPU) {
- LOG(WebGL, "Requesting low power GPU.");
+ // These properties are defined for EGL_ANGLE_power_preference as EGLContext attributes,
+ // but Metal backend uses EGLDisplay attributes.
+ auto powerPreference = attrs.forceRequestForHighPerformanceGPU ? GraphicsContextGLAttributes::PowerPreference::HighPerformance : attrs.powerPreference;
+ if (powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower) {
+ displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
displayAttributes.append(EGL_LOW_POWER_ANGLE);
- } else {
- ASSERT(attrs.powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance || attrs.forceRequestForHighPerformanceGPU);
- LOG(WebGL, "Requesting high power GPU if available.");
+ nativeDisplay = GraphicsContextGLOpenGL::lowPowerDisplay;
+ } else if (powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance) {
+ displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
displayAttributes.append(EGL_HIGH_POWER_ANGLE);
+ nativeDisplay = GraphicsContextGLOpenGL::highPerformanceDisplay;
}
}
displayAttributes.append(EGL_NONE);
- display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
+ display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(nativeDisplay), displayAttributes.data());
if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
LOG(WebGL, "EGLDisplay Initialization failed.");
@@ -173,7 +174,7 @@
LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion);
if (shouldInitializeWithVolatileContextSupport) {
// After initialization, EGL_DEFAULT_DISPLAY will return the platform-customized display.
- ASSERT(display == EGL_GetDisplay(EGL_DEFAULT_DISPLAY));
+ ASSERT(display == EGL_GetDisplay(nativeDisplay));
ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_eagl", "EGL_ANGLE_device_eagl", EGL_EAGL_CONTEXT_ANGLE));
ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_cgl", "EGL_ANGLE_device_cgl", EGL_CGL_CONTEXT_ANGLE));
}
@@ -241,16 +242,25 @@
if (!m_displayObj)
return;
- bool supportsPowerPreference = false;
#if PLATFORM(MAC)
- const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
- m_supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference");
- supportsPowerPreference = m_supportsPowerPreference;
+ if (!attrs.useMetal) {
+ // For OpenGL, EGL_ANGLE_power_preference is used. The context is initialized with the
+ // default, low-power device. For high-performance contexts, we request the high-performance
+ // GPU in setContextVisibility. When the request is fullfilled by the system, we get the
+ // display reconfiguration callback. Upon this, we update the CGL contexts inside ANGLE.
+ const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
+ bool supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference");
+ if (supportsPowerPreference) {
+ m_switchesGPUOnDisplayReconfiguration = attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance
+ || attrs.forceRequestForHighPerformanceGPU;
+ } else {
+ if (attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) {
+ attrs.powerPreference = GraphicsContextGLPowerPreference::Default;
+ setContextAttributes(attrs);
+ }
+ }
+ }
#endif
- if (!supportsPowerPreference && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) {
- attrs.powerPreference = GraphicsContextGLPowerPreference::Default;
- setContextAttributes(attrs);
- }
EGLint configAttributes[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
@@ -535,7 +545,7 @@
void GraphicsContextGLOpenGL::setContextVisibility(bool isVisible)
{
#if PLATFORM(MAC)
- if (contextAttributes().powerPreference != GraphicsContextGLPowerPreference::HighPerformance)
+ if (!m_switchesGPUOnDisplayReconfiguration)
return;
if (isVisible)
m_highPerformanceGPURequest = ScopedHighPerformanceGPURequest::acquire();
@@ -549,7 +559,7 @@
void GraphicsContextGLOpenGL::displayWasReconfigured()
{
#if PLATFORM(MAC)
- if (m_supportsPowerPreference)
+ if (m_switchesGPUOnDisplayReconfiguration)
EGL_HandleGPUSwitchANGLE(m_displayObj);
#endif
dispatchContextChangedNotification();
Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (285518 => 285519)
--- branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-11-09 19:42:11 UTC (rev 285519)
@@ -97,7 +97,7 @@
typedef WTF::HashMap<CString, uint64_t> ShaderNameHash;
-class WEBCORE_EXPORT GraphicsContextGLOpenGL final : public GraphicsContextGL
+class WEBCORE_EXPORT GraphicsContextGLOpenGL : public GraphicsContextGL
{
public:
static RefPtr<GraphicsContextGLOpenGL> create(GraphicsContextGLAttributes, HostWindow*);
@@ -542,10 +542,20 @@
#endif
#endif
-private:
+#if USE(ANGLE)
+ constexpr static EGLNativeDisplayType defaultDisplay = EGL_DEFAULT_DISPLAY;
#if PLATFORM(COCOA)
+ constexpr static EGLNativeDisplayType lowPowerDisplay = EGL_CAST(EGLNativeDisplayType, -1);
+ constexpr static EGLNativeDisplayType highPerformanceDisplay = EGL_CAST(EGLNativeDisplayType, -2);
+#endif
+#endif
+
+protected:
+#if PLATFORM(COCOA)
GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
-#else
+#endif
+private:
+#if !PLATFORM(COCOA)
GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*);
#endif
@@ -795,7 +805,7 @@
void* m_displayBufferPbuffer { nullptr };
#endif
#if PLATFORM(MAC)
- bool m_supportsPowerPreference { false };
+ bool m_switchesGPUOnDisplayReconfiguration { false };
ScopedHighPerformanceGPURequest m_highPerformanceGPURequest;
#endif
#if ENABLE(VIDEO) && USE(AVFOUNDATION)
Modified: branches/safari-612-branch/Tools/ChangeLog (285518 => 285519)
--- branches/safari-612-branch/Tools/ChangeLog 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Tools/ChangeLog 2021-11-09 19:42:11 UTC (rev 285519)
@@ -1,3 +1,88 @@
+2021-11-09 Alan Coon <alanc...@apple.com>
+
+ Apply patch. rdar://problem/83971417
+
+ 2021-10-26 Russell Epstein <repst...@apple.com>
+
+ Cherry-pick r284669. rdar://problem/83971417
+
+ WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
+ https://bugs.webkit.org/show_bug.cgi?id=231012
+ <rdar://problem/83971417>
+
+ Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2021-10-22
+ Reviewed by Dean Jackson.
+
+ Source/WebCore:
+
+ Use per-power preference EGLDisplay when creating Metal
+ contexts.
+
+ Adds a new API test.
+
+ * platform/RuntimeApplicationChecks.cpp:
+ (WebCore::setAuxiliaryProcessTypeForTesting):
+ * platform/RuntimeApplicationChecks.h:
+ Add a test function to reset the process type after test has set a specific type and then
+ run to completion. process for the duration of the test. The volatile context flag in
+ GraphicsContextGLOpenGL depends on condition isWebProcess || isGPUProcess.
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::releaseThreadResources):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::initializeEGLDisplay):
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+ (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
+ Tools:
+
+ Add a API test to test GraphicsContextGLOpenGL
+ Cocoa implementation regarding the bug where
+ the GraphicsContextGLOpenGL instances would use
+ the GPU that was selected by the first instance.
+
+ * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm: Added.
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::create):
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::TestedGraphicsContextGLOpenGL):
+ (TestWebKitAPI::hasMultipleGPUs):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/WebCoreUtilities.h: Added.
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::ScopedSetAuxiliaryProcessTypeForTesting):
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::~ScopedSetAuxiliaryProcessTypeForTesting):
+ Add a utility state setter to set the process type for the
+ duration of a test.
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-10-22 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
+ https://bugs.webkit.org/show_bug.cgi?id=231012
+ <rdar://problem/83971417>
+
+ Reviewed by Dean Jackson.
+
+ Add a API test to test GraphicsContextGLOpenGL
+ Cocoa implementation regarding the bug where
+ the GraphicsContextGLOpenGL instances would use
+ the GPU that was selected by the first instance.
+
+ * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm: Added.
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::create):
+ (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::TestedGraphicsContextGLOpenGL):
+ (TestWebKitAPI::hasMultipleGPUs):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/WebCoreUtilities.h: Added.
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::ScopedSetAuxiliaryProcessTypeForTesting):
+ (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::~ScopedSetAuxiliaryProcessTypeForTesting):
+ Add a utility state setter to set the process type for the
+ duration of a test.
+
2021-11-08 Kocsen Chung <kocsen_ch...@apple.com>
Cherry-pick r285208. rdar://problem/84824703
Modified: branches/safari-612-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig (285518 => 285519)
--- branches/safari-612-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig 2021-11-09 19:42:11 UTC (rev 285519)
@@ -86,7 +86,7 @@
OTHER_CPLUSPLUSFLAGS = $(inherited) -isystem $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders;
-OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework _javascript_Core -framework WebKit -lWebCoreTestSupport $(WK_AUTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH));
+OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework _javascript_Core -framework WebKit -lWebCoreTestSupport -framework Metal $(WK_AUTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH));
OTHER_LDFLAGS_PLATFORM_ = -framework Cocoa -framework Carbon;
// FIXME: This should not be built on iOS. Instead we should create and use a TestWebKitAPI application.
Modified: branches/safari-612-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (285518 => 285519)
--- branches/safari-612-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-11-09 19:42:06 UTC (rev 285518)
+++ branches/safari-612-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-11-09 19:42:11 UTC (rev 285519)
@@ -603,6 +603,7 @@
7B2739F32632AB640040F182 /* ThreadAssertionsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B2739F22632AB640040F182 /* ThreadAssertionsTest.cpp */; };
7B774906267CCE72009873B4 /* TestRunnerTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B774904267CCE68009873B4 /* TestRunnerTests.cpp */; };
7B7D096A2519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */; };
+ 7BA3936C271EDFCA0015911C /* TestGraphicsContextGLOpenGLCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7BA3936B271EDFCA0015911C /* TestGraphicsContextGLOpenGLCocoa.mm */; };
7C1AF7951E8DCBAB002645B9 /* PrepareForMoveToWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */; };
7C3965061CDD74F90094DBB8 /* ColorTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3965051CDD74F90094DBB8 /* ColorTests.cpp */; };
7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */; };
@@ -2488,6 +2489,8 @@
7B2739F22632AB640040F182 /* ThreadAssertionsTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadAssertionsTest.cpp; sourceTree = "<group>"; };
7B774904267CCE68009873B4 /* TestRunnerTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestRunnerTests.cpp; sourceTree = "<group>"; };
7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebGLNoCrashOnOtherThreadAccess.mm; sourceTree = "<group>"; };
+ 7BA3936B271EDFCA0015911C /* TestGraphicsContextGLOpenGLCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestGraphicsContextGLOpenGLCocoa.mm; sourceTree = "<group>"; };
+ 7BA3936D271EEC530015911C /* WebCoreUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreUtilities.h; sourceTree = "<group>"; };
7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrepareForMoveToWindow.mm; sourceTree = "<group>"; };
7C3965051CDD74F90094DBB8 /* ColorTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorTests.cpp; sourceTree = "<group>"; };
7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CommandBackForward.mm; sourceTree = "<group>"; };
@@ -3281,6 +3284,7 @@
BC131AA8117131FC00B69727 /* TestsController.cpp */,
BCB9E7C711234E3A00A137E0 /* TestsController.h */,
7C83E0361D0A5F7000FEBCF3 /* Utilities.h */,
+ 7BA3936D271EEC530015911C /* WebCoreUtilities.h */,
7CBD5A2222DE42A6004A9E32 /* WTFStringUtilities.cpp */,
44A622C114A0E2B60048515B /* WTFStringUtilities.h */,
);
@@ -4935,6 +4939,7 @@
57F1C91025DDD51900E8F6EA /* PrivateClickMeasurementCocoa.mm */,
5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */,
A17991861E1C994E00A505ED /* SharedBuffer.mm */,
+ 7BA3936B271EDFCA0015911C /* TestGraphicsContextGLOpenGLCocoa.mm */,
CD89D0381C4EDB2A00040A04 /* WebCoreNSURLSession.mm */,
);
path = cocoa;
@@ -5851,6 +5856,7 @@
F46128CB211D475100D9FADB /* TestDraggingInfo.mm in Sources */,
F4E0A2B82122847400AF7C7F /* TestFilePromiseReceiver.mm in Sources */,
F4F5BB5221667BAA002D06B9 /* TestFontOptions.mm in Sources */,
+ 7BA3936C271EDFCA0015911C /* TestGraphicsContextGLOpenGLCocoa.mm in Sources */,
F45E15762112CE6200307E82 /* TestInputDelegate.mm in Sources */,
F45D3891215A7B4B002A2979 /* TestInspectorBar.mm in Sources */,
516281252325C18000BB7E42 /* TestPDFDocument.mm in Sources */,
Added: branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm (0 => 285519)
--- branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm (rev 0)
+++ branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm 2021-11-09 19:42:11 UTC (rev 285519)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#import "config.h"
+#import "Test.h"
+
+#if PLATFORM(COCOA) && ENABLE(WEBGL)
+#import "WebCoreUtilities.h"
+#import <Metal/Metal.h>
+#import <WebCore/GraphicsContextGLOpenGL.h>
+
+namespace TestWebKitAPI {
+using namespace WebCore;
+
+namespace {
+class TestedGraphicsContextGLOpenGL : public GraphicsContextGLOpenGL {
+public:
+ static RefPtr<TestedGraphicsContextGLOpenGL> create(GraphicsContextGLAttributes attributes)
+ {
+ auto context = adoptRef(*new TestedGraphicsContextGLOpenGL(WTFMove(attributes)));
+ return context;
+ }
+private:
+ TestedGraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes)
+ : GraphicsContextGLOpenGL(WTFMove(attributes), nullptr, nullptr)
+ {
+ }
+};
+}
+
+static bool hasMultipleGPUs()
+{
+#if (PLATFORM(MAC) || PLATFORM(MACCATALYST))
+ auto devices = adoptNS(MTLCopyAllDevices());
+ return [devices count] > 1;
+#else
+ return false;
+#endif
+}
+
+#if HAVE(WEBGL_COMPATIBLE_METAL) && (PLATFORM(MAC) || PLATFORM(MACCATALYST))
+#define MAYBE_MultipleGPUsDifferentPowerPreferenceMetal MultipleGPUsDifferentPowerPreferenceMetal
+#else
+#define MAYBE_MultipleGPUsDifferentPowerPreferenceMetal DISABLED_MultipleGPUsDifferentPowerPreferenceMetal
+#endif
+// Tests for a bug where high-performance context would use low-power GPU if low-power or default
+// context was created first. Test is applicable only for Metal, since GPU selection for OpenGL is
+// very different.
+TEST(GraphicsContextGLOpenGLCocoaTest, MAYBE_MultipleGPUsDifferentPowerPreferenceMetal)
+{
+ if (!hasMultipleGPUs())
+ return;
+ ScopedSetAuxiliaryProcessTypeForTesting scopedProcessType { AuxiliaryProcessType::GPU };
+
+ GraphicsContextGLAttributes attributes;
+ attributes.useMetal = true;
+ EXPECT_EQ(attributes.powerPreference, GraphicsContextGLPowerPreference::Default);
+ auto defaultContext = TestedGraphicsContextGLOpenGL::create(attributes);
+ EXPECT_NE(defaultContext, nullptr);
+
+ attributes.powerPreference = GraphicsContextGLPowerPreference::LowPower;
+ auto lowPowerContext = TestedGraphicsContextGLOpenGL::create(attributes);
+ EXPECT_NE(lowPowerContext, nullptr);
+
+ attributes.powerPreference = GraphicsContextGLPowerPreference::HighPerformance;
+ auto highPerformanceContext = TestedGraphicsContextGLOpenGL::create(attributes);
+ EXPECT_NE(highPerformanceContext, nullptr);
+
+ EXPECT_NE(lowPowerContext->getString(GraphicsContextGL::RENDERER), highPerformanceContext->getString(GraphicsContextGL::RENDERER));
+ EXPECT_EQ(defaultContext->getString(GraphicsContextGL::RENDERER), lowPowerContext->getString(GraphicsContextGL::RENDERER));
+}
+
+}
+#endif
Added: branches/safari-612-branch/Tools/TestWebKitAPI/WebCoreUtilities.h (0 => 285519)
--- branches/safari-612-branch/Tools/TestWebKitAPI/WebCoreUtilities.h (rev 0)
+++ branches/safari-612-branch/Tools/TestWebKitAPI/WebCoreUtilities.h 2021-11-09 19:42:11 UTC (rev 285519)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <WebCore/RuntimeApplicationChecks.h>
+
+namespace TestWebKitAPI {
+
+class ScopedSetAuxiliaryProcessTypeForTesting {
+public:
+ explicit ScopedSetAuxiliaryProcessTypeForTesting(WebCore::AuxiliaryProcessType type)
+ : m_oldType(WebCore::processType())
+ {
+ setAuxiliaryProcessTypeForTesting(type);
+ }
+ ~ScopedSetAuxiliaryProcessTypeForTesting()
+ {
+ setAuxiliaryProcessTypeForTesting(m_oldType);
+ }
+private:
+ std::optional<WebCore::AuxiliaryProcessType> m_oldType;
+};
+
+} // namespace TestWebKitAPI