Bug 814159 - Part 2: remove the global context code from GLContextProviderEGL.cpp - r=benwa
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 11 Oct 2013 09:16:44 -0400
changeset 164287 86a2a0fe62902c2ae2557ab1385c4d969c58a15d
parent 164286 fefe4254ee1797d5544ee2819962ed388ba9e2f2
child 164288 4dbbf905f83c39a371bdecfed8f20bbe7f5c5be6
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenwa
bugs814159
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 814159 - Part 2: remove the global context code from GLContextProviderEGL.cpp - r=benwa
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -980,23 +980,16 @@ bool GLContextEGL::AttachSharedHandle(Sh
 }
 
 bool
 GLContextEGL::ResizeOffscreen(const gfxIntSize& aNewSize)
 {
 	return ResizeScreenBuffer(aNewSize);
 }
 
-
-static GLContextEGL *
-GetGlobalContextEGL()
-{
-    return static_cast<GLContextEGL*>(GLContextProviderEGL::GetGlobalContext());
-}
-
 static GLenum
 GLFormatForImage(gfxImageFormat aFormat)
 {
     switch (aFormat) {
     case gfxImageFormatARGB32:
     case gfxImageFormatRGB24:
         // Thebes only supports RGBX, not packed RGB.
         return LOCAL_GL_RGBA;
@@ -1070,31 +1063,28 @@ public:
             } else {
                 mTextureFormat = FORMAT_B8G8R8A8;
             }
         }
     }
 
     virtual ~TextureImageEGL()
     {
-        GLContext *ctx = mGLContext;
-        if (ctx->IsDestroyed() || !ctx->IsOwningThreadCurrent()) {
-            ctx = ctx->GetSharedContext();
+        if (mGLContext->IsDestroyed() || !mGLContext->IsOwningThreadCurrent()) {
+            return;
         }
 
         // If we have a context, then we need to delete the texture;
         // if we don't have a context (either real or shared),
         // then they went away when the contex was deleted, because it
         // was the only one that had access to it.
-        if (ctx && !ctx->IsDestroyed()) {
-            ctx->MakeCurrent();
-            ctx->fDeleteTextures(1, &mTexture);
-            ReleaseTexImage();
-            DestroyEGLSurface();
-        }
+        mGLContext->MakeCurrent();
+        mGLContext->fDeleteTextures(1, &mTexture);
+        ReleaseTexImage();
+        DestroyEGLSurface();
     }
 
     bool UsingDirectTexture()
     {
         return !!mBackingSurface;
     }
 
     virtual void GetUpdateRegion(nsIntRegion& aForRegion)
@@ -1413,18 +1403,16 @@ GLContextEGL::TileGenFunc(const nsIntSiz
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter);
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
   fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
 
   return teximage.forget();
 }
 
-static nsRefPtr<GLContext> gGlobalContext;
-
 static const EGLint kEGLConfigAttribsOffscreenPBuffer[] = {
     LOCAL_EGL_SURFACE_TYPE,    LOCAL_EGL_PBUFFER_BIT,
     LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
     LOCAL_EGL_NONE
 };
 
 static const EGLint kEGLConfigAttribsRGB16[] = {
     LOCAL_EGL_SURFACE_TYPE,    LOCAL_EGL_WINDOW_BIT,
@@ -1573,30 +1561,26 @@ GLContextProviderEGL::CreateForWindow(ns
     EGLContext eglContext = sEGLLibrary.fGetCurrentContext();
     if (hasNativeContext && eglContext) {
         void* platformContext = eglContext;
         SurfaceCaps caps = SurfaceCaps::Any();
         EGLConfig config = EGL_NO_CONFIG;
         EGLSurface surface = sEGLLibrary.fGetCurrentSurface(LOCAL_EGL_DRAW);
         nsRefPtr<GLContextEGL> glContext =
             new GLContextEGL(caps,
-                             gGlobalContext, false,
+                             nullptr, false,
                              config, surface, eglContext);
 
         if (!glContext->Init())
             return nullptr;
 
         glContext->MakeCurrent();
         glContext->SetIsDoubleBuffered(doubleBuffered);
         glContext->SetPlatformContext(platformContext);
 
-        if (!gGlobalContext) {
-            gGlobalContext = glContext;
-        }
-
         return glContext.forget();
     }
 
     EGLConfig config;
     if (!CreateConfig(&config)) {
         printf_stderr("Failed to create EGL config!\n");
         return nullptr;
     }
@@ -1608,21 +1592,20 @@ GLContextProviderEGL::CreateForWindow(ns
     EGLSurface surface = CreateSurfaceForWindow(aWidget, config);
 #endif
 
     if (!surface) {
         printf_stderr("Failed to create EGLSurface!\n");
         return nullptr;
     }
 
-    GLContextEGL* shareContext = GetGlobalContextEGL();
     SurfaceCaps caps = SurfaceCaps::Any();
     nsRefPtr<GLContextEGL> glContext =
         GLContextEGL::CreateGLContext(caps,
-                                      shareContext, false,
+                                      nullptr, false,
                                       config, surface);
 
     if (!glContext) {
         sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
         return nullptr;
     }
 
     glContext->MakeCurrent();
@@ -1659,21 +1642,20 @@ GLContextEGL::CreateEGLPBufferOffscreenC
     surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(config,
                                                                  LOCAL_EGL_NONE,
                                                                  pbSize);
     if (!surface) {
         NS_WARNING("Failed to create PBuffer for context!");
         return nullptr;
     }
 
-    GLContextEGL* shareContext = GetGlobalContextEGL();
     SurfaceCaps dummyCaps = SurfaceCaps::Any();
     nsRefPtr<GLContextEGL> glContext =
         GLContextEGL::CreateGLContext(dummyCaps,
-                                      shareContext, true,
+                                      nullptr, true,
                                       config, surface);
     if (!glContext) {
         NS_WARNING("Failed to create GLContext from PBuffer");
         sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
         return nullptr;
     }
 
     if (!glContext->Init()) {
@@ -1698,21 +1680,20 @@ GLContextEGL::CreateEGLPixmapOffscreenCo
     EGLSurface surface = 0;
     EGLConfig config = 0;
 
     if (!config) {
         return nullptr;
     }
     MOZ_ASSERT(surface);
 
-    GLContextEGL* shareContext = GetGlobalContextEGL();
     SurfaceCaps dummyCaps = SurfaceCaps::Any();
     nsRefPtr<GLContextEGL> glContext =
         GLContextEGL::CreateGLContext(dummyCaps,
-                                      shareContext, true,
+                                      nullptr, true,
                                       config, surface);
     if (!glContext) {
         NS_WARNING("Failed to create GLContext from XSurface");
         sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
         return nullptr;
     }
 
     if (!glContext->Init()) {
@@ -1739,19 +1720,16 @@ GLContextProviderEGL::CreateOffscreen(co
 
     gfxIntSize dummySize = gfxIntSize(16, 16);
     nsRefPtr<GLContextEGL> glContext;
     glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
 
     if (!glContext)
         return nullptr;
 
-    if (flags & ContextFlagsGlobal)
-        return glContext.forget();
-
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
 SharedTextureHandle
 GLContextProviderEGL::CreateSharedHandle(SharedTextureShareType shareType,
@@ -1775,14 +1753,13 @@ GLContext *
 GLContextProviderEGL::GetGlobalContext(const ContextFlags)
 {
     return nullptr;
 }
 
 void
 GLContextProviderEGL::Shutdown()
 {
-    gGlobalContext = nullptr;
 }
 
 } /* namespace gl */
 } /* namespace mozilla */