Bug 788319, fixups to make EGL work with gtk. r=bjacob
authorNicholas Cameron <ncameron@mozilla.com>
Tue, 30 Apr 2013 15:16:04 +1200
changeset 130294 476d5bc13806d610f8ad094bf13b583a5233c0e5
parent 130293 9018a6a45065cd57de2418938356c56af5b7b1b1
child 130295 a9a56206a0dc0b3ce880cf770f123b2ba6bc6b02
push id27289
push userncameron@mozilla.com
push dateTue, 30 Apr 2013 03:16:39 +0000
treeherdermozilla-inbound@a9a56206a0dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs788319
milestone23.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 788319, fixups to make EGL work with gtk. r=bjacob
gfx/gl/GLContextProvider.h
gfx/layers/opengl/CanvasLayerOGL.cpp
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
widget/xpwidgets/nsBaseWidget.cpp
--- a/gfx/gl/GLContextProvider.h
+++ b/gfx/gl/GLContextProvider.h
@@ -39,36 +39,35 @@ namespace gl {
 #undef GL_CONTEXT_PROVIDER_NAME
 #define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderCGL
 #endif
 
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO) || defined(XP_WIN)
 #define GL_CONTEXT_PROVIDER_NAME GLContextProviderEGL
 #include "GLContextProviderImpl.h"
 #undef GL_CONTEXT_PROVIDER_NAME
-
 #ifndef GL_CONTEXT_PROVIDER_DEFAULT
 #define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderEGL
 #endif
 #endif
 
+#ifdef MOZ_GL_PROVIDER
+#define GL_CONTEXT_PROVIDER_NAME MOZ_GL_PROVIDER
+#include "GLContextProviderImpl.h"
+#undef GL_CONTEXT_PROVIDER_NAME
+#define GL_CONTEXT_PROVIDER_DEFAULT MOZ_GL_PROVIDER
+#endif
+
 #if defined(MOZ_X11) && !defined(GL_CONTEXT_PROVIDER_DEFAULT)
 #define GL_CONTEXT_PROVIDER_NAME GLContextProviderGLX
 #include "GLContextProviderImpl.h"
 #undef GL_CONTEXT_PROVIDER_NAME
 #define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderGLX
 #endif
 
-#ifdef MOZ_GL_PROVIDER
-#define GL_CONTEXT_PROVIDER_NAME MOZ_GL_PROVIDER
-#include "GLContextProviderImpl.h"
-#undef GL_CONTEXT_PROVIDER_NAME
-#define GL_CONTEXT_PROVIDER_DEFAULT MOZ_GL_PROVIDER
-#endif
-
 #ifdef GL_CONTEXT_PROVIDER_DEFAULT
 typedef GL_CONTEXT_PROVIDER_DEFAULT GLContextProvider;
 #else
 typedef GLContextProviderNull GLContextProvider;
 #endif
 
 #undef IN_GL_CONTEXT_PROVIDER_H
 
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -28,17 +28,17 @@
 #include "gfxWindowsSurface.h"
 #include "WGLLibrary.h"
 #endif
 
 #ifdef XP_MACOSX
 #include <OpenGL/OpenGL.h>
 #endif
 
-#ifdef MOZ_X11
+#ifdef GL_PROVIDER_GLX
 #include "gfxXlibSurface.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
