cairo_draw_with_xlib should provide a non-NULL visual to callback. b=445250 r=vlad
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 17 Jul 2008 13:22:50 +1200
changeset 15986 f84c0fa102900d41f3402b7ee5384e415a72fe83
parent 15985 568dc709dfda48e2668b414db842a89d3c62b2a9
child 15987 cd504b4a2257524f68f1b96c1034735d44785916
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs445250
milestone1.9.1a1pre
cairo_draw_with_xlib should provide a non-NULL visual to callback. b=445250 r=vlad
gfx/thebes/src/cairo-xlib-utils.c
widget/src/gtk2/nsNativeThemeGTK.cpp
--- a/gfx/thebes/src/cairo-xlib-utils.c
+++ b/gfx/thebes/src/cairo-xlib-utils.c
@@ -293,18 +293,23 @@ static cairo_bool_t
     /* Check that the display is supported */  
     screen = cairo_xlib_surface_get_screen (target);
     if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN) &&
         screen != DefaultScreenOfDisplay (default_display)) {
         CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default display\n");
         return False;
     }
         
-    /* Check that the visual is supported */  
+    /* Check that there is a visual */
     visual = cairo_xlib_surface_get_visual (target);
+    if (!visual) {
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: no Visual for surface\n");
+        return False;
+    }        
+    /* Check that the visual is supported */
     if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL) &&
         DefaultVisualOfScreen (screen) != visual) {
         CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default visual\n");
         return False;
     }
   
     /* we're good to go! */
     CAIRO_XLIB_DRAWING_NOTE("TAKING FAST PATH\n");
@@ -337,16 +342,17 @@ static cairo_surface_t *
     
     /* make the temporary surface match target_drawable to the extent supported
        by the native rendering code */
     if (target_drawable) {
         Screen *target_screen = cairo_xlib_surface_get_screen (target);
         Visual *target_visual = cairo_xlib_surface_get_visual (target);
         if ((target_screen == screen ||
              (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN)) &&
+            target_visual &&
             (target_visual == DefaultVisualOfScreen (target_screen) ||
              (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL))) {
             drawable = target_drawable;
             dpy = cairo_xlib_surface_get_display (target);
             visual = target_visual;
             depth = cairo_xlib_surface_get_depth (target);
         }
     }
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -662,29 +662,28 @@ ThemeRenderer::NativeDraw(Screen* screen
   if (gdkPixmap) {
     g_object_ref(G_OBJECT(gdkPixmap));
   } else {
     // XXX gtk+2.10 has gdk_pixmap_foreign_new_for_screen which would not
     // use XGetGeometry.
     gdkPixmap = gdk_pixmap_foreign_new_for_display(gdkDpy, drawable);
     if (!gdkPixmap)
       return NS_ERROR_FAILURE;
-    if (visual) {
-      // We requested that gfxXlibNativeRenderer give us the default screen
-      GdkScreen* gdkScreen = gdk_display_get_default_screen(gdkDpy);
-      NS_ASSERTION(screen == GDK_SCREEN_XSCREEN(gdkScreen),
-                   "'screen' should be the default Screen");
-      // GDK requires a GdkColormap to be set on the GdkPixmap.
-      GdkVisual* gdkVisual =
-        gdk_x11_screen_lookup_visual(gdkScreen, visual->visualid);
-      GdkColormap* gdkColormap =
-        gdk_x11_colormap_foreign_new(gdkVisual, colormap);
-      gdk_drawable_set_colormap(gdkPixmap, gdkColormap);
-      g_object_unref(G_OBJECT(gdkColormap));
-    }
+
+    // We requested that gfxXlibNativeRenderer give us the default screen
+    GdkScreen* gdkScreen = gdk_display_get_default_screen(gdkDpy);
+    NS_ASSERTION(screen == GDK_SCREEN_XSCREEN(gdkScreen),
+                 "'screen' should be the default Screen");
+    // GDK requires a GdkColormap to be set on the GdkPixmap.
+    GdkVisual* gdkVisual =
+      gdk_x11_screen_lookup_visual(gdkScreen, visual->visualid);
+    GdkColormap* gdkColormap =
+      gdk_x11_colormap_foreign_new(gdkVisual, colormap);
+    gdk_drawable_set_colormap(gdkPixmap, gdkColormap);
+    g_object_unref(G_OBJECT(gdkColormap));
   }
 
   NS_ASSERTION(numClipRects == 0, "We don't support clipping!!!");
   moz_gtk_widget_paint(mGTKWidgetType, gdkPixmap, &gdk_rect, &gdk_clip, &mState,
                        mFlags, mDirection);
 
   g_object_unref(G_OBJECT(gdkPixmap));
   return NS_OK;