static GType object_type = 0;
if (!object_type)
+ object_type = g_type_register_static_simple (GDK_TYPE_DRAWABLE,
+ "GdkWindow",
+ sizeof (GdkWindowObjectClass),
+ (GClassInitFunc) gdk_window_class_init,
+ sizeof (GdkWindowObject),
+ (GInstanceInitFunc) gdk_window_init,
+ 0);
+
+ return object_type;
+}
+
+GType
+_gdk_paintable_get_type (void)
+{
+ static GType paintable_type = 0;
+
+ if (!paintable_type)
{
- static const GTypeInfo object_info =
+ static const GTypeInfo paintable_info =
{
- sizeof (GdkWindowObjectClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gdk_window_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GdkWindowObject),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gdk_window_init,
+ sizeof (GdkPaintableIface), /* class_size */
+ NULL, /* base_init */
+ NULL, /* base_finalize */
};
-
- object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
- g_intern_static_string ("GdkWindow"),
- &object_info, 0);
+
+ paintable_type = g_type_register_static (G_TYPE_INTERFACE,
+ g_intern_static_string ("GdkPaintable"),
+ &paintable_info, 0);
+
+ g_type_interface_add_prerequisite (paintable_type, G_TYPE_OBJECT);
}
-
- return object_type;
+
+ return paintable_type;
}
static void
GdkWindowObject *private;
GdkWindowObject *temp_private;
GdkWindow *temp_window;
+ GdkScreen *screen;
GList *children;
GList *tmp;
switch (GDK_WINDOW_TYPE (window))
{
+ case GDK_WINDOW_ROOT:
+ screen = gdk_drawable_get_screen (GDK_DRAWABLE (window));
+ if (!screen->closed)
+ {
+ g_error ("attempted to destroy root window");
+ break;
+ }
+ /* else fall thru */
case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_CHILD:
case GDK_WINDOW_DIALOG:
gdk_drawable_set_colormap (GDK_DRAWABLE (window), NULL);
}
break;
-
- case GDK_WINDOW_ROOT:
- g_error ("attempted to destroy root window");
- break;
}
}
* gdk_window_get_toplevels:
*
* Obtains a list of all toplevel windows known to GDK on the default
- * screen (see gdk_window_get_toplevels_for_screen()).
+ * screen (see gdk_screen_get_toplevel_windows()).
* A toplevel window is a child of the root window (see
* gdk_get_default_root_window()).
*
if (GDK_WINDOW_DESTROYED (window))
return;
+ if (GDK_IS_PAINTABLE (private->impl) &&
+ GDK_PAINTABLE_GET_IFACE (private->impl)->begin_paint_region)
+ {
+ GDK_PAINTABLE_GET_IFACE (private->impl)->begin_paint_region (GDK_PAINTABLE (private->impl), region);
+ return;
+ }
+
gdk_region_get_clipbox (region, &clip_box);
paint = g_new (GdkWindowPaint, 1);
if (GDK_WINDOW_DESTROYED (window))
return;
+ if (GDK_IS_PAINTABLE (private->impl) &&
+ GDK_PAINTABLE_GET_IFACE (private->impl)->end_paint)
+ {
+ GDK_PAINTABLE_GET_IFACE (private->impl)->end_paint (GDK_PAINTABLE (private->impl));
+ return;
+ }
+
if (private->paint_stack == NULL)
{
g_warning (G_STRLOC": no preceding call to gdk_window_begin_paint_region(), see documentation");
RESTORE_GC (gc);
}
+typedef struct {
+ cairo_t *cr; /* if non-null, it means use this cairo context */
+ GdkGC *gc; /* if non-null, it means use this GC instead */
+} BackingRectMethod;
+
static void
-gdk_window_set_bg_pattern (GdkWindow *window,
- cairo_t *cr,
- int x_offset,
- int y_offset)
+setup_backing_rect_method (BackingRectMethod *method, GdkWindow *window, GdkWindowPaint *paint, int x_offset_cairo, int y_offset_cairo)
{
GdkWindowObject *private = (GdkWindowObject *)window;
if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG && private->parent)
{
- x_offset += private->x;
- y_offset += private->y;
- gdk_window_set_bg_pattern (GDK_WINDOW (private->parent), cr,
- x_offset, y_offset);
+ GdkWindowPaint tmp_paint;
+
+ tmp_paint = *paint;
+ tmp_paint.x_offset += private->x;
+ tmp_paint.y_offset += private->y;
+
+ x_offset_cairo += private->x;
+ y_offset_cairo += private->y;
+
+ setup_backing_rect_method (method, GDK_WINDOW (private->parent), &tmp_paint, x_offset_cairo, y_offset_cairo);
}
- else if (private->bg_pixmap &&
- private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
- private->bg_pixmap != GDK_NO_BG)
+ else if (private->bg_pixmap &&
+ private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
+ private->bg_pixmap != GDK_NO_BG)
{
+/* This is a workaround for https://bugs.freedesktop.org/show_bug.cgi?id=4320.
+ * In it, using a pixmap as a repeating pattern in Cairo, and painting it to a
+ * pixmap destination surface, can be very slow (on the order of seconds for a
+ * whole-screen copy). The workaround is to use pretty much the same code that
+ * we used in GTK+ 2.6 (pre-Cairo), which clears the double-buffer pixmap with
+ * a tiled GC XFillRectangle().
+ */
+
+/* Actually computing this flag is left as an exercise for the reader */
+#if defined (G_OS_UNIX)
+# define GDK_CAIRO_REPEAT_IS_FAST 0
+#else
+# define GDK_CAIRO_REPEAT_IS_FAST 1
+#endif
+
+#if GDK_CAIRO_REPEAT_IS_FAST
cairo_surface_t *surface = _gdk_drawable_ref_cairo_surface (private->bg_pixmap);
cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface);
cairo_surface_destroy (surface);
- if (x_offset != 0 || y_offset != 0)
+ if (x_offset_cairo != 0 || y_offset_cairo != 0)
{
cairo_matrix_t matrix;
- cairo_matrix_init_translate (&matrix, x_offset, y_offset);
+ cairo_matrix_init_translate (&matrix, x_offset_cairo, y_offset_cairo);
cairo_pattern_set_matrix (pattern, &matrix);
}
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
- cairo_set_source (cr, pattern);
+
+ method->cr = cairo_create (paint->surface);
+ method->gc = NULL;
+
+ cairo_set_source (method->cr, pattern);
cairo_pattern_destroy (pattern);
+#else
+ guint gc_mask;
+ GdkGCValues gc_values;
+
+ gc_values.fill = GDK_TILED;
+ gc_values.tile = private->bg_pixmap;
+ gc_values.ts_x_origin = -x_offset_cairo;
+ gc_values.ts_y_origin = -y_offset_cairo;
+
+ gc_mask = GDK_GC_FILL | GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN;
+
+ method->gc = gdk_gc_new_with_values (paint->pixmap, &gc_values, gc_mask);
+#endif
}
else
{
- gdk_cairo_set_source_color (cr, &private->bg_color);
+ method->cr = cairo_create (paint->surface);
+
+ gdk_cairo_set_source_color (method->cr, &private->bg_color);
}
}
{
GdkWindowObject *private = (GdkWindowObject *)window;
GdkWindowPaint *paint = private->paint_stack->data;
- cairo_t *cr;
+ BackingRectMethod method;
+#if 0
+ GTimer *timer;
+ double elapsed;
+#endif
if (GDK_WINDOW_DESTROYED (window))
return;
- cr = cairo_create (paint->surface);
+#if 0
+ timer = g_timer_new ();
+#endif
+
+ method.cr = NULL;
+ method.gc = NULL;
+ setup_backing_rect_method (&method, window, paint, 0, 0);
+
+ if (method.cr)
+ {
+ g_assert (method.gc == NULL);
+
+ cairo_rectangle (method.cr, x, y, width, height);
+ cairo_clip (method.cr);
+
+ gdk_cairo_region (method.cr, paint->region);
+ cairo_fill (method.cr);
- gdk_window_set_bg_pattern (window, cr, 0, 0);
+ cairo_destroy (method.cr);
+#if 0
+ elapsed = g_timer_elapsed (timer, NULL);
+ g_print ("Draw the background with Cairo: %fs\n", elapsed);
+#endif
+ }
+ else
+ {
+ g_assert (method.gc != NULL);
- cairo_rectangle (cr, x, y, width, height);
- cairo_clip (cr);
+ gdk_gc_set_clip_region (method.gc, paint->region);
+ gdk_draw_rectangle (window, method.gc, TRUE, x, y, width, height);
+ g_object_unref (method.gc);
- gdk_cairo_region (cr, paint->region);
- cairo_fill (cr);
+#if 0
+ elapsed = g_timer_elapsed (timer, NULL);
+ g_print ("Draw the background with GDK: %fs\n", elapsed);
+#endif
+ }
- cairo_destroy (cr);
+#if 0
+ g_timer_destroy (timer);
+#endif
}
/**
g_slist_free (displays);
}
+/* Currently it is not possible to override
+ * gdk_window_process_all_updates in the same manner as
+ * gdk_window_process_updates and gdk_window_invalidate_maybe_recurse
+ * by implementing the GdkPaintable interface. If in the future a
+ * backend would need this, the right solution would be to add a
+ * method to GdkDisplay that can be optionally
+ * NULL. gdk_window_process_all_updates can then walk the list of open
+ * displays and call the mehod.
+ */
+
/**
* gdk_window_process_all_updates:
*
g_return_if_fail (window != NULL);
g_return_if_fail (GDK_IS_WINDOW (window));
+ if (GDK_IS_PAINTABLE (private->impl) &&
+ GDK_PAINTABLE_GET_IFACE (private->impl)->process_updates)
+ {
+ GDK_PAINTABLE_GET_IFACE (private->impl)->process_updates (GDK_PAINTABLE (private->impl), update_children);
+ return;
+ }
+
if (private->update_area && !private->update_freeze_count)
{
gdk_window_process_updates_internal (window);
if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
return;
+ if (GDK_IS_PAINTABLE (private->impl) &&
+ GDK_PAINTABLE_GET_IFACE (private->impl)->invalidate_maybe_recurse)
+ {
+ GDK_PAINTABLE_GET_IFACE (private->impl)->invalidate_maybe_recurse (GDK_PAINTABLE (private->impl), region,
+ child_func, user_data);
+ return;
+ }
+
visible_region = gdk_drawable_get_visible_region (window);
gdk_region_intersect (visible_region, region);
* @mask: return location for modifier mask
*
* Obtains the current pointer position and modifier state.
- * The position is given in coordinates relative to @window.
+ * The position is given in coordinates relative to the upper left
+ * corner of @window.
*
* Return value: the window containing the pointer (as with
* gdk_window_at_pointer()), or %NULL if the window containing the