Changeset 208997 in webkit


Ignore:
Timestamp:
Nov 28, 2016 7:00:41 AM (7 years ago)
Author:
magomez@igalia.com
Message:

[GTK] Dramatic increase on memory usage since 2.14.x
https://bugs.webkit.org/show_bug.cgi?id=164049

Reviewed by Žan Doberšek.

Use OpenGL version 3.2 Core for rendering when available.
Update some operations that have changed when using 3.2 Core:

  • Use glGetStringi to get the extensions list.
  • Do not use GL_POINT_SPRITE.
  • Always use a VAO when rendering.
  • Use a GLSL 1.50 compatible shader.

No new tests needed.

  • platform/graphics/GLContext.cpp:

(WebCore::GLContext::version):
Add a method to get OpenGL version we are using.

  • platform/graphics/GLContext.h:

Ditto.

  • platform/graphics/GraphicsContext3D.h:

Add an attribute to store the VAO used for rendering.

  • platform/graphics/OpenGLShims.cpp:

(WebCore::initializeOpenGLShims):
Add glGetStringi to the list of functions.

  • platform/graphics/OpenGLShims.h:

Ditto.

  • platform/graphics/cairo/GraphicsContext3DCairo.cpp:

(WebCore::GraphicsContext3D::GraphicsContext3D):
Set appropriate output to the shader compiler and initalize the VAO if needed.
(WebCore::GraphicsContext3D::~GraphicsContext3D):
Delete the VAO if needed.
(WebCore::GraphicsContext3D::getExtensions):
Use glGetExtensionsi for OpenGL versions >= 3.2.

  • platform/graphics/glx/GLContextGLX.cpp:

(WebCore::hasGLXARBCreateContextExtension):
Check whether the GLX_ARB_create_context extension is available.
(WebCore::GLContextGLX::createWindowContext):
Use glXCreateContextAttribsARB() if possible to request an OpenGL 3.2 context.
(WebCore::GLContextGLX::createPbufferContext):
Ditto.

  • platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:

(WebCore::Extensions3DOpenGLCommon::initializeAvailableExtensions):
Enable glGetStringi for GTK.

  • platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:

Do not use default getExtensions() method for GTK.

  • platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:

