Bug 814159 - Part 1: remove X11, Qt, and unused Gonk code from GLContextProviderEGL.cpp - r=benwa
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 11 Oct 2013 09:16:44 -0400
changeset 150485 fefe4254ee1797d5544ee2819962ed388ba9e2f2
parent 150484 a9f84f6cbc71707656775c200eb592408dfd870b
child 150486 86a2a0fe62902c2ae2557ab1385c4d969c58a15d
push id3001
push userryanvm@gmail.com
push dateFri, 11 Oct 2013 21:03:10 +0000
treeherderfx-team@9ab188de8245 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenwa
bugs814159
milestone27.0a1
Bug 814159 - Part 1: remove X11, Qt, and unused Gonk code from GLContextProviderEGL.cpp - r=benwa
gfx/gl/GLContext.h
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -2489,17 +2489,16 @@ public:
                                    GraphicsFilter aFilter);
 
     virtual bool BindExternalBuffer(GLuint texture, void* buffer) { return false; }
     virtual bool UnbindExternalBuffer(GLuint texture) { return false; }
 
 #ifdef MOZ_WIDGET_GONK
     virtual EGLImage CreateEGLImageForNativeBuffer(void* buffer) = 0;
     virtual void DestroyEGLImage(EGLImage image) = 0;
-    virtual EGLImage GetNullEGLImage() = 0;
 #endif
 
     virtual already_AddRefed<TextureImage>
     CreateDirectTextureImage(android::GraphicBuffer* aBuffer, GLenum aWrapMode)
     { return nullptr; }
 
     // Before reads from offscreen texture
     void GuaranteeResolve();
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -1,41 +1,28 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GLContext.h"
 #include "mozilla/Util.h"
-// please add new includes below Qt, otherwise it break Qt build due malloc wrapper conflicts
 
 #if defined(XP_UNIX)
 
 #ifdef MOZ_WIDGET_GTK
 #include <gdk/gdkx.h>
 // we're using default display for now
 #define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
-#elif defined(MOZ_WIDGET_QT)
-#include <QtOpenGL/QGLContext>
-#define GLdouble_defined 1
-// we're using default display for now
-#define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
 #elif defined(MOZ_WIDGET_GONK)
 #define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_WINDOW))
 #include "HwcComposer2D.h"
 #include "libdisplay/GonkDisplay.h"
 #endif
 
-#if defined(MOZ_X11)
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include "mozilla/X11Util.h"
-#include "gfxXlibSurface.h"
-#endif
-
 #if defined(ANDROID)
 /* from widget */
 #if defined(MOZ_WIDGET_ANDROID)
 #include "AndroidBridge.h"
 #include "nsSurfaceTexture.h"
 #endif
 
 #include <android/log.h>
@@ -151,21 +138,16 @@ static GLLibraryEGL sEGLLibrary;
 
 #ifndef MOZ_ANDROID_OMTC
 static EGLSurface
 CreateSurfaceForWindow(nsIWidget *aWidget, EGLConfig config);
 #endif
 
 static bool
 CreateConfig(EGLConfig* aConfig);
-#ifdef MOZ_X11
-
-static EGLConfig
-CreateEGLSurfaceForXSurface(gfxASurface* aSurface, EGLConfig* aConfig = nullptr);
-#endif
 
 static EGLint gContextAttribs[] = {
     LOCAL_EGL_CONTEXT_CLIENT_VERSION, 2,
     LOCAL_EGL_NONE
 };
 
 static EGLint gContextAttribsRobustness[] = {
     LOCAL_EGL_CONTEXT_CLIENT_VERSION, 2,
@@ -439,36 +421,16 @@ public:
                                         LOCAL_EGL_NATIVE_BUFFER_ANDROID,
                                         buffer, attrs);
     }
 
     void DestroyEGLImage(EGLImage image) MOZ_OVERRIDE
     {
         sEGLLibrary.fDestroyImage(EGL_DISPLAY(), image);
     }
