(file) Return to cfbscrinit.c CVS log (file) (dir) Up to [XFree86 CVS] / xc / programs / Xserver / hw / xfree86 / xf8_16bpp

  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.6 /* $XFree86: xc/programs/Xserver/hw/xfree86/xf8_16bpp/cfbscrinit.c,v 1.5 1999/04/04 08:46:24 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           extern WindowPtr *WindowTable;
 39           
 40           static PixmapPtr cfb8_16GetWindowPixmap(WindowPtr pWin);
 41           static void
 42           cfb8_16SaveAreas(
 43               PixmapPtr	  	pPixmap,
 44               RegionPtr	  	prgnSave, 
 45               int	    	  	xorg,
 46               int	    	  	yorg,
 47               WindowPtr		pWin
 48           );
 49           
 50           static void
 51           cfb8_16RestoreAreas(
 52 dawes 1.1     PixmapPtr	  	pPixmap, 
 53               RegionPtr	  	prgnRestore,
 54               int	    	  	xorg,
 55               int	    	  	yorg,
 56               WindowPtr		pWin
 57           );
 58           
 59           static BSFuncRec cfb8_16BSFuncRec = {
 60               cfb8_16SaveAreas,
 61               cfb8_16RestoreAreas,
 62               (BackingStoreSetClipmaskRgnProcPtr) 0,
 63               (BackingStoreGetImagePixmapProcPtr) 0,
 64               (BackingStoreGetSpansPixmapProcPtr) 0,
 65           };
 66           
 67           static void
 68           cfb8_16GetSpans(
 69              DrawablePtr pDraw,
 70              int wMax,
 71              DDXPointPtr ppt,
 72              int *pwidth,
 73 dawes 1.1    int nspans,
 74              char *pchardstStart
 75           );
 76           
 77           static void
 78           cfb8_16GetImage (
 79               DrawablePtr pDraw,
 80               int sx, int sy, int w, int h,
 81               unsigned int format,
 82               unsigned long planeMask,
 83               char *pdstLine
 84           );
 85           
 86           static Bool cfb8_16CreateGC(GCPtr pGC);
 87 dawes 1.2 static Bool cfb8_16SaveRestoreImage(int index, SaveRestoreFlags what);
 88 dawes 1.1 
 89           
 90           static Bool
 91           cfb8_16AllocatePrivates(ScreenPtr pScreen)
 92           {
 93              cfb8_16ScreenPtr pScreenPriv;
 94           
 95              if(cfb8_16Generation != serverGeneration) {
 96           	if((cfb8_16ScreenPrivateIndex = AllocateScreenPrivateIndex()) < 0)
 97           	    return FALSE;
 98           	cfb8_16Generation = serverGeneration;
 99              }
100           
101              if (!(pScreenPriv = xalloc(sizeof(cfb8_16ScreenRec))))
102                   return FALSE;
103           
104              pScreen->devPrivates[cfb8_16ScreenPrivateIndex].ptr = (pointer)pScreenPriv;
105              
106              
107              /* All cfb will have the same GC and Window private indicies */
108              if(!mfbAllocatePrivates(pScreen,&cfbWindowPrivateIndex, &cfbGCPrivateIndex))
109 dawes 1.1 	return FALSE;
110           
111              /* The cfb indicies are the mfb indicies. Reallocating them resizes them */ 
112              if(!AllocateWindowPrivate(pScreen,cfbWindowPrivateIndex,sizeof(cfbPrivWin)))
113           	return FALSE;
114           
115              if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
116                   return FALSE;
117           
118              return TRUE;
119           }
120           
121           static Bool
122           cfb8_16SetupScreen(
123               ScreenPtr pScreen,
124               int xsize, int ysize,	/* in pixels */
125               int dpix, int dpiy
126           ){
127               if (!cfb8_16AllocatePrivates(pScreen))
128           	return FALSE;
129               pScreen->defColormap = FakeClientID(0);
130 dawes 1.1     /* let CreateDefColormap do whatever it wants for pixels */ 
131               pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
132               pScreen->QueryBestSize = mfbQueryBestSize;
133               /* SaveScreen */
134               pScreen->GetImage = cfb8_16GetImage;
135               pScreen->GetSpans = cfb8_16GetSpans;
136               pScreen->CreateWindow = cfb8_16CreateWindow;
137               pScreen->DestroyWindow = cfb8_16DestroyWindow;	
138               pScreen->PositionWindow = cfb8_16PositionWindow;
139               pScreen->ChangeWindowAttributes = cfb8_16ChangeWindowAttributes;
140               pScreen->RealizeWindow = cfb16MapWindow;			/* OK */
141               pScreen->UnrealizeWindow = cfb16UnmapWindow;		/* OK */
142               pScreen->PaintWindowBackground = cfb8_16PaintWindow;
143               pScreen->PaintWindowBorder = cfb8_16PaintWindow;
144               pScreen->CopyWindow = cfb8_16CopyWindow;
145               pScreen->CreatePixmap = cfb16CreatePixmap;			/* OK */
146               pScreen->DestroyPixmap = cfb16DestroyPixmap; 		/* OK */
147               pScreen->RealizeFont = mfbRealizeFont;
148               pScreen->UnrealizeFont = mfbUnrealizeFont;
149               pScreen->CreateGC = cfb8_16CreateGC;
150               pScreen->CreateColormap = miInitializeColormap;
151 dawes 1.1     pScreen->DestroyColormap = (void (*)())NoopDDA;
152               pScreen->InstallColormap = miInstallColormap;
153               pScreen->UninstallColormap = miUninstallColormap;
154               pScreen->ListInstalledColormaps = miListInstalledColormaps;
155               pScreen->StoreColors = (void (*)())NoopDDA;
156               pScreen->ResolveColor = miResolveColor;
157               pScreen->BitmapToRegion = mfbPixmapToRegion;
158           
159               mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
160               return TRUE;
161           }
162           
163           static Bool
164           cfb8_16CreateScreenResources(ScreenPtr pScreen)
165           {
166 dawes 1.3     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
167 dawes 1.1     cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
168               PixmapPtr pix8, pix16;
169               
170               xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
171           
172               pix8 = (*pScreen->CreatePixmap)(pScreen, 0, 0, 8);
173 dawes 1.3     pix16 = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScrn->depth);
174 dawes 1.1     if(!pix16 || !pix8)
175           	return FALSE;
176           
177               pix8->drawable.width = pScreen->width;
178               pix8->drawable.height = pScreen->height;
179               pix8->devKind = pScreenPriv->width8;
180               pix8->devPrivate.ptr = pScreenPriv->pix8;
181           
182               pix16->drawable.width = pScreen->width;
183               pix16->drawable.height = pScreen->height;
184               pix16->devKind = pScreenPriv->width16 * 2;
185               pix16->devPrivate.ptr = pScreenPriv->pix16;
186           
187               pScreenPriv->pix8 = (pointer)pix8;
188               pScreenPriv->pix16 = (pointer)pix16;
189           
190 dawes 1.2     pScreen->devPrivate = (pointer)pix16;
191 dawes 1.1 
192               return TRUE;
193           }
194           
195           
196           static Bool
197           cfb8_16CloseScreen (int i, ScreenPtr pScreen)
198           {
199               cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
200           
201               xfree((pointer) pScreenPriv);
202           
203               return(cfb16CloseScreen(i, pScreen));
204           }
205           
206           static Bool
207           cfb8_16FinishScreenInit(
208               ScreenPtr pScreen,
209               int xsize, int ysize,	/* in pixels */
210               int dpix, int dpiy		/* dots per inch */
211           ){
212 dawes 1.2     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
213 dawes 1.1     VisualPtr	visuals;
214               DepthPtr	depths;
215               int		nvisuals;
216               int		ndepths;
217               int		rootdepth;
218               VisualID	defaultVisual;
219           
220               rootdepth = 0;
221               if (!miInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
222           			 &defaultVisual,((unsigned long)1<<(16-1)), 8, -1))
223           	return FALSE;
224               if (! miScreenInit(pScreen, NULL, xsize, ysize, dpix, dpiy, 0,
225           			rootdepth, ndepths, depths,
226           			defaultVisual, nvisuals, visuals))
227           	return FALSE;
228           
229               pScreen->BackingStoreFuncs = cfb8_16BSFuncRec;
230               pScreen->CreateScreenResources = cfb8_16CreateScreenResources;
231               pScreen->CloseScreen = cfb8_16CloseScreen;
232               pScreen->GetWindowPixmap = cfb8_16GetWindowPixmap;
233               pScreen->WindowExposures = cfb8_16WindowExposures;
234 dawes 1.2 
235               pScrn->SaveRestoreImage = cfb8_16SaveRestoreImage;
236           
237 dawes 1.1     return TRUE;
238           }
239           
240           Bool
241           cfb8_16ScreenInit(
242               ScreenPtr pScreen,
243               pointer pbits16,		/* pointer to screen bitmap */
244               pointer pbits8,
245               int xsize, int ysize,	/* in pixels */
246               int dpix, int dpiy,		/* dots per inch */
247               int width16,		/* pixel width of frame buffer */
248 dawes 1.4     int width8
249 dawes 1.1 ){
250 dawes 1.4     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
251 dawes 1.1     cfb8_16ScreenPtr pScreenPriv;
252           
253               if (!cfb8_16SetupScreen(pScreen, xsize, ysize, dpix, dpiy))
254           	return FALSE;
255           
256               pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
257               pScreenPriv->pix8 = pbits8;
258               pScreenPriv->pix16 = pbits16;
259               pScreenPriv->width8 = width8;
260               pScreenPriv->width16 = width16;
261 dawes 1.4     pScreenPriv->key = pScrn->colorKey;
262 dawes 1.1 
263               return cfb8_16FinishScreenInit(pScreen, xsize, ysize, dpix, dpiy);
264           }
265           
266           
267           static PixmapPtr
268           cfb8_16GetWindowPixmap(WindowPtr pWin)
269           {
270               cfb8_16ScreenPtr pScreenPriv = 
271           		CFB8_16_GET_SCREEN_PRIVATE(pWin->drawable.pScreen);
272           
273               return((pWin->drawable.bitsPerPixel == 16) ?
274           	(PixmapPtr)pScreenPriv->pix16 : (PixmapPtr)pScreenPriv->pix8);
275           }
276           
277           static void
278           cfb8_16GetImage (
279               DrawablePtr pDraw,
280               int sx, int sy, int w, int h,
281               unsigned int format,
282               unsigned long planemask,
283 dawes 1.1     char *pdstLine
284           ){
285               if(!w || !h) return;
286           
287               if(pDraw->bitsPerPixel == 16)
288           	cfb16GetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
289               else
290           	cfbGetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
291           }
292           
293           static void
294           cfb8_16GetSpans(
295              DrawablePtr pDraw,
296              int wMax,
297              DDXPointPtr ppt,
298              int *pwidth,
299              int nspans,
300              char *pDst
301           ){
302               if(pDraw->bitsPerPixel == 16)
303           	cfb16GetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
304 dawes 1.1     else
305           	cfbGetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
306           }
307           
308           static void
309           cfb8_16SaveAreas(
310               PixmapPtr	  	pPixmap,
311               RegionPtr	  	prgnSave, 
312               int	    	  	xorg,
313               int	    	  	yorg,
314               WindowPtr		pWin
315           ){
316               if(pWin->drawable.bitsPerPixel == 16)
317                   cfb16SaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
318               else
319                   cfbSaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
320           }
321           
322           static void
323           cfb8_16RestoreAreas(
324               PixmapPtr	  	pPixmap, 
325 dawes 1.1     RegionPtr	  	prgnRestore,
326               int	    	  	xorg,
327               int	    	  	yorg,
328               WindowPtr		pWin
329           ){
330               if(pWin->drawable.bitsPerPixel == 16)
331                   cfb16RestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
332               else
333                   cfbRestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
334           }
335           
336           
337           static Bool
338           cfb8_16CreateGC(GCPtr pGC)
339           {
340 dawes 1.3     if(pGC->depth == 8)
341           	return(cfbCreateGC(pGC));
342               else
343 dawes 1.1 	return(cfb16CreateGC(pGC));
344 dawes 1.2 }
345           
346           static Bool
347           cfb8_16SaveRestoreImage(int index, SaveRestoreFlags what)
348           {
349               ScreenPtr pScreen = xf86Screens[index]->pScreen;
350 dawes 1.3     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
351 dawes 1.2     cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
352               static unsigned char *devPrivates8[MAXSCREENS];
353               static unsigned char *devPrivates16[MAXSCREENS];
354               static int devKinds8[MAXSCREENS];
355               static int devKinds16[MAXSCREENS];
356               pointer devPrivate8, devPrivate16;
357               Bool ret = FALSE;
358               int devKind8, devKind16;
359               PixmapPtr pPixSrc, pPixDst;
360               BoxRec pixBox;
361               RegionRec pixReg;
362               DDXPointRec Pnt;
363           
364               pixBox.x1 = pixBox.y1 = 0;
365               pixBox.x2 = pScreen->width;
366               pixBox.y2 = pScreen->height;
367 dawes 1.6     REGION_INIT(pScreen, &pixReg, &pixBox, 1);
368 dawes 1.2 
369               Pnt.x = 0;
370               Pnt.y = 0;
371           
372               switch (what) {
373               case SaveImage:
374           
375           	/* save the old data */
376           	devPrivates8[index] = 
377           	  (unsigned char*)(((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr);
378           	devKinds8[index] = ((PixmapPtr)pScreenPriv->pix8)->devKind;
379           	devPrivates16[index] = 
380           	  (unsigned char*)(((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr);
381           	devKinds16[index] = ((PixmapPtr)pScreenPriv->pix16)->devKind;
382           	
383           	/* allocate new data */
384 dawes 1.5 	devKind8 = PixmapBytePad(pScreen->width, 8);
385 dawes 1.2         if(!(devPrivate8 = xalloc(devKind8 * pScreen->height)))
386           	   break;
387           
388 dawes 1.5 	devKind16 = PixmapBytePad(pScreen->width, pScrn->depth);
389 dawes 1.2         if(!(devPrivate16 = xalloc(devKind16 * pScreen->height))) {
390           	    xfree(devPrivate8);
391           	    break;
392           	}
393           
394           	/* DEPTH 8 */
395           
396           	pPixDst = GetScratchPixmapHeader(pScreen, pScreen->width, 
397           				pScreen->height, 8, 8, devKind8, devPrivate8);
398           
399           	pPixSrc = GetScratchPixmapHeader(pScreen, pScreen->width, 
400           				pScreen->height, 8, 8, devKinds8[index],
401           				devPrivates8[index]);
402           
403           	cfbDoBitbltCopy((DrawablePtr)pPixSrc, (DrawablePtr)pPixDst,
404                               			GXcopy, &pixReg, &Pnt, ~0L);
405           
406           	FreeScratchPixmapHeader(pPixSrc);
407           	FreeScratchPixmapHeader(pPixDst);
408           
409           	((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr = (pointer)devPrivate8;
410 dawes 1.2 	((PixmapPtr)pScreenPriv->pix8)->devKind = devKind8;
411           
412           
413           	/* DEPTH 16 */
414           
415           	pPixDst = GetScratchPixmapHeader(pScreen, pScreen->width, 
416 dawes 1.3 			pScreen->height, pScrn->depth, 16, devKind16,
417           			devPrivate16);
418 dawes 1.2 
419           	pPixSrc = GetScratchPixmapHeader(pScreen, pScreen->width, 
420 dawes 1.3 				pScreen->height, pScrn->depth, 16,
421           				devKinds16[index], devPrivates16[index]);
422 dawes 1.2 
423           	cfb16DoBitbltCopy((DrawablePtr)pPixSrc, (DrawablePtr)pPixDst,
424                               			GXcopy, &pixReg, &Pnt, ~0L);
425           
426           	FreeScratchPixmapHeader(pPixSrc);
427           	FreeScratchPixmapHeader(pPixDst);
428           
429           	((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr = (pointer)devPrivate16;
430           	((PixmapPtr)pScreenPriv->pix16)->devKind = devKind16;
431           	((PixmapPtr)pScreen->devPrivate)->devKind = devKind16;
432           	((PixmapPtr)pScreen->devPrivate)->devPrivate.ptr = 
433           						(pointer)devPrivate16;
434           
435           	ret = TRUE;
436           
437           	WalkTree(xf86Screens[index]->pScreen,xf86NewSerialNumber,0);
438           
439           	break;
440               case RestoreImage:
441           	
442           	if (!xf86ServerIsResetting()) {
443 dawes 1.2             devPrivate8 = ((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr;
444           	    devKind8 = ((PixmapPtr)pScreenPriv->pix8)->devKind;
445           
446                       devPrivate16 = ((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr;
447           	    devKind16 = ((PixmapPtr)pScreenPriv->pix16)->devKind;
448           
449           	    /* DEPTH 8 */
450           
451           	    pPixSrc = GetScratchPixmapHeader(pScreen, pScreen->width, 
452           		   pScreen->height, 8, 8, devKind8, devPrivate8);
453           
454           
455           	    pPixDst = GetScratchPixmapHeader(pScreen, pScreen->width, 
456           		   pScreen->height, 8, 8, devKinds8[index], 
457           		   devPrivates8[index]);
458           
459           	    cfbDoBitbltCopy((DrawablePtr)pPixSrc, (DrawablePtr)pPixDst,
460                               			GXcopy, &pixReg, &Pnt, ~0L);
461           
462           	    xfree(devPrivate8);
463           	    FreeScratchPixmapHeader(pPixSrc);
464 dawes 1.2 	    FreeScratchPixmapHeader(pPixDst);
465           
466           	    ((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr = 
467           					(pointer)devPrivates8[index];
468           	    ((PixmapPtr)pScreenPriv->pix8)->devKind = devKinds8[index];
469           
470           
471           	    /* DEPTH 16 */
472           	    pPixSrc = GetScratchPixmapHeader(pScreen, pScreen->width, 
473           		   pScreen->height, 16, 16, devKind16, devPrivate16);
474           
475           
476           	    pPixDst = GetScratchPixmapHeader(pScreen, pScreen->width, 
477           		   pScreen->height, 16, 16, devKinds16[index], 
478           		   devPrivates16[index]);
479           
480           	    cfbDoBitbltCopy((DrawablePtr)pPixSrc, (DrawablePtr)pPixDst,
481                               			GXcopy, &pixReg, &Pnt, ~0L);
482           
483           	    xfree(devPrivate16);
484           	    FreeScratchPixmapHeader(pPixSrc);
485 dawes 1.2 	    FreeScratchPixmapHeader(pPixDst);
486           
487           	    ((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr = 
488           					(pointer)devPrivates16[index];
489           	    ((PixmapPtr)pScreenPriv->pix16)->devKind = devKinds16[index];
490           	    ((PixmapPtr)pScreen->devPrivate)->devKind = devKinds16[index];
491           	    ((PixmapPtr)pScreen->devPrivate)->devPrivate.ptr = 
492           					(pointer)devPrivates16[index];
493           
494           	    WalkTree(xf86Screens[index]->pScreen,xf86NewSerialNumber,0);
495           	    ret = TRUE;
496           	    break;
497           	}
498           	/* Fall through */
499               case FreeImage:
500           	if (((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr)
501           	    xfree(((PixmapPtr)pScreenPriv->pix16)->devPrivate.ptr);
502           	if (((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr)
503           	    xfree(((PixmapPtr)pScreenPriv->pix8)->devPrivate.ptr);
504           	ret = TRUE;
505           	break;
506 dawes 1.2     default:
507           	ErrorF("cfb8_16SaveRestoreImage: Invalid flag (%d)\n", what);
508               }
509 dawes 1.6     REGION_UNINIT(pScreen, &pixReg);
510 dawes 1.2     return ret;
511 dawes 1.1 }

Powered by
ViewCVS 0.9.2