gtk+ r20869 - in trunk: . gdk/quartz
- From: herzi svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk+ r20869 - in trunk: . gdk/quartz
- Date: Sun, 20 Jul 2008 16:14:35 +0000 (UTC)
Author: herzi
Date: Sun Jul 20 16:14:35 2008
New Revision: 20869
URL: http://svn.gnome.org/viewvc/gtk+?rev=20869&view=rev
Log:
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()
Modified:
trunk/ChangeLog
trunk/gdk/quartz/gdkdrawable-quartz.c
trunk/gdk/quartz/gdkdrawable-quartz.h
trunk/gdk/quartz/gdkpixmap-quartz.c
trunk/gdk/quartz/gdkwindow-quartz.c
Modified: trunk/gdk/quartz/gdkdrawable-quartz.c
==============================================================================
--- trunk/gdk/quartz/gdkdrawable-quartz.c (original)
+++ trunk/gdk/quartz/gdkdrawable-quartz.c Sun Jul 20 16:14:35 2008
@@ -664,88 +664,18 @@
return object_type;
}
-CGContextRef
+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))
- {
- 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])
- 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 = ▭
- 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
+ if (!GDK_DRAWABLE_IMPL_QUARTZ_GET_CLASS (drawable)->get_context)
{
- g_warning ("Tried to create CGContext for something not a quartz window or pixmap");
- cg_context = NULL;
+ g_warning ("%s doesn't implement GdkDrawableImplQuartzClass::get_context()",
+ G_OBJECT_TYPE_NAME (drawable));
+ return NULL;
}
- return cg_context;
+ return GDK_DRAWABLE_IMPL_QUARTZ_GET_CLASS (drawable)->get_context (drawable, antialias);
}
void
Modified: trunk/gdk/quartz/gdkdrawable-quartz.h
==============================================================================
--- trunk/gdk/quartz/gdkdrawable-quartz.h (original)
+++ trunk/gdk/quartz/gdkdrawable-quartz.h Sun Jul 20 16:14:35 2008
@@ -49,9 +49,13 @@
cairo_surface_t *cairo_surface;
};
-struct _GdkDrawableImplQuartzClass
+struct _GdkDrawableImplQuartzClass
{
GdkDrawableClass parent_class;
+
+ /* vtable */
+ CGContextRef (*get_context) (GdkDrawable* drawable,
+ gboolean antialias);
};
GType gdk_drawable_impl_quartz_get_type (void);
Modified: trunk/gdk/quartz/gdkpixmap-quartz.c
==============================================================================
--- trunk/gdk/quartz/gdkpixmap-quartz.c (original)
+++ trunk/gdk/quartz/gdkpixmap-quartz.c Sun Jul 20 16:14:35 2008
@@ -41,6 +41,25 @@
*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 @@
{
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
Modified: trunk/gdk/quartz/gdkwindow-quartz.c
==============================================================================
--- trunk/gdk/quartz/gdkwindow-quartz.c (original)
+++ trunk/gdk/quartz/gdkwindow-quartz.c Sun Jul 20 16:14:35 2008
@@ -89,6 +89,67 @@
*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 = ▭
+ 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 @@
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 @@
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]