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);
29 static Window create_window(struct RrInstance *inst, Window parent)
31 Window win = XCreateWindow(RrDisplay(inst), parent, 0, 0, 1, 1, 0,
32 RrDepth(inst), InputOutput, RrVisual(inst),
37 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
40 struct RrSurface *sur;
42 sur = surface_new(type, numtex);
50 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
51 enum RrSurfaceType type,
55 struct RrSurface *sur;
57 sur = surface_new(type, numtex);
65 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
66 struct RrSurface *parent,
69 struct RrSurface *sur;
71 /* can't be a child of a prototype! */
73 if (!parent->inst) return NULL;
75 sur = surface_new(type, numtex);
76 sur->inst = parent->inst;
77 sur->win = create_window(sur->inst, parent->win);
83 /* doesn't set win or parent */
84 static struct RrSurface *surface_copy(struct RrSurface *orig)
86 struct RrSurface *sur;
88 sur = malloc(sizeof(struct RrSurface));
89 sur->type = orig->type;
91 case RR_SURFACE_PLANAR:
92 sur->data = orig->data;
94 case RR_SURFACE_NONPLANAR:
100 sur->ntextures = orig->ntextures;
101 sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
102 memcpy(sur->texture, orig->texture,
103 sizeof(struct RrTexture) * sur->ntextures);
107 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
108 struct RrSurface *orig,
111 struct RrSurface *sur;
113 sur = surface_copy(orig);
121 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
122 struct RrSurface *parent)
124 struct RrSurface *sur;
126 /* can't be a child of a prototype! */
127 assert(parent->inst);
128 if (!parent->inst) return NULL;
130 sur = surface_copy(orig);
131 sur->inst = parent->inst;
132 sur->win = create_window(sur->inst, parent->win);
133 sur->parent = parent;
138 void RrSurfaceFree(struct RrSurface *sur)
142 for (i = 0; i < sur->ntextures; ++i)
143 RrTextureFreeContents(&sur->texture[i]);
146 if (sur->parent && sur->win)
147 XDestroyWindow(RrDisplay(sur->inst), sur->win);
152 void RrSurfaceSetArea(struct RrSurface *sur,
158 assert(w > 0 && h > 0);
159 if (!(w > 0 && h > 0)) return;
166 XMoveResizeWindow(RrDisplay(sur->inst), sur->win, x, y, w, h);
169 Window RrSurfaceWindow(struct RrSurface *sur)
171 /* can't get a window for a prototype */
173 if (!sur->inst) return None;
178 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
180 assert(texnum < sur->ntextures);
181 return &(sur->texture[texnum]);
184 void RrSurfaceMinSize(struct RrSurface *sur, int *w, int *h)
190 case RR_SURFACE_NONE:
193 case RR_SURFACE_PLANAR:
194 RrPlanarMinSize(sur, w, h);
196 case RR_SURFACE_NONPLANAR:
201 for (i = 0; i < sur->ntextures; ++i) {
202 switch (sur->texture[i].type) {
203 case RR_TEXTURE_NONE:
207 case RR_TEXTURE_TEXT:
208 /* XXX MEASUER STRING PLS */
209 minw = MAX(minw, 100 /*MEASURESTRING*/);
210 minh = MAX(minh, 10 /*HEIGHTOFFONT*/);
212 case RR_TEXTURE_RGBA:
213 minw = MAX(minw, (sur->texture[i].data.rgba.x +
214 sur->texture[i].data.rgba.w));
215 minh = MAX(minw, (sur->texture[i].data.rgba.y +
216 sur->texture[i].data.rgba.h));
228 void RrSurfaceShow(struct RrSurface *sur)
232 XMapWindow(RrDisplay(sur->inst), sur->win);
235 void RrSurfaceHide(struct RrSurface *sur)
239 XUnmapWindow(RrDisplay(sur->inst), sur->win);
242 int RrSurfaceVisible(struct RrSurface *sur)