annotate lisp/oobr/tree-x/dbl.c @ 100:4be1180a9e89 r20-1b2

Import from CVS: tag r20-1b2
author cvs
date Mon, 13 Aug 2007 09:15:11 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* ----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 * Double buffering code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 * ----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 #include "dbl.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 unsigned short red;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 unsigned short green;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 unsigned short blue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 } color[] = {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 { 65280, 65280, 65280 }, /* white */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 { 0, 0, 65280 }, /* blue */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 { 0, 65280, 0 }, /* green */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 { 65280, 0, 0 }, /* red */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 { 42240, 10752, 10752 }, /* brown */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 { 65280, 32512, 0 }, /* orange */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 { 32512, 32512, 32512 }, /* gray */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 { 0, 0, 0 } /* black */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* ------------------------------------------------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 DoubleBuffer *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 DBLcreate_double_buffer (display, window, backing_store, colors, num_colors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 Display *display;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 Window window;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 int backing_store;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 XColor *colors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 int num_colors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 int i, j, k, l, m, offset, mask, size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 int max_planes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 char *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Surface *surface;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 DoubleBuffer *db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 XGCValues xgcv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 unsigned long xgcvmask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* allocate the double buffer structure, and then open the display */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 if ((db = (DoubleBuffer *)calloc(1, sizeof(DoubleBuffer))) == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 printf("DBLopen_double_buffer : memory allocation error\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 return (NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* note the display */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 db->display = display;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* first some information about our display */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 db->screen = DefaultScreenOfDisplay(db->display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 db->window = window;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* now get some information on color resources */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 db->visual = DefaultVisualOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 db->depth = DefaultDepthOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 db->colormap = DefaultColormapOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* set up colors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 for (i = 0 ; i < num_colors; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 color[i].red = colors[i].red;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 color[i].green = colors[i].green;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 color[i].blue = colors[i].blue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /* see if the user wanted to limit the number of planes used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 then see how many are available, make it a multiple of 2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 if ((string = getenv("DBL_MAX_PLANES")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 max_planes = DBL_MAX_PLANES;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 max_planes = atoi(string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if ((db->num_planes = PlanesOfScreen(db->screen)) > max_planes) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 db->num_planes = max_planes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 db->num_planes = (db->num_planes >> 1) << 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 /* otherwise allocate contiguous planes to do double buffering */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 while (db->num_planes >= DBL_MIN_PLANES) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 if (XAllocColorCells (db->display, db->colormap, 1, db->planes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 db->num_planes, db->pixels, 1)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 db->num_planes -= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* if we have at least minimum planes, then we can do double
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 buffering and we want to setup our surfaces and colormaps */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if (db->num_planes < DBL_MIN_PLANES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 db->num_surfaces = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 db->num_colors = 1 << (db->num_planes >> 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 db->num_surfaces = DBL_MAX_SURFACES;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 /* if the number of colors is less than DBL_MAX_COLORS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 then we want to make sure black is the last color */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 for (i = db->num_colors - 1; i < DBL_MAX_COLORS; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 color[i].red = color[DBL_MAX_COLORS - 1].red;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 color[i].green = color[DBL_MAX_COLORS - 1].green;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 color[i].blue = color[DBL_MAX_COLORS - 1].blue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 /* we have a set of contiguous planes. compute a mask for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 the planes, and figure out the offset in the hardware */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 for (i = 0; i < db->num_planes; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 db->mask |= db->planes[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 mask = db->mask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 offset = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 while ((mask & 1) == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 mask = mask >> 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 offset = offset + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 mask = (1 << (db->num_planes >> 1)) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 /* now create the surfaces that will contain plane mask and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 colormap information that we use to do double buffering */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 for (i = 0; i < db->num_surfaces; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 size = sizeof(Surface) + sizeof(XColor) * (1 << db->num_planes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 if ((surface = (Surface *)malloc(size)) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 db->surface[i] = surface;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 printf("DBLcreate_double_buffer : memory allocation error\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 DBLdelete_double_buffer(db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 return(NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 surface->offset = offset + i * (db->num_planes >> 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 surface->mask = mask << surface->offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 surface->num_colors = 1 << db->num_planes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 /* compute our pixel values by taking every permutation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 of the pixel and planes returned by XAllocColorCells */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 for (j = 0; j < (surface->num_colors); j++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 surface->color[j].pixel = db->pixels[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 for (j = 0; j < db->num_planes; j++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 for (k = (1 << j); k < (surface->num_colors); k += (2 << j)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 for (l = k; l < (k + (1 << j)); l++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 surface->color[l].pixel |= db->planes[j];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 /* now populate those pixels with the proper colors so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 that we can do animation by banging in a new colormap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 for (j = 0; j < surface->num_colors; j++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 k = (j & surface->mask) >> surface->offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 surface->color[j].red = color[k].red;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 surface->color[j].green = color[k].green;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 surface->color[j].blue = color[k].blue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 surface->color[j].flags = DoRed | DoGreen | DoBlue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 db->current_surface = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 /* now figure out what pixel values we will use to draw with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 and store them in the double buffer structure */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (db->num_surfaces == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 db->num_colors = DBL_MAX_COLORS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 db->colors[0] = WhitePixelOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 for (i = 1; i < db->num_colors; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 db->colors[i] = BlackPixelOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 for (i = 0; i < db->num_colors; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 j = (i << (db->num_planes >> 1)) + i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 db->colors[i] = db->surface[0]->color[j].pixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* fill out the remaining colors with the last color */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 for (; i < DBL_MAX_COLORS; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 db->colors[i] = db->colors[db->num_colors - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 db->width = WidthOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 db->height = HeightOfScreen(db->screen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 /* if there are no surfaces then we are doing animation with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 a frame buffer, so create a pixmap as our frame buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 if (db->num_surfaces > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 db->drawable = db->window;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 db->frame = XCreatePixmap(db->display, db->window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 db->width, db->height, db->depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 db->drawable = db->frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 /* if they have requested backing store, then create an extra
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 pixmap which we can use as backing store to handle exposures */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if (backing_store) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 db->backing = XCreatePixmap(db->display, db->window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 db->width, db->height, db->depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 /* use the 0 pixel from one of the surfaces for the background */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 xgcv.background = DBLinq_background(db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 xgcv.line_style = LineSolid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 xgcv.line_width = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 xgcv.cap_style = CapButt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 xgcv.join_style = JoinRound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 xgcvmask = GCBackground | GCLineStyle | GCLineWidth | GCCapStyle |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 GCJoinStyle;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 db->gc = XCreateGC(db->display, db->drawable, xgcvmask, &xgcv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 /* do an initial frame to setup the colormap, and return */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 DBLbegin_frame(db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 DBLend_frame(db, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 return (db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /* ------------------------------------------------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 DBLdelete_double_buffer (db)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 DoubleBuffer *db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 /* remove and and all surfaces that are out there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 for (i = 0; i < DBL_MAX_SURFACES; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 if (db->surface[i] != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 free(db->surface[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 /* now clean up the various resources used for this double buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 if (db->frame != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 XFreePixmap(db->display, db->frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 if (db->backing != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 XFreePixmap(db->display, db->backing);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 /* if we created our own private colormap, then free the colormap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 if (db->colormap != DefaultColormapOfScreen(db->screen)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 XFreeColormap(db->display, db->colormap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 free (db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 /* ------------------------------------------------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 DBLinq_background(db)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 DoubleBuffer *db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 if (db->num_surfaces > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 return(db->surface[0]->color[0].pixel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 return(WhitePixelOfScreen(db->screen));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 /* ------------------------------------------------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 DBLbegin_frame(db)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 DoubleBuffer *db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 Surface *surface;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 /* there will be at most two surfaces optimize with "&"*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 if (db->num_surfaces > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 db->current_surface = (db->current_surface + 1) & 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 surface = db->surface[db->current_surface];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 /* clear the back surface of the window which may actually be a pixmap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (db->num_surfaces > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 XSetPlaneMask (db->display, db->gc, surface->mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* clear out the back surface or frame buffer as appropriate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 XSetFunction(db->display, db->gc, GXclear);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 XFillRectangle(db->display, db->drawable, db->gc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 0, 0, db->width, db->height);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 /* set writing mode back to copy */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 XSetFunction (db->display, db->gc, GXcopy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 XSync(db->display, False);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 /* ------------------------------------------------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 DBLend_frame(db, init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 DoubleBuffer *db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 short init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 Surface *surface;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 /* if there are no drawing surfaces, then we are doing animation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 with a frame buffer, copy the frame buffers to their viewports */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 if (db->num_surfaces == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 if (! init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 XCopyArea (db->display, db->frame, db->window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 db->gc, 0,0, db->width, db->height, 0,0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 /* otherwise, we can flip the surface by banging in the new colormap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 XSync(db->display, False);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 surface = db->surface[db->current_surface];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 XStoreColors (db->display, db->colormap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 surface->color, surface->num_colors);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 if (db->backing != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 XCopyArea (db->display, db->window, db->backing,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 db->gc, 0,0, db->width, db->height, 0,0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 /* make sure this all goes off to the server, right away */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 XSync(db->display, False);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377