Bug 1262265 - Cleanup GLContext symbol init. - r=jrmuizel

This commit is contained in:
Jeff Gilbert 2016-04-21 16:32:18 -07:00
parent 20c4935185
commit ed674372da
13 changed files with 1007 additions and 1244 deletions

View File

@ -1470,7 +1470,7 @@ CheckContextLost(GLContext* gl, bool* const out_isGuilty)
bool isEGL = gl->GetContextType() == gl::GLContextType::EGL;
GLenum resetStatus = LOCAL_GL_NO_ERROR;
if (gl->HasRobustness()) {
if (gl->IsSupported(GLFeature::robustness)) {
gl->MakeCurrent();
resetStatus = gl->fGetGraphicsResetStatus();
} else if (isEGL) {

File diff suppressed because it is too large Load Diff

View File

@ -341,7 +341,6 @@ public:
}
protected:
bool mInitialized;
bool mIsOffscreen;
bool mContextLost;
@ -359,8 +358,8 @@ protected:
GLRenderer mRenderer;
void SetProfileVersion(ContextProfile profile, uint32_t version) {
MOZ_ASSERT(!mInitialized, "SetProfileVersion can only be called before"
" initialization!");
MOZ_ASSERT(!mSymbols.fBindFramebuffer,
"SetProfileVersion can only be called before initialization!");
MOZ_ASSERT(profile != ContextProfile::Unknown &&
profile != ContextProfile::OpenGL,
"Invalid `profile` for SetProfileVersion");
@ -554,23 +553,16 @@ private:
// -----------------------------------------------------------------------------
// Robustness handling
public:
bool HasRobustness() const {
return mHasRobustness;
}
private:
/**
* The derived class is expected to provide information on whether or not it
* supports robustness.
*/
virtual bool SupportsRobustness() const = 0;
private:
bool mHasRobustness;
public:
// -----------------------------------------------------------------------------
// Error handling
public:
static const char* GLErrorToString(GLenum aError) {
switch (aError) {
case LOCAL_GL_INVALID_ENUM:
@ -2221,8 +2213,6 @@ public:
}
GLenum fGetGraphicsResetStatus() {
MOZ_ASSERT(mHasRobustness);
BEFORE_GL_CALL;
ASSERT_SYMBOL_PRESENT(fGetGraphicsResetStatus);
GLenum ret = mSymbols.fGetGraphicsResetStatus();
@ -3508,8 +3498,17 @@ public:
bool IsOffscreenSizeAllowed(const gfx::IntSize& aSize) const;
protected:
bool InitWithPrefix(const char *prefix, bool trygl);
bool InitWithPrefix(const char* prefix, bool trygl);
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,
GLExtensions ext);
bool LoadFeatureSymbols(const char* prefix, bool trygl, const SymLoadStruct* list,
GLFeature feature);
protected:
void InitExtensions();
GLint mViewportRect[4];

View File

@ -55,7 +55,7 @@ public:
virtual bool IsDoubleBuffered() const override;
virtual bool SupportsRobustness() const override;
virtual bool SupportsRobustness() const override { return false; }
virtual bool SwapBuffers() override;
};

View File

@ -52,7 +52,7 @@ public:
virtual bool IsDoubleBuffered() const override;
virtual bool SupportsRobustness() const override;
virtual bool SupportsRobustness() const override { return false; }
virtual bool SwapBuffers() override;

View File

@ -154,12 +154,6 @@ GLContextCGL::IsDoubleBuffered() const
return sCGLLibrary.UseDoubleBufferedWindows();
}
bool
GLContextCGL::SupportsRobustness() const
{
return false;
}
bool
GLContextCGL::SwapBuffers()
{
@ -362,20 +356,16 @@ static RefPtr<GLContext> gGlobalContext;
GLContext*
GLContextProviderCGL::GetGlobalContext()
{
if (!sCGLLibrary.EnsureInitialized()) {
return nullptr;
}
static bool triedToCreateContext = false;
if (!triedToCreateContext) {
triedToCreateContext = true;
if (!gGlobalContext) {
// There are bugs in some older drivers with pbuffers less
// than 16x16 in size; also 16x16 is POT so that we can do
// a FBO with it on older video cards. A FBO context for
// sharing is preferred since it has no associated target.
gGlobalContext = CreateOffscreenFBOContext(CreateContextFlags::NONE);
if (!gGlobalContext || !static_cast<GLContextCGL*>(gGlobalContext.get())->Init()) {
MOZ_RELEASE_ASSERT(!gGlobalContext);
RefPtr<GLContext> temp = CreateHeadless(CreateContextFlags::NONE);
gGlobalContext = temp;
if (!gGlobalContext) {
NS_WARNING("Couldn't init gGlobalContext.");
gGlobalContext = nullptr;
return nullptr;
}
}

View File

@ -142,12 +142,6 @@ GLContextEAGL::IsDoubleBuffered() const
return true;
}
bool
GLContextEAGL::SupportsRobustness() const
{
return false;
}
bool
GLContextEAGL::SwapBuffers()
{
@ -249,11 +243,15 @@ static RefPtr<GLContext> gGlobalContext;
GLContext*
GLContextProviderEAGL::GetGlobalContext()
{
if (!gGlobalContext) {
gGlobalContext = CreateEAGLContext(true, nullptr);
if (!gGlobalContext ||
!static_cast<GLContextEAGL*>(gGlobalContext.get())->Init())
{
static bool triedToCreateContext = false;
if (!triedToCreateContext) {
triedToCreateContext = true;
MOZ_RELEASE_ASSERT(!gGlobalContext);
RefPtr<GLContext> temp = CreateHeadless(CreateContextFlags::NONE);
gGlobalContext = temp;
if (!gGlobalContext) {
MOZ_CRASH("Failed to create global context");
}
}

View File

@ -928,6 +928,10 @@ GLContextEGL::CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
const mozilla::gfx::IntSize& size,
const SurfaceCaps& minCaps)
{
bool forceEnableHardware = bool(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE);
if (!sEGLLibrary.EnsureInitialized(forceEnableHardware))
return nullptr;
SurfaceCaps configCaps;
EGLConfig config = ChooseConfig(&sEGLLibrary, flags, minCaps, &configCaps);
if (config == EGL_NO_CONFIG) {
@ -935,8 +939,9 @@ GLContextEGL::CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
return nullptr;
}
if (GLContext::ShouldSpew())
if (GLContext::ShouldSpew()) {
sEGLLibrary.DumpEGLConfig(config);
}
mozilla::gfx::IntSize pbSize(size);
EGLSurface surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(config,
@ -947,7 +952,6 @@ GLContextEGL::CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
return nullptr;
}
RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags, configCaps, nullptr, true,
config, surface);
if (!gl) {
@ -956,22 +960,12 @@ GLContextEGL::CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
return nullptr;
}
if (!gl->Init()) {
NS_WARNING("Failed to initialize GLContext!");
// GLContextEGL::dtor will destroy |surface| for us.
return nullptr;
}
return gl.forget();
}
/*static*/ already_AddRefed<GLContext>
GLContextProviderEGL::CreateHeadless(CreateContextFlags flags)
{
bool forceEnableHardware = bool(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE);
if (!sEGLLibrary.EnsureInitialized(forceEnableHardware))
return nullptr;
mozilla::gfx::IntSize dummySize = mozilla::gfx::IntSize(16, 16);
SurfaceCaps dummyCaps = SurfaceCaps::Any();
return GLContextEGL::CreateEGLPBufferOffscreenContext(flags, dummySize, dummyCaps);
@ -985,7 +979,7 @@ GLContextProviderEGL::CreateOffscreen(const mozilla::gfx::IntSize& size,
CreateContextFlags flags)
{
bool forceEnableHardware = bool(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE);
if (!sEGLLibrary.EnsureInitialized(forceEnableHardware))
if (!sEGLLibrary.EnsureInitialized(forceEnableHardware)) // Needed for IsANGLE().
return nullptr;
bool canOffscreenUseHeadless = true;

View File

@ -1324,22 +1324,16 @@ GLContextProviderGLX::CreateOffscreen(const IntSize& size,
GLContextProviderGLX::GetGlobalContext()
{
// TODO: get GLX context sharing to work well with multiple threads
if (gfxEnv::DisableContextSharingGlx()) {
if (gfxEnv::DisableContextSharingGlx())
return nullptr;
}
static bool triedToCreateContext = false;
if (!triedToCreateContext && !gGlobalContext) {
if (!triedToCreateContext) {
triedToCreateContext = true;
IntSize dummySize = IntSize(16, 16);
SurfaceCaps dummyCaps = SurfaceCaps::Any();
// StaticPtr doesn't support assignments from already_AddRefed,
// so use a temporary nsRefPtr to make the reference counting
// fall out correctly.
RefPtr<GLContext> holder;
holder = CreateOffscreenPixmapContext(dummySize, dummyCaps);
gGlobalContext = holder;
MOZ_RELEASE_ASSERT(!gGlobalContext);
RefPtr<GLContext> temp = CreateHeadless(CreateContextFlags::NONE);
gGlobalContext = temp;
}
return gGlobalContext;

View File

@ -688,31 +688,18 @@ GLContextProviderWGL::CreateOffscreen(const IntSize& size,
return gl.forget();
}
static StaticRefPtr<GLContextWGL> gGlobalContext;
static StaticRefPtr<GLContext> gGlobalContext;
/*static*/ GLContext*
GLContextProviderWGL::GetGlobalContext()
{
if (!sWGLLib.EnsureInitialized()) {
return nullptr;
}
static bool triedToCreateContext = false;
if (!triedToCreateContext && !gGlobalContext) {
if (!triedToCreateContext) {
triedToCreateContext = true;
// conveniently, we already have what we need...
SurfaceCaps dummyCaps = SurfaceCaps::Any();
gGlobalContext = new GLContextWGL(dummyCaps,
nullptr, true,
sWGLLib.GetWindowDC(),
sWGLLib.GetWindowGLContext());
if (!gGlobalContext->Init()) {
NS_WARNING("Global context GLContext initialization failed?");
gGlobalContext = nullptr;
return nullptr;
}
MOZ_RELEASE_ASSERT(!gGlobalContext);
RefPtr<GLContext> temp = CreateHeadless(CreateContextFlags::NONE);
gGlobalContext = temp;
}
return static_cast<GLContext*>(gGlobalContext);

View File

@ -499,14 +499,17 @@ public:
}
EGLDisplay Display() {
MOZ_ASSERT(mInitialized);
return mEGLDisplay;
}
bool IsANGLE() const {
MOZ_ASSERT(mInitialized);
return mIsANGLE;
}
bool IsWARP() const {
MOZ_ASSERT(mInitialized);
return mIsWARP;
}

View File

@ -24,7 +24,7 @@ GLLibraryLoader::OpenLibrary(const char *library)
}
bool
GLLibraryLoader::LoadSymbols(SymLoadStruct *firstStruct,
GLLibraryLoader::LoadSymbols(const SymLoadStruct *firstStruct,
bool tryplatform,
const char *prefix,
bool warnOnFailure)
@ -64,7 +64,7 @@ GLLibraryLoader::LookupSymbol(PRLibrary *lib,
bool
GLLibraryLoader::LoadSymbols(PRLibrary *lib,
SymLoadStruct *firstStruct,
const SymLoadStruct *firstStruct,
PlatformLookupFunction lookupFunction,
const char *prefix,
bool warnOnFailure)
@ -72,7 +72,7 @@ GLLibraryLoader::LoadSymbols(PRLibrary *lib,
char sbuf[MAX_SYMBOL_LENGTH * 2];
int failCount = 0;
SymLoadStruct *ss = firstStruct;
const SymLoadStruct *ss = firstStruct;
while (ss->symPointer) {
*ss->symPointer = 0;

View File

@ -35,7 +35,7 @@ public:
const char *symNames[MAX_SYMBOL_NAMES];
} SymLoadStruct;
bool LoadSymbols(SymLoadStruct *firstStruct,
bool LoadSymbols(const SymLoadStruct *firstStruct,
bool tryplatform = false,
const char *prefix = nullptr,
bool warnOnFailure = true);
@ -47,7 +47,7 @@ public:
const char *symname,
PlatformLookupFunction lookupFunction = nullptr);
static bool LoadSymbols(PRLibrary *lib,
SymLoadStruct *firstStruct,
const SymLoadStruct *firstStruct,
PlatformLookupFunction lookupFunction = nullptr,
const char *prefix = nullptr,
bool warnOnFailure = true);