-
-    EGLImage GetNullEGLImage() MOZ_OVERRIDE
-    {
-        if (!mNullGraphicBuffer.get()) {
-            mNullGraphicBuffer
-              = new android::GraphicBuffer(
-                  1, 1,
-                  PIXEL_FORMAT_RGB_565,
-                  GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER);
-            EGLint attrs[] = {
-                LOCAL_EGL_NONE, LOCAL_EGL_NONE
-            };
-            mNullEGLImage = sEGLLibrary.fCreateImage(EGL_DISPLAY(),
-                                                     EGL_NO_CONTEXT,
-                                                     LOCAL_EGL_NATIVE_BUFFER_ANDROID,
-                                                     mNullGraphicBuffer->getNativeBuffer(),
-                                                     attrs);
-        }
-        return mNullEGLImage;
-    }
 #endif
 
     virtual void MakeCurrent_EGLSurface(void* surf) {
         EGLSurface eglSurface = (EGLSurface)surf;
         if (!eglSurface)
             eglSurface = mSurface;
 
         if (eglSurface == mCurSurface)
@@ -489,42 +451,17 @@ public:
     }
 
     bool MakeCurrentImpl(bool aForce = false) {
         bool succeeded = true;
 
         // Assume that EGL has the same problem as WGL does,
         // where MakeCurrent with an already-current context is
         // still expensive.
-#ifndef MOZ_WIDGET_QT
-        if (!mSurface) {
-            // We need to be able to bind NO_SURFACE when we don't
-            // have access to a surface. We won't be drawing to the screen
-            // but we will be able to do things like resource releases.
-            succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
-                                                 EGL_NO_SURFACE, EGL_NO_SURFACE,
-                                                 EGL_NO_CONTEXT);
-            if (!succeeded && sEGLLibrary.fGetError() == LOCAL_EGL_CONTEXT_LOST) {
-                mContextLost = true;
-                NS_WARNING("EGL context has been lost.");
-            }
-            NS_ASSERTION(succeeded, "Failed to make GL context current!");
-            return succeeded;
-        }
-#endif
         if (aForce || sEGLLibrary.fGetCurrentContext() != mContext) {
-#ifdef MOZ_WIDGET_QT
-            // Shared Qt GL context need to be informed about context switch
-            if (mSharedContext) {
-                QGLContext* qglCtx = static_cast<QGLContext*>(static_cast<GLContextEGL*>(mSharedContext.get())->mPlatformContext);
-                if (qglCtx) {
-                    qglCtx->doneCurrent();
-                }
-            }
-#endif
             succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
                                                  mCurSurface, mCurSurface,
                                                  mContext);
             
             int eglError = sEGLLibrary.fGetError();
             if (!succeeded) {
                 if (eglError == LOCAL_EGL_CONTEXT_LOST) {
                     mContextLost = true;
@@ -540,23 +477,16 @@ public:
 
         return succeeded;
     }
 
     virtual bool IsCurrent() {
         return sEGLLibrary.fGetCurrentContext() == mContext;
     }
 
-#ifdef MOZ_WIDGET_QT
-    virtual bool
-    RenewSurface() {
-        /* We don't support renewing on QT because we don't create the surface ourselves */
-        return false;
-    }
-#else
     virtual bool
     RenewSurface() {
         sEGLLibrary.fMakeCurrent(EGL_DISPLAY(), EGL_NO_SURFACE, EGL_NO_SURFACE,
                                  EGL_NO_CONTEXT);
         if (!mSurface) {
 #ifdef MOZ_ANDROID_OMTC
             mSurface = mozilla::AndroidBridge::Bridge()->ProvideEGLSurface();
             if (!mSurface) {
@@ -567,17 +497,16 @@ public:
             CreateConfig(&config);
             mSurface = CreateSurfaceForWindow(nullptr, config);
 #endif
         }
         return sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
                                         mSurface, mSurface,
                                         mContext);
     }
-#endif
 
     virtual void
     ReleaseSurface() {
         if (mSurface && !mPlatformContext) {
             sEGLLibrary.fMakeCurrent(EGL_DISPLAY(), EGL_NO_SURFACE, EGL_NO_SURFACE,
                                      EGL_NO_CONTEXT);
             sEGLLibrary.fDestroySurface(EGL_DISPLAY(), mSurface);
             mSurface = nullptr;
@@ -682,28 +611,16 @@ protected:
     bool mBound;
 
     bool mIsPBuffer;
     bool mIsDoubleBuffered;
     bool mCanBindToTexture;
     bool mShareWithEGLImage;
 #ifdef MOZ_WIDGET_GONK
     nsRefPtr<HwcComposer2D> mHwc;
-
-    /* mNullEGLImage and mNullGraphicBuffer are a hack to unattach a gralloc buffer
-     * from a texture, which we don't know how to do otherwise (at least in the
-     * TEXTURE_EXTERNAL case --- in the TEXTURE_2D case we could also use TexImage2D).
-     *
-     * So mNullGraphicBuffer will be initialized once to be a 1x1 gralloc buffer,
-     * and mNullEGLImage will be initialized once to be an EGLImage wrapping it.
-     *
-     * This happens in GetNullEGLImage().
-     */
-    EGLImage mNullEGLImage;
-    android::sp<android::GraphicBuffer> mNullGraphicBuffer;
 #endif
 
     // A dummy texture ID that can be used when we need a texture object whose
     // images we're going to define with EGLImageTargetTexture2D.
     GLuint mTemporaryEGLImageTexture;
 
     static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
                                                            EGLenum bindToTextureFormat,
@@ -1229,22 +1146,16 @@ public:
         return mUpdateSurface;
     }
 
     virtual void EndUpdate()
     {
         NS_ASSERTION(!!mUpdateSurface, "EndUpdate() without BeginUpdate()?");
 
         if (mBackingSurface && mUpdateSurface == mBackingSurface) {
-#ifdef MOZ_X11
-            if (mBackingSurface->GetType() == gfxSurfaceTypeXlib) {
-                FinishX(DefaultXDisplay());
-            }
-#endif
-
             mBackingSurface->SetDeviceOffset(gfxPoint(0, 0));
             mTextureState = Valid;
             mUpdateSurface = nullptr;
             return;
         }
 
         //printf_stderr("EndUpdate: slow path");
 
@@ -1420,43 +1331,17 @@ public:
     virtual already_AddRefed<gfxASurface> GetBackingSurface()
     {
         nsRefPtr<gfxASurface> copy = mBackingSurface;
         return copy.forget();
     }
 
     virtual bool CreateEGLSurface(gfxASurface* aSurface)
     {
-#ifdef MOZ_X11
-        if (!aSurface) {
-            NS_WARNING("no surface");
-            return false;
-        }
-
-        if (aSurface->GetType() != gfxSurfaceTypeXlib) {
-            NS_WARNING("wrong surface type, must be xlib");
-            return false;
-        }
-
-        if (mSurface) {
-            return true;
-        }
-
-        EGLSurface surface = CreateEGLSurfaceForXSurface(aSurface, &mConfig);
-
-        if (!surface) {
-            NS_WARNING("couldn't find X config for surface");
-            return false;
-        }
-
-        mSurface = surface;
-        return true;
-#else
         return false;
-#endif
     }
 
     virtual void DestroyEGLSurface(void)
     {
         if (!mSurface)
             return;
 
         sEGLLibrary.fDestroySurface(EGL_DISPLAY(), mSurface);
@@ -1464,65 +1349,17 @@ public:
     }
 
     virtual bool CreateBackingSurface(const gfxIntSize& aSize)
     {
         ReleaseTexImage();
         DestroyEGLSurface();
         mBackingSurface = nullptr;
 
-#ifdef MOZ_X11
-        Display* dpy = DefaultXDisplay();
-        XRenderPictFormat* renderFMT =
-            gfxXlibSurface::FindRenderFormat(dpy, mUpdateFormat);
-
-        nsRefPtr<gfxXlibSurface> xsurface =
-            gfxXlibSurface::Create(DefaultScreenOfDisplay(dpy),
-                                   renderFMT,
-                                   gfxIntSize(aSize.width, aSize.height));
-
-        XSync(dpy, False);
-        mConfig = nullptr;
-
-        if (sEGLLibrary.HasKHRImagePixmap() &&
-            mGLContext->IsExtensionSupported(GLContext::OES_EGL_image))
-        {
-            mEGLImage =
-                sEGLLibrary.fCreateImage(EGL_DISPLAY(),
-                                         EGL_NO_CONTEXT,
-                                         LOCAL_EGL_NATIVE_PIXMAP,
-                                         (EGLClientBuffer)xsurface->XDrawable(),
-                                         nullptr);
-
-            if (!mEGLImage) {
-                printf_stderr("couldn't create EGL image: ERROR (0x%04x)\n", sEGLLibrary.fGetError());
-                return false;
-            }
-            mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
-            mGLContext->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, mEGLImage);
-            sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mEGLImage);
-            mEGLImage = nullptr;
-        } else {
-            if (!CreateEGLSurface(xsurface)) {
-                printf_stderr("ProviderEGL Failed create EGL surface: ERROR (0x%04x)\n", sEGLLibrary.fGetError());
-                return false;
-            }
-
-            if (!BindTexImage()) {
-                printf_stderr("ProviderEGL Failed to bind teximage: ERROR (0x%04x)\n", sEGLLibrary.fGetError());
-                return false;
-            }
-        }
-
-        mBackingSurface = xsurface;
-
-        return mBackingSurface != nullptr;
-#endif
-
-        return mBackingSurface != nullptr;
+        return false;
     }
 
 protected:
     typedef gfxImageFormat ImageFormat;
 
     GLContext* mGLContext;
 
     nsIntRect mUpdateRect;
@@ -1732,30 +1569,16 @@ GLContextProviderEGL::CreateForWindow(ns
 
     bool doubleBuffered = true;
 
     bool hasNativeContext = aWidget->HasGLContext();
     EGLContext eglContext = sEGLLibrary.fGetCurrentContext();
     if (hasNativeContext && eglContext) {
         void* platformContext = eglContext;
         SurfaceCaps caps = SurfaceCaps::Any();
-#ifdef MOZ_WIDGET_QT
-        int depth = gfxPlatform::GetPlatform()->GetScreenDepth();
-        QGLContext* context = const_cast<QGLContext*>(QGLContext::currentContext());
-        if (context && context->device()) {
-            depth = context->device()->depth();
-        }
-        const QGLFormat& format = context->format();
-        doubleBuffered = format.doubleBuffer();
-        platformContext = context;
-        caps.bpp16 = depth == 16 ? true : false;
-        caps.alpha = format.rgba();
-        caps.depth = format.depth();
-        caps.stencil = format.stencil();
-#endif
         EGLConfig config = EGL_NO_CONFIG;
         EGLSurface surface = sEGLLibrary.fGetCurrentSurface(LOCAL_EGL_DRAW);
         nsRefPtr<GLContextEGL> glContext =
             new GLContextEGL(caps,
                              gGlobalContext, false,
                              config, surface, eglContext);
 
         if (!glContext->Init())
@@ -1857,130 +1680,29 @@ GLContextEGL::CreateEGLPBufferOffscreenC
         NS_WARNING("Failed to initialize GLContext!");
         // GLContextEGL::dtor will destroy |surface| for us.
         return nullptr;
     }
 
     return glContext.forget();
 }
 
-#ifdef MOZ_X11
-EGLSurface
-CreateEGLSurfaceForXSurface(gfxASurface* aSurface, EGLConfig* aConfig)
-{
-    gfxXlibSurface* xsurface = static_cast<gfxXlibSurface*>(aSurface);
-    bool opaque =
-        aSurface->GetContentType() == GFX_CONTENT_COLOR;
-
-    static EGLint pixmap_config_rgb[] = {
-        LOCAL_EGL_TEXTURE_TARGET,       LOCAL_EGL_TEXTURE_2D,
-        LOCAL_EGL_TEXTURE_FORMAT,       LOCAL_EGL_TEXTURE_RGB,
-        LOCAL_EGL_NONE
-    };
-
-    static EGLint pixmap_config_rgba[] = {
-        LOCAL_EGL_TEXTURE_TARGET,       LOCAL_EGL_TEXTURE_2D,
-        LOCAL_EGL_TEXTURE_FORMAT,       LOCAL_EGL_TEXTURE_RGBA,
-        LOCAL_EGL_NONE
-    };
-
-    EGLSurface surface = nullptr;
-    if (aConfig && *aConfig) {
-        if (opaque)
-            surface = sEGLLibrary.fCreatePixmapSurface(EGL_DISPLAY(), *aConfig,
-                                                       (EGLNativePixmapType)xsurface->XDrawable(),
-                                                       pixmap_config_rgb);
-        else
-            surface = sEGLLibrary.fCreatePixmapSurface(EGL_DISPLAY(), *aConfig,
-                                                       (EGLNativePixmapType)xsurface->XDrawable(),
-                                                       pixmap_config_rgba);
-
-        if (surface != EGL_NO_SURFACE)
-            return surface;
-    }
-
-    EGLConfig configs[32];
-    int numConfigs = 32;
-
-    static EGLint pixmap_config[] = {
-        LOCAL_EGL_SURFACE_TYPE,         LOCAL_EGL_PIXMAP_BIT,
-        LOCAL_EGL_RENDERABLE_TYPE,      LOCAL_EGL_OPENGL_ES2_BIT,
-        LOCAL_EGL_DEPTH_SIZE,           0,
-        LOCAL_EGL_BIND_TO_TEXTURE_RGB,  LOCAL_EGL_TRUE,
-        LOCAL_EGL_NONE
-    };
-
-    if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(),
-                                   pixmap_config,
-                                   configs, numConfigs, &numConfigs)
-        || numConfigs == 0)
-    {
-        NS_WARNING("No EGL Config for pixmap!");
-        return nullptr;
-    }
-
-    int i = 0;
-    for (i = 0; i < numConfigs; ++i) {
-        if (opaque)
-            surface = sEGLLibrary.fCreatePixmapSurface(EGL_DISPLAY(), configs[i],
-                                                       (EGLNativePixmapType)xsurface->XDrawable(),
-                                                       pixmap_config_rgb);
-        else
-            surface = sEGLLibrary.fCreatePixmapSurface(EGL_DISPLAY(), configs[i],
-                                                       (EGLNativePixmapType)xsurface->XDrawable(),
-                                                       pixmap_config_rgba);
-
-        if (surface != EGL_NO_SURFACE)
-            break;
-    }
-
-    if (!surface) {
-        NS_WARNING("Failed to CreatePixmapSurface!");
-        return nullptr;
-    }
-
-    if (aConfig)
-        *aConfig = configs[i];
-
-    return surface;
-}
-#endif
-
 already_AddRefed<GLContextEGL>
 GLContextEGL::CreateEGLPixmapOffscreenContext(const gfxIntSize& size)
 {
     gfxASurface *thebesSurface = nullptr;
     EGLNativePixmapType pixmap = 0;
 
-#ifdef MOZ_X11
-    nsRefPtr<gfxXlibSurface> xsurface =
-        gfxXlibSurface::Create(DefaultScreenOfDisplay(DefaultXDisplay()),
-                               gfxXlibSurface::FindRenderFormat(DefaultXDisplay(),
-                                                                gfxImageFormatRGB24),
-                               size);
-
-    // XSync required after gfxXlibSurface::Create, otherwise EGL will fail with BadDrawable error
-    XSync(DefaultXDisplay(), False);
-    if (xsurface->CairoStatus() != 0)
-        return nullptr;
-
-    thebesSurface = xsurface;
-    pixmap = (EGLNativePixmapType)xsurface->XDrawable();
-#endif
-
     if (!pixmap) {
         return nullptr;
     }
 
     EGLSurface surface = 0;
     EGLConfig config = 0;
 
-#ifdef MOZ_X11
-    surface = CreateEGLSurfaceForXSurface(thebesSurface, &config);
-#endif
     if (!config) {
         return nullptr;
     }
     MOZ_ASSERT(surface);
 
     GLContextEGL* shareContext = GetGlobalContextEGL();
     SurfaceCaps dummyCaps = SurfaceCaps::Any();
     nsRefPtr<GLContextEGL> glContext =
@@ -2012,21 +1734,17 @@ GLContextProviderEGL::CreateOffscreen(co
                                       ContextFlags flags)
 {
     if (!sEGLLibrary.EnsureInitialized()) {
         return nullptr;
     }
 
     gfxIntSize dummySize = gfxIntSize(16, 16);
     nsRefPtr<GLContextEGL> glContext;
-#if defined(MOZ_X11)
-    glContext = GLContextEGL::CreateEGLPixmapOffscreenContext(dummySize);
-#else
     glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
-#endif
 
     if (!glContext)
         return nullptr;
 
     if (flags & ContextFlagsGlobal)
         return glContext.forget();
 
     if (!glContext->InitOffscreen(size, caps))