1 dawes 1.1 /*
2 Copyright (C) 1999. The XFree86 Project Inc.
3
4 Written by Mark Vojkovich (mvojkovi@ucsd.edu)
5 */
6
|
7 dawes 1.9 /* $XFree86: xc/programs/Xserver/hw/xfree86/xf8_16bpp/cfbscrinit.c,v 1.8 2003/02/17 16:08:30 dawes Exp $ */
|
8 dawes 1.1
9 #include "X.h"
10 #include "Xmd.h"
11 #include "misc.h"
12 #include "servermd.h"
13 #include "scrnintstr.h"
14 #include "pixmapstr.h"
15 #include "resource.h"
16 #include "colormap.h"
17 #include "colormapst.h"
18 #define PSZ 8
19 #include "cfb.h"
20 #undef PSZ
21 #include "cfb16.h"
22 #include "cfb8_16.h"
23 #include "mi.h"
24 #include "micmap.h"
25 #include "mistruct.h"
26 #include "gcstruct.h"
27 #include "dix.h"
28 #include "mibstore.h"
|
29 dawes 1.2 #include "xf86str.h"
30 #include "xf86.h"
|
31 dawes 1.1
32 /* CAUTION: We require that cfb8 and cfb16 were NOT
33 compiled with CFB_NEED_SCREEN_PRIVATE */
34
35 int cfb8_16ScreenPrivateIndex;
36
37 static unsigned long cfb8_16Generation = 0;
38
39 static PixmapPtr cfb8_16GetWindowPixmap(WindowPtr pWin);
40 static void
41 cfb8_16SaveAreas(
42 PixmapPtr pPixmap,
43 RegionPtr prgnSave,
44 int xorg,
45 int yorg,
46 WindowPtr pWin
47 );
48
49 static void
50 cfb8_16RestoreAreas(
51 PixmapPtr pPixmap,
52 dawes 1.1 RegionPtr prgnRestore,
53 int xorg,
54 int yorg,
55 WindowPtr pWin
56 );
57
58 static BSFuncRec cfb8_16BSFuncRec = {
59 cfb8_16SaveAreas,
60 cfb8_16RestoreAreas,
61 (BackingStoreSetClipmaskRgnProcPtr) 0,
62 (BackingStoreGetImagePixmapProcPtr) 0,
63 (BackingStoreGetSpansPixmapProcPtr) 0,
64 };
65
66 static void
67 cfb8_16GetSpans(
68 DrawablePtr pDraw,
69 int wMax,
70 DDXPointPtr ppt,
71 int *pwidth,
72 int nspans,
73 dawes 1.1 char *pchardstStart
74 );
75
76 static void
77 cfb8_16GetImage (
78 DrawablePtr pDraw,
79 int sx, int sy, int w, int h,
80 unsigned int format,
81 unsigned long planeMask,
82 char *pdstLine
83 );
84
85 static Bool cfb8_16CreateGC(GCPtr pGC);
|
86 dawes 1.7 static void cfb8_16EnableDisableFBAccess(int index, Bool enable);
|
87 dawes 1.1
88
89 static Bool
90 cfb8_16AllocatePrivates(ScreenPtr pScreen)
91 {
92 cfb8_16ScreenPtr pScreenPriv;
93
94 if(cfb8_16Generation != serverGeneration) {
95 if((cfb8_16ScreenPrivateIndex = AllocateScreenPrivateIndex()) < 0)
96 return FALSE;
97 cfb8_16Generation = serverGeneration;
98 }
99
100 if (!(pScreenPriv = xalloc(sizeof(cfb8_16ScreenRec))))
101 return FALSE;
102
103 pScreen->devPrivates[cfb8_16ScreenPrivateIndex].ptr = (pointer)pScreenPriv;
104
105
106 /* All cfb will have the same GC and Window private indicies */
107 if(!mfbAllocatePrivates(pScreen,&cfbWindowPrivateIndex, &cfbGCPrivateIndex))
108 dawes 1.1 return FALSE;
109
110 /* The cfb indicies are the mfb indicies. Reallocating them resizes them */
111 if(!AllocateWindowPrivate(pScreen,cfbWindowPrivateIndex,sizeof(cfbPrivWin)))
112 return FALSE;
113
114 if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
115 return FALSE;
116
117 return TRUE;
118 }
119
|
120 dawes 1.9 static void
121 DestroyColormapNoop(ColormapPtr pColormap)
122 {
123 /* NOOP */
124 }
125
126 static void
127 StoreColorsNoop(ColormapPtr pColormap, int ndef, xColorItem *pdef)
128 {
129 /* NOOP */
130 }
131
|
132 dawes 1.1 static Bool
133 cfb8_16SetupScreen(
134 ScreenPtr pScreen,
135 int xsize, int ysize, /* in pixels */
136 int dpix, int dpiy
137 ){
138 if (!cfb8_16AllocatePrivates(pScreen))
139 return FALSE;
140 pScreen->defColormap = FakeClientID(0);
141 /* let CreateDefColormap do whatever it wants for pixels */
142 pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
143 pScreen->QueryBestSize = mfbQueryBestSize;
144 /* SaveScreen */
145 pScreen->GetImage = cfb8_16GetImage;
146 pScreen->GetSpans = cfb8_16GetSpans;
147 pScreen->CreateWindow = cfb8_16CreateWindow;
148 pScreen->DestroyWindow = cfb8_16DestroyWindow;
149 pScreen->PositionWindow = cfb8_16PositionWindow;
150 pScreen->ChangeWindowAttributes = cfb8_16ChangeWindowAttributes;
151 pScreen->RealizeWindow = cfb16MapWindow; /* OK */
152 pScreen->UnrealizeWindow = cfb16UnmapWindow; /* OK */
153 dawes 1.1 pScreen->PaintWindowBackground = cfb8_16PaintWindow;
154 pScreen->PaintWindowBorder = cfb8_16PaintWindow;
155 pScreen->CopyWindow = cfb8_16CopyWindow;
156 pScreen->CreatePixmap = cfb16CreatePixmap; /* OK */
157 pScreen->DestroyPixmap = cfb16DestroyPixmap; /* OK */
158 pScreen->RealizeFont = mfbRealizeFont;
159 pScreen->UnrealizeFont = mfbUnrealizeFont;
160 pScreen->CreateGC = cfb8_16CreateGC;
161 pScreen->CreateColormap = miInitializeColormap;
|
162 dawes 1.9 pScreen->DestroyColormap = DestroyColormapNoop;
|
163 dawes 1.1 pScreen->InstallColormap = miInstallColormap;
164 pScreen->UninstallColormap = miUninstallColormap;
165 pScreen->ListInstalledColormaps = miListInstalledColormaps;
|
166 dawes 1.9 pScreen->StoreColors = StoreColorsNoop;
|
167 dawes 1.1 pScreen->ResolveColor = miResolveColor;
168 pScreen->BitmapToRegion = mfbPixmapToRegion;
169
170 mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
171 return TRUE;
172 }
173
174 static Bool
175 cfb8_16CreateScreenResources(ScreenPtr pScreen)
176 {
|
177 dawes 1.3 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
178 dawes 1.1 cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
179 PixmapPtr pix8, pix16;
180
181 xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
182
183 pix8 = (*pScreen->CreatePixmap)(pScreen, 0, 0, 8);
|
184 dawes 1.3 pix16 = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScrn->depth);
|
185 dawes 1.1 if(!pix16 || !pix8)
186 return FALSE;
187
188 pix8->drawable.width = pScreen->width;
189 pix8->drawable.height = pScreen->height;
190 pix8->devKind = pScreenPriv->width8;
191 pix8->devPrivate.ptr = pScreenPriv->pix8;
192
193 pix16->drawable.width = pScreen->width;
194 pix16->drawable.height = pScreen->height;
195 pix16->devKind = pScreenPriv->width16 * 2;
196 pix16->devPrivate.ptr = pScreenPriv->pix16;
197
198 pScreenPriv->pix8 = (pointer)pix8;
199 pScreenPriv->pix16 = (pointer)pix16;
200
|
201 dawes 1.2 pScreen->devPrivate = (pointer)pix16;
|
202 dawes 1.1
203 return TRUE;
204 }
205
206
207 static Bool
208 cfb8_16CloseScreen (int i, ScreenPtr pScreen)
209 {
210 cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
211
212 xfree((pointer) pScreenPriv);
213
214 return(cfb16CloseScreen(i, pScreen));
215 }
216
217 static Bool
218 cfb8_16FinishScreenInit(
219 ScreenPtr pScreen,
220 int xsize, int ysize, /* in pixels */
221 int dpix, int dpiy /* dots per inch */
222 ){
|
223 dawes 1.2 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
224 dawes 1.1 VisualPtr visuals;
225 DepthPtr depths;
226 int nvisuals;
227 int ndepths;
228 int rootdepth;
229 VisualID defaultVisual;
230
231 rootdepth = 0;
232 if (!miInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
233 &defaultVisual,((unsigned long)1<<(16-1)), 8, -1))
234 return FALSE;
235 if (! miScreenInit(pScreen, NULL, xsize, ysize, dpix, dpiy, 0,
236 rootdepth, ndepths, depths,
237 defaultVisual, nvisuals, visuals))
238 return FALSE;
239
240 pScreen->BackingStoreFuncs = cfb8_16BSFuncRec;
241 pScreen->CreateScreenResources = cfb8_16CreateScreenResources;
242 pScreen->CloseScreen = cfb8_16CloseScreen;
243 pScreen->GetWindowPixmap = cfb8_16GetWindowPixmap;
244 pScreen->WindowExposures = cfb8_16WindowExposures;
|
245 dawes 1.2
|
246 dawes 1.7 pScrn->EnableDisableFBAccess = cfb8_16EnableDisableFBAccess;
|
247 dawes 1.2
|
248 dawes 1.1 return TRUE;
249 }
250
251 Bool
252 cfb8_16ScreenInit(
253 ScreenPtr pScreen,
254 pointer pbits16, /* pointer to screen bitmap */
255 pointer pbits8,
256 int xsize, int ysize, /* in pixels */
257 int dpix, int dpiy, /* dots per inch */
258 int width16, /* pixel width of frame buffer */
|
259 dawes 1.4 int width8
|
260 dawes 1.1 ){
|
261 dawes 1.4 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
262 dawes 1.1 cfb8_16ScreenPtr pScreenPriv;
263
264 if (!cfb8_16SetupScreen(pScreen, xsize, ysize, dpix, dpiy))
265 return FALSE;
266
267 pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
268 pScreenPriv->pix8 = pbits8;
269 pScreenPriv->pix16 = pbits16;
270 pScreenPriv->width8 = width8;
271 pScreenPriv->width16 = width16;
|
272 dawes 1.4 pScreenPriv->key = pScrn->colorKey;
|
273 dawes 1.1
274 return cfb8_16FinishScreenInit(pScreen, xsize, ysize, dpix, dpiy);
275 }
276
277
278 static PixmapPtr
279 cfb8_16GetWindowPixmap(WindowPtr pWin)
280 {
281 cfb8_16ScreenPtr pScreenPriv =
282 CFB8_16_GET_SCREEN_PRIVATE(pWin->drawable.pScreen);
283
284 return((pWin->drawable.bitsPerPixel == 16) ?
285 (PixmapPtr)pScreenPriv->pix16 : (PixmapPtr)pScreenPriv->pix8);
286 }
287
288 static void
289 cfb8_16GetImage (
290 DrawablePtr pDraw,
291 int sx, int sy, int w, int h,
292 unsigned int format,
293 unsigned long planemask,
294 dawes 1.1 char *pdstLine
295 ){
296 if(!w || !h) return;
297
298 if(pDraw->bitsPerPixel == 16)
299 cfb16GetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
300 else
301 cfbGetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
302 }
303
304 static void
305 cfb8_16GetSpans(
306 DrawablePtr pDraw,
307 int wMax,
308 DDXPointPtr ppt,
309 int *pwidth,
310 int nspans,
311 char *pDst
312 ){
313 if(pDraw->bitsPerPixel == 16)
314 cfb16GetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
315 dawes 1.1 else
316 cfbGetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
317 }
318
319 static void
320 cfb8_16SaveAreas(
321 PixmapPtr pPixmap,
322 RegionPtr prgnSave,
323 int xorg,
324 int yorg,
325 WindowPtr pWin
326 ){
327 if(pWin->drawable.bitsPerPixel == 16)
328 cfb16SaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
329 else
330 cfbSaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
331 }
332
333 static void
334 cfb8_16RestoreAreas(
335 PixmapPtr pPixmap,
336 dawes 1.1 RegionPtr prgnRestore,
337 int xorg,
338 int yorg,
339 WindowPtr pWin
340 ){
341 if(pWin->drawable.bitsPerPixel == 16)
342 cfb16RestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
343 else
344 cfbRestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
345 }
346
347
348 static Bool
349 cfb8_16CreateGC(GCPtr pGC)
350 {
|
351 dawes 1.3 if(pGC->depth == 8)
352 return(cfbCreateGC(pGC));
353 else
|
354 dawes 1.1 return(cfb16CreateGC(pGC));
|
355 dawes 1.2 }
356
|
357 dawes 1.7 static void
358 cfb8_16EnableDisableFBAccess(int index, Bool enable)
|
359 dawes 1.2 {
360 ScreenPtr pScreen = xf86Screens[index]->pScreen;
361 cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
|
362 dawes 1.7 static DevUnion devPrivates8[MAXSCREENS];
363 static DevUnion devPrivates16[MAXSCREENS];
364 PixmapPtr pix8, pix16;
365
366 pix8 = (PixmapPtr) pScreenPriv->pix8;
367 pix16 = (PixmapPtr) pScreenPriv->pix16;
368
369 if (enable)
370 {
371 pix8->devPrivate = devPrivates8[index];
372 pix16->devPrivate = devPrivates16[index];
373 }
374 xf86EnableDisableFBAccess (index, enable);
375 if (!enable)
376 {
377 devPrivates8[index] = pix8->devPrivate;
378 pix8->devPrivate.ptr = 0;
379 devPrivates16[index] = pix16->devPrivate;
380 pix16->devPrivate.ptr = 0;
|
381 dawes 1.2 }
|
382 dawes 1.1 }
|