Title: [272279] branches/safari-611-branch/Source
Revision
272279
Author
[email protected]
Date
2021-02-02 17:41:19 -0800 (Tue, 02 Feb 2021)

Log Message

Cherry-pick r271880. rdar://problem/73889737

    WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
    https://bugs.webkit.org/show_bug.cgi?id=220843

    Patch by Kimmo Kinnunen <[email protected]> on 2021-01-26
    Reviewed by Dean Jackson.

    Source/WebCore:

    Use ANGLE extension EGL_ANGLE_power_preference to signal to ANGLE that the underlying
    CGL context should be updated as a response to display reconfiguration signal.
    This ensures that ANGLE state stays consistent with the actual CGL context behavior, as
    we don't change the context behind ANGLE's back.

    Remove the feature where the context GPU is selected based on the display the window is
    on. This cannot work with the logic of "powerPreference = "high-performance" goes to
    discrete GPU". Also, this cannot work with ANGLE at all, since all contexts are backed
    by a single platform context. Thus all contexts will use the same underlying GPU.

    No new tests due to the test runner missing features. The bug blockers track the testing.

    * PlatformMac.cmake:
    * SourcesCocoa.txt:
    * WebCore.xcodeproj/project.pbxproj:
    * html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::isHighPerformanceContext):
    * page/Chrome.cpp:
    (WebCore::Chrome::windowScreenDidChange):
    * platform/graphics/GraphicsContextGL.h:
    * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
    * platform/graphics/RemoteGraphicsContextGLProxyBase.h:
    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
    (WebCore::GraphicsContextGLOpenGL::create):
    (WebCore::GraphicsContextGLOpenGL::createShared):
    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
    (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
    (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
    (WebCore::GraphicsContextGLOpenGL::simulateContextChanged):
    * platform/graphics/mac/GraphicsChecksMac.cpp: Added.
    (WebCore::attachToAppleGraphicsControl):
    (WebCore::hasMuxCapability):
    (WebCore::hasLowAndHighPowerGPUs):
    * platform/graphics/mac/GraphicsChecksMac.h: Copied from Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h.
    * platform/graphics/mac/ScopedHighPerformanceGPURequest.h: Copied from Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h.
    (WebCore::ScopedHighPerformanceGPURequest::ScopedHighPerformanceGPURequest):
    (WebCore::ScopedHighPerformanceGPURequest::~ScopedHighPerformanceGPURequest):
    (WebCore::ScopedHighPerformanceGPURequest::operator=):
    (WebCore::ScopedHighPerformanceGPURequest::acquire):
    * platform/graphics/mac/SwitchingGPUClient.h:
    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp:
    (WebCore::GraphicsContextGLOpenGLManager::displayWasReconfigured):
    (WebCore::GraphicsContextGLOpenGLManager::addContext):
    (WebCore::GraphicsContextGLOpenGLManager::removeContext):
    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.h:
    * testing/Internals.cpp:

    Source/WebKit:

    Move the high-performance GPU shutdown timer from individual web processes to the main class
    in the ui process. This simplifies the implementation and reduces the number of timers.

    * UIProcess/mac/HighPerformanceGPUManager.h:
    * UIProcess/mac/HighPerformanceGPUManager.mm:
    (WebKit::HighPerformanceGPUManager::HighPerformanceGPUManager):
    (WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance):
    (WebKit::HighPerformanceGPUManager::updateState):
    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp:
    (WebKit::WebSwitchingGPUClient::requestHighPerformanceGPU):
    (WebKit::WebSwitchingGPUClient::releaseHighPerformanceGPU):
    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271880 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-611-branch/Source/WebCore/ChangeLog (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-03 01:41:19 UTC (rev 272279)
@@ -1,5 +1,137 @@
 2021-02-02  Alan Coon  <[email protected]>
 
+        Cherry-pick r271880. rdar://problem/73889737
+
+    WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
+    https://bugs.webkit.org/show_bug.cgi?id=220843
+    
+    Patch by Kimmo Kinnunen <[email protected]> on 2021-01-26
+    Reviewed by Dean Jackson.
+    
+    Source/WebCore:
+    
+    Use ANGLE extension EGL_ANGLE_power_preference to signal to ANGLE that the underlying
+    CGL context should be updated as a response to display reconfiguration signal.
+    This ensures that ANGLE state stays consistent with the actual CGL context behavior, as
+    we don't change the context behind ANGLE's back.
+    
+    Remove the feature where the context GPU is selected based on the display the window is
+    on. This cannot work with the logic of "powerPreference = "high-performance" goes to
+    discrete GPU". Also, this cannot work with ANGLE at all, since all contexts are backed
+    by a single platform context. Thus all contexts will use the same underlying GPU.
+    
+    No new tests due to the test runner missing features. The bug blockers track the testing.
+    
+    * PlatformMac.cmake:
+    * SourcesCocoa.txt:
+    * WebCore.xcodeproj/project.pbxproj:
+    * html/canvas/WebGLRenderingContextBase.cpp:
+    (WebCore::isHighPerformanceContext):
+    * page/Chrome.cpp:
+    (WebCore::Chrome::windowScreenDidChange):
+    * platform/graphics/GraphicsContextGL.h:
+    * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
+    * platform/graphics/RemoteGraphicsContextGLProxyBase.h:
+    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+    (WebCore::GraphicsContextGLOpenGL::create):
+    (WebCore::GraphicsContextGLOpenGL::createShared):
+    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+    (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+    (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+    (WebCore::GraphicsContextGLOpenGL::simulateContextChanged):
+    * platform/graphics/mac/GraphicsChecksMac.cpp: Added.
+    (WebCore::attachToAppleGraphicsControl):
+    (WebCore::hasMuxCapability):
+    (WebCore::hasLowAndHighPowerGPUs):
+    * platform/graphics/mac/GraphicsChecksMac.h: Copied from Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h.
+    * platform/graphics/mac/ScopedHighPerformanceGPURequest.h: Copied from Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h.
+    (WebCore::ScopedHighPerformanceGPURequest::ScopedHighPerformanceGPURequest):
+    (WebCore::ScopedHighPerformanceGPURequest::~ScopedHighPerformanceGPURequest):
+    (WebCore::ScopedHighPerformanceGPURequest::operator=):
+    (WebCore::ScopedHighPerformanceGPURequest::acquire):
+    * platform/graphics/mac/SwitchingGPUClient.h:
+    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp:
+    (WebCore::GraphicsContextGLOpenGLManager::displayWasReconfigured):
+    (WebCore::GraphicsContextGLOpenGLManager::addContext):
+    (WebCore::GraphicsContextGLOpenGLManager::removeContext):
+    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.h:
+    * testing/Internals.cpp:
+    
+    Source/WebKit:
+    
+    Move the high-performance GPU shutdown timer from individual web processes to the main class
+    in the ui process. This simplifies the implementation and reduces the number of timers.
+    
+    * UIProcess/mac/HighPerformanceGPUManager.h:
+    * UIProcess/mac/HighPerformanceGPUManager.mm:
+    (WebKit::HighPerformanceGPUManager::HighPerformanceGPUManager):
+    (WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance):
+    (WebKit::HighPerformanceGPUManager::updateState):
+    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp:
+    (WebKit::WebSwitchingGPUClient::requestHighPerformanceGPU):
+    (WebKit::WebSwitchingGPUClient::releaseHighPerformanceGPU):
+    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271880 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-26  Kimmo Kinnunen  <[email protected]>
+
+            WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
+            https://bugs.webkit.org/show_bug.cgi?id=220843
+
+            Reviewed by Dean Jackson.
+
+            Use ANGLE extension EGL_ANGLE_power_preference to signal to ANGLE that the underlying
+            CGL context should be updated as a response to display reconfiguration signal.
+            This ensures that ANGLE state stays consistent with the actual CGL context behavior, as
+            we don't change the context behind ANGLE's back.
+
+            Remove the feature where the context GPU is selected based on the display the window is
+            on. This cannot work with the logic of "powerPreference = "high-performance" goes to
+            discrete GPU". Also, this cannot work with ANGLE at all, since all contexts are backed
+            by a single platform context. Thus all contexts will use the same underlying GPU.
+
+            No new tests due to the test runner missing features. The bug blockers track the testing.
+
+            * PlatformMac.cmake:
+            * SourcesCocoa.txt:
+            * WebCore.xcodeproj/project.pbxproj:
+            * html/canvas/WebGLRenderingContextBase.cpp:
+            (WebCore::isHighPerformanceContext):
+            * page/Chrome.cpp:
+            (WebCore::Chrome::windowScreenDidChange):
+            * platform/graphics/GraphicsContextGL.h:
+            * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
+            * platform/graphics/RemoteGraphicsContextGLProxyBase.h:
+            * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+            (WebCore::GraphicsContextGLOpenGL::create):
+            (WebCore::GraphicsContextGLOpenGL::createShared):
+            (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+            (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+            (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+            (WebCore::GraphicsContextGLOpenGL::simulateContextChanged):
+            * platform/graphics/mac/GraphicsChecksMac.cpp: Added.
+            (WebCore::attachToAppleGraphicsControl):
+            (WebCore::hasMuxCapability):
+            (WebCore::hasLowAndHighPowerGPUs):
+            * platform/graphics/mac/GraphicsChecksMac.h: Copied from Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h.
+            * platform/graphics/mac/ScopedHighPerformanceGPURequest.h: Copied from Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h.
+            (WebCore::ScopedHighPerformanceGPURequest::ScopedHighPerformanceGPURequest):
+            (WebCore::ScopedHighPerformanceGPURequest::~ScopedHighPerformanceGPURequest):
+            (WebCore::ScopedHighPerformanceGPURequest::operator=):
+            (WebCore::ScopedHighPerformanceGPURequest::acquire):
+            * platform/graphics/mac/SwitchingGPUClient.h:
+            * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+            * platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp:
+            (WebCore::GraphicsContextGLOpenGLManager::displayWasReconfigured):
+            (WebCore::GraphicsContextGLOpenGLManager::addContext):
+            (WebCore::GraphicsContextGLOpenGLManager::removeContext):
+            * platform/graphics/opengl/GraphicsContextGLOpenGLManager.h:
+            * testing/Internals.cpp:
+
+2021-02-02  Alan Coon  <[email protected]>
+
         Cherry-pick r271797. rdar://problem/73847580
 
     Activate simulcast through addTransceiver

Modified: branches/safari-611-branch/Source/WebCore/PlatformMac.cmake (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/PlatformMac.cmake	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/PlatformMac.cmake	2021-02-03 01:41:19 UTC (rev 272279)
@@ -340,6 +340,7 @@
     platform/graphics/mac/FloatPointMac.mm
     platform/graphics/mac/FloatSizeMac.mm
     platform/graphics/mac/FontCustomPlatformData.cpp
+    platform/graphics/mac/GraphicsChecksMac.cpp
     platform/graphics/mac/IconMac.mm
     platform/graphics/mac/ImageMac.mm
     platform/graphics/mac/IntPointMac.mm

Modified: branches/safari-611-branch/Source/WebCore/SourcesCocoa.txt (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/SourcesCocoa.txt	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/SourcesCocoa.txt	2021-02-03 01:41:19 UTC (rev 272279)
@@ -418,6 +418,7 @@
 platform/graphics/mac/FloatPointMac.mm
 platform/graphics/mac/FloatSizeMac.mm
 platform/graphics/mac/FontCustomPlatformData.cpp
+platform/graphics/mac/GraphicsChecksMac.cpp
 platform/graphics/mac/IconMac.mm
 platform/graphics/mac/ImageMac.mm
 platform/graphics/mac/IntPointMac.mm

Modified: branches/safari-611-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-02-03 01:41:19 UTC (rev 272279)
@@ -2257,6 +2257,9 @@
 		7B90417025501142006EEB8C /* RemoteGraphicsContextGLProxyBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B90416E25501109006EEB8C /* RemoteGraphicsContextGLProxyBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; };
 		7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		7BB680B225BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		7BB680B625BA1AE2002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */; };
+		7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
 		7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C1843FE1C8B7283002EB973 /* Autofill.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C1843FC1C8B7283002EB973 /* Autofill.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10285,6 +10288,10 @@
 		7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; };
 		7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; };
 		7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; };
+		7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedHighPerformanceGPURequest.h; sourceTree = "<group>"; };
+		7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedHighPerformanceGPURequest.h; sourceTree = "<group>"; };
+		7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsChecksMac.cpp; sourceTree = "<group>"; };
+		7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsChecksMac.h; sourceTree = "<group>"; };
 		7BE7265B25763B8D00E85D98 /* RemoteGraphicsContextGLProxyBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyBase.cpp; sourceTree = "<group>"; };
 		7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; };
 		7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; };
@@ -26482,11 +26489,15 @@
 				B275354D0B053814002CE64F /* FloatSizeMac.mm */,
 				B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */,
 				B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */,
+				7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */,
+				7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */,
 				B275358D0B053A66002CE64F /* IconMac.mm */,
 				B275354E0B053814002CE64F /* ImageMac.mm */,
 				B275354F0B053814002CE64F /* IntPointMac.mm */,
 				B27535510B053814002CE64F /* IntSizeMac.mm */,
 				2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */,
+				7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */,
+				7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */,
 				163E88F5118A39D200ED9231 /* SimpleFontDataCoreText.cpp */,
 				C11A9ED22140578B00CFB20A /* SwitchingGPUClient.cpp */,
 				C11A9ECD21403A5C00CFB20A /* SwitchingGPUClient.h */,
@@ -32218,6 +32229,7 @@
 				BC53C5F50DA56B920021EB5D /* Gradient.h in Headers */,
 				B22279640D00BF220071B782 /* GradientAttributes.h in Headers */,
 				2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */,
+				7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */,
 				B2A015A90AF6CD53006BCE0E /* GraphicsContext.h in Headers */,
 				934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
 				313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */,
@@ -34438,6 +34450,8 @@
 				49E911CB0EF86D47009D0CAF /* ScaleTransformOperation.h in Headers */,
 				5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */,
 				9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */,
+				7BB680B625BA1AE2002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */,
+				7BB680B225BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */,
 				BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
 				C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */,
 				A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,

Modified: branches/safari-611-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -642,7 +642,7 @@
 
 static bool isHighPerformanceContext(const RefPtr<GraphicsContextGL>& context)
 {
-    return context->powerPreferenceUsedForCreation() == WebGLPowerPreference::HighPerformance;
+    return context->contextAttributes().powerPreference == WebGLPowerPreference::HighPerformance;
 }
 
 std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(CanvasBase& canvas, WebGLContextAttributes& attributes, WebGLVersion type)

Modified: branches/safari-611-branch/Source/WebCore/page/Chrome.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/page/Chrome.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/page/Chrome.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -67,10 +67,6 @@
 #include "DateTimeChooser.h"
 #endif
 
-#if PLATFORM(MAC) && ENABLE(WEBGL)
-#include "GraphicsContextGLOpenGLManager.h"
-#endif
-
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -548,10 +544,6 @@
         return;
 
     m_page.windowScreenDidChange(displayID, nominalFrameInterval);
-
-#if PLATFORM(MAC) && ENABLE(WEBGL)
-    GraphicsContextGLOpenGLManager::sharedManager().screenDidChange(displayID, this);
-#endif
 }
 
 bool Chrome::selectItemWritingDirectionIsNatural()

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -1255,8 +1255,6 @@
 
     virtual void setContextVisibility(bool) = 0;
 
-    virtual GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const = 0;
-
     virtual bool isGLES2Compliant() const = 0;
 
     // Synthesizes an OpenGL error which will be returned from a

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -49,12 +49,6 @@
     notImplemented();
 }
 
-GraphicsContextGLPowerPreference RemoteGraphicsContextGLProxyBase::powerPreferenceUsedForCreation() const
-{
-    notImplemented();
-    return { };
-}
-
 bool RemoteGraphicsContextGLProxyBase::isGLES2Compliant() const
 {
 #if ENABLE(WEBGL2)

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -61,7 +61,6 @@
     PlatformLayer* platformLayer() const final;
     ExtensionsGL& getExtensions() final;
     void setContextVisibility(bool) final;
-    GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final;
     bool isGLES2Compliant() const final;
     void markContextChanged() final;
     bool layerComposited() const final;

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-02-03 01:41:19 UTC (rev 272279)
@@ -20,7 +20,7 @@
  * 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. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #import "config.h"
@@ -32,9 +32,7 @@
 #import "GraphicsContextGLANGLEUtilities.h"
 #import "GraphicsContextGLIOSurfaceSwapChain.h"
 #import "GraphicsContextGLOpenGLManager.h"
-#import "HostWindow.h"
 #import "Logging.h"
-#import "OpenGLSoftLinkCocoa.h"
 #import "RuntimeApplicationChecks.h"
 #import "WebCoreThread.h"
 #import "WebGLLayer.h"
@@ -42,11 +40,6 @@
 #import <wtf/BlockObjCExceptions.h>
 #import <wtf/text/CString.h>
 
-#if PLATFORM(MAC)
-#import "ScreenProperties.h"
-#import <OpenGL/CGLRenderers.h>
-#endif
-
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
 #include "GraphicsContextGLCV.h"
 #endif
@@ -151,7 +144,7 @@
     if (!context->m_contextObj)
         return nullptr;
 
-    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get(), hostWindow);
+    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get());
 
     return context;
 }
@@ -158,11 +151,11 @@
 
 Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createShared(GraphicsContextGLOpenGL& sharedContext)
 {
-    auto hostWindow = GraphicsContextGLOpenGLManager::sharedManager().hostWindowForContext(&sharedContext);
-    auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), hostWindow, &sharedContext, nullptr));
 
-    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr(), hostWindow);
+    auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), nullptr, &sharedContext, nullptr));
 
