]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkdraw.c
Use depth - 1 to index the cached gcs, not depth. (#139494)
[~andy/gtk] / gdk / gdkdraw.c
index 8e024fa76fabd7fb5395bcf2079ff25f8decbb74..7d77eaed01c6daacea0d466701fa2a52cdd9e4f6 100644 (file)
@@ -24,6 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
 #include "gdkdrawable.h"
 #include "gdkinternals.h"
 #include "gdkwindow.h"
@@ -211,6 +212,8 @@ gdk_drawable_get_depth (GdkDrawable *drawable)
  * Gets the #GdkScreen associated with a #GdkDrawable.
  * 
  * Return value: the #GdkScreen associated with @drawable
+ *
+ * Since: 2.2
  **/
 GdkScreen*
 gdk_drawable_get_screen(GdkDrawable *drawable)
@@ -227,6 +230,8 @@ gdk_drawable_get_screen(GdkDrawable *drawable)
  * Gets the #GdkDisplay associated with a #GdkDrawable.
  * 
  * Return value: the #GdkDisplay associated with @drawable
+ *
+ * Since: 2.2
  **/
 GdkDisplay*
 gdk_drawable_get_display (GdkDrawable *drawable)
@@ -343,10 +348,10 @@ gdk_draw_point (GdkDrawable *drawable,
  * gdk_draw_line:
  * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap). 
  * @gc: a #GdkGC.
- * @x1: the x coordinate of the start point.
- * @y1: the y coordinate of the start point.
- * @x2: the x coordinate of the end point.
- * @y2: the y coordinate of the end point.
+ * @x1_: the x coordinate of the start point.
+ * @y1_: the y coordinate of the start point.
+ * @x2_: the x coordinate of the end point.
+ * @y2_: the y coordinate of the end point.
  * 
  * Draws a line, using the foreground color and other attributes of 
  * the #GdkGC.
@@ -515,6 +520,8 @@ gdk_draw_polygon (GdkDrawable *drawable,
  * @string:  the string of characters to draw.
  * 
  * Draws a string of characters in the given font or fontset.
+ * 
+ * Deprecated: Use gdk_draw_layout() instead.
  **/
 void
 gdk_draw_string (GdkDrawable *drawable,
@@ -544,6 +551,8 @@ gdk_draw_string (GdkDrawable *drawable,
  * @text_length: the number of characters of @text to draw.
  * 
  * Draws a number of characters in the given font or fontset.
+ *
+ * Deprecated: Use gdk_draw_layout() instead.
  **/
 void
 gdk_draw_text (GdkDrawable *drawable,
@@ -575,6 +584,8 @@ gdk_draw_text (GdkDrawable *drawable,
  * Draws a number of wide characters using the given font of fontset.
  * If the font is a 1-byte font, the string is converted into 1-byte 
  * characters (discarding the high bytes) before output.
+ * 
+ * Deprecated: Use gdk_draw_layout() instead.
  **/
 void
 gdk_draw_text_wc (GdkDrawable   *drawable,
@@ -597,7 +608,7 @@ gdk_draw_text_wc (GdkDrawable        *drawable,
  * gdk_draw_drawable:
  * @drawable: a #GdkDrawable
  * @gc: a #GdkGC sharing the drawable's visual and colormap
- * @src: another #GdkDrawable
+ * @src: the source #GdkDrawable, which may be the same as @drawable
  * @xsrc: X position in @src of rectangle to draw
  * @ysrc: Y position in @src of rectangle to draw
  * @xdest: X position in @drawable where the rectangle should be drawn
@@ -723,17 +734,23 @@ gdk_draw_image (GdkDrawable *drawable,
  * @dest_y: Destination Y coordinate within drawable.
  * @width: Width of region to render, in pixels, or -1 to use pixbuf width.
  * @height: Height of region to render, in pixels, or -1 to use pixbuf height.
- * @dither: Dithering mode for GdkRGB.
+ * @dither: Dithering mode for #GdkRGB.
  * @x_dither: X offset for dither.
  * @y_dither: Y offset for dither.
  * 
  * Renders a rectangular portion of a pixbuf to a drawable.  The destination
  * drawable must have a colormap. All windows have a colormap, however, pixmaps
- * only have colormap by default if they were created with a non-NULL window argument.
- * Otherwise a colormap must be set on them with gdk_drawable_set_colormap.
+ * only have colormap by default if they were created with a non-%NULL window 
+ * argument. Otherwise a colormap must be set on them with 
+ * gdk_drawable_set_colormap().
  *
- * On older X servers, rendering pixbufs with an alpha channel involves round trips
- * to the X server, and may be somewhat slow.
+ * On older X servers, rendering pixbufs with an alpha channel involves round 
+ * trips to the X server, and may be somewhat slow.
+ *
+ * The clip mask of @gc is ignored, but clip rectangles and clip regions work
+ * fine.
+ * 
+ * Since: 2.2
  **/
 void
 gdk_draw_pixbuf (GdkDrawable     *drawable,
@@ -884,7 +901,7 @@ gdk_draw_glyphs (GdkDrawable      *drawable,
 
 
 /**
- * _gdk_drawable_copy_to_image:
+ * gdk_drawable_copy_to_image:
  * @drawable: a #GdkDrawable
  * @image: a #GdkDrawable, or %NULL if a new @image should be created.
  * @src_x: x coordinate on @drawable
@@ -899,17 +916,19 @@ gdk_draw_glyphs (GdkDrawable      *drawable,
  * and copies into that. See gdk_drawable_get_image() for further details.
  * 
  * Return value: @image, or a new a #GdkImage containing the contents
-                 of @drawable
+ *               of @drawable
+ * 
+ * Since: 2.4
  **/
 GdkImage*
-_gdk_drawable_copy_to_image (GdkDrawable *drawable,
-                            GdkImage    *image,
-                            gint         src_x,
-                            gint         src_y,
-                            gint         dest_x,
-                            gint         dest_y,
-                            gint         width,
-                            gint         height)
+gdk_drawable_copy_to_image (GdkDrawable *drawable,
+                           GdkImage    *image,
+                           gint         src_x,
+                           gint         src_y,
+                           gint         dest_x,
+                           gint         dest_y,
+                           gint         width,
+                           gint         height)
 {
   GdkDrawable *composite;
   gint composite_x_offset = 0;
@@ -1052,7 +1071,7 @@ gdk_drawable_real_get_image (GdkDrawable     *drawable,
                             gint             width,
                             gint             height)
 {
-  return _gdk_drawable_copy_to_image (drawable, NULL, x, y, 0, 0, width, height);
+  return gdk_drawable_copy_to_image (drawable, NULL, x, y, 0, 0, width, height);
 }
 
 static GdkDrawable*
@@ -1311,7 +1330,6 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable  *drawable,
                               gint          x_dither,
                               gint          y_dither)
 {
-  gboolean free_gc = FALSE;
   GdkPixbuf *composited = NULL;
   gint dwidth, dheight;
   GdkRegion *clip;
@@ -1387,12 +1405,8 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable  *drawable,
     return;
   
   /* Actually draw */
-
   if (!gc)
-    {
-      gc = gdk_gc_new (drawable);
-      free_gc = TRUE;
-    }
+    gc = _gdk_drawable_get_scratch_gc (drawable, FALSE);
   
   if (pixbuf->has_alpha)
     {
@@ -1444,10 +1458,10 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable  *drawable,
                                                            width1, height1,
                                                            gdk_drawable_get_depth (drawable), &xs0, &ys0);
                  
-                 _gdk_drawable_copy_to_image (drawable, image,
-                                              dest_x + x0, dest_y + y0,
-                                              xs0, ys0,
-                                              width1, height1);
+                 gdk_drawable_copy_to_image (drawable, image,
+                                             dest_x + x0, dest_y + y0,
+                                             xs0, ys0,
+                                             width1, height1);
                  (*composite_func) (pixbuf->pixels + (src_y + y0) * pixbuf->rowstride + (src_x + x0) * 4,
                                     pixbuf->rowstride,
                                     (guchar*)image->mem + ys0 * image->bpl + xs0 * image->bpp,
@@ -1517,7 +1531,63 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable  *drawable,
  out:
   if (composited)
     g_object_unref (composited);
+}
 
-  if (free_gc)
-    g_object_unref (gc);
+/**
+ * _gdk_drawable_get_scratch_gc:
+ * @drawable: A #GdkDrawable
+ * @graphics_exposures: Whether the returned #GdkGC should generate graphics exposures 
+ * 
+ * Returns a #GdkGC suitable for drawing on @drawable. The #GdkGC has
+ * the standard values for @drawable, except for the graphics_exposures
+ * field which is determined by the @graphics_exposures parameter.
+ *
+ * The foreground color of the returned #GdkGC is undefined. The #GdkGC
+ * must not be altered in any way, except to change its foreground color.
+ * 
+ * Return value: A #GdkGC suitable for drawing on @drawable
+ * 
+ * Since: 2.4
+ **/
+GdkGC *
+_gdk_drawable_get_scratch_gc (GdkDrawable *drawable,
+                             gboolean     graphics_exposures)
+{
+  GdkScreen *screen;
+  gint depth;
+
+  g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
+
+  screen = gdk_drawable_get_screen (drawable);
+
+  g_return_val_if_fail (!screen->closed, NULL);
+
+  depth = gdk_drawable_get_depth (drawable) - 1;
+
+  if (graphics_exposures)
+    {
+      if (!screen->exposure_gcs[depth])
+       {
+         GdkGCValues values;
+         GdkGCValuesMask mask;
+
+         values.graphics_exposures = TRUE;
+         mask = GDK_GC_EXPOSURES;  
+
+         screen->exposure_gcs[depth] =
+           gdk_gc_new_with_values (drawable, &values, mask);
+       }
+
+      return screen->exposure_gcs[depth];
+    }
+  else
+    {
+      if (!screen->normal_gcs[depth])
+       {
+         screen->normal_gcs[depth] =
+           gdk_gc_new (drawable);
+       }
+
+      return screen->normal_gcs[depth];
+    }
 }