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);
24 static Window create_window(struct RrInstance *inst, Window parent)
26 Window win = XCreateWindow(RrDisplay(inst), parent, 0, 0, 1, 1, 0,
27 RrDepth(inst), InputOutput, RrVisual(inst),
29 XMapWindow(RrDisplay(inst), win);
33 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
36 struct RrSurface *sur;
38 sur = surface_new(type, numtex);
45 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
46 enum RrSurfaceType type,
50 struct RrSurface *sur;
52 sur = surface_new(type, numtex);
59 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
60 struct RrSurface *parent,
63 struct RrSurface *sur;
65 /* cant be a child of a prototype! */
67 if (!parent->inst) return NULL;
69 sur = surface_new(type, numtex);
70 sur->inst = parent->inst;
71 sur->win = create_window(sur->inst, parent->win);
78 /* doesn't set win or parent */
79 static struct RrSurface *surface_copy(struct RrSurface *orig)
81 struct RrSurface *sur;
83 sur = malloc(sizeof(struct RrSurface));
84 sur->type = orig->type;
86 case RR_SURFACE_PLANAR:
87 sur->data = orig->data;
89 case RR_SURFACE_NONPLANAR:
93 sur->ntextures = orig->ntextures;
94 sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
95 memcpy(sur->texture, orig->texture,
96 sizeof(struct RrTexture) * sur->ntextures);
100 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
101 struct RrSurface *orig,
104 struct RrSurface *sur;
106 sur = surface_copy(orig);
113 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
114 struct RrSurface *parent)
116 struct RrSurface *sur;
118 /* cant be a child of a prototype! */
119 assert(parent->inst);
120 if (!parent->inst) return NULL;
122 sur = surface_copy(orig);
123 sur->inst = parent->inst;
124 sur->win = create_window(sur->inst, parent->win);
125 sur->parent = parent;
129 void RrSurfaceFree(struct RrSurface *sur)
134 if (sur->parent && sur->win)
135 XDestroyWindow(RrDisplay(sur->inst), sur->win);
140 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
142 assert(texnum < sur->ntextures);
143 return &(sur->texture[texnum]);