reviewed by: Richard Hult

2008-07-20  Sven Herzberg  <sven@imendio.com>

	reviewed by: Richard Hult

	Extracted the CGContextRef creation into a virtual function of
	GdkDrawableImplQuartz; implement get_context() for GdkPixmap and
	GdkWindow

	* gdk/quartz/gdkdrawable-quartz.c
	(gdk_quartz_drawable_get_context): dropped the different
	implementations; forward to the virtual function now
	* gdk/quartz/gdkdrawable-quartz.h: added the virtual function
	* gdk/quartz/gdkpixmap-quartz.c
	(gdk_pixmap_impl_quartz_get_context),
	(gdk_pixmap_impl_quartz_class_init): implemented get_context()
	* gdk/quartz/gdkwindow-quartz.c
	(gdk_window_impl_quartz_get_context),
	(gdk_window_impl_quartz_class_init): implemented get_context()


svn path=/trunk/; revision=20869
This commit is contained in:
Sven Herzberg 2008-07-20 16:14:35 +00:00 committed by Sven Herzberg
parent 66781b84d0
commit 61ca4f71a0
5 changed files with 116 additions and 77 deletions

View File

@ -1,3 +1,22 @@
2008-07-20 Sven Herzberg <sven@imendio.com>
reviewed by: Richard Hult
Extracted the CGContextRef creation into a virtual function of
GdkDrawableImplQuartz; implement get_context() for GdkPixmap and
GdkWindow
* gdk/quartz/gdkdrawable-quartz.c
(gdk_quartz_drawable_get_context): dropped the different
implementations; forward to the virtual function now
* gdk/quartz/gdkdrawable-quartz.h: added the virtual function
* gdk/quartz/gdkpixmap-quartz.c
(gdk_pixmap_impl_quartz_get_context),
(gdk_pixmap_impl_quartz_class_init): implemented get_context()
* gdk/quartz/gdkwindow-quartz.c
(gdk_window_impl_quartz_get_context),
(gdk_window_impl_quartz_class_init): implemented get_context()
2007-08-19 Matthias Clasen <mclasen@redhat.com>
* NEWS: Updates

View File

@ -668,84 +668,14 @@ CGContextRef
gdk_quartz_drawable_get_context (GdkDrawable *drawable,
gboolean antialias)
{
GdkDrawableImplQuartz *drawable_impl = GDK_DRAWABLE_IMPL_QUARTZ (drawable);
CGContextRef cg_context;
if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable) &&
GDK_WINDOW_DESTROYED (drawable_impl->wrapper))
return NULL;
if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
if (!GDK_DRAWABLE_IMPL_QUARTZ_GET_CLASS (drawable)->get_context)
{
GdkWindowImplQuartz *window_impl = GDK_WINDOW_IMPL_QUARTZ (drawable);
/* Lock focus when not called as part of a drawRect call. This
* is needed when called from outside "real" expose events, for
* example for synthesized expose events when realizing windows
* and for widgets that send fake expose events like the arrow
* buttons in spinbuttons.
*/
if (window_impl->in_paint_rect_count == 0)
{
if (![window_impl->view lockFocusIfCanDraw])
g_warning ("%s doesn't implement GdkDrawableImplQuartzClass::get_context()",
G_OBJECT_TYPE_NAME (drawable));
return NULL;
}
cg_context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState (cg_context);
CGContextSetAllowsAntialiasing (cg_context, antialias);
/* We'll emulate the clipping caused by double buffering here */
if (window_impl->begin_paint_count != 0)
{
CGRect rect;
CGRect *cg_rects;
GdkRectangle *rects;
gint n_rects, i;
gdk_region_get_rectangles (window_impl->paint_clip_region,
&rects, &n_rects);
if (n_rects == 1)
cg_rects = &rect;
else
cg_rects = g_new (CGRect, n_rects);
for (i = 0; i < n_rects; i++)
{
cg_rects[i].origin.x = rects[i].x;
cg_rects[i].origin.y = rects[i].y;
cg_rects[i].size.width = rects[i].width;
cg_rects[i].size.height = rects[i].height;
}
CGContextClipToRects (cg_context, cg_rects, n_rects);
g_free (rects);
if (cg_rects != &rect)
g_free (cg_rects);
}
}
else if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable))
{
GdkPixmapImplQuartz *impl = GDK_PIXMAP_IMPL_QUARTZ (drawable);
cg_context = CGBitmapContextCreate (impl->data,
CGImageGetWidth (impl->image),
CGImageGetHeight (impl->image),
CGImageGetBitsPerComponent (impl->image),
CGImageGetBytesPerRow (impl->image),
CGImageGetColorSpace (impl->image),
CGImageGetBitmapInfo (impl->image));
CGContextSetAllowsAntialiasing (cg_context, antialias);
}
else
{
g_warning ("Tried to create CGContext for something not a quartz window or pixmap");
cg_context = NULL;
}
return cg_context;
return GDK_DRAWABLE_IMPL_QUARTZ_GET_CLASS (drawable)->get_context (drawable, antialias);
}
void

