summaryrefslogtreecommitdiff
path: root/src/s3_dga.c
blob: a8e6560a63eeb747d56a429d05471881a3e0038b (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
/*
 *      Copyright 2001  Ani Joshi <ajoshi@unixbox.com>
 * 
 *      XFree86 4.x driver for S3 chipsets
 * 
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation and
 * that the name of Ani Joshi not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  Ani Joshi makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as-is" without express or implied warranty.
 *                 
 * ANI JOSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL ANI JOSHI 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.
 *
 *
 */
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/s3/s3_dga.c,v 1.1 2001/07/02 10:46:04 alanh Exp $ */

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"

#include "dgaproc.h"

#include "s3.h"
#include "s3_reg.h"


static Bool S3_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode);
static int S3_GetViewport(ScrnInfoPtr pScrn);
static void S3_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags);
static void S3_FillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h,
		        unsigned long color);
static void S3_BltRect(ScrnInfoPtr pScrn, int srcx, int srcy, int w, int h,
		       int dstx, int dsty);
static Bool S3_OpenFramebuffer(ScrnInfoPtr pScrn, char **name,
			       unsigned char **mem, int *size, int *offset,
			       int *flags);
static void S3_Sync(ScrnInfoPtr pScrn);


static DGAFunctionRec S3_DGAFuncs = {
	S3_OpenFramebuffer,
	NULL,
	S3_SetMode,
	S3_SetViewport,
	S3_GetViewport,
	S3_Sync,
	S3_FillRect,
	S3_BltRect,
	NULL
};


static DGAModePtr S3SetupDGAMode(ScrnInfoPtr pScrn, DGAModePtr modes,
				 int *num, int bitsPerPixel, int depth,
				 Bool pixmap, int secondPitch,
				 unsigned long red, unsigned long green,
				 unsigned long blue, short visualClass)
{
	S3Ptr pS3 = S3PTR(pScrn);
	DGAModePtr newmodes = NULL, currentMode;
	DisplayModePtr pMode, firstMode;
	int otherPitch, Bpp = bitsPerPixel >> 3;
	Bool oneMore;

	pMode = firstMode = pScrn->modes;

	while (pMode) {
		otherPitch = secondPitch ? secondPitch : pMode->HDisplay;

		if (pMode->HDisplay != otherPitch) {
			newmodes = xrealloc(modes, (*num + 2) * sizeof(DGAModeRec));
			oneMore = TRUE;
		} else {
			newmodes = xrealloc(modes, (*num + 1) * sizeof(DGAModeRec));
			oneMore = FALSE;
		}

		if (!newmodes) {
			xfree(modes);
			return NULL;
		}

		modes = newmodes;

SECOND_PASS:

		currentMode = modes + *num;
		(*num)++;

		currentMode->mode = pMode;
		currentMode->flags = DGA_CONCURRENT_ACCESS;
		if (pixmap)
			currentMode->flags |= DGA_PIXMAP_AVAILABLE;
		if (pS3->pXAA)
			currentMode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT;
		if (pMode->Flags & V_DBLSCAN)
			currentMode->flags |= DGA_DOUBLESCAN;
		if (pMode->Flags & V_INTERLACE)
			currentMode->flags |= DGA_INTERLACED;
		currentMode->byteOrder = pScrn->imageByteOrder;
		currentMode->depth = depth;
		currentMode->bitsPerPixel = bitsPerPixel;
		currentMode->red_mask = red;
		currentMode->green_mask = green;
		currentMode->blue_mask = blue;
		currentMode->visualClass = visualClass;
		currentMode->viewportWidth = pMode->HDisplay;
		currentMode->viewportHeight = pMode->VDisplay;
		currentMode->xViewportStep = 8;
		currentMode->yViewportStep = 1;
		currentMode->viewportFlags = DGA_FLIP_RETRACE;
		currentMode->offset = 0;
		currentMode->address = (unsigned char*)pS3->FBAddress;

		if (oneMore) {
			currentMode->bytesPerScanline = (((pMode->HDisplay * Bpp) + 3) & ~3L);

			currentMode->imageWidth = pMode->HDisplay;
			currentMode->imageHeight = pMode->VDisplay;
			currentMode->pixmapWidth = currentMode->imageWidth;
			currentMode->pixmapHeight = currentMode->imageHeight;
			currentMode->maxViewportX = currentMode->imageWidth -
						    currentMode->viewportWidth;
			currentMode->maxViewportY = currentMode->imageHeight -
						    currentMode->viewportHeight;

			oneMore = FALSE;
			goto SECOND_PASS;
		} else {
			currentMode->bytesPerScanline = (((otherPitch * Bpp) + 3) & ~3L);

			currentMode->imageWidth = otherPitch;
			currentMode->imageHeight = pMode->VDisplay;
			currentMode->pixmapWidth = currentMode->imageWidth;
			currentMode->pixmapHeight = currentMode->imageHeight;
			currentMode->maxViewportX = currentMode->imageWidth -
						    currentMode->viewportWidth;
			currentMode->maxViewportY = currentMode->imageHeight -
						    currentMode->viewportHeight;
			
		}

		pMode = pMode->next;

		if (pMode == firstMode)
			break;

	}

	return modes;
}



Bool S3DGAInit(ScreenPtr pScreen)
{
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
	S3Ptr pS3 = S3PTR(pScrn);
	DGAModePtr modes = NULL;
	int num = 0;

	modes = S3SetupDGAMode(pScrn, modes, &num, 8, 8,
			       (pScrn->bitsPerPixel == 8),
			       ((pScrn->bitsPerPixel != 8) ? 0 : pScrn->displayWidth),
			       0, 0, 0, PseudoColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 16, 15,
			       (pScrn->bitsPerPixel == 16),
			       ((pScrn->depth != 15)
			       ? 0 : pScrn->displayWidth),
			       0x7c00, 0x03e0, 0x001f, TrueColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 16, 15,
			       (pScrn->bitsPerPixel == 16),
			       ((pScrn->depth != 15)
			       ? 0 : pScrn->displayWidth),
			       0x7c00, 0x03e0, 0x001f, DirectColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 16, 16,
			       (pScrn->bitsPerPixel == 16),
			       ((pScrn->depth != 16)
			       ? 0 : pScrn->displayWidth),
			       0xf800, 0x07e0, 0x001f, TrueColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 16, 16,
			       (pScrn->bitsPerPixel == 16),
			       ((pScrn->depth != 16)
			       ? 0 : pScrn->displayWidth),
			       0xf800, 0x07e0, 0x001f, DirectColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 32, 24,
			       (pScrn->bitsPerPixel == 32),
			       ((pScrn->bitsPerPixel != 32)
			       ? 0 : pScrn->displayWidth),
			       0xff0000, 0x00ff00, 0x0000ff, TrueColor);

	modes = S3SetupDGAMode(pScrn, modes, &num, 32, 24,
			       (pScrn->bitsPerPixel == 32),
			       ((pScrn->bitsPerPixel != 32)
			       ? 0 : pScrn->displayWidth),
			       0xff0000, 0x00ff00, 0x0000ff, DirectColor);

	pS3->numDGAModes = num;
	pS3->DGAModes = modes;

	return DGAInit(pScreen, &S3_DGAFuncs, modes, num);
}


static Bool S3_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
{
	S3Ptr pS3 = S3PTR(pScrn);
	static S3FBLayout SavedLayouts[MAXSCREENS];
	int indx = pScrn->pScreen->myNum;

	if (!pMode) {
		if (pS3->DGAactive) {
			memcpy(&pS3->CurrentLayout, &SavedLayouts[indx],
			       sizeof(S3FBLayout));
			pS3->DGAactive = TRUE;
		}

		pS3->CurrentLayout.bitsPerPixel = pMode->bitsPerPixel;
		pS3->CurrentLayout.depth = pMode->depth;
		pS3->CurrentLayout.displayWidth = (pMode->bytesPerScanline /
						   (pMode->bitsPerPixel >> 3));
		pS3->CurrentLayout.pixel_bytes = pMode->bitsPerPixel / 8;
		pS3->CurrentLayout.pixel_code = (pMode->bitsPerPixel != 16 ?
						 pMode->bitsPerPixel :
						 pMode->depth);

		S3SwitchMode(indx, pMode->mode, 0);
	}

	return TRUE;
}


static int S3_GetViewport(ScrnInfoPtr pScrn)
{
	S3Ptr pS3 = S3PTR(pScrn);

	return pS3->DGAViewportStatus;
}


static void S3_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
{
	S3Ptr pS3 = S3PTR(pScrn);

	pScrn->AdjustFrame(pScrn->pScreen->myNum, x, y, flags);
	pS3->DGAViewportStatus = 0;
}


static void S3_FillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h,
		        unsigned long color)
{
	S3Ptr pS3 = S3PTR(pScrn);

	if (pS3->pXAA) {
		(*pS3->pXAA->SetupForSolidFill)(pScrn, color, GXcopy, (CARD32)(~0));
		(*pS3->pXAA->SubsequentSolidFillRect)(pScrn, x, y, w, h);
		SET_SYNC_FLAG(pS3->pXAA);
	}
}


static void S3_BltRect(ScrnInfoPtr pScrn, int srcx, int srcy, int w, int h,
		       int dstx, int dsty)
{
	S3Ptr pS3 = S3PTR(pScrn);

	if (pS3->pXAA) {
		int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1;
		int ydir = (srcy < dsty) ? -1 : 1;

		(*pS3->pXAA->SetupForScreenToScreenCopy)(pScrn, xdir, ydir,
							 GXcopy, (CARD32)(~0), -1);
		(*pS3->pXAA->SubsequentScreenToScreenCopy)(pScrn, srcx, srcy,
							   dstx, dsty, w, h);
		SET_SYNC_FLAG(pS3->pXAA);
	}
}


static Bool S3_OpenFramebuffer(ScrnInfoPtr pScrn, char **name,
			       unsigned char **mem, int *size, int *offset,
			       int *flags)
{
	S3Ptr pS3 = S3PTR(pScrn);

	*name = NULL;
	*mem = (unsigned char*)pS3->FBAddress;
	*size = (pScrn->videoRam * 1024);
	*offset = 0;
	*flags = 0;

	return TRUE;
}


static void S3_Sync(ScrnInfoPtr pScrn)
{
	WaitIdle();
}