summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/accel/mach64/mach64scrin.c
blob: ac8fd5da62d75f2df3b30c9539fe4d555be908e7 (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
/* $XConsortium: mach64scrin.c,v 1.1 94/12/14 15:04:34 kaleb Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/accel/mach64/mach64scrin.c,v 3.0 1994/11/26 12:42:59 dawes Exp $ */
/************************************************************
Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
Copyright 1993,1994 by Kevin E. Martin, Chapel Hill, North Carolina.

                    All Rights Reserved

Permission  to  use,  copy,  modify,  and  distribute   this
software  and  its documentation for any purpose and without
fee is hereby granted, provided that the above copyright no-
tice  appear  in all copies and that both that copyright no-
tice and this permission notice appear in  supporting  docu-
mentation,  and  that the name of Sun not be used in
advertising or publicity pertaining to distribution  of  the
software  without specific prior written permission. Sun
makes no representations about the suitability of this
software for any purpose. It is provided "as is" without any
express or implied warranty.

SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

Modified for the 8514/A by Kevin E. Martin (martin@cs.unc.edu)

KEVIN E. MARTIN AND RICKARD E. FAITH DISCLAIM ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL KEVIN E. MARTIN BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

Modified for the Mach-8 by Rickard E. Faith (faith@cs.unc.edu)
Modified for the Mach32 by Kevin E. Martin (martin@cs.unc.edu)
Modified for the Mach64 by Kevin E. Martin (martin@cs.unc.edu)

********************************************************/

#include "X.h"
#include "Xmd.h"
#include "Xproto.h"
#include "servermd.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "resource.h"
#include "colormap.h"
#include "colormapst.h"
#include "cfb.h"
#include "cfb16.h"
#include "cfb32.h"
#include "mi.h"
#include "mistruct.h"
#include "dix.h"
#include "cfbmskbits.h"
#include "mibstore.h"
#include "mach64.h"

extern RegionPtr mfbPixmapToRegion();
extern Bool cfbAllocatePrivates();
extern Bool cfb16AllocatePrivates();
extern Bool cfb32AllocatePrivates();
extern Bool cfbInitVisuals();
extern Bool miScreenInit();
extern Bool mfbRegisterCopyPlaneProc();
extern RegionPtr miCopyPlane();
extern void mach64BlockHandler();
extern Bool mach64DestroyPixmap();

extern int defaultColorVisualClass;
extern xrgb xf86weight;

static unsigned long cfbGeneration = 0;

miBSFuncRec mach64BSFuncRec = {
    mach64SaveAreas,
    mach64RestoreAreas,
    (void (*)()) 0,
    (PixmapPtr (*)()) 0,
    (PixmapPtr (*)()) 0,
};


/* dts * (inch/dot) * (25.4 mm / inch) = mm */
Bool
mach64ScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
    register ScreenPtr pScreen;
    pointer pbits;		/* pointer to screen bitmap */
    int xsize; int ysize;	/* in pixels */
    int dpix; int dpiy;		/* dots per inch */
    int width;			/* pixel width of frame buffer */
{
    VisualPtr visuals;
    DepthPtr depths;
    int nvisuals;
    int ndepths;
    int rootdepth;
    VisualID defaultVisual;
    int bitsPerRGB;
    int	i;
    Bool Rstatus;
    VisualPtr visual;
    pointer oldDevPrivate;

    rootdepth = 0;
    switch (mach64InfoRec.bitsPerPixel) {
    case 8:
	if (mach64DAC8Bit)
	    bitsPerRGB = 8;
	else
	    bitsPerRGB = 6;
	break;
    case 16:
	if (mach64WeightMask == RGB16_555)
	    bitsPerRGB = 5;
	else
	    bitsPerRGB = 6;
	break;
    case 32:
	bitsPerRGB = 8;
	break;
    default:
	FatalError("mach64ScreenInit: unsupported depth %d \n",
		    mach64InfoRec.bitsPerPixel);
    }
	
    if (cfbGeneration != serverGeneration) 
    {
	/* Only TrueColor for 16/32bpp */
	if (mach64InfoRec.bitsPerPixel > 8) 
	{
	    if (!cfbSetVisualTypes(mach64InfoRec.depth, 1 << TrueColor,
				   bitsPerRGB))
	    {
		return FALSE;
	    }
	}
	if (!cfbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
	    &defaultVisual, 1<<(mach64InfoRec.bitsPerPixel - 1), bitsPerRGB))
	{
	    return FALSE;
	}
	cfbGeneration = serverGeneration;
    }

    if (mach64InfoRec.bitsPerPixel == 16 || mach64InfoRec.bitsPerPixel == 32) 
    {
        /*
         * There are several possible color weightings at 16bpp and 32bpp.
         * Set them up here.
         */
        for (i = 0, visual = visuals; i < nvisuals; i++, visual++) 
	{
	    if (visual->class == DirectColor || visual->class == TrueColor) 
	    {
		if (mach64InfoRec.bitsPerPixel == 16) {
	        	visual->offsetRed = xf86weight.green + xf86weight.blue;
	        	visual->offsetGreen = xf86weight.blue;
	        	visual->offsetBlue = 0;
		} else if (mach64InfoRec.bitsPerPixel == 32) {
			visual->offsetRed = 0;
			visual->offsetGreen = 8;
			visual->offsetBlue = 16;
		}
		visual->redMask = ((1 << xf86weight.red) - 1)
					<< visual->offsetRed;
		visual->greenMask = ((1 << xf86weight.green) - 1)
					<< visual->offsetGreen;
		visual->blueMask = ((1 << xf86weight.blue) - 1)
					<< visual->offsetBlue;
	    }
	}
    }

    cfbWindowPrivateIndex = cfbGCPrivateIndex = -1;
    pScreen->defColormap = FakeClientID(0);
    /* let CreateDefColormap do whatever it wants for pixels */ 
    pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
    pScreen->QueryBestSize = mfbQueryBestSize;
    /* SaveScreen */
    pScreen->PaintWindowBackground = mach64PaintWindow;
    pScreen->PaintWindowBorder = mach64PaintWindow;
    pScreen->CopyWindow = mach64CopyWindow;
    pScreen->RealizeFont = mach64RealizeFont;
    pScreen->UnrealizeFont = mach64UnrealizeFont;
    pScreen->CreateGC = mach64CreateGC;
    switch (mach64InfoRec.bitsPerPixel) {
    case 8:
        if (!cfbAllocatePrivates(pScreen, &cfbWindowPrivateIndex,
            &cfbGCPrivateIndex))
            return FALSE;
        pScreen->GetImage = mach64GetImage;
        pScreen->GetSpans = cfbGetSpans;
	pScreen->CreateWindow = cfbCreateWindow;
	pScreen->DestroyWindow = cfbDestroyWindow;
	pScreen->PositionWindow = cfbPositionWindow;
	pScreen->ChangeWindowAttributes = cfbChangeWindowAttributes;
	pScreen->RealizeWindow = cfbMapWindow;
	pScreen->UnrealizeWindow = cfbUnmapWindow;
	pScreen->CreatePixmap = cfbCreatePixmap;
	pScreen->DestroyPixmap = mach64DestroyPixmap;
	/* InstallColormap, UninstallColormap, ListInstalledColormaps,
	 * StoreColors in mach64.c */
	mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
	break;
    case 16:
        if (!cfb16AllocatePrivates(pScreen, &cfbWindowPrivateIndex,
	    &cfbGCPrivateIndex))
	    return FALSE;
        pScreen->GetImage = mach64GetImage;
        pScreen->GetSpans = cfb16GetSpans;
	pScreen->CreateWindow = cfb16CreateWindow;
	pScreen->DestroyWindow = cfb16DestroyWindow;
	pScreen->PositionWindow = cfb16PositionWindow;
	pScreen->ChangeWindowAttributes = cfb16ChangeWindowAttributes;
	pScreen->RealizeWindow = cfb16MapWindow;
	pScreen->UnrealizeWindow = cfb16UnmapWindow;
	pScreen->CreatePixmap = cfb16CreatePixmap;
	pScreen->DestroyPixmap = mach64DestroyPixmap;
	/* InstallColormap, UninstallColormap, ListInstalledColormaps,
	 * StoreColors in mach64.c */
	mfbRegisterCopyPlaneProc (pScreen, cfb16CopyPlane);
	break;
    case 32:
        if (!cfb32AllocatePrivates(pScreen, &cfbWindowPrivateIndex,
	    &cfbGCPrivateIndex))
	    return FALSE;
        pScreen->GetImage = mach64GetImage;
        pScreen->GetSpans = cfb32GetSpans;
	pScreen->CreateWindow = cfb32CreateWindow;
	pScreen->DestroyWindow = cfb32DestroyWindow;
	pScreen->PositionWindow = cfb32PositionWindow;
	pScreen->ChangeWindowAttributes = cfb32ChangeWindowAttributes;
	pScreen->RealizeWindow = cfb32MapWindow;
	pScreen->UnrealizeWindow = cfb32UnmapWindow;
	pScreen->CreatePixmap = cfb32CreatePixmap;
	pScreen->DestroyPixmap = mach64DestroyPixmap;
	/* InstallColormap, UninstallColormap, ListInstalledColormaps,
	 * StoreColors in mach64.c */
	mfbRegisterCopyPlaneProc (pScreen, cfb32CopyPlane);
	break;
    default:
	FatalError("root depth %d not supported\n", mach64InfoRec.bitsPerPixel);
    }
    pScreen->CreateColormap = cfbInitializeColormap;
    pScreen->DestroyColormap = (DestroyColormapProcPtr)NoopDDA;
    pScreen->ResolveColor = cfbResolveColor;
    pScreen->BitmapToRegion = mfbPixmapToRegion;
    pScreen->BlockHandler = mach64BlockHandler; 

    if (rootdepth != 8) {
	oldDevPrivate = pScreen->devPrivate;
    }
    Rstatus = miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
			rootdepth, ndepths, depths,
			defaultVisual, nvisuals, visuals,
			&mach64BSFuncRec);

    if (rootdepth > 16) 
    {
        pScreen->CreateScreenResources = cfb32CreateScreenResources;
        pScreen->devPrivates[cfb32ScreenPrivateIndex].ptr = pScreen->devPrivate;
        pScreen->devPrivate = oldDevPrivate;
    }
    else if (rootdepth > 8) 
    {
	pScreen->CreateScreenResources = cfb16CreateScreenResources;
	pScreen->devPrivates[cfb16ScreenPrivateIndex].ptr = pScreen->devPrivate;
	pScreen->devPrivate = oldDevPrivate;
    }
    return Rstatus;
}