Simplify and standardize GetGlobalContext. r?jrmuizel
draft
Simplify and standardize GetGlobalContext. r?jrmuizel
From e3d71725311f93eb774fa49e0268abe1df2b89cb Mon Sep 17 00:00:00 2001
---
gfx/gl/GLContextProviderCGL.mm | 19 +++++++------------
gfx/gl/GLContextProviderEAGL.mm | 13 ++++++++-----
gfx/gl/GLContextProviderGLX.cpp | 15 ++++-----------
gfx/gl/GLContextProviderWGL.cpp | 20 +++-----------------
4 files changed, 22 insertions(+), 45 deletions(-)
MozReview-Commit-ID: 7vRMadRhWog
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -351,30 +351,25 @@ GLContextProviderCGL::CreateOffscreen(co
return gl.forget();
}
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);
+ gGlobalContext = CreateHeadless(0);
+
+ if (!gGlobalContext) {
NS_WARNING("Couldn't init gGlobalContext.");
- gGlobalContext = nullptr;
- return nullptr;
}
}
return gGlobalContext;
}
void
GLContextProviderCGL::Shutdown()
--- a/gfx/gl/GLContextProviderEAGL.mm
+++ b/gfx/gl/GLContextProviderEAGL.mm
@@ -238,21 +238,24 @@ GLContextProviderEAGL::CreateOffscreen(c
return glContext.forget();
}
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);
+ gGlobalContext = CreateHeadless(0);
+
+ if (!gGlobalContext) {
MOZ_CRASH("Failed to create global context");
}
}
return gGlobalContext;
}
void
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1319,32 +1319,25 @@ GLContextProviderGLX::CreateOffscreen(co
return gl.forget();
}
/*static*/ GLContext*
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);
+ gGlobalContext = CreateHeadless(0);
}
return gGlobalContext;
}
/*static*/ void
GLContextProviderGLX::Shutdown()
{
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -688,36 +688,22 @@ GLContextProviderWGL::CreateOffscreen(co
return gl.forget();
}
static StaticRefPtr<GLContextWGL> 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);
+ gGlobalContext = CreateHeadless(0);
}
return static_cast<GLContext*>(gGlobalContext);
}
/*static*/ void
GLContextProviderWGL::Shutdown()
{