+    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr());
+
     return context;
 }
 
@@ -171,72 +164,25 @@
     return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, nullptr, swapChain));
 }
 
-#if PLATFORM(MAC) // FIXME: This probably should be just enabled - see <rdar://53062794>.
-
-static void setGPUByRegistryID(CGLContextObj contextObj, CGLPixelFormatObj pixelFormatObj, IORegistryGPUID preferredGPUID)
-{
-    // When the WebProcess does not have access to the WindowServer, there is no way for OpenGL to tell which GPU is connected to a display.
-    // On 10.13+, find the virtual screen that corresponds to the preferred GPU by its registryID.
-    // CGLSetVirtualScreen can then be used to tell OpenGL which GPU it should be using.
-
-    if (!contextObj || !preferredGPUID)
-        return;
-
-    GLint virtualScreenCount = 0;
-    CGLError error = CGLDescribePixelFormat(pixelFormatObj, 0, kCGLPFAVirtualScreenCount, &virtualScreenCount);
-    ASSERT(error == kCGLNoError);
-
-    GLint firstAcceleratedScreen = -1;
-
-    for (GLint virtualScreen = 0; virtualScreen < virtualScreenCount; ++virtualScreen) {
-        GLint displayMask = 0;
-        error = CGLDescribePixelFormat(pixelFormatObj, virtualScreen, kCGLPFADisplayMask, &displayMask);
-        ASSERT(error == kCGLNoError);
-
-        auto gpuID = gpuIDForDisplayMask(displayMask);
-
-        if (gpuID == preferredGPUID) {
-            error = CGLSetVirtualScreen(contextObj, virtualScreen);
-            ASSERT(error == kCGLNoError);
-            LOG(WebGL, "Context (%p) set to GPU with ID: (%lld).", contextObj, gpuID);
-            return;
-        }
-
-        if (firstAcceleratedScreen < 0) {
-            GLint isAccelerated = 0;
-            error = CGLDescribePixelFormat(pixelFormatObj, virtualScreen, kCGLPFAAccelerated, &isAccelerated);
-            ASSERT(error == kCGLNoError);
-            if (isAccelerated)
-                firstAcceleratedScreen = virtualScreen;
-        }
-    }
-
-    // No registryID match found; set to first hardware-accelerated virtual screen.
-    if (firstAcceleratedScreen >= 0) {
-        error = CGLSetVirtualScreen(contextObj, firstAcceleratedScreen);
-        ASSERT(error == kCGLNoError);
-        LOG(WebGL, "RegistryID (%lld) not matched; Context (%p) set to virtual screen (%d).", preferredGPUID, contextObj, firstAcceleratedScreen);
-    }
-}
-
-#endif // PLATFORM(MAC)
-
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow* hostWindow, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain)
     : GraphicsContextGL(attrs, Destination::Offscreen, sharedContext)
 {
     m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
 
-#if HAVE(APPLE_GRAPHICS_CONTROL)
-    m_powerPreferenceUsedForCreation = (hasLowAndHighPowerGPUs() && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) ? GraphicsContextGLPowerPreference::HighPerformance : GraphicsContextGLPowerPreference::Default;
-#else
-    m_powerPreferenceUsedForCreation = GraphicsContextGLPowerPreference::Default;
-#endif
-
     m_displayObj = InitializeEGLDisplay(attrs);
     if (m_displayObj == EGL_NO_DISPLAY)
         return;
+
+    bool supportsPowerPreference = false;
+#if PLATFORM(MAC)
     const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
-    LOG(WebGL, "Extensions: %s", displayExtensions);
+    m_supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference");
+    supportsPowerPreference = m_supportsPowerPreference;
+#endif
+    if (!supportsPowerPreference && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) {
+        attrs.powerPreference = GraphicsContextGLPowerPreference::Default;
+        setContextAttributes(attrs);
+    }
 
     EGLint configAttributes[] = {
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
@@ -290,12 +236,6 @@
     eglContextAttributes.append(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM);
     eglContextAttributes.append(EGL_FALSE);
 
-    if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {
-        eglContextAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
-        // EGL_LOW_POWER_ANGLE is the default. Change to
-        // EGL_HIGH_POWER_ANGLE if desired.
-        eglContextAttributes.append(EGL_LOW_POWER_ANGLE);
-    }
     eglContextAttributes.append(EGL_NONE);
 
     m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharedContext ? static_cast<EGLContext>(sharedContext->m_contextObj) : EGL_NO_CONTEXT, eglContextAttributes.data());
@@ -332,21 +272,6 @@
         }
         extensions.ensureEnabled(extension);
     }