Ditto.

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208995 r208997  
     12016-11-28  Miguel Gomez  <magomez@igalia.com>
     2
     3        [GTK] Dramatic increase on memory usage since 2.14.x
     4        https://bugs.webkit.org/show_bug.cgi?id=164049
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Use OpenGL version 3.2 Core for rendering when available.
     9        Update some operations that have changed when using 3.2 Core:
     10        - Use glGetStringi to get the extensions list.
     11        - Do not use GL_POINT_SPRITE.
     12        - Always use a VAO when rendering.
     13        - Use a GLSL 1.50 compatible shader.
     14
     15        No new tests needed.
     16
     17        * platform/graphics/GLContext.cpp:
     18        (WebCore::GLContext::version):
     19        Add a method to get OpenGL version we are using.
     20        * platform/graphics/GLContext.h:
     21        Ditto.
     22        * platform/graphics/GraphicsContext3D.h:
     23        Add an attribute to store the VAO used for rendering.
     24        * platform/graphics/OpenGLShims.cpp:
     25        (WebCore::initializeOpenGLShims):
     26        Add glGetStringi to the list of functions.
     27        * platform/graphics/OpenGLShims.h:
     28        Ditto.
     29        * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
     30        (WebCore::GraphicsContext3D::GraphicsContext3D):
     31        Set appropriate output to the shader compiler and initalize the VAO if needed.
     32        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     33        Delete the VAO if needed.
     34        (WebCore::GraphicsContext3D::getExtensions):
     35        Use glGetExtensionsi for OpenGL versions >= 3.2.
     36        * platform/graphics/glx/GLContextGLX.cpp:
     37        (WebCore::hasGLXARBCreateContextExtension):
     38        Check whether the GLX_ARB_create_context extension is available.
     39        (WebCore::GLContextGLX::createWindowContext):
     40        Use glXCreateContextAttribsARB() if possible to request an OpenGL 3.2 context.
     41        (WebCore::GLContextGLX::createPbufferContext):
     42        Ditto.
     43        * platform/graphics/opengl/Extensions3DOpenGLCommon.cpp:
     44        (WebCore::Extensions3DOpenGLCommon::initializeAvailableExtensions):
     45        Enable glGetStringi for GTK.
     46        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
     47        Do not use default getExtensions() method for GTK.
     48        * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
     49        Ditto.
     50
    1512016-11-24  Sergio Villar Senin  <svillar@igalia.com>
    252
  • trunk/Source/WebCore/platform/graphics/GLContext.cpp

    r207615 r208997  
    161161}
    162162
     163unsigned GLContext::version()
     164{
     165    if (!m_version) {
     166        GC3Dint major = 0;
     167        GC3Dint minor = 0;
     168        ::glGetIntegerv(GL_MAJOR_VERSION, &major);
     169        ::glGetIntegerv(GL_MINOR_VERSION, &minor);
     170        m_version = major * 100 + minor * 10;
     171    }
     172    return m_version;
     173}
     174
    163175} // namespace WebCore
    164176
  • trunk/Source/WebCore/platform/graphics/GLContext.h

    r207615 r208997  
    4848
    4949    PlatformDisplay& display() const { return m_display; }
     50    unsigned version();
    5051
    5152    virtual ~GLContext();
     
    7879
    7980    PlatformDisplay& m_display;
     81    unsigned m_version { 0 };
    8082};
    8183
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r208910 r208997  
    14371437
    14381438    bool m_isForWebGL2 { false };
     1439
     1440#if USE(CAIRO)
     1441    Platform3DObject m_vao { 0 };
     1442#endif
     1443
    14391444};
    14401445
  • trunk/Source/WebCore/platform/graphics/OpenGLShims.cpp

    r183432 r208997  
    163163    ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderiv, success);
    164164    ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderSource, success);
     165    // glGetStringi is only available on OpenGL or GLES versions >= 3.0.
     166    // Add it with _EXT so it doesn't cause an initialization failure on lower versions.
     167    ASSIGN_FUNCTION_TABLE_ENTRY_EXT(glGetStringi);
    165168    ASSIGN_FUNCTION_TABLE_ENTRY(glGetUniformfv, success);
    166169    ASSIGN_FUNCTION_TABLE_ENTRY(glGetUniformiv, success);
  • trunk/Source/WebCore/platform/graphics/OpenGLShims.h

    r164525 r208997  
    9393typedef void (GLAPIENTRY *glGetShaderivType) (GLuint, GLenum, GLint*);
    9494typedef void (GLAPIENTRY *glGetShaderSourceType) (GLuint, GLsizei, GLsizei*, char*);
     95typedef const GLubyte* (GLAPIENTRY *glGetStringiType) (GLenum, GLuint);
    9596typedef GLint (GLAPIENTRY *glGetUniformLocationType) (GLuint, const char*);
    9697typedef void (GLAPIENTRY *glGetUniformfvType) (GLuint, GLint, GLfloat*);
     
    199200    FUNCTION_TABLE_ENTRY(glGetShaderiv);
    200201    FUNCTION_TABLE_ENTRY(glGetShaderSource);
     202    FUNCTION_TABLE_ENTRY(glGetStringi);
    201203    FUNCTION_TABLE_ENTRY(glGetUniformfv);
    202204    FUNCTION_TABLE_ENTRY(glGetUniformiv);
     
    326328#define glGetShaderiv                          LOOKUP_GL_FUNCTION(glGetShaderiv)
    327329#define glGetShaderSource                      LOOKUP_GL_FUNCTION(glGetShaderSource)
     330#define glGetStringi                           LOOKUP_GL_FUNCTION(glGetStringi)
    328331#define glGetUniformfv                         LOOKUP_GL_FUNCTION(glGetUniformfv)
    329332#define glGetUniformiv                         LOOKUP_GL_FUNCTION(glGetUniformiv)
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp

    r207332 r208997  
    8080    : m_currentWidth(0)
    8181    , m_currentHeight(0)
    82     , m_compiler(isGLES2Compliant() ? SH_ESSL_OUTPUT : SH_GLSL_COMPATIBILITY_OUTPUT)
    8382    , m_attrs(attributes)
    8483    , m_texture(0)
     
    146145    }
    147146
     147#if !USE(OPENGL_ES_2)
     148    ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
     149
     150    if (GLContext::current()->version() >= 320) {
     151        // From version 3.2 on we use the OpenGL Core profile, so request that ouput to the shader compiler.
     152        // OpenGL version 3.2 uses GLSL version 1.50.
     153        m_compiler = ANGLEWebKitBridge(SH_GLSL_150_CORE_OUTPUT);
     154
     155        // From version 3.2 on we use the OpenGL Core profile, and we need a VAO for rendering.
     156        // A VAO could be created and bound by each component using GL rendering (TextureMapper, WebGL, etc). This is
     157        // a simpler solution: the first GraphicsContext3D created on a GLContext will create and bind a VAO for that context.
     158        GC3Dint currentVAO = 0;
     159        getIntegerv(GraphicsContext3D::VERTEX_ARRAY_BINDING, &currentVAO);
     160        if (!currentVAO) {
     161            m_vao = createVertexArray();
     162            bindVertexArray(m_vao);
     163        }
     164    } else {
     165        // For lower versions request the compatibility output to the shader compiler.
     166        m_compiler = ANGLEWebKitBridge(SH_GLSL_COMPATIBILITY_OUTPUT);
     167
     168        // GL_POINT_SPRITE is needed in lower versions.
     169        ::glEnable(GL_POINT_SPRITE);
     170    }
     171#else
     172    m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT);
     173#endif
     174
    148175    // ANGLE initialization.
    149176    ShBuiltInResources ANGLEResources;
     
    166193
    167194    m_compiler.setResources(ANGLEResources);
    168 
    169 #if !USE(OPENGL_ES_2)
    170     ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    171     ::glEnable(GL_POINT_SPRITE);
    172 #endif
    173195
    174196    ::glClearColor(0, 0, 0, 0);
     
    199221    ::glDeleteTextures(1, &m_intermediateTexture);
    200222#endif
     223
     224    if (m_vao)
     225        deleteVertexArray(m_vao);
    201226}
    202227
     
    345370}
    346371
     372#if PLATFORM(GTK)
     373Extensions3D& GraphicsContext3D::getExtensions()
     374{
     375    if (!m_extensions) {
     376#if USE(OPENGL_ES_2)
     377        // glGetStringi is not available on GLES2.
     378        m_extensions = std::make_unique<Extensions3DOpenGLES>(this,  false);
     379#else
     380        // From OpenGL 3.2 on we use the Core profile, and there we must use glGetStringi.
     381        m_extensions = std::make_unique<Extensions3DOpenGL>(this, GLContext::current()->version() >= 320);
     382#endif
     383    }
     384    return *m_extensions;
     385}
     386#endif
     387
    347388} // namespace WebCore
    348389
  • trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp

    r207615 r208997  
    3636typedef int (*PFNGLXSWAPINTERVALSGIPROC) (int);
    3737#endif
     38#if !defined(PFNGLXCREATECONTEXTATTRIBSARBPROC)
     39typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
     40#endif
    3841
    3942static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
     43static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
    4044
    4145static bool hasSGISwapControlExtension(Display* display)
     
    5357}
    5458
     59static bool hasGLXARBCreateContextExtension(Display* display)
     60{
     61    static bool initialized = false;
     62    if (initialized)
     63        return !!glXCreateContextAttribsARB;
     64
     65    initialized = true;
     66    if (!GLContext::isExtensionSupported(glXQueryExtensionsString(display, 0), "GLX_ARB_create_context"))
     67        return false;
     68
     69    glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(reinterpret_cast<const unsigned char*>("glXCreateContextAttribsARB")));
     70    return !!glXCreateContextAttribsARB;
     71}
     72
    5573std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(GLNativeWindowType window, PlatformDisplay& platformDisplay, GLXContext sharingContext)
    5674{
     
    6381    visualInfo.visualid = XVisualIDFromVisual(attributes.visual);
    6482
    65     int numReturned = 0;
    66     XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned));
    67 
    68     XUniqueGLXContext context(glXCreateContext(display, visualInfoList.get(), sharingContext, True));
     83    int numConfigs = 0;
     84    GLXFBConfig config = nullptr;
     85    XUniquePtr<GLXFBConfig> configs(glXGetFBConfigs(display, DefaultScreen(display), &numConfigs));
     86    for (int i = 0; i < numConfigs; i++) {
     87        XUniquePtr<XVisualInfo> glxVisualInfo(glXGetVisualFromFBConfig(display, configs.get()[i]));
     88        if (!glxVisualInfo)
     89            continue;
     90
     91        if (glxVisualInfo.get()->visualid == visualInfo.visualid) {
     92            config = configs.get()[i];
     93            break;
     94        }
     95    }
     96    ASSERT(config);
     97
     98    XUniqueGLXContext context;
     99    if (hasGLXARBCreateContextExtension(display)) {
     100        // Request OpenGL version 3.2 and core profile, which guarantees that the i965 driver doesn't use the software renderer.
     101        static const int contextAttributes[] = {
     102            GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
     103            GLX_CONTEXT_MINOR_VERSION_ARB, 2,
     104            0
     105        };
     106        context.reset(glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, contextAttributes));
     107    }
     108
     109    if (!context) {
     110        // Fallback to legacy OpenGL version.
     111        XUniquePtr<XVisualInfo> visualInfoList(glXGetVisualFromFBConfig(display, config));
     112        context.reset(glXCreateContext(display, visualInfoList.get(), sharingContext, True));
     113    }
     114
    69115    if (!context)
    70116        return nullptr;
     
    98144        return nullptr;
    99145
    100     XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
     146    XUniqueGLXContext context;
     147
     148    if (hasGLXARBCreateContextExtension(display)) {
     149        // Request OpenGL version 3.2 and core profile, which guarantees that the i965 driver doesn't use the software renderer.
     150        static const int contextAttributes[] = {
     151            GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
     152            GLX_CONTEXT_MINOR_VERSION_ARB, 2,
     153            0
     154        };
     155        context.reset(glXCreateContextAttribsARB(display, configs.get()[0], sharingContext, GL_TRUE, contextAttributes));
     156    }
     157
     158    if (!context) {
     159        // Fallback to legacy OpenGL version.
     160        context.reset(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
     161    }
     162
    101163    if (!context)
    102164        return nullptr;
  • trunk/Source/WebCore/platform/graphics/opengl/Extensions3DOpenGLCommon.cpp

    r208910 r208997  
    210210void Extensions3DOpenGLCommon::initializeAvailableExtensions()
    211211{
    212 #if PLATFORM(MAC)
     212#if PLATFORM(MAC) || PLATFORM(GTK)
    213213    if (m_useIndexedGetString) {
    214214        GLint numExtensions = 0;
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r208740 r208997  
    408408}
    409409
     410#if !PLATFORM(GTK)
    410411Extensions3D& GraphicsContext3D::getExtensions()
    411412{
     
    414415    return *m_extensions;
    415416}
     417#endif
    416418
    417419void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp

    r208873 r208997  
    239239}
    240240
     241#if !PLATFORM(GTK)
    241242Extensions3D& GraphicsContext3D::getExtensions()
    242243{
     
    245246    return *m_extensions;
    246247}
     248#endif
    247249
    248250}
Note: See TracChangeset for help on using the changeset viewer.