WebKit Bugzilla
Attachment 349090 Details for
Bug 189361
: [macOS] Switching to discrete GPU should be done in the UI process
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189361-20180906163934.patch (text/plain), 51.04 KB, created by
Per Arne Vollan
on 2018-09-06 16:39:35 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Per Arne Vollan
Created:
2018-09-06 16:39:35 PDT
Size:
51.04 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 235745) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,40 @@ >+2018-09-06 Per Arne Vollan <pvollan@apple.com> >+ >+ [macOS] Switching to discrete GPU should be done in the UI process >+ https://bugs.webkit.org/show_bug.cgi?id=189361 >+ <rdar://problem/43949622> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ When WebGL is requesting to use the discrete GPU on a muxable system by setting the powerPreference >+ attribute to "high-performance", a call to CGLChoosePixelFormat is made to perform the switch. This >+ method of switching does not work when there is no WindowServer access in the WebContent process. >+ This call needs to be made in the UI process. This patch adds two new support classes (GPUClient >+ and WebGPUClient) to broker these calls to the UI process. WebKit legacy support is maintained by >+ implementing the WebGPUClient class on the legacy side. The new code is protected by using the >+ ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) define. >+ >+ Test: fast/canvas/webgl/switch-to-discrete-gpu.html >+ >+ * WebCore.xcodeproj/project.pbxproj: >+ * platform/graphics/GraphicsContext3DManager.cpp: >+ (WebCore::GraphicsContext3DManager::enableHighPerformanceGPU): >+ (WebCore::GraphicsContext3DManager::disableHighPerformanceGPU): >+ (WebCore::GraphicsContext3DManager::updateHighPerformanceState): >+ (WebCore::GraphicsContext3DManager::highPerformanceGPUEnabled const): >+ (WebCore::GraphicsContext3DManager::disableHighPerformanceGPUTimerFired): >+ * platform/graphics/GraphicsContext3DManager.h: >+ * platform/graphics/mac/GPUClient.cpp: Added. >+ (WebCore::GPUClient::singleton): >+ (WebCore::GPUClient::setSingleton): >+ * platform/graphics/mac/GPUClient.h: Added. >+ (WebCore::GPUClient::~GPUClient): >+ * testing/Internals.cpp: >+ (WebCore::Internals::hasMuxableGPU): >+ * testing/Internals.h: >+ * testing/Internals.idl: >+ * testing/Internals.mm: >+ > 2018-09-06 Zalan Bujtas <zalan@apple.com> > > [LFC][BFC] Add support for min(max)-width >Index: Source/WebCore/WebCore.xcodeproj/project.pbxproj >=================================================================== >--- Source/WebCore/WebCore.xcodeproj/project.pbxproj (revision 235745) >+++ Source/WebCore/WebCore.xcodeproj/project.pbxproj (working copy) >@@ -3897,6 +3897,8 @@ > C0C054CD1118C8E400CE2636 /* IDLParser.pm in Headers */ = {isa = PBXBuildFile; fileRef = 14813BF309EDF88E00F757E1 /* IDLParser.pm */; settings = {ATTRIBUTES = (Private, ); }; }; > C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */ = {isa = PBXBuildFile; fileRef = C0F2A43F13869A280066C534 /* preprocessor.pm */; settings = {ATTRIBUTES = (Private, ); }; }; > C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; }; >+ C11A9ECE21403A5C00CFB20A /* GPUClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C11A9ECD21403A5C00CFB20A /* GPUClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ C11A9ED32140578B00CFB20A /* GPUClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C11A9ED22140578B00CFB20A /* GPUClient.cpp */; }; > C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = C1E1D235203DF15400584665 /* ScreenProperties.h */; settings = {ATTRIBUTES = (Private, ); }; }; > C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */; }; > C21DF2EA1D9E4E9900F5B24C /* CSSFontVariationValue.h in Headers */ = {isa = PBXBuildFile; fileRef = C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */; }; >@@ -13036,6 +13038,8 @@ > C0F2A43F13869A280066C534 /* preprocessor.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = preprocessor.pm; path = scripts/preprocessor.pm; sourceTree = "<group>"; }; > C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; }; > C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; }; >+ C11A9ECD21403A5C00CFB20A /* GPUClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUClient.h; sourceTree = "<group>"; }; >+ C11A9ED22140578B00CFB20A /* GPUClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUClient.cpp; sourceTree = "<group>"; }; > C1E1D235203DF15400584665 /* ScreenProperties.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenProperties.h; sourceTree = "<group>"; }; > C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontVariantBuilder.h; sourceTree = "<group>"; }; > C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; }; >@@ -23521,6 +23525,8 @@ > B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */, > B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */, > B2AFFC7B0D00A5C10030074D /* GlyphPageMac.cpp */, >+ C11A9ED22140578B00CFB20A /* GPUClient.cpp */, >+ C11A9ECD21403A5C00CFB20A /* GPUClient.h */, > B275358D0B053A66002CE64F /* IconMac.mm */, > B275354E0B053814002CE64F /* ImageMac.mm */, > B275354F0B053814002CE64F /* IntPointMac.mm */, >@@ -28041,6 +28047,7 @@ > 0873B86B136064EA00A522C2 /* GlyphPage.h in Headers */, > 311518FC1E78C15F00EC514A /* GPUBasedCanvasRenderingContext.h in Headers */, > 316BDBAA1E71FA9300DE0D5A /* GPUBuffer.h in Headers */, >+ C11A9ECE21403A5C00CFB20A /* GPUClient.h in Headers */, > 316BDBCE1E75F18A00DE0D5A /* GPUCommandBuffer.h in Headers */, > 316BDBBC1E73880600DE0D5A /* GPUCommandQueue.h in Headers */, > 93A953B420EBD43200A619F6 /* GPUComputeCommandEncoder.h in Headers */, >@@ -31476,6 +31483,7 @@ > 51A9D9E9195B931F001B2B5C /* GamepadManager.cpp in Sources */, > 515BE1911D54F5FB00DD7C68 /* GamepadProvider.cpp in Sources */, > 837964CF1F8DB69D00218EA0 /* GeolocationPositionIOS.mm in Sources */, >+ C11A9ED32140578B00CFB20A /* GPUClient.cpp in Sources */, > 6E21C6C01126338500A7BE02 /* GraphicsContext3D.cpp in Sources */, > D0843A4D20FEC16500FE860E /* GraphicsContext3DManager.cpp in Sources */, > 7C3E510B18DF8F3500C112F7 /* HTMLConverter.mm in Sources */, >Index: Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp >=================================================================== >--- Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp (revision 235745) >+++ Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp (working copy) >@@ -36,6 +36,7 @@ > #endif > > #if PLATFORM(MAC) >+#include "GPUClient.h" > #include <OpenGL/OpenGL.h> > #endif > >@@ -130,6 +131,29 @@ void GraphicsContext3DManager::displayWa > } > #endif > >+CGLPixelFormatObj GraphicsContext3DManager::enableHighPerformanceGPU() >+{ >+ CGLPixelFormatObj pixelFormatObj = nullptr; >+ >+ LOG(WebGL, "Turning on high-performance GPU."); >+ >+ CGLPixelFormatAttribute attributes[] = { kCGLPFAAccelerated, kCGLPFAColorSize, static_cast<CGLPixelFormatAttribute>(32), static_cast<CGLPixelFormatAttribute>(0) }; >+ GLint numPixelFormats = 0; >+ auto ret = CGLChoosePixelFormat(attributes, &pixelFormatObj, &numPixelFormats); >+ ASSERT_UNUSED(ret, ret == kCGLNoError); >+ >+ return pixelFormatObj; >+} >+ >+void GraphicsContext3DManager::disableHighPerformanceGPU(CGLPixelFormatObj& pixelFormatObj) >+{ >+ if (pixelFormatObj) { >+ LOG(WebGL, "Turning off high-performance GPU."); >+ CGLReleasePixelFormat(pixelFormatObj); >+ pixelFormatObj = nullptr; >+ } >+} >+ > void GraphicsContext3DManager::updateAllContexts() > { > #if PLATFORM(MAC) >@@ -226,15 +250,17 @@ void GraphicsContext3DManager::updateHig > m_disableHighPerformanceGPUTimer.stop(); > } > >- if (!m_pixelFormatObj) { >- LOG(WebGL, "Turning on high-performance GPU."); >- >- CGLPixelFormatAttribute attributes[] = { kCGLPFAAccelerated, kCGLPFAColorSize, static_cast<CGLPixelFormatAttribute>(32), static_cast<CGLPixelFormatAttribute>(0) }; >- GLint numPixelFormats = 0; >- CGLChoosePixelFormat(attributes, &m_pixelFormatObj, &numPixelFormats); >+#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ if (!m_highPerformanceGPUEnabled) { >+ GPUClient::singleton().enableHighPerformanceGPU(); >+ m_highPerformanceGPUEnabled = true; > } >+#else >+ if (!m_pixelFormatObj) >+ m_pixelFormatObj = enableHighPerformanceGPU(); >+#endif > >- } else if (m_pixelFormatObj) { >+ } else if (highPerformanceGPUEnabled()) { > // 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. >@@ -249,14 +275,26 @@ void GraphicsContext3DManager::updateHig > #endif > } > >+bool GraphicsContext3DManager::highPerformanceGPUEnabled() const >+{ >+#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ return m_highPerformanceGPUEnabled; >+#else >+ return m_pixelFormatObj; >+#endif >+} >+ > void GraphicsContext3DManager::disableHighPerformanceGPUTimerFired() > { >+ if (m_contextsRequiringHighPerformance.size()) >+ return; > #if PLATFORM(MAC) >- if (!m_contextsRequiringHighPerformance.size() && m_pixelFormatObj) { >- LOG(WebGL, "Turning off high-performance GPU."); >- CGLReleasePixelFormat(m_pixelFormatObj); >- m_pixelFormatObj = nullptr; >- } >+#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ GPUClient::singleton().disableHighPerformanceGPU(); >+ m_highPerformanceGPUEnabled = false; >+#else >+ disableHighPerformanceGPU(m_pixelFormatObj); >+#endif > #endif > } > >Index: Source/WebCore/platform/graphics/GraphicsContext3DManager.h >=================================================================== >--- Source/WebCore/platform/graphics/GraphicsContext3DManager.h (revision 235745) >+++ Source/WebCore/platform/graphics/GraphicsContext3DManager.h (working copy) >@@ -44,7 +44,7 @@ class HostWindow; > using PlatformDisplayID = uint32_t; > > #if HAVE(APPLE_GRAPHICS_CONTROL) >-bool hasMuxableGPU(); >+WEBCORE_EXPORT bool hasMuxableGPU(); > #endif > > class GraphicsContext3DManager { >@@ -67,6 +67,8 @@ public: > #if PLATFORM(MAC) > void screenDidChange(PlatformDisplayID, const HostWindow*); > WEBCORE_EXPORT static void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void*); >+ WEBCORE_EXPORT static CGLPixelFormatObj enableHighPerformanceGPU(); >+ WEBCORE_EXPORT static void disableHighPerformanceGPU(CGLPixelFormatObj&); > #endif > > private: >@@ -87,8 +89,13 @@ private: > Timer m_disableHighPerformanceGPUTimer; > > #if PLATFORM(MAC) >+ bool highPerformanceGPUEnabled() const; >+#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ bool m_highPerformanceGPUEnabled { false }; >+#else > CGLPixelFormatObj m_pixelFormatObj { nullptr }; > #endif >+#endif > }; > > } >Index: Source/WebCore/platform/graphics/mac/GPUClient.cpp >=================================================================== >--- Source/WebCore/platform/graphics/mac/GPUClient.cpp (nonexistent) >+++ Source/WebCore/platform/graphics/mac/GPUClient.cpp (working copy) >@@ -0,0 +1,44 @@ >+/* >+ * Copyright (C) 2018 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 "GPUClient.h" >+ >+namespace WebCore { >+ >+GPUClient* GPUClient::m_singleton = nullptr; >+ >+GPUClient& GPUClient::singleton() >+{ >+ return *m_singleton; >+} >+ >+void GPUClient::setSingleton(GPUClient& singleton) >+{ >+ m_singleton = &singleton; >+} >+ >+} >+ >Index: Source/WebCore/platform/graphics/mac/GPUClient.h >=================================================================== >--- Source/WebCore/platform/graphics/mac/GPUClient.h (nonexistent) >+++ Source/WebCore/platform/graphics/mac/GPUClient.h (working copy) >@@ -0,0 +1,44 @@ >+/* >+ * Copyright (C) 2018 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 { >+ >+class GPUClient { >+public: >+ static GPUClient& singleton(); >+ WEBCORE_EXPORT static void setSingleton(GPUClient&); >+ >+ virtual ~GPUClient() { } >+ >+ virtual void enableHighPerformanceGPU() = 0; >+ virtual void disableHighPerformanceGPU() = 0; >+ >+private: >+ static GPUClient* m_singleton; >+}; >+ >+} >Index: Source/WebCore/testing/Internals.cpp >=================================================================== >--- Source/WebCore/testing/Internals.cpp (revision 235745) >+++ Source/WebCore/testing/Internals.cpp (working copy) >@@ -271,6 +271,10 @@ > #include "MockCredentialsMessenger.h" > #endif > >+#if PLATFORM(MAC) >+#include "GraphicsContext3DManager.h" >+#endif >+ > using JSC::CallData; > using JSC::CallType; > using JSC::CodeBlock; >@@ -4718,4 +4722,13 @@ unsigned long Internals::primaryScreenDi > #endif > } > >+bool Internals::hasMuxableGPU() >+{ >+#if PLATFORM(MAC) >+ return WebCore::hasMuxableGPU(); >+#else >+ return false; >+#endif >+} >+ > } // namespace WebCore >Index: Source/WebCore/testing/Internals.h >=================================================================== >--- Source/WebCore/testing/Internals.h (revision 235745) >+++ Source/WebCore/testing/Internals.h (working copy) >@@ -736,6 +736,8 @@ public: > > unsigned long primaryScreenDisplayID(); > >+ bool hasMuxableGPU(); >+ > private: > explicit Internals(Document&); > Document* contextDocument() const; >Index: Source/WebCore/testing/Internals.idl >=================================================================== >--- Source/WebCore/testing/Internals.idl (revision 235745) >+++ Source/WebCore/testing/Internals.idl (working copy) >@@ -670,4 +670,6 @@ enum CompositingPolicy { > void notifyResourceLoadObserver(); > > unsigned long primaryScreenDisplayID(); >+ >+ boolean hasMuxableGPU(); > }; >Index: Source/WebKit/ChangeLog >=================================================================== >--- Source/WebKit/ChangeLog (revision 235745) >+++ Source/WebKit/ChangeLog (working copy) >@@ -1,3 +1,34 @@ >+2018-09-06 Per Arne Vollan <pvollan@apple.com> >+ >+ [macOS] Switching to discrete GPU should be done in the UI process >+ https://bugs.webkit.org/show_bug.cgi?id=189361 >+ <rdar://problem/43949622> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ When WebGL is requesting to use the discrete GPU on a muxable system by setting the powerPreference >+ attribute to "high-performance", a call to CGLChoosePixelFormat is made to perform the switch. This >+ method of switching does not work when there is no WindowServer access in the WebContent process. >+ This call needs to be made in the UI process. This patch adds two new support classes (GPUClient >+ and WebGPUClient) to broker these calls to the UI process. WebKit legacy support is maintained by >+ implementing the WebGPUClient class on the legacy side. The new code is protected by using the >+ ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) define. >+ >+ * UIProcess/Cocoa/WebProcessProxyCocoa.mm: >+ (WebKit::WebProcessProxy::enableHighPerformanceGPU): >+ (WebKit::WebProcessProxy::disableHighPerformanceGPU): >+ * UIProcess/WebPageProxy.h: >+ * UIProcess/WebProcessProxy.h: >+ * UIProcess/WebProcessProxy.messages.in: >+ * WebKit.xcodeproj/project.pbxproj: >+ * WebProcess/WebCoreSupport/mac/WebGPUClient.cpp: Added. >+ (WebKit::WebGPUClient::singleton): >+ (WebKit::WebGPUClient::enableHighPerformanceGPU): >+ (WebKit::WebGPUClient::disableHighPerformanceGPU): >+ * WebProcess/WebCoreSupport/mac/WebGPUClient.h: Added. >+ * WebProcess/cocoa/WebProcessCocoa.mm: >+ (WebKit::WebProcess::platformInitializeProcess): >+ > 2018-09-06 Frederic Wang <fwang@igalia.com> > > Use more generic names than "overflow" for functions that can be used for subframes >Index: Source/WebKit/UIProcess/WebPageProxy.h >=================================================================== >--- Source/WebKit/UIProcess/WebPageProxy.h (revision 235745) >+++ Source/WebKit/UIProcess/WebPageProxy.h (working copy) >@@ -1820,6 +1820,9 @@ private: > #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) > void startDisplayLink(unsigned observerID); > void stopDisplayLink(unsigned observerID); >+ >+ void enableHighPerformanceGPU(); >+ void disableHighPerformanceGPU(); > #endif > > void reportPageLoadResult(const WebCore::ResourceError& = { }); >Index: Source/WebKit/UIProcess/WebProcessProxy.h >=================================================================== >--- Source/WebKit/UIProcess/WebProcessProxy.h (revision 235745) >+++ Source/WebKit/UIProcess/WebProcessProxy.h (working copy) >@@ -50,6 +50,10 @@ > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > >+#if PLATFORM(MAC) >+#include <WebCore/GraphicsContext3DManager.h> >+#endif >+ > namespace API { > class Navigation; > class PageConfiguration; >@@ -226,6 +230,11 @@ public: > void cacheMediaMIMETypes(const Vector<String>&); > #endif > >+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ void enableHighPerformanceGPU(); >+ void disableHighPerformanceGPU(); >+#endif >+ > // Called when the web process has crashed or we know that it will terminate soon. > // Will potentially cause the WebProcessProxy object to be freed. > void shutDown(); >@@ -397,6 +406,10 @@ private: > #if PLATFORM(WATCHOS) > ProcessThrottler::BackgroundActivityToken m_backgroundActivityTokenForFullscreenFormControls; > #endif >+ >+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ CGLPixelFormatObj m_pixelFormatObj { nullptr }; >+#endif > }; > > } // namespace WebKit >Index: Source/WebKit/UIProcess/WebProcessProxy.messages.in >=================================================================== >--- Source/WebKit/UIProcess/WebProcessProxy.messages.in (revision 235745) >+++ Source/WebKit/UIProcess/WebProcessProxy.messages.in (working copy) >@@ -70,4 +70,9 @@ messages -> WebProcessProxy LegacyReceiv > #if PLATFORM(COCOA) > CacheMediaMIMETypes(Vector<String> types) > #endif >+ >+#if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) >+ EnableHighPerformanceGPU() >+ DisableHighPerformanceGPU() >+#endif > } >Index: Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm >=================================================================== >--- Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm (revision 235745) >+++ Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm (working copy) >@@ -172,4 +172,17 @@ Vector<String> WebProcessProxy::mediaMIM > return mediaTypeCache(); > } > >+ >+void WebProcessProxy::enableHighPerformanceGPU() >+{ >+ if (m_pixelFormatObj) >+ return; >+ m_pixelFormatObj = WebCore::GraphicsContext3DManager::enableHighPerformanceGPU(); >+} >+ >+void WebProcessProxy::disableHighPerformanceGPU() >+{ >+ WebCore::GraphicsContext3DManager::disableHighPerformanceGPU(m_pixelFormatObj); >+} >+ > } >Index: Source/WebKit/WebKit.xcodeproj/project.pbxproj >=================================================================== >--- Source/WebKit/WebKit.xcodeproj/project.pbxproj (revision 235745) >+++ Source/WebKit/WebKit.xcodeproj/project.pbxproj (working copy) >@@ -1709,6 +1709,8 @@ > C0CE72A11247E71D00BC0EC4 /* WebPageMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = C0CE729F1247E71D00BC0EC4 /* WebPageMessages.h */; }; > C0CE72AD1247E78D00BC0EC4 /* HandleMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */; }; > C0E3AA7C1209E83C00A49D01 /* Module.h in Headers */ = {isa = PBXBuildFile; fileRef = C0E3AA441209E2BA00A49D01 /* Module.h */; }; >+ C11A9ECC214035F800CFB20A /* WebGPUClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C11A9ECB214035F800CFB20A /* WebGPUClient.h */; }; >+ C11A9ED121403B4000CFB20A /* WebGPUClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C11A9ED021403B4000CFB20A /* WebGPUClient.cpp */; }; > C11E1694212B87C500985FF6 /* WKMockDisplay.h in Headers */ = {isa = PBXBuildFile; fileRef = C11E1692212B87C500985FF6 /* WKMockDisplay.h */; settings = {ATTRIBUTES = (Private, ); }; }; > C11E1695212B87C500985FF6 /* WKMockDisplay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C11E1693212B87C500985FF6 /* WKMockDisplay.cpp */; }; > C18173612058424700DFDA65 /* DisplayLink.h in Headers */ = {isa = PBXBuildFile; fileRef = C18173602058424700DFDA65 /* DisplayLink.h */; }; >@@ -4472,6 +4474,8 @@ > C0E3AA441209E2BA00A49D01 /* Module.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Module.h; sourceTree = "<group>"; }; > C0E3AA451209E2BA00A49D01 /* Module.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Module.cpp; sourceTree = "<group>"; }; > C0E3AA481209E45000A49D01 /* ModuleCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModuleCF.cpp; sourceTree = "<group>"; }; >+ C11A9ECB214035F800CFB20A /* WebGPUClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUClient.h; sourceTree = "<group>"; }; >+ C11A9ED021403B4000CFB20A /* WebGPUClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUClient.cpp; sourceTree = "<group>"; }; > C11E1692212B87C500985FF6 /* WKMockDisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKMockDisplay.h; sourceTree = "<group>"; }; > C11E1693212B87C500985FF6 /* WKMockDisplay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKMockDisplay.cpp; sourceTree = "<group>"; }; > C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingAreaMac.cpp; sourceTree = "<group>"; }; >@@ -7846,6 +7850,8 @@ > C5237F5F12441CA300780472 /* WebEditorClientMac.mm */, > 9391F283121B38F500EBF7E8 /* WebFrameNetworkingContext.h */, > 9391F284121B38F500EBF7E8 /* WebFrameNetworkingContext.mm */, >+ C11A9ED021403B4000CFB20A /* WebGPUClient.cpp */, >+ C11A9ECB214035F800CFB20A /* WebGPUClient.h */, > BCC43AC6127B99DE00317F16 /* WebPopupMenuMac.mm */, > ); > path = mac; >@@ -9533,6 +9539,7 @@ > BC0E607312D6BC200012A72A /* WebGeolocationPosition.h in Headers */, > BC1BE1F212D54DBD0004A228 /* WebGeolocationProvider.h in Headers */, > 2D5036761BCED19F00E20BB3 /* WebGestureEvent.h in Headers */, >+ C11A9ECC214035F800CFB20A /* WebGPUClient.h in Headers */, > 93A88B331BC6E9CD00ABA5C2 /* WebHitTestResultData.h in Headers */, > F44DFEB21E9E752F0038D196 /* WebIconUtilities.h in Headers */, > 510523701C739D42007993CB /* WebIDBConnectionToClient.h in Headers */, >@@ -11222,6 +11229,7 @@ > CD73BA47131ACC9A00EEDED2 /* WebFullScreenManagerProxyMessageReceiver.cpp in Sources */, > BC0E606112D6BA910012A72A /* WebGeolocationManagerMessageReceiver.cpp in Sources */, > BC0E618212D6CB1D0012A72A /* WebGeolocationManagerProxyMessageReceiver.cpp in Sources */, >+ C11A9ED121403B4000CFB20A /* WebGPUClient.cpp in Sources */, > 5105236F1C739D42007993CB /* WebIDBConnectionToClient.cpp in Sources */, > 510523791C73DA77007993CB /* WebIDBConnectionToClientMessageReceiver.cpp in Sources */, > 510523751C73D38F007993CB /* WebIDBConnectionToServerMessageReceiver.cpp in Sources */, >Index: Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.cpp >=================================================================== >--- Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.cpp (nonexistent) >+++ Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.cpp (working copy) >@@ -0,0 +1,52 @@ >+/* >+ * Copyright (C) 2018 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. ``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 >+ * 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 "WebGPUClient.h" >+ >+#include "WebProcess.h" >+#include "WebProcessProxyMessages.h" >+#include <wtf/NeverDestroyed.h> >+ >+namespace WebKit { >+ >+WebGPUClient& WebGPUClient::singleton() >+{ >+ static NeverDestroyed<WebGPUClient> client; >+ return client; >+} >+ >+void WebGPUClient::enableHighPerformanceGPU() >+{ >+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::EnableHighPerformanceGPU(), 0); >+} >+ >+void WebGPUClient::disableHighPerformanceGPU() >+{ >+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DisableHighPerformanceGPU(), 0); >+} >+ >+} >+ >Index: Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.h >=================================================================== >--- Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.h (nonexistent) >+++ Source/WebKit/WebProcess/WebCoreSupport/mac/WebGPUClient.h (working copy) >@@ -0,0 +1,40 @@ >+/* >+ * Copyright (C) 2018 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/GPUClient.h> >+ >+namespace WebKit { >+ >+class WebGPUClient : public WebCore::GPUClient { >+public: >+ static WebGPUClient& singleton(); >+ >+ void enableHighPerformanceGPU() override; >+ void disableHighPerformanceGPU() override; >+}; >+ >+} >Index: Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm >=================================================================== >--- Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (revision 235745) >+++ Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (working copy) >@@ -89,6 +89,7 @@ > > #if PLATFORM(MAC) > #import "WKAccessibilityWebPageObjectMac.h" >+#import "WebGPUClient.h" > #import <WebCore/GraphicsContext3DManager.h> > #import <WebCore/ScrollbarThemeMac.h> > #import <pal/spi/mac/NSScrollerImpSPI.h> >@@ -330,6 +331,8 @@ void WebProcess::platformInitializeProce > RELEASE_ASSERT(retval == kCGErrorSuccess); > // Make sure that we close any WindowServer connections after checking in with Launch Services. > CGSShutdownServerConnections(); >+ >+ GPUClient::setSingleton(WebGPUClient::singleton()); > #else > if (![NSApp isRunning]) { > // This call is needed when the WebProcess is not running the NSApplication event loop. >Index: Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj >=================================================================== >--- Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj (revision 235745) >+++ Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj (working copy) >@@ -772,6 +772,8 @@ > C0B88E8B10A08F3D00FBB3F5 /* WebFrameLoadDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B88E8A10A08F3D00FBB3F5 /* WebFrameLoadDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; > C0C5B3EE1177A4A0002B0AEF /* WebUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = C0C5B3EC1177A4A0002B0AEF /* WebUserContentURLPattern.h */; settings = {ATTRIBUTES = (Private, ); }; }; > C0C5B3EF1177A4A0002B0AEF /* WebUserContentURLPattern.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5B3ED1177A4A0002B0AEF /* WebUserContentURLPattern.mm */; }; >+ C11EBF4121419CCE00D659E7 /* WebGPUClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C11EBF3F21419CCE00D659E7 /* WebGPUClient.cpp */; }; >+ C11EBF4221419CCE00D659E7 /* WebGPUClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C11EBF4021419CCE00D659E7 /* WebGPUClient.h */; }; > C1D81128202CD80000EE74F9 /* WebVideoFullscreenController.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1D81127202CD80000EE74F9 /* WebVideoFullscreenController.mm */; }; > C1D8112B202CDCC400EE74F9 /* WebVideoFullscreenHUDWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1D81129202CDCC200EE74F9 /* WebVideoFullscreenHUDWindowController.mm */; }; > C1D8112E202CED0800EE74F9 /* WebWindowAnimation.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1D8112D202CED0700EE74F9 /* WebWindowAnimation.mm */; }; >@@ -1525,6 +1527,8 @@ > C0B88E8A10A08F3D00FBB3F5 /* WebFrameLoadDelegatePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFrameLoadDelegatePrivate.h; sourceTree = "<group>"; }; > C0C5B3EC1177A4A0002B0AEF /* WebUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentURLPattern.h; sourceTree = "<group>"; }; > C0C5B3ED1177A4A0002B0AEF /* WebUserContentURLPattern.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebUserContentURLPattern.mm; sourceTree = "<group>"; }; >+ C11EBF3F21419CCE00D659E7 /* WebGPUClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUClient.cpp; sourceTree = "<group>"; }; >+ C11EBF4021419CCE00D659E7 /* WebGPUClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUClient.h; sourceTree = "<group>"; }; > C1D81126202CD7FE00EE74F9 /* WebVideoFullscreenController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVideoFullscreenController.h; sourceTree = "<group>"; }; > C1D81127202CD80000EE74F9 /* WebVideoFullscreenController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebVideoFullscreenController.mm; sourceTree = "<group>"; }; > C1D81129202CDCC200EE74F9 /* WebVideoFullscreenHUDWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebVideoFullscreenHUDWindowController.mm; sourceTree = "<group>"; }; >@@ -2587,6 +2591,8 @@ > 9391F274121B38BD00EBF7E8 /* WebFrameNetworkingContext.mm */, > BC7F884910C8775A00D6133D /* WebGeolocationClient.h */, > BC7F884A10C8775A00D6133D /* WebGeolocationClient.mm */, >+ C11EBF3F21419CCE00D659E7 /* WebGPUClient.cpp */, >+ C11EBF4021419CCE00D659E7 /* WebGPUClient.h */, > 06693DDA0BFBA85200216072 /* WebInspectorClient.h */, > 06693DDB0BFBA85200216072 /* WebInspectorClient.mm */, > 1C7B0C650EB2464D00A28502 /* WebInspectorClientCF.cpp */, >@@ -3034,6 +3040,7 @@ > BC7F88A510C9D88B00D6133D /* WebGeolocationPositionInternal.h in Headers */, > A10C1D701820300E0036883A /* WebGeolocationPrivate.h in Headers */, > A10C1D3618202FC50036883A /* WebGeolocationProviderIOS.h in Headers */, >+ C11EBF4221419CCE00D659E7 /* WebGPUClient.h in Headers */, > 939810120824BF01008DF038 /* WebHistory.h in Headers */, > 5158F6EF106D862A00AF457C /* WebHistoryDelegate.h in Headers */, > 93FDE9330D79CAF30074F029 /* WebHistoryInternal.h in Headers */, >@@ -3587,6 +3594,7 @@ > A10C1D3518202FC50036883A /* WebGeolocationCoreLocationProvider.mm in Sources */, > BC7F889F10C9D30C00D6133D /* WebGeolocationPosition.mm in Sources */, > A10C1D3718202FC50036883A /* WebGeolocationProviderIOS.mm in Sources */, >+ C11EBF4121419CCE00D659E7 /* WebGPUClient.cpp in Sources */, > 939811130824BF01008DF038 /* WebHistory.mm in Sources */, > 939810BD0824BF01008DF038 /* WebHistoryItem.mm in Sources */, > 1AAF5FC00EDE3A92008D883D /* WebHostedNetscapePluginView.mm in Sources */, >Index: Source/WebKitLegacy/mac/ChangeLog >=================================================================== >--- Source/WebKitLegacy/mac/ChangeLog (revision 235745) >+++ Source/WebKitLegacy/mac/ChangeLog (working copy) >@@ -1,3 +1,28 @@ >+2018-09-06 Per Arne Vollan <pvollan@apple.com> >+ >+ [macOS] Switching to discrete GPU should be done in the UI process >+ https://bugs.webkit.org/show_bug.cgi?id=189361 >+ <rdar://problem/43949622> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ When WebGL is requesting to use the discrete GPU on a muxable system by setting the powerPreference >+ attribute to "high-performance", a call to CGLChoosePixelFormat is made to perform the switch. This >+ method of switching does not work when there is no WindowServer access in the WebContent process. >+ This call needs to be made in the UI process. This patch adds two new support classes (GPUClient >+ and WebGPUClient) to broker these calls to the UI process. WebKit legacy support is maintained by >+ implementing the WebGPUClient class on the legacy side. The new code is protected by using the >+ ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) define. >+ >+ * WebCoreSupport/WebGPUClient.cpp: Added. >+ (WebGPUClient::singleton): >+ (WebGPUClient::enableHighPerformanceGPU): >+ (WebGPUClient::disableHighPerformanceGPU): >+ * WebCoreSupport/WebGPUClient.h: Added. >+ (WebGPUClient::~WebGPUClient): >+ * WebView/WebView.mm: >+ (-[WebView _commonInitializationWithFrameName:groupName:]): >+ > 2018-09-05 Jer Noble <jer.noble@apple.com> > > Add MediaCapabilities as an Experimental Feature >Index: Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.cpp >=================================================================== >--- Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.cpp (nonexistent) >+++ Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.cpp (working copy) >@@ -0,0 +1,47 @@ >+ >+/* >+ * Copyright (C) 2018 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. ``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 >+ * 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 "WebGPUClient.h" >+ >+#include <wtf/NeverDestroyed.h> >+ >+using namespace WebCore; >+ >+WebGPUClient& WebGPUClient::singleton() >+{ >+ static NeverDestroyed<WebGPUClient> client; >+ return client; >+} >+ >+void WebGPUClient::enableHighPerformanceGPU() >+{ >+ m_pixelFormatObj = GraphicsContext3DManager::enableHighPerformanceGPU(); >+} >+ >+void WebGPUClient::disableHighPerformanceGPU() >+{ >+ GraphicsContext3DManager::disableHighPerformanceGPU(m_pixelFormatObj); >+} >Index: Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.h >=================================================================== >--- Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.h (nonexistent) >+++ Source/WebKitLegacy/mac/WebCoreSupport/WebGPUClient.h (working copy) >@@ -0,0 +1,41 @@ >+/* >+ * Copyright (C) 2018 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/GPUClient.h> >+#include <WebCore/GraphicsContext3DManager.h> >+ >+class WebGPUClient : public WebCore::GPUClient { >+public: >+ static WebGPUClient& singleton(); >+ virtual ~WebGPUClient() { } >+ >+ void enableHighPerformanceGPU() override; >+ void disableHighPerformanceGPU() override; >+ >+private: >+ CGLPixelFormatObj m_pixelFormatObj { nullptr }; >+}; >Index: Source/WebKitLegacy/mac/WebView/WebView.mm >=================================================================== >--- Source/WebKitLegacy/mac/WebView/WebView.mm (revision 235745) >+++ Source/WebKitLegacy/mac/WebView/WebView.mm (working copy) >@@ -67,6 +67,7 @@ > #import "WebFrameLoaderClient.h" > #import "WebFrameNetworkingContext.h" > #import "WebFrameViewInternal.h" >+#import "WebGPUClient.h" > #import "WebGeolocationClient.h" > #import "WebGeolocationPositionInternal.h" > #import "WebHTMLRepresentation.h" >@@ -151,6 +152,7 @@ > #import <WebCore/FrameTree.h> > #import <WebCore/FrameView.h> > #import <WebCore/GCController.h> >+#import <WebCore/GPUClient.h> > #import <WebCore/GameControllerGamepadProvider.h> > #import <WebCore/GeolocationController.h> > #import <WebCore/GeolocationError.h> >@@ -1406,7 +1408,7 @@ - (void)_commonInitializationWithFrameNa > #if ENABLE(GAMEPAD) > WebKitInitializeGamepadProviderIfNecessary(); > #endif >- >+ GPUClient::setSingleton(WebGPUClient::singleton()); > DeprecatedGlobalSettings::setShouldRespectPriorityInCSSAttributeSetters(shouldRespectPriorityInCSSAttributeSetters()); > > #if PLATFORM(IOS) >Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 235763) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,29 @@ >+2018-09-06 Per Arne Vollan <pvollan@apple.com> >+ >+ [macOS] Switching to discrete GPU should be done in the UI process >+ https://bugs.webkit.org/show_bug.cgi?id=189361 >+ <rdar://problem/43949622> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ When WebGL is requesting to use the discrete GPU on a muxable system by setting the powerPreference >+ attribute to "high-performance", a call to CGLChoosePixelFormat is made to perform the switch. This >+ method of switching does not work when there is no WindowServer access in the WebContent process. >+ This call needs to be made in the UI process. This patch adds two new support classes (GPUClient >+ and WebGPUClient) to broker these calls to the UI process. WebKit legacy support is maintained by >+ implementing the WebGPUClient class on the legacy side. The new code is protected by using the >+ ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) define. >+ >+ * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: >+ * WebKitTestRunner/InjectedBundle/TestRunner.cpp: >+ (WTR::TestRunner::isCurrentGPULowPower): >+ * WebKitTestRunner/InjectedBundle/TestRunner.h: >+ * WebKitTestRunner/TestController.h: >+ * WebKitTestRunner/TestInvocation.cpp: >+ (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): >+ * WebKitTestRunner/mac/TestControllerMac.mm: >+ (WTR::TestController::isCurrentGPULowPower): >+ > 2018-09-06 Zalan Bujtas <zalan@apple.com> > > [LFC][BFC] Add support for min(max)-height >Index: Tools/WebKitTestRunner/TestController.h >=================================================================== >--- Tools/WebKitTestRunner/TestController.h (revision 235745) >+++ Tools/WebKitTestRunner/TestController.h (working copy) >@@ -253,6 +253,8 @@ public: > > void sendDisplayConfigurationChangedMessageForTesting(); > >+ bool isCurrentGPULowPower(); >+ > private: > WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef); > WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration() const; >Index: Tools/WebKitTestRunner/TestInvocation.cpp >=================================================================== >--- Tools/WebKitTestRunner/TestInvocation.cpp (revision 235745) >+++ Tools/WebKitTestRunner/TestInvocation.cpp (working copy) >@@ -1427,6 +1427,11 @@ WKRetainPtr<WKTypeRef> TestInvocation::d > return nullptr; > } > >+ if (WKStringIsEqualToUTF8CString(messageName, "IsCurrentGPULowPower")) { >+ WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(TestController::singleton().isCurrentGPULowPower())); >+ return result; >+ } >+ > if (WKStringIsEqualToUTF8CString(messageName, "TerminateStorageProcess")) { > ASSERT(!messageBody); > TestController::singleton().terminateStorageProcess(); >Index: Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp >=================================================================== >--- Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (revision 235745) >+++ Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (working copy) >@@ -2341,4 +2341,12 @@ void TestRunner::sendDisplayConfiguratio > WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); > } > >+bool TestRunner::isCurrentGPULowPower() >+{ >+ WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("IsCurrentGPULowPower")); >+ WKTypeRef returnData = 0; >+ WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); >+ return WKBooleanGetValue(static_cast<WKBooleanRef>(returnData)); >+} >+ > } // namespace WTR >Index: Tools/WebKitTestRunner/InjectedBundle/TestRunner.h >=================================================================== >--- Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (revision 235745) >+++ Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (working copy) >@@ -467,6 +467,8 @@ public: > > void sendDisplayConfigurationChangedMessageForTesting(); > >+ bool isCurrentGPULowPower(); >+ > private: > TestRunner(); > >Index: Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl >=================================================================== >--- Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (revision 235745) >+++ Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (working copy) >@@ -350,4 +350,6 @@ interface TestRunner { > readonly attribute unsigned long userScriptInjectedCount; > > void sendDisplayConfigurationChangedMessageForTesting(); >+ >+ boolean isCurrentGPULowPower(); > }; >Index: Tools/WebKitTestRunner/mac/TestControllerMac.mm >=================================================================== >--- Tools/WebKitTestRunner/mac/TestControllerMac.mm (revision 235745) >+++ Tools/WebKitTestRunner/mac/TestControllerMac.mm (working copy) >@@ -31,6 +31,7 @@ > #import "TestInvocation.h" > #import "TestRunnerWKWebView.h" > #import "WebKitTestRunnerPasteboard.h" >+#import <Metal/MTLDevice.h> > #import <WebKit/WKContextPrivate.h> > #import <WebKit/WKPageGroup.h> > #import <WebKit/WKProcessPoolPrivate.h> >@@ -350,4 +351,11 @@ const char* TestController::platformLibr > return [[@"~/Library/Application Support/DumpRenderTree" stringByExpandingTildeInPath] UTF8String]; > } > >+bool TestController::isCurrentGPULowPower() >+{ >+ auto display = CGMainDisplayID(); >+ auto device = adoptNS(CGDirectDisplayCopyCurrentMetalDevice(display)); >+ return device.get().isLowPower; >+} >+ > } // namespace WTR >Index: LayoutTests/ChangeLog >=================================================================== >--- LayoutTests/ChangeLog (revision 235745) >+++ LayoutTests/ChangeLog (working copy) >@@ -1,3 +1,21 @@ >+2018-09-06 Per Arne Vollan <pvollan@apple.com> >+ >+ [macOS] Switching to discrete GPU should be done in the UI process >+ https://bugs.webkit.org/show_bug.cgi?id=189361 >+ <rdar://problem/43949622> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ When WebGL is requesting to use the discrete GPU on a muxable system by setting the powerPreference >+ attribute to "high-performance", a call to CGLChoosePixelFormat is made to perform the switch. This >+ method of switching does not work when there is no WindowServer access in the WebContent process. >+ This call needs to be made in the UI process. This patch adds two new support classes (GPUClient >+ and WebGPUClient) to broker these calls to the UI process. WebKit legacy support is maintained by >+ implementing the WebGPUClient class on the legacy side. The new code is protected by using the >+ ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) define. >+ >+ * fast/canvas/webgl/switch-to-discrete-gpu.html: Added. >+ > 2018-09-06 Zalan Bujtas <zalan@apple.com> > > [LFC][BFC] Add support for min(max)-width >Index: LayoutTests/fast/canvas/webgl/switch-to-discrete-gpu.html >=================================================================== >--- LayoutTests/fast/canvas/webgl/switch-to-discrete-gpu.html (nonexistent) >+++ LayoutTests/fast/canvas/webgl/switch-to-discrete-gpu.html (working copy) >@@ -0,0 +1,48 @@ >+<html> >+<head> >+<style> >+#example { >+ width: 100%; >+ height: 100%; >+} >+</style> >+<script src="../../../resources/js-test.js"></script> >+<script src="resources/webgl-test-utils.js"> </script> >+<script> >+description('Tests that the discrete GPU is used when the powerPreference attribute is set to "high-performance"'); >+ >+function checkGPU() >+{ >+ if (window.testRunner) { >+ if (!testRunner.isCurrentGPULowPower()) >+ testRunner.notifyDone(); >+ } >+} >+ >+function start() >+{ >+ if (window.testRunner) { >+ testRunner.dumpAsText(); >+ testRunner.waitUntilDone(); >+ >+ } >+ >+ // Finish the test if there is no muxable GPU on the machine, since the test is not relevant then. >+ if (window.internals) >+ if (!window.internals.hasMuxableGPU()) >+ testRunner.notifyDone(); >+ >+ var canvas = document.getElementById('example'); >+ >+ var gl = WebGLTestUtils.create3DContext(canvas, {powerPreference: "high-performance"}); >+ >+ checkGPU(); >+} >+</script> >+</head> >+ >+<body onload="start()"> >+ <canvas id="example"></canvas> >+</body> >+</html> >+
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189361
:
349090
|
349145
|
349147
|
349150
|
349337
|
349344
|
349351
|
349451
|
349459
|
351268
|
351344
|
351348
|
351350
|
351371
|
351407
|
351421
|
351434