#include <glib.h>
#include <pango/pangowin32.h>
+#include <cairo-win32.h>
#include "gdkscreen.h" /* gdk_screen_get_default() */
#include "gdkregion-generic.h"
GdkGC *gc,
GdkPoint *points,
gint npoints);
-static void gdk_win32_draw_glyphs (GdkDrawable *drawable,
- GdkGC *gc,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs);
-static void gdk_win32_draw_glyphs_transformed (GdkDrawable *drawable,
- GdkGC *gc,
- PangoMatrix *matrix,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs);
static void gdk_win32_draw_image (GdkDrawable *drawable,
GdkGC *gc,
GdkImage *image,
gint width,
gint height);
+static cairo_surface_t *gdk_win32_ref_cairo_surface (GdkDrawable *drawable);
+
static void gdk_win32_set_colormap (GdkDrawable *drawable,
GdkColormap *colormap);
static void gdk_drawable_impl_win32_finalize (GObject *object);
static gpointer parent_class = NULL;
+static const cairo_user_data_key_t gdk_win32_cairo_key;
GType
gdk_drawable_impl_win32_get_type (void)
drawable_class->draw_points = gdk_win32_draw_points;
drawable_class->draw_segments = gdk_win32_draw_segments;
drawable_class->draw_lines = gdk_win32_draw_lines;
- drawable_class->draw_glyphs = gdk_win32_draw_glyphs;
- drawable_class->draw_glyphs_transformed = gdk_win32_draw_glyphs_transformed;
drawable_class->draw_image = gdk_win32_draw_image;
+ drawable_class->ref_cairo_surface = gdk_win32_ref_cairo_surface;
+
drawable_class->set_colormap = gdk_win32_set_colormap;
drawable_class->get_colormap = gdk_win32_get_colormap;
g_free (pts);
}
-static void
-draw_glyphs (GdkGCWin32 *gcwin32,
- HDC hdc,
- gint x_offset,
- gint y_offset,
- va_list args)
-{
- PangoFont *font;
- gint x;
- gint y;
- PangoGlyphString *glyphs;
-
- font = va_arg (args, PangoFont *);
- x = va_arg (args, gint);
- y = va_arg (args, gint);
- glyphs = va_arg (args, PangoGlyphString *);
-
- x -= x_offset;
- y -= y_offset;
-
- pango_win32_render (hdc, font, glyphs, x, y);
-}
-
-static void
-draw_glyphs_transformed (GdkGCWin32 *gcwin32,
- HDC hdc,
- gint x_offset,
- gint y_offset,
- va_list args)
-{
- PangoFont *font;
- gint x;
- gint y;
- PangoGlyphString *glyphs;
- PangoMatrix *matrix;
-
- matrix = va_arg(args, PangoMatrix *);
- font = va_arg (args, PangoFont *);
- x = va_arg (args, gint);
- y = va_arg (args, gint);
- glyphs = va_arg (args, PangoGlyphString *);
-
- x -= x_offset;
- y -= y_offset;
-
- pango_win32_render_transformed (hdc, matrix, font, glyphs, x, y);
-}
-
-static void
-gdk_win32_draw_glyphs (GdkDrawable *drawable,
- GdkGC *gc,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs)
-{
- GdkRectangle bounds;
- GdkRegion *region;
- PangoRectangle ink_rect;
-
- pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
-
- bounds.x = x + PANGO_PIXELS (ink_rect.x) - 1;
- bounds.y = y + PANGO_PIXELS (ink_rect.y) - 1;
- bounds.width = PANGO_PIXELS (ink_rect.width) + 2;
- bounds.height = PANGO_PIXELS (ink_rect.height) + 2;
- region = gdk_region_rectangle (&bounds);
-
- generic_draw (drawable, gc, GDK_GC_FOREGROUND|GDK_GC_FONT,
- draw_glyphs, region, font, x, y, glyphs);
-
- gdk_region_destroy (region);
-}
-
-static void
-gdk_win32_draw_glyphs_transformed (GdkDrawable *drawable,
- GdkGC *gc,
- PangoMatrix *matrix,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs)
-{
- GdkRectangle bounds;
- GdkRegion *region;
- PangoRectangle ink_rect;
-
- pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
-
- bounds.x = x + PANGO_PIXELS (ink_rect.x) - 1;
- bounds.y = y + PANGO_PIXELS (ink_rect.y) - 1;
- bounds.width = PANGO_PIXELS (ink_rect.width) + 2;
- bounds.height = PANGO_PIXELS (ink_rect.height) + 2;
- region = gdk_region_rectangle (&bounds);
-
- if (matrix)
- {
- /* transform region */
- bounds.x = bounds.x * matrix->xx + bounds.y * matrix->xy + matrix->x0;
- bounds.y = bounds.x * matrix->yx + bounds.y * matrix->yy + matrix->x0;
- bounds.width = bounds.width * matrix->xx + bounds.height * matrix->xy;
- bounds.height = bounds.height * matrix->yx + bounds.width * matrix->xy;
-
- generic_draw (drawable, gc, GDK_GC_FOREGROUND|GDK_GC_FONT,
- draw_glyphs_transformed, region, matrix, font, x, y, glyphs);
- }
- else
- {
- generic_draw (drawable, gc, GDK_GC_FOREGROUND|GDK_GC_FONT,
- draw_glyphs, region, font, x/PANGO_SCALE, y/PANGO_SCALE, glyphs);
- }
-
- gdk_region_destroy (region);
-}
-
static void
blit_from_pixmap (gboolean use_fg_bg,
GdkDrawableImplWin32 *dest,
GDK_NOTE (MISC, g_print ("blit_from_pixmap\n"));
- if (!(srcdc = CreateCompatibleDC (NULL)))
- {
- WIN32_GDI_FAILED ("CreateCompatibleDC");
- return;
- }
-
+ srcdc = _gdk_win32_drawable_acquire_dc (GDK_DRAWABLE (src));
+ if (!srcdc)
+ return;
+
if (!(holdbitmap = SelectObject (srcdc, ((GdkDrawableImplWin32 *) src)->handle)))
WIN32_GDI_FAILED ("SelectObject");
else
GDI_CALL (SelectObject, (srcdc, holdbitmap));
}
- GDI_CALL (DeleteDC, (srcdc));
+
+ _gdk_win32_drawable_release_dc (GDK_DRAWABLE (src));
}
static void
xsrc, ysrc, xdest, ydest, width, height);
}
+/**
+ * _gdk_win32_drawable_acquire_dc
+ * @drawable: a Win32 #GdkDrawable implementation
+ *
+ * Gets a DC with the given drawable selected into
+ * it.
+ *
+ * Return value: The DC, on success. Otherwise
+ * %NULL. If this function succeeded
+ * _gdk_win32_drawable_release_dc() must be called
+ * release the DC when you are done using it.
+ **/
+HDC
+_gdk_win32_drawable_acquire_dc (GdkDrawable *drawable)
+{
+ GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
+
+ if (GDK_IS_WINDOW_IMPL_WIN32 (drawable) &&
+ GDK_WINDOW_DESTROYED (impl->wrapper))
+ return NULL;
+
+ if (!impl->hdc)
+ {
+ if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
+ {
+ impl->hdc = CreateCompatibleDC (NULL);
+ if (!impl->hdc)
+ WIN32_GDI_FAILED ("CreateCompatibleDC");
+
+ if (impl->hdc)
+ {
+ impl->saved_dc_bitmap = SelectObject (impl->hdc,
+ impl->handle);
+ if (!impl->saved_dc_bitmap)
+ {
+ WIN32_GDI_FAILED ("CreateCompatibleDC");
+ DeleteDC (impl->hdc);
+ impl->hdc = NULL;
+ }
+ }
+ }
+ else
+ {
+ impl->hdc = GetDC (impl->handle);
+ if (!impl->hdc)
+ WIN32_GDI_FAILED ("GetDC");
+ }
+ }
+
+ if (impl->hdc)
+ {
+ impl->hdc_count++;
+ return impl->hdc;
+ }
+ else
+ return NULL;
+}
+
+/**
+ * _gdk_win32_drawable_release_dc
+ * @drawable: a Win32 #GdkDrawable implementation
+ *
+ * Releases the reference count for the DC
+ * from _gdk_win32_drawable_acquire_dc()
+ **/
+void
+_gdk_win32_drawable_release_dc (GdkDrawable *drawable)
+{
+ GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
+
+ g_return_if_fail (impl->hdc_count > 0);
+
+ impl->hdc_count--;
+ if (impl->hdc_count == 0)
+ {
+ if (impl->saved_dc_bitmap)
+ {
+ GDI_CALL (SelectObject, (impl->hdc, impl->saved_dc_bitmap));
+ impl->saved_dc_bitmap = NULL;
+ }
+
+ if (impl->hdc)
+ {
+ GDI_CALL (DeleteDC, (impl->hdc));
+ impl->hdc = NULL;
+ }
+ }
+}
+
+static void
+gdk_win32_cairo_surface_destroy (void *data)
+{
+ GdkDrawableImplWin32 *impl = data;
+
+ _gdk_win32_drawable_release_dc (GDK_DRAWABLE (impl));
+ impl->cairo_surface = NULL;
+}
+
+static cairo_surface_t *
+gdk_win32_ref_cairo_surface (GdkDrawable *drawable)
+{
+ GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
+
+ if (GDK_IS_WINDOW_IMPL_WIN32 (drawable) &&
+ GDK_WINDOW_DESTROYED (impl->wrapper))
+ return NULL;
+
+ if (!impl->cairo_surface)
+ {
+ HDC hdc = _gdk_win32_drawable_acquire_dc (drawable);
+ if (!hdc)
+ return NULL;
+
+ impl->cairo_surface = cairo_win32_surface_create (hdc);
+
+ cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key,
+ drawable, gdk_win32_cairo_surface_destroy);
+ }
+ else
+ cairo_surface_reference (impl->cairo_surface);
+
+ return impl->cairo_surface;
+}
+
static gint
gdk_win32_get_depth (GdkDrawable *drawable)
{
return GDK_DRAWABLE_HANDLE (drawable);
}
-gboolean
-gdk_draw_rectangle_alpha_libgtk_only (GdkDrawable *drawable,
- gint x,
- gint y,
- gint width,
- gint height,
- GdkColor *color,
- guint16 alpha)
+/**
+ * _gdk_win32_drawable_finish
+ * @drawable: a Win32 #GdkDrawable implementation
+ *
+ * Releases any resources allocated internally for the drawable.
+ * This is called when the drawable becomes unusable
+ * (gdk_window_destroy() for a window, or the refcount going to
+ * zero for a pixmap.)
+ **/
+void
+_gdk_win32_drawable_finish (GdkDrawable *drawable)
{
- return FALSE;
+ GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
+
+ if (impl->cairo_surface)
+ {
+ cairo_surface_finish (impl->cairo_surface);
+ cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key,
+ NULL, NULL);
+ }
+
+ g_assert (impl->hdc_count == 0);
}
+
GDK_NOTE (GC, g_print ("\n"));
win32_gc->hdc = NULL;
- win32_gc->hwnd = NULL;
return gc;
}
dst_win32_gc->hdc = NULL;
dst_win32_gc->saved_dc = FALSE;
- dst_win32_gc->hwnd = NULL;
dst_win32_gc->holdpal = NULL;
dst_win32_gc->pen_hbrbg = NULL;
}
return ok;
}
+static GdkDrawableImplWin32 *
+get_impl_drawable (GdkDrawable *drawable)
+{
+ if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32(drawable);
+ else if (GDK_IS_WINDOW (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
+ else if (GDK_IS_PIXMAP (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
+ else
+ g_assert_not_reached ();
+
+ return NULL;
+}
+
/**
* gdk_win32_hdc_get:
* @drawable: destination #GdkDrawable
g_assert (win32_gc->hdc == NULL);
- if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32(drawable);
- else if (GDK_IS_WINDOW (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
- else if (GDK_IS_PIXMAP (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
- else
- g_assert_not_reached ();
-
- win32_gc->hwnd = impl->handle;
-
- if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
- {
- if ((win32_gc->hdc = CreateCompatibleDC (NULL)) == NULL)
- WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
+ impl = get_impl_drawable (drawable);
+
+ win32_gc->hdc = _gdk_win32_drawable_acquire_dc (GDK_DRAWABLE (impl));
+ ok = win32_gc->hdc != NULL;
- if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
- WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
-
- if (ok && SelectObject (win32_gc->hdc, win32_gc->hwnd) == NULL)
- WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
- }
- else
- {
- if ((win32_gc->hdc = GetDC (win32_gc->hwnd)) == NULL)
- WIN32_GDI_FAILED ("GetDC");
+ if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
+ WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
- if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
- WIN32_GDI_FAILED ("SaveDC");
- }
-
if (ok && (usage & (GDK_GC_FOREGROUND | GDK_GC_BACKGROUND)))
ok = predraw (gc, impl->colormap);
win32_gc, win32_gc->hdc,
_gdk_win32_gcvalues_mask_to_string (usage)));
- if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32(drawable);
- else if (GDK_IS_WINDOW (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
- else if (GDK_IS_PIXMAP (drawable))
- impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
- else
- g_assert_not_reached ();
+ impl = get_impl_drawable (drawable);
if (win32_gc->holdpal != NULL)
{
GDI_CALL (RestoreDC, (win32_gc->hdc, win32_gc->saved_dc));
- if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
- GDI_CALL (DeleteDC, (win32_gc->hdc));
- else
- GDI_CALL (ReleaseDC, (win32_gc->hwnd, win32_gc->hdc));
+ _gdk_win32_drawable_release_dc (GDK_DRAWABLE (impl));
if (hpen != NULL)
GDI_CALL (DeleteObject, (hpen));