1/* $Xorg: sunMultiDepth.c,v 1.4 2001/02/09 02:04:44 xorgcvs Exp $ */
2/*
3
4Copyright 1992, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included
13in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall
24not be used in advertising or otherwise to promote the sale, use or
25other dealings in this Software without prior written authorization
26from The Open Group.
27
28*/
29
30/* $XFree86: xc/programs/Xserver/hw/sun/sunMultiDepth.c,v 1.6 2001/12/14 19:59:43 dawes Exp $ */
31
32#include "sun.h"
33#include <X11/Xmd.h>
34#include "pixmapstr.h"
35#include "mi.h"
36#include "mistruct.h"
37#include "gcstruct.h"
38#include "fb.h"
39
40#ifndef SINGLEDEPTH
41
42static Bool
43sunCfbCreateGC(GCPtr pGC)
44{
45    if (pGC->depth == 1)
46    {
47	return mfbCreateGC (pGC);
48    }
49    else if (pGC->depth <= 8)
50    {
51	return cfbCreateGC (pGC);
52    }
53    else if (pGC->depth <= 16)
54    {
55	return cfb16CreateGC (pGC);
56    }
57    else if (pGC->depth <= 32)
58    {
59	return cfb32CreateGC (pGC);
60    }
61    return FALSE;
62}
63
64static void
65sunCfbGetSpans(
66    DrawablePtr		pDrawable,	/* drawable from which to get bits */
67    int			wMax,		/* largest value of all *pwidths */
68    DDXPointPtr 	ppt,		/* points to start copying from */
69    int			*pwidth,	/* list of number of bits to copy */
70    int			nspans,		/* number of scanlines to copy */
71    char		*pdstStart	/* where to put the bits */
72)
73{
74    switch (pDrawable->bitsPerPixel) {
75    case 1:
76	mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
77	break;
78    case 8:
79	cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
80	break;
81    case 16:
82	cfb16GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
83	break;
84    case 32:
85	cfb32GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
86	break;
87    }
88    return;
89}
90
91static void
92sunCfbGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char *pdstLine)
93{
94    switch (pDrawable->bitsPerPixel)
95    {
96    case 1:
97	mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
98	break;
99    case 8:
100	cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
101	break;
102    case 16:
103	cfb16GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
104	break;
105    case 32:
106	cfb32GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
107	break;
108    }
109}
110
111Bool
112sunCfbSetupScreen(
113    ScreenPtr pScreen,
114    pointer pbits,		/* pointer to screen bitmap */
115    int xsize,			/* in pixels */
116    int ysize,			/* in pixels */
117    int dpix,			/* dots per inch */
118    int dpiy,			/* dots per inch */
119    int width,			/* pixel width of frame buffer */
120    int	bpp			/* bits per pixel of root */
121)
122{
123    int ret;
124
125    sunRegisterPixmapFormat( /* depth */ 1,  /* bits per pixel */ 1);
126    sunRegisterPixmapFormat( /* depth */ 8,  /* bits per pixel */ 8);
127    sunRegisterPixmapFormat( /* depth */ 12,  /* bits per pixel */ 16);
128    sunRegisterPixmapFormat( /* depth */ 24,  /* bits per pixel */ 32);
129
130    ret = fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
131    pScreen->CreateGC = sunCfbCreateGC;
132    pScreen->GetImage = sunCfbGetImage;
133    pScreen->GetSpans = sunCfbGetSpans;
134    return ret;
135}
136
137Bool
138sunCfbFinishScreenInit(
139    ScreenPtr pScreen,
140    pointer pbits,		/* pointer to screen bitmap */
141    int xsize,			/* in pixels */
142    int ysize,			/* in pixels */
143    int dpix,			/* dots per inch */
144    int dpiy,			/* dots per inch */
145    int width,			/* pixel width of frame buffer */
146    int bpp
147)
148{
149    int		i;
150    VisualPtr	visuals;
151    int		nvisuals;
152    DepthPtr	depths;
153    int		ndepths;
154    VisualID	defaultVisual;
155    int		rootdepth;
156
157    if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths,
158			&rootdepth, &defaultVisual, 1 << (bpp - 1), 8))
159	return FALSE;
160    if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
161			rootdepth, ndepths, depths,
162			defaultVisual, nvisuals, visuals))
163	return FALSE;
164    pScreen->CloseScreen = fbCloseScreen;
165    return TRUE;
166}
167
168
169Bool
170sunCfbScreenInit(
171    ScreenPtr pScreen,
172    pointer pbits,		/* pointer to screen bitmap */
173    int xsize,			/* in pixels */
174    int ysize,			/* in pixels */
175    int dpix,			/* dots per inch */
176    int dpiy,			/* dots per inch */
177    int width,			/* pixel width of frame buffer */
178    int bpp
179)
180{
181    if (!sunCfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy,
182			   width, bpp))
183	return FALSE;
184    return sunCfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix,
185				  dpiy, width, bpp);
186}
187
188
189#else /* SINGLEDEPTH */
190
191/* stuff for 8-bit only server */
192
193Bool
194sunCfbSetupScreen(
195    ScreenPtr pScreen,
196    pointer pbits,		/* pointer to screen bitmap */
197    int xsize,			/* in pixels */
198    int ysize,			/* in pixels */
199    int dpix,			/* dots per inch */
200    int dpiy,			/* dots per inch */
201    int width,			/* pixel width of frame buffer */
202    int	bpp			/* bits per pixel of root */
203)
204{
205    sunRegisterPixmapFormat( /* depth */ 1, /* bits per pixel */ 1);
206    sunRegisterPixmapFormat( /* depth */ 8,  /* bits per pixel */ 8);
207    return fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
208}
209
210Bool
211sunCfbFinishScreenInit(
212    ScreenPtr pScreen,
213    pointer pbits,		/* pointer to screen bitmap */
214    int xsize,			/* in pixels */
215    int ysize,			/* in pixels */
216    int dpix,			/* dots per inch */
217    int dpiy,			/* dots per inch */
218    int width,			/* pixel width of frame buffer */
219    int bpp
220)
221{
222    return fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
223			      width, bpp);
224}
225
226Bool
227sunCfbScreenInit(
228    ScreenPtr pScreen,
229    pointer pbits,		/* pointer to screen bitmap */
230    int xsize,			/* in pixels */
231    int ysize,			/* in pixels */
232    int dpix,			/* dots per inch */
233    int dpiy,			/* dots per inch */
234    int width,			/* pixel width of frame buffer */
235    int bpp
236)
237{
238    sunRegisterPixmapFormat( /* depth */ 1, /* bits per pixel */ 1);
239    sunRegisterPixmapFormat( /* depth */ 8,  /* bits per pixel */ 8);
240    return fbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
241}
242
243#endif /* SINGLEDEPTH */
244