Bug 627699 - Port GTK2 to GTK3, gfx patch. r=karlt
authorMartin Stransky <stransky@redhat.com>
Wed, 27 Jun 2012 20:15:32 -0400
changeset 100543 ab0ba9f18f3d17a3d776c7eacb09926699c33a1a
parent 100542 44931b8274b4e659998a447670bfede0d9f6ae2f
child 100544 9f3af99c8297a47f4b894a13c1570b9d09d4717d
push idunknown
push userunknown
push dateunknown
reviewerskarlt
bugs627699
milestone16.0a1
Bug 627699 - Port GTK2 to GTK3, gfx patch. r=karlt
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/src/Makefile.in
gfx/src/X11Util.h
gfx/src/nsDeviceContext.cpp
gfx/tests/gfxFontSelectionTest.cpp
gfx/tests/gfxTextRunPerfTest.cpp
gfx/tests/gfxWordCacheTest.cpp
gfx/thebes/gfxFT2Fonts.cpp
gfx/thebes/gfxGdkNativeRenderer.cpp
gfx/thebes/gfxGdkNativeRenderer.h
gfx/thebes/gfxPangoFonts.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -3,17 +3,17 @@
  * 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 "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_GTK2
+#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()
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1,14 +1,14 @@
 /* -*- 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/. */
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #define GET_NATIVE_WINDOW(aWidget) GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
 #elif defined(MOZ_WIDGET_QT)
 #include <QWidget>
 #define GET_NATIVE_WINDOW(aWidget) static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
 #endif
 
@@ -27,17 +27,17 @@
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
 #include "gfxPlatform.h"
 #include "GLContext.h"
 #include "gfxUtils.h"
 
 #include "gfxCrashReporterUtils.h"
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gfxPlatformGtk.h"
 #endif
 
 namespace mozilla {
 namespace gl {
 
 static bool gIsATI = false;
 static bool gIsChromium = false;
@@ -219,17 +219,17 @@ GLXLibrary::EnsureInitialized()
         NS_WARNING("Couldn't find required entry point in OpenGL shared library");
         return false;
     }
 
     if (HasExtension(extensionsStr, "GLX_EXT_texture_from_pixmap") &&
         GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_texturefrompixmap, 
                                          (GLLibraryLoader::PlatformLookupFunction)&xGetProcAddress))
     {
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
         mUseTextureFromPixmap = gfxPlatformGtk::UseXRender();
 #else
         mUseTextureFromPixmap = true;
 #endif
     } else {
         mUseTextureFromPixmap = false;
         NS_WARNING("Texture from pixmap disabled");
     }
--- a/gfx/src/Makefile.in
+++ b/gfx/src/Makefile.in
@@ -72,17 +72,16 @@ ifdef MOZ_X11
 CPPSRCS += X11Util.cpp
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-DEFINES += -DMOZ_ENABLE_GTK2
 CXXFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_PANGO_CFLAGS)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
 CXXFLAGS += $(CAIRO_FT_CFLAGS)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
--- a/gfx/src/X11Util.h
+++ b/gfx/src/X11Util.h
@@ -5,17 +5,18 @@
  * 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/. */
 
 #ifndef mozilla_X11Util_h
 #define mozilla_X11Util_h
 
 // Utilities common to all X clients, regardless of UI toolkit.
 
-#if defined(MOZ_WIDGET_GTK2)
+#if defined(MOZ_WIDGET_GTK)
+#  include <gdk/gdk.h>
 #  include <gdk/gdkx.h>
 #elif defined(MOZ_WIDGET_QT)
 #include "gfxQtPlatform.h"
 #undef CursorShape
 #  include <X11/Xlib.h>
 #else
 #  error Unknown toolkit
 #endif 