@@ -121,17 +121,17 @@ CanvasLayerOGL::Initialize(const Data& a
     return;
   } else if (aData.mDrawTarget) {
     mDrawTarget = aData.mDrawTarget;
     mCanvasSurface = gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget);
     mNeedsYFlip = false;
   } else if (aData.mSurface) {
     mCanvasSurface = aData.mSurface;
     mNeedsYFlip = false;
-#if defined(MOZ_X11) && !defined(MOZ_PLATFORM_MAEMO)
+#if defined(GL_PROVIDER_GLX)
     if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
         gfxXlibSurface *xsurf = static_cast<gfxXlibSurface*>(aData.mSurface);
         mPixmap = xsurf->GetGLXPixmap();
         if (mPixmap) {
             if (aData.mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
                 mLayerProgram = gl::RGBALayerProgramType;
             } else {
                 mLayerProgram = gl::RGBXLayerProgramType;
@@ -192,17 +192,17 @@ CanvasLayerOGL::UpdateSurface()
   if (!IsDirty())
     return;
   Painted();
 
   if (mDestroyed || mDelayedUpdates) {
     return;
   }
 
-#if defined(MOZ_X11) && !defined(MOZ_PLATFORM_MAEMO)
+#if defined(GL_PROVIDER_GLX)
   if (mPixmap) {
     return;
   }
 #endif
 
   gfxASurface* updatedSurface = nullptr;
   gfxImageSurface* temporarySurface = nullptr;
   bool nothingToShow = false;
@@ -304,17 +304,17 @@ CanvasLayerOGL::RenderLayer(int aPreviou
                                    drawRect.TopLeft());
     mTexture = mUploadTexture;
   }
 
   if (!program) {
     program = mOGLManager->GetProgram(mLayerProgram, GetMaskLayer());
   }
 
-#if defined(MOZ_X11) && !defined(MOZ_PLATFORM_MAEMO)
+#if defined(GL_PROVIDER_GLX)
   if (mPixmap && !mDelayedUpdates) {
     sDefGLXLib.BindTexImage(mPixmap);
   }
 #endif
 
   gl()->ApplyFilterToBoundTexture(mFilter);
 
   program->Activate();
@@ -330,17 +330,17 @@ CanvasLayerOGL::RenderLayer(int aPreviou
   program->LoadMask(GetMaskLayer());
 
   if (gl()->CanUploadNonPowerOfTwo()) {
     mOGLManager->BindAndDrawQuad(program, mNeedsYFlip ? true : false);
   } else {
     mOGLManager->BindAndDrawQuadWithTextureRect(program, drawRect, drawRect.Size());
   }
 
-#if defined(MOZ_X11) && !defined(MOZ_PLATFORM_MAEMO)
+#if defined(GL_PROVIDER_GLX)
   if (mPixmap && !mDelayedUpdates) {
     sDefGLXLib.ReleaseTexImage(mPixmap);
   }
 #endif
 }
 
 void
 CanvasLayerOGL::CleanupResources()
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -449,17 +449,17 @@ ImageLayerOGL::AllocateTexturesCairo(Cai
   mozilla::gl::GLContext *gl = texture.GetGLContext();
   gl->MakeCurrent();
 
   GLuint tex = texture.GetTextureID();
   gl->fActiveTexture(LOCAL_GL_TEXTURE0);
 
   SetClamping(gl, tex);
 
-#if defined(MOZ_X11) && !defined(MOZ_PLATFORM_MAEMO)
+#if defined(GL_PROVIDER_GLX)
   if (aImage->mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
     gfxXlibSurface *xsurf =
       static_cast<gfxXlibSurface*>(aImage->mSurface.get());
     GLXPixmap pixmap = xsurf->GetGLXPixmap();
     if (pixmap) {
       if (aImage->mSurface->GetContentType()
           == gfxASurface::CONTENT_COLOR_ALPHA) {
         backendData->mLayerProgram = gl::RGBALayerProgramType;
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -475,16 +475,34 @@ gfxPlatformGtk::GetOffscreenFormat()
     GdkScreen *screen = gdk_screen_get_default();
     if (screen && gdk_visual_get_depth(gdk_visual_get_system()) == 16) {
         return gfxASurface::ImageFormatRGB16_565;
     }
 
     return gfxASurface::ImageFormatRGB24;
 }
 
+static int sDepth = 0;
+
+int
+gfxPlatformGtk::GetScreenDepth() const
+{
+    if (!sDepth) {
+        GdkScreen *screen = gdk_screen_get_default();
+        if (screen) {
+            sDepth = gdk_visual_get_depth(gdk_visual_get_system());
+        } else {
+            sDepth = 24;
+        }
+
+    }
+
+    return sDepth;
+}
+
 qcms_profile *
 gfxPlatformGtk::GetPlatformCMSOutputProfile()
 {
 #ifdef MOZ_X11
     const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
     const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
 
     Atom edidAtom, iccAtom;
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -118,16 +118,18 @@ public:
         return sUseXRender;
 #else
         return false;
 #endif
     }
 
     virtual gfxImageFormat GetOffscreenFormat();
 
+    virtual int GetScreenDepth() const;
+
 protected:
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 #ifdef MOZ_X11
     static bool sUseXRender;
 #endif
--- a/widget/xpwidgets/nsBaseWidget.cpp
+++ b/widget/xpwidgets/nsBaseWidget.cpp
@@ -859,17 +859,19 @@ nsBaseWidget::ComputeShouldAccelerate(bo
 
   /* use the window acceleration flag */
   return aDefault;
 }
 
 CompositorParent* nsBaseWidget::NewCompositorParent(int aSurfaceWidth,
                                                     int aSurfaceHeight)
 {
-    return new CompositorParent(this, false, aSurfaceWidth, aSurfaceHeight);
+  // Even if we are using EGL, unless we are on Android, we don't want
+  // CompositorParent to think we are, so we pass aRenderToEGLSurface = false.
+  return new CompositorParent(this, false, aSurfaceWidth, aSurfaceHeight);
 }
 
 void nsBaseWidget::CreateCompositor()
 {
   nsIntRect rect;
   GetBounds(rect);
   CreateCompositor(rect.width, rect.height);
 }