* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
+#include "config.h"
+#include <math.h>
+#include <pango/pangocairo.h>
+#include "gdkcairo.h"
#include "gdkdrawable.h"
#include "gdkinternals.h"
#include "gdkwindow.h"
#include "gdkscreen.h"
#include "gdk-pixbuf-private.h"
#include "gdkpixbuf.h"
+#include "gdkalias.h"
static GdkImage* gdk_drawable_real_get_image (GdkDrawable *drawable,
gint x,
GdkRgbDither dither,
gint x_dither,
gint y_dither);
+
-static void gdk_drawable_class_init (GdkDrawableClass *klass);
-
-GType
-gdk_drawable_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type)
- {
- static const GTypeInfo object_info =
- {
- sizeof (GdkDrawableClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gdk_drawable_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GdkDrawable),
- 0, /* n_preallocs */
- (GInstanceInitFunc) NULL,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "GdkDrawable",
- &object_info,
- G_TYPE_FLAG_ABSTRACT);
- }
-
- return object_type;
-}
+G_DEFINE_ABSTRACT_TYPE (GdkDrawable, gdk_drawable, G_TYPE_OBJECT)
static void
gdk_drawable_class_init (GdkDrawableClass *klass)
/* Default implementation for clip and visible region is the same */
klass->get_clip_region = gdk_drawable_real_get_visible_region;
klass->get_visible_region = gdk_drawable_real_get_visible_region;
- klass->_draw_pixbuf = gdk_drawable_real_draw_pixbuf;
+ klass->draw_pixbuf = gdk_drawable_real_draw_pixbuf;
+}
+
+static void
+gdk_drawable_init (GdkDrawable *drawable)
+{
}
/* Manipulation of drawables
* Gets the #GdkScreen associated with a #GdkDrawable.
*
* Return value: the #GdkScreen associated with @drawable
+ *
+ * Since: 2.2
**/
GdkScreen*
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)
/* Drawing
*/
+
+/**
+ * gdk_draw_point:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @x: the x coordinate of the point.
+ * @y: the y coordinate of the point.
+ *
+ * Draws a point, using the foreground color and other attributes of
+ * the #GdkGC.
+ **/
void
gdk_draw_point (GdkDrawable *drawable,
GdkGC *gc,
GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, &point, 1);
}
+/**
+ * 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.
+ *
+ * Draws a line, using the foreground color and other attributes of
+ * the #GdkGC.
+ **/
void
gdk_draw_line (GdkDrawable *drawable,
GdkGC *gc,
GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, &segment, 1);
}
+/**
+ * gdk_draw_rectangle:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @filled: %TRUE if the rectangle should be filled.
+ * @x: the x coordinate of the left edge of the rectangle.
+ * @y: the y coordinate of the top edge of the rectangle.
+ * @width: the width of the rectangle.
+ * @height: the height of the rectangle.
+ *
+ * Draws a rectangular outline or filled rectangle, using the foreground color
+ * and other attributes of the #GdkGC.
+ *
+ * A rectangle drawn filled is 1 pixel smaller in both dimensions than a
+ * rectangle outlined. Calling
+ * <literal>gdk_draw_rectangle (window, gc, TRUE, 0, 0, 20, 20)</literal>
+ * results in a filled rectangle 20 pixels wide and 20 pixels high. Calling
+ * <literal>gdk_draw_rectangle (window, gc, FALSE, 0, 0, 20, 20)</literal>
+ * results in an outlined rectangle with corners at (0, 0), (0, 20), (20, 20),
+ * and (20, 0), which makes it 21 pixels wide and 21 pixels high.
+ **/
void
gdk_draw_rectangle (GdkDrawable *drawable,
GdkGC *gc,
- gint filled,
+ gboolean filled,
gint x,
gint y,
gint width,
width, height);
}
+/**
+ * gdk_draw_arc:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @filled: %TRUE if the arc should be filled, producing a 'pie slice'.
+ * @x: the x coordinate of the left edge of the bounding rectangle.
+ * @y: the y coordinate of the top edge of the bounding rectangle.
+ * @width: the width of the bounding rectangle.
+ * @height: the height of the bounding rectangle.
+ * @angle1: the start angle of the arc, relative to the 3 o'clock position,
+ * counter-clockwise, in 1/64ths of a degree.
+ * @angle2: the end angle of the arc, relative to @angle1, in 1/64ths
+ * of a degree.
+ *
+ * Draws an arc or a filled 'pie slice'. The arc is defined by the bounding
+ * rectangle of the entire ellipse, and the start and end angles of the part
+ * of the ellipse to be drawn.
+ **/
void
gdk_draw_arc (GdkDrawable *drawable,
GdkGC *gc,
- gint filled,
+ gboolean filled,
gint x,
gint y,
gint width,
x, y, width, height, angle1, angle2);
}
+/**
+ * gdk_draw_polygon:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @filled: %TRUE if the polygon should be filled. The polygon is closed
+ * automatically, connecting the last point to the first point if
+ * necessary.
+ * @points: an array of #GdkPoint structures specifying the points making
+ * up the polygon.
+ * @n_points: the number of points.
+ *
+ * Draws an outlined or filled polygon.
+ **/
void
-gdk_draw_polygon (GdkDrawable *drawable,
- GdkGC *gc,
- gint filled,
- GdkPoint *points,
- gint npoints)
+gdk_draw_polygon (GdkDrawable *drawable,
+ GdkGC *gc,
+ gboolean filled,
+ const GdkPoint *points,
+ gint n_points)
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (GDK_IS_GC (gc));
GDK_DRAWABLE_GET_CLASS (drawable)->draw_polygon (drawable, gc, filled,
- points, npoints);
+ (GdkPoint *) points,
+ n_points);
}
/* gdk_draw_string
*
* Interface changed: add "GdkFont *font" to specify font or fontset explicitely
*/
+/**
+ * gdk_draw_string:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @font: a #GdkFont.
+ * @gc: a #GdkGC.
+ * @x: the x coordinate of the left edge of the text.
+ * @y: the y coordinate of the baseline of the text.
+ * @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,
GdkFont *font,
*
* Interface changed: add "GdkFont *font" to specify font or fontset explicitely
*/
+/**
+ * gdk_draw_text:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @font: a #GdkFont.
+ * @gc: a #GdkGC.
+ * @x: the x coordinate of the left edge of the text.
+ * @y: the y coordinate of the baseline of the text.
+ * @text: the characters to draw.
+ * @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,
GdkFont *font,
GDK_DRAWABLE_GET_CLASS (drawable)->draw_text (drawable, font, gc, x, y, text, text_length);
}
+/**
+ * gdk_draw_text_wc:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @font: a #GdkFont.
+ * @gc: a #GdkGC.
+ * @x: the x coordinate of the left edge of the text.
+ * @y: the y coordinate of the baseline of the text.
+ * @text: the wide characters to draw.
+ * @text_length: the number of characters to draw.
+ *
+ * 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,
GdkFont *font,
* 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
* colormap, or errors will result. (On X11, failure to match
* visual/colormap results in a BadMatch error from the X server.)
* A common cause of this problem is an attempt to draw a bitmap to
- * a color drawable. The way to draw a bitmap is to set the
- * bitmap as a clip mask on your #GdkGC, then use gdk_draw_rectangle()
- * to draw a rectangle clipped to the bitmap.
+ * a color drawable. The way to draw a bitmap is to set the bitmap as
+ * the stipple on the #GdkGC, set the fill mode to %GDK_STIPPLED, and
+ * then draw the rectangle.
**/
void
gdk_draw_drawable (GdkDrawable *drawable,
g_object_unref (composite);
}
+/**
+ * gdk_draw_image:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @image: the #GdkImage to draw.
+ * @xsrc: the left edge of the source rectangle within @image.
+ * @ysrc: the top of the source rectangle within @image.
+ * @xdest: the x coordinate of the destination within @drawable.
+ * @ydest: the y coordinate of the destination within @drawable.
+ * @width: the width of the area to be copied, or -1 to make the area
+ * extend to the right edge of @image.
+ * @height: the height of the area to be copied, or -1 to make the area
+ * extend to the bottom edge of @image.
+ *
+ * Draws a #GdkImage onto a drawable.
+ * The depth of the #GdkImage must match the depth of the #GdkDrawable.
+ **/
void
gdk_draw_image (GdkDrawable *drawable,
GdkGC *gc,
}
/**
- * _gdk_draw_pixbuf:
+ * gdk_draw_pixbuf:
* @drawable: Destination drawable.
* @gc: a #GdkGC, used for clipping, or %NULL
* @pixbuf: a #GdkPixbuf
* @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.
+ *
+ * If GDK is built with the Sun mediaLib library, the gdk_draw_pixbuf
+ * function is accelerated using mediaLib, which provides hardware
+ * acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib
+ * support can be turned off by setting the GDK_DISABLE_MEDIALIB environment
+ * variable.
+ *
+ * Since: 2.2
**/
void
-_gdk_draw_pixbuf (GdkDrawable *drawable,
- GdkGC *gc,
- GdkPixbuf *pixbuf,
- gint src_x,
- gint src_y,
- gint dest_x,
- gint dest_y,
- gint width,
- gint height,
- GdkRgbDither dither,
- gint x_dither,
- gint y_dither)
+gdk_draw_pixbuf (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkPixbuf *pixbuf,
+ gint src_x,
+ gint src_y,
+ gint dest_x,
+ gint dest_y,
+ gint width,
+ gint height,
+ GdkRgbDither dither,
+ gint x_dither,
+ gint y_dither)
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (gc == NULL || GDK_IS_GC (gc));
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+ if (width == 0 || height == 0)
+ return;
+
if (width == -1)
width = gdk_pixbuf_get_width (pixbuf);
if (height == -1)
height = gdk_pixbuf_get_height (pixbuf);
- GDK_DRAWABLE_GET_CLASS (drawable)->_draw_pixbuf (drawable, gc, pixbuf,
- src_x, src_y, dest_x, dest_y, width, height,
- dither, x_dither, y_dither);
+ GDK_DRAWABLE_GET_CLASS (drawable)->draw_pixbuf (drawable, gc,
+ (GdkPixbuf *) pixbuf,
+ src_x, src_y, dest_x, dest_y,
+ width, height,
+ dither, x_dither, y_dither);
}
+/**
+ * gdk_draw_points:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @points: an array of #GdkPoint structures.
+ * @n_points: the number of points to be drawn.
+ *
+ * Draws a number of points, using the foreground color and other
+ * attributes of the #GdkGC.
+ **/
void
-gdk_draw_points (GdkDrawable *drawable,
- GdkGC *gc,
- GdkPoint *points,
- gint npoints)
+gdk_draw_points (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkPoint *points,
+ gint n_points)
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail ((points != NULL) && (npoints > 0));
+ g_return_if_fail ((points != NULL) && (n_points > 0));
g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (npoints >= 0);
+ g_return_if_fail (n_points >= 0);
- if (npoints == 0)
+ if (n_points == 0)
return;
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, points, npoints);
+ GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc,
+ (GdkPoint *) points, n_points);
}
+/**
+ * gdk_draw_segments:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @segs: an array of #GdkSegment structures specifying the start and
+ * end points of the lines to be drawn.
+ * @n_segs: the number of line segments to draw, i.e. the size of the
+ * @segs array.
+ *
+ * Draws a number of unconnected lines.
+ **/
void
-gdk_draw_segments (GdkDrawable *drawable,
- GdkGC *gc,
- GdkSegment *segs,
- gint nsegs)
+gdk_draw_segments (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkSegment *segs,
+ gint n_segs)
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- if (nsegs == 0)
+ if (n_segs == 0)
return;
g_return_if_fail (segs != NULL);
g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (nsegs >= 0);
+ g_return_if_fail (n_segs >= 0);
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, segs, nsegs);
+ GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc,
+ (GdkSegment *) segs, n_segs);
}
+/**
+ * gdk_draw_lines:
+ * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
+ * @gc: a #GdkGC.
+ * @points: an array of #GdkPoint structures specifying the endpoints of the
+ * @n_points: the size of the @points array.
+ *
+ * Draws a series of lines connecting the given points.
+ * The way in which joins between lines are draw is determined by the
+ * #GdkCapStyle value in the #GdkGC. This can be set with
+ * gdk_gc_set_line_attributes().
+ **/
void
-gdk_draw_lines (GdkDrawable *drawable,
- GdkGC *gc,
- GdkPoint *points,
- gint npoints)
+gdk_draw_lines (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkPoint *points,
+ gint n_points)
{
-
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (points != NULL);
g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (npoints >= 0);
+ g_return_if_fail (n_points >= 0);
- if (npoints == 0)
+ if (n_points == 0)
return;
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_lines (drawable, gc, points, npoints);
+ GDK_DRAWABLE_GET_CLASS (drawable)->draw_lines (drawable, gc,
+ (GdkPoint *) points, n_points);
+}
+
+static void
+real_draw_glyphs (GdkDrawable *drawable,
+ GdkGC *gc,
+ const PangoMatrix *matrix,
+ PangoFont *font,
+ gdouble x,
+ gdouble y,
+ PangoGlyphString *glyphs)
+{
+ cairo_t *cr;
+
+ cr = gdk_cairo_create (drawable);
+ _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE);
+
+ if (matrix)
+ {
+ cairo_matrix_t cairo_matrix;
+
+ cairo_matrix.xx = matrix->xx;
+ cairo_matrix.yx = matrix->yx;
+ cairo_matrix.xy = matrix->xy;
+ cairo_matrix.yy = matrix->yy;
+ cairo_matrix.x0 = matrix->x0;
+ cairo_matrix.y0 = matrix->y0;
+
+ cairo_set_matrix (cr, &cairo_matrix);
+ }
+
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_glyph_string (cr, font, glyphs);
+
+ cairo_destroy (cr);
}
/**
* @font: font to be used
* @x: X coordinate of baseline origin
* @y: Y coordinate of baseline origin
- * @glyphs: glyphs to render
+ * @glyphs: the glyph string to draw
*
* This is a low-level function; 99% of text rendering should be done
* using gdk_draw_layout() instead.
*
- * A glyph is a character in a font. This function draws a sequence of
+ * A glyph is a single image in a font. This function draws a sequence of
* glyphs. To obtain a sequence of glyphs you have to understand a
* lot about internationalized text handling, which you don't want to
* understand; thus, use gdk_draw_layout() instead of this function,
{
g_return_if_fail (GDK_IS_DRAWABLE (drawable));
g_return_if_fail (GDK_IS_GC (gc));
+
+ real_draw_glyphs (drawable, gc, NULL, font,
+ x, y, glyphs);
+}
+/**
+ * gdk_draw_glyphs_transformed:
+ * @drawable: a #GdkDrawable
+ * @gc: a #GdkGC
+ * @matrix: a #PangoMatrix, or %NULL to use an identity transformation
+ * @font: the font in which to draw the string
+ * @x: the x position of the start of the string (in Pango
+ * units in user space coordinates)
+ * @y: the y position of the baseline (in Pango units
+ * in user space coordinates)
+ * @glyphs: the glyph string to draw
+ *
+ * Renders a #PangoGlyphString onto a drawable, possibly
+ * transforming the layed-out coordinates through a transformation
+ * matrix. Note that the transformation matrix for @font is not
+ * changed, so to produce correct rendering results, the @font
+ * must have been loaded using a #PangoContext with an identical
+ * transformation matrix to that passed in to this function.
+ *
+ * See also gdk_draw_glyphs(), gdk_draw_layout().
+ *
+ * Since: 2.6
+ **/
+void
+gdk_draw_glyphs_transformed (GdkDrawable *drawable,
+ GdkGC *gc,
+ const PangoMatrix *matrix,
+ PangoFont *font,
+ gint x,
+ gint y,
+ PangoGlyphString *glyphs)
+{
+ g_return_if_fail (GDK_IS_DRAWABLE (drawable));
+ g_return_if_fail (GDK_IS_GC (gc));
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_glyphs (drawable, gc, font, x, y, glyphs);
+ real_draw_glyphs (drawable, gc, matrix, font,
+ x / PANGO_SCALE, y / PANGO_SCALE, glyphs);
}
+/**
+ * gdk_draw_trapezoids:
+ * @drawable: a #GdkDrawable
+ * @gc: a #GdkGC
+ * @trapezoids: an array of #GdkTrapezoid structures
+ * @n_trapezoids: the number of trapezoids to draw
+ *
+ * Draws a set of anti-aliased trapezoids. The trapezoids are
+ * combined using saturation addition, then drawn over the background
+ * as a set. This is low level functionality used internally to implement
+ * rotated underlines and backgrouds when rendering a PangoLayout and is
+ * likely not useful for applications.
+ *
+ * Since: 2.6
+ **/
+void
+gdk_draw_trapezoids (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkTrapezoid *trapezoids,
+ gint n_trapezoids)
+{
+ cairo_t *cr;
+ int i;
+
+ g_return_if_fail (GDK_IS_DRAWABLE (drawable));
+ g_return_if_fail (GDK_IS_GC (gc));
+ g_return_if_fail (n_trapezoids == 0 || trapezoids != NULL);
+
+ cr = gdk_cairo_create (drawable);
+ _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE);
+
+ for (i = 0; i < n_trapezoids; i++)
+ {
+ cairo_move_to (cr, trapezoids[i].x11, trapezoids[i].y1);
+ cairo_line_to (cr, trapezoids[i].x21, trapezoids[i].y1);
+ cairo_line_to (cr, trapezoids[i].x22, trapezoids[i].y2);
+ cairo_line_to (cr, trapezoids[i].x12, trapezoids[i].y2);
+ cairo_close_path (cr);
+ }
+
+ cairo_fill (cr);
+
+ cairo_destroy (cr);
+}
/**
- * _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
* 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;
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*
* but no area outside of this region will be affected by drawing
* primitives.
*
- * Return value: a #GdkRegion. This must be freed with gdk_region_destroy()
- * when you are done.
+ * Returns: a #GdkRegion. This must be freed with gdk_region_destroy()
+ * when you are done.
**/
GdkRegion *
gdk_drawable_get_clip_region (GdkDrawable *drawable)
/**
* gdk_drawable_get_visible_region:
- * @drawable:
+ * @drawable: a #GdkDrawable
*
* Computes the region of a drawable that is potentially visible.
* This does not necessarily take into account if the window is
* obscured by other windows, but no area outside of this region
* is visible.
*
- * Return value: a #GdkRegion. This must be freed with gdk_region_destroy()
- * when you are done.
+ * Returns: a #GdkRegion. This must be freed with gdk_region_destroy()
+ * when you are done.
**/
GdkRegion *
gdk_drawable_get_visible_region (GdkDrawable *drawable)
return gdk_region_rectangle (&rect);
}
+/**
+ * _gdk_drawable_ref_cairo_surface:
+ * @drawable: a #GdkDrawable
+ *
+ * Obtains a #cairo_surface_t for the given drawable. If a
+ * #cairo_surface_t for the drawable already exists, it will be
+ * referenced, otherwise a new surface will be created.
+ *
+ * Return value: a newly referenced #cairo_surface_t that points
+ * to @drawable. Unref with cairo_surface_destroy()
+ **/
+cairo_surface_t *
+_gdk_drawable_ref_cairo_surface (GdkDrawable *drawable)
+{
+ g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
+
+ return GDK_DRAWABLE_GET_CLASS (drawable)->ref_cairo_surface (drawable);
+}
+
static void
composite (guchar *src_buf,
gint src_rowstride,
}
}
+#ifdef USE_MEDIALIB
+static void
+composite_0888_medialib (guchar *src_buf,
+ gint src_rowstride,
+ guchar *dest_buf,
+ gint dest_rowstride,
+ GdkByteOrder dest_byte_order,
+ gint width,
+ gint height)
+{
+ guchar *src = src_buf;
+ guchar *dest = dest_buf;
+
+ mlib_image img_src, img_dst;
+
+ mlib_ImageSetStruct (&img_dst,
+ MLIB_BYTE,
+ 4,
+ width,
+ height,
+ dest_rowstride,
+ dest_buf);
+
+ mlib_ImageSetStruct (&img_src,
+ MLIB_BYTE,
+ 4,
+ width,
+ height,
+ src_rowstride,
+ src_buf);
+
+ if (dest_byte_order == GDK_LSB_FIRST)
+ mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src);
+ else
+ mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src);
+}
+#endif
+
static void
composite_565 (guchar *src_buf,
gint src_rowstride,
gint x_dither,
gint y_dither)
{
- gboolean free_gc = FALSE;
GdkPixbuf *composited = NULL;
gint dwidth, dheight;
GdkRegion *clip;
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)
{
visual->red_mask == 0xff0000 &&
visual->green_mask == 0x00ff00 &&
visual->blue_mask == 0x0000ff)
- composite_func = composite_0888;
+ {
+#ifdef USE_MEDIALIB
+ if (_gdk_use_medialib ())
+ composite_func = composite_0888_medialib;
+ else
+ composite_func = composite_0888;
+#else
+ composite_func = composite_0888;
+#endif
+ }
}
/* We can't use our composite func if we are required to dither
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,
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];
+ }
}
+
+#define __GDK_DRAW_C__
+#include "gdkaliasdef.c"