0
|
1 /*
|
|
2 SDL - Simple DirectMedia Layer
|
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
|
4
|
|
5 This library is free software; you can redistribute it and/or
|
|
6 modify it under the terms of the GNU Library General Public
|
|
7 License as published by the Free Software Foundation; either
|
|
8 version 2 of the License, or (at your option) any later version.
|
|
9
|
|
10 This library is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 Library General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Library General Public
|
|
16 License along with this library; if not, write to the Free
|
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
|
19 Sam Lantinga
|
|
20 slouken@devolution.com
|
|
21 */
|
|
22
|
|
23 #ifdef SAVE_RCSID
|
|
24 static char rcsid =
|
|
25 "@(#) $Id$";
|
|
26 #endif
|
|
27
|
|
28 #include "SDL_types.h"
|
|
29 #include "SDL_video.h"
|
|
30 #include "SDL_blit.h"
|
|
31 #include "SDL_fbmatrox.h"
|
|
32 #include "matrox_mmio.h"
|
|
33
|
|
34
|
|
35 static int LockHWSurface(_THIS, SDL_Surface *surface)
|
|
36 {
|
|
37 if ( surface == SDL_VideoSurface ) {
|
|
38 mga_waitidle();
|
|
39 }
|
|
40 return(0);
|
|
41 }
|
|
42 static void UnlockHWSurface(_THIS, SDL_Surface *surface)
|
|
43 {
|
|
44 return;
|
|
45 }
|
|
46
|
|
47 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */
|
|
48 static void WaitVBL(_THIS)
|
|
49 {
|
|
50 int count;
|
|
51
|
|
52 /* find start of retrace */
|
|
53 mga_waitidle();
|
|
54 while ( (mga_in8(0x1FDA) & 0x08) )
|
|
55 ;
|
|
56 while ( !(mga_in8(0x1FDA) & 0x08) )
|
|
57 ;
|
|
58 /* wait until we're past the start */
|
|
59 count = mga_in32(0x1E20) + 2;
|
|
60 while ( mga_in32(0x1E20) < count )
|
|
61 ;
|
|
62 }
|
|
63
|
|
64 /* Sets video mem colorkey and accelerated blit function */
|
|
65 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
|
|
66 {
|
|
67 return(0);
|
|
68 }
|
|
69
|
|
70 /* Sets per surface hardware alpha value */
|
20
|
71 #if 0
|
0
|
72 static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value)
|
|
73 {
|
|
74 return(0);
|
|
75 }
|
20
|
76 #endif
|
0
|
77
|
|
78 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
|
|
79 {
|
|
80 int dstX, dstY;
|
|
81 Uint32 fxbndry;
|
|
82 Uint32 ydstlen;
|
|
83 Uint32 fillop;
|
|
84
|
|
85 switch (dst->format->BytesPerPixel) {
|
|
86 case 1:
|
|
87 color |= (color<<8);
|
|
88 case 2:
|
|
89 color |= (color<<16);
|
|
90 break;
|
|
91 }
|
|
92
|
|
93 /* Set up the X/Y base coordinates */
|
|
94 dstX = 0;
|
|
95 dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch;
|
|
96
|
|
97 /* Adjust for the current rectangle */
|
|
98 dstX += rect->x;
|
|
99 dstY += rect->y;
|
|
100
|
|
101 /* Set up the X boundaries */
|
|
102 fxbndry = (dstX | ((dstX+rect->w) << 16));
|
|
103
|
|
104 /* Set up the Y boundaries */
|
|
105 ydstlen = (rect->h | (dstY << 16));
|
|
106
|
|
107 #if 0 /* This old way doesn't work on the Matrox G450 */
|
|
108 /* Set up for color fill operation */
|
|
109 fillop = MGADWG_TRAP | MGADWG_SOLID |
|
|
110 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO |
|
|
111 MGADWG_BFCOL | MGADWG_BLK;
|
|
112
|
|
113 /* Execute the operations! */
|
|
114 mga_wait(4);
|
|
115 mga_out32(MGAREG_FCOL, color);
|
|
116 mga_out32(MGAREG_FXBNDRY, fxbndry);
|
|
117 mga_out32(MGAREG_YDSTLEN, ydstlen);
|
|
118 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, fillop);
|
|
119 #else
|
|
120 /* Set up for color fill operation */
|
|
121 fillop = MGADWG_TRAP | MGADWG_SOLID |
|
|
122 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO;
|
|
123
|
|
124 /* Execute the operations! */
|
|
125 mga_wait(5);
|
|
126 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE);
|
|
127 mga_out32(MGAREG_FCOL, color);
|
|
128 mga_out32(MGAREG_FXBNDRY, fxbndry);
|
|
129 mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen);
|
|
130 #endif
|
|
131
|
|
132 return(0);
|
|
133 }
|
|
134
|
|
135 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
|
|
136 SDL_Surface *dst, SDL_Rect *dstrect)
|
|
137 {
|
|
138 SDL_VideoDevice *this;
|
|
139 int bpp;
|
|
140 int srcX, srcY;
|
|
141 int dstX, dstY;
|
|
142 Uint32 sign;
|
|
143 Uint32 sstart, sstop;
|
|
144 int sskip;
|
|
145 Uint32 blitop;
|
|
146
|
|
147 /* FIXME: For now, only blit to display surface */
|
|
148 if ( dst->pitch != SDL_VideoSurface->pitch ) {
|
|
149 return(src->map->sw_blit(src, srcrect, dst, dstrect));
|
|
150 }
|
|
151
|
|
152 /* Calculate source and destination base coordinates (in pixels) */
|
|
153 this = current_video;
|
|
154 srcX= 0; /* FIXME: Calculate this from memory offset */
|
|
155 srcY = ((char *)src->pixels - mapped_mem) / SDL_VideoSurface->pitch;
|
|
156 dstX = 0; /* FIXME: Calculate this from memory offset */
|
|
157 dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch;
|
|
158
|
|
159 /* Adjust for the current blit rectangles */
|
|
160 srcX += srcrect->x;
|
|
161 srcY += srcrect->y;
|
|
162 dstX += dstrect->x;
|
|
163 dstY += dstrect->y;
|
|
164
|
|
165 /* Set up the blit direction (sign) flags */
|
|
166 sign = 0;
|
|
167 if ( srcX < dstX ) {
|
|
168 sign |= 1;
|
|
169 }
|
|
170 if ( srcY < dstY ) {
|
|
171 sign |= 4;
|
|
172 }
|
|
173
|
|
174 /* Set up the blit source row start, end, and skip (in pixels) */
|
|
175 bpp = src->format->BytesPerPixel;
|
|
176 sstop = sstart = ((srcY * SDL_VideoSurface->pitch)/bpp) + srcX;
|
|
177 if ( srcX < dstX ) {
|
|
178 sstart += (dstrect->w - 1);
|
|
179 } else {
|
|
180 sstop += (dstrect->w - 1);
|
|
181 }
|
|
182 sskip = src->pitch/bpp;
|
|
183 if ( srcY < dstY ) {
|
|
184 sskip = -sskip;
|
|
185 }
|
|
186
|
|
187 /* Set up the blit operation */
|
|
188 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
|
|
189 Uint32 colorkey;
|
|
190
|
|
191 blitop = MGADWG_BFCOL | MGADWG_BITBLT |
|
|
192 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) |
|
|
193 MGADWG_TRANSC;
|
|
194
|
|
195 colorkey = src->format->colorkey;
|
|
196 switch (dst->format->BytesPerPixel) {
|
|
197 case 1:
|
|
198 colorkey |= (colorkey<<8);
|
|
199 case 2:
|
|
200 colorkey |= (colorkey<<16);
|
|
201 break;
|
|
202 }
|
|
203 mga_wait(2);
|
|
204 mga_out32(MGAREG_FCOL, colorkey);
|
|
205 mga_out32(MGAREG_BCOL, 0xFFFFFFFF);
|
|
206 } else {
|
|
207 blitop = MGADWG_BFCOL | MGADWG_BITBLT |
|
|
208 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16);
|
|
209 }
|
|
210 mga_wait(7);
|
|
211 mga_out32(MGAREG_SGN, sign);
|
|
212 mga_out32(MGAREG_AR3, sstart);
|
|
213 mga_out32(MGAREG_AR0, sstop);
|
|
214 mga_out32(MGAREG_AR5, sskip);
|
|
215 mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + dstrect->w-1) << 16)));
|
|
216 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | dstrect->h);
|
|
217 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop);
|
|
218
|
|
219 return(0);
|
|
220 }
|
|
221
|
|
222 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
|
|
223 {
|
|
224 int accelerated;
|
|
225
|
|
226 /* Set initial acceleration on */
|
|
227 src->flags |= SDL_HWACCEL;
|
|
228
|
|
229 /* Set the surface attributes */
|
|
230 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
|
|
231 if ( ! this->info.blit_hw_A ) {
|
|
232 src->flags &= ~SDL_HWACCEL;
|
|
233 }
|
|
234 }
|
|
235 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
|
|
236 if ( ! this->info.blit_hw_CC ) {
|
|
237 src->flags &= ~SDL_HWACCEL;
|
|
238 }
|
|
239 }
|
|
240
|
|
241 /* Check to see if final surface blit is accelerated */
|
|
242 accelerated = !!(src->flags & SDL_HWACCEL);
|
|
243 if ( accelerated ) {
|
|
244 src->map->hw_blit = HWAccelBlit;
|
|
245 }
|
|
246 return(accelerated);
|
|
247 }
|
|
248
|
|
249 void FB_MatroxAccel(_THIS, __u32 card)
|
|
250 {
|
|
251 /* We have hardware accelerated surface functions */
|
|
252 this->CheckHWBlit = CheckHWBlit;
|
|
253 this->LockHWSurface = LockHWSurface;
|
|
254 this->UnlockHWSurface = UnlockHWSurface;
|
|
255 wait_vbl = WaitVBL;
|
|
256
|
|
257 /* The Matrox has an accelerated color fill */
|
|
258 this->info.blit_fill = 1;
|
|
259 this->FillHWRect = FillHWRect;
|
|
260
|
|
261 /* The Matrox has accelerated normal and colorkey blits. */
|
|
262 this->info.blit_hw = 1;
|
|
263 /* The Millenium I appears to do the colorkey test a word
|
|
264 at a time, and the transparency is intverted. (?)
|
|
265 */
|
|
266 if ( card != FB_ACCEL_MATROX_MGA2064W ) {
|
|
267 this->info.blit_hw_CC = 1;
|
|
268 this->SetHWColorKey = SetHWColorKey;
|
|
269 }
|
|
270
|
|
271 #if 0 /* Not yet implemented? */
|
|
272 /* The Matrox G200/G400 has an accelerated alpha blit */
|
|
273 if ( (card == FB_ACCEL_MATROX_MGAG200)
|
|
274 || (card == FB_ACCEL_MATROX_MGAG400)
|
|
275 ) {
|
|
276 this->info.blit_hw_A = 1;
|
|
277 this->SetHWAlpha = SetHWAlpha;
|
|
278 }
|
|
279 #endif
|
|
280 }
|