@@ -28,18 +29,18 @@
 namespace mozilla {
 
 /**
  * Return the default X Display created and used by the UI toolkit.
  */
 inline Display*
 DefaultXDisplay()
 {
-#if defined(MOZ_WIDGET_GTK2)
-  return GDK_DISPLAY();
+#if defined(MOZ_WIDGET_GTK)
+  return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
 #elif defined(MOZ_WIDGET_QT)
   return gfxQtPlatform::GetXDisplay();
 #endif
 }
 
 /**
  * Sets *aVisual to point to aDisplay's Visual struct corresponding to
  * aVisualID, and *aDepth to its depth.  When aVisualID is None, these are set
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -18,17 +18,17 @@
 #include "nsIObserverService.h"
 
 #include "gfxImageSurface.h"
 
 #if !XP_MACOSX
 #include "gfxPDFSurface.h"
 #endif
 
-#ifdef MOZ_ENABLE_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gfxPSSurface.h"
 #elif XP_WIN
 #include "gfxWindowsSurface.h"
 #elif defined(XP_OS2)
 #include "gfxOS2Surface.h"
 #elif XP_MACOSX
 #include "gfxQuartzSurface.h"
 #endif
@@ -635,17 +635,17 @@ nsDeviceContext::CalcPrintingSize()
 
 #if defined(MOZ_PDF_PRINTING)
     case gfxASurface::SurfaceTypePDF:
         inPoints = true;
         size = reinterpret_cast<gfxPDFSurface*>(mPrintingSurface.get())->GetSize();
         break;
 #endif
 
-#ifdef MOZ_ENABLE_GTK2
+#ifdef MOZ_WIDGET_GTK
     case gfxASurface::SurfaceTypePS:
         inPoints = true;
         size = reinterpret_cast<gfxPSSurface*>(mPrintingSurface.get())->GetSize();
         break;
 #endif
 
 #ifdef XP_MACOSX
     case gfxASurface::SurfaceTypeQuartz:
--- a/gfx/tests/gfxFontSelectionTest.cpp
+++ b/gfx/tests/gfxFontSelectionTest.cpp
@@ -15,17 +15,17 @@
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
 #endif
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gtk/gtk.h"
 #endif
 
 using namespace mozilla;
 
 enum {
     S_UTF8 = 0,
     S_ASCII = 1
@@ -292,17 +292,17 @@ RunTest (TestEntry *test, gfxContext *ct
     return true;
 }
 
 int
 main (int argc, char **argv) {
     int passed = 0;
     int failed = 0;
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
     gtk_init(&argc, &argv); 
 #endif
 #ifdef XP_MACOSX
     CocoaPoolInit();
 #endif
 
     // Initialize XPCOM
     nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
--- a/gfx/tests/gfxTextRunPerfTest.cpp
+++ b/gfx/tests/gfxTextRunPerfTest.cpp
@@ -17,17 +17,17 @@
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
 #endif
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gtk/gtk.h"
 #endif
 
 using namespace mozilla;
 
 struct TestEntry {
   const char* mFamilies;
   const char* mString;
@@ -101,17 +101,17 @@ RunTest (TestEntry *test, gfxContext *ct
     
     textRun->GetAdvanceWidth(0, length, nsnull);
 }
 
 PRUint32 iterations = 20;
 
 int
 main (int argc, char **argv) {
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
     gtk_init(&argc, &argv); 
 #endif
 #ifdef XP_MACOSX
     CocoaPoolInit();
 #endif
 
     // Initialize XPCOM
     nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
--- a/gfx/tests/gfxWordCacheTest.cpp
+++ b/gfx/tests/gfxWordCacheTest.cpp
@@ -16,17 +16,17 @@
 
 #include "gfxFontTest.h"
 #include "mozilla/Attributes.h"
 
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
 #endif
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gtk/gtk.h"
 #endif
 
 class FrameTextRunCache;
 
 static FrameTextRunCache *gTextRuns = nsnull;
 
 /*
@@ -89,17 +89,17 @@ MakeContext ()
                               gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
    gfxContext *ctx = new gfxContext(surface);
    NS_IF_ADDREF(ctx);
    return ctx;
 }
 
 int
 main (int argc, char **argv) {
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
    gtk_init(&argc, &argv);
 #endif
 #ifdef XP_MACOSX
    CocoaPoolInit();
 #endif
 
    // Initialize XPCOM
    nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
--- a/gfx/thebes/gfxFT2Fonts.cpp
+++ b/gfx/thebes/gfxFT2Fonts.cpp
@@ -1,14 +1,14 @@
 /* -*- 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/. */
 
-#if defined(MOZ_WIDGET_GTK2)
+#if defined(MOZ_WIDGET_GTK)
 #include "gfxPlatformGtk.h"
 #define gfxToolkitPlatform gfxPlatformGtk
 #elif defined(MOZ_WIDGET_QT)
 #include <qfontinfo.h>
 #include "gfxQtPlatform.h"
 #define gfxToolkitPlatform gfxQtPlatform
 #elif defined(XP_WIN)
 #include "gfxWindowsPlatform.h"
@@ -92,17 +92,17 @@ gfxFT2FontGroup::gfxFT2FontGroup(const n
     }
     if (familyArray.Length() == 0) {
 #if defined(MOZ_WIDGET_QT) /* FIXME DFB */
         printf("failde to find a font. sadface\n");
         // We want to get rid of this entirely at some point, but first we need real lists of fonts.
         QFont defaultFont;
         QFontInfo fi (defaultFont);
         familyArray.AppendElement(nsDependentString(static_cast<const PRUnichar *>(fi.family().utf16())));
-#elif defined(MOZ_WIDGET_GTK2)
+#elif defined(MOZ_WIDGET_GTK)
         FcResult result;
         FcChar8 *family = nsnull;
         FcPattern* pat = FcPatternCreate();
         FcPattern *match = FcFontMatch(nsnull, pat, &result);
         if (match)
             FcPatternGetString(match, FC_FAMILY, 0, &family);
         if (family)
             familyArray.AppendElement(NS_ConvertUTF8toUTF16((char*)family));
--- a/gfx/thebes/gfxGdkNativeRenderer.cpp
+++ b/gfx/thebes/gfxGdkNativeRenderer.cpp
@@ -6,16 +6,18 @@
 #include "gfxGdkNativeRenderer.h"
 #include "gfxContext.h"
 #include "gfxPlatformGtk.h"
 
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #include "cairo-xlib.h"
 #include "gfxXlibSurface.h"
+
+#if (MOZ_WIDGET_GTK == 2)
 nsresult
 gfxGdkNativeRenderer::DrawWithXlib(gfxXlibSurface* surface,
                                    nsIntPoint offset,
                                    nsIntRect* clipRects, PRUint32 numClipRects)
 {
     GdkDrawable *drawable = gfxPlatformGtk::GetGdkDrawable(surface);
     if (!drawable) {
         gfxIntSize size = surface->GetSize();
@@ -54,9 +56,13 @@ gfxGdkNativeRenderer::Draw(gfxContext* c
     Visual* visual =
         gdk_x11_visual_get_xvisual(gdk_colormap_get_visual(colormap));
     Screen* screen =
         gdk_x11_screen_get_xscreen(gdk_colormap_get_screen(colormap));
 
     gfxXlibNativeRenderer::Draw(ctx, size, flags, screen, visual, nsnull);
 }
 
+#else
+// TODO GTK3
 #endif
+
+#endif
--- a/gfx/thebes/gfxGdkNativeRenderer.h
+++ b/gfx/thebes/gfxGdkNativeRenderer.h
@@ -30,19 +30,22 @@ public:
     /**
      * Perform the native drawing.
      * @param offsetX draw at this offset into the given drawable
      * @param offsetY draw at this offset into the given drawable
      * @param clipRects an array of rects; clip to the union
      * @param numClipRects the number of rects in the array, or zero if
      * no clipping is required
      */
+
+#if (MOZ_WIDGET_GTK == 2)
     virtual nsresult DrawWithGDK(GdkDrawable * drawable, gint offsetX, 
             gint offsetY, GdkRectangle * clipRects, PRUint32 numClipRects) = 0;
-  
+#endif
+
     enum {
         // If set, then Draw() is opaque, i.e., every pixel in the intersection
         // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
         // will be set and there is no dependence on what the existing pixels
         // in the drawable are set to.
         DRAW_IS_OPAQUE =
 #ifdef MOZ_X11
             gfxXlibNativeRenderer::DRAW_IS_OPAQUE
@@ -60,23 +63,27 @@ public:
     };
 
     /**
      * @param flags see above
      * @param bounds Draw()'s drawing is guaranteed to be restricted to
      * the rectangle (offset.x,offset.y,bounds.width,bounds.height)
      * @param dpy a display to use for the drawing if ctx doesn't have one
      */
+#if (MOZ_WIDGET_GTK == 2)
     void Draw(gfxContext* ctx, nsIntSize size,
               PRUint32 flags, GdkColormap* colormap);
+#endif
 
 private:
 #ifdef MOZ_X11
     // for gfxXlibNativeRenderer:
     virtual nsresult DrawWithXlib(gfxXlibSurface* surface,
                                   nsIntPoint offset,
                                   nsIntRect* clipRects, PRUint32 numClipRects);
 
+#if (MOZ_WIDGET_GTK == 2)
     GdkColormap *mColormap;
 #endif
+#endif
 };
 
 #endif /*GFXGDKNATIVERENDER_H_*/
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -10,17 +10,17 @@
 
 #include "prtypes.h"
 #include "prlink.h"
 #include "gfxTypes.h"
 
 #include "nsTArray.h"
 
 #include "gfxContext.h"
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include "gfxPlatformGtk.h"
 #endif
 #ifdef MOZ_WIDGET_QT
 #include "gfxQtPlatform.h"
 #endif
 #include "gfxPangoFonts.h"
 #include "gfxFT2FontBase.h"
 #include "gfxFT2Utils.h"
@@ -39,17 +39,17 @@
 #include <cairo-ft.h>
 
 #include <fontconfig/fcfreetype.h>
 #include <pango/pango.h>
 #include <pango/pangocairo.h>
 #include <pango/pango-modules.h>
 #include <pango/pangofc-fontmap.h>
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 #include <gdk/gdk.h>
 #endif
 
 #include <math.h>
 
 using namespace mozilla;
 using namespace mozilla::unicode;
 
@@ -945,17 +945,17 @@ gfx_pango_fc_font_get_coverage(PangoFont
     }
 
     return pango_coverage_ref(self->mCoverage);
 }
 
 static PRInt32
 GetDPI()
 {
-#if defined(MOZ_WIDGET_GTK2)
+#if defined(MOZ_WIDGET_GTK)
     return gfxPlatformGtk::GetDPI();
 #elif defined(MOZ_WIDGET_QT)
     return gfxQtPlatform::GetDPI();
 #else
     return 96;
 #endif
 }
 
@@ -1726,17 +1726,17 @@ gfx_pango_font_map_class_init(gfxPangoFo
     // The API for create_font changed between Pango 1.22 and 1.24 so new_font
     // is provided instead.
     fcfontmap_class->new_font = gfx_pango_font_map_new_font;
     // get_resolution is not required.
     // context_key_* virtual functions are only necessary if we want to
     // dynamically respond to changes in the screen cairo_font_options_t.
 }
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 static void ApplyGdkScreenFontOptions(FcPattern *aPattern);
 #endif
 
 // Apply user settings and defaults to pattern in preparation for matching.
 static void
 PrepareSortPattern(FcPattern *aPattern, double aFallbackSize,
                    double aSizeAdjustFactor, bool aIsPrinterFont)
 {
@@ -1763,17 +1763,17 @@ PrepareSortPattern(FcPattern *aPattern, 
        FcPatternAddBool(aPattern, PRINTING_FC_PROPERTY, FcTrue);
     } else {
 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
        cairo_font_options_t *options = cairo_font_options_create();
        cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
        cairo_ft_font_options_substitute(options, aPattern);
        cairo_font_options_destroy(options);
 #endif
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
        ApplyGdkScreenFontOptions(aPattern);
 #endif
     }
 
     // Protect against any fontconfig settings that may have incorrectly
     // modified the pixelsize, and consider aSizeAdjustFactor.
     double size = aFallbackSize;
     if (FcPatternGetDouble(aPattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch
@@ -3140,17 +3140,17 @@ GuessPangoLanguage(nsIAtom *aLanguage)
     nsCAutoString lang;
     gfxFontconfigUtils::GetSampleLangForGroup(aLanguage, &lang);
     if (lang.IsEmpty())
         return NULL;
 
     return pango_language_from_string(lang.get());
 }
 
-#ifdef MOZ_WIDGET_GTK2
+#ifdef MOZ_WIDGET_GTK
 /***************************************************************************
  *
  * This function must be last in the file because it uses the system cairo
  * library.  Above this point the cairo library used is the tree cairo if
  * MOZ_TREE_CAIRO.
  */
 
 #if MOZ_TREE_CAIRO
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -10,17 +10,17 @@
 
 #include "gfxPlatform.h"
 
 #if defined(XP_WIN)
 #include "gfxWindowsPlatform.h"
 #include "gfxD2DSurface.h"
 #elif defined(XP_MACOSX)
 #include "gfxPlatformMac.h"
-#elif defined(MOZ_WIDGET_GTK2)
+#elif defined(MOZ_WIDGET_GTK)
 #include "gfxPlatformGtk.h"
 #elif defined(MOZ_WIDGET_QT)
 #include "gfxQtPlatform.h"
 #elif defined(XP_OS2)
 #include "gfxOS2Platform.h"
 #elif defined(ANDROID)
 #include "gfxAndroidPlatform.h"
 #endif
@@ -254,17 +254,17 @@ gfxPlatform::Init()
     nsCOMPtr<nsIGfxInfo> gfxInfo;
     /* this currently will only succeed on Windows */
     gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
 
 #if defined(XP_WIN)
     gPlatform = new gfxWindowsPlatform;
 #elif defined(XP_MACOSX)
     gPlatform = new gfxPlatformMac;
-#elif defined(MOZ_WIDGET_GTK2)
+#elif defined(MOZ_WIDGET_GTK)
     gPlatform = new gfxPlatformGtk;
 #elif defined(MOZ_WIDGET_QT)
     gPlatform = new gfxQtPlatform;
 #elif defined(XP_OS2)
     gPlatform = new gfxOS2Platform;
 #elif defined(ANDROID)
     gPlatform = new gfxAndroidPlatform;
 #else
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -23,16 +23,19 @@
 #include FT_FREETYPE_H
 #include "gfxFT2Fonts.h"
 #endif
 
 #include "mozilla/gfx/2D.h"
 
 #include "cairo.h"
 #include <gtk/gtk.h>
+#if (MOZ_WIDGET_GTK == 2)
+#include "gtk2compat.h"
+#endif
 
 #include "gfxImageSurface.h"
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #include "gfxXlibSurface.h"
 #include "cairo-xlib.h"
 #include "mozilla/Preferences.h"
 
@@ -61,21 +64,16 @@ typedef nsDataHashtable<nsCStringHashKey
 static FontTable *gPlatformFonts = NULL;
 static FontTable *gPlatformFontAliases = NULL;
 static PrefFontTable *gPrefFonts = NULL;
 static gfxSparseBitSet *gCodepointsWithNoFonts = NULL;
 static FT_Library gPlatformFTLibrary = NULL;
 #endif
 
 static cairo_user_data_key_t cairo_gdk_drawable_key;
-static void do_gdk_drawable_unref (void *data)
-{
-    GdkDrawable *d = (GdkDrawable*) data;
-    g_object_unref (d);
-}
 
 #ifdef MOZ_X11
     bool gfxPlatformGtk::sUseXRender = true;
 #endif
 
 gfxPlatformGtk::gfxPlatformGtk()
 {
     if (!sFontconfigUtils)
@@ -470,32 +468,32 @@ gfxPlatformGtk::GetDPI()
     return sDPI;
 }
 
 gfxImageFormat
 gfxPlatformGtk::GetOffscreenFormat()
 {
     // Make sure there is a screen
     GdkScreen *screen = gdk_screen_get_default();
-    if (screen && gdk_visual_get_system()->depth == 16) {
+    if (screen && gdk_visual_get_depth(gdk_visual_get_system()) == 16) {
         return gfxASurface::ImageFormatRGB16_565;
     }
 
     return gfxASurface::ImageFormatRGB24;
 }
 
 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;
-    Display *dpy = GDK_DISPLAY();
+    Display *dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
     Window root = gdk_x11_get_default_root_xwindow();
 
     Atom retAtom;
     int retFormat;
     unsigned long retLength, retAfter;
     unsigned char *retProperty ;
 
     iccAtom = XInternAtom(dpy, ICC_PROFILE_ATOM_NAME, TRUE);
@@ -685,30 +683,30 @@ gfxPlatformGtk::GetPrefFontEntries(const
 
 void
 gfxPlatformGtk::SetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
 {
     gPrefFonts->Put(aKey, aFontEntryList);
 }
 #endif
 
-
+#if (MOZ_WIDGET_GTK == 2)
 void
 gfxPlatformGtk::SetGdkDrawable(gfxASurface *target,
                                GdkDrawable *drawable)
 {
     if (target->CairoStatus())
         return;
 
     g_object_ref(drawable);
 
     cairo_surface_set_user_data (target->CairoSurface(),
                                  &cairo_gdk_drawable_key,
                                  drawable,
-                                 do_gdk_drawable_unref);
+                                 g_object_unref);
 }
 
 GdkDrawable *
 gfxPlatformGtk::GetGdkDrawable(gfxASurface *target)
 {
     if (target->CairoStatus())
         return NULL;
 
@@ -730,16 +728,17 @@ gfxPlatformGtk::GetGdkDrawable(gfxASurfa
     if (result) {
         SetGdkDrawable(target, result);
         return result;
     }
 #endif
 
     return NULL;
 }
+#endif
 
 RefPtr<ScaledFont>
 gfxPlatformGtk::GetScaledFontForFont(gfxFont *aFont)
 {
     NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font");
     NativeFont nativeFont;
     nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
     nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions();
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -5,19 +5,21 @@
 
 #ifndef GFX_PLATFORM_GTK_H
 #define GFX_PLATFORM_GTK_H
 
 #include "gfxPlatform.h"
 #include "nsAutoRef.h"
 #include "nsTArray.h"
 
+#if (MOZ_WIDGET_GTK == 2)
 extern "C" {
     typedef struct _GdkDrawable GdkDrawable;
 }
+#endif
 
 class gfxFontconfigUtils;
 #ifndef MOZ_PANGO
 class FontFamily;
 class FontEntry;
 typedef struct FT_LibraryRec_ *FT_Library;
 #endif
 
@@ -85,19 +87,21 @@ public:
     bool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList);
     void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
 #endif
 
 #ifndef MOZ_PANGO
     FT_Library GetFTLibrary();
 #endif
 
+#if (MOZ_WIDGET_GTK == 2)
     static void SetGdkDrawable(gfxASurface *target,
                                GdkDrawable *drawable);
     static GdkDrawable *GetGdkDrawable(gfxASurface *target);
+#endif
 
     static PRInt32 GetDPI();
 
     static bool UseXRender() {
 #if defined(MOZ_X11) && defined(MOZ_PLATFORM_MAEMO)
         // XRender is not accelerated on the Maemo at the moment, and 
         // X server pixman is out of our control; it's likely to be 
         // older than (our) cairo's.   So fall back on software