Changeset 271880 in webkit
- Timestamp:
- Jan 26, 2021 5:43:59 AM (18 months ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 20 edited
- 2 copied
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/PlatformMac.cmake (modified) (1 diff)
-
WebCore/SourcesCocoa.txt (modified) (1 diff)
-
WebCore/WebCore.xcodeproj/project.pbxproj (modified) (6 diffs)
-
WebCore/html/canvas/WebGLRenderingContextBase.cpp (modified) (1 diff)
-
WebCore/page/Chrome.cpp (modified) (2 diffs)
-
WebCore/platform/graphics/GraphicsContextGL.h (modified) (1 diff)
-
WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp (modified) (1 diff)
-
WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h (modified) (1 diff)
-
WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (modified) (10 diffs)
-
WebCore/platform/graphics/mac/GraphicsChecksMac.cpp (added)
-
WebCore/platform/graphics/mac/GraphicsChecksMac.h (copied) (copied from trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h) (2 diffs)
-
WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h (copied) (copied from trunk/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h) (2 diffs)
-
WebCore/platform/graphics/mac/SwitchingGPUClient.h (modified) (1 diff)
-
WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (modified) (10 diffs)
-
WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp (modified) (4 diffs)
-
WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.h (modified) (3 diffs)
-
WebCore/testing/Internals.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/mac/HighPerformanceGPUManager.h (modified) (2 diffs)
-
WebKit/UIProcess/mac/HighPerformanceGPUManager.mm (modified) (4 diffs)
-
WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp (modified) (2 diffs)
-
WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r271878 r271880 1 2021-01-26 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE 4 https://bugs.webkit.org/show_bug.cgi?id=220843 5 6 Reviewed by Dean Jackson. 7 8 Use ANGLE extension EGL_ANGLE_power_preference to signal to ANGLE that the underlying 9 CGL context should be updated as a response to display reconfiguration signal. 10 This ensures that ANGLE state stays consistent with the actual CGL context behavior, as 11 we don't change the context behind ANGLE's back. 12 13 Remove the feature where the context GPU is selected based on the display the window is 14 on. This cannot work with the logic of "powerPreference = "high-performance" goes to 15 discrete GPU". Also, this cannot work with ANGLE at all, since all contexts are backed 16 by a single platform context. Thus all contexts will use the same underlying GPU. 17 18 No new tests due to the test runner missing features. The bug blockers track the testing. 19 20 * PlatformMac.cmake: 21 * SourcesCocoa.txt: 22 * WebCore.xcodeproj/project.pbxproj: 23 * html/canvas/WebGLRenderingContextBase.cpp: 24 (WebCore::isHighPerformanceContext): 25 * page/Chrome.cpp: 26 (WebCore::Chrome::windowScreenDidChange): 27 * platform/graphics/GraphicsContextGL.h: 28 * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp: 29 * platform/graphics/RemoteGraphicsContextGLProxyBase.h: 30 * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm: 31 (WebCore::GraphicsContextGLOpenGL::create): 32 (WebCore::GraphicsContextGLOpenGL::createShared): 33 (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL): 34 (WebCore::GraphicsContextGLOpenGL::setContextVisibility): 35 (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured): 36 (WebCore::GraphicsContextGLOpenGL::simulateContextChanged): 37 * platform/graphics/mac/GraphicsChecksMac.cpp: Added. 38 (WebCore::attachToAppleGraphicsControl): 39 (WebCore::hasMuxCapability): 40 (WebCore::hasLowAndHighPowerGPUs): 41 * platform/graphics/mac/GraphicsChecksMac.h: Copied from Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h. 42 * platform/graphics/mac/ScopedHighPerformanceGPURequest.h: Copied from Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h. 43 (WebCore::ScopedHighPerformanceGPURequest::ScopedHighPerformanceGPURequest): 44 (WebCore::ScopedHighPerformanceGPURequest::~ScopedHighPerformanceGPURequest): 45 (WebCore::ScopedHighPerformanceGPURequest::operator=): 46 (WebCore::ScopedHighPerformanceGPURequest::acquire): 47 * platform/graphics/mac/SwitchingGPUClient.h: 48 * platform/graphics/opengl/GraphicsContextGLOpenGL.h: 49 * platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp: 50 (WebCore::GraphicsContextGLOpenGLManager::displayWasReconfigured): 51 (WebCore::GraphicsContextGLOpenGLManager::addContext): 52 (WebCore::GraphicsContextGLOpenGLManager::removeContext): 53 * platform/graphics/opengl/GraphicsContextGLOpenGLManager.h: 54 * testing/Internals.cpp: 55 1 56 2021-01-25 Ryosuke Niwa <rniwa@webkit.org> 2 57 -
trunk/Source/WebCore/PlatformMac.cmake
r271089 r271880 341 341 platform/graphics/mac/FloatSizeMac.mm 342 342 platform/graphics/mac/FontCustomPlatformData.cpp 343 platform/graphics/mac/GraphicsChecksMac.cpp 343 344 platform/graphics/mac/IconMac.mm 344 345 platform/graphics/mac/ImageMac.mm -
trunk/Source/WebCore/SourcesCocoa.txt
r271089 r271880 419 419 platform/graphics/mac/FloatSizeMac.mm 420 420 platform/graphics/mac/FontCustomPlatformData.cpp 421 platform/graphics/mac/GraphicsChecksMac.cpp 421 422 platform/graphics/mac/IconMac.mm 422 423 platform/graphics/mac/ImageMac.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r271806 r271880 2263 2263 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; }; 2264 2264 7BB34A48253776CA00029D08 /* GraphicsContextGLImageExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2265 7BB680B225BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2266 7BB680B625BA1AE2002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */; }; 2267 7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2265 2268 7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; }; 2266 2269 7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 10302 10305 7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; }; 10303 10306 7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; }; 10307 7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedHighPerformanceGPURequest.h; sourceTree = "<group>"; }; 10308 7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedHighPerformanceGPURequest.h; sourceTree = "<group>"; }; 10309 7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsChecksMac.cpp; sourceTree = "<group>"; }; 10310 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsChecksMac.h; sourceTree = "<group>"; }; 10304 10311 7BE7265B25763B8D00E85D98 /* RemoteGraphicsContextGLProxyBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyBase.cpp; sourceTree = "<group>"; }; 10305 10312 7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; }; … … 26504 26511 B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */, 26505 26512 B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */, 26513 7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */, 26514 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */, 26506 26515 B275358D0B053A66002CE64F /* IconMac.mm */, 26507 26516 B275354E0B053814002CE64F /* ImageMac.mm */, … … 26509 26518 B27535510B053814002CE64F /* IntSizeMac.mm */, 26510 26519 2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */, 26520 7BB680B425BA1AE1002B8738 /* ScopedHighPerformanceGPURequest.h */, 26521 7BB680B025BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h */, 26511 26522 163E88F5118A39D200ED9231 /* SimpleFontDataCoreText.cpp */, 26512 26523 C11A9ED22140578B00CFB20A /* SwitchingGPUClient.cpp */, … … 32248 32259 B22279640D00BF220071B782 /* GradientAttributes.h in Headers */, 32249 32260 2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */, 32261 7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */, 32250 32262 B2A015A90AF6CD53006BCE0E /* GraphicsContext.h in Headers */, 32251 32263 934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */, … … 34470 34482 5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */, 34471 34483 9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */, 34484 7BB680B625BA1AE2002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */, 34485 7BB680B225BA0D4A002B8738 /* ScopedHighPerformanceGPURequest.h in Headers */, 34472 34486 BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */, 34473 34487 C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */, -
trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
r271679 r271880 643 643 static bool isHighPerformanceContext(const RefPtr<GraphicsContextGL>& context) 644 644 { 645 return context-> powerPreferenceUsedForCreation()== WebGLPowerPreference::HighPerformance;645 return context->contextAttributes().powerPreference == WebGLPowerPreference::HighPerformance; 646 646 } 647 647 -
trunk/Source/WebCore/page/Chrome.cpp
r270587 r271880 68 68 #endif 69 69 70 #if PLATFORM(MAC) && ENABLE(WEBGL)71 #include "GraphicsContextGLOpenGLManager.h"72 #endif73 74 70 namespace WebCore { 75 71 … … 549 545 550 546 m_page.windowScreenDidChange(displayID, nominalFrameInterval); 551 552 #if PLATFORM(MAC) && ENABLE(WEBGL)553 GraphicsContextGLOpenGLManager::sharedManager().screenDidChange(displayID, this);554 #endif555 547 } 556 548 -
trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h
r271679 r271880 1264 1264 virtual void setContextVisibility(bool) = 0; 1265 1265 1266 virtual GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const = 0;1267 1268 1266 virtual bool isGLES2Compliant() const = 0; 1269 1267 -
trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp
r271065 r271880 48 48 { 49 49 notImplemented(); 50 }51 52 GraphicsContextGLPowerPreference RemoteGraphicsContextGLProxyBase::powerPreferenceUsedForCreation() const53 {54 notImplemented();55 return { };56 50 } 57 51 -
trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h
r270964 r271880 62 62 ExtensionsGL& getExtensions() final; 63 63 void setContextVisibility(bool) final; 64 GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final;65 64 bool isGLES2Compliant() const final; 66 65 void markContextChanged() final; -
trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm
r271609 r271880 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 33 33 #import "GraphicsContextGLIOSurfaceSwapChain.h" 34 34 #import "GraphicsContextGLOpenGLManager.h" 35 #import "HostWindow.h"36 35 #import "Logging.h" 37 #import "OpenGLSoftLinkCocoa.h"38 36 #import "RuntimeApplicationChecks.h" 39 37 #import "WebCoreThread.h" … … 42 40 #import <wtf/BlockObjCExceptions.h> 43 41 #import <wtf/text/CString.h> 44 45 #if PLATFORM(MAC)46 #import "ScreenProperties.h"47 #import <OpenGL/CGLRenderers.h>48 #endif49 42 50 43 #if ENABLE(VIDEO) && USE(AVFOUNDATION) … … 152 145 return nullptr; 153 146 154 GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get() , hostWindow);147 GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get()); 155 148 156 149 return context; … … 159 152 Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createShared(GraphicsContextGLOpenGL& sharedContext) 160 153 { 161 auto hostWindow = GraphicsContextGLOpenGLManager::sharedManager().hostWindowForContext(&sharedContext); 162 auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), hostWindow, &sharedContext, nullptr));163 164 GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr() , hostWindow);154 155 auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), nullptr, &sharedContext, nullptr)); 156 157 GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr()); 165 158 166 159 return context; … … 172 165 } 173 166 174 #if PLATFORM(MAC) // FIXME: This probably should be just enabled - see <rdar://53062794>. 175 176 static void setGPUByRegistryID(CGLContextObj contextObj, CGLPixelFormatObj pixelFormatObj, IORegistryGPUID preferredGPUID) 177 { 178 // 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. 179 // On 10.13+, find the virtual screen that corresponds to the preferred GPU by its registryID. 180 // CGLSetVirtualScreen can then be used to tell OpenGL which GPU it should be using. 181 182 if (!contextObj || !preferredGPUID) 183 return; 184 185 GLint virtualScreenCount = 0; 186 CGLError error = CGLDescribePixelFormat(pixelFormatObj, 0, kCGLPFAVirtualScreenCount, &virtualScreenCount); 187 ASSERT(error == kCGLNoError); 188 189 GLint firstAcceleratedScreen = -1; 190 191 for (GLint virtualScreen = 0; virtualScreen < virtualScreenCount; ++virtualScreen) { 192 GLint displayMask = 0; 193 error = CGLDescribePixelFormat(pixelFormatObj, virtualScreen, kCGLPFADisplayMask, &displayMask); 194 ASSERT(error == kCGLNoError); 195 196 auto gpuID = gpuIDForDisplayMask(displayMask); 197 198 if (gpuID == preferredGPUID) { 199 error = CGLSetVirtualScreen(contextObj, virtualScreen); 200 ASSERT(error == kCGLNoError); 201 LOG(WebGL, "Context (%p) set to GPU with ID: (%lld).", contextObj, gpuID); 202 return; 203 } 204 205 if (firstAcceleratedScreen < 0) { 206 GLint isAccelerated = 0; 207 error = CGLDescribePixelFormat(pixelFormatObj, virtualScreen, kCGLPFAAccelerated, &isAccelerated); 208 ASSERT(error == kCGLNoError); 209 if (isAccelerated) 210 firstAcceleratedScreen = virtualScreen; 211 } 212 } 213 214 // No registryID match found; set to first hardware-accelerated virtual screen. 215 if (firstAcceleratedScreen >= 0) { 216 error = CGLSetVirtualScreen(contextObj, firstAcceleratedScreen); 217 ASSERT(error == kCGLNoError); 218 LOG(WebGL, "RegistryID (%lld) not matched; Context (%p) set to virtual screen (%d).", preferredGPUID, contextObj, firstAcceleratedScreen); 219 } 220 } 221 222 #endif // PLATFORM(MAC) 223 224 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow* hostWindow, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain) 167 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain) 225 168 : GraphicsContextGL(attrs, Destination::Offscreen, sharedContext) 226 169 { 227 170 m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2; 228 229 #if HAVE(APPLE_GRAPHICS_CONTROL)230 m_powerPreferenceUsedForCreation = (hasLowAndHighPowerGPUs() && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) ? GraphicsContextGLPowerPreference::HighPerformance : GraphicsContextGLPowerPreference::Default;231 #else232 m_powerPreferenceUsedForCreation = GraphicsContextGLPowerPreference::Default;233 #endif234 171 235 172 m_displayObj = InitializeEGLDisplay(attrs); 236 173 if (m_displayObj == EGL_NO_DISPLAY) 237 174 return; 175 176 bool supportsPowerPreference = false; 177 #if PLATFORM(MAC) 238 178 const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS); 239 LOG(WebGL, "Extensions: %s", displayExtensions); 179 m_supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference"); 180 supportsPowerPreference = m_supportsPowerPreference; 181 #endif 182 if (!supportsPowerPreference && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) { 183 attrs.powerPreference = GraphicsContextGLPowerPreference::Default; 184 setContextAttributes(attrs); 185 } 240 186 241 187 EGLint configAttributes[] = { … … 291 237 eglContextAttributes.append(EGL_FALSE); 292 238 293 if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {294 eglContextAttributes.append(EGL_POWER_PREFERENCE_ANGLE);295 // EGL_LOW_POWER_ANGLE is the default. Change to296 // EGL_HIGH_POWER_ANGLE if desired.297 eglContextAttributes.append(EGL_LOW_POWER_ANGLE);298 }299 239 eglContextAttributes.append(EGL_NONE); 300 240 … … 333 273 extensions.ensureEnabled(extension); 334 274 } 335 #if PLATFORM(MAC)336 // FIXME: It's unclear if MACCATALYST should take these steps as well, but that337 // would require the PlatformScreenMac code to be exposed to Catalyst too.338 EGLDeviceEXT device = nullptr;339 EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));340 CGLContextObj cglContext = nullptr;341 CGLPixelFormatObj pixelFormat = nullptr;342 EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));343 EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat));344 auto gpuID = (hostWindow && hostWindow->displayID()) ? gpuIDForDisplay(hostWindow->displayID()) : primaryGPUID();345 setGPUByRegistryID(cglContext, pixelFormat, gpuID);346 #else347 UNUSED_PARAM(hostWindow);348 #endif349 350 275 validateAttributes(); 351 276 attrs = contextAttributes(); // They may have changed during validation. … … 562 487 void GraphicsContextGLOpenGL::setContextVisibility(bool isVisible) 563 488 { 564 if (m_powerPreferenceUsedForCreation == GraphicsContextGLPowerPreference::HighPerformance) {565 if (isVisible)566 GraphicsContextGLOpenGLManager::sharedManager().addContextRequiringHighPerformance(this);567 else568 GraphicsContextGLOpenGLManager::sharedManager().removeContextRequiringHighPerformance(this);569 }570 }571 572 489 #if PLATFORM(MAC) 573 void GraphicsContextGLOpenGL::updateCGLContext() 574 { 575 if (!makeContextCurrent()) 576 return; 577 LOG(WebGL, "Detected a mux switch or display reconfiguration. Call CGLUpdateContext. (%p)", this); 578 579 EGLDeviceEXT device = nullptr; 580 EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device)); 581 CGLContextObj cglContext = nullptr; 582 EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext)); 583 584 CGLUpdateContext(cglContext); 585 m_hasSwitchedToHighPerformanceGPU = true; 586 } 587 #endif 490 if (contextAttributes().powerPreference != GraphicsContextGLPowerPreference::HighPerformance) 491 return; 492 if (isVisible) 493 m_highPerformanceGPURequest = ScopedHighPerformanceGPURequest::acquire(); 494 else 495 m_highPerformanceGPURequest = { }; 496 #else 497 UNUSED_PARAM(isVisible); 498 #endif 499 } 500 501 void GraphicsContextGLOpenGL::displayWasReconfigured() 502 { 503 #if PLATFORM(MAC) 504 if (m_supportsPowerPreference) 505 EGL_HandleGPUSwitchANGLE(m_displayObj); 506 #endif 507 dispatchContextChangedNotification(); 508 } 588 509 589 510 bool GraphicsContextGLOpenGL::reshapeDisplayBufferBacking() … … 655 576 void GraphicsContextGLOpenGL::simulateContextChanged() 656 577 { 657 GraphicsContextGLOpenGLManager::sharedManager().updateAllContexts(); 658 } 659 660 bool GraphicsContextGLOpenGL::allowOfflineRenderers() const 661 { 662 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 663 // When WindowServer access is blocked in the WebProcess, there is no way 664 // for OpenGL to decide which GPU is connected to a display (online/offline). 665 // OpenGL will then consider all GPUs, or renderers, as offline, which means 666 // all offline renderers need to be considered when finding a pixel format. 667 // In WebKit legacy, there will still be a WindwServer connection, and 668 // m_displayMask will not be set in this case. 669 if (primaryOpenGLDisplayMask()) 670 return true; 671 #elif PLATFORM(MACCATALYST) 672 // FIXME: <rdar://53062794> We're very inconsistent about WEBPROCESS_WINDOWSERVER_BLOCKING 673 // and MAC/MACCATALYST and OPENGL/OPENGLES. 674 return true; 675 #endif 676 677 #if HAVE(APPLE_GRAPHICS_CONTROL) 678 if (hasLowAndHighPowerGPUs()) 679 return true; 680 #endif 681 682 return false; 683 } 684 685 #if PLATFORM(MAC) 686 void GraphicsContextGLOpenGL::screenDidChange(PlatformDisplayID displayID) 687 { 688 if (!m_contextObj) 689 return; 690 if (!m_hasSwitchedToHighPerformanceGPU) { 691 EGLDeviceEXT device = nullptr; 692 EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device)); 693 CGLContextObj cglContext = nullptr; 694 CGLPixelFormatObj pixelFormat = nullptr; 695 EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext)); 696 EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat)); 697 setGPUByRegistryID(cglContext, pixelFormat, gpuIDForDisplay(displayID)); 698 } 699 } 700 #endif // !PLATFORM(MAC) 578 GraphicsContextGLOpenGLManager::sharedManager().displayWasReconfigured(); 579 } 701 580 702 581 void GraphicsContextGLOpenGL::prepareForDisplay() -
trunk/Source/WebCore/platform/graphics/mac/GraphicsChecksMac.h
r271879 r271880 1 1 /* 2 * Copyright (C) 20 18Apple Inc. All rights reserved.2 * Copyright (C) 2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include <WebCore/SwitchingGPUClient.h> 28 namespace WebCore { 29 29 30 namespace WebKit { 31 32 class WebSwitchingGPUClient : public WebCore::SwitchingGPUClient { 33 public: 34 static WebSwitchingGPUClient& singleton(); 35 36 void requestHighPerformanceGPU() override; 37 void releaseHighPerformanceGPU() override; 38 }; 30 WEBCORE_EXPORT bool hasLowAndHighPowerGPUs(); 39 31 40 32 } -
trunk/Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h
r271879 r271880 1 1 /* 2 * Copyright (C) 20 18Apple Inc. All rights reserved.2 * Copyright (C) 2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include "GraphicsChecksMac.h" 29 #include "SwitchingGPUClient.h" 30 28 31 namespace WebCore { 29 32 30 class S witchingGPUClient {33 class ScopedHighPerformanceGPURequest { 31 34 public: 32 WEBCORE_EXPORT static SwitchingGPUClient* singletonIfExists(); 33 WEBCORE_EXPORT static void setSingleton(SwitchingGPUClient&); 34 35 virtual ~SwitchingGPUClient() = default; 36 37 virtual void requestHighPerformanceGPU() = 0; 38 virtual void releaseHighPerformanceGPU() = 0; 39 35 ScopedHighPerformanceGPURequest() = default; 36 ScopedHighPerformanceGPURequest(ScopedHighPerformanceGPURequest&& other) 37 : m_requested(std::exchange(other.m_requested, false)) 38 { 39 } 40 ~ScopedHighPerformanceGPURequest() 41 { 42 if (!m_requested) 43 return; 44 SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU(); 45 } 46 ScopedHighPerformanceGPURequest& operator=(ScopedHighPerformanceGPURequest&& other) 47 { 48 if (m_requested) 49 SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU(); 50 m_requested = std::exchange(other.m_requested, false); 51 return *this; 52 } 53 static ScopedHighPerformanceGPURequest acquire() 54 { 55 if (!hasLowAndHighPowerGPUs()) 56 return { }; 57 auto client = SwitchingGPUClient::singletonIfExists(); 58 if (!client) 59 return { }; 60 client->requestHighPerformanceGPU(); 61 return { DidRequest }; 62 } 40 63 private: 41 static SwitchingGPUClient* m_singleton; 64 enum RequestState { DidRequest }; 65 ScopedHighPerformanceGPURequest(RequestState) 66 : m_requested(true) 67 { 68 } 69 bool m_requested { false }; 42 70 }; 43 71 -
trunk/Source/WebCore/platform/graphics/mac/SwitchingGPUClient.h
r262811 r271880 30 30 class SwitchingGPUClient { 31 31 public: 32 WEBCORE_EXPORT static SwitchingGPUClient* singletonIfExists();33 32 WEBCORE_EXPORT static void setSingleton(SwitchingGPUClient&); 34 33 35 34 virtual ~SwitchingGPUClient() = default; 36 35 private: 36 WEBCORE_EXPORT static SwitchingGPUClient* singletonIfExists(); 37 37 virtual void requestHighPerformanceGPU() = 0; 38 38 virtual void releaseHighPerformanceGPU() = 0; 39 40 private: 39 41 40 static SwitchingGPUClient* m_singleton; 41 friend class ScopedHighPerformanceGPURequest; 42 42 }; 43 43 -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r271679 r271880 68 68 class GCGLLayer; 69 69 } 70 #endif 71 72 #if PLATFORM(MAC) 73 #include "ScopedHighPerformanceGPURequest.h" 70 74 #endif 71 75 … … 257 261 void texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLintptr offset) final; 258 262 void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data) final; 259 void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLintptr offset) final; 263 void compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLintptr offset) final; 260 264 void compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data) final; 261 265 void compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLintptr offset) final; … … 462 466 #endif 463 467 464 #if PLATFORM(COCOA) && PLATFORM(MAC)465 void updateCGLContext();468 #if PLATFORM(COCOA) 469 void displayWasReconfigured(); 466 470 #endif 467 471 468 472 void setContextVisibility(bool) final; 469 470 GraphicsContextGLPowerPreference powerPreferenceUsedForCreation() const final { return m_powerPreferenceUsedForCreation; }471 473 472 474 // Support for buffer creation and deletion … … 498 500 unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); } 499 501 500 #if PLATFORM(MAC)501 using PlatformDisplayID = uint32_t;502 void screenDidChange(PlatformDisplayID);503 #endif504 505 502 void prepareForDisplay() final; 506 503 … … 530 527 void validateDepthStencil(const char* packedDepthStencilExtension); 531 528 void validateAttributes(); 532 529 533 530 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); 534 531 … … 548 545 549 546 #if PLATFORM(COCOA) 550 bool allowOfflineRenderers() const;551 547 bool reshapeDisplayBufferBacking(); 552 548 bool allocateAndBindDisplayBufferBacking(); … … 584 580 { 585 581 } 586 582 587 583 ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType) 588 584 { … … 649 645 #endif 650 646 651 GraphicsContextGLPowerPreference m_powerPreferenceUsedForCreation { GraphicsContextGLPowerPreference::Default };652 647 Vector<Vector<float>> m_vertexArray; 653 648 … … 681 676 using BoundTextureMap = HashMap<GCGLenum, 682 677 std::pair<GCGLuint, GCGLenum>, 683 WTF::IntHash<GCGLenum>, 678 WTF::IntHash<GCGLenum>, 684 679 WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>, 685 680 WTF::PairHashTraits<WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>, WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>> … … 762 757 std::unique_ptr<IOSurface> m_displayBufferBacking; 763 758 void* m_displayBufferPbuffer { nullptr }; 764 765 bool m_hasSwitchedToHighPerformanceGPU { false }; 759 #endif 760 #if PLATFORM(MAC) 761 bool m_supportsPowerPreference { false }; 762 ScopedHighPerformanceGPURequest m_highPerformanceGPURequest; 766 763 #endif 767 764 #if ENABLE(VIDEO) && USE(AVFOUNDATION) -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.cpp
r270477 r271880 32 32 #include "Logging.h" 33 33 34 #if HAVE(APPLE_GRAPHICS_CONTROL)35 #include <sys/sysctl.h>36 #endif37 38 #if PLATFORM(MAC)39 #include "SwitchingGPUClient.h"40 #endif41 42 34 namespace WebCore { 43 44 #if HAVE(APPLE_GRAPHICS_CONTROL)45 46 enum {47 kAGCOpen,48 kAGCClose49 };50 51 static io_connect_t attachToAppleGraphicsControl()52 {53 mach_port_t masterPort = MACH_PORT_NULL;54 55 if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)56 return MACH_PORT_NULL;57 58 CFDictionaryRef classToMatch = IOServiceMatching("AppleGraphicsControl");59 if (!classToMatch)60 return MACH_PORT_NULL;61 62 kern_return_t kernResult;63 io_iterator_t iterator;64 if ((kernResult = IOServiceGetMatchingServices(masterPort, classToMatch, &iterator)) != KERN_SUCCESS)65 return MACH_PORT_NULL;66 67 io_service_t serviceObject = IOIteratorNext(iterator);68 IOObjectRelease(iterator);69 if (!serviceObject)70 return MACH_PORT_NULL;71 72 io_connect_t dataPort;73 IOObjectRetain(serviceObject);74 kernResult = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);75 IOObjectRelease(serviceObject);76 77 return (kernResult == KERN_SUCCESS) ? dataPort : MACH_PORT_NULL;78 }79 80 static bool hasMuxCapability()81 {82 io_connect_t dataPort = attachToAppleGraphicsControl();83 84 if (dataPort == MACH_PORT_NULL)85 return false;86 87 bool result;88 if (IOConnectCallScalarMethod(dataPort, kAGCOpen, nullptr, 0, nullptr, nullptr) == KERN_SUCCESS) {89 IOConnectCallScalarMethod(dataPort, kAGCClose, nullptr, 0, nullptr, nullptr);90 result = true;91 } else92 result = false;93 94 IOServiceClose(dataPort);95 96 if (result) {97 // This is detecting Mac hardware with an Intel g575 GPU, which98 // we don't want to make available to muxing.99 // Based on information from Apple's OpenGL team, such devices100 // have four or fewer processors.101 // <rdar://problem/30060378>102 int names[2] = { CTL_HW, HW_NCPU };103 int cpuCount;104 size_t cpuCountLength = sizeof(cpuCount);105 sysctl(names, 2, &cpuCount, &cpuCountLength, nullptr, 0);106 result = cpuCount > 4;107 }108 109 return result;110 }111 112 bool hasLowAndHighPowerGPUs()113 {114 static bool canMux = hasMuxCapability();115 return canMux;116 }117 #endif // HAVE(APPLE_GRAPHICS_CONTROL)118 35 119 36 GraphicsContextGLOpenGLManager& GraphicsContextGLOpenGLManager::sharedManager() … … 128 45 LOG(WebGL, "GraphicsContextGLOpenGLManager::displayWasReconfigured"); 129 46 if (flags & kCGDisplaySetModeFlag) 130 GraphicsContextGLOpenGLManager::sharedManager(). updateAllContexts();47 GraphicsContextGLOpenGLManager::sharedManager().displayWasReconfigured(); 131 48 } 132 49 #endif 133 50 134 void GraphicsContextGLOpenGLManager::updateAllContexts() 51 #if PLATFORM(COCOA) 52 void GraphicsContextGLOpenGLManager::displayWasReconfigured() 135 53 { 136 #if PLATFORM(MAC) 137 for (const auto& context : m_contexts) { 138 context->updateCGLContext(); 139 context->dispatchContextChangedNotification(); 140 } 141 #endif 142 } 143 144 #if PLATFORM(MAC) 145 void GraphicsContextGLOpenGLManager::screenDidChange(PlatformDisplayID displayID, const HostWindow* window) 146 { 147 for (const auto& contextAndWindow : m_contextWindowMap) { 148 if (contextAndWindow.value == window) { 149 contextAndWindow.key->screenDidChange(displayID); 150 LOG(WebGL, "Changing context (%p) to display (%d).", contextAndWindow.key, displayID); 151 } 152 } 54 for (const auto& context : m_contexts) 55 context->displayWasReconfigured(); 153 56 } 154 57 #endif 155 58 156 void GraphicsContextGLOpenGLManager::addContext(GraphicsContextGLOpenGL* context , HostWindow* window)59 void GraphicsContextGLOpenGLManager::addContext(GraphicsContextGLOpenGL* context) 157 60 { 158 61 ASSERT(context); … … 167 70 ASSERT(!m_contexts.contains(context)); 168 71 m_contexts.append(context); 169 m_contextWindowMap.set(context, window);170 72 } 171 73 … … 175 77 return; 176 78 m_contexts.removeFirst(context); 177 m_contextWindowMap.remove(context);178 removeContextRequiringHighPerformance(context);179 180 79 #if PLATFORM(MAC) && !ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 181 80 if (!m_contexts.size()) 182 81 CGDisplayRemoveReconfigurationCallback(displayWasReconfigured, nullptr); 183 #endif184 }185 186 HostWindow* GraphicsContextGLOpenGLManager::hostWindowForContext(GraphicsContextGLOpenGL* context) const187 {188 ASSERT(m_contextWindowMap.contains(context));189 return m_contextWindowMap.get(context);190 }191 192 void GraphicsContextGLOpenGLManager::addContextRequiringHighPerformance(GraphicsContextGLOpenGL* context)193 {194 ASSERT(context);195 if (!context)196 return;197 198 ASSERT(m_contexts.contains(context));199 ASSERT(!m_contextsRequiringHighPerformance.contains(context));200 201 LOG(WebGL, "This context (%p) requires the high-performance GPU.", context);202 m_contextsRequiringHighPerformance.add(context);203 204 updateHighPerformanceState();205 }206 207 void GraphicsContextGLOpenGLManager::removeContextRequiringHighPerformance(GraphicsContextGLOpenGL* context)208 {209 if (!context)210 return;211 212 if (!m_contextsRequiringHighPerformance.contains(context))213 return;214 215 LOG(WebGL, "This context (%p) no longer requires the high-performance GPU.", context);216 m_contextsRequiringHighPerformance.remove(context);217 218 updateHighPerformanceState();219 }220 221 void GraphicsContextGLOpenGLManager::updateHighPerformanceState()222 {223 #if PLATFORM(MAC)224 if (!hasLowAndHighPowerGPUs())225 return;226 227 if (m_contextsRequiringHighPerformance.size()) {228 229 if (m_disableHighPerformanceGPUTimer.isActive()) {230 LOG(WebGL, "Cancel pending timer for turning off high-performance GPU.");231 m_disableHighPerformanceGPUTimer.stop();232 }233 234 if (!m_requestingHighPerformance) {235 LOG(WebGL, "Request the high-performance GPU.");236 m_requestingHighPerformance = true;237 if (auto* singleton = SwitchingGPUClient::singletonIfExists())238 singleton->requestHighPerformanceGPU();239 }240 241 } else {242 // Don't immediately turn off the high-performance GPU. The user might be243 // swapping back and forth between tabs or windows, and we don't want to cause244 // churn if we can avoid it.245 if (!m_disableHighPerformanceGPUTimer.isActive()) {246 LOG(WebGL, "Set a timer to release the high-performance GPU.");247 // FIXME: Expose this value as a Setting, which would require this class248 // to reference a frame, page or document.249 static const Seconds timeToKeepHighPerformanceGPUAlive { 10_s };250 m_disableHighPerformanceGPUTimer.startOneShot(timeToKeepHighPerformanceGPUAlive);251 }252 }253 #endif254 }255 256 void GraphicsContextGLOpenGLManager::disableHighPerformanceGPUTimerFired()257 {258 if (m_contextsRequiringHighPerformance.size())259 return;260 261 m_requestingHighPerformance = false;262 #if PLATFORM(MAC)263 if (auto* singleton = SwitchingGPUClient::singletonIfExists())264 singleton->releaseHighPerformanceGPU();265 82 #endif 266 83 } -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLManager.h
r268198 r271880 26 26 #pragma once 27 27 28 #include "Timer.h"29 #include <wtf/HashMap.h>30 28 #include <wtf/HashSet.h> 31 29 … … 39 37 40 38 class GraphicsContextGLOpenGL; 41 class HostWindow;42 43 using PlatformDisplayID = uint32_t;44 45 #if HAVE(APPLE_GRAPHICS_CONTROL)46 WEBCORE_EXPORT bool hasLowAndHighPowerGPUs();47 #endif48 39 49 40 class GraphicsContextGLOpenGLManager { … … 52 43 static GraphicsContextGLOpenGLManager& sharedManager(); 53 44 54 void addContext(GraphicsContextGLOpenGL* , HostWindow*);45 void addContext(GraphicsContextGLOpenGL*); 55 46 void removeContext(GraphicsContextGLOpenGL*); 56 57 HostWindow* hostWindowForContext(GraphicsContextGLOpenGL*) const;58 59 void addContextRequiringHighPerformance(GraphicsContextGLOpenGL*);60 void removeContextRequiringHighPerformance(GraphicsContextGLOpenGL*);61 47 62 48 void recycleContextIfNecessary(); 63 49 bool hasTooManyContexts() const { return m_contexts.size() >= MaxContexts; } 64 50 65 void updateAllContexts();66 67 51 #if PLATFORM(MAC) 68 void screenDidChange(PlatformDisplayID, const HostWindow*);69 52 WEBCORE_EXPORT static void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void*); 53 #endif 54 #if PLATFORM(COCOA) 55 void displayWasReconfigured(); 70 56 #endif 71 57 72 58 private: 73 GraphicsContextGLOpenGLManager() 74 : m_disableHighPerformanceGPUTimer(*this, &GraphicsContextGLOpenGLManager::disableHighPerformanceGPUTimerFired) 75 { 76 } 77 78 void updateHighPerformanceState(); 79 void disableHighPerformanceGPUTimerFired(); 59 GraphicsContextGLOpenGLManager() = default; 80 60 81 61 Vector<GraphicsContextGLOpenGL*> m_contexts; 82 HashMap<GraphicsContextGLOpenGL*, HostWindow*> m_contextWindowMap;83 HashSet<GraphicsContextGLOpenGL*> m_contextsRequiringHighPerformance;84 85 Timer m_disableHighPerformanceGPUTimer;86 bool m_requestingHighPerformance { false };87 62 }; 88 63 -
trunk/Source/WebCore/testing/Internals.cpp
r271806 r271880 322 322 323 323 #if PLATFORM(MAC) 324 #include "GraphicsC ontextGLOpenGLManager.h"324 #include "GraphicsChecksMac.h" 325 325 #include "NSScrollerImpDetails.h" 326 326 #include "ScrollbarThemeMac.h" -
trunk/Source/WebKit/ChangeLog
r271879 r271880 1 2021-01-26 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE 4 https://bugs.webkit.org/show_bug.cgi?id=220843 5 6 Reviewed by Dean Jackson. 7 8 Move the high-performance GPU shutdown timer from individual web processes to the main class 9 in the ui process. This simplifies the implementation and reduces the number of timers. 10 11 * UIProcess/mac/HighPerformanceGPUManager.h: 12 * UIProcess/mac/HighPerformanceGPUManager.mm: 13 (WebKit::HighPerformanceGPUManager::HighPerformanceGPUManager): 14 (WebKit::HighPerformanceGPUManager::removeProcessRequiringHighPerformance): 15 (WebKit::HighPerformanceGPUManager::updateState): 16 * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp: 17 (WebKit::WebSwitchingGPUClient::requestHighPerformanceGPU): 18 (WebKit::WebSwitchingGPUClient::releaseHighPerformanceGPU): 19 * WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h: 20 1 21 2021-01-26 Carlos Garcia Campos <cgarcia@igalia.com> 2 22 -
trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.h
r236773 r271880 29 29 30 30 #include <OpenGL/CGLTypes.h> 31 #include <WebCore/Timer.h> 31 32 #include <wtf/HashSet.h> 32 33 #include <wtf/NeverDestroyed.h> … … 45 46 46 47 private: 47 HighPerformanceGPUManager() = default;48 HighPerformanceGPUManager(); 48 49 ~HighPerformanceGPUManager(); 49 50 50 void updateState(); 51 51 52 52 HashSet<WebProcessProxy*> m_processesRequiringHighPerformance; 53 53 CGLPixelFormatObj m_pixelFormatObj { nullptr }; 54 WebCore::Timer m_updateStateTimer; 54 55 }; 55 56 -
trunk/Source/WebKit/UIProcess/mac/HighPerformanceGPUManager.mm
r269118 r271880 30 30 31 31 #include "Logging.h" 32 #include <WebCore/GraphicsC ontextGLOpenGLManager.h>32 #include <WebCore/GraphicsChecksMac.h> 33 33 #include <WebCore/OpenGLSoftLinkCocoa.h> 34 34 … … 44 44 return sharedManager; 45 45 } 46 47 HighPerformanceGPUManager::HighPerformanceGPUManager() 48 : m_updateStateTimer(*this, &HighPerformanceGPUManager::updateState) 49 { 50 } 51 52 HighPerformanceGPUManager::~HighPerformanceGPUManager() = default; 46 53 47 54 void HighPerformanceGPUManager::addProcessRequiringHighPerformance(WebProcessProxy* process) … … 66 73 if (m_processesRequiringHighPerformance.remove(process)) { 67 74 LOG(WebGL, "HighPerformanceGPUManager::removeProcessRequiringHighPerformance() - removing process %p", process); 68 updateState(); 75 static const Seconds timeToKeepHighPerformanceGPUAlive { 10_s }; 76 m_updateStateTimer.startOneShot(timeToKeepHighPerformanceGPUAlive); 69 77 return; 70 78 } … … 75 83 void HighPerformanceGPUManager::updateState() 76 84 { 85 if (m_updateStateTimer.isActive()) 86 m_updateStateTimer.stop(); 77 87 if (m_processesRequiringHighPerformance.size()) { 78 88 if (!m_pixelFormatObj) { -
trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.cpp
r236773 r271880 44 44 void WebSwitchingGPUClient::requestHighPerformanceGPU() 45 45 { 46 m_requests++; 47 if (m_requests != 1) 48 return; 46 49 LOG(WebGL, "WebSwitchingGPUClient::requestHighPerformanceGPU() from WebProcess"); 47 50 WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::RequestHighPerformanceGPU(), 0); … … 50 53 void WebSwitchingGPUClient::releaseHighPerformanceGPU() 51 54 { 55 ASSERT(m_requests); 56 m_requests--; 57 if (m_requests) 58 return; 52 59 LOG(WebGL, "WebSwitchingGPUClient::releaseHighPerformanceGPU() from WebProcess"); 53 60 WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::ReleaseHighPerformanceGPU(), 0); -
trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebSwitchingGPUClient.h
r236773 r271880 33 33 public: 34 34 static WebSwitchingGPUClient& singleton(); 35 35 private: 36 36 void requestHighPerformanceGPU() override; 37 37 void releaseHighPerformanceGPU() override; 38 unsigned m_requests { 0 }; 38 39 }; 39 40
Note: See TracChangeset
for help on using the changeset viewer.