-#if PLATFORM(MAC)
-    // FIXME: It's unclear if MACCATALYST should take these steps as well, but that
-    // would require the PlatformScreenMac code to be exposed to Catalyst too.
-    EGLDeviceEXT device = nullptr;
-    EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
-    CGLContextObj cglContext = nullptr;
-    CGLPixelFormatObj pixelFormat = nullptr;
-    EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
-    EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat));
-    auto gpuID = (hostWindow && hostWindow->displayID()) ? gpuIDForDisplay(hostWindow->displayID()) : primaryGPUID();
-    setGPUByRegistryID(cglContext, pixelFormat, gpuID);
-#else
-    UNUSED_PARAM(hostWindow);
-#endif
-
     validateAttributes();
     attrs = contextAttributes(); // They may have changed during validation.
 
@@ -561,30 +486,26 @@
 
 void GraphicsContextGLOpenGL::setContextVisibility(bool isVisible)
 {
-    if (m_powerPreferenceUsedForCreation == GraphicsContextGLPowerPreference::HighPerformance) {
-        if (isVisible)
-            GraphicsContextGLOpenGLManager::sharedManager().addContextRequiringHighPerformance(this);
-        else
-            GraphicsContextGLOpenGLManager::sharedManager().removeContextRequiringHighPerformance(this);
-    }
+#if PLATFORM(MAC)
+    if (contextAttributes().powerPreference != GraphicsContextGLPowerPreference::HighPerformance)
+        return;
+    if (isVisible)
+        m_highPerformanceGPURequest = ScopedHighPerformanceGPURequest::acquire();
+    else
+        m_highPerformanceGPURequest = { };
+#else
+    UNUSED_PARAM(isVisible);
+#endif
 }
 