View File

@ -52,6 +52,10 @@ struct _GdkDrawableImplQuartz
struct _GdkDrawableImplQuartzClass
{
GdkDrawableClass parent_class;
/* vtable */
CGContextRef (*get_context) (GdkDrawable* drawable,
gboolean antialias);
};
GType gdk_drawable_impl_quartz_get_type (void);

View File

@ -41,6 +41,25 @@ gdk_pixmap_impl_quartz_get_size (GdkDrawable *drawable,
*height = GDK_PIXMAP_IMPL_QUARTZ (drawable)->height;
}
static CGContextRef
gdk_pixmap_impl_quartz_get_context (GdkDrawable *drawable,
gboolean antialias)
{
GdkPixmapImplQuartz *impl = GDK_PIXMAP_IMPL_QUARTZ (drawable);
CGContextRef cg_context;
cg_context = CGBitmapContextCreate (impl->data,
CGImageGetWidth (impl->image),
CGImageGetHeight (impl->image),
CGImageGetBitsPerComponent (impl->image),
CGImageGetBytesPerRow (impl->image),
CGImageGetColorSpace (impl->image),
CGImageGetBitmapInfo (impl->image));
CGContextSetAllowsAntialiasing (cg_context, antialias);
return cg_context;
}
static void
gdk_pixmap_impl_quartz_finalize (GObject *object)
{
@ -58,12 +77,15 @@ gdk_pixmap_impl_quartz_class_init (GdkPixmapImplQuartzClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
GdkDrawableImplQuartzClass *drawable_quartz_class = GDK_DRAWABLE_IMPL_QUARTZ_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gdk_pixmap_impl_quartz_finalize;
drawable_class->get_size = gdk_pixmap_impl_quartz_get_size;
drawable_quartz_class->get_context = gdk_pixmap_impl_quartz_get_context;
}
GType

View File

@ -89,6 +89,67 @@ gdk_window_impl_quartz_get_size (GdkDrawable *drawable,
*height = GDK_WINDOW_IMPL_QUARTZ (drawable)->height;
}
static CGContextRef
gdk_window_impl_quartz_get_context (GdkDrawable *drawable,
gboolean antialias)
{
GdkDrawableImplQuartz *drawable_impl = GDK_DRAWABLE_IMPL_QUARTZ (drawable);
GdkWindowImplQuartz *window_impl = GDK_WINDOW_IMPL_QUARTZ (drawable);
CGContextRef cg_context;
if (GDK_WINDOW_DESTROYED (drawable_impl->wrapper))
return NULL;
/* Lock focus when not called as part of a drawRect call. This
* is needed when called from outside "real" expose events, for
* example for synthesized expose events when realizing windows
* and for widgets that send fake expose events like the arrow
* buttons in spinbuttons.
*/
if (window_impl->in_paint_rect_count == 0)
{
if (![window_impl->view lockFocusIfCanDraw])
return NULL;
}
cg_context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState (cg_context);
CGContextSetAllowsAntialiasing (cg_context, antialias);
/* We'll emulate the clipping caused by double buffering here */
if (window_impl->begin_paint_count != 0)
{
CGRect rect;
CGRect *cg_rects;
GdkRectangle *rects;
gint n_rects, i;
gdk_region_get_rectangles (window_impl->paint_clip_region,
&rects, &n_rects);
if (n_rects == 1)
cg_rects = &rect;
else
cg_rects = g_new (CGRect, n_rects);
for (i = 0; i < n_rects; i++)
{
cg_rects[i].origin.x = rects[i].x;
cg_rects[i].origin.y = rects[i].y;
cg_rects[i].size.width = rects[i].width;
cg_rects[i].size.height = rects[i].height;
}
CGContextClipToRects (cg_context, cg_rects, n_rects);
g_free (rects);
if (cg_rects != &rect)
g_free (cg_rects);
}
return cg_context;
}
static GdkRegion*
gdk_window_impl_quartz_get_visible_region (GdkDrawable *drawable)
{
@ -159,6 +220,7 @@ gdk_window_impl_quartz_finalize (GObject *object)
static void
gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
{
GdkDrawableImplQuartzClass *drawable_quartz_class = GDK_DRAWABLE_IMPL_QUARTZ_CLASS (klass);
GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@ -168,6 +230,8 @@ gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
drawable_class->get_size = gdk_window_impl_quartz_get_size;
drawable_quartz_class->get_context = gdk_window_impl_quartz_get_context;
/* Visible and clip regions are the same */
drawable_class->get_clip_region = gdk_window_impl_quartz_get_visible_region;
drawable_class->get_visible_region = gdk_window_impl_quartz_get_visible_region;