[macOS] Switching to discrete GPU should be done in the UI process
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Oct 2018 23:42:38 +0000 (23:42 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Oct 2018 23:42:38 +0000 (23:42 +0000)
commite6272c4937edbb8f2fd55dacbce3e83fc227d3a6
tree42b823da385c729e75fdbcd8f00fae82bd23570a
parentfa52e2745ceae640b8bc7757cdba4220ba539374
[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 Simon Fraser.

Source/WebCore:

Based on an earlier patch by Per Arne Vollan.

Due to the fact we can't talk to the Window Server, the Web Process can
no longer muxing to the discrete GPU directly. Instead we have to get the
UI Process to process the change. Do this by adding a new Chrome client
called GPUClient, that will have implementations provided by both WebKit
and legacy WebKit.

Unfortunately this can't be tested by a regular WKTR since:
- it requires specific hardware
- swapping to/from the discrete GPU takes about 20 seconds
- running concurrent tests could confuse the tests into thinking
  the wrong GPU is active

Instead we'll write a specific test for this functionality and
run it on a separate bot.

* WebCore.xcodeproj/project.pbxproj: Add GPUClient files.

* page/Chrome.cpp: Drive by clean-up.
(WebCore::Chrome::windowScreenDidChange):

* platform/graphics/GraphicsContext3D.h: We need to keep track of
whether we've muxed for this context, in order to not respond to
the screen change notifications (they are misleading in the case
of muxing).

* platform/graphics/GraphicsContext3DManager.cpp: Rather than try
to mux directly, call into GPUClient.
(WebCore::GraphicsContext3DManager::displayWasReconfigured):
(WebCore::GraphicsContext3DManager::updateHighPerformanceState):
(WebCore::GraphicsContext3DManager::disableHighPerformanceGPUTimerFired):
(WebCore::GraphicsContext3DManager::recycleContextIfNecessary):
* platform/graphics/GraphicsContext3DManager.h:

* platform/graphics/cocoa/GraphicsContext3DCocoa.mm: Only reconfigure
the virtual display if it didn't happen from muxing.
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::updateCGLContext):
(WebCore::GraphicsContext3D::screenDidChange):

* platform/graphics/mac/GPUClient.cpp: Added.
(WebCore::GPUClient::singleton):
(WebCore::GPUClient::setSingleton):
* platform/graphics/mac/GPUClient.h: Added.

* testing/Internals.cpp: Testing helper.
(WebCore::Internals::hasMuxableGPU):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Implement the UI-side process for triggering a GPU mux.

* Platform/Logging.h: Add a WebGL logging channel.

* SourcesCocoa.txt: Add the new files: WebGPUClient and HighPerformanceGPUManager.

* UIProcess/Cocoa/WebProcessProxyCocoa.mm: UI process calls that use HighPerformanceGPUManager
to keep track of whether or not this process needs the high-performance GPU.
(WebKit::WebProcessProxy::requestHighPerformanceGPU):
(WebKit::WebProcessProxy::releaseHighPerformanceGPU):

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::~WebProcessProxy): Make sure to unregister with the HighPerformanceGPUManager
as the process disappears without manually removing itself (e.g. crashes).
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in: New messages.

* UIProcess/mac/HighPerformanceGPUManager.cpp: New class that copies most of what used
to live in GraphicsContext3DManager. It creates a CGLPixelFormat object when it sees
that at least one process needs the high-performance GPU.
(WebKit::HighPerformanceGPUManager::singleton):
(WebKit::HighPerformanceGPUManager::addProcessRequiringHighPerformance):
(WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance):
(WebKit::HighPerformanceGPUManager::updateState):
* UIProcess/mac/HighPerformanceGPUManager.h: Added.

* WebKit.xcodeproj/project.pbxproj: Add new files.

* WebProcess/WebCoreSupport/mac/WebGPUClient.cpp: Implementation of the GPUClient for
WebCore, which sends messages to the UI process.
(WebKit::WebGPUClient::singleton):
(WebKit::WebGPUClient::requestHighPerformanceGPU):
(WebKit::WebGPUClient::releaseHighPerformanceGPU):
* WebProcess/WebCoreSupport/mac/WebGPUClient.h: Added.

* WebProcess/cocoa/WebProcessCocoa.mm: Register the GPUClient.
(WebKit::WebProcess::platformInitializeProcess):

Source/WebKitLegacy:

* WebKitLegacy.xcodeproj/project.pbxproj: Add new files.

Source/WebKitLegacy/mac:

Implement a no-op GPUClient instance in legacy WebKit. We will
not support swapping to the discrete GPU in this configuration.

* WebCoreSupport/WebGPUClient.cpp: Added.
(WebKit::WebGPUClient::singleton):
* WebCoreSupport/WebGPUClient.h: Added.
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):

Source/WTF:

Define GL_SILENCE_DEPRECATION to avoid deprecation warnings for OpenGL.

* wtf/Platform.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236773 268f45cc-cd09-0410-ab3c-d52691b4dbfc
33 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/Chrome.cpp
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp
Source/WebCore/platform/graphics/GraphicsContext3DManager.h
Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm
Source/WebCore/platform/graphics/mac/SwitchingGPUClient.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h [new file with mode: 0644]
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Platform/Logging.h
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h [new file with mode: 0644]
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h [new file with mode: 0644]
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebSwitchingGPUClient.cpp [new file with mode: 0644]
Source/WebKitLegacy/mac/WebCoreSupport/WebSwitchingGPUClient.h [new file with mode: 0644]
Source/WebKitLegacy/mac/WebView/WebView.mm