From 2f680de24a2e422d8236f767b18c8afc2bd715cc Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Fri, 22 Feb 2019 21:17:28 +0000 Subject: [PATCH] Bug 1528396 - More precise GL symbol loading. r=lsalzman In particular, don't fallback to loading symbols from any loaded library. Differential Revision: https://phabricator.services.mozilla.com/D20455 --HG-- extra : moz-landing-system : lando --- gfx/gl/GLContext.cpp | 644 ++++++++++++------------ gfx/gl/GLContext.h | 25 +- gfx/gl/GLContextCGL.h | 6 +- gfx/gl/GLContextEAGL.h | 4 +- gfx/gl/GLContextEGL.h | 2 +- gfx/gl/GLContextGLX.h | 2 +- gfx/gl/GLContextProviderCGL.mm | 16 +- gfx/gl/GLContextProviderEAGL.mm | 19 +- gfx/gl/GLContextProviderEGL.cpp | 20 +- gfx/gl/GLContextProviderGLX.cpp | 70 ++- gfx/gl/GLContextProviderWGL.cpp | 97 ++-- gfx/gl/GLContextWGL.h | 7 +- gfx/gl/GLLibraryEGL.cpp | 197 +++++--- gfx/gl/GLLibraryEGL.h | 10 +- gfx/gl/GLLibraryLoader.cpp | 101 ++-- gfx/gl/GLLibraryLoader.h | 80 ++- gfx/gl/GLXLibrary.h | 6 +- gfx/gl/WGLLibrary.h | 2 + gfx/layers/wr/WebRenderBridgeParent.cpp | 10 +- 19 files changed, 652 insertions(+), 666 deletions(-) diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index 74796d5a6282..4057a92245ba 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -64,11 +64,11 @@ MOZ_THREAD_LOCAL(uintptr_t) GLContext::sCurrentContext; // If adding defines, don't forget to undefine symbols. See #undef block below. // clang-format off -#define CORE_SYMBOL(x) { (PRFuncPtr*) &mSymbols.f##x, { #x, nullptr } } -#define CORE_EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, { #x, #x #y, #x #z, nullptr } } -#define EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, { #x #y, #x #z, nullptr } } -#define EXT_SYMBOL3(x,y,z,w) { (PRFuncPtr*) &mSymbols.f##x, { #x #y, #x #z, #x #w, nullptr } } -#define END_SYMBOLS { nullptr, { nullptr } } +#define CORE_SYMBOL(x) { (PRFuncPtr*) &mSymbols.f##x, {{ "gl" #x }} } +#define CORE_EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, {{ "gl" #x, "gl" #x #y, "gl" #x #z }} } +#define EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, {{ "gl" #x #y, "gl" #x #z }} } +#define EXT_SYMBOL3(x,y,z,w) { (PRFuncPtr*) &mSymbols.f##x, {{ "gl" #x #y, "gl" #x #z, "gl" #x #w }} } +#define END_SYMBOLS { nullptr, {} } // clang-format on // should match the order of GLExtensions, and be null-terminated. @@ -303,20 +303,13 @@ GLContext::~GLContext() { gl->DebugCallback(source, type, id, severity, length, message); } -static void ClearSymbols(const GLLibraryLoader::SymLoadStruct* symbols) { - while (symbols->symPointer) { - *symbols->symPointer = nullptr; - symbols++; - } -} - -bool GLContext::InitWithPrefix(const char* prefix, bool trygl) { +bool GLContext::Init() { MOZ_RELEASE_ASSERT(!mSymbols.fBindFramebuffer, - "GFX: InitWithPrefix should only be called once."); + "GFX: GLContext::Init should only be called once."); ScopedGfxFeatureReporter reporter("GL Context"); - if (!InitWithPrefixImpl(prefix, trygl)) { + if (!InitImpl()) { // If initialization fails, zero the symbols to avoid hard-to-understand // bugs. mSymbols = {}; @@ -328,11 +321,10 @@ bool GLContext::InitWithPrefix(const char* prefix, bool trygl) { return true; } -static bool LoadGLSymbols(GLContext* gl, const char* prefix, bool trygl, - const GLLibraryLoader::SymLoadStruct* list, - const char* desc) { +static bool LoadSymbolsWithDesc(const SymbolLoader& loader, + const SymLoadStruct* list, const char* desc) { const auto warnOnFailure = bool(desc); - if (gl->LoadSymbols(list, trygl, prefix, warnOnFailure)) return true; + if (loader.LoadSymbols(list, warnOnFailure)) return true; ClearSymbols(list); @@ -343,170 +335,178 @@ static bool LoadGLSymbols(GLContext* gl, const char* prefix, bool trygl, return false; } -bool GLContext::LoadExtSymbols(const char* prefix, bool trygl, +bool GLContext::LoadExtSymbols(const SymbolLoader& loader, const SymLoadStruct* list, GLExtensions ext) { const char* extName = sExtensionNames[size_t(ext)]; - if (!LoadGLSymbols(this, prefix, trygl, list, extName)) { + if (!LoadSymbolsWithDesc(loader, list, extName)) { MarkExtensionUnsupported(ext); return false; } return true; }; -bool GLContext::LoadFeatureSymbols(const char* prefix, bool trygl, +bool GLContext::LoadFeatureSymbols(const SymbolLoader& loader, const SymLoadStruct* list, GLFeature feature) { const char* featureName = GetFeatureName(feature); - if (!LoadGLSymbols(this, prefix, trygl, list, featureName)) { + if (!LoadSymbolsWithDesc(loader, list, featureName)) { MarkUnsupported(feature); return false; } return true; }; -bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { +bool GLContext::InitImpl() { if (!MakeCurrent(true)) return false; + const auto loader = GetSymbolLoader(); + if (!loader) return false; + + const auto fnLoadSymbols = [&](const SymLoadStruct* const list, + const char* const desc) { + return LoadSymbolsWithDesc(*loader, list, desc); + }; + // clang-format off const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fActiveTexture, { "ActiveTexture", "ActiveTextureARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fAttachShader, { "AttachShader", "AttachShaderARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindAttribLocation, { "BindAttribLocation", "BindAttribLocationARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindBuffer, { "BindBuffer", "BindBufferARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindTexture, { "BindTexture", "BindTextureARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBlendColor, { "BlendColor", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBlendEquation, { "BlendEquation", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBlendEquationSeparate, { "BlendEquationSeparate", "BlendEquationSeparateEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBlendFunc, { "BlendFunc", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBlendFuncSeparate, { "BlendFuncSeparate", "BlendFuncSeparateEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBufferData, { "BufferData", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBufferSubData, { "BufferSubData", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClear, { "Clear", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClearColor, { "ClearColor", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClearStencil, { "ClearStencil", nullptr } }, - { (PRFuncPtr*) &mSymbols.fColorMask, { "ColorMask", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCompressedTexImage2D, {"CompressedTexImage2D", nullptr} }, - { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage2D, {"CompressedTexSubImage2D", nullptr} }, - { (PRFuncPtr*) &mSymbols.fCullFace, { "CullFace", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDetachShader, { "DetachShader", "DetachShaderARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDepthFunc, { "DepthFunc", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDepthMask, { "DepthMask", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDisable, { "Disable", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDisableVertexAttribArray, { "DisableVertexAttribArray", "DisableVertexAttribArrayARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDrawArrays, { "DrawArrays", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDrawElements, { "DrawElements", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEnable, { "Enable", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEnableVertexAttribArray, { "EnableVertexAttribArray", "EnableVertexAttribArrayARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fFinish, { "Finish", nullptr } }, - { (PRFuncPtr*) &mSymbols.fFlush, { "Flush", nullptr } }, - { (PRFuncPtr*) &mSymbols.fFrontFace, { "FrontFace", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetActiveAttrib, { "GetActiveAttrib", "GetActiveAttribARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetActiveUniform, { "GetActiveUniform", "GetActiveUniformARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetAttachedShaders, { "GetAttachedShaders", "GetAttachedShadersARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetAttribLocation, { "GetAttribLocation", "GetAttribLocationARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetIntegerv, { "GetIntegerv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetFloatv, { "GetFloatv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetBooleanv, { "GetBooleanv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetBufferParameteriv, { "GetBufferParameteriv", "GetBufferParameterivARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetError, { "GetError", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetProgramiv, { "GetProgramiv", "GetProgramivARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetProgramInfoLog, { "GetProgramInfoLog", "GetProgramInfoLogARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexParameteri, { "TexParameteri", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexParameteriv, { "TexParameteriv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexParameterf, { "TexParameterf", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetString, { "GetString", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetTexParameterfv, { "GetTexParameterfv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetTexParameteriv, { "GetTexParameteriv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetUniformfv, { "GetUniformfv", "GetUniformfvARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetUniformiv, { "GetUniformiv", "GetUniformivARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetUniformLocation, { "GetUniformLocation", "GetUniformLocationARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetVertexAttribfv, { "GetVertexAttribfv", "GetVertexAttribfvARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetVertexAttribiv, { "GetVertexAttribiv", "GetVertexAttribivARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetVertexAttribPointerv, { "GetVertexAttribPointerv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fHint, { "Hint", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsBuffer, { "IsBuffer", "IsBufferARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsEnabled, { "IsEnabled", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsProgram, { "IsProgram", "IsProgramARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsShader, { "IsShader", "IsShaderARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsTexture, { "IsTexture", "IsTextureARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fLineWidth, { "LineWidth", nullptr } }, - { (PRFuncPtr*) &mSymbols.fLinkProgram, { "LinkProgram", "LinkProgramARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPixelStorei, { "PixelStorei", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPolygonOffset, { "PolygonOffset", nullptr } }, - { (PRFuncPtr*) &mSymbols.fReadPixels, { "ReadPixels", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSampleCoverage, { "SampleCoverage", nullptr } }, - { (PRFuncPtr*) &mSymbols.fScissor, { "Scissor", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilFunc, { "StencilFunc", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilFuncSeparate, { "StencilFuncSeparate", "StencilFuncSeparateEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilMask, { "StencilMask", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilMaskSeparate, { "StencilMaskSeparate", "StencilMaskSeparateEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilOp, { "StencilOp", nullptr } }, - { (PRFuncPtr*) &mSymbols.fStencilOpSeparate, { "StencilOpSeparate", "StencilOpSeparateEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexImage2D, { "TexImage2D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexSubImage2D, { "TexSubImage2D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1f, { "Uniform1f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1fv, { "Uniform1fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1i, { "Uniform1i", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1iv, { "Uniform1iv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2f, { "Uniform2f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2fv, { "Uniform2fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2i, { "Uniform2i", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2iv, { "Uniform2iv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3f, { "Uniform3f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3fv, { "Uniform3fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3i, { "Uniform3i", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3iv, { "Uniform3iv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4f, { "Uniform4f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4fv, { "Uniform4fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4i, { "Uniform4i", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4iv, { "Uniform4iv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix2fv, { "UniformMatrix2fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix3fv, { "UniformMatrix3fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix4fv, { "UniformMatrix4fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUseProgram, { "UseProgram", nullptr } }, - { (PRFuncPtr*) &mSymbols.fValidateProgram, { "ValidateProgram", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, { "VertexAttribPointer", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib1f, { "VertexAttrib1f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib2f, { "VertexAttrib2f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib3f, { "VertexAttrib3f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib4f, { "VertexAttrib4f", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib1fv, { "VertexAttrib1fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib2fv, { "VertexAttrib2fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib3fv, { "VertexAttrib3fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttrib4fv, { "VertexAttrib4fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fViewport, { "Viewport", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCompileShader, { "CompileShader", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCopyTexImage2D, { "CopyTexImage2D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCopyTexSubImage2D, { "CopyTexSubImage2D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetShaderiv, { "GetShaderiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetShaderInfoLog, { "GetShaderInfoLog", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetShaderSource, { "GetShaderSource", nullptr } }, - { (PRFuncPtr*) &mSymbols.fShaderSource, { "ShaderSource", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, { "VertexAttribPointer", nullptr } }, + { (PRFuncPtr*) &mSymbols.fActiveTexture, {{ "glActiveTexture", "glActiveTextureARB" }} }, + { (PRFuncPtr*) &mSymbols.fAttachShader, {{ "glAttachShader", "glAttachShaderARB" }} }, + { (PRFuncPtr*) &mSymbols.fBindAttribLocation, {{ "glBindAttribLocation", "glBindAttribLocationARB" }} }, + { (PRFuncPtr*) &mSymbols.fBindBuffer, {{ "glBindBuffer", "glBindBufferARB" }} }, + { (PRFuncPtr*) &mSymbols.fBindTexture, {{ "glBindTexture", "glBindTextureARB" }} }, + { (PRFuncPtr*) &mSymbols.fBlendColor, {{ "glBlendColor" }} }, + { (PRFuncPtr*) &mSymbols.fBlendEquation, {{ "glBlendEquation" }} }, + { (PRFuncPtr*) &mSymbols.fBlendEquationSeparate, {{ "glBlendEquationSeparate", "glBlendEquationSeparateEXT" }} }, + { (PRFuncPtr*) &mSymbols.fBlendFunc, {{ "glBlendFunc" }} }, + { (PRFuncPtr*) &mSymbols.fBlendFuncSeparate, {{ "glBlendFuncSeparate", "glBlendFuncSeparateEXT" }} }, + { (PRFuncPtr*) &mSymbols.fBufferData, {{ "glBufferData" }} }, + { (PRFuncPtr*) &mSymbols.fBufferSubData, {{ "glBufferSubData" }} }, + { (PRFuncPtr*) &mSymbols.fClear, {{ "glClear" }} }, + { (PRFuncPtr*) &mSymbols.fClearColor, {{ "glClearColor" }} }, + { (PRFuncPtr*) &mSymbols.fClearStencil, {{ "glClearStencil" }} }, + { (PRFuncPtr*) &mSymbols.fColorMask, {{ "glColorMask" }} }, + { (PRFuncPtr*) &mSymbols.fCompressedTexImage2D, {{ "glCompressedTexImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage2D, {{ "glCompressedTexSubImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fCullFace, {{ "glCullFace" }} }, + { (PRFuncPtr*) &mSymbols.fDetachShader, {{ "glDetachShader", "glDetachShaderARB" }} }, + { (PRFuncPtr*) &mSymbols.fDepthFunc, {{ "glDepthFunc" }} }, + { (PRFuncPtr*) &mSymbols.fDepthMask, {{ "glDepthMask" }} }, + { (PRFuncPtr*) &mSymbols.fDisable, {{ "glDisable" }} }, + { (PRFuncPtr*) &mSymbols.fDisableVertexAttribArray, {{ "glDisableVertexAttribArray", "glDisableVertexAttribArrayARB" }} }, + { (PRFuncPtr*) &mSymbols.fDrawArrays, {{ "glDrawArrays" }} }, + { (PRFuncPtr*) &mSymbols.fDrawElements, {{ "glDrawElements" }} }, + { (PRFuncPtr*) &mSymbols.fEnable, {{ "glEnable" }} }, + { (PRFuncPtr*) &mSymbols.fEnableVertexAttribArray, {{ "glEnableVertexAttribArray", "glEnableVertexAttribArrayARB" }} }, + { (PRFuncPtr*) &mSymbols.fFinish, {{ "glFinish" }} }, + { (PRFuncPtr*) &mSymbols.fFlush, {{ "glFlush" }} }, + { (PRFuncPtr*) &mSymbols.fFrontFace, {{ "glFrontFace" }} }, + { (PRFuncPtr*) &mSymbols.fGetActiveAttrib, {{ "glGetActiveAttrib", "glGetActiveAttribARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetActiveUniform, {{ "glGetActiveUniform", "glGetActiveUniformARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetAttachedShaders, {{ "glGetAttachedShaders", "glGetAttachedShadersARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetAttribLocation, {{ "glGetAttribLocation", "glGetAttribLocationARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetIntegerv, {{ "glGetIntegerv" }} }, + { (PRFuncPtr*) &mSymbols.fGetFloatv, {{ "glGetFloatv" }} }, + { (PRFuncPtr*) &mSymbols.fGetBooleanv, {{ "glGetBooleanv" }} }, + { (PRFuncPtr*) &mSymbols.fGetBufferParameteriv, {{ "glGetBufferParameteriv", "glGetBufferParameterivARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetError, {{ "glGetError" }} }, + { (PRFuncPtr*) &mSymbols.fGetProgramiv, {{ "glGetProgramiv", "glGetProgramivARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetProgramInfoLog, {{ "glGetProgramInfoLog", "glGetProgramInfoLogARB" }} }, + { (PRFuncPtr*) &mSymbols.fTexParameteri, {{ "glTexParameteri" }} }, + { (PRFuncPtr*) &mSymbols.fTexParameteriv, {{ "glTexParameteriv" }} }, + { (PRFuncPtr*) &mSymbols.fTexParameterf, {{ "glTexParameterf" }} }, + { (PRFuncPtr*) &mSymbols.fGetString, {{ "glGetString" }} }, + { (PRFuncPtr*) &mSymbols.fGetTexParameterfv, {{ "glGetTexParameterfv" }} }, + { (PRFuncPtr*) &mSymbols.fGetTexParameteriv, {{ "glGetTexParameteriv" }} }, + { (PRFuncPtr*) &mSymbols.fGetUniformfv, {{ "glGetUniformfv", "glGetUniformfvARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetUniformiv, {{ "glGetUniformiv", "glGetUniformivARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetUniformLocation, {{ "glGetUniformLocation", "glGetUniformLocationARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetVertexAttribfv, {{ "glGetVertexAttribfv", "glGetVertexAttribfvARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetVertexAttribiv, {{ "glGetVertexAttribiv", "glGetVertexAttribivARB" }} }, + { (PRFuncPtr*) &mSymbols.fGetVertexAttribPointerv, {{ "glGetVertexAttribPointerv" }} }, + { (PRFuncPtr*) &mSymbols.fHint, {{ "glHint" }} }, + { (PRFuncPtr*) &mSymbols.fIsBuffer, {{ "glIsBuffer", "glIsBufferARB" }} }, + { (PRFuncPtr*) &mSymbols.fIsEnabled, {{ "glIsEnabled" }} }, + { (PRFuncPtr*) &mSymbols.fIsProgram, {{ "glIsProgram", "glIsProgramARB" }} }, + { (PRFuncPtr*) &mSymbols.fIsShader, {{ "glIsShader", "glIsShaderARB" }} }, + { (PRFuncPtr*) &mSymbols.fIsTexture, {{ "glIsTexture", "glIsTextureARB" }} }, + { (PRFuncPtr*) &mSymbols.fLineWidth, {{ "glLineWidth" }} }, + { (PRFuncPtr*) &mSymbols.fLinkProgram, {{ "glLinkProgram", "glLinkProgramARB" }} }, + { (PRFuncPtr*) &mSymbols.fPixelStorei, {{ "glPixelStorei" }} }, + { (PRFuncPtr*) &mSymbols.fPolygonOffset, {{ "glPolygonOffset" }} }, + { (PRFuncPtr*) &mSymbols.fReadPixels, {{ "glReadPixels" }} }, + { (PRFuncPtr*) &mSymbols.fSampleCoverage, {{ "glSampleCoverage" }} }, + { (PRFuncPtr*) &mSymbols.fScissor, {{ "glScissor" }} }, + { (PRFuncPtr*) &mSymbols.fStencilFunc, {{ "glStencilFunc" }} }, + { (PRFuncPtr*) &mSymbols.fStencilFuncSeparate, {{ "glStencilFuncSeparate", "glStencilFuncSeparateEXT" }} }, + { (PRFuncPtr*) &mSymbols.fStencilMask, {{ "glStencilMask" }} }, + { (PRFuncPtr*) &mSymbols.fStencilMaskSeparate, {{ "glStencilMaskSeparate", "glStencilMaskSeparateEXT" }} }, + { (PRFuncPtr*) &mSymbols.fStencilOp, {{ "glStencilOp" }} }, + { (PRFuncPtr*) &mSymbols.fStencilOpSeparate, {{ "glStencilOpSeparate", "glStencilOpSeparateEXT" }} }, + { (PRFuncPtr*) &mSymbols.fTexImage2D, {{ "glTexImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fTexSubImage2D, {{ "glTexSubImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1f, {{ "glUniform1f" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1fv, {{ "glUniform1fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1i, {{ "glUniform1i" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1iv, {{ "glUniform1iv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2f, {{ "glUniform2f" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2fv, {{ "glUniform2fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2i, {{ "glUniform2i" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2iv, {{ "glUniform2iv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3f, {{ "glUniform3f" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3fv, {{ "glUniform3fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3i, {{ "glUniform3i" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3iv, {{ "glUniform3iv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4f, {{ "glUniform4f" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4fv, {{ "glUniform4fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4i, {{ "glUniform4i" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4iv, {{ "glUniform4iv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix2fv, {{ "glUniformMatrix2fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix3fv, {{ "glUniformMatrix3fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix4fv, {{ "glUniformMatrix4fv" }} }, + { (PRFuncPtr*) &mSymbols.fUseProgram, {{ "glUseProgram" }} }, + { (PRFuncPtr*) &mSymbols.fValidateProgram, {{ "glValidateProgram" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, {{ "glVertexAttribPointer" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib1f, {{ "glVertexAttrib1f" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib2f, {{ "glVertexAttrib2f" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib3f, {{ "glVertexAttrib3f" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib4f, {{ "glVertexAttrib4f" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib1fv, {{ "glVertexAttrib1fv" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib2fv, {{ "glVertexAttrib2fv" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib3fv, {{ "glVertexAttrib3fv" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttrib4fv, {{ "glVertexAttrib4fv" }} }, + { (PRFuncPtr*) &mSymbols.fViewport, {{ "glViewport" }} }, + { (PRFuncPtr*) &mSymbols.fCompileShader, {{ "glCompileShader" }} }, + { (PRFuncPtr*) &mSymbols.fCopyTexImage2D, {{ "glCopyTexImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fCopyTexSubImage2D, {{ "glCopyTexSubImage2D" }} }, + { (PRFuncPtr*) &mSymbols.fGetShaderiv, {{ "glGetShaderiv" }} }, + { (PRFuncPtr*) &mSymbols.fGetShaderInfoLog, {{ "glGetShaderInfoLog" }} }, + { (PRFuncPtr*) &mSymbols.fGetShaderSource, {{ "glGetShaderSource" }} }, + { (PRFuncPtr*) &mSymbols.fShaderSource, {{ "glShaderSource" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, {{ "glVertexAttribPointer" }} }, - { (PRFuncPtr*) &mSymbols.fGenBuffers, { "GenBuffers", "GenBuffersARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenTextures, { "GenTextures", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCreateProgram, { "CreateProgram", "CreateProgramARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCreateShader, { "CreateShader", "CreateShaderARB", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGenBuffers, {{ "glGenBuffers", "glGenBuffersARB" }} }, + { (PRFuncPtr*) &mSymbols.fGenTextures, {{ "glGenTextures" }} }, + { (PRFuncPtr*) &mSymbols.fCreateProgram, {{ "glCreateProgram", "glCreateProgramARB" }} }, + { (PRFuncPtr*) &mSymbols.fCreateShader, {{ "glCreateShader", "glCreateShaderARB" }} }, - { (PRFuncPtr*) &mSymbols.fDeleteBuffers, { "DeleteBuffers", "DeleteBuffersARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteTextures, { "DeleteTextures", "DeleteTexturesARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteProgram, { "DeleteProgram", "DeleteProgramARB", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteShader, { "DeleteShader", "DeleteShaderARB", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDeleteBuffers, {{ "glDeleteBuffers", "glDeleteBuffersARB" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteTextures, {{ "glDeleteTextures", "glDeleteTexturesARB" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteProgram, {{ "glDeleteProgram", "glDeleteProgramARB" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteShader, {{ "glDeleteShader", "glDeleteShaderARB" }} }, END_SYMBOLS }; // clang-format on - if (!LoadGLSymbols(this, prefix, trygl, coreSymbols, "GL")) return false; + if (!fnLoadSymbols(coreSymbols, "GL")) return false; { const SymLoadStruct symbols[] = { {(PRFuncPtr*)&mSymbols.fGetGraphicsResetStatus, - {"GetGraphicsResetStatus", "GetGraphicsResetStatusARB", - "GetGraphicsResetStatusKHR", "GetGraphicsResetStatusEXT", nullptr}}, + {{"glGetGraphicsResetStatus", "glGetGraphicsResetStatusARB", + "glGetGraphicsResetStatusKHR", "glGetGraphicsResetStatusEXT"}}}, END_SYMBOLS}; - (void)LoadGLSymbols(this, prefix, trygl, symbols, nullptr); + (void)fnLoadSymbols(symbols, nullptr); auto err = fGetError(); if (err == LOCAL_GL_CONTEXT_LOST) { @@ -572,7 +572,7 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { CORE_SYMBOL(ClearDepthf), CORE_SYMBOL(DepthRangef), END_SYMBOLS}; - if (!LoadGLSymbols(this, prefix, trygl, symbols, "OpenGL ES")) return false; + if (!fnLoadSymbols(symbols, "OpenGL ES")) return false; } else { const SymLoadStruct symbols[] = { CORE_SYMBOL(ClearDepth), CORE_SYMBOL(DepthRange), @@ -588,8 +588,7 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { CORE_SYMBOL(TexGenf), CORE_SYMBOL(TexGenfv), CORE_SYMBOL(VertexPointer), END_SYMBOLS}; - if (!LoadGLSymbols(this, prefix, trygl, symbols, "Desktop OpenGL")) - return false; + if (!fnLoadSymbols(symbols, "Desktop OpenGL")) return false; } //////////////// @@ -654,10 +653,9 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { if (mVersion >= 300) { // Both GL3 and ES3. const SymLoadStruct symbols[] = { - {(PRFuncPtr*)&mSymbols.fGetStringi, {"GetStringi", nullptr}}, - END_SYMBOLS}; + {(PRFuncPtr*)&mSymbols.fGetStringi, {{"glGetStringi"}}}, END_SYMBOLS}; - if (!LoadGLSymbols(this, prefix, trygl, symbols, "GetStringi")) { + if (!fnLoadSymbols(symbols, "GetStringi")) { MOZ_RELEASE_ASSERT(false, "GFX: GetStringi is required!"); return false; } @@ -732,9 +730,9 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { //////////////////////////////////////////////////////////////////////////// - const auto fnLoadForFeature = [this, prefix, trygl](const SymLoadStruct* list, - GLFeature feature) { - return this->LoadFeatureSymbols(prefix, trygl, list, feature); + const auto fnLoadForFeature = [&](const SymLoadStruct* list, + GLFeature feature) { + return this->LoadFeatureSymbols(*loader, list, feature); }; // Check for ARB_framebuffer_objects @@ -803,7 +801,7 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { IsExtensionSupported(GLContext::NV_geometry_program4)) { const SymLoadStruct symbols[] = { EXT_SYMBOL2(FramebufferTextureLayer, ARB, EXT), END_SYMBOLS}; - if (!LoadGLSymbols(this, prefix, trygl, symbols, + if (!fnLoadSymbols(symbols, "ARB_geometry_shader4/NV_geometry_program4")) { MarkExtensionUnsupported(GLContext::ARB_geometry_shader4); MarkExtensionUnsupported(GLContext::NV_geometry_program4); @@ -825,7 +823,7 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { MOZ_RELEASE_ASSERT(!IsBadCallError(err)); if (err) return false; - LoadMoreSymbols(prefix, trygl); + LoadMoreSymbols(*loader); //////////////////////////////////////////////////////////////////////////// @@ -936,19 +934,17 @@ bool GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) { return true; } -void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { - const auto fnLoadForExt = [this, prefix, trygl](const SymLoadStruct* list, - GLExtensions ext) { - return this->LoadExtSymbols(prefix, trygl, list, ext); +void GLContext::LoadMoreSymbols(const SymbolLoader& loader) { + const auto fnLoadForExt = [&](const SymLoadStruct* list, GLExtensions ext) { + return this->LoadExtSymbols(loader, list, ext); }; - const auto fnLoadForFeature = [this, prefix, trygl](const SymLoadStruct* list, - GLFeature feature) { - return this->LoadFeatureSymbols(prefix, trygl, list, feature); + const auto fnLoadForFeature = [&](const SymLoadStruct* list, + GLFeature feature) { + return this->LoadFeatureSymbols(loader, list, feature); }; - const auto fnLoadFeatureByCore = [this, fnLoadForFeature]( - const SymLoadStruct* coreList, + const auto fnLoadFeatureByCore = [&](const SymLoadStruct* coreList, const SymLoadStruct* extList, GLFeature feature) { const bool useCore = this->IsFeatureProvidedByCoreSymbols(feature); @@ -985,9 +981,9 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsExtensionSupported(OES_EGL_image)) { const SymLoadStruct symbols[] = { {(PRFuncPtr*)&mSymbols.fEGLImageTargetTexture2D, - {"EGLImageTargetTexture2DOES", nullptr}}, + {{"glEGLImageTargetTexture2DOES"}}}, {(PRFuncPtr*)&mSymbols.fEGLImageTargetRenderbufferStorage, - {"EGLImageTargetRenderbufferStorageOES", nullptr}}, + {{"glEGLImageTargetRenderbufferStorageOES"}}}, END_SYMBOLS}; fnLoadForExt(symbols, OES_EGL_image); } @@ -1008,17 +1004,17 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::vertex_array_object)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fIsVertexArray, { "IsVertexArray", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenVertexArrays, { "GenVertexArrays", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindVertexArray, { "BindVertexArray", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, { "DeleteVertexArrays", nullptr } }, + { (PRFuncPtr*) &mSymbols.fIsVertexArray, {{ "glIsVertexArray" }} }, + { (PRFuncPtr*) &mSymbols.fGenVertexArrays, {{ "glGenVertexArrays" }} }, + { (PRFuncPtr*) &mSymbols.fBindVertexArray, {{ "glBindVertexArray" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, {{ "glDeleteVertexArrays" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fIsVertexArray, { "IsVertexArrayARB", "IsVertexArrayOES", "IsVertexArrayAPPLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenVertexArrays, { "GenVertexArraysARB", "GenVertexArraysOES", "GenVertexArraysAPPLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindVertexArray, { "BindVertexArrayARB", "BindVertexArrayOES", "BindVertexArrayAPPLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, { "DeleteVertexArraysARB", "DeleteVertexArraysOES", "DeleteVertexArraysAPPLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fIsVertexArray, {{ "glIsVertexArrayARB", "glIsVertexArrayOES", "glIsVertexArrayAPPLE" }} }, + { (PRFuncPtr*) &mSymbols.fGenVertexArrays, {{ "glGenVertexArraysARB", "glGenVertexArraysOES", "glGenVertexArraysAPPLE" }} }, + { (PRFuncPtr*) &mSymbols.fBindVertexArray, {{ "glBindVertexArrayARB", "glBindVertexArrayOES", "glBindVertexArrayAPPLE" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, {{ "glDeleteVertexArraysARB", "glDeleteVertexArraysOES", "glDeleteVertexArraysAPPLE" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::vertex_array_object); @@ -1026,13 +1022,13 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::draw_instanced)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawArraysInstanced, { "DrawArraysInstanced", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDrawElementsInstanced, { "DrawElementsInstanced", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDrawArraysInstanced, {{ "glDrawArraysInstanced" }} }, + { (PRFuncPtr*) &mSymbols.fDrawElementsInstanced, {{ "glDrawElementsInstanced" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawArraysInstanced, { "DrawArraysInstancedARB", "DrawArraysInstancedEXT", "DrawArraysInstancedNV", "DrawArraysInstancedANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDrawElementsInstanced, { "DrawElementsInstancedARB", "DrawElementsInstancedEXT", "DrawElementsInstancedNV", "DrawElementsInstancedANGLE", nullptr } + { (PRFuncPtr*) &mSymbols.fDrawArraysInstanced, {{ "glDrawArraysInstancedARB", "glDrawArraysInstancedEXT", "glDrawArraysInstancedNV", "glDrawArraysInstancedANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fDrawElementsInstanced, {{ "glDrawElementsInstancedARB", "glDrawElementsInstancedEXT", "glDrawElementsInstancedNV", "glDrawElementsInstancedANGLE" }} }, END_SYMBOLS }; @@ -1041,11 +1037,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::instanced_arrays)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fVertexAttribDivisor, { "VertexAttribDivisor", nullptr } }, + { (PRFuncPtr*) &mSymbols.fVertexAttribDivisor, {{ "glVertexAttribDivisor" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fVertexAttribDivisor, { "VertexAttribDivisorARB", "VertexAttribDivisorNV", "VertexAttribDivisorANGLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fVertexAttribDivisor, {{ "glVertexAttribDivisorARB", "glVertexAttribDivisorNV", "glVertexAttribDivisorANGLE" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::instanced_arrays); @@ -1053,13 +1049,13 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::texture_storage)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fTexStorage2D, { "TexStorage2D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexStorage3D, { "TexStorage3D", nullptr } }, + { (PRFuncPtr*) &mSymbols.fTexStorage2D, {{ "glTexStorage2D" }} }, + { (PRFuncPtr*) &mSymbols.fTexStorage3D, {{ "glTexStorage3D" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fTexStorage2D, { "TexStorage2DEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexStorage3D, { "TexStorage3DEXT", nullptr } }, + { (PRFuncPtr*) &mSymbols.fTexStorage2D, {{ "glTexStorage2DEXT" }} }, + { (PRFuncPtr*) &mSymbols.fTexStorage3D, {{ "glTexStorage3DEXT" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::texture_storage); @@ -1067,16 +1063,16 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::sampler_objects)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fGenSamplers, { "GenSamplers", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteSamplers, { "DeleteSamplers", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsSampler, { "IsSampler", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindSampler, { "BindSampler", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSamplerParameteri, { "SamplerParameteri", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSamplerParameteriv, { "SamplerParameteriv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSamplerParameterf, { "SamplerParameterf", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSamplerParameterfv, { "SamplerParameterfv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetSamplerParameteriv, { "GetSamplerParameteriv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetSamplerParameterfv, { "GetSamplerParameterfv", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGenSamplers, {{ "glGenSamplers" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteSamplers, {{ "glDeleteSamplers" }} }, + { (PRFuncPtr*) &mSymbols.fIsSampler, {{ "glIsSampler" }} }, + { (PRFuncPtr*) &mSymbols.fBindSampler, {{ "glBindSampler" }} }, + { (PRFuncPtr*) &mSymbols.fSamplerParameteri, {{ "glSamplerParameteri" }} }, + { (PRFuncPtr*) &mSymbols.fSamplerParameteriv, {{ "glSamplerParameteriv" }} }, + { (PRFuncPtr*) &mSymbols.fSamplerParameterf, {{ "glSamplerParameterf" }} }, + { (PRFuncPtr*) &mSymbols.fSamplerParameterfv, {{ "glSamplerParameterfv" }} }, + { (PRFuncPtr*) &mSymbols.fGetSamplerParameteriv, {{ "glGetSamplerParameteriv" }} }, + { (PRFuncPtr*) &mSymbols.fGetSamplerParameterfv, {{ "glGetSamplerParameterfv" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::sampler_objects); @@ -1088,33 +1084,33 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { // glResumeTransformFeedback, which are required for WebGL2. if (IsSupported(GLFeature::transform_feedback2)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fBindBufferBase, { "BindBufferBase", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindBufferRange, { "BindBufferRange", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenTransformFeedbacks, { "GenTransformFeedbacks", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindTransformFeedback, { "BindTransformFeedback", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteTransformFeedbacks, { "DeleteTransformFeedbacks", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsTransformFeedback, { "IsTransformFeedback", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBeginTransformFeedback, { "BeginTransformFeedback", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEndTransformFeedback, { "EndTransformFeedback", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTransformFeedbackVaryings, { "TransformFeedbackVaryings", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetTransformFeedbackVarying, { "GetTransformFeedbackVarying", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPauseTransformFeedback, { "PauseTransformFeedback", nullptr } }, - { (PRFuncPtr*) &mSymbols.fResumeTransformFeedback, { "ResumeTransformFeedback", nullptr } }, + { (PRFuncPtr*) &mSymbols.fBindBufferBase, {{ "glBindBufferBase" }} }, + { (PRFuncPtr*) &mSymbols.fBindBufferRange, {{ "glBindBufferRange" }} }, + { (PRFuncPtr*) &mSymbols.fGenTransformFeedbacks, {{ "glGenTransformFeedbacks" }} }, + { (PRFuncPtr*) &mSymbols.fBindTransformFeedback, {{ "glBindTransformFeedback" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteTransformFeedbacks, {{ "glDeleteTransformFeedbacks" }} }, + { (PRFuncPtr*) &mSymbols.fIsTransformFeedback, {{ "glIsTransformFeedback" }} }, + { (PRFuncPtr*) &mSymbols.fBeginTransformFeedback, {{ "glBeginTransformFeedback" }} }, + { (PRFuncPtr*) &mSymbols.fEndTransformFeedback, {{ "glEndTransformFeedback" }} }, + { (PRFuncPtr*) &mSymbols.fTransformFeedbackVaryings, {{ "glTransformFeedbackVaryings" }} }, + { (PRFuncPtr*) &mSymbols.fGetTransformFeedbackVarying, {{ "glGetTransformFeedbackVarying" }} }, + { (PRFuncPtr*) &mSymbols.fPauseTransformFeedback, {{ "glPauseTransformFeedback" }} }, + { (PRFuncPtr*) &mSymbols.fResumeTransformFeedback, {{ "glResumeTransformFeedback" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fBindBufferBase, { "BindBufferBaseEXT", "BindBufferBaseNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindBufferRange, { "BindBufferRangeEXT", "BindBufferRangeNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenTransformFeedbacks, { "GenTransformFeedbacksNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBindTransformFeedback, { "BindTransformFeedbackNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteTransformFeedbacks, { "DeleteTransformFeedbacksNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsTransformFeedback, { "IsTransformFeedbackNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fBeginTransformFeedback, { "BeginTransformFeedbackEXT", "BeginTransformFeedbackNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEndTransformFeedback, { "EndTransformFeedbackEXT", "EndTransformFeedbackNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTransformFeedbackVaryings, { "TransformFeedbackVaryingsEXT", "TransformFeedbackVaryingsNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetTransformFeedbackVarying, { "GetTransformFeedbackVaryingEXT", "GetTransformFeedbackVaryingNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPauseTransformFeedback, { "PauseTransformFeedbackNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fResumeTransformFeedback, { "ResumeTransformFeedbackNV", nullptr } }, + { (PRFuncPtr*) &mSymbols.fBindBufferBase, {{ "glBindBufferBaseEXT", "glBindBufferBaseNV" }} }, + { (PRFuncPtr*) &mSymbols.fBindBufferRange, {{ "glBindBufferRangeEXT", "glBindBufferRangeNV" }} }, + { (PRFuncPtr*) &mSymbols.fGenTransformFeedbacks, {{ "glGenTransformFeedbacksNV" }} }, + { (PRFuncPtr*) &mSymbols.fBindTransformFeedback, {{ "glBindTransformFeedbackNV" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteTransformFeedbacks, {{ "glDeleteTransformFeedbacksNV" }} }, + { (PRFuncPtr*) &mSymbols.fIsTransformFeedback, {{ "glIsTransformFeedbackNV" }} }, + { (PRFuncPtr*) &mSymbols.fBeginTransformFeedback, {{ "glBeginTransformFeedbackEXT", "glBeginTransformFeedbackNV" }} }, + { (PRFuncPtr*) &mSymbols.fEndTransformFeedback, {{ "glEndTransformFeedbackEXT", "glEndTransformFeedbackNV" }} }, + { (PRFuncPtr*) &mSymbols.fTransformFeedbackVaryings, {{ "glTransformFeedbackVaryingsEXT", "glTransformFeedbackVaryingsNV" }} }, + { (PRFuncPtr*) &mSymbols.fGetTransformFeedbackVarying, {{ "glGetTransformFeedbackVaryingEXT", "glGetTransformFeedbackVaryingNV" }} }, + { (PRFuncPtr*) &mSymbols.fPauseTransformFeedback, {{ "glPauseTransformFeedbackNV" }} }, + { (PRFuncPtr*) &mSymbols.fResumeTransformFeedback, {{ "glResumeTransformFeedbackNV" }} }, END_SYMBOLS }; if (!fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::texture_storage)) { @@ -1125,12 +1121,12 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::bind_buffer_offset)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fBindBufferOffset, { "BindBufferOffset", nullptr } }, + { (PRFuncPtr*) &mSymbols.fBindBufferOffset, {{ "glBindBufferOffset" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { { (PRFuncPtr*) &mSymbols.fBindBufferOffset, - { "BindBufferOffsetEXT", "BindBufferOffsetNV", nullptr } + {{ "glBindBufferOffsetEXT", "glBindBufferOffsetNV" }} }, END_SYMBOLS }; @@ -1139,11 +1135,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::query_counter)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fQueryCounter, { "QueryCounter", nullptr } }, + { (PRFuncPtr*) &mSymbols.fQueryCounter, {{ "glQueryCounter" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fQueryCounter, { "QueryCounterEXT", "QueryCounterANGLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fQueryCounter, {{ "glQueryCounterEXT", "glQueryCounterANGLE" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::query_counter); @@ -1151,23 +1147,23 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::query_objects)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fBeginQuery, { "BeginQuery", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenQueries, { "GenQueries", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteQueries, { "DeleteQueries", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEndQuery, { "EndQuery", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryiv, { "GetQueryiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryObjectuiv, { "GetQueryObjectuiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsQuery, { "IsQuery", nullptr } }, + { (PRFuncPtr*) &mSymbols.fBeginQuery, {{ "glBeginQuery" }} }, + { (PRFuncPtr*) &mSymbols.fGenQueries, {{ "glGenQueries" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteQueries, {{ "glDeleteQueries" }} }, + { (PRFuncPtr*) &mSymbols.fEndQuery, {{ "glEndQuery" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryiv, {{ "glGetQueryiv" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectuiv, {{ "glGetQueryObjectuiv" }} }, + { (PRFuncPtr*) &mSymbols.fIsQuery, {{ "glIsQuery" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fBeginQuery, { "BeginQueryEXT", "BeginQueryANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGenQueries, { "GenQueriesEXT", "GenQueriesANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteQueries, { "DeleteQueriesEXT", "DeleteQueriesANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fEndQuery, { "EndQueryEXT", "EndQueryANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryiv, { "GetQueryivEXT", "GetQueryivANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryObjectuiv, { "GetQueryObjectuivEXT", "GetQueryObjectuivANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsQuery, { "IsQueryEXT", "IsQueryANGLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fBeginQuery, {{ "glBeginQueryEXT", "glBeginQueryANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fGenQueries, {{ "glGenQueriesEXT", "glGenQueriesANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteQueries, {{ "glDeleteQueriesEXT", "glDeleteQueriesANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fEndQuery, {{ "glEndQueryEXT", "glEndQueryANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryiv, {{ "glGetQueryivEXT", "glGetQueryivANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectuiv, {{ "glGetQueryObjectuivEXT", "glGetQueryObjectuivANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fIsQuery, {{ "glIsQueryEXT", "glIsQueryANGLE" }} }, END_SYMBOLS }; if (!fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::query_objects)) { @@ -1181,13 +1177,13 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::get_query_object_i64v)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fGetQueryObjecti64v, { "GetQueryObjecti64v", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryObjectui64v, { "GetQueryObjectui64v", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjecti64v, {{ "glGetQueryObjecti64v" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectui64v, {{ "glGetQueryObjectui64v" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fGetQueryObjecti64v, { "GetQueryObjecti64vEXT", "GetQueryObjecti64vANGLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetQueryObjectui64v, { "GetQueryObjectui64vEXT", "GetQueryObjectui64vANGLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjecti64v, {{ "glGetQueryObjecti64vEXT", "glGetQueryObjecti64vANGLE" }} }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectui64v, {{ "glGetQueryObjectui64vEXT", "glGetQueryObjectui64vANGLE" }} }, END_SYMBOLS }; if (!fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::get_query_object_i64v)) { @@ -1197,11 +1193,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::get_query_object_iv)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fGetQueryObjectiv, { "GetQueryObjectiv", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectiv, {{ "glGetQueryObjectiv" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fGetQueryObjectiv, { "GetQueryObjectivEXT", "GetQueryObjectivANGLE", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetQueryObjectiv, {{ "glGetQueryObjectivEXT", "glGetQueryObjectivANGLE" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::get_query_object_iv); @@ -1209,10 +1205,10 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::clear_buffers)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fClearBufferfi, { "ClearBufferfi", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClearBufferfv, { "ClearBufferfv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClearBufferiv, { "ClearBufferiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fClearBufferuiv, { "ClearBufferuiv", nullptr } }, + { (PRFuncPtr*) &mSymbols.fClearBufferfi, {{ "glClearBufferfi", }} }, + { (PRFuncPtr*) &mSymbols.fClearBufferfv, {{ "glClearBufferfv", }} }, + { (PRFuncPtr*) &mSymbols.fClearBufferiv, {{ "glClearBufferiv", }} }, + { (PRFuncPtr*) &mSymbols.fClearBufferuiv, {{ "glClearBufferuiv" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::clear_buffers); @@ -1220,7 +1216,7 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::copy_buffer)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fCopyBufferSubData, { "CopyBufferSubData", nullptr } }, + { (PRFuncPtr*) &mSymbols.fCopyBufferSubData, {{ "glCopyBufferSubData" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::copy_buffer); @@ -1228,11 +1224,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::draw_buffers)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawBuffers, { "DrawBuffers", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDrawBuffers, {{ "glDrawBuffers" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawBuffers, { "DrawBuffersARB", "DrawBuffersEXT", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDrawBuffers, {{ "glDrawBuffersARB", "glDrawBuffersEXT" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::draw_buffers); @@ -1240,11 +1236,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::draw_range_elements)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawRangeElements, { "DrawRangeElements", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDrawRangeElements, {{ "glDrawRangeElements" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fDrawRangeElements, { "DrawRangeElementsEXT", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDrawRangeElements, {{ "glDrawRangeElementsEXT" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::draw_range_elements); @@ -1252,11 +1248,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::get_integer_indexed)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fGetIntegeri_v, { "GetIntegeri_v", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetIntegeri_v, {{ "glGetIntegeri_v" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] ={ - { (PRFuncPtr*) &mSymbols.fGetIntegeri_v, { "GetIntegerIndexedvEXT", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetIntegeri_v, {{ "glGetIntegerIndexedvEXT" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::get_integer_indexed); @@ -1264,7 +1260,7 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::get_integer64_indexed)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fGetInteger64i_v, { "GetInteger64i_v", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetInteger64i_v, {{ "glGetInteger64i_v" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::get_integer64_indexed); @@ -1272,23 +1268,23 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::gpu_shader4)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fGetVertexAttribIiv, { "GetVertexAttribIiv", "GetVertexAttribIivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetVertexAttribIuiv, { "GetVertexAttribIuiv", "GetVertexAttribIuivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribI4i, { "VertexAttribI4i", "VertexAttribI4iEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribI4iv, { "VertexAttribI4iv","VertexAttribI4ivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribI4ui, { "VertexAttribI4ui", "VertexAttribI4uiEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribI4uiv, { "VertexAttribI4uiv", "VertexAttribI4uivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fVertexAttribIPointer, { "VertexAttribIPointer", "VertexAttribIPointerEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1ui, { "Uniform1ui", "Uniform1uiEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2ui, { "Uniform2ui", "Uniform2uiEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3ui, { "Uniform3ui", "Uniform3uiEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4ui, { "Uniform4ui", "Uniform4uiEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform1uiv, { "Uniform1uiv", "Uniform1uivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform2uiv, { "Uniform2uiv", "Uniform2uivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform3uiv, { "Uniform3uiv", "Uniform3uivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniform4uiv, { "Uniform4uiv", "Uniform4uivEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetFragDataLocation, { "GetFragDataLocation", "GetFragDataLocationEXT", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetUniformuiv, { "GetUniformuiv", "GetUniformuivEXT", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetVertexAttribIiv, {{ "glGetVertexAttribIiv", "glGetVertexAttribIivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fGetVertexAttribIuiv, {{ "glGetVertexAttribIuiv", "glGetVertexAttribIuivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribI4i, {{ "glVertexAttribI4i", "glVertexAttribI4iEXT" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribI4iv, {{ "glVertexAttribI4iv", "glVertexAttribI4ivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribI4ui, {{ "glVertexAttribI4ui", "glVertexAttribI4uiEXT" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribI4uiv, {{ "glVertexAttribI4uiv", "glVertexAttribI4uivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fVertexAttribIPointer, {{ "glVertexAttribIPointer", "glVertexAttribIPointerEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1ui, {{ "glUniform1ui", "glUniform1uiEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2ui, {{ "glUniform2ui", "glUniform2uiEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3ui, {{ "glUniform3ui", "glUniform3uiEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4ui, {{ "glUniform4ui", "glUniform4uiEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform1uiv, {{ "glUniform1uiv", "glUniform1uivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform2uiv, {{ "glUniform2uiv", "glUniform2uivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform3uiv, {{ "glUniform3uiv", "glUniform3uivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fUniform4uiv, {{ "glUniform4uiv", "glUniform4uivEXT" }} }, + { (PRFuncPtr*) &mSymbols.fGetFragDataLocation, {{ "glGetFragDataLocation", "glGetFragDataLocationEXT" }} }, + { (PRFuncPtr*) &mSymbols.fGetUniformuiv, {{ "glGetUniformuiv", "glGetUniformuivEXT" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::gpu_shader4); @@ -1296,9 +1292,9 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::map_buffer_range)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fMapBufferRange, { "MapBufferRange", nullptr } }, - { (PRFuncPtr*) &mSymbols.fFlushMappedBufferRange, { "FlushMappedBufferRange", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUnmapBuffer, { "UnmapBuffer", nullptr } }, + { (PRFuncPtr*) &mSymbols.fMapBufferRange, {{ "glMapBufferRange" }} }, + { (PRFuncPtr*) &mSymbols.fFlushMappedBufferRange, {{ "glFlushMappedBufferRange" }} }, + { (PRFuncPtr*) &mSymbols.fUnmapBuffer, {{ "glUnmapBuffer" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::map_buffer_range); @@ -1306,12 +1302,12 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::texture_3D)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fTexImage3D, { "TexImage3D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTexSubImage3D, { "TexSubImage3D", nullptr } }, + { (PRFuncPtr*) &mSymbols.fTexImage3D, {{ "glTexImage3D" }} }, + { (PRFuncPtr*) &mSymbols.fTexSubImage3D, {{ "glTexSubImage3D" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fTexSubImage3D, { "TexSubImage3DEXT", "TexSubImage3DOES", nullptr } }, + { (PRFuncPtr*) &mSymbols.fTexSubImage3D, {{ "glTexSubImage3DEXT", "glTexSubImage3DOES" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::texture_3D); @@ -1319,13 +1315,13 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::texture_3D_compressed)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fCompressedTexImage3D, { "CompressedTexImage3D", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage3D, { "CompressedTexSubImage3D", nullptr } }, + { (PRFuncPtr*) &mSymbols.fCompressedTexImage3D, {{ "glCompressedTexImage3D" }} }, + { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage3D, {{ "glCompressedTexSubImage3D" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fCompressedTexImage3D, { "CompressedTexImage3DARB", "CompressedTexImage3DOES", nullptr } }, - { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage3D, { "CompressedTexSubImage3DARB", "CompressedTexSubImage3DOES", nullptr } }, + { (PRFuncPtr*) &mSymbols.fCompressedTexImage3D, {{ "glCompressedTexImage3DARB", "glCompressedTexImage3DOES" }} }, + { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage3D, {{ "glCompressedTexSubImage3DARB", "glCompressedTexSubImage3DOES" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::texture_3D_compressed); @@ -1333,11 +1329,11 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::texture_3D_copy)) { const SymLoadStruct coreSymbols[] = { - { (PRFuncPtr*) &mSymbols.fCopyTexSubImage3D, { "CopyTexSubImage3D", nullptr } }, + { (PRFuncPtr*) &mSymbols.fCopyTexSubImage3D, {{ "glCopyTexSubImage3D" }} }, END_SYMBOLS }; const SymLoadStruct extSymbols[] = { - { (PRFuncPtr*) &mSymbols.fCopyTexSubImage3D, { "CopyTexSubImage3DEXT", "CopyTexSubImage3DOES", nullptr } }, + { (PRFuncPtr*) &mSymbols.fCopyTexSubImage3D, {{ "glCopyTexSubImage3DEXT", "glCopyTexSubImage3DOES" }} }, END_SYMBOLS }; fnLoadFeatureByCore(coreSymbols, extSymbols, GLFeature::texture_3D_copy); @@ -1347,12 +1343,12 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { // Note: Don't query for glGetActiveUniformName because it is not // supported by GL ES 3. const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fGetUniformIndices, { "GetUniformIndices", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetActiveUniformsiv, { "GetActiveUniformsiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetUniformBlockIndex, { "GetUniformBlockIndex", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetActiveUniformBlockiv, { "GetActiveUniformBlockiv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetActiveUniformBlockName, { "GetActiveUniformBlockName", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformBlockBinding, { "UniformBlockBinding", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGetUniformIndices, {{ "glGetUniformIndices" }} }, + { (PRFuncPtr*) &mSymbols.fGetActiveUniformsiv, {{ "glGetActiveUniformsiv" }} }, + { (PRFuncPtr*) &mSymbols.fGetUniformBlockIndex, {{ "glGetUniformBlockIndex" }} }, + { (PRFuncPtr*) &mSymbols.fGetActiveUniformBlockiv, {{ "glGetActiveUniformBlockiv" }} }, + { (PRFuncPtr*) &mSymbols.fGetActiveUniformBlockName, {{ "glGetActiveUniformBlockName" }} }, + { (PRFuncPtr*) &mSymbols.fUniformBlockBinding, {{ "glUniformBlockBinding" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::uniform_buffer_object); @@ -1360,12 +1356,12 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::uniform_matrix_nonsquare)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fUniformMatrix2x3fv, { "UniformMatrix2x3fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix2x4fv, { "UniformMatrix2x4fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix3x2fv, { "UniformMatrix3x2fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix3x4fv, { "UniformMatrix3x4fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix4x2fv, { "UniformMatrix4x2fv", nullptr } }, - { (PRFuncPtr*) &mSymbols.fUniformMatrix4x3fv, { "UniformMatrix4x3fv", nullptr } }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix2x3fv, {{ "glUniformMatrix2x3fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix2x4fv, {{ "glUniformMatrix2x4fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix3x2fv, {{ "glUniformMatrix3x2fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix3x4fv, {{ "glUniformMatrix3x4fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix4x2fv, {{ "glUniformMatrix4x2fv" }} }, + { (PRFuncPtr*) &mSymbols.fUniformMatrix4x3fv, {{ "glUniformMatrix4x3fv" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::uniform_matrix_nonsquare); @@ -1381,8 +1377,8 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::invalidate_framebuffer)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fInvalidateFramebuffer, { "InvalidateFramebuffer", nullptr } }, - { (PRFuncPtr*) &mSymbols.fInvalidateSubFramebuffer, { "InvalidateSubFramebuffer", nullptr } }, + { (PRFuncPtr*) &mSymbols.fInvalidateFramebuffer, {{ "glInvalidateFramebuffer" }} }, + { (PRFuncPtr*) &mSymbols.fInvalidateSubFramebuffer, {{ "glInvalidateSubFramebuffer" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::invalidate_framebuffer); @@ -1390,7 +1386,7 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsSupported(GLFeature::prim_restart)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fPrimitiveRestartIndex, { "PrimitiveRestartIndex", "PrimitiveRestartIndexNV", nullptr } }, + { (PRFuncPtr*) &mSymbols.fPrimitiveRestartIndex, {{ "glPrimitiveRestartIndex", "glPrimitiveRestartIndexNV" }} }, END_SYMBOLS }; fnLoadForFeature(symbols, GLFeature::prim_restart); @@ -1398,17 +1394,17 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsExtensionSupported(KHR_debug)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fDebugMessageControl, { "DebugMessageControl", "DebugMessageControlKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDebugMessageInsert, { "DebugMessageInsert", "DebugMessageInsertKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDebugMessageCallback, { "DebugMessageCallback", "DebugMessageCallbackKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetDebugMessageLog, { "GetDebugMessageLog", "GetDebugMessageLogKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetPointerv, { "GetPointerv", "GetPointervKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPushDebugGroup, { "PushDebugGroup", "PushDebugGroupKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fPopDebugGroup, { "PopDebugGroup", "PopDebugGroupKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fObjectLabel, { "ObjectLabel", "ObjectLabelKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetObjectLabel, { "GetObjectLabel", "GetObjectLabelKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fObjectPtrLabel, { "ObjectPtrLabel", "ObjectPtrLabelKHR", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetObjectPtrLabel, { "GetObjectPtrLabel", "GetObjectPtrLabelKHR", nullptr } }, + { (PRFuncPtr*) &mSymbols.fDebugMessageControl, {{ "glDebugMessageControl", "glDebugMessageControlKHR", }} }, + { (PRFuncPtr*) &mSymbols.fDebugMessageInsert, {{ "glDebugMessageInsert", "glDebugMessageInsertKHR", }} }, + { (PRFuncPtr*) &mSymbols.fDebugMessageCallback, {{ "glDebugMessageCallback", "glDebugMessageCallbackKHR" }} }, + { (PRFuncPtr*) &mSymbols.fGetDebugMessageLog, {{ "glGetDebugMessageLog", "glGetDebugMessageLogKHR", }} }, + { (PRFuncPtr*) &mSymbols.fGetPointerv, {{ "glGetPointerv", "glGetPointervKHR", }} }, + { (PRFuncPtr*) &mSymbols.fPushDebugGroup, {{ "glPushDebugGroup", "glPushDebugGroupKHR", }} }, + { (PRFuncPtr*) &mSymbols.fPopDebugGroup, {{ "glPopDebugGroup", "glPopDebugGroupKHR", }} }, + { (PRFuncPtr*) &mSymbols.fObjectLabel, {{ "glObjectLabel", "glObjectLabelKHR", }} }, + { (PRFuncPtr*) &mSymbols.fGetObjectLabel, {{ "glGetObjectLabel", "glGetObjectLabelKHR", }} }, + { (PRFuncPtr*) &mSymbols.fObjectPtrLabel, {{ "glObjectPtrLabel", "glObjectPtrLabelKHR", }} }, + { (PRFuncPtr*) &mSymbols.fGetObjectPtrLabel, {{ "glGetObjectPtrLabel", "glGetObjectPtrLabelKHR", }} }, END_SYMBOLS }; fnLoadForExt(symbols, KHR_debug); @@ -1416,13 +1412,13 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsExtensionSupported(NV_fence)) { const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fGenFences, { "GenFencesNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fDeleteFences, { "DeleteFencesNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fSetFence, { "SetFenceNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTestFence, { "TestFenceNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fFinishFence, { "FinishFenceNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fIsFence, { "IsFenceNV", nullptr } }, - { (PRFuncPtr*) &mSymbols.fGetFenceiv, { "GetFenceivNV", nullptr } }, + { (PRFuncPtr*) &mSymbols.fGenFences, {{ "glGenFencesNV" }} }, + { (PRFuncPtr*) &mSymbols.fDeleteFences, {{ "glDeleteFencesNV" }} }, + { (PRFuncPtr*) &mSymbols.fSetFence, {{ "glSetFenceNV" }} }, + { (PRFuncPtr*) &mSymbols.fTestFence, {{ "glTestFenceNV" }} }, + { (PRFuncPtr*) &mSymbols.fFinishFence, {{ "glFinishFenceNV" }} }, + { (PRFuncPtr*) &mSymbols.fIsFence, {{ "glIsFenceNV" }} }, + { (PRFuncPtr*) &mSymbols.fGetFenceiv, {{ "glGetFenceivNV" }} }, END_SYMBOLS }; fnLoadForExt(symbols, NV_fence); @@ -1432,7 +1428,7 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { if (IsExtensionSupported(NV_texture_barrier)) { const SymLoadStruct symbols[] = { - {(PRFuncPtr*)&mSymbols.fTextureBarrier, {"TextureBarrierNV", nullptr}}, + {(PRFuncPtr*)&mSymbols.fTextureBarrier, {{"glTextureBarrierNV"}}}, END_SYMBOLS}; fnLoadForExt(symbols, NV_texture_barrier); } @@ -1453,7 +1449,7 @@ void GLContext::LoadMoreSymbols(const char* prefix, bool trygl) { CORE_SYMBOL(GetTexLevelParameteriv), END_SYMBOLS}; const bool warnOnFailures = ShouldSpew(); - LoadSymbols(devSymbols, trygl, prefix, warnOnFailures); + loader.LoadSymbols(devSymbols, warnOnFailures); } #undef CORE_SYMBOL diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index f26465f357d7..87772c2ebe12 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -191,8 +191,7 @@ enum class GLRenderer { Other }; -class GLContext : public GLLibraryLoader, - public GenericAtomicRefCounted, +class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { public: MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext) @@ -3312,8 +3311,8 @@ class GLContext : public GLLibraryLoader, // ----------------------------------------------------------------------------- // Constructor protected: - explicit GLContext(CreateContextFlags flags, const SurfaceCaps& caps, - GLContext* sharedContext = nullptr, + explicit GLContext(CreateContextFlags flags, + const SurfaceCaps& caps, GLContext* sharedContext = nullptr, bool isOffscreen = false, bool canUseTLSIsCurrent = false); // ----------------------------------------------------------------------------- @@ -3334,10 +3333,6 @@ class GLContext : public GLLibraryLoader, typedef gfx::SurfaceFormat SurfaceFormat; public: - virtual bool Init() = 0; - - virtual bool SetupLookupFunction() = 0; - virtual void ReleaseSurface() {} bool IsDestroyed() const { @@ -3372,6 +3367,8 @@ class GLContext : public GLLibraryLoader, */ virtual bool ReleaseTexImage() { return false; } + virtual Maybe GetSymbolLoader() const = 0; + // Before reads from offscreen texture void GuaranteeResolve(); @@ -3565,16 +3562,14 @@ class GLContext : public GLLibraryLoader, bool IsOffscreenSizeAllowed(const gfx::IntSize& aSize) const; - protected: - bool InitWithPrefix(const char* prefix, bool trygl); + virtual bool Init(); private: - bool InitWithPrefixImpl(const char* prefix, bool trygl); - void LoadMoreSymbols(const char* prefix, bool trygl); - bool LoadExtSymbols(const char* prefix, bool trygl, const SymLoadStruct* list, + bool InitImpl(); + void LoadMoreSymbols(const SymbolLoader& loader); + bool LoadExtSymbols(const SymbolLoader& loader, const SymLoadStruct* list, GLExtensions ext); - bool LoadFeatureSymbols(const char* prefix, bool trygl, - const SymLoadStruct* list, GLFeature feature); + bool LoadFeatureSymbols(const SymbolLoader& loader, const SymLoadStruct* list, GLFeature feature); protected: void InitExtensions(); diff --git a/gfx/gl/GLContextCGL.h b/gfx/gl/GLContextCGL.h index 1f7e09aa17cf..7765c65e0dbf 100644 --- a/gfx/gl/GLContextCGL.h +++ b/gfx/gl/GLContextCGL.h @@ -41,8 +41,6 @@ class GLContextCGL : public GLContext { return static_cast(gl); } - bool Init() override; - NSOpenGLContext* GetNSOpenGLContext() const { return mContext; } CGLContextObj GetCGLContext() const; @@ -52,13 +50,13 @@ class GLContextCGL : public GLContext { virtual GLenum GetPreferredARGB32Format() const override; - virtual bool SetupLookupFunction() override; - virtual bool IsDoubleBuffered() const override; virtual bool SwapBuffers() override; virtual void GetWSIInfo(nsCString* const out) const override; + + Maybe GetSymbolLoader() const override; }; } // namespace gl diff --git a/gfx/gl/GLContextEAGL.h b/gfx/gl/GLContextEAGL.h index 9d2605adbdf3..0270c6bdb8a9 100644 --- a/gfx/gl/GLContextEAGL.h +++ b/gfx/gl/GLContextEAGL.h @@ -37,8 +37,6 @@ class GLContextEAGL : public GLContext { return static_cast(gl); } - bool Init() override; - bool AttachToWindow(nsIWidget* aWidget); EAGLContext* GetEAGLContext() const { return mContext; } @@ -47,7 +45,7 @@ class GLContextEAGL : public GLContext { virtual bool IsCurrentImpl() const override; - virtual bool SetupLookupFunction() override; + Maybe GetSymbolLoader() const override; virtual bool IsDoubleBuffered() const override; diff --git a/gfx/gl/GLContextEGL.h b/gfx/gl/GLContextEGL.h index adb37e59a9f7..92c4ca5cf6b0 100644 --- a/gfx/gl/GLContextEGL.h +++ b/gfx/gl/GLContextEGL.h @@ -67,7 +67,7 @@ class GLContextEGL : public GLContext { virtual void ReleaseSurface() override; - virtual bool SetupLookupFunction() override; + Maybe GetSymbolLoader() const override; virtual bool SwapBuffers() override; diff --git a/gfx/gl/GLContextGLX.h b/gfx/gl/GLContextGLX.h index 2dc6419cbd8c..89b607957468 100644 --- a/gfx/gl/GLContextGLX.h +++ b/gfx/gl/GLContextGLX.h @@ -50,7 +50,7 @@ class GLContextGLX : public GLContext { virtual bool IsCurrentImpl() const override; - virtual bool SetupLookupFunction() override; + Maybe GetSymbolLoader() const override; virtual bool IsDoubleBuffered() const override; diff --git a/gfx/gl/GLContextProviderCGL.mm b/gfx/gl/GLContextProviderCGL.mm index b0203bcc68b1..a7829c73d037 100644 --- a/gfx/gl/GLContextProviderCGL.mm +++ b/gfx/gl/GLContextProviderCGL.mm @@ -56,6 +56,8 @@ class CGLLibrary { return mUseDoubleBufferedWindows; } + const auto& Library() const { return mOGLLibrary; } + private: bool mInitialized = false; bool mUseDoubleBufferedWindows = true; @@ -82,12 +84,6 @@ GLContextCGL::~GLContextCGL() { } } -bool GLContextCGL::Init() { - if (!InitWithPrefix("gl", true)) return false; - - return true; -} - CGLContextObj GLContextCGL::GetCGLContext() const { return static_cast([mContext CGLContextObj]); } @@ -112,8 +108,6 @@ bool GLContextCGL::IsCurrentImpl() const { return [NSOpenGLContext currentContex GLenum GLContextCGL::GetPreferredARGB32Format() const { return LOCAL_GL_BGRA; } -bool GLContextCGL::SetupLookupFunction() { return false; } - bool GLContextCGL::IsDoubleBuffered() const { return sCGLLibrary.UseDoubleBufferedWindows(); } bool GLContextCGL::SwapBuffers() { @@ -125,6 +119,12 @@ bool GLContextCGL::SwapBuffers() { void GLContextCGL::GetWSIInfo(nsCString* const out) const { out->AppendLiteral("CGL"); } +Maybe GLContextCGL::GetSymbolLoader() const +{ + const auto& lib = sCGLLibrary.Library(); + return Some(SymbolLoader(*lib)); +} + already_AddRefed GLContextProviderCGL::CreateWrappingExisting(void*, void*) { return nullptr; } diff --git a/gfx/gl/GLContextProviderEAGL.mm b/gfx/gl/GLContextProviderEAGL.mm index e58542b661d6..d5a6a204ea11 100644 --- a/gfx/gl/GLContextProviderEAGL.mm +++ b/gfx/gl/GLContextProviderEAGL.mm @@ -49,12 +49,6 @@ GLContextEAGL::~GLContextEAGL() { } } -bool GLContextEAGL::Init() { - if (!InitWithPrefix("gl", true)) return false; - - return true; -} - bool GLContextEAGL::AttachToWindow(nsIWidget* aWidget) { // This should only be called once MOZ_ASSERT(!mBackbufferFB && !mBackbufferRB); @@ -106,7 +100,18 @@ bool GLContextEAGL::MakeCurrentImpl() const { bool GLContextEAGL::IsCurrentImpl() const { return [EAGLContext currentContext] == mContext; } -bool GLContextEAGL::SetupLookupFunction() { return false; } +static PRFuncPtr GLAPIENTRY GetLoadedProcAddress(const char* const name) { + PRLibrary* lib = nullptr; + const auto& ret = PR_FindFunctionSymbolAndLibrary(name, &leakedLibRef); + if (lib) { + PR_UnloadLibrary(lib); + } + return ret; +} + +Maybe GLContextEAGL::GetSymbolLoader() const { + return Some(SymbolLoader(&GetLoadedProcAddress)); +} bool GLContextEAGL::IsDoubleBuffered() const { return true; } diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 6114906b8e4e..3f4b47f8255f 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -366,20 +366,7 @@ GLContextEGL::~GLContextEGL() { } bool GLContextEGL::Init() { - mLibrary = LoadApitraceLibrary(); - if (!mLibrary) { - if (!OpenLibrary(GLES2_LIB)) { -#if defined(XP_UNIX) - if (!OpenLibrary(GLES2_LIB2)) { - NS_WARNING("Couldn't load GLES2 LIB."); - return false; - } -#endif - } - } - - SetupLookupFunction(); - if (!InitWithPrefix("gl", true)) return false; + if (!GLContext::Init()) return false; bool current = MakeCurrent(); if (!current) { @@ -499,9 +486,8 @@ void GLContextEGL::ReleaseSurface() { mSurface = EGL_NO_SURFACE; } -bool GLContextEGL::SetupLookupFunction() { - mLookupFunc = mEgl->GetLookupFunction(); - return true; +Maybe GLContextEGL::GetSymbolLoader() const { + return mEgl->GetSymbolLoader(); } bool GLContextEGL::SwapBuffers() { diff --git a/gfx/gl/GLContextProviderGLX.cpp b/gfx/gl/GLContextProviderGLX.cpp index c36b6c5edf68..5e92e628a6a5 100644 --- a/gfx/gl/GLContextProviderGLX.cpp +++ b/gfx/gl/GLContextProviderGLX.cpp @@ -74,20 +74,17 @@ bool GLXLibrary::EnsureInitialized() { PR_SetEnv("force_s3tc_enable=true"); if (!mOGLLibrary) { - const char* libGLfilename = nullptr; - bool forceFeatureReport = false; - // see e.g. bug 608526: it is intrinsically interesting to know whether we // have dynamically linked to libGL.so.1 because at least the NVIDIA // implementation requires an executable stack, which causes mprotect calls, // which trigger glibc bug // http://sourceware.org/bugzilla/show_bug.cgi?id=12225 + const char* libGLfilename = "libGL.so.1"; #ifdef __OpenBSD__ libGLfilename = "libGL.so"; -#else - libGLfilename = "libGL.so.1"; #endif + const bool forceFeatureReport = false; ScopedGfxFeatureReporter reporter(libGLfilename, forceFeatureReport); mOGLLibrary = PR_LoadLibrary(libGLfilename); if (!mOGLLibrary) { @@ -101,16 +98,18 @@ bool GLXLibrary::EnsureInitialized() { mDebug = true; } -#define SYMBOL(X) \ - { \ - (PRFuncPtr*)&mSymbols.f##X, { "glX" #X, nullptr } \ +#define SYMBOL(X) \ + { \ + (PRFuncPtr*)&mSymbols.f##X, { \ + { "glX" #X } \ + } \ } -#define END_OF_SYMBOLS \ - { \ - nullptr, { nullptr } \ +#define END_OF_SYMBOLS \ + { \ + nullptr, {} \ } - const GLLibraryLoader::SymLoadStruct symbols[] = { + const SymLoadStruct symbols[] = { /* functions that were in GLX 1.0 */ SYMBOL(DestroyContext), SYMBOL(MakeCurrent), @@ -137,12 +136,17 @@ bool GLXLibrary::EnsureInitialized() { // Core in GLX 1.4, ARB extension before. {(PRFuncPtr*)&mSymbols.fGetProcAddress, - {"glXGetProcAddress", "glXGetProcAddressARB", nullptr}}, + {{"glXGetProcAddress", "glXGetProcAddressARB"}}}, END_OF_SYMBOLS}; - if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols)) { - NS_WARNING("Couldn't load required GLX symbols."); - return false; + + { + const SymbolLoader libLoader(*mOGLLibrary); + if (!libLoader.LoadSymbols(symbols)) { + NS_WARNING("Couldn't load required GLX symbols."); + return false; + } } + const SymbolLoader pfnLoader(mSymbols.fGetProcAddress); Display* display = DefaultXDisplay(); int screen = DefaultScreen(display); @@ -155,29 +159,24 @@ bool GLXLibrary::EnsureInitialized() { } } - const GLLibraryLoader::SymLoadStruct symbols_texturefrompixmap[] = { + const SymLoadStruct symbols_texturefrompixmap[] = { SYMBOL(BindTexImageEXT), SYMBOL(ReleaseTexImageEXT), END_OF_SYMBOLS}; - const GLLibraryLoader::SymLoadStruct symbols_createcontext[] = { + const SymLoadStruct symbols_createcontext[] = { SYMBOL(CreateContextAttribsARB), END_OF_SYMBOLS}; - const GLLibraryLoader::SymLoadStruct symbols_videosync[] = { + const SymLoadStruct symbols_videosync[] = { SYMBOL(GetVideoSyncSGI), SYMBOL(WaitVideoSyncSGI), END_OF_SYMBOLS}; - const GLLibraryLoader::SymLoadStruct symbols_swapcontrol[] = { - SYMBOL(SwapIntervalEXT), END_OF_SYMBOLS}; + const SymLoadStruct symbols_swapcontrol[] = {SYMBOL(SwapIntervalEXT), + END_OF_SYMBOLS}; - const auto lookupFunction = - (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; + const auto fnLoadSymbols = [&](const SymLoadStruct* symbols) { + if (pfnLoader.LoadSymbols(symbols)) return true; - const auto fnLoadSymbols = - [&](const GLLibraryLoader::SymLoadStruct* symbols) { - if (GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols, lookupFunction)) - return true; - - GLLibraryLoader::ClearSymbols(symbols); - return false; - }; + ClearSymbols(symbols); + return false; + }; const char* clientVendor = fGetClientString(display, LOCAL_GLX_VENDOR); const char* serverVendor = @@ -571,8 +570,7 @@ GLContextGLX::~GLContextGLX() { } bool GLContextGLX::Init() { - SetupLookupFunction(); - if (!InitWithPrefix("gl", true)) { + if (!GLContext::Init()) { return false; } @@ -609,9 +607,9 @@ bool GLContextGLX::IsCurrentImpl() const { return mGLX->fGetCurrentContext() == mContext; } -bool GLContextGLX::SetupLookupFunction() { - mLookupFunc = (PlatformLookupFunction)sGLXLibrary.GetGetProcAddress(); - return true; +Maybe GLContextGLX::GetSymbolLoader() const { + const auto pfn = sGLXLibrary.GetGetProcAddress(); + return Some(SymbolLoader(pfn)); } bool GLContextGLX::IsDoubleBuffered() const { return mDoubleBuffered; } diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp index 0c76dd0eeceb..f364390f343b 100644 --- a/gfx/gl/GLContextProviderWGL.cpp +++ b/gfx/gl/GLContextProviderWGL.cpp @@ -68,6 +68,12 @@ static inline bool HasExtension(const char* aExtensions, reinterpret_cast(aExtensions), aRequiredExtension); } +SymbolLoader WGLLibrary::GetSymbolLoader() const { + auto ret = SymbolLoader(*mOGLLibrary); + ret.mPfn = SymbolLoader::GetProcAddressT(mSymbols.fGetProcAddress); + return ret; +} + bool WGLLibrary::EnsureInitialized() { if (mInitialized) return true; @@ -88,24 +94,29 @@ bool WGLLibrary::EnsureInitialized() { } } -#define SYMBOL(X) \ - { \ - (PRFuncPtr*)&mSymbols.f##X, { "wgl" #X, nullptr } \ - } -#define END_OF_SYMBOLS \ - { \ - nullptr, { nullptr } \ +#define SYMBOL(X) \ + { \ + (PRFuncPtr*)&mSymbols.f##X, { \ + { "wgl" #X } \ + } \ } +#define END_OF_SYMBOLS {nullptr, {}} - const GLLibraryLoader::SymLoadStruct earlySymbols[] = { - SYMBOL(CreateContext), SYMBOL(MakeCurrent), SYMBOL(GetProcAddress), - SYMBOL(DeleteContext), SYMBOL(GetCurrentContext), SYMBOL(GetCurrentDC), - END_OF_SYMBOLS}; + { + const auto loader = SymbolLoader(*mOGLLibrary); + const SymLoadStruct earlySymbols[] = {SYMBOL(CreateContext), + SYMBOL(MakeCurrent), + SYMBOL(GetProcAddress), + SYMBOL(DeleteContext), + SYMBOL(GetCurrentContext), + SYMBOL(GetCurrentDC), + END_OF_SYMBOLS}; - if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) { - NS_WARNING( - "Couldn't find required entry points in OpenGL DLL (early init)"); - return false; + if (!loader.LoadSymbols(earlySymbols)) { + NS_WARNING( + "Couldn't find required entry points in OpenGL DLL (early init)"); + return false; + } } mDummyWindow = CreateDummyWindow(); @@ -156,26 +167,25 @@ bool WGLLibrary::EnsureInitialized() { const auto resetContext = MakeScopeExit([&]() { mSymbols.fMakeCurrent(curDC, curCtx); }); - const auto lookupFunc = - (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; + const auto loader = GetSymbolLoader(); // Now we can grab all the other symbols that we couldn't without having // a context current. // clang-format off - const GLLibraryLoader::SymLoadStruct reqExtSymbols[] = { - { (PRFuncPtr*)&mSymbols.fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", nullptr } }, - { (PRFuncPtr*)&mSymbols.fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", nullptr } }, - { (PRFuncPtr*)&mSymbols.fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", nullptr } }, - { (PRFuncPtr*)&mSymbols.fReleasePbufferDC, { "wglReleasePbufferDCARB", "wglReleasePbufferDCEXT", nullptr } }, - // { (PRFuncPtr*)&mSymbols.fBindTexImage, { "wglBindTexImageARB", "wglBindTexImageEXT", nullptr } }, - // { (PRFuncPtr*)&mSymbols.fReleaseTexImage, { "wglReleaseTexImageARB", "wglReleaseTexImageEXT", nullptr } }, - { (PRFuncPtr*)&mSymbols.fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", nullptr } }, - // { (PRFuncPtr*)&mSymbols.fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", nullptr } }, + const SymLoadStruct reqExtSymbols[] = { + { (PRFuncPtr*)&mSymbols.fCreatePbuffer, {{ "wglCreatePbufferARB", "wglCreatePbufferEXT" }} }, + { (PRFuncPtr*)&mSymbols.fDestroyPbuffer, {{ "wglDestroyPbufferARB", "wglDestroyPbufferEXT" }} }, + { (PRFuncPtr*)&mSymbols.fGetPbufferDC, {{ "wglGetPbufferDCARB", "wglGetPbufferDCEXT" }} }, + { (PRFuncPtr*)&mSymbols.fReleasePbufferDC, {{ "wglReleasePbufferDCARB", "wglReleasePbufferDCEXT" }} }, + // { (PRFuncPtr*)&mSymbols.fBindTexImage, {{ "wglBindTexImageARB", "wglBindTexImageEXT" }} }, + // { (PRFuncPtr*)&mSymbols.fReleaseTexImage, {{ "wglReleaseTexImageARB", "wglReleaseTexImageEXT" }} }, + { (PRFuncPtr*)&mSymbols.fChoosePixelFormat, {{ "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT" }} }, + // { (PRFuncPtr*)&mSymbols.fGetPixelFormatAttribiv, {{ "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT" }} }, SYMBOL(GetExtensionsStringARB), END_OF_SYMBOLS }; // clang-format on - if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, reqExtSymbols, lookupFunc)) { + if (!loader.LoadSymbols(reqExtSymbols)) { NS_WARNING("reqExtSymbols missing"); return false; } @@ -189,10 +199,9 @@ bool WGLLibrary::EnsureInitialized() { // -- if (HasExtension(extString, "WGL_ARB_create_context")) { - const GLLibraryLoader::SymLoadStruct createContextSymbols[] = { + const SymLoadStruct createContextSymbols[] = { SYMBOL(CreateContextAttribsARB), END_OF_SYMBOLS}; - if (GLLibraryLoader::LoadSymbols(mOGLLibrary, createContextSymbols, - lookupFunc)) { + if (loader.LoadSymbols(createContextSymbols)) { if (HasExtension(extString, "WGL_ARB_create_context_robustness")) { mHasRobustness = true; } @@ -211,7 +220,7 @@ bool WGLLibrary::EnsureInitialized() { } if (hasDXInterop2) { - const GLLibraryLoader::SymLoadStruct dxInteropSymbols[] = { + const SymLoadStruct dxInteropSymbols[] = { SYMBOL(DXSetResourceShareHandleNV), SYMBOL(DXOpenDeviceNV), SYMBOL(DXCloseDeviceNV), @@ -221,8 +230,7 @@ bool WGLLibrary::EnsureInitialized() { SYMBOL(DXLockObjectsNV), SYMBOL(DXUnlockObjectsNV), END_OF_SYMBOLS}; - if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, dxInteropSymbols, - lookupFunc)) { + if (!loader.LoadSymbols(dxInteropSymbols)) { NS_ERROR( "WGL_NV_DX_interop2 announceed without supplying its functions."); ClearSymbols(dxInteropSymbols); @@ -292,18 +300,6 @@ GLContextWGL::~GLContextWGL() { } } -bool GLContextWGL::Init() { - if (!mDC || !mContext) return false; - - // see bug 929506 comment 29. wglGetProcAddress requires a current context. - if (!sWGLLib.mSymbols.fMakeCurrent(mDC, mContext)) return false; - - SetupLookupFunction(); - if (!InitWithPrefix("gl", true)) return false; - - return true; -} - bool GLContextWGL::MakeCurrentImpl() const { const bool succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext); NS_ASSERTION(succeeded, "Failed to make GL context current!"); @@ -324,17 +320,6 @@ void GLContextWGL::GetWSIInfo(nsCString* const out) const { out->Append(sWGLLib.mSymbols.fGetExtensionsStringARB(mDC)); } -bool GLContextWGL::SetupLookupFunction() { - // Make sure that we have a ref to the OGL library; - // when run under CodeXL, wglGetProcAddress won't return - // the right thing for some core functions. - MOZ_ASSERT(mLibrary == nullptr); - - mLibrary = sWGLLib.GetOGLLibrary(); - mLookupFunc = (PlatformLookupFunction)sWGLLib.mSymbols.fGetProcAddress; - return true; -} - already_AddRefed GLContextProviderWGL::CreateWrappingExisting( void*, void*) { return nullptr; diff --git a/gfx/gl/GLContextWGL.h b/gfx/gl/GLContextWGL.h index a3e17f43ff90..af64e40cd2d5 100644 --- a/gfx/gl/GLContextWGL.h +++ b/gfx/gl/GLContextWGL.h @@ -32,13 +32,16 @@ class GLContextWGL final : public GLContext { return GLContextType::WGL; } - bool Init() override; virtual bool MakeCurrentImpl() const override; virtual bool IsCurrentImpl() const override; virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; } virtual bool SwapBuffers() override; - virtual bool SetupLookupFunction() override; virtual void GetWSIInfo(nsCString* const out) const override; + + Maybe GetSymbolLoader() const override { + return Some(sWGLLib.GetSymbolLoader()); + } + HGLRC Context() { return mContext; } protected: diff --git a/gfx/gl/GLLibraryEGL.cpp b/gfx/gl/GLLibraryEGL.cpp index 2f488f66a396..47089ea8715f 100644 --- a/gfx/gl/GLLibraryEGL.cpp +++ b/gfx/gl/GLLibraryEGL.cpp @@ -357,6 +357,25 @@ bool GLLibraryEGL::ReadbackEGLImage(EGLImage image, return true; } +// - + +#if defined(XP_UNIX) +# define GLES2_LIB "libGLESv2.so" +# define GLES2_LIB2 "libGLESv2.so.2" +#elif defined(XP_WIN) +# define GLES2_LIB "libGLESv2.dll" +#else +# error "Platform not recognized" +#endif + +Maybe GLLibraryEGL::GetSymbolLoader() const { + auto ret = SymbolLoader(mSymbols.fGetProcAddress); + ret.mLib = mGLLibrary; + return Some(ret); +} + +// - + /* static */ bool GLLibraryEGL::EnsureInitialized( bool forceAccel, nsACString* const out_failureId) { if (!sEGLLibrary) { @@ -365,6 +384,11 @@ bool GLLibraryEGL::ReadbackEGLImage(EGLImage image, return sEGLLibrary->DoEnsureInitialized(forceAccel, out_failureId); } +bool GLLibraryEGL::DoEnsureInitialized() { + nsCString failureId; + return DoEnsureInitialized(false, &failureId); +} + bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, nsACString* const out_failureId) { if (mInitialized && !mSymbols.fTerminate) { @@ -406,14 +430,9 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, MOZ_ASSERT(false, "d3dcompiler DLL loading failed."); } while (false); - LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); + mGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll")); - - if (!mEGLLibrary) { - *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_LOAD"); - return false; - } } #else // !Windows @@ -435,61 +454,81 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } # endif - if (!mEGLLibrary) { - NS_WARNING("Couldn't load EGL LIB."); - *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_LOAD_2"); - return false; +# ifdef APITRACE_LIB + if (!mGLLibrary) { + mGLLibrary = PR_LoadLibrary(APITRACE_LIB); } +# endif + + if (!mGLLibrary) { + mGLLibrary = PR_LoadLibrary(GLES2_LIB); + } + +# ifdef GLES2_LIB2 + if (!mGLLibrary) { + mGLLibrary = PR_LoadLibrary(GLES2_LIB2); + } +# endif #endif // !Windows -#define SYMBOL(X) \ - { \ - (PRFuncPtr*)&mSymbols.f##X, { "egl" #X, nullptr } \ - } -#define END_OF_SYMBOLS \ - { \ - nullptr, { nullptr } \ - } - - GLLibraryLoader::SymLoadStruct earlySymbols[] = { - SYMBOL(GetDisplay), - SYMBOL(Terminate), - SYMBOL(GetCurrentSurface), - SYMBOL(GetCurrentContext), - SYMBOL(MakeCurrent), - SYMBOL(DestroyContext), - SYMBOL(CreateContext), - SYMBOL(DestroySurface), - SYMBOL(CreateWindowSurface), - SYMBOL(CreatePbufferSurface), - SYMBOL(CreatePbufferFromClientBuffer), - SYMBOL(CreatePixmapSurface), - SYMBOL(BindAPI), - SYMBOL(Initialize), - SYMBOL(ChooseConfig), - SYMBOL(GetError), - SYMBOL(GetConfigs), - SYMBOL(GetConfigAttrib), - SYMBOL(WaitNative), - SYMBOL(GetProcAddress), - SYMBOL(SwapBuffers), - SYMBOL(CopyBuffers), - SYMBOL(QueryString), - SYMBOL(QueryContext), - SYMBOL(BindTexImage), - SYMBOL(ReleaseTexImage), - SYMBOL(SwapInterval), - SYMBOL(QuerySurface), - END_OF_SYMBOLS}; - - if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, earlySymbols)) { - NS_WARNING( - "Couldn't find required entry points in EGL library (early init)"); - *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_SYM"); + if (!mEGLLibrary || !mGLLibrary) { + NS_WARNING("Couldn't load EGL LIB."); + *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_LOAD_3"); return false; } +#define SYMBOL(X) \ + { \ + (PRFuncPtr*)&mSymbols.f##X, { \ + { "egl" #X } \ + } \ + } +#define END_OF_SYMBOLS \ + { \ + nullptr, {} \ + } + + SymLoadStruct earlySymbols[] = {SYMBOL(GetDisplay), + SYMBOL(Terminate), + SYMBOL(GetCurrentSurface), + SYMBOL(GetCurrentContext), + SYMBOL(MakeCurrent), + SYMBOL(DestroyContext), + SYMBOL(CreateContext), + SYMBOL(DestroySurface), + SYMBOL(CreateWindowSurface), + SYMBOL(CreatePbufferSurface), + SYMBOL(CreatePbufferFromClientBuffer), + SYMBOL(CreatePixmapSurface), + SYMBOL(BindAPI), + SYMBOL(Initialize), + SYMBOL(ChooseConfig), + SYMBOL(GetError), + SYMBOL(GetConfigs), + SYMBOL(GetConfigAttrib), + SYMBOL(WaitNative), + SYMBOL(GetProcAddress), + SYMBOL(SwapBuffers), + SYMBOL(CopyBuffers), + SYMBOL(QueryString), + SYMBOL(QueryContext), + SYMBOL(BindTexImage), + SYMBOL(ReleaseTexImage), + SYMBOL(SwapInterval), + SYMBOL(QuerySurface), + END_OF_SYMBOLS}; + + { + const SymbolLoader libLoader(*mEGLLibrary); + if (!libLoader.LoadSymbols(earlySymbols)) { + NS_WARNING( + "Couldn't find required entry points in EGL library (early init)"); + *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_SYM"); + return false; + } + } + { const char internalFuncName[] = "_Z35eglQueryStringImplementationANDROIDPvi"; @@ -499,20 +538,16 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, *(PRFuncPtr*)&mSymbols.fQueryString = internalFunc; } } + const SymbolLoader pfnLoader(mSymbols.fGetProcAddress); InitClientExtensions(); - const auto lookupFunction = - (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; + const auto fnLoadSymbols = [&](const SymLoadStruct* symbols) { + if (pfnLoader.LoadSymbols(symbols)) return true; - const auto fnLoadSymbols = - [&](const GLLibraryLoader::SymLoadStruct* symbols) { - if (GLLibraryLoader::LoadSymbols(mEGLLibrary, symbols, lookupFunction)) - return true; - - ClearSymbols(symbols); - return false; - }; + ClearSymbols(symbols); + return false; + }; // Check the ANGLE support the system has nsCOMPtr gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); @@ -522,14 +557,14 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, if (mIsANGLE) { MOZ_ASSERT(IsExtensionSupported(ANGLE_platform_angle_d3d)); - const GLLibraryLoader::SymLoadStruct angleSymbols[] = { - SYMBOL(GetPlatformDisplayEXT), END_OF_SYMBOLS}; + const SymLoadStruct angleSymbols[] = {SYMBOL(GetPlatformDisplayEXT), + END_OF_SYMBOLS}; if (!fnLoadSymbols(angleSymbols)) { gfxCriticalError() << "Failed to load ANGLE symbols!"; return false; } MOZ_ASSERT(IsExtensionSupported(ANGLE_platform_angle_d3d)); - const GLLibraryLoader::SymLoadStruct createDeviceSymbols[] = { + const SymLoadStruct createDeviceSymbols[] = { SYMBOL(CreateDeviceANGLE), SYMBOL(ReleaseDeviceANGLE), END_OF_SYMBOLS}; if (!fnLoadSymbols(createDeviceSymbols)) { NS_ERROR( @@ -549,7 +584,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, // Alright, load display exts. if (IsExtensionSupported(KHR_lock_surface)) { - const GLLibraryLoader::SymLoadStruct lockSymbols[] = { + const SymLoadStruct lockSymbols[] = { SYMBOL(LockSurfaceKHR), SYMBOL(UnlockSurfaceKHR), END_OF_SYMBOLS}; if (!fnLoadSymbols(lockSymbols)) { NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!"); @@ -558,8 +593,8 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { - const GLLibraryLoader::SymLoadStruct d3dSymbols[] = { - SYMBOL(QuerySurfacePointerANGLE), END_OF_SYMBOLS}; + const SymLoadStruct d3dSymbols[] = {SYMBOL(QuerySurfacePointerANGLE), + END_OF_SYMBOLS}; if (!fnLoadSymbols(d3dSymbols)) { NS_ERROR( "EGL supports ANGLE_surface_d3d_texture_2d_share_handle without " @@ -569,7 +604,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(KHR_fence_sync)) { - const GLLibraryLoader::SymLoadStruct syncSymbols[] = { + const SymLoadStruct syncSymbols[] = { SYMBOL(CreateSyncKHR), SYMBOL(DestroySyncKHR), SYMBOL(ClientWaitSyncKHR), SYMBOL(GetSyncAttribKHR), END_OF_SYMBOLS}; if (!fnLoadSymbols(syncSymbols)) { @@ -579,7 +614,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) { - const GLLibraryLoader::SymLoadStruct imageSymbols[] = { + const SymLoadStruct imageSymbols[] = { SYMBOL(CreateImageKHR), SYMBOL(DestroyImageKHR), END_OF_SYMBOLS}; if (!fnLoadSymbols(imageSymbols)) { NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!"); @@ -592,8 +627,8 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(ANDROID_native_fence_sync)) { - const GLLibraryLoader::SymLoadStruct nativeFenceSymbols[] = { - SYMBOL(DupNativeFenceFDANDROID), END_OF_SYMBOLS}; + const SymLoadStruct nativeFenceSymbols[] = {SYMBOL(DupNativeFenceFDANDROID), + END_OF_SYMBOLS}; if (!fnLoadSymbols(nativeFenceSymbols)) { NS_ERROR( "EGL supports ANDROID_native_fence_sync without exposing its " @@ -603,7 +638,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(KHR_stream)) { - const GLLibraryLoader::SymLoadStruct streamSymbols[] = { + const SymLoadStruct streamSymbols[] = { SYMBOL(CreateStreamKHR), SYMBOL(DestroyStreamKHR), SYMBOL(QueryStreamKHR), END_OF_SYMBOLS}; if (!fnLoadSymbols(streamSymbols)) { @@ -613,7 +648,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(KHR_stream_consumer_gltexture)) { - const GLLibraryLoader::SymLoadStruct streamConsumerSymbols[] = { + const SymLoadStruct streamConsumerSymbols[] = { SYMBOL(StreamConsumerGLTextureExternalKHR), SYMBOL(StreamConsumerAcquireKHR), SYMBOL(StreamConsumerReleaseKHR), END_OF_SYMBOLS}; @@ -626,9 +661,9 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(EXT_device_query)) { - const GLLibraryLoader::SymLoadStruct queryDisplaySymbols[] = { - SYMBOL(QueryDisplayAttribEXT), SYMBOL(QueryDeviceAttribEXT), - END_OF_SYMBOLS}; + const SymLoadStruct queryDisplaySymbols[] = {SYMBOL(QueryDisplayAttribEXT), + SYMBOL(QueryDeviceAttribEXT), + END_OF_SYMBOLS}; if (!fnLoadSymbols(queryDisplaySymbols)) { NS_ERROR("EGL supports EXT_device_query without exposing its functions!"); MarkExtensionUnsupported(EXT_device_query); @@ -636,7 +671,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(NV_stream_consumer_gltexture_yuv)) { - const GLLibraryLoader::SymLoadStruct nvStreamSymbols[] = { + const SymLoadStruct nvStreamSymbols[] = { SYMBOL(StreamConsumerGLTextureExternalAttribsNV), END_OF_SYMBOLS}; if (!fnLoadSymbols(nvStreamSymbols)) { NS_ERROR( @@ -647,7 +682,7 @@ bool GLLibraryEGL::DoEnsureInitialized(bool forceAccel, } if (IsExtensionSupported(ANGLE_stream_producer_d3d_texture)) { - const GLLibraryLoader::SymLoadStruct nvStreamSymbols[] = { + const SymLoadStruct nvStreamSymbols[] = { SYMBOL(CreateStreamProducerD3DTextureANGLE), SYMBOL(StreamPostD3DTextureANGLE), END_OF_SYMBOLS}; if (!fnLoadSymbols(nvStreamSymbols)) { diff --git a/gfx/gl/GLLibraryEGL.h b/gfx/gl/GLLibraryEGL.h index c74482df552a..838024cfc0c9 100644 --- a/gfx/gl/GLLibraryEGL.h +++ b/gfx/gl/GLLibraryEGL.h @@ -44,7 +44,7 @@ PRLibrary* LoadApitraceLibrary(); void BeforeEGLCall(const char* funcName); void AfterEGLCall(const char* funcName); -class GLLibraryEGL { +class GLLibraryEGL final { protected: ~GLLibraryEGL() {} @@ -101,10 +101,6 @@ class GLLibraryEGL { std::bitset mAvailableExtensions; public: - GLLibraryLoader::PlatformLookupFunction GetLookupFunction() const { - return (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; - } - //// #ifdef MOZ_WIDGET_ANDROID @@ -408,6 +404,8 @@ class GLLibraryEGL { void DumpEGLConfig(EGLConfig cfg); void DumpEGLConfigs(); + Maybe GetSymbolLoader() const; + private: struct { EGLCastToRelevantPtr(GLAPIENTRY* fGetProcAddress)(const char* procname); @@ -527,12 +525,14 @@ class GLLibraryEGL { } mSymbols = {}; private: + bool DoEnsureInitialized(); bool DoEnsureInitialized(bool forceAccel, nsACString* const out_failureId); EGLDisplay CreateDisplay(bool forceAccel, const nsCOMPtr& gfxInfo, nsACString* const out_failureId); bool mInitialized = false; PRLibrary* mEGLLibrary = nullptr; + mutable PRLibrary* mGLLibrary = nullptr; EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; RefPtr mReadbackGL; diff --git a/gfx/gl/GLLibraryLoader.cpp b/gfx/gl/GLLibraryLoader.cpp index bdc6e1bd5de6..e4be54b11340 100644 --- a/gfx/gl/GLLibraryLoader.cpp +++ b/gfx/gl/GLLibraryLoader.cpp @@ -4,6 +4,8 @@ #include "GLLibraryLoader.h" +#include + #include "nsDebug.h" #ifdef WIN32 @@ -13,31 +15,16 @@ namespace mozilla { namespace gl { -bool GLLibraryLoader::OpenLibrary(const char* library) { - PRLibSpec lspec; - lspec.type = PR_LibSpec_Pathname; - lspec.value.pathname = library; - - mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL); - if (!mLibrary) return false; - - return true; +void ClearSymbols(const SymLoadStruct* const firstStruct) { + for (auto itr = firstStruct; itr->symPointer; ++itr) { + *itr->symPointer = nullptr; + } } -bool GLLibraryLoader::LoadSymbols(const SymLoadStruct* firstStruct, - bool tryplatform, const char* prefix, - bool warnOnFailure) { - return LoadSymbols(mLibrary, firstStruct, tryplatform ? mLookupFunc : nullptr, - prefix, warnOnFailure); -} - -PRFuncPtr GLLibraryLoader::LookupSymbol(const char* sym) { - return LookupSymbol(mLibrary, sym, mLookupFunc); -} - -PRFuncPtr GLLibraryLoader::LookupSymbol(PRLibrary* lib, const char* sym, - PlatformLookupFunction lookupFunction) { - PRFuncPtr res = 0; +/* +PRFuncPtr GLLibraryLoader::LookupSymbol(PRLibrary& lib, const char* const sym, + const PlatformLookupFunction lookupFunction) { + PRFuncPtr res = nullptr; // try finding it in the library directly, if we have one if (lib) { @@ -57,55 +44,55 @@ PRFuncPtr GLLibraryLoader::LookupSymbol(PRLibrary* lib, const char* sym, return res; } +*/ -bool GLLibraryLoader::LoadSymbols(PRLibrary* lib, - const SymLoadStruct* firstStruct, - PlatformLookupFunction lookupFunction, - const char* prefix, bool warnOnFailure) { - char sbuf[MAX_SYMBOL_LENGTH * 2]; - int failCount = 0; +bool SymbolLoader::LoadSymbols(const SymLoadStruct* const firstStruct, + const bool warnOnFailures) const { + bool ok = true; - const SymLoadStruct* ss = firstStruct; - while (ss->symPointer) { - *ss->symPointer = 0; + for (auto itr = firstStruct; itr->symPointer; ++itr) { + *itr->symPointer = nullptr; - for (int i = 0; i < MAX_SYMBOL_NAMES; i++) { - if (ss->symNames[i] == nullptr) break; + for (const auto& s : itr->symNames) { + if (!s) break; - const char* s = ss->symNames[i]; - if (prefix && *prefix != 0) { - strcpy(sbuf, prefix); - strcat(sbuf, ss->symNames[i]); - s = sbuf; - } - - PRFuncPtr p = LookupSymbol(lib, s, lookupFunction); + const auto p = GetProcAddress(s); if (p) { - *ss->symPointer = p; + *itr->symPointer = p; break; } } - if (*ss->symPointer == 0) { - if (warnOnFailure) { - printf_stderr("Can't find symbol '%s'.\n", ss->symNames[0]); + if (!*itr->symPointer) { + if (warnOnFailures) { + printf_stderr("Can't find symbol '%s'.\n", itr->symNames[0]); } - - failCount++; + ok = false; } - - ss++; } - return failCount == 0 ? true : false; + return ok; } -/*static*/ void GLLibraryLoader::ClearSymbols( - const SymLoadStruct* const firstStruct) { - for (auto cur = firstStruct; cur->symPointer; ++cur) { - *cur->symPointer = nullptr; +// - + +PRFuncPtr SymbolLoader::GetProcAddress(const char* const name) const { +#ifdef DEBUG + static const std::regex kRESymbol("[a-z].*"); + if (!std::regex_match(name, kRESymbol)) { + gfxCriticalError() << "Bad symbol name : " << name; } +#endif + + PRFuncPtr ret = nullptr; + if (!ret && mPfn) { + ret = mPfn(name); + } + if (!ret && mLib) { + ret = PR_FindFunctionSymbol(mLib, name); + } + return ret; } -} /* namespace gl */ -} /* namespace mozilla */ +} // namespace gl +} // namespace mozilla diff --git a/gfx/gl/GLLibraryLoader.h b/gfx/gl/GLLibraryLoader.h index 4e0cebf0fcb9..1a13d1aef764 100644 --- a/gfx/gl/GLLibraryLoader.h +++ b/gfx/gl/GLLibraryLoader.h @@ -5,6 +5,7 @@ #ifndef GLLIBRARYLOADER_H_ #define GLLIBRARYLOADER_H_ +#include #include #include "GLDefs.h" @@ -14,48 +15,43 @@ namespace mozilla { namespace gl { -class GLLibraryLoader { - public: - bool OpenLibrary(const char* library); - - typedef PRFuncPtr(GLAPIENTRY* PlatformLookupFunction)(const char*); - - enum { MAX_SYMBOL_NAMES = 6, MAX_SYMBOL_LENGTH = 128 }; - - typedef struct { - PRFuncPtr* symPointer; - const char* symNames[MAX_SYMBOL_NAMES]; - } SymLoadStruct; - - bool LoadSymbols(const SymLoadStruct* firstStruct, bool tryplatform = false, - const char* prefix = nullptr, bool warnOnFailure = true); - - static void ClearSymbols(const SymLoadStruct* firstStruct); - - PRFuncPtr LookupSymbol(const char* symname); - - /* - * Static version of the functions in this class - */ - static PRFuncPtr LookupSymbol( - PRLibrary* lib, const char* symname, - PlatformLookupFunction lookupFunction = nullptr); - static bool LoadSymbols(PRLibrary* lib, const SymLoadStruct* firstStruct, - PlatformLookupFunction lookupFunction = nullptr, - const char* prefix = nullptr, - bool warnOnFailure = true); - - protected: - GLLibraryLoader() { - mLibrary = nullptr; - mLookupFunc = nullptr; - } - - PRLibrary* mLibrary; - PlatformLookupFunction mLookupFunc; +struct SymLoadStruct final { + PRFuncPtr* symPointer; + std::array symNames; }; -} /* namespace gl */ -} /* namespace mozilla */ +void ClearSymbols(const SymLoadStruct* firstStruct); -#endif /* GLLIBRARYLOADER_H_ */ +class SymbolLoader final { +public: + typedef PRFuncPtr (GLAPIENTRY * GetProcAddressT)(const char*); + + GetProcAddressT mPfn = nullptr; // Try this first, if not null. + PRLibrary* mLib = nullptr; + + explicit SymbolLoader(void* (GLAPIENTRY * pfn)(const char*)) + : mPfn(GetProcAddressT(pfn)) + { + MOZ_ASSERT(mPfn); + } + + explicit SymbolLoader(const GetProcAddressT pfn) + : mPfn(pfn) + { + MOZ_ASSERT(mPfn); + } + + explicit SymbolLoader(PRLibrary& lib) + : mLib(&lib) + { + MOZ_ASSERT(mLib); + } + + PRFuncPtr GetProcAddress(const char*) const; + bool LoadSymbols(const SymLoadStruct* firstStruct, bool warnOnFailures = true) const; +}; + +} // namespace gl +} // namespace mozilla + +#endif // GLLIBRARYLOADER_H_ diff --git a/gfx/gl/GLXLibrary.h b/gfx/gl/GLXLibrary.h index 3d3284d3d6c9..fea818cc6ea6 100644 --- a/gfx/gl/GLXLibrary.h +++ b/gfx/gl/GLXLibrary.h @@ -30,7 +30,7 @@ namespace gl { class GLContextGLX; -class GLXLibrary { +class GLXLibrary final { public: bool EnsureInitialized(); @@ -179,8 +179,8 @@ class GLXLibrary { bool IsATI() { return mIsATI; } bool IsMesa() { return mClientIsMesa; } - PRFuncPtr GetGetProcAddress() const { - return (PRFuncPtr)mSymbols.fGetProcAddress; + auto GetGetProcAddress() const { + return mSymbols.fGetProcAddress; } private: diff --git a/gfx/gl/WGLLibrary.h b/gfx/gl/WGLLibrary.h index 442205c9665d..82c764b3dba8 100644 --- a/gfx/gl/WGLLibrary.h +++ b/gfx/gl/WGLLibrary.h @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "GLContextTypes.h" +#include "GLLibraryLoader.h" #include "mozilla/UniquePtr.h" #include @@ -95,6 +96,7 @@ class WGLLibrary { bool IsInitialized() const { return mInitialized; } auto GetOGLLibrary() const { return mOGLLibrary; } auto RootDc() const { return mRootDc; } + SymbolLoader GetSymbolLoader() const; private: bool mInitialized = false; diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 86d91d816838..c6f2c02bd63d 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -104,15 +104,17 @@ void gecko_printf_stderr_output(const char* msg) { printf_stderr("%s\n", msg); } void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname) { - MOZ_ASSERT(glcontext_ptr); - mozilla::gl::GLContext* glcontext = reinterpret_cast(glcontext_ptr); + MOZ_ASSERT(glcontext); if (!glcontext) { return nullptr; } - PRFuncPtr p = glcontext->LookupSymbol(procname); - return reinterpret_cast(p); + const auto& loader = glcontext->GetSymbolLoader(); + MOZ_ASSERT(loader); + + const auto ret = loader->GetProcAddress(procname); + return reinterpret_cast(ret); } void gecko_profiler_register_thread(const char* name) {