Bug 1341913 - Proof of concept.
MozReview-Commit-ID: B4JXiGbFM15
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -59,16 +59,18 @@ namespace gl {
using namespace mozilla::gfx;
using namespace mozilla::layers;
#ifdef MOZ_GL_DEBUG
unsigned GLContext::sCurrentGLContextTLS = -1;
#endif
+GLContextSymbols GLContext::mSymbols;
+
// If adding defines, don't forget to undefine symbols. See #undef block below.
#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 } }
// should match the order of GLExtensions, and be null-terminated.
@@ -308,53 +310,37 @@ GLContext::StaticDebugCallback(GLenum so
GLsizei length,
const GLchar* message,
const GLvoid* userParam)
{
GLContext* gl = (GLContext*)userParam;
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)
{
- MOZ_RELEASE_ASSERT(!mSymbols.fBindFramebuffer,
- "GFX: InitWithPrefix should only be called once.");
-
ScopedGfxFeatureReporter reporter("GL Context");
if (!InitWithPrefixImpl(prefix, trygl)) {
- // If initialization fails, zero the symbols to avoid hard-to-understand bugs.
- mSymbols.Zero();
NS_WARNING("GLContext::InitWithPrefix failed!");
return false;
}
reporter.SetSuccessful();
return true;
}
static bool
LoadGLSymbols(GLContext* gl, const char* prefix, bool trygl,
const GLLibraryLoader::SymLoadStruct* list, const char* desc)
{
if (gl->LoadSymbols(list, trygl, prefix))
return true;
- ClearSymbols(list);
-
if (desc) {
const nsPrintfCString err("Failed to load symbols for %s.", desc);
NS_ERROR(err.BeginReading());
}
return false;
}
bool
@@ -2112,18 +2098,16 @@ GLContext::MarkDestroyed()
// still be alive in *their* dtors.
mScreen = nullptr;
mBlitHelper = nullptr;
mReadTexImageHelper = nullptr;
if (!MakeCurrent()) {
NS_WARNING("MakeCurrent() failed during MarkDestroyed! Skipping GL object teardown.");
}
-
- mSymbols.Zero();
}
#ifdef MOZ_GL_DEBUG
/* static */ void
GLContext::AssertNotPassingStackBufferToTheGL(const void* ptr)
{
int somethingOnTheStack;
const void* someStackPtr = &somethingOnTheStack;
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -3340,17 +3340,17 @@ public:
const uint8_t mDebugFlags;
protected:
RefPtr<GLContext> mSharedContext;
// The thread id which this context was created.
PlatformThreadId mOwningThreadId;
- GLContextSymbols mSymbols;
+ static GLContextSymbols mSymbols;
#ifdef MOZ_GL_DEBUG
// Non-zero debug flags will check that we don't send call
// to a GLContext that isn't current on the current
// thread.
// Store the current context when binding to thread local
// storage to support debug flags on an arbitrary thread.
static unsigned sCurrentGLContextTLS;
--- a/gfx/gl/GLContextSymbols.h
+++ b/gfx/gl/GLContextSymbols.h
@@ -22,24 +22,16 @@
#define GLAPI
#endif
namespace mozilla {
namespace gl {
struct GLContextSymbols
{
- GLContextSymbols() {
- Zero();
- }
-
- void Zero() {
- memset(this, 0, sizeof(GLContextSymbols));
- }
-
void (GLAPIENTRY * fActiveTexture)(GLenum);
void (GLAPIENTRY * fAttachShader)(GLuint, GLuint);
void (GLAPIENTRY * fBeginQuery)(GLenum, GLuint);
void (GLAPIENTRY * fBindAttribLocation)(GLuint, GLuint, const GLchar*);
void (GLAPIENTRY * fBindBuffer)(GLenum, GLuint);
void (GLAPIENTRY * fBindTexture)(GLenum, GLuint);
void (GLAPIENTRY * fBindVertexArray)(GLuint);
void (GLAPIENTRY * fBlendColor)(GLfloat, GLfloat, GLfloat, GLfloat);
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -443,17 +443,16 @@ GLLibraryEGL::EnsureInitialized(bool for
const auto lookupFunction =
(GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress;
const auto fnLoadSymbols = [&](const GLLibraryLoader::SymLoadStruct* symbols) {
if (GLLibraryLoader::LoadSymbols(mEGLLibrary, symbols, lookupFunction))
return true;
- ClearSymbols(symbols);
return false;
};
// Check the ANGLE support the system has
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
mIsANGLE = IsExtensionSupported(ANGLE_platform_angle);
EGLDisplay chosenDisplay = nullptr;
--- a/gfx/gl/GLLibraryLoader.cpp
+++ b/gfx/gl/GLLibraryLoader.cpp
@@ -77,19 +77,21 @@ GLLibraryLoader::LoadSymbols(PRLibrary*
const SymLoadStruct* firstStruct,
PlatformLookupFunction lookupFunction,
const char* prefix,
bool warnOnFailure)
{
char sbuf[MAX_SYMBOL_LENGTH * 2];
int failCount = 0;
- const SymLoadStruct* ss = firstStruct;
- while (ss->symPointer) {
- *ss->symPointer = 0;
+
+ for (const SymLoadStruct* ss = firstStruct; ss->symPointer; ss++) {
+ if (*ss->symPointer) {
+ continue;
+ }
for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
if (ss->symNames[i] == nullptr)
break;
const char* s = ss->symNames[i];
if (prefix && *prefix != 0) {
strcpy(sbuf, prefix);
@@ -106,26 +108,16 @@ GLLibraryLoader::LoadSymbols(PRLibrary*
if (*ss->symPointer == 0) {
if (warnOnFailure) {
printf_stderr("Can't find symbol '%s'.\n", ss->symNames[0]);
}
failCount++;
}
-
- ss++;
}
return failCount == 0 ? true : false;
}
-/*static*/ void
-GLLibraryLoader::ClearSymbols(const SymLoadStruct* const firstStruct)
-{
- for (auto cur = firstStruct; cur->symPointer; ++cur) {
- *cur->symPointer = nullptr;
- }
-}
-
} /* namespace gl */
} /* namespace mozilla */
--- a/gfx/gl/GLLibraryLoader.h
+++ b/gfx/gl/GLLibraryLoader.h
@@ -31,18 +31,16 @@ public:
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);