Remove MetaRegion

In many places, MetaRegion was being used entirely internally, rather
than for gtk2/gtk3 compatibility. In these cases, it's simpler to just
depend on cairo-1.10 (for both gtk2 and gtk3) and use cairo_region_t.

The few places where we did need GDK compatibility (GdkEvent.region and
gdk_window_shape_combine_mask) are replaced with a combination of
converting GdkRegion to cairo_region_t and conditional code.

https://bugzilla.gnome.org/show_bug.cgi?id=632474
This commit is contained in:
Owen W. Taylor 2010-10-18 11:32:50 -04:00
parent 9a4d1686a6
commit 804117c456
14 changed files with 189 additions and 244 deletions

View File

@ -154,7 +154,7 @@ esac
AM_CONDITIONAL(INSTALL_LIBMUTTER_PRIVATE, test "$with_gtk" = "3.0") AM_CONDITIONAL(INSTALL_LIBMUTTER_PRIVATE, test "$with_gtk" = "3.0")
MUTTER_PC_MODULES="gtk+-$GTK_API_VERSION >= $GTK_MIN_VERSION pango >= 1.2.0" MUTTER_PC_MODULES="gtk+-$GTK_API_VERSION >= $GTK_MIN_VERSION pango >= 1.2.0 cairo >= 1.10.0"
AC_SUBST(GTK_API_VERSION) AC_SUBST(GTK_API_VERSION)
AC_ARG_ENABLE(gconf, AC_ARG_ENABLE(gconf,

View File

@ -50,7 +50,6 @@ mutter_SOURCES= \
include/compositor.h \ include/compositor.h \
include/mutter-plugin.h \ include/mutter-plugin.h \
include/mutter-window.h \ include/mutter-window.h \
include/region.h \
include/compositor-mutter.h \ include/compositor-mutter.h \
core/constraints.c \ core/constraints.c \
core/constraints.h \ core/constraints.h \
@ -147,7 +146,6 @@ libmutter_private_la_SOURCES= \
include/common.h \ include/common.h \
ui/preview-widget.c \ ui/preview-widget.c \
ui/preview-widget.h \ ui/preview-widget.h \
include/region.h \
gdk2-drawing-utils.c \ gdk2-drawing-utils.c \
gdk2-drawing-utils.h \ gdk2-drawing-utils.h \
ui/theme-parser.c \ ui/theme-parser.c \
@ -187,8 +185,7 @@ libmutterinclude_base_headers = \
# atomnames.h: macros cause problems for scanning process # atomnames.h: macros cause problems for scanning process
libmutterinclude_extra_headers = \ libmutterinclude_extra_headers = \
ui/preview-widget.h \ ui/preview-widget.h \
include/atomnames.h \ include/atomnames.h
include/region.h
if INSTALL_LIBMUTTER_PRIVATE if INSTALL_LIBMUTTER_PRIVATE
libmutterincludedir = $(includedir)/mutter/mutter-private libmutterincludedir = $(includedir)/mutter/mutter-private

View File

@ -68,7 +68,7 @@ struct _MutterShapedTexturePrivate
CoglHandle material; CoglHandle material;
CoglHandle material_unshaped; CoglHandle material_unshaped;
MetaRegion *clip_region; cairo_region_t *clip_region;
guint mask_width, mask_height; guint mask_width, mask_height;
@ -303,7 +303,7 @@ mutter_shaped_texture_paint (ClutterActor *actor)
CoglHandle material; CoglHandle material;
if (priv->clip_region && meta_region_is_empty (priv->clip_region)) if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
return; return;
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex))) if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex)))
@ -386,7 +386,6 @@ mutter_shaped_texture_paint (ClutterActor *actor)
if (priv->clip_region) if (priv->clip_region)
{ {
GdkRectangle *rects;
int n_rects; int n_rects;
int i; int i;
@ -394,31 +393,27 @@ mutter_shaped_texture_paint (ClutterActor *actor)
* fall back and draw the whole thing */ * fall back and draw the whole thing */
# define MAX_RECTS 16 # define MAX_RECTS 16
/* Would be nice to be able to check the number of rects first */ n_rects = cairo_region_num_rectangles (priv->clip_region);
meta_region_get_rectangles (priv->clip_region, &rects, &n_rects); if (n_rects <= MAX_RECTS)
if (n_rects > MAX_RECTS)
{
g_free (rects);
/* Fall through to following code */
}
else
{ {
float coords[8]; float coords[8];
float x1, y1, x2, y2; float x1, y1, x2, y2;
for (i = 0; i < n_rects; i++) for (i = 0; i < n_rects; i++)
{ {
GdkRectangle *rect = &rects[i]; cairo_rectangle_int_t rect;
x1 = rect->x; cairo_region_get_rectangle (priv->clip_region, i, &rect);
y1 = rect->y;
x2 = rect->x + rect->width;
y2 = rect->y + rect->height;
coords[0] = rect->x / (alloc.x2 - alloc.x1); x1 = rect.x;
coords[1] = rect->y / (alloc.y2 - alloc.y1); y1 = rect.y;
coords[2] = (rect->x + rect->width) / (alloc.x2 - alloc.x1); x2 = rect.x + rect.width;
coords[3] = (rect->y + rect->height) / (alloc.y2 - alloc.y1); y2 = rect.y + rect.height;
coords[0] = rect.x / (alloc.x2 - alloc.x1);
coords[1] = rect.y / (alloc.y2 - alloc.y1);
coords[2] = (rect.x + rect.width) / (alloc.x2 - alloc.x1);
coords[3] = (rect.y + rect.height) / (alloc.y2 - alloc.y1);
coords[4] = coords[0]; coords[4] = coords[0];
coords[5] = coords[1]; coords[5] = coords[1];
@ -429,8 +424,6 @@ mutter_shaped_texture_paint (ClutterActor *actor)
&coords[0], 8); &coords[0], 8);
} }
g_free (rects);
return; return;
} }
} }
@ -624,7 +617,7 @@ mutter_shaped_texture_add_rectangles (MutterShapedTexture *stex,
*/ */
void void
mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex, mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex,
MetaRegion *clip_region) cairo_region_t *clip_region)
{ {
MutterShapedTexturePrivate *priv; MutterShapedTexturePrivate *priv;
@ -634,7 +627,7 @@ mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex,
if (priv->clip_region) if (priv->clip_region)
{ {
meta_region_destroy (priv->clip_region); cairo_region_destroy (priv->clip_region);
priv->clip_region = NULL; priv->clip_region = NULL;
} }

View File

@ -33,8 +33,6 @@
#include <clutter/glx/clutter-glx.h> #include <clutter/glx/clutter-glx.h>
#endif /* HAVE_GLX_TEXTURE_PIXMAP */ #endif /* HAVE_GLX_TEXTURE_PIXMAP */
#include "region.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define MUTTER_TYPE_SHAPED_TEXTURE \ #define MUTTER_TYPE_SHAPED_TEXTURE \
@ -101,7 +99,7 @@ void mutter_shaped_texture_add_rectangles (MutterShapedTexture *stex,
/* Assumes ownership of clip_region */ /* Assumes ownership of clip_region */
void mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex, void mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex,
MetaRegion *clip_region); cairo_region_t *clip_region);
G_END_DECLS G_END_DECLS

View File

@ -7,7 +7,6 @@
#include "mutter-window-private.h" #include "mutter-window-private.h"
#include "mutter-window-group.h" #include "mutter-window-group.h"
#include "region.h"
struct _MutterWindowGroupClass struct _MutterWindowGroupClass
{ {
@ -102,8 +101,8 @@ static void
mutter_window_group_paint (ClutterActor *actor) mutter_window_group_paint (ClutterActor *actor)
{ {
MutterWindowGroup *window_group = MUTTER_WINDOW_GROUP (actor); MutterWindowGroup *window_group = MUTTER_WINDOW_GROUP (actor);
MetaRegion *visible_region; cairo_region_t *visible_region;
GdkRectangle screen_rect = { 0 }; cairo_rectangle_int_t screen_rect = { 0 };
GList *children, *l; GList *children, *l;
/* We walk the list from top to bottom (opposite of painting order), /* We walk the list from top to bottom (opposite of painting order),
@ -119,7 +118,7 @@ mutter_window_group_paint (ClutterActor *actor)
* optimization, however.) * optimization, however.)
*/ */
meta_screen_get_size (window_group->screen, &screen_rect.width, &screen_rect.height); meta_screen_get_size (window_group->screen, &screen_rect.width, &screen_rect.height);
visible_region = meta_region_new_from_rectangle (&screen_rect); visible_region = cairo_region_create_rectangle (&screen_rect);
for (l = children; l; l = l->next) for (l = children; l; l = l->next)
{ {
@ -135,22 +134,22 @@ mutter_window_group_paint (ClutterActor *actor)
continue; continue;
/* Temporarily move to the coordinate system of the actor */ /* Temporarily move to the coordinate system of the actor */
meta_region_translate (visible_region, - x, - y); cairo_region_translate (visible_region, - x, - y);
mutter_window_set_visible_region (cw, visible_region); mutter_window_set_visible_region (cw, visible_region);
if (clutter_actor_get_paint_opacity (CLUTTER_ACTOR (cw)) == 0xff) if (clutter_actor_get_paint_opacity (CLUTTER_ACTOR (cw)) == 0xff)
{ {
MetaRegion *obscured_region = mutter_window_get_obscured_region (cw); cairo_region_t *obscured_region = mutter_window_get_obscured_region (cw);
if (obscured_region) if (obscured_region)
meta_region_subtract (visible_region, obscured_region); cairo_region_subtract (visible_region, obscured_region);
} }
mutter_window_set_visible_region_beneath (cw, visible_region); mutter_window_set_visible_region_beneath (cw, visible_region);
meta_region_translate (visible_region, x, y); cairo_region_translate (visible_region, x, y);
} }
meta_region_destroy (visible_region); cairo_region_destroy (visible_region);
CLUTTER_ACTOR_CLASS (mutter_window_group_parent_class)->paint (actor); CLUTTER_ACTOR_CLASS (mutter_window_group_parent_class)->paint (actor);

View File

@ -7,7 +7,6 @@
#include <X11/extensions/Xdamage.h> #include <X11/extensions/Xdamage.h>
#include "compositor-mutter.h" #include "compositor-mutter.h"
#include "region.h"
MutterWindow *mutter_window_new (MetaWindow *window); MutterWindow *mutter_window_new (MetaWindow *window);
@ -38,12 +37,12 @@ void mutter_window_update_opacity (MutterWindow *cw);
void mutter_window_mapped (MutterWindow *cw); void mutter_window_mapped (MutterWindow *cw);
void mutter_window_unmapped (MutterWindow *cw); void mutter_window_unmapped (MutterWindow *cw);
MetaRegion *mutter_window_get_obscured_region (MutterWindow *cw); cairo_region_t *mutter_window_get_obscured_region (MutterWindow *cw);
void mutter_window_set_visible_region (MutterWindow *cw, void mutter_window_set_visible_region (MutterWindow *cw,
MetaRegion *visible_region); cairo_region_t *visible_region);
void mutter_window_set_visible_region_beneath (MutterWindow *cw, void mutter_window_set_visible_region_beneath (MutterWindow *cw,
MetaRegion *beneath_region); cairo_region_t *beneath_region);
void mutter_window_reset_visible_regions (MutterWindow *cw); void mutter_window_reset_visible_regions (MutterWindow *cw);
void mutter_window_effect_completed (MutterWindow *actor, void mutter_window_effect_completed (MutterWindow *actor,

View File

@ -41,10 +41,10 @@ struct _MutterWindowPrivate
gchar * desc; gchar * desc;
/* If the window is shaped, a region that matches the shape */ /* If the window is shaped, a region that matches the shape */
MetaRegion *shape_region; cairo_region_t *shape_region;
/* A rectangular region with the unshaped extends of the window /* A rectangular region with the unshaped extends of the window
* texture */ * texture */
MetaRegion *bounding_region; cairo_region_t *bounding_region;
gint freeze_count; gint freeze_count;
@ -1341,7 +1341,7 @@ mutter_window_clear_shape_region (MutterWindow *self)
if (priv->shape_region) if (priv->shape_region)
{ {
meta_region_destroy (priv->shape_region); cairo_region_destroy (priv->shape_region);
priv->shape_region = NULL; priv->shape_region = NULL;
} }
} }
@ -1353,7 +1353,7 @@ mutter_window_clear_bounding_region (MutterWindow *self)
if (priv->bounding_region) if (priv->bounding_region)
{ {
meta_region_destroy (priv->bounding_region); cairo_region_destroy (priv->bounding_region);
priv->bounding_region = NULL; priv->bounding_region = NULL;
} }
} }
@ -1364,11 +1364,11 @@ mutter_window_update_bounding_region (MutterWindow *self,
int height) int height)
{ {
MutterWindowPrivate *priv = self->priv; MutterWindowPrivate *priv = self->priv;
GdkRectangle bounding_rectangle = { 0, 0, width, height }; cairo_rectangle_int_t bounding_rectangle = { 0, 0, width, height };
mutter_window_clear_bounding_region (self); mutter_window_clear_bounding_region (self);
priv->bounding_region = meta_region_new_from_rectangle (&bounding_rectangle); priv->bounding_region = cairo_region_create_rectangle (&bounding_rectangle);
} }
static void static void
@ -1381,11 +1381,11 @@ mutter_window_update_shape_region (MutterWindow *self,
mutter_window_clear_shape_region (self); mutter_window_clear_shape_region (self);
priv->shape_region = meta_region_new (); priv->shape_region = cairo_region_create ();
for (i = 0; i < n_rects; i++) for (i = 0; i < n_rects; i++)
{ {
GdkRectangle rect = { rects[i].x, rects[i].y, rects[i].width, rects[i].height }; cairo_rectangle_int_t rect = { rects[i].x, rects[i].y, rects[i].width, rects[i].height };
meta_region_union_rectangle (priv->shape_region, &rect); cairo_region_union_rectangle (priv->shape_region, &rect);
} }
} }
@ -1399,7 +1399,7 @@ mutter_window_update_shape_region (MutterWindow *self,
* Return value: (transfer none): the area obscured by the window, * Return value: (transfer none): the area obscured by the window,
* %NULL is the same as an empty region. * %NULL is the same as an empty region.
*/ */
MetaRegion * cairo_region_t *
mutter_window_get_obscured_region (MutterWindow *self) mutter_window_get_obscured_region (MutterWindow *self)
{ {
MutterWindowPrivate *priv = self->priv; MutterWindowPrivate *priv = self->priv;
@ -1418,21 +1418,21 @@ mutter_window_get_obscured_region (MutterWindow *self)
#if 0 #if 0
/* Print out a region; useful for debugging */ /* Print out a region; useful for debugging */
static void static void
dump_region (MetaRegion *region) dump_region (cairo_region_t *region)
{ {
GdkRectangle *rects;
int n_rects; int n_rects;
int i; int i;
meta_region_get_rectangles (region, &rects, &n_rects); n_rects = cairo_region_num_rectangles (region);
g_print ("["); g_print ("[");
for (i = 0; i < n_rects; i++) for (i = 0; i < n_rects; i++)
{ {
cairo_rectangle_int_t rect;
cairo_region_get_rectangle (region, &rect);
g_print ("+%d+%dx%dx%d ", g_print ("+%d+%dx%dx%d ",
rects[i].x, rects[i].y, rects[i].width, rects[i].height); rect.x, rect.y, rect.width, rect.height);
} }
g_print ("]\n"); g_print ("]\n");
g_free (rects);
} }
#endif #endif
@ -1447,11 +1447,11 @@ dump_region (MetaRegion *region)
* This will be set before painting then unset afterwards. * This will be set before painting then unset afterwards.
*/ */
void void
mutter_window_set_visible_region (MutterWindow *self, mutter_window_set_visible_region (MutterWindow *self,
MetaRegion *visible_region) cairo_region_t *visible_region)
{ {
MutterWindowPrivate *priv = self->priv; MutterWindowPrivate *priv = self->priv;
MetaRegion *texture_clip_region = NULL; cairo_region_t *texture_clip_region = NULL;
/* Get the area of the window texture that would be drawn if /* Get the area of the window texture that would be drawn if
* we weren't obscured at all * we weren't obscured at all
@ -1459,21 +1459,21 @@ mutter_window_set_visible_region (MutterWindow *self,
if (priv->shaped) if (priv->shaped)
{ {
if (priv->shape_region) if (priv->shape_region)
texture_clip_region = meta_region_copy (priv->shape_region); texture_clip_region = cairo_region_copy (priv->shape_region);
} }
else else
{ {
if (priv->bounding_region) if (priv->bounding_region)
texture_clip_region = meta_region_copy (priv->bounding_region); texture_clip_region = cairo_region_copy (priv->bounding_region);
} }
if (!texture_clip_region) if (!texture_clip_region)
texture_clip_region = meta_region_new (); texture_clip_region = cairo_region_create ();
/* Then intersect that with the visible region to get the region /* Then intersect that with the visible region to get the region
* that we actually need to redraw. * that we actually need to redraw.
*/ */
meta_region_intersect (texture_clip_region, visible_region); cairo_region_intersect (texture_clip_region, visible_region);
/* Assumes ownership */ /* Assumes ownership */
mutter_shaped_texture_set_clip_region (MUTTER_SHAPED_TEXTURE (priv->actor), mutter_shaped_texture_set_clip_region (MUTTER_SHAPED_TEXTURE (priv->actor),
@ -1493,16 +1493,16 @@ mutter_window_set_visible_region (MutterWindow *self,
* then unset afterwards. * then unset afterwards.
*/ */
void void
mutter_window_set_visible_region_beneath (MutterWindow *self, mutter_window_set_visible_region_beneath (MutterWindow *self,
MetaRegion *beneath_region) cairo_region_t *beneath_region)
{ {
MutterWindowPrivate *priv = self->priv; MutterWindowPrivate *priv = self->priv;
if (priv->shadow) if (priv->shadow)
{ {
GdkRectangle shadow_rect; cairo_rectangle_int_t shadow_rect;
ClutterActorBox box; ClutterActorBox box;
MetaOverlapType overlap; cairo_region_overlap_t overlap;
/* We could compute an full clip region as we do for the window /* We could compute an full clip region as we do for the window
* texture, but the shadow is relatively cheap to draw, and * texture, but the shadow is relatively cheap to draw, and
@ -1517,10 +1517,10 @@ mutter_window_set_visible_region_beneath (MutterWindow *self,
shadow_rect.width = roundf (box.x2 - box.x1); shadow_rect.width = roundf (box.x2 - box.x1);
shadow_rect.height = roundf (box.y2 - box.y1); shadow_rect.height = roundf (box.y2 - box.y1);
overlap = meta_region_contains_rectangle (beneath_region, &shadow_rect); overlap = cairo_region_contains_rectangle (beneath_region, &shadow_rect);
tidy_texture_frame_set_needs_paint (TIDY_TEXTURE_FRAME (priv->shadow), tidy_texture_frame_set_needs_paint (TIDY_TEXTURE_FRAME (priv->shadow),
overlap != META_REGION_OVERLAP_OUT); overlap != CAIRO_REGION_OVERLAP_OUT);
} }
} }

View File

@ -880,29 +880,5 @@ meta_later_remove (guint later_id)
} }
} }
#ifdef USE_CAIRO_REGION
#include "region.h"
void
meta_region_get_rectangles (MetaRegion *region,
GdkRectangle **rectangles,
int *n_rectangles)
{
int n = cairo_region_num_rectangles (region);
if (n_rectangles != NULL)
*n_rectangles = n;
if (rectangles != NULL)
{
int i;
*rectangles = g_new (cairo_rectangle_int_t, n);
for (i = 0; i < n; i++)
cairo_region_get_rectangle (region, i, *rectangles + i);
}
}
#endif
/* eof util.c */ /* eof util.c */

View File

@ -1,60 +0,0 @@
#ifndef META_REGION_H
#define META_REGION_H
#ifndef PACKAGE_NAME
#error "<config.h> must be included before region.h"
#endif
#include <gdk/gdk.h>
#ifdef USE_CAIRO_REGION
#include <cairo.h>
#define MetaRegion cairo_region_t
typedef enum {
META_REGION_OVERLAP_IN = CAIRO_REGION_OVERLAP_IN,
META_REGION_OVERLAP_OUT = CAIRO_REGION_OVERLAP_OUT,
META_REGION_OVERLAP_PART = CAIRO_REGION_OVERLAP_PART
} MetaOverlapType;
#define meta_region_new() cairo_region_create()
#define meta_region_new_from_rectangle(rect) cairo_region_create_rectangle(rect)
#define meta_region_copy(r) cairo_region_copy(r)
#define meta_region_destroy(r) cairo_region_destroy(r)
#define meta_region_is_empty(r) cairo_region_is_empty(r)
#define meta_region_union_rectangle(r, rect) cairo_region_union_rectangle(r, rect)
#define meta_region_subtract(r, other) cairo_region_subtract(r, other)
#define meta_region_translate(r, x, y) cairo_region_translate(r, x, y)
#define meta_region_intersect(r, other) cairo_region_intersect(r, other)
#define meta_region_contains_rectangle(r, rect) cairo_region_contains_rectangle(r, rect)
void meta_region_get_rectangles (MetaRegion *region,
GdkRectangle **rectangles,
int *n_rectangles);
#else
#define MetaRegion GdkRegion
typedef enum {
META_REGION_OVERLAP_IN = GDK_OVERLAP_RECTANGLE_IN,
META_REGION_OVERLAP_OUT = GDK_OVERLAP_RECTANGLE_OUT,
META_REGION_OVERLAP_PART = GDK_OVERLAP_RECTANGLE_PART
} MetaOverlapType;
#define meta_region_new() gdk_region_new()
#define meta_region_new_from_rectangle(rect) gdk_region_rectangle(rect)
#define meta_region_copy(r) gdk_region_copy(r)
#define meta_region_destroy(r) gdk_region_destroy(r)
#define meta_region_is_empty(r) gdk_region_empty(r)
#define meta_region_union_rectangle(r, rect) gdk_region_union_with_rect(r, rect)
#define meta_region_subtract(r, other) gdk_region_subtract(r, other)
#define meta_region_translate(r, x, y) gdk_region_offset(r, x, y)
#define meta_region_intersect(r, other) gdk_region_intersect(r, other)
#define meta_region_contains_rectangle(r, rect) gdk_region_rect_in(r, rect)
#define meta_region_get_rectangles(r, rects, num) gdk_region_get_rectangles(r, rects, num)
#endif /* HAVE_CAIRO_REGION */
#endif /* META_REGION_H */

View File

@ -27,7 +27,6 @@
#include <math.h> #include <math.h>
#include "boxes.h" #include "boxes.h"
#include "frames.h" #include "frames.h"
#include "region.h"
#include "util.h" #include "util.h"
#include "core.h" #include "core.h"
#include "menu.h" #include "menu.h"
@ -300,7 +299,7 @@ meta_frames_finalize (GObject *object)
typedef struct typedef struct
{ {
GdkRectangle rect; cairo_rectangle_int_t rect;
MetaPixmap *pixmap; MetaPixmap *pixmap;
} CachedFramePiece; } CachedFramePiece;
@ -2111,9 +2110,9 @@ setup_bg_cr (cairo_t *cr, GdkWindow *window, int x_offset, int y_offset)
*/ */
static MetaPixmap * static MetaPixmap *
generate_pixmap (MetaFrames *frames, generate_pixmap (MetaFrames *frames,
MetaUIFrame *frame, MetaUIFrame *frame,
GdkRectangle *rect) cairo_rectangle_int_t *rect)
{ {
MetaPixmap *result; MetaPixmap *result;
cairo_t *cr; cairo_t *cr;
@ -2220,11 +2219,12 @@ populate_cache (MetaFrames *frames,
} }
static void static void
clip_to_screen (MetaRegion *region, MetaUIFrame *frame) clip_to_screen (cairo_region_t *region,
MetaUIFrame *frame)
{ {
GdkRectangle frame_area; cairo_rectangle_int_t frame_area;
GdkRectangle screen_area = { 0, 0, 0, 0 }; cairo_rectangle_int_t screen_area = { 0, 0, 0, 0 };
MetaRegion *tmp_region; cairo_region_t *tmp_region;
/* Chop off stuff outside the screen; this optimization /* Chop off stuff outside the screen; this optimization
* is crucial to handle huge client windows, * is crucial to handle huge client windows,
@ -2240,26 +2240,27 @@ clip_to_screen (MetaRegion *region, MetaUIFrame *frame)
META_CORE_GET_SCREEN_HEIGHT, &screen_area.height, META_CORE_GET_SCREEN_HEIGHT, &screen_area.height,
META_CORE_GET_END); META_CORE_GET_END);
meta_region_translate (region, frame_area.x, frame_area.y); cairo_region_translate (region, frame_area.x, frame_area.y);
tmp_region = meta_region_new_from_rectangle (&frame_area); tmp_region = cairo_region_create_rectangle (&frame_area);
meta_region_intersect (region, tmp_region); cairo_region_intersect (region, tmp_region);
meta_region_destroy (tmp_region); cairo_region_destroy (tmp_region);
tmp_region = meta_region_new_from_rectangle (&screen_area); tmp_region = cairo_region_create_rectangle (&screen_area);
meta_region_intersect (region, tmp_region); cairo_region_intersect (region, tmp_region);
meta_region_destroy (tmp_region); cairo_region_destroy (tmp_region);
meta_region_translate (region, - frame_area.x, - frame_area.y); cairo_region_translate (region, - frame_area.x, - frame_area.y);
} }
static void static void
subtract_client_area (MetaRegion *region, MetaUIFrame *frame) subtract_client_area (cairo_region_t *region,
MetaUIFrame *frame)
{ {
GdkRectangle area; cairo_rectangle_int_t area;
MetaFrameFlags flags; MetaFrameFlags flags;
MetaFrameType type; MetaFrameType type;
MetaRegion *tmp_region; cairo_region_t *tmp_region;
Display *display; Display *display;
display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
@ -2274,17 +2275,17 @@ subtract_client_area (MetaRegion *region, MetaUIFrame *frame)
type, frame->text_height, flags, type, frame->text_height, flags,
&area.y, NULL, &area.x, NULL); &area.y, NULL, &area.x, NULL);
tmp_region = meta_region_new_from_rectangle (&area); tmp_region = cairo_region_create_rectangle (&area);
meta_region_subtract (region, tmp_region); cairo_region_subtract (region, tmp_region);
meta_region_destroy (tmp_region); cairo_region_destroy (tmp_region);
} }
static void static void
cached_pixels_draw (CachedPixels *pixels, cached_pixels_draw (CachedPixels *pixels,
cairo_t *cr, cairo_t *cr,
MetaRegion *region) cairo_region_t *region)
{ {
MetaRegion *region_piece; cairo_region_t *region_piece;
int i; int i;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
@ -2298,9 +2299,9 @@ cached_pixels_draw (CachedPixels *pixels,
piece->rect.x, piece->rect.y); piece->rect.x, piece->rect.y);
cairo_paint (cr); cairo_paint (cr);
region_piece = meta_region_new_from_rectangle (&piece->rect); region_piece = cairo_region_create_rectangle (&piece->rect);
meta_region_subtract (region, region_piece); cairo_region_subtract (region, region_piece);
meta_region_destroy (region_piece); cairo_region_destroy (region_piece);
} }
} }
} }
@ -2313,8 +2314,8 @@ meta_frames_draw (GtkWidget *widget,
MetaUIFrame *frame; MetaUIFrame *frame;
MetaFrames *frames; MetaFrames *frames;
CachedPixels *pixels; CachedPixels *pixels;
MetaRegion *region; cairo_region_t *region;
GdkRectangle *areas, clip; cairo_rectangle_int_t clip;
int i, n_areas; int i, n_areas;
cairo_surface_t *target; cairo_surface_t *target;
@ -2336,7 +2337,7 @@ meta_frames_draw (GtkWidget *widget,
populate_cache (frames, frame); populate_cache (frames, frame);
region = meta_region_new_from_rectangle (&clip); region = cairo_region_create_rectangle (&clip);
pixels = get_cache (frames, frame); pixels = get_cache (frames, frame);
@ -2345,13 +2346,17 @@ meta_frames_draw (GtkWidget *widget,
clip_to_screen (region, frame); clip_to_screen (region, frame);
subtract_client_area (region, frame); subtract_client_area (region, frame);
meta_region_get_rectangles (region, &areas, &n_areas); n_areas = cairo_region_num_rectangles (region);
for (i = 0; i < n_areas; i++) for (i = 0; i < n_areas; i++)
{ {
cairo_rectangle_int_t area;
cairo_region_get_rectangle (region, i, &area);
cairo_save (cr); cairo_save (cr);
gdk_cairo_rectangle (cr, &areas[i]); cairo_rectangle (cr, area.x, area.y, area.width, area.height);
cairo_clip (cr); cairo_clip (cr);
cairo_push_group (cr); cairo_push_group (cr);
@ -2364,9 +2369,7 @@ meta_frames_draw (GtkWidget *widget,
cairo_restore (cr); cairo_restore (cr);
} }
g_free (areas); cairo_region_destroy (region);
meta_region_destroy (region);
return TRUE; return TRUE;
} }
@ -2378,9 +2381,10 @@ meta_frames_expose_event (GtkWidget *widget,
MetaUIFrame *frame; MetaUIFrame *frame;
MetaFrames *frames; MetaFrames *frames;
CachedPixels *pixels; CachedPixels *pixels;
MetaRegion *region, *area_region; cairo_region_t *region;
GdkRectangle *areas;
int i, n_areas; int i, n_areas;
GdkRectangle *event_rectangles;
int n_event_rectangles;
cairo_t *cr; cairo_t *cr;
frames = META_FRAMES (widget); frames = META_FRAMES (widget);
@ -2398,7 +2402,11 @@ meta_frames_expose_event (GtkWidget *widget,
populate_cache (frames, frame); populate_cache (frames, frame);
region = meta_region_copy (event->region); /* Count on GdkRectangle and cairo_rectangle_int_t being identical */
gdk_region_get_rectangles (event->region, &event_rectangles, &n_event_rectangles);
region = cairo_region_create_rectangles ((cairo_rectangle_int_t *)event_rectangles,
n_event_rectangles);
g_free (event_rectangles);
pixels = get_cache (frames, frame); pixels = get_cache (frames, frame);
@ -2409,13 +2417,16 @@ meta_frames_expose_event (GtkWidget *widget,
clip_to_screen (region, frame); clip_to_screen (region, frame);
subtract_client_area (region, frame); subtract_client_area (region, frame);
meta_region_get_rectangles (region, &areas, &n_areas); n_areas = cairo_region_num_rectangles (region);
for (i = 0; i < n_areas; i++) for (i = 0; i < n_areas; i++)
{ {
area_region = meta_region_new_from_rectangle (&areas[i]); GdkRectangle area;
gdk_window_begin_paint_region (event->window, area_region); /* Count on GdkRectangle and cairo_rectangle_int_t being identical */
cairo_region_get_rectangle (region, i, (cairo_rectangle_int_t *)&area);
gdk_window_begin_paint_rect (event->window, &area);
cr = gdk_cairo_create (event->window); cr = gdk_cairo_create (event->window);
/* no need to clip, begin_paint_region ensures the pixmap /* no need to clip, begin_paint_region ensures the pixmap
* is only as big as the rect we use. */ * is only as big as the rect we use. */
@ -2424,13 +2435,9 @@ meta_frames_expose_event (GtkWidget *widget,
cairo_destroy (cr); cairo_destroy (cr);
gdk_window_end_paint (event->window); gdk_window_end_paint (event->window);
meta_region_destroy (area_region);
} }
g_free (areas); cairo_region_destroy (region);
meta_region_destroy (region);
return TRUE; return TRUE;
} }
@ -2745,7 +2752,7 @@ get_control (MetaFrames *frames,
MetaFrameGeometry fgeom; MetaFrameGeometry fgeom;
MetaFrameFlags flags; MetaFrameFlags flags;
gboolean has_vert, has_horiz; gboolean has_vert, has_horiz;
GdkRectangle client; cairo_rectangle_int_t client;
meta_frames_calc_geometry (frames, frame, &fgeom); meta_frames_calc_geometry (frames, frame, &fgeom);

View File

@ -487,11 +487,11 @@ meta_preview_get_mini_icon (void)
return default_icon; return default_icon;
} }
MetaRegion * cairo_region_t *
meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint new_window_height) meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint new_window_height)
{ {
GdkRectangle xrect; cairo_rectangle_int_t xrect;
MetaRegion *corners_xregion, *window_xregion; cairo_region_t *corners_xregion, *window_xregion;
gint flags; gint flags;
MetaFrameLayout *fgeom; MetaFrameLayout *fgeom;
MetaFrameStyle *frame_style; MetaFrameStyle *frame_style;
@ -500,14 +500,14 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
flags = (META_PREVIEW (preview)->flags); flags = (META_PREVIEW (preview)->flags);
window_xregion = meta_region_new (); window_xregion = cairo_region_create ();
xrect.x = 0; xrect.x = 0;
xrect.y = 0; xrect.y = 0;
xrect.width = new_window_width; xrect.width = new_window_width;
xrect.height = new_window_height; xrect.height = new_window_height;
meta_region_union_rectangle (window_xregion, &xrect); cairo_region_union_rectangle (window_xregion, &xrect);
if (preview->theme == NULL) if (preview->theme == NULL)
return window_xregion; return window_xregion;
@ -518,7 +518,7 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
fgeom = frame_style->layout; fgeom = frame_style->layout;
corners_xregion = meta_region_new (); corners_xregion = cairo_region_create ();
if (fgeom->top_left_corner_rounded_radius != 0) if (fgeom->top_left_corner_rounded_radius != 0)
{ {
@ -535,7 +535,7 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
xrect.width = width; xrect.width = width;
xrect.height = 1; xrect.height = 1;
meta_region_union_rectangle (corners_xregion, &xrect); cairo_region_union_rectangle (corners_xregion, &xrect);
} }
} }
@ -553,7 +553,7 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
xrect.width = width; xrect.width = width;
xrect.height = 1; xrect.height = 1;
meta_region_union_rectangle (corners_xregion, &xrect); cairo_region_union_rectangle (corners_xregion, &xrect);
} }
} }
@ -571,7 +571,7 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
xrect.width = width; xrect.width = width;
xrect.height = 1; xrect.height = 1;
meta_region_union_rectangle (corners_xregion, &xrect); cairo_region_union_rectangle (corners_xregion, &xrect);
} }
} }
@ -589,12 +589,12 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
xrect.width = width; xrect.width = width;
xrect.height = 1; xrect.height = 1;
meta_region_union_rectangle (corners_xregion, &xrect); cairo_region_union_rectangle (corners_xregion, &xrect);
} }
} }
meta_region_subtract (window_xregion, corners_xregion); cairo_region_subtract (window_xregion, corners_xregion);
meta_region_destroy (corners_xregion); cairo_region_destroy (corners_xregion);
return window_xregion; return window_xregion;
} }

