From 75c5f6394de4ffa8992a6e04c2af7b715c97c0fd Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 28 May 2003 05:06:32 +0000 Subject: [PATCH] add support for shaped surfaces --- render2/instance.c | 3 +++ render2/instance.h | 4 ++++ render2/render.h | 14 +++++++++++- render2/surface.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ render2/surface.h | 4 ++++ 5 files changed, 79 insertions(+), 1 deletion(-) diff --git a/render2/instance.c b/render2/instance.c index 97036248..7d8d3286 100644 --- a/render2/instance.c +++ b/render2/instance.c @@ -97,6 +97,9 @@ struct RrInstance *RrInstanceNew(Display *display, int screen) RrVisual(inst), AllocNone); inst->glx_context = glXCreateContext(display, &vilist[best], NULL, True); + inst->shape_window = XCreateSimpleWindow(display, + RootWindow(display, screen), + 0, 0, 1, 1, 0, 0, 0); inst->surface_map = g_hash_table_new(g_int_hash, g_int_equal); assert(inst->glx_context); diff --git a/render2/instance.h b/render2/instance.h index c41a96af..a9b7833e 100644 --- a/render2/instance.h +++ b/render2/instance.h @@ -14,6 +14,8 @@ struct RrInstance { Colormap cmap; GLXContext glx_context; + Window shape_window; + GHashTable *surface_map; }; @@ -28,6 +30,8 @@ struct RrInstance { #define RrColormap(i) ((i)->cmap) #define RrContext(i) ((i)->glx_context) +#define RrShapeWindow(i) ((i)->shape_window) + struct RrSurface; void RrInstaceAddSurface(struct RrSurface *sur); diff --git a/render2/render.h b/render2/render.h index 5e218b8e..53599d7e 100644 --- a/render2/render.h +++ b/render2/render.h @@ -125,7 +125,19 @@ void RrSurfaceShow(struct RrSurface *sur); void RrSurfaceHide(struct RrSurface *sur); int RrSurfaceVisible(struct RrSurface *sur); -void RrSurfaceMinSize(struct RrSurface *sur, int *w, int *h); +void RrSurfaceMinSize(struct RrSurface *sur, + int *w, + int *h); + +void RrSurfaceShape(struct RrSurface *sur); + +/*! Set the base shape for a surface. To clear the base, pass 0 for all + of the arguments (except for the surface of course!) +*/ +void RrSurfaceShapeSetBase(struct RrSurface *sur, + Window base, + int x, + int y); /* planar surfaces */ diff --git a/render2/surface.c b/render2/surface.c index b4e03370..4afb35f2 100644 --- a/render2/surface.c +++ b/render2/surface.c @@ -3,6 +3,9 @@ #include #include #include +#ifdef SHAPE +#include +#endif /* doesn't set win or parent */ static struct RrSurface *surface_new(enum RrSurfaceType type, @@ -12,6 +15,9 @@ static struct RrSurface *surface_new(enum RrSurfaceType type, sur = malloc(sizeof(struct RrSurface)); sur->type = type; + sur->shape_base = None; + sur->shape_base_x = 0; + sur->shape_base_y = 0; sur->ntextures = numtex; if (numtex) { sur->texture = malloc(sizeof(struct RrTexture) * numtex); @@ -277,5 +283,54 @@ void RrSurfaceHide(struct RrSurface *sur) int RrSurfaceVisible(struct RrSurface *sur) { + assert(sur->inst); return sur->visible; } + +void RrSurfaceShapeSetBase(struct RrSurface *sur, Window base, int x, int y) +{ + assert(sur->inst); + sur->shape_base = base; + sur->shape_base_x = x; + sur->shape_base_y = y; +} + +void RrSurfaceShape(struct RrSurface *sur) +{ + GSList *it; + + assert(sur->inst); + +#ifdef SHAPE + XResizeWindow(RrDisplay(sur->inst), RrShapeWindow(sur->inst), + sur->w, sur->h); + XShapeCombineShape(RrDisplay(sur->inst), RrShapeWindow(sur->inst), + ShapeBounding, + sur->shape_base_x, sur->shape_base_y, + sur->shape_base, ShapeBounding, ShapeSet); + /* include the shape of the children */ + for (it = sur->children; it; it = g_slist_next(it)) { + struct RrSurface *ch = it->data; + if (ch->win) + XShapeCombineShape(RrDisplay(sur->inst), + RrShapeWindow(sur->inst), + ShapeBounding, ch->x, ch->y, ch->win, + ShapeBounding, ShapeUnion); + } + switch (sur->type) { + case RR_SURFACE_NONE: + break; + case RR_SURFACE_PLANAR: + /* XXX shape me based on something! an alpha mask? */ + break; + case RR_SURFACE_NONPLANAR: + /* XXX shape me based on my GL form! */ + assert(0); + break; + } + + /* apply the final shape */ + XShapeCombineShape(RrDisplay(sur->inst), sur->win, ShapeBounding, 0, 0, + RrShapeWindow(sur->inst), ShapeBounding, ShapeSet); +#endif +} diff --git a/render2/surface.h b/render2/surface.h index d3bc9a4f..39dbffc2 100644 --- a/render2/surface.h +++ b/render2/surface.h @@ -29,6 +29,10 @@ struct RrSurface { */ Window win; /* XXX this can optionally be None if parent != NULL ... */ + Window shape_base; + int shape_base_x; + int shape_base_y; + int ntextures; struct RrTexture *texture; -- 2.39.2