7 /* doesn't set win or parent */
8 static struct RrSurface *surface_new(enum RrSurfaceType type,
11 struct RrSurface *sur;
13 sur = malloc(sizeof(struct RrSurface));
15 sur->ntextures = numtex;
17 sur->texture = malloc(sizeof(struct RrTexture) * numtex);
18 memset(sur->texture, 0, sizeof(struct RrTexture) * numtex);
30 static Window create_window(struct RrInstance *inst, Window parent)
32 XSetWindowAttributes attrib;
35 attrib.event_mask = ExposureMask;
36 win = XCreateWindow(RrDisplay(inst), parent, 0, 0, 1, 1, 0,
37 RrDepth(inst), InputOutput, RrVisual(inst),
38 CWEventMask, &attrib);
42 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
45 struct RrSurface *sur;
47 sur = surface_new(type, numtex);
55 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
56 enum RrSurfaceType type,
60 struct RrSurface *sur;
62 sur = surface_new(type, numtex);
68 RrInstaceAddSurface(sur);
72 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
73 struct RrSurface *parent,
76 struct RrSurface *sur;
78 /* can't be a child of a prototype! */
80 if (!parent->inst) return NULL;
82 sur = surface_new(type, numtex);
83 sur->inst = parent->inst;
84 sur->win = create_window(sur->inst, parent->win);
88 parent->children = g_slist_append(parent->children, sur);
90 RrInstaceAddSurface(sur);
94 /* doesn't set win or parent */
95 static struct RrSurface *surface_copy(struct RrSurface *orig)
97 struct RrSurface *sur;
99 sur = malloc(sizeof(struct RrSurface));
100 sur->type = orig->type;
102 case RR_SURFACE_PLANAR:
103 sur->data = orig->data;
105 case RR_SURFACE_NONPLANAR:
108 case RR_SURFACE_NONE:
111 sur->ntextures = orig->ntextures;
112 sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
113 memcpy(sur->texture, orig->texture,
114 sizeof(struct RrTexture) * sur->ntextures);
118 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
119 struct RrSurface *orig,
122 struct RrSurface *sur;
124 sur = surface_copy(orig);
130 RrInstaceAddSurface(sur);
134 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
135 struct RrSurface *parent)
137 struct RrSurface *sur;
139 /* can't be a child of a prototype! */
140 assert(parent->inst);
141 if (!parent->inst) return NULL;
143 sur = surface_copy(orig);
144 sur->inst = parent->inst;
145 sur->win = create_window(sur->inst, parent->win);
146 sur->parent = parent;
149 parent->children = g_slist_append(parent->children, sur);
151 RrInstaceAddSurface(sur);
155 void RrSurfaceFree(struct RrSurface *sur)
160 sur->parent->children = g_slist_remove(sur->parent->children, sur);
162 RrInstaceRemoveSurface(sur);
163 for (i = 0; i < sur->ntextures; ++i)
164 RrTextureFreeContents(&sur->texture[i]);
167 if (sur->parent && sur->win)
168 XDestroyWindow(RrDisplay(sur->inst), sur->win);
173 void RrSurfaceSetArea(struct RrSurface *sur,
179 assert(w > 0 && h > 0);
180 if (!(w > 0 && h > 0)) return;
187 XMoveResizeWindow(RrDisplay(sur->inst), sur->win, x, y, w, h);
190 Window RrSurfaceWindow(struct RrSurface *sur)
192 /* can't get a window for a prototype */
194 if (!sur->inst) return None;
199 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
201 assert(texnum < sur->ntextures);
202 return &(sur->texture[texnum]);
205 void RrSurfaceMinSize(struct RrSurface *sur, int *w, int *h)
211 case RR_SURFACE_NONE:
214 case RR_SURFACE_PLANAR:
215 RrPlanarMinSize(sur, w, h);
217 case RR_SURFACE_NONPLANAR:
223 for (i = 0; i < sur->ntextures; ++i) {
224 switch (sur->texture[i].type) {
225 case RR_TEXTURE_NONE:
229 case RR_TEXTURE_TEXT:
230 /* XXX MEASUER STRING PLS */
231 minw = MAX(minw, 100 /*MEASURESTRING*/);
232 minh = MAX(minh, 10 /*HEIGHTOFFONT*/);
234 case RR_TEXTURE_RGBA:
235 minw = MAX(minw, (sur->texture[i].data.rgba.x +
236 sur->texture[i].data.rgba.w));
237 minh = MAX(minw, (sur->texture[i].data.rgba.y +
238 sur->texture[i].data.rgba.h));
250 void RrSurfaceShow(struct RrSurface *sur)
254 XMapWindow(RrDisplay(sur->inst), sur->win);
257 void RrSurfaceHide(struct RrSurface *sur)
261 XUnmapWindow(RrDisplay(sur->inst), sur->win);
264 int RrSurfaceVisible(struct RrSurface *sur)