+void GraphicsContextGLOpenGL::displayWasReconfigured()
+{
 #if PLATFORM(MAC)
-void GraphicsContextGLOpenGL::updateCGLContext()
-{
-    if (!makeContextCurrent())
-        return;
-    LOG(WebGL, "Detected a mux switch or display reconfiguration. Call CGLUpdateContext. (%p)", this);
-
-    EGLDeviceEXT device = nullptr;
-    EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
-    CGLContextObj cglContext = nullptr;
-    EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
-
-    CGLUpdateContext(cglContext);
-    m_hasSwitchedToHighPerformanceGPU = true;
+    if (m_supportsPowerPreference)
+        EGL_HandleGPUSwitchANGLE(m_displayObj);
+#endif
+    dispatchContextChangedNotification();
 }
-#endif
 
 bool GraphicsContextGLOpenGL::reshapeDisplayBufferBacking()
 {
@@ -654,51 +575,9 @@
 
 void GraphicsContextGLOpenGL::simulateContextChanged()
 {
-    GraphicsContextGLOpenGLManager::sharedManager().updateAllContexts();
+    GraphicsContextGLOpenGLManager::sharedManager().displayWasReconfigured();
 }
 
-bool GraphicsContextGLOpenGL::allowOfflineRenderers() const
-{
-#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
-    // When WindowServer access is blocked in the WebProcess, there is no way
-    // for OpenGL to decide which GPU is connected to a display (online/offline).
-    // OpenGL will then consider all GPUs, or renderers, as offline, which means
-    // all offline renderers need to be considered when finding a pixel format.
-    // In WebKit legacy, there will still be a WindwServer connection, and
-    // m_displayMask will not be set in this case.
-    if (primaryOpenGLDisplayMask())
-        return true;
-#elif PLATFORM(MACCATALYST)
-    // FIXME: <rdar://53062794> We're very inconsistent about WEBPROCESS_WINDOWSERVER_BLOCKING
-    // and MAC/MACCATALYST and OPENGL/OPENGLES.
-    return true;
-#endif
-        
-#if HAVE(APPLE_GRAPHICS_CONTROL)
-    if (hasLowAndHighPowerGPUs())
-        return true;
-#endif
-    
-    return false;
-}
-
-#if PLATFORM(MAC)
-void GraphicsContextGLOpenGL::screenDidChange(PlatformDisplayID displayID)
-{
-    if (!m_contextObj)
-        return;
-    if (!m_hasSwitchedToHighPerformanceGPU) {
-        EGLDeviceEXT device = nullptr;
-        EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
-        CGLContextObj cglContext = nullptr;
-        CGLPixelFormatObj pixelFormat = nullptr;
-        EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
-        EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat));
-        setGPUByRegistryID(cglContext, pixelFormat, gpuIDForDisplay(displayID));
-    }
-}
-#endif // !PLATFORM(MAC)
-
 void GraphicsContextGLOpenGL::prepareForDisplay()
 {
     if (m_layerComposited)

Added: branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.cpp (0 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.cpp	                        (rev 0)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "GraphicsChecksMac.h"
+
+#if PLATFORM(MAC)
+
+#if HAVE(APPLE_GRAPHICS_CONTROL)
+#include <sys/sysctl.h>
+#endif
+
+namespace WebCore {
+
+#if HAVE(APPLE_GRAPHICS_CONTROL)
+
+enum {
+    kAGCOpen,
+    kAGCClose
+};
+
+static io_connect_t attachToAppleGraphicsControl()
+{
+    mach_port_t masterPort = MACH_PORT_NULL;
+
+    if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
+        return MACH_PORT_NULL;
+
+    CFDictionaryRef classToMatch = IOServiceMatching("AppleGraphicsControl");
+    if (!classToMatch)
+        return MACH_PORT_NULL;
+
+    kern_return_t kernResult;
+    io_iterator_t iterator;
+    if ((kernResult = IOServiceGetMatchingServices(masterPort, classToMatch, &iterator)) != KERN_SUCCESS)
+        return MACH_PORT_NULL;
+
+    io_service_t serviceObject = IOIteratorNext(iterator);
+    IOObjectRelease(iterator);
+    if (!serviceObject)
+        return MACH_PORT_NULL;
+
+    io_connect_t dataPort;
+    IOObjectRetain(serviceObject);
+    kernResult = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);
+    IOObjectRelease(serviceObject);
+
+    return (kernResult == KERN_SUCCESS) ? dataPort : MACH_PORT_NULL;
+}
+
+static bool hasMuxCapability()
+{
+    io_connect_t dataPort = attachToAppleGraphicsControl();
+
+    if (dataPort == MACH_PORT_NULL)
+        return false;
+
+    bool result;
+    if (IOConnectCallScalarMethod(dataPort, kAGCOpen, nullptr, 0, nullptr, nullptr) == KERN_SUCCESS) {
+        IOConnectCallScalarMethod(dataPort, kAGCClose, nullptr, 0, nullptr, nullptr);
+        result = true;
+    } else
+        result = false;
+
+    IOServiceClose(dataPort);
+
+    if (result) {
+        // This is detecting Mac hardware with an Intel g575 GPU, which
+        // we don't want to make available to muxing.
+        // Based on information from Apple's OpenGL team, such devices
+        // have four or fewer processors.
+        // <rdar://problem/30060378>
+        int names[2] = { CTL_HW, HW_NCPU };
+        int cpuCount;
+        size_t cpuCountLength = sizeof(cpuCount);
+        sysctl(names, 2, &cpuCount, &cpuCountLength, nullptr, 0);
+        result = cpuCount > 4;
+    }
+
+    return result;
+}
+
+#endif // HAVE(APPLE_GRAPHICS_CONTROL)
+
+bool hasLowAndHighPowerGPUs()
+{
+#if HAVE(APPLE_GRAPHICS_CONTROL)
+    static bool canMux = hasMuxCapability();
+    return canMux;
+#else
+    return false;
+#endif
+}
+
+}
+
+#endif
+

Copied: branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.h (from rev 272278, branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h) (0 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.h	                        (rev 0)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -0,0 +1,32 @@
+/*
+ * 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
+
+namespace WebCore {
+
+WEBCORE_EXPORT bool hasLowAndHighPowerGPUs();
+
+}

Copied: branches/safari-611-branch/Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h (from rev 272278, branches/safari-611-branch/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h) (0 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h	                        (rev 0)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -0,0 +1,72 @@
+/*
+ * 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 "GraphicsChecksMac.h"
+#include "SwitchingGPUClient.h"
+
+namespace WebCore {
+
+class ScopedHighPerformanceGPURequest {
+public:
+    ScopedHighPerformanceGPURequest() = default;
+    ScopedHighPerformanceGPURequest(ScopedHighPerformanceGPURequest&& other)
+        : m_requested(std::exchange(other.m_requested, false))
+    {
+    }
+    ~ScopedHighPerformanceGPURequest()
+    {
+        if (!m_requested)
+            return;
+        SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU();
+    }
+    ScopedHighPerformanceGPURequest& operator=(ScopedHighPerformanceGPURequest&& other)
+    {
+        if (m_requested)
+            SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU();
+        m_requested = std::exchange(other.m_requested, false);
+        return *this;
+    }
+    static ScopedHighPerformanceGPURequest acquire()
+    {
+        if (!hasLowAndHighPowerGPUs())
+            return { };
+        auto client = SwitchingGPUClient::singletonIfExists();
+        if (!client)
+            return { };
+        client->requestHighPerformanceGPU();
+        return { DidRequest };
+    }
+private:
+    enum RequestState { DidRequest };
+    ScopedHighPerformanceGPURequest(RequestState)
+        : m_requested(true)
+    {
+    }
+    bool m_requested { false };
+};
+
+}

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -29,16 +29,16 @@
 
 class SwitchingGPUClient {
 public:
-    WEBCORE_EXPORT static SwitchingGPUClient* singletonIfExists();
     WEBCORE_EXPORT static void setSingleton(SwitchingGPUClient&);
 
     virtual ~SwitchingGPUClient() = default;
-
+private:
+    WEBCORE_EXPORT static SwitchingGPUClient* singletonIfExists();
     virtual void requestHighPerformanceGPU() = 0;
     virtual void releaseHighPerformanceGPU() = 0;
-    
-private:
+
     static SwitchingGPUClient* m_singleton;
+    friend class ScopedHighPerformanceGPURequest;
 };
 
 }

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -69,6 +69,10 @@
 }
 #endif
 
+#if PLATFORM(MAC)
+#include "ScopedHighPerformanceGPURequest.h"
+#endif
+
 namespace WebCore {
 class ExtensionsGL;
 #if USE(ANGLE)
@@ -256,7 +260,7 @@
     void texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLSpan<const GCGLvoid> pixels) final;
     void texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLintptr offset) final;
     void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data) final;
-    void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLintptr offset) final; 
+    void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLintptr offset) final;
     void compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data) final;
     void compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLintptr offset) final;
 
@@ -455,14 +459,12 @@
     void primitiveRestartIndex(GCGLuint);
 #endif
 
-#if PLATFORM(COCOA) && PLATFORM(MAC)
-    void updateCGLContext();
+#if PLATFORM(COCOA)
+    void displayWasReconfigured();
 #endif
 
     void setContextVisibility(bool) final;
 
-    GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final { return m_powerPreferenceUsedForCreation; }
-
     // Support for buffer creation and deletion
     PlatformGLObject createBuffer() final;
     PlatformGLObject createFramebuffer() final;
@@ -491,11 +493,6 @@
 
     unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); }
 
-#if PLATFORM(MAC)
-    using PlatformDisplayID = uint32_t;
-    void screenDidChange(PlatformDisplayID);
-#endif
-
     void prepareForDisplay() final;
 
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
@@ -523,7 +520,7 @@
     // implementation.
     void validateDepthStencil(const char* packedDepthStencilExtension);
     void validateAttributes();
-    
+
     void readnPixelsImpl(GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLsizei bufSize, GCGLsizei* length, GCGLsizei* columns, GCGLsizei* rows, GCGLvoid* data, bool readingToPixelBufferObject);
 
     // Did the most recent drawing operation leave the GPU in an acceptable state?
@@ -541,7 +538,6 @@
     void attachDepthAndStencilBufferIfNeeded(GCGLuint internalDepthStencilFormat, int width, int height);
 
 #if PLATFORM(COCOA)
-    bool allowOfflineRenderers() const;
     bool reshapeDisplayBufferBacking();
     bool allocateAndBindDisplayBufferBacking();
     bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
@@ -577,7 +573,7 @@
             , isValid(false)
         {
         }
-        
+
         ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType)
         {
             ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING);
@@ -642,7 +638,6 @@
     std::unique_ptr<ExtensionsGLOpenGL> m_extensions;
 #endif
 
-    GraphicsContextGLPowerPreference m_powerPreferenceUsedForCreation { GraphicsContextGLPowerPreference::Default };
     Vector<Vector<float>> m_vertexArray;
 
 #if !USE(ANGLE)
@@ -672,7 +667,7 @@
 
         using BoundTextureMap = HashMap<GCGLenum,
             std::pair<GCGLuint, GCGLenum>,
-            WTF::IntHash<GCGLenum>, 
+            WTF::IntHash<GCGLenum>,
             WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>,
             WTF::PairHashTraits<WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>, WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>>
         >;
@@ -753,9 +748,11 @@
     // When preserveDrawingBuffer == true, this is blitted to during display prepare.
     std::unique_ptr<IOSurface> m_displayBufferBacking;
     void* m_displayBufferPbuffer { nullptr };
-
-    bool m_hasSwitchedToHighPerformanceGPU { false };
 #endif
+#if PLATFORM(MAC)
+    bool m_supportsPowerPreference { false };
+    ScopedHighPerformanceGPURequest m_highPerformanceGPURequest;
+#endif
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
     std::unique_ptr<GraphicsContextGLCV> m_cv;
 #endif

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -31,91 +31,8 @@
 #include "GraphicsContextGLOpenGL.h"
 #include "Logging.h"
 
-#if HAVE(APPLE_GRAPHICS_CONTROL)
-#include <sys/sysctl.h>
-#endif
-
-#if PLATFORM(MAC)
-#include "SwitchingGPUClient.h"
-#endif
-
 namespace WebCore {
 
-#if HAVE(APPLE_GRAPHICS_CONTROL)
-
-enum {
-    kAGCOpen,
-    kAGCClose
-};
-
-static io_connect_t attachToAppleGraphicsControl()
-{
-    mach_port_t masterPort = MACH_PORT_NULL;
-    
-    if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
-        return MACH_PORT_NULL;
-    
-    CFDictionaryRef classToMatch = IOServiceMatching("AppleGraphicsControl");
-    if (!classToMatch)
-        return MACH_PORT_NULL;
-    
-    kern_return_t kernResult;
-    io_iterator_t iterator;
-    if ((kernResult = IOServiceGetMatchingServices(masterPort, classToMatch, &iterator)) != KERN_SUCCESS)
-        return MACH_PORT_NULL;
-    
-    io_service_t serviceObject = IOIteratorNext(iterator);
-    IOObjectRelease(iterator);
-    if (!serviceObject)
-        return MACH_PORT_NULL;
-    
-    io_connect_t dataPort;
-    IOObjectRetain(serviceObject);
-    kernResult = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);
-    IOObjectRelease(serviceObject);
-    
-    return (kernResult == KERN_SUCCESS) ? dataPort : MACH_PORT_NULL;
-}
-
-static bool hasMuxCapability()
-{
-    io_connect_t dataPort = attachToAppleGraphicsControl();
-    
-    if (dataPort == MACH_PORT_NULL)
-        return false;
-    
-    bool result;
-    if (IOConnectCallScalarMethod(dataPort, kAGCOpen, nullptr, 0, nullptr, nullptr) == KERN_SUCCESS) {
-        IOConnectCallScalarMethod(dataPort, kAGCClose, nullptr, 0, nullptr, nullptr);
-        result = true;
-    } else
-        result = false;
-    
-    IOServiceClose(dataPort);
-    
-    if (result) {
-        // This is detecting Mac hardware with an Intel g575 GPU, which
-        // we don't want to make available to muxing.
-        // Based on information from Apple's OpenGL team, such devices
-        // have four or fewer processors.
-        // <rdar://problem/30060378>
-        int names[2] = { CTL_HW, HW_NCPU };
-        int cpuCount;
-        size_t cpuCountLength = sizeof(cpuCount);
-        sysctl(names, 2, &cpuCount, &cpuCountLength, nullptr, 0);
-        result = cpuCount > 4;
-    }
-    
-    return result;
-}
-
-bool hasLowAndHighPowerGPUs()
-{
-    static bool canMux = hasMuxCapability();
-    return canMux;
-}
-#endif // HAVE(APPLE_GRAPHICS_CONTROL)
-
 GraphicsContextGLOpenGLManager& GraphicsContextGLOpenGLManager::sharedManager()
 {
     static NeverDestroyed<GraphicsContextGLOpenGLManager> s_manager;
@@ -127,33 +44,19 @@
 {
     LOG(WebGL, "GraphicsContextGLOpenGLManager::displayWasReconfigured");
     if (flags & kCGDisplaySetModeFlag)
-        GraphicsContextGLOpenGLManager::sharedManager().updateAllContexts();
+        GraphicsContextGLOpenGLManager::sharedManager().displayWasReconfigured();
 }
 #endif
 
-void GraphicsContextGLOpenGLManager::updateAllContexts()
+#if PLATFORM(COCOA)
+void GraphicsContextGLOpenGLManager::displayWasReconfigured()
 {
-#if PLATFORM(MAC)
-    for (const auto& context : m_contexts) {
-        context->updateCGLContext();
-        context->dispatchContextChangedNotification();
-    }
-#endif
+    for (const auto& context : m_contexts)
+        context->displayWasReconfigured();
 }
-
-#if PLATFORM(MAC)
-void GraphicsContextGLOpenGLManager::screenDidChange(PlatformDisplayID displayID, const HostWindow* window)
-{
-    for (const auto& contextAndWindow : m_contextWindowMap) {
-        if (contextAndWindow.value == window) {
-            contextAndWindow.key->screenDidChange(displayID);
-            LOG(WebGL, "Changing context (%p) to display (%d).", contextAndWindow.key, displayID);
-        }
-    }
-}
 #endif
 
-void GraphicsContextGLOpenGLManager::addContext(GraphicsContextGLOpenGL* context, HostWindow* window)
+void GraphicsContextGLOpenGLManager::addContext(GraphicsContextGLOpenGL* context)
 {
     ASSERT(context);
     if (!context)
@@ -166,7 +69,6 @@
 
     ASSERT(!m_contexts.contains(context));
     m_contexts.append(context);
-    m_contextWindowMap.set(context, window);
 }
 
 void GraphicsContextGLOpenGLManager::removeContext(GraphicsContextGLOpenGL* context)
@@ -174,9 +76,6 @@
     if (!m_contexts.contains(context))
         return;
     m_contexts.removeFirst(context);
-    m_contextWindowMap.remove(context);
-    removeContextRequiringHighPerformance(context);
-    
 #if PLATFORM(MAC) && !ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     if (!m_contexts.size())
         CGDisplayRemoveReconfigurationCallback(displayWasReconfigured, nullptr);
@@ -183,88 +82,6 @@
 #endif
 }
 
-HostWindow* GraphicsContextGLOpenGLManager::hostWindowForContext(GraphicsContextGLOpenGL* context) const
-{
-    ASSERT(m_contextWindowMap.contains(context));
-    return m_contextWindowMap.get(context);
-}
-
-void GraphicsContextGLOpenGLManager::addContextRequiringHighPerformance(GraphicsContextGLOpenGL* context)
-{
-    ASSERT(context);
-    if (!context)
-        return;
-    
-    ASSERT(m_contexts.contains(context));
-    ASSERT(!m_contextsRequiringHighPerformance.contains(context));
-    
-    LOG(WebGL, "This context (%p) requires the high-performance GPU.", context);
-    m_contextsRequiringHighPerformance.add(context);
-    
-    updateHighPerformanceState();
-}
-
-void GraphicsContextGLOpenGLManager::removeContextRequiringHighPerformance(GraphicsContextGLOpenGL* context)
-{
-    if (!context)
-        return;
-
-    if (!m_contextsRequiringHighPerformance.contains(context))
-        return;
-    
-    LOG(WebGL, "This context (%p) no longer requires the high-performance GPU.", context);
-    m_contextsRequiringHighPerformance.remove(context);
-    
-    updateHighPerformanceState();
-}
-
-void GraphicsContextGLOpenGLManager::updateHighPerformanceState()
-{
-#if PLATFORM(MAC)
-    if (!hasLowAndHighPowerGPUs())
-        return;
-    
-    if (m_contextsRequiringHighPerformance.size()) {
-        
-        if (m_disableHighPerformanceGPUTimer.isActive()) {
-            LOG(WebGL, "Cancel pending timer for turning off high-performance GPU.");
-            m_disableHighPerformanceGPUTimer.stop();
-        }
-
-        if (!m_requestingHighPerformance) {
-            LOG(WebGL, "Request the high-performance GPU.");
-            m_requestingHighPerformance = true;
-            if (auto* singleton = SwitchingGPUClient::singletonIfExists())
-                singleton->requestHighPerformanceGPU();
-        }
-
-    } else {
-        // Don't immediately turn off the high-performance GPU. The user might be
-        // swapping back and forth between tabs or windows, and we don't want to cause
-        // churn if we can avoid it.
-        if (!m_disableHighPerformanceGPUTimer.isActive()) {
-            LOG(WebGL, "Set a timer to release the high-performance GPU.");
-            // FIXME: Expose this value as a Setting, which would require this class
-            // to reference a frame, page or document.
-            static const Seconds timeToKeepHighPerformanceGPUAlive { 10_s };
-            m_disableHighPerformanceGPUTimer.startOneShot(timeToKeepHighPerformanceGPUAlive);
-        }
-    }
-#endif
-}
-
-void GraphicsContextGLOpenGLManager::disableHighPerformanceGPUTimerFired()
-{
-    if (m_contextsRequiringHighPerformance.size())
-        return;
-
-    m_requestingHighPerformance = false;
-#if PLATFORM(MAC)
-    if (auto* singleton = SwitchingGPUClient::singletonIfExists())
-        singleton->releaseHighPerformanceGPU();
-#endif
-}
-
 void GraphicsContextGLOpenGLManager::recycleContextIfNecessary()
 {
     if (hasTooManyContexts()) {

Modified: branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -25,8 +25,6 @@
 
 #pragma once
 
-#include "Timer.h"
-#include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 
 #if PLATFORM(MAC)
@@ -38,52 +36,29 @@
 const unsigned MaxContexts = 16;
 
 class GraphicsContextGLOpenGL;
-class HostWindow;
 
-using PlatformDisplayID = uint32_t;
-
-#if HAVE(APPLE_GRAPHICS_CONTROL)
-WEBCORE_EXPORT bool hasLowAndHighPowerGPUs();
-#endif
-
 class GraphicsContextGLOpenGLManager {
     friend NeverDestroyed<GraphicsContextGLOpenGLManager>;
 public:
     static GraphicsContextGLOpenGLManager& sharedManager();
     
-    void addContext(GraphicsContextGLOpenGL*, HostWindow*);
+    void addContext(GraphicsContextGLOpenGL*);
     void removeContext(GraphicsContextGLOpenGL*);
-
-    HostWindow* hostWindowForContext(GraphicsContextGLOpenGL*) const;
     
-    void addContextRequiringHighPerformance(GraphicsContextGLOpenGL*);
-    void removeContextRequiringHighPerformance(GraphicsContextGLOpenGL*);
-    
     void recycleContextIfNecessary();
     bool hasTooManyContexts() const { return m_contexts.size() >= MaxContexts; }
     
-    void updateAllContexts();
-
 #if PLATFORM(MAC)
-    void screenDidChange(PlatformDisplayID, const HostWindow*);
     WEBCORE_EXPORT static void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void*);
 #endif
+#if PLATFORM(COCOA)
+    void displayWasReconfigured();
+#endif
     
 private:
-    GraphicsContextGLOpenGLManager()
-        : m_disableHighPerformanceGPUTimer(*this, &GraphicsContextGLOpenGLManager::disableHighPerformanceGPUTimerFired)
-    {
-    }
+    GraphicsContextGLOpenGLManager() = default;
 
-    void updateHighPerformanceState();
-    void disableHighPerformanceGPUTimerFired();
-
     Vector<GraphicsContextGLOpenGL*> m_contexts;
-    HashMap<GraphicsContextGLOpenGL*, HostWindow*> m_contextWindowMap;
-    HashSet<GraphicsContextGLOpenGL*> m_contextsRequiringHighPerformance;
-    
-    Timer m_disableHighPerformanceGPUTimer;
-    bool m_requestingHighPerformance { false };
 };
 
 }

Modified: branches/safari-611-branch/Source/WebCore/testing/Internals.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebCore/testing/Internals.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebCore/testing/Internals.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -319,7 +319,7 @@
 #endif
 
 #if PLATFORM(MAC)
-#include "GraphicsContextGLOpenGLManager.h"
+#include "GraphicsChecksMac.h"
 #include "NSScrollerImpDetails.h"
 #include "ScrollbarThemeMac.h"
 #endif

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (272278 => 272279)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-02-03 01:41:19 UTC (rev 272279)
@@ -1,5 +1,102 @@
 2021-02-02  Alan Coon  <[email protected]>
 
+        Cherry-pick r271880. rdar://problem/73889737
+
+    WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
+    https://bugs.webkit.org/show_bug.cgi?id=220843
+    
+    Patch by Kimmo Kinnunen <[email protected]> on 2021-01-26
+    Reviewed by Dean Jackson.
+    
+    Source/WebCore:
+    
+    Use ANGLE extension EGL_ANGLE_power_preference to signal to ANGLE that the underlying
+    CGL context should be updated as a response to display reconfiguration signal.
+    This ensures that ANGLE state stays consistent with the actual CGL context behavior, as
+    we don't change the context behind ANGLE's back.
+    
+    Remove the feature where the context GPU is selected based on the display the window is
+    on. This cannot work with the logic of "powerPreference = "high-performance" goes to
+    discrete GPU". Also, this cannot work with ANGLE at all, since all contexts are backed
+    by a single platform context. Thus all contexts will use the same underlying GPU.
+    
+    No new tests due to the test runner missing features. The bug blockers track the testing.
+    
+    * PlatformMac.cmake:
+    * SourcesCocoa.txt:
+    * WebCore.xcodeproj/project.pbxproj:
+    * html/canvas/WebGLRenderingContextBase.cpp:
+    (WebCore::isHighPerformanceContext):
+    * page/Chrome.cpp:
+    (WebCore::Chrome::windowScreenDidChange):
+    * platform/graphics/GraphicsContextGL.h:
+    * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
+    * platform/graphics/RemoteGraphicsContextGLProxyBase.h:
+    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+    (WebCore::GraphicsContextGLOpenGL::create):
+    (WebCore::GraphicsContextGLOpenGL::createShared):
+    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+    (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
+    (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
+    (WebCore::GraphicsContextGLOpenGL::simulateContextChanged):
+    * platform/graphics/mac/GraphicsChecksMac.cpp: Added.
+    (WebCore::attachToAppleGraphicsControl):
+    (WebCore::hasMuxCapability):
+    (WebCore::hasLowAndHighPowerGPUs):
+    * platform/graphics/mac/GraphicsChecksMac.h: Copied from Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h.
+    * platform/graphics/mac/ScopedHighPerformanceGPURequest.h: Copied from Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h.
+    (WebCore::ScopedHighPerformanceGPURequest::ScopedHighPerformanceGPURequest):
+    (WebCore::ScopedHighPerformanceGPURequest::~ScopedHighPerformanceGPURequest):
+    (WebCore::ScopedHighPerformanceGPURequest::operator=):
+    (WebCore::ScopedHighPerformanceGPURequest::acquire):
+    * platform/graphics/mac/SwitchingGPUClient.h:
+    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp:
+    (WebCore::GraphicsContextGLOpenGLManager::displayWasReconfigured):
+    (WebCore::GraphicsContextGLOpenGLManager::addContext):
+    (WebCore::GraphicsContextGLOpenGLManager::removeContext):
+    * platform/graphics/opengl/GraphicsContextGLOpenGLManager.h:
+    * testing/Internals.cpp:
+    
+    Source/WebKit:
+    
+    Move the high-performance GPU shutdown timer from individual web processes to the main class
+    in the ui process. This simplifies the implementation and reduces the number of timers.
+    
+    * UIProcess/mac/HighPerformanceGPUManager.h:
+    * UIProcess/mac/HighPerformanceGPUManager.mm:
+    (WebKit::HighPerformanceGPUManager::HighPerformanceGPUManager):
+    (WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance):
+    (WebKit::HighPerformanceGPUManager::updateState):
+    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp:
+    (WebKit::WebSwitchingGPUClient::requestHighPerformanceGPU):
+    (WebKit::WebSwitchingGPUClient::releaseHighPerformanceGPU):
+    * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271880 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-26  Kimmo Kinnunen  <[email protected]>
+
+            WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
+            https://bugs.webkit.org/show_bug.cgi?id=220843
+
+            Reviewed by Dean Jackson.
+
+            Move the high-performance GPU shutdown timer from individual web processes to the main class
+            in the ui process. This simplifies the implementation and reduces the number of timers.
+
+            * UIProcess/mac/HighPerformanceGPUManager.h:
+            * UIProcess/mac/HighPerformanceGPUManager.mm:
+            (WebKit::HighPerformanceGPUManager::HighPerformanceGPUManager):
+            (WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance):
+            (WebKit::HighPerformanceGPUManager::updateState):
+            * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp:
+            (WebKit::WebSwitchingGPUClient::requestHighPerformanceGPU):
+            (WebKit::WebSwitchingGPUClient::releaseHighPerformanceGPU):
+            * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h:
+
+2021-02-02  Alan Coon  <[email protected]>
+
         Cherry-pick r272072. rdar://problem/73890534
 
     [iOS] Stop observing changes in one preference domain

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -28,6 +28,7 @@
 #if PLATFORM(MAC)
 
 #include <OpenGL/CGLTypes.h>
+#include <WebCore/Timer.h>
 #include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 
@@ -44,13 +45,13 @@
     void removeProcessRequiringHighPerformance(WebProcessProxy*);
 
 private:
-    HighPerformanceGPUManager() = default;
+    HighPerformanceGPUManager();
     ~HighPerformanceGPUManager();
-
     void updateState();
 
     HashSet<WebProcessProxy*> m_processesRequiringHighPerformance;
     CGLPixelFormatObj m_pixelFormatObj { nullptr };
+    WebCore::Timer m_updateStateTimer;
 };
 
 }

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.mm (272278 => 272279)


--- branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.mm	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.mm	2021-02-03 01:41:19 UTC (rev 272279)
@@ -29,7 +29,7 @@
 #if PLATFORM(MAC)
 
 #include "Logging.h"
-#include <WebCore/GraphicsContextGLOpenGLManager.h>
+#include <WebCore/GraphicsChecksMac.h>
 #include <WebCore/OpenGLSoftLinkCocoa.h>
 
 namespace WebKit {
@@ -44,6 +44,13 @@
     return sharedManager;
 }
 
+HighPerformanceGPUManager::HighPerformanceGPUManager()
+    : m_updateStateTimer(*this, &HighPerformanceGPUManager::updateState)
+{
+}
+
+HighPerformanceGPUManager::~HighPerformanceGPUManager() = default;
+
 void HighPerformanceGPUManager::addProcessRequiringHighPerformance(WebProcessProxy* process)
 {
     if (!WebCore::hasLowAndHighPowerGPUs())
@@ -65,7 +72,8 @@
 
     if (m_processesRequiringHighPerformance.remove(process)) {
         LOG(WebGL, "HighPerformanceGPUManager::removeProcessRequiringHighPerformance() - removing process %p", process);
-        updateState();
+        static const Seconds timeToKeepHighPerformanceGPUAlive { 10_s };
+        m_updateStateTimer.startOneShot(timeToKeepHighPerformanceGPUAlive);
         return;
     }
 
@@ -74,6 +82,8 @@
 
 void HighPerformanceGPUManager::updateState()
 {
+    if (m_updateStateTimer.isActive())
+        m_updateStateTimer.stop();
     if (m_processesRequiringHighPerformance.size()) {
         if (!m_pixelFormatObj) {
             LOG(WebGL, "HighPerformanceGPUManager - turning on high-performance GPU.");

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp (272278 => 272279)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp	2021-02-03 01:41:19 UTC (rev 272279)
@@ -43,6 +43,9 @@
 
 void WebSwitchingGPUClient::requestHighPerformanceGPU()
 {
+    m_requests++;
+    if (m_requests != 1)
+        return;
     LOG(WebGL, "WebSwitchingGPUClient::requestHighPerformanceGPU() from WebProcess");
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::RequestHighPerformanceGPU(), 0);
 }
@@ -49,6 +52,10 @@
 
 void WebSwitchingGPUClient::releaseHighPerformanceGPU()
 {
+    ASSERT(m_requests);
+    m_requests--;
+    if (m_requests)
+        return;
     LOG(WebGL, "WebSwitchingGPUClient::releaseHighPerformanceGPU() from WebProcess");
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::ReleaseHighPerformanceGPU(), 0);
 }

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h (272278 => 272279)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h	2021-02-03 01:41:12 UTC (rev 272278)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h	2021-02-03 01:41:19 UTC (rev 272279)
@@ -32,9 +32,10 @@
 class WebSwitchingGPUClient : public WebCore::SwitchingGPUClient {
 public:
     static WebSwitchingGPUClient& singleton();
-    
+private:
     void requestHighPerformanceGPU() override;
     void releaseHighPerformanceGPU() override;
+    unsigned m_requests { 0 };
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to