Changeset 252909 in webkit


Ignore:
Timestamp:
Nov 27, 2019 10:59:39 AM (4 years ago)
Author:
commit-queue@webkit.org
Message:

Enable GPU switching with ANGLE
https://bugs.webkit.org/show_bug.cgi?id=203916

This enables the same GPU switching code that we use with OpenGL on ANGLE
contexts. ANGLE contexts can now be switched to the high power GPU.

Patch by James Darpinian <James Darpinian> on 2019-11-27
Reviewed by Dean Jackson.

  • platform/graphics/GraphicsContext3D.h:
  • platform/graphics/GraphicsContext3DManager.cpp:

(WebCore::GraphicsContext3DManager::updateAllContexts):

  • platform/graphics/cocoa/GraphicsContext3DCocoa.mm:

(WebCore::setGPUByRegistryID):
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::updateCGLContext):
(WebCore::GraphicsContext3D::screenDidChange):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252907 r252909  
     12019-11-27  James Darpinian  <jdarpinian@chromium.org>
     2
     3        Enable GPU switching with ANGLE
     4        https://bugs.webkit.org/show_bug.cgi?id=203916
     5
     6        This enables the same GPU switching code that we use with OpenGL on ANGLE
     7        contexts. ANGLE contexts can now be switched to the high power GPU.
     8
     9        Reviewed by Dean Jackson.
     10
     11        * platform/graphics/GraphicsContext3D.h:
     12        * platform/graphics/GraphicsContext3DManager.cpp:
     13        (WebCore::GraphicsContext3DManager::updateAllContexts):
     14        * platform/graphics/cocoa/GraphicsContext3DCocoa.mm:
     15        (WebCore::setGPUByRegistryID):
     16        (WebCore::GraphicsContext3D::GraphicsContext3D):
     17        (WebCore::GraphicsContext3D::updateCGLContext):
     18        (WebCore::GraphicsContext3D::screenDidChange):
     19
    1202019-11-27  Antti Koivisto  <antti@apple.com>
    221
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r252741 r252909  
    12001200#endif
    12011201
    1202 #if USE(OPENGL)
     1202#if USE(OPENGL) || USE(ANGLE)
    12031203    void allocateIOSurfaceBackingStore(IntSize);
    12041204    void updateFramebufferTextureBackingStoreFromLayer();
     1205#if PLATFORM(MAC)
    12051206    void updateCGLContext();
    12061207#endif
    1207 
    1208 #if USE(ANGLE)
    1209     void allocateIOSurfaceBackingStore(IntSize);
    1210     void updateFramebufferTextureBackingStoreFromLayer();
    12111208#endif
    12121209#endif // PLATFORM(COCOA)
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp

    r252055 r252909  
    135135void GraphicsContext3DManager::updateAllContexts()
    136136{
    137     // FIXME: determine whether to do anything when using ANGLE.
    138 #if PLATFORM(MAC) && USE(OPENGL)
     137#if PLATFORM(MAC) && (USE(OPENGL) || USE(ANGLE))
    139138    for (const auto& context : m_contexts) {
    140139        context->updateCGLContext();
  • trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm

    r252741 r252909  
    5858#elif USE(OPENGL)
    5959#import <IOKit/IOKitLib.h>
    60 #import <OpenGL/CGLRenderers.h>
    6160#import <OpenGL/gl.h>
    6261#elif USE(ANGLE)
     
    8584#if PLATFORM(MAC)
    8685#import "ScreenProperties.h"
     86#if USE(OPENGL) || USE(ANGLE)
     87#import <OpenGL/CGLRenderers.h>
     88#endif
    8789#endif
    8890
     
    132134}
    133135
    134 #if PLATFORM(MAC) && USE(OPENGL) // FIXME: This probably should be just USE(OPENGL) - see <rdar://53062794>.
    135 
    136 static void setGPUByRegistryID(PlatformGraphicsContext3D contextObj, CGLPixelFormatObj pixelFormatObj, IORegistryGPUID preferredGPUID)
     136#if PLATFORM(MAC) && (USE(OPENGL) || USE(ANGLE)) // FIXME: This probably should be just (USE(OPENGL) || USE(ANGLE)) - see <rdar://53062794>.
     137
     138static void setGPUByRegistryID(CGLContextObj contextObj, CGLPixelFormatObj pixelFormatObj, IORegistryGPUID preferredGPUID)
    137139{
    138140    // 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.
     
    289291
    290292#elif USE(ANGLE)
    291 
    292     UNUSED_PARAM(hostWindow);
    293293
    294294    m_displayObj = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
     
    373373        extensions.ensureEnabled(requiredExtensions[i]);
    374374    }
     375
     376    EGLDeviceEXT device = nullptr;
     377    EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
     378    CGLContextObj cglContext = nullptr;
     379    CGLPixelFormatObj pixelFormat = nullptr;
     380    EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
     381    EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat));
     382    auto gpuID = (hostWindow && hostWindow->displayID()) ? gpuIDForDisplay(hostWindow->displayID()) : primaryGPUID();
     383    setGPUByRegistryID(cglContext, pixelFormat, gpuID);
     384#else
     385    UNUSED_PARAM(hostWindow);
    375386#endif // PLATFORM(MAC)
    376387
     
    717728
    718729#if USE(ANGLE)
     730
     731#if PLATFORM(MAC)
     732void GraphicsContext3D::updateCGLContext()
     733{
     734    if (!m_contextObj)
     735        return;
     736
     737    LOG(WebGL, "Detected a mux switch or display reconfiguration. Call CGLUpdateContext. (%p)", this);
     738
     739    makeContextCurrent();
     740    EGLDeviceEXT device = nullptr;
     741    EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
     742    CGLContextObj cglContext = nullptr;
     743    EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
     744
     745    CGLUpdateContext(cglContext);
     746    m_hasSwitchedToHighPerformanceGPU = true;
     747}
     748#endif
     749
    719750void GraphicsContext3D::allocateIOSurfaceBackingStore(IntSize size)
    720751{
     
    785816        return;
    786817#if USE(ANGLE)
    787     UNUSED_PARAM(displayID);
     818    if (!m_hasSwitchedToHighPerformanceGPU) {
     819        EGLDeviceEXT device = nullptr;
     820        EGL_QueryDisplayAttribEXT(m_displayObj, EGL_DEVICE_EXT, reinterpret_cast<EGLAttrib*>(&device));
     821        CGLContextObj cglContext = nullptr;
     822        CGLPixelFormatObj pixelFormat = nullptr;
     823        EGL_QueryDeviceAttribEXT(device, EGL_CGL_CONTEXT_ANGLE, reinterpret_cast<EGLAttrib*>(&cglContext));
     824        EGL_QueryDeviceAttribEXT(device, EGL_CGL_PIXEL_FORMAT_ANGLE, reinterpret_cast<EGLAttrib*>(&pixelFormat));
     825        setGPUByRegistryID(cglContext, pixelFormat, gpuIDForDisplay(displayID));
     826    }
    788827#else
    789     // FIXME: figure out whether to integrate more code into ANGLE to have this effect.
    790828#if USE(OPENGL)
    791829    if (!m_hasSwitchedToHighPerformanceGPU)
Note: See TracChangeset for help on using the changeset viewer.