]> icculus.org git repositories - dana/openbox.git/blob - render2/surface.c
add surface prototypes
[dana/openbox.git] / render2 / surface.c
1 #include "surface.h"
2 #include "instance.h"
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 /* doesn't set win or parent */
8 static struct RrSurface *surface_new(enum RrSurfaceType type,
9                                      int numtex)
10 {
11     struct RrSurface *sur;
12
13     sur = malloc(sizeof(struct RrSurface));
14     sur->type = type;
15     sur->ntextures = numtex;
16     if (numtex) {
17         sur->texture = malloc(sizeof(struct RrTexture) * numtex);
18         memset(sur->texture, 0, sizeof(struct RrTexture) * numtex);
19     } else
20         sur->texture = NULL;
21     return sur;
22 }
23
24 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
25                                     int numtex)
26 {
27     struct RrSurface *sur;
28
29     sur = surface_new(type, numtex);
30     sur->inst = inst;
31     sur->win = None;
32     sur->parent = NULL;
33     return sur;
34 }
35
36 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
37                                enum RrSurfaceType type,
38                                Window win,
39                                int numtex)
40 {
41     struct RrSurface *sur;
42
43     sur = surface_new(type, numtex);
44     sur->inst = inst;
45     sur->win = win;
46     sur->parent = NULL;
47     return sur;
48 }
49
50 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
51                                     struct RrSurface *parent,
52                                     int numtex)
53 {
54     struct RrSurface *sur;
55
56     sur = surface_new(type, numtex);
57     sur->inst = parent->inst;
58     sur->win = None; /* XXX XCreateWindow? */
59     sur->parent = parent;
60     sur->parentx = 0;
61     sur->parenty = 0;
62     return sur;
63 }
64
65 /* doesn't set win or parent */
66 static struct RrSurface *surface_copy(struct RrSurface *orig)
67 {
68     struct RrSurface *sur;
69
70     sur = malloc(sizeof(struct RrSurface));
71     sur->type = orig->type;
72     switch (sur->type) {
73     case RR_SURFACE_PLANAR:
74         sur->data = orig->data;
75         break;
76     case RR_SURFACE_NONPLANAR:
77         assert(0);
78         break;
79     }
80     sur->ntextures = orig->ntextures;
81     sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
82     memcpy(sur->texture, orig->texture,
83            sizeof(struct RrTexture) * sur->ntextures);
84     return sur;
85 }
86
87 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
88                                 struct RrSurface *orig,
89                                 Window win)
90 {
91     struct RrSurface *sur;
92
93     sur = surface_copy(orig);
94     sur->inst = inst;
95     sur->win = win;
96     sur->parent = NULL;
97     return sur;
98 }
99
100 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
101                                      struct RrSurface *parent)
102 {
103     struct RrSurface *sur;
104
105     sur = surface_copy(orig);
106     sur->inst = parent->inst;
107     sur->win = None; /* XXX XCreateWindow? */
108     sur->parent = parent;
109     return sur;
110 }
111
112 void RrSurfaceFree(struct RrSurface *sur)
113 {
114     if (sur) {
115         if (sur->ntextures)
116             free(sur->texture);
117         if (sur->parent && sur->win)
118             XDestroyWindow(RrDisplay(sur->inst), sur->win);
119         free(sur);
120     }
121 }
122
123 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
124 {
125     assert(texnum < sur->ntextures);
126     return &(sur->texture[texnum]);
127 }