View File

@ -24,7 +24,6 @@
#include <config.h> #include <config.h>
#include "theme.h" #include "theme.h"
#include "region.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#ifndef META_PREVIEW_WIDGET_H #ifndef META_PREVIEW_WIDGET_H
@ -80,9 +79,9 @@ void meta_preview_set_frame_flags (MetaPreview *preview,
void meta_preview_set_button_layout (MetaPreview *preview, void meta_preview_set_button_layout (MetaPreview *preview,
const MetaButtonLayout *button_layout); const MetaButtonLayout *button_layout);
MetaRegion * meta_preview_get_clip_region (MetaPreview *preview, cairo_region_t * meta_preview_get_clip_region (MetaPreview *preview,
gint new_window_width, gint new_window_width,
gint new_window_height); gint new_window_height);
GdkPixbuf* meta_preview_get_icon (void); GdkPixbuf* meta_preview_get_icon (void);
GdkPixbuf* meta_preview_get_mini_icon (void); GdkPixbuf* meta_preview_get_mini_icon (void);

View File

@ -32,7 +32,6 @@
*/ */
#include "../core/workspace-private.h" #include "../core/workspace-private.h"
#include "../core/frame-private.h" #include "../core/frame-private.h"
#include "region.h"
#include "draw-workspace.h" #include "draw-workspace.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <math.h> #include <math.h>
@ -481,8 +480,6 @@ display_entry (MetaTabPopup *popup,
{ {
GdkRectangle rect; GdkRectangle rect;
GdkWindow *window; GdkWindow *window;
MetaRegion *region;
MetaRegion *inner_region;
if (popup->current_selected_entry) if (popup->current_selected_entry)
@ -520,16 +517,39 @@ display_entry (MetaTabPopup *popup,
gdk_window_set_background (window, gdk_window_set_background (window,
&gtk_widget_get_style (popup->outline_window)->black); &gtk_widget_get_style (popup->outline_window)->black);
region = meta_region_new_from_rectangle (&rect); #if GTK_CHECK_VERSION (2, 90, 8) /* gtk3 */
inner_region = meta_region_new_from_rectangle (&te->inner_rect); {
meta_region_subtract (region, inner_region); cairo_region_t *region;
meta_region_destroy (inner_region); cairo_region_t *inner_region;
gdk_window_shape_combine_region (window, region = cairo_region_create_rectangle (&rect);
region, inner_region = cairo_region_create_rectangle (&te->inner_rect);
0, 0); cairo_region_subtract (region, inner_region);
cairo_region_destroy (inner_region);
meta_region_destroy (region); gdk_window_shape_combine_region (window,
region,
0, 0);
cairo_region_destroy (region);
}
#else /* gtk2 */
{
GdkRegion *region;
GdkRegion *inner_region;
region = gdk_region_rectangle (&rect);
inner_region = gdk_region_rectangle (&te->inner_rect);
gdk_region_subtract (region, inner_region);
gdk_region_destroy (inner_region);
gdk_window_shape_combine_region (window,
region,
0, 0);
gdk_region_destroy (region);
}
#endif /* gtk2 */
/* This should piss off gtk a bit, but we don't want to raise /* This should piss off gtk a bit, but we don't want to raise
* above the tab popup. So, instead of calling gtk_widget_show, * above the tab popup. So, instead of calling gtk_widget_show,

View File

@ -28,7 +28,6 @@
#include "tile-preview.h" #include "tile-preview.h"
#include "core.h" #include "core.h"
#include "region.h"
#include "gdk2-drawing-utils.h" #include "gdk2-drawing-utils.h"
@ -241,7 +240,6 @@ meta_tile_preview_show (MetaTilePreview *preview,
if (!preview->has_alpha) if (!preview->has_alpha)
{ {
GdkRectangle outer_rect, inner_rect; GdkRectangle outer_rect, inner_rect;
MetaRegion *outer_region, *inner_region;
GdkColor black; GdkColor black;
black = gtk_widget_get_style (preview->preview_window)->black; black = gtk_widget_get_style (preview->preview_window)->black;
@ -256,14 +254,33 @@ meta_tile_preview_show (MetaTilePreview *preview,
inner_rect.width = outer_rect.width - 2 * OUTLINE_WIDTH; inner_rect.width = outer_rect.width - 2 * OUTLINE_WIDTH;
inner_rect.height = outer_rect.height - 2 * OUTLINE_WIDTH; inner_rect.height = outer_rect.height - 2 * OUTLINE_WIDTH;
outer_region = meta_region_new_from_rectangle (&outer_rect); #if GTK_CHECK_VERSION (2, 90, 8) /* gtk3 */
inner_region = meta_region_new_from_rectangle (&inner_rect); {
cairo_region_t *outer_region, *inner_region;
meta_region_subtract (outer_region, inner_region); outer_region = cairo_region_create_rectangle (&outer_rect);
meta_region_destroy (inner_region); inner_region = cairo_region_create_rectangle (&inner_rect);
gdk_window_shape_combine_region (window, outer_region, 0, 0); cairo_region_subtract (outer_region, inner_region);
meta_region_destroy (outer_region); cairo_region_destroy (inner_region);
gdk_window_shape_combine_region (window, outer_region, 0, 0);
cairo_region_destroy (outer_region);
}
#else /* gtk2 */
{
GdkRegion *outer_region, *inner_region;
outer_region = gdk_region_rectangle (&outer_rect);
inner_region = gdk_region_rectangle (&inner_rect);
gdk_region_subtract (outer_region, inner_region);
gdk_region_destroy (inner_region);
gdk_window_shape_combine_region (window, outer_region, 0, 0);
gdk_region_destroy (outer_region);
}
#endif /* gtk2 */
} }
} }