summaryrefslogtreecommitdiff
path: root/hw/xfree86/xf8_16bpp/cfbscrinit.c
blob: cb4b8d7261a6f9f30172da08c5bed3a953b46f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
   Copyright (C) 1999.  The XFree86 Project Inc.

   Written by Mark Vojkovich (mvojkovi@ucsd.edu)
*/

/* $XFree86: xc/programs/Xserver/hw/xfree86/xf8_16bpp/cfbscrinit.c,v 1.7 2000/01/21 01:12:24 dawes Exp $ */

#include "X.h"
#include "Xmd.h"
#include "misc.h"
#include "servermd.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "resource.h"
#include "colormap.h"
#include "colormapst.h"
#define PSZ 8
#include "cfb.h"
#undef PSZ
#include "cfb16.h"
#include "cfb8_16.h"
#include "mi.h"
#include "micmap.h"
#include "mistruct.h"
#include "gcstruct.h"
#include "dix.h"
#include "mibstore.h"
#include "xf86str.h"
#include "xf86.h"

/* CAUTION:  We require that cfb8 and cfb16 were NOT 
	compiled with CFB_NEED_SCREEN_PRIVATE */

int cfb8_16ScreenPrivateIndex;

static unsigned long cfb8_16Generation = 0;

static PixmapPtr cfb8_16GetWindowPixmap(WindowPtr pWin);
static void
cfb8_16SaveAreas(
    PixmapPtr	  	pPixmap,
    RegionPtr	  	prgnSave, 
    int	    	  	xorg,
    int	    	  	yorg,
    WindowPtr		pWin
);

static void
cfb8_16RestoreAreas(
    PixmapPtr	  	pPixmap, 
    RegionPtr	  	prgnRestore,
    int	    	  	xorg,
    int	    	  	yorg,
    WindowPtr		pWin
);

static BSFuncRec cfb8_16BSFuncRec = {
    cfb8_16SaveAreas,
    cfb8_16RestoreAreas,
    (BackingStoreSetClipmaskRgnProcPtr) 0,
    (BackingStoreGetImagePixmapProcPtr) 0,
    (BackingStoreGetSpansPixmapProcPtr) 0,
};

static void
cfb8_16GetSpans(
   DrawablePtr pDraw,
   int wMax,
   DDXPointPtr ppt,
   int *pwidth,
   int nspans,
   char *pchardstStart
);

static void
cfb8_16GetImage (
    DrawablePtr pDraw,
    int sx, int sy, int w, int h,
    unsigned int format,
    unsigned long planeMask,
    char *pdstLine
);

static Bool cfb8_16CreateGC(GCPtr pGC);
static void cfb8_16EnableDisableFBAccess(int index, Bool enable);


static Bool
cfb8_16AllocatePrivates(ScreenPtr pScreen)
{
   cfb8_16ScreenPtr pScreenPriv;

   if(cfb8_16Generation != serverGeneration) {
	if((cfb8_16ScreenPrivateIndex = AllocateScreenPrivateIndex()) < 0)
	    return FALSE;
	cfb8_16Generation = serverGeneration;
   }

   if (!(pScreenPriv = xalloc(sizeof(cfb8_16ScreenRec))))
        return FALSE;

   pScreen->devPrivates[cfb8_16ScreenPrivateIndex].ptr = (pointer)pScreenPriv;
   
   
   /* All cfb will have the same GC and Window private indicies */
   if(!mfbAllocatePrivates(pScreen,&cfbWindowPrivateIndex, &cfbGCPrivateIndex))
	return FALSE;

   /* The cfb indicies are the mfb indicies. Reallocating them resizes them */ 
   if(!AllocateWindowPrivate(pScreen,cfbWindowPrivateIndex,sizeof(cfbPrivWin)))
	return FALSE;

   if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
        return FALSE;

   return TRUE;
}

static Bool
cfb8_16SetupScreen(
    ScreenPtr pScreen,
    int xsize, int ysize,	/* in pixels */
    int dpix, int dpiy
){
    if (!cfb8_16AllocatePrivates(pScreen))
	return FALSE;
    pScreen->defColormap = FakeClientID(0);
    /* let CreateDefColormap do whatever it wants for pixels */ 
    pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
    pScreen->QueryBestSize = mfbQueryBestSize;
    /* SaveScreen */
    pScreen->GetImage = cfb8_16GetImage;
    pScreen->GetSpans = cfb8_16GetSpans;
    pScreen->CreateWindow = cfb8_16CreateWindow;
    pScreen->DestroyWindow = cfb8_16DestroyWindow;	
    pScreen->PositionWindow = cfb8_16PositionWindow;
    pScreen->ChangeWindowAttributes = cfb8_16ChangeWindowAttributes;
    pScreen->RealizeWindow = cfb16MapWindow;			/* OK */
    pScreen->UnrealizeWindow = cfb16UnmapWindow;		/* OK */
    pScreen->PaintWindowBackground = cfb8_16PaintWindow;
    pScreen->PaintWindowBorder = cfb8_16PaintWindow;
    pScreen->CopyWindow = cfb8_16CopyWindow;
    pScreen->CreatePixmap = cfb16CreatePixmap;			/* OK */
    pScreen->DestroyPixmap = cfb16DestroyPixmap; 		/* OK */
    pScreen->RealizeFont = mfbRealizeFont;
    pScreen->UnrealizeFont = mfbUnrealizeFont;
    pScreen->CreateGC = cfb8_16CreateGC;
    pScreen->CreateColormap = miInitializeColormap;
    pScreen->DestroyColormap = (void (*)())NoopDDA;
    pScreen->InstallColormap = miInstallColormap;
    pScreen->UninstallColormap = miUninstallColormap;
    pScreen->ListInstalledColormaps = miListInstalledColormaps;
    pScreen->StoreColors = (void (*)())NoopDDA;
    pScreen->ResolveColor = miResolveColor;
    pScreen->BitmapToRegion = mfbPixmapToRegion;

    mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
    return TRUE;
}

static Bool
cfb8_16CreateScreenResources(ScreenPtr pScreen)
{
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
    PixmapPtr pix8, pix16;
    
    xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */

    pix8 = (*pScreen->CreatePixmap)(pScreen, 0, 0, 8);
    pix16 = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScrn->depth);
    if(!pix16 || !pix8)
	return FALSE;

    pix8->drawable.width = pScreen->width;
    pix8->drawable.height = pScreen->height;
    pix8->devKind = pScreenPriv->width8;
    pix8->devPrivate.ptr = pScreenPriv->pix8;

    pix16->drawable.width = pScreen->width;
    pix16->drawable.height = pScreen->height;
    pix16->devKind = pScreenPriv->width16 * 2;
    pix16->devPrivate.ptr = pScreenPriv->pix16;

    pScreenPriv->pix8 = (pointer)pix8;
    pScreenPriv->pix16 = (pointer)pix16;

    pScreen->devPrivate = (pointer)pix16;

    return TRUE;
}


static Bool
cfb8_16CloseScreen (int i, ScreenPtr pScreen)
{
    cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);

    xfree((pointer) pScreenPriv);

    return(cfb16CloseScreen(i, pScreen));
}

static Bool
cfb8_16FinishScreenInit(
    ScreenPtr pScreen,
    int xsize, int ysize,	/* in pixels */
    int dpix, int dpiy		/* dots per inch */
){
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    VisualPtr	visuals;
    DepthPtr	depths;
    int		nvisuals;
    int		ndepths;
    int		rootdepth;
    VisualID	defaultVisual;

    rootdepth = 0;
    if (!miInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
			 &defaultVisual,((unsigned long)1<<(16-1)), 8, -1))
	return FALSE;
    if (! miScreenInit(pScreen, NULL, xsize, ysize, dpix, dpiy, 0,
			rootdepth, ndepths, depths,
			defaultVisual, nvisuals, visuals))
	return FALSE;

    pScreen->BackingStoreFuncs = cfb8_16BSFuncRec;
    pScreen->CreateScreenResources = cfb8_16CreateScreenResources;
    pScreen->CloseScreen = cfb8_16CloseScreen;
    pScreen->GetWindowPixmap = cfb8_16GetWindowPixmap;
    pScreen->WindowExposures = cfb8_16WindowExposures;

    pScrn->EnableDisableFBAccess = cfb8_16EnableDisableFBAccess;

    return TRUE;
}

Bool
cfb8_16ScreenInit(
    ScreenPtr pScreen,
    pointer pbits16,		/* pointer to screen bitmap */
    pointer pbits8,
    int xsize, int ysize,	/* in pixels */
    int dpix, int dpiy,		/* dots per inch */
    int width16,		/* pixel width of frame buffer */
    int width8
){
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    cfb8_16ScreenPtr pScreenPriv;

    if (!cfb8_16SetupScreen(pScreen, xsize, ysize, dpix, dpiy))
	return FALSE;

    pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
    pScreenPriv->pix8 = pbits8;
    pScreenPriv->pix16 = pbits16;
    pScreenPriv->width8 = width8;
    pScreenPriv->width16 = width16;
    pScreenPriv->key = pScrn->colorKey;

    return cfb8_16FinishScreenInit(pScreen, xsize, ysize, dpix, dpiy);
}


static PixmapPtr
cfb8_16GetWindowPixmap(WindowPtr pWin)
{
    cfb8_16ScreenPtr pScreenPriv = 
		CFB8_16_GET_SCREEN_PRIVATE(pWin->drawable.pScreen);

    return((pWin->drawable.bitsPerPixel == 16) ?
	(PixmapPtr)pScreenPriv->pix16 : (PixmapPtr)pScreenPriv->pix8);
}

static void
cfb8_16GetImage (
    DrawablePtr pDraw,
    int sx, int sy, int w, int h,
    unsigned int format,
    unsigned long planemask,
    char *pdstLine
){
    if(!w || !h) return;

    if(pDraw->bitsPerPixel == 16)
	cfb16GetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
    else
	cfbGetImage(pDraw, sx, sy, w, h, format, planemask, pdstLine);
}

static void
cfb8_16GetSpans(
   DrawablePtr pDraw,
   int wMax,
   DDXPointPtr ppt,
   int *pwidth,
   int nspans,
   char *pDst
){
    if(pDraw->bitsPerPixel == 16)
	cfb16GetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
    else
	cfbGetSpans(pDraw, wMax, ppt, pwidth, nspans, pDst);
}

static void
cfb8_16SaveAreas(
    PixmapPtr	  	pPixmap,
    RegionPtr	  	prgnSave, 
    int	    	  	xorg,
    int	    	  	yorg,
    WindowPtr		pWin
){
    if(pWin->drawable.bitsPerPixel == 16)
        cfb16SaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
    else
        cfbSaveAreas(pPixmap, prgnSave, xorg, yorg, pWin);
}

static void
cfb8_16RestoreAreas(
    PixmapPtr	  	pPixmap, 
    RegionPtr	  	prgnRestore,
    int	    	  	xorg,
    int	    	  	yorg,
    WindowPtr		pWin
){
    if(pWin->drawable.bitsPerPixel == 16)
        cfb16RestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
    else
        cfbRestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin);
}


static Bool
cfb8_16CreateGC(GCPtr pGC)
{
    if(pGC->depth == 8)
	return(cfbCreateGC(pGC));
    else
	return(cfb16CreateGC(pGC));
}

static void
cfb8_16EnableDisableFBAccess(int index, Bool enable)
{
    ScreenPtr pScreen = xf86Screens[index]->pScreen;
    cfb8_16ScreenPtr pScreenPriv = CFB8_16_GET_SCREEN_PRIVATE(pScreen);
    static DevUnion devPrivates8[MAXSCREENS];
    static DevUnion devPrivates16[MAXSCREENS];
    PixmapPtr	pix8, pix16;

    pix8 = (PixmapPtr) pScreenPriv->pix8;
    pix16 = (PixmapPtr) pScreenPriv->pix16;

    if (enable)
    {
	pix8->devPrivate = devPrivates8[index];
	pix16->devPrivate = devPrivates16[index];
    }
    xf86EnableDisableFBAccess (index, enable);
    if (!enable)
    {
	devPrivates8[index] = pix8->devPrivate;
	pix8->devPrivate.ptr = 0;
	devPrivates16[index] = pix16->devPrivate;
	pix16->devPrivate.ptr = 0;
    }
}