Diff
Modified: branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog (285834 => 285835)
--- branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog 2021-11-15 22:16:34 UTC (rev 285834)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog 2021-11-15 22:16:38 UTC (rev 285835)
@@ -1,5 +1,96 @@
2021-11-15 Alan Coon <[email protected]>
+ Apply patch. rdar://problem/83971417
+
+ 2021-11-09 Alan Coon <[email protected]>
+
+ Apply patch. rdar://problem/83971417
+
+ 2021-10-26 Russell Epstein <[email protected]>
+
+ 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 <[email protected]> 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 <[email protected]>
+
+ 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-15 Alan Coon <[email protected]>
+
Cherry-pick r285728. rdar://problem/85236241
[Web Animations] Accelerated animations with a single keyframe don't account for prior forward-filling animations
Modified: branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (285834 => 285835)
--- branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-11-15 22:16:34 UTC (rev 285834)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-11-15 22:16:38 UTC (rev 285835)
@@ -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.3.6.1-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (285834 => 285835)
--- branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-11-15 22:16:34 UTC (rev 285834)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-11-15 22:16:38 UTC (rev 285835)
@@ -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.3.6.1-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (285834 => 285835)
--- branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-11-15 22:16:34 UTC (rev 285834)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-11-15 22:16:38 UTC (rev 285835)
@@ -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)