First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xf8_32bpp / cfbscrinit.c
blob7cbdb5a66233d5cee69d8915d8cf9778aba186ec
3 #ifdef HAVE_XORG_CONFIG_H
4 #include <xorg-config.h>
5 #endif
7 #include <X11/X.h>
8 #include <X11/Xmd.h>
9 #include "misc.h"
10 #include "servermd.h"
11 #include "scrnintstr.h"
12 #include "pixmapstr.h"
13 #include "resource.h"
14 #include "colormap.h"
15 #include "colormapst.h"
16 #define PSZ 8
17 #include "cfb.h"
18 #undef PSZ
19 #include "cfb32.h"
20 #include "cfb8_32.h"
21 #include "mi.h"
22 #include "micmap.h"
23 #include "mistruct.h"
24 #include "dix.h"
25 #include "mibstore.h"
26 #include "mioverlay.h"
27 #include "xf86.h"
28 #include "xf86str.h"
29 #include "globals.h"
31 /* CAUTION: We require that cfb8 and cfb32 were NOT
32 compiled with CFB_NEED_SCREEN_PRIVATE */
34 static BSFuncRec cfb8_32BSFuncRec = {
35 cfb8_32SaveAreas,
36 cfb8_32RestoreAreas,
37 (BackingStoreSetClipmaskRgnProcPtr) 0,
38 (BackingStoreGetImagePixmapProcPtr) 0,
39 (BackingStoreGetSpansPixmapProcPtr) 0,
43 int cfb8_32GCPrivateIndex;
44 int cfb8_32GetGCPrivateIndex(void) { return cfb8_32GCPrivateIndex; }
45 int cfb8_32ScreenPrivateIndex;
46 int cfb8_32GetScreenPrivateIndex(void) { return cfb8_32ScreenPrivateIndex; }
47 static unsigned long cfb8_32Generation = 0;
49 static Bool
50 cfb8_32AllocatePrivates(ScreenPtr pScreen)
52 cfb8_32ScreenPtr pScreenPriv;
54 if(cfb8_32Generation != serverGeneration) {
55 if(((cfb8_32GCPrivateIndex = AllocateGCPrivateIndex()) < 0) ||
56 ((cfb8_32ScreenPrivateIndex = AllocateScreenPrivateIndex()) < 0))
57 return FALSE;
58 cfb8_32Generation = serverGeneration;
61 if (!(pScreenPriv = xalloc(sizeof(cfb8_32ScreenRec))))
62 return FALSE;
64 pScreen->devPrivates[cfb8_32ScreenPrivateIndex].ptr = (pointer)pScreenPriv;
67 /* All cfb will have the same GC and Window private indicies */
68 if(!mfbAllocatePrivates(pScreen,&cfbWindowPrivateIndex, &cfbGCPrivateIndex))
69 return FALSE;
71 /* The cfb indicies are the mfb indicies. Reallocating them resizes them */
72 if(!AllocateWindowPrivate(pScreen,cfbWindowPrivateIndex,sizeof(cfbPrivWin)))
73 return FALSE;
75 if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
76 return FALSE;
78 if(!AllocateGCPrivate(pScreen, cfb8_32GCPrivateIndex, sizeof(cfb8_32GCRec)))
79 return FALSE;
81 return TRUE;
84 static void DestroyColormapNoop(
85 ColormapPtr pColormap)
87 /* NOOP */
90 static void StoreColorsNoop(
91 ColormapPtr pColormap,
92 int ndef,
93 xColorItem * pdef)
95 /* NOOP */
98 static Bool
99 cfb8_32SetupScreen(
100 ScreenPtr pScreen,
101 pointer pbits, /* pointer to screen bitmap */
102 int xsize, int ysize, /* in pixels */
103 int dpix, int dpiy, /* dots per inch */
104 int width /* pixel width of frame buffer */
106 if (!cfb8_32AllocatePrivates(pScreen))
107 return FALSE;
108 pScreen->defColormap = FakeClientID(0);
109 /* let CreateDefColormap do whatever it wants for pixels */
110 pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
111 pScreen->QueryBestSize = mfbQueryBestSize;
112 /* SaveScreen */
113 pScreen->GetImage = cfb8_32GetImage;
114 pScreen->GetSpans = cfb8_32GetSpans;
115 pScreen->CreateWindow = cfb8_32CreateWindow;
116 pScreen->DestroyWindow = cfb8_32DestroyWindow;
117 pScreen->PositionWindow = cfb8_32PositionWindow;
118 pScreen->ChangeWindowAttributes = cfb8_32ChangeWindowAttributes;
119 pScreen->RealizeWindow = cfb32MapWindow; /* OK */
120 pScreen->UnrealizeWindow = cfb32UnmapWindow; /* OK */
121 pScreen->PaintWindowBackground = cfb8_32PaintWindow;
122 pScreen->PaintWindowBorder = cfb8_32PaintWindow;
123 pScreen->CopyWindow = cfb8_32CopyWindow;
124 pScreen->CreatePixmap = cfb32CreatePixmap; /* OK */
125 pScreen->DestroyPixmap = cfb32DestroyPixmap; /* OK */
126 pScreen->RealizeFont = mfbRealizeFont;
127 pScreen->UnrealizeFont = mfbUnrealizeFont;
128 pScreen->CreateGC = cfb8_32CreateGC;
129 pScreen->CreateColormap = miInitializeColormap;
130 pScreen->DestroyColormap = DestroyColormapNoop;
131 pScreen->InstallColormap = miInstallColormap;
132 pScreen->UninstallColormap = miUninstallColormap;
133 pScreen->ListInstalledColormaps = miListInstalledColormaps;
134 pScreen->StoreColors = StoreColorsNoop;
135 pScreen->ResolveColor = miResolveColor;
136 pScreen->BitmapToRegion = mfbPixmapToRegion;
138 mfbRegisterCopyPlaneProc (pScreen, cfb8_32CopyPlane);
139 return TRUE;
142 typedef struct {
143 pointer pbits;
144 int width;
145 } miScreenInitParmsRec, *miScreenInitParmsPtr;
147 static Bool
148 cfb8_32CreateScreenResources(ScreenPtr pScreen)
150 miScreenInitParmsPtr pScrInitParms;
151 int pitch;
152 Bool retval;
154 /* get the pitch before mi destroys it */
155 pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
156 pitch = pScrInitParms->width << 2;
158 if((retval = miCreateScreenResources(pScreen))) {
159 /* fix the screen pixmap */
160 PixmapPtr pPix = (PixmapPtr)pScreen->devPrivate;
161 pPix->drawable.bitsPerPixel = 32;
162 pPix->drawable.depth = 8;
163 pPix->devKind = pitch;
166 return retval;
170 static Bool
171 cfb8_32CloseScreen (int i, ScreenPtr pScreen)
173 cfb8_32ScreenPtr pScreenPriv = CFB8_32_GET_SCREEN_PRIVATE(pScreen);
174 if(pScreenPriv->visualData)
175 xfree(pScreenPriv->visualData);
177 xfree((pointer) pScreenPriv);
178 pScreen->devPrivates[cfb8_32ScreenPrivateIndex].ptr = NULL;
180 return(cfb32CloseScreen(i, pScreen));
183 static void
184 cfb8_32TransFunc(
185 ScreenPtr pScreen,
186 int nbox,
187 BoxPtr pbox
189 cfb8_32FillBoxSolid8(&(WindowTable[pScreen->myNum]->drawable),
190 nbox, pbox, xf86Screens[pScreen->myNum]->colorKey);
193 static Bool
194 cfb8_32InOverlayFunc(WindowPtr pWin)
196 return (pWin->drawable.depth == 8);
199 static Bool
200 cfb8_32FinishScreenInit(
201 ScreenPtr pScreen,
202 pointer pbits, /* pointer to screen bitmap */
203 int xsize, int ysize, /* in pixels */
204 int dpix, int dpiy, /* dots per inch */
205 int width /* pixel width of frame buffer */
207 VisualPtr visuals;
208 DepthPtr depths;
209 int nvisuals;
210 int ndepths;
211 int rootdepth;
212 VisualID defaultVisual;
214 rootdepth = 0;
215 if (!miInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
216 &defaultVisual,((unsigned long)1<<(32-1)), 8, -1))
217 return FALSE;
218 if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
219 rootdepth, ndepths, depths,
220 defaultVisual, nvisuals, visuals))
221 return FALSE;
223 pScreen->BackingStoreFuncs = cfb8_32BSFuncRec;
224 pScreen->CreateScreenResources = cfb8_32CreateScreenResources;
225 pScreen->CloseScreen = cfb8_32CloseScreen;
226 pScreen->GetScreenPixmap = cfb32GetScreenPixmap; /* OK */
227 pScreen->SetScreenPixmap = cfb32SetScreenPixmap; /* OK */
229 if (! miInitOverlay(pScreen, cfb8_32InOverlayFunc, cfb8_32TransFunc))
230 return FALSE;
232 return TRUE;
235 static void
236 cfb8_32EnableDisableFBAccess (
237 int index,
238 Bool enable
240 ScreenPtr pScreen = screenInfo.screens[index];
241 cfb8_32ScreenPtr pScreenPriv = CFB8_32_GET_SCREEN_PRIVATE(pScreen);
243 miOverlaySetRootClip(pScreen, enable);
245 (*pScreenPriv->EnableDisableFBAccess) (index, enable);
248 static Atom overlayVisualsAtom;
250 typedef struct {
251 CARD32 overlay_visual;
252 CARD32 transparent_type;
253 CARD32 value;
254 CARD32 layer;
255 } overlayVisualRec;
257 static void
258 cfb8_32SetupVisuals (ScreenPtr pScreen)
260 cfb8_32ScreenPtr pScreenPriv = CFB8_32_GET_SCREEN_PRIVATE(pScreen);
261 char atomString[] = {"SERVER_OVERLAY_VISUALS"};
262 overlayVisualRec *overlayVisuals;
263 VisualID *visuals = NULL;
264 int numVisuals = 0;
265 DepthPtr pDepth = pScreen->allowedDepths;
266 int numDepths = pScreen->numDepths;
267 int i;
269 /* find depth 8 visuals */
270 for(i = 0; i < numDepths; i++, pDepth++) {
271 if(pDepth->depth == 8) {
272 numVisuals = pDepth->numVids;
273 visuals = pDepth->vids;
274 break;
278 if(!numVisuals || !visuals) {
279 ErrorF("No overlay visuals found!\n");
280 return;
283 if(!(overlayVisuals = xalloc(numVisuals * sizeof(overlayVisualRec))))
284 return;
286 for(i = 0; i < numVisuals; i++) {
287 overlayVisuals[i].overlay_visual = visuals[i];
288 overlayVisuals[i].transparent_type = 1; /* transparent pixel */
289 overlayVisuals[i].value = pScreenPriv->key;
290 overlayVisuals[i].layer = 1;
293 overlayVisualsAtom = MakeAtom(atomString, sizeof(atomString) - 1, TRUE);
294 xf86RegisterRootWindowProperty(pScreen->myNum, overlayVisualsAtom,
295 overlayVisualsAtom, 32, numVisuals * 4, overlayVisuals);
296 pScreenPriv->visualData = (pointer)overlayVisuals;
299 Bool
300 cfb8_32ScreenInit(
301 ScreenPtr pScreen,
302 pointer pbits, /* pointer to screen bitmap */
303 int xsize, int ysize, /* in pixels */
304 int dpix, int dpiy, /* dots per inch */
305 int w /* pixel width of frame buffer */
307 cfb8_32ScreenPtr pScreenPriv;
308 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
310 if (!cfb8_32SetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, w))
311 return FALSE;
313 pScreenPriv = CFB8_32_GET_SCREEN_PRIVATE(pScreen);
314 pScreenPriv->key = pScrn->colorKey;
315 pScreenPriv->visualData = NULL;
318 pScreenPriv->EnableDisableFBAccess = pScrn->EnableDisableFBAccess;
319 pScrn->EnableDisableFBAccess = cfb8_32EnableDisableFBAccess;
322 if(cfb8_32FinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, w))
324 cfb8_32SetupVisuals(pScreen);
325 return TRUE;
327 return FALSE;