2 * Copyright © 2004 David Reveman
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * David Reveman not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * David Reveman makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
15 * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: David Reveman <davidr@novell.com>
27 #include "colormapst.h"
31 static xglPixelFormatRec xglPixelFormats
[] = {
80 #define NUM_XGL_PIXEL_FORMATS \
81 (sizeof (xglPixelFormats) / sizeof (xglPixelFormats[0]))
83 xglVisualPtr xglVisuals
= NULL
;
86 xglSetVisualTypes (int depth
,
92 xglPixelFormatPtr pBestFormat
= 0;
93 int i
, rs
, gs
, bs
, diff
, bestDiff
= 0;
95 for (i
= 0; i
< NUM_XGL_PIXEL_FORMATS
; i
++)
97 if (xglPixelFormats
[i
].depth
== depth
)
101 rs
= Ones (xglPixelFormats
[i
].masks
.red_mask
);
102 gs
= Ones (xglPixelFormats
[i
].masks
.green_mask
);
103 bs
= Ones (xglPixelFormats
[i
].masks
.blue_mask
);
109 diff
= (redSize
- rs
) + (greenSize
- gs
) + (blueSize
- bs
);
114 pBestFormat
= &xglPixelFormats
[i
];
120 pBestFormat
= &xglPixelFormats
[i
];
127 pBestFormat
= &xglPixelFormats
[i
];
135 xglVisualPtr
new, *prev
, v
;
136 unsigned int bitsPerRGB
;
139 new = xalloc (sizeof (xglVisualRec
));
145 new->format
.surface
= 0;
146 new->format
.drawable
= 0;
147 new->pPixel
= pBestFormat
;
150 bitsPerRGB
= pBestFormat
->bitsPerRGB
;
152 rm
= pBestFormat
->masks
.red_mask
;
153 gm
= pBestFormat
->masks
.green_mask
;
154 bm
= pBestFormat
->masks
.blue_mask
;
156 fbSetVisualTypesAndMasks (depth
, visuals
, bitsPerRGB
, rm
, gm
, bm
);
158 for (prev
= &xglVisuals
; (v
= *prev
); prev
= &v
->next
);
163 fbSetVisualTypesAndMasks (depth
, 0, 0, 0, 0, 0);
168 xglHasVisualTypes (xglVisualPtr pVisual
,
173 for (v
= pVisual
; v
; v
= v
->next
)
174 if (v
->pPixel
->depth
== depth
)
181 xglFindBestSurfaceFormat (ScreenPtr pScreen
,
182 xglPixelFormatPtr pPixel
)
184 glitz_format_t templ
, *format
, *best
= 0;
186 unsigned short rs
, gs
, bs
, as
;
189 XGL_SCREEN_PRIV (pScreen
);
191 rs
= Ones (pPixel
->masks
.red_mask
);
192 gs
= Ones (pPixel
->masks
.green_mask
);
193 bs
= Ones (pPixel
->masks
.blue_mask
);
194 as
= Ones (pPixel
->masks
.alpha_mask
);
196 templ
.color
.fourcc
= GLITZ_FOURCC_RGB
;
197 mask
= GLITZ_FORMAT_FOURCC_MASK
;
200 format
= glitz_find_format (pScreenPriv
->drawable
, mask
, &templ
, i
++);
203 if (format
->color
.red_size
>= rs
&&
204 format
->color
.green_size
>= gs
&&
205 format
->color
.blue_size
>= bs
&&
206 format
->color
.alpha_size
>= as
)
210 if (((format
->color
.red_size
- rs
) +
211 (format
->color
.green_size
- gs
) +
212 (format
->color
.blue_size
- bs
)) <
213 ((best
->color
.red_size
- rs
) +
214 (best
->color
.green_size
- gs
) +
215 (best
->color
.blue_size
- bs
)))
230 xglInitVisual (ScreenPtr pScreen
,
231 xglVisualPtr pVisual
,
232 xglPixelFormatPtr pPixel
,
235 glitz_format_t
*format
;
237 XGL_SCREEN_PRIV (pScreen
);
239 format
= xglFindBestSurfaceFormat (pScreen
, pPixel
);
242 glitz_drawable_format_t templ
;
245 templ
.color
= format
->color
;
246 templ
.depth_size
= 0;
247 templ
.stencil_size
= 0;
248 templ
.doublebuffer
= 0;
252 GLITZ_FORMAT_FOURCC_MASK
|
253 GLITZ_FORMAT_RED_SIZE_MASK
|
254 GLITZ_FORMAT_GREEN_SIZE_MASK
|
255 GLITZ_FORMAT_BLUE_SIZE_MASK
|
256 GLITZ_FORMAT_ALPHA_SIZE_MASK
|
257 GLITZ_FORMAT_DEPTH_SIZE_MASK
|
258 GLITZ_FORMAT_STENCIL_SIZE_MASK
|
259 GLITZ_FORMAT_DOUBLEBUFFER_MASK
|
260 GLITZ_FORMAT_SAMPLES_MASK
;
264 pVisual
->pPixel
= pPixel
;
265 pVisual
->pbuffer
= FALSE
;
267 pVisual
->format
.surface
= format
;
268 pVisual
->format
.drawable
=
269 glitz_find_drawable_format (pScreenPriv
->drawable
,
279 xglInitPbufferVisual (ScreenPtr pScreen
,
280 xglVisualPtr pVisual
,
281 xglPixelFormatPtr pPixel
,
284 glitz_format_t
*format
;
286 XGL_SCREEN_PRIV (pScreen
);
288 format
= xglFindBestSurfaceFormat (pScreen
, pPixel
);
291 glitz_drawable_format_t templ
, *screenFormat
;
294 /* use same drawable format as screen for pbuffers */
295 screenFormat
= glitz_drawable_get_format (pScreenPriv
->drawable
);
296 templ
.id
= screenFormat
->id
;
298 templ
.color
= format
->color
;
302 GLITZ_FORMAT_ID_MASK
|
303 GLITZ_FORMAT_FOURCC_MASK
|
304 GLITZ_FORMAT_RED_SIZE_MASK
|
305 GLITZ_FORMAT_GREEN_SIZE_MASK
|
306 GLITZ_FORMAT_BLUE_SIZE_MASK
|
307 GLITZ_FORMAT_SAMPLES_MASK
;
311 pVisual
->pPixel
= pPixel
;
312 pVisual
->pbuffer
= TRUE
;
314 pVisual
->format
.surface
= format
;
315 pVisual
->format
.drawable
=
316 glitz_find_pbuffer_format (pScreenPriv
->drawable
,
319 if (pVisual
->format
.drawable
)
327 xglInitVisuals (ScreenPtr pScreen
)
329 xglVisualPtr pVisual
, v
, new, *prev
;
332 XGL_SCREEN_PRIV (pScreen
);
334 for (i
= 0; i
< pScreen
->numVisuals
; i
++)
336 for (pVisual
= xglVisuals
; pVisual
; pVisual
= pVisual
->next
)
337 if (pVisual
->pPixel
->depth
== pScreen
->visuals
[i
].nplanes
)
342 new = xalloc (sizeof (xglVisualRec
));
345 if (xglInitVisual (pScreen
, new, pVisual
->pPixel
,
346 pScreen
->visuals
[i
].vid
))
350 prev
= &pScreenPriv
->pVisual
;
362 new = xalloc (sizeof (xglVisualRec
));
365 if (xglInitPbufferVisual (pScreen
, new, pVisual
->pPixel
,
366 pScreen
->visuals
[i
].vid
))
370 prev
= &pScreenPriv
->pVisual
;
384 /* Add additional Xgl visuals for pixmap formats */
385 for (i
= 0; i
< screenInfo
.numPixmapFormats
; i
++)
387 if (!xglHasVisualTypes (pScreenPriv
->pVisual
,
388 screenInfo
.formats
[i
].depth
))
390 for (v
= xglVisuals
; v
; v
= v
->next
)
391 if (v
->pPixel
->depth
== screenInfo
.formats
[i
].depth
)
396 new = xalloc (sizeof (xglVisualRec
));
399 if (xglInitVisual (pScreen
, new, v
->pPixel
, 0))
403 prev
= &pScreenPriv
->pVisual
;
420 xglFindVisualWithDepth (ScreenPtr pScreen
,
425 XGL_SCREEN_PRIV (pScreen
);
427 for (v
= pScreenPriv
->pVisual
; v
; v
= v
->next
)
429 if (v
->pPixel
->depth
== depth
)
437 xglFindVisualWithId (ScreenPtr pScreen
,
442 XGL_SCREEN_PRIV (pScreen
);
444 for (v
= pScreenPriv
->pVisual
; v
; v
= v
->next
)
454 xglClearVisualTypes (void)
461 xglVisuals
= v
->next
;
465 miClearVisualTypes ();