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);
28 static Window create_window(struct RrInstance *inst, Window parent)
30 Window win = XCreateWindow(RrDisplay(inst), parent, 0, 0, 1, 1, 0,
31 RrDepth(inst), InputOutput, RrVisual(inst),
33 XMapWindow(RrDisplay(inst), win);
37 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
40 struct RrSurface *sur;
42 sur = surface_new(type, numtex);
49 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
50 enum RrSurfaceType type,
54 struct RrSurface *sur;
56 sur = surface_new(type, numtex);
63 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
64 struct RrSurface *parent,
67 struct RrSurface *sur;
69 /* can't be a child of a prototype! */
71 if (!parent->inst) return NULL;
73 sur = surface_new(type, numtex);
74 sur->inst = parent->inst;
75 sur->win = create_window(sur->inst, parent->win);
80 /* doesn't set win or parent */
81 static struct RrSurface *surface_copy(struct RrSurface *orig)
83 struct RrSurface *sur;
85 sur = malloc(sizeof(struct RrSurface));
86 sur->type = orig->type;
88 case RR_SURFACE_PLANAR:
89 sur->data = orig->data;
91 case RR_SURFACE_NONPLANAR:
95 sur->ntextures = orig->ntextures;
96 sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
97 memcpy(sur->texture, orig->texture,
98 sizeof(struct RrTexture) * sur->ntextures);
102 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
103 struct RrSurface *orig,
106 struct RrSurface *sur;
108 sur = surface_copy(orig);
115 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
116 struct RrSurface *parent)
118 struct RrSurface *sur;
120 /* can't be a child of a prototype! */
121 assert(parent->inst);
122 if (!parent->inst) return NULL;
124 sur = surface_copy(orig);
125 sur->inst = parent->inst;
126 sur->win = create_window(sur->inst, parent->win);
127 sur->parent = parent;
131 void RrSurfaceFree(struct RrSurface *sur)
136 if (sur->parent && sur->win)
137 XDestroyWindow(RrDisplay(sur->inst), sur->win);
142 void RrSurfaceSetArea(struct RrSurface *sur,
154 Window RrSurfaceWindow(struct RrSurface *sur)
156 /* can't get a window for a prototype */
158 if (!sur->inst) return None;
163 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
165 assert(texnum < sur->ntextures);
166 return &(sur->texture[texnum]);