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
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ati/atiscreen.c,v 1.31 2004/01/05 16:42:04 tsi Exp $ */
/*
* Copyright 1999 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
*
* 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 Marc Aurele La France not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Marc Aurele La France makes no representations
* about the suitability of this software for any purpose. It is provided
* "as-is" without express or implied warranty.
*
* MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL MARC AURELE LA FRANCE 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.
*/
#include "ati.h"
#include "atiaccel.h"
#include "aticonsole.h"
#include "aticursor.h"
#include "atidac.h"
#include "atidga.h"
#include "atiscreen.h"
#include "atistruct.h"
#include "atixv.h"
#include "shadowfb.h"
#include "xf86cmap.h"
#include "xf1bpp.h"
#include "xf4bpp.h"
#include "fb.h"
#include "mibank.h"
#include "micmap.h"
#include "mipointer.h"
/*
* ATIRefreshArea --
*
* This function is called by the shadow frame buffer code to refresh the
* hardware frame buffer.
*/
static void
ATIRefreshArea
(
ScrnInfoPtr pScreenInfo,
int nBox,
BoxPtr pBox
)
{
ATIPtr pATI = ATIPTR(pScreenInfo);
pointer pSrc, pDst;
int offset, w, h;
while (nBox-- > 0)
{
w = (pBox->x2 - pBox->x1) * pATI->AdjustDepth;
h = pBox->y2 - pBox->y1;
offset = (pBox->y1 * pATI->FBPitch) + (pBox->x1 * pATI->AdjustDepth);
pSrc = (char *)pATI->pShadow + offset;
pDst = (char *)pATI->pMemory + offset;
while (h-- > 0)
{
(void)memcpy(pDst, pSrc, w);
pSrc = (char *)pSrc + pATI->FBPitch;
pDst = (char *)pDst + pATI->FBPitch;
}
pBox++;
}
}
/*
* ATIScreenInit --
*
* This function is called by DIX to initialise the screen.
*/
Bool
ATIScreenInit
(
int iScreen,
ScreenPtr pScreen,
int argc,
char **argv
)
{
ScrnInfoPtr pScreenInfo = xf86Screens[iScreen];
ATIPtr pATI = ATIPTR(pScreenInfo);
pointer pFB;
int VisualMask;
/* Set video hardware state */
if (!ATIEnterGraphics(pScreen, pScreenInfo, pATI))
return FALSE;
/* Re-initialise mi's visual list */
miClearVisualTypes();
if ((pATI->depth > 8) && (pATI->DAC == ATI_DAC_INTERNAL))
VisualMask = TrueColorMask;
else
VisualMask = miGetDefaultVisualMask(pATI->depth);
if (!miSetVisualTypes(pATI->depth, VisualMask, pATI->rgbBits,
pScreenInfo->defaultVisual))
return FALSE;
if (!miSetPixmapDepths())
return FALSE;
pFB = pATI->pMemory;
pATI->FBPitch = PixmapBytePad(pATI->displayWidth, pATI->depth);
if (pATI->OptionShadowFB)
{
if ((pATI->pShadow = xalloc(pATI->FBPitch * pScreenInfo->virtualY)))
{
pFB = pATI->pShadow;
}
else
{
xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
"Insufficient virtual memory for shadow frame buffer.\n");
pATI->OptionShadowFB = FALSE;
}
}
/* Initialise framebuffer layer */
switch (pATI->bitsPerPixel)
{
#ifndef AVOID_CPIO
case 1:
pATI->Closeable = xf1bppScreenInit(pScreen, pFB,
pScreenInfo->virtualX, pScreenInfo->virtualY,
pScreenInfo->xDpi, pScreenInfo->yDpi, pATI->displayWidth);
break;
case 4:
pATI->Closeable = xf4bppScreenInit(pScreen, pFB,
pScreenInfo->virtualX, pScreenInfo->virtualY,
pScreenInfo->xDpi, pScreenInfo->yDpi, pATI->displayWidth);
break;
#endif /* AVOID_CPIO */
case 8:
case 16:
case 24:
case 32:
pATI->Closeable = fbScreenInit(pScreen, pFB,
pScreenInfo->virtualX, pScreenInfo->virtualY,
pScreenInfo->xDpi, pScreenInfo->yDpi, pATI->displayWidth,
pATI->bitsPerPixel);
break;
default:
return FALSE;
}
if (!pATI->Closeable)
return FALSE;
/* Fixup RGB ordering */
if (pATI->depth > 8)
{
VisualPtr pVisual = pScreen->visuals + pScreen->numVisuals;
while (--pVisual >= pScreen->visuals)
{
if ((pVisual->class | DynamicClass) != DirectColor)
continue;
pVisual->offsetRed = pScreenInfo->offset.red;
pVisual->offsetGreen = pScreenInfo->offset.green;
pVisual->offsetBlue = pScreenInfo->offset.blue;
pVisual->redMask = pScreenInfo->mask.red;
pVisual->greenMask = pScreenInfo->mask.green;
pVisual->blueMask = pScreenInfo->mask.blue;
}
}
/* If applicable, initialise RENDER extension */
if (pATI->bitsPerPixel > 4)
{
if (pATI->OptionShadowFB)
{
if (serverGeneration == 1)
xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
"RENDER extension not supported with a shadowed"
" framebuffer.\n");
}
#ifndef AVOID_CPIO
else if (pATI->BankInfo.BankSize)
{
if (serverGeneration == 1)
xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
"RENDER extension not supported with a banked"
" framebuffer.\n");
}
#endif /* AVOID_CPIO */
else if (!fbPictureInit(pScreen, NULL, 0) &&
(serverGeneration == 1))
{
xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
"RENDER extension initialisation failed.\n");
}
}
xf86SetBlackWhitePixels(pScreen);
#ifndef AVOID_CPIO
/* Initialise banking if needed */
if (!miInitializeBanking(pScreen,
pScreenInfo->virtualX, pScreenInfo->virtualY,
pATI->displayWidth, &pATI->BankInfo))
return FALSE;
#endif /* AVOID_CPIO */
/* Setup acceleration */
if (!ATIInitializeAcceleration(pScreen, pScreenInfo, pATI))
return FALSE;
#ifndef AVOID_DGA
/* Initialise DGA support */
(void)ATIDGAInit(pScreen, pScreenInfo, pATI);
#endif /* AVOID_DGA */
/* Initialise backing store */
miInitializeBackingStore(pScreen);
xf86SetBackingStore(pScreen);
/* Initialise cursor */
if (!ATIInitializeCursor(pScreen, pATI))
return FALSE;
/* Create default colourmap */
if (!miCreateDefColormap(pScreen))
return FALSE;
#ifdef AVOID_CPIO
if (!xf86HandleColormaps(pScreen, 256, pATI->rgbBits, ATILoadPalette, NULL,
CMAP_PALETTED_TRUECOLOR |
CMAP_LOAD_EVEN_IF_OFFSCREEN))
return FALSE;
#else /* AVOID_CPIO */
if (pATI->depth > 1)
if (!xf86HandleColormaps(pScreen, (pATI->depth == 4) ? 16 : 256,
pATI->rgbBits, ATILoadPalette, NULL,
CMAP_PALETTED_TRUECOLOR |
CMAP_LOAD_EVEN_IF_OFFSCREEN))
return FALSE;
#endif /* AVOID_CPIO */
/* Initialise shadow framebuffer */
if (pATI->OptionShadowFB &&
!ShadowFBInit(pScreen, ATIRefreshArea))
return FALSE;
/* Initialise DPMS support */
(void)xf86DPMSInit(pScreen, ATISetDPMSMode, 0);
/* Initialise XVideo support */
(void)ATIInitializeXVideo(pScreen, pScreenInfo, pATI);
/* Set pScreen->SaveScreen and wrap CloseScreen vector */
pScreen->SaveScreen = ATISaveScreen;
pATI->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = ATICloseScreen;
if (serverGeneration == 1)
xf86ShowUnusedOptions(pScreenInfo->scrnIndex, pScreenInfo->options);
return TRUE;
}
/*
* ATICloseScreen --
*
* This function is called by DIX to close the screen.
*/
Bool
ATICloseScreen
(
int iScreen,
ScreenPtr pScreen
)
{
ScrnInfoPtr pScreenInfo = xf86Screens[iScreen];
ATIPtr pATI = ATIPTR(pScreenInfo);
Bool Closed = TRUE;
ATICloseXVideo(pScreen, pScreenInfo, pATI);
if (pATI->pXAAInfo)
{
XAADestroyInfoRec(pATI->pXAAInfo);
pATI->pXAAInfo = NULL;
}
if ((pScreen->CloseScreen = pATI->CloseScreen))
{
pATI->CloseScreen = NULL;
Closed = (*pScreen->CloseScreen)(iScreen, pScreen);
}
pATI->Closeable = FALSE;
if (pATI->pCursorInfo)
{
xf86DestroyCursorInfoRec(pATI->pCursorInfo);
pATI->pCursorInfo = NULL;
}
ATILeaveGraphics(pScreenInfo, pATI);
xfree(pATI->ExpansionBitmapScanlinePtr[1]);
pATI->ExpansionBitmapScanlinePtr[0] =
pATI->ExpansionBitmapScanlinePtr[1] = NULL;
xfree(pATI->pShadow);
pATI->pShadow = NULL;
pScreenInfo->pScreen = NULL;
return Closed;
}
|