Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbmatrox.c @ 252:e8157fcb3114
Updated the source with the correct e-mail address
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Dec 2001 12:38:15 +0000 |
parents | 5a9c36a45db1 |
children | f6ffac90895c |
rev | line source |
---|---|
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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
109
diff
changeset
|
20 slouken@libsdl.org |
0 | 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 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */ | |
36 static void WaitVBL(_THIS) | |
37 { | |
38 int count; | |
39 | |
40 /* find start of retrace */ | |
41 mga_waitidle(); | |
42 while ( (mga_in8(0x1FDA) & 0x08) ) | |
43 ; | |
44 while ( !(mga_in8(0x1FDA) & 0x08) ) | |
45 ; | |
46 /* wait until we're past the start */ | |
47 count = mga_in32(0x1E20) + 2; | |
48 while ( mga_in32(0x1E20) < count ) | |
49 ; | |
50 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
51 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
52 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
53 mga_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
54 } |
0 | 55 |
56 /* Sets video mem colorkey and accelerated blit function */ | |
57 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
58 { | |
59 return(0); | |
60 } | |
61 | |
62 /* Sets per surface hardware alpha value */ | |
20 | 63 #if 0 |
0 | 64 static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value) |
65 { | |
66 return(0); | |
67 } | |
20 | 68 #endif |
0 | 69 |
70 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
71 { | |
72 int dstX, dstY; | |
73 Uint32 fxbndry; | |
74 Uint32 ydstlen; | |
75 Uint32 fillop; | |
76 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
77 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
78 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
79 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
80 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
81 |
0 | 82 switch (dst->format->BytesPerPixel) { |
83 case 1: | |
84 color |= (color<<8); | |
85 case 2: | |
86 color |= (color<<16); | |
87 break; | |
88 } | |
89 | |
90 /* Set up the X/Y base coordinates */ | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
91 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 92 |
93 /* Adjust for the current rectangle */ | |
94 dstX += rect->x; | |
95 dstY += rect->y; | |
96 | |
97 /* Set up the X boundaries */ | |
98 fxbndry = (dstX | ((dstX+rect->w) << 16)); | |
99 | |
100 /* Set up the Y boundaries */ | |
101 ydstlen = (rect->h | (dstY << 16)); | |
102 | |
103 /* Set up for color fill operation */ | |
104 fillop = MGADWG_TRAP | MGADWG_SOLID | | |
105 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO; | |
106 | |
107 /* Execute the operations! */ | |
108 mga_wait(5); | |
109 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE); | |
110 mga_out32(MGAREG_FCOL, color); | |
111 mga_out32(MGAREG_FXBNDRY, fxbndry); | |
112 mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
113 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
114 FB_AddBusySurface(dst); |
0 | 115 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
116 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
117 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
118 } |
0 | 119 return(0); |
120 } | |
121 | |
122 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
123 SDL_Surface *dst, SDL_Rect *dstrect) | |
124 { | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
125 SDL_VideoDevice *this = current_video; |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
126 int pitch, w, h; |
0 | 127 int srcX, srcY; |
128 int dstX, dstY; | |
129 Uint32 sign; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
130 Uint32 start, stop; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
131 int skip; |
0 | 132 Uint32 blitop; |
133 | |
134 /* FIXME: For now, only blit to display surface */ | |
135 if ( dst->pitch != SDL_VideoSurface->pitch ) { | |
136 return(src->map->sw_blit(src, srcrect, dst, dstrect)); | |
137 } | |
138 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
139 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
140 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
141 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
142 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
143 |
0 | 144 /* Calculate source and destination base coordinates (in pixels) */ |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
145 w = dstrect->w; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
146 h = dstrect->h; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
147 FB_dst_to_xy(this, src, &srcX, &srcY); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
148 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 149 |
150 /* Adjust for the current blit rectangles */ | |
151 srcX += srcrect->x; | |
152 srcY += srcrect->y; | |
153 dstX += dstrect->x; | |
154 dstY += dstrect->y; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
155 pitch = dst->pitch/dst->format->BytesPerPixel; |
0 | 156 |
157 /* Set up the blit direction (sign) flags */ | |
158 sign = 0; | |
159 if ( srcX < dstX ) { | |
160 sign |= 1; | |
161 } | |
162 if ( srcY < dstY ) { | |
163 sign |= 4; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
164 srcY += (h - 1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
165 dstY += (h - 1); |
0 | 166 } |
167 | |
168 /* Set up the blit source row start, end, and skip (in pixels) */ | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
169 stop = start = (srcY * pitch) + srcX; |
0 | 170 if ( srcX < dstX ) { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
171 start += (w - 1); |
0 | 172 } else { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
173 stop += (w - 1); |
0 | 174 } |
175 if ( srcY < dstY ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
176 skip = -pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
177 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
178 skip = pitch; |
0 | 179 } |
180 | |
181 /* Set up the blit operation */ | |
182 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
183 Uint32 colorkey; | |
184 | |
185 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
186 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) | | |
187 MGADWG_TRANSC; | |
188 | |
189 colorkey = src->format->colorkey; | |
190 switch (dst->format->BytesPerPixel) { | |
191 case 1: | |
192 colorkey |= (colorkey<<8); | |
193 case 2: | |
194 colorkey |= (colorkey<<16); | |
195 break; | |
196 } | |
197 mga_wait(2); | |
198 mga_out32(MGAREG_FCOL, colorkey); | |
199 mga_out32(MGAREG_BCOL, 0xFFFFFFFF); | |
200 } else { | |
201 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
202 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16); | |
203 } | |
204 mga_wait(7); | |
205 mga_out32(MGAREG_SGN, sign); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
206 mga_out32(MGAREG_AR3, start); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
207 mga_out32(MGAREG_AR0, stop); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
208 mga_out32(MGAREG_AR5, skip); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
209 mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + w-1) << 16))); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
210 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h); |
0 | 211 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop); |
212 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
213 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
214 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
215 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
216 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
217 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
218 } |
0 | 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 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
254 wait_idle = WaitIdle; |
0 | 255 |
256 /* The Matrox has an accelerated color fill */ | |
257 this->info.blit_fill = 1; | |
258 this->FillHWRect = FillHWRect; | |
259 | |
260 /* The Matrox has accelerated normal and colorkey blits. */ | |
261 this->info.blit_hw = 1; | |
262 /* The Millenium I appears to do the colorkey test a word | |
263 at a time, and the transparency is intverted. (?) | |
264 */ | |
265 if ( card != FB_ACCEL_MATROX_MGA2064W ) { | |
266 this->info.blit_hw_CC = 1; | |
267 this->SetHWColorKey = SetHWColorKey; | |
268 } | |
269 | |
270 #if 0 /* Not yet implemented? */ | |
271 /* The Matrox G200/G400 has an accelerated alpha blit */ | |
272 if ( (card == FB_ACCEL_MATROX_MGAG200) | |
273 || (card == FB_ACCEL_MATROX_MGAG400) | |
274 ) { | |
275 this->info.blit_hw_A = 1; | |
276 this->SetHWAlpha = SetHWAlpha; | |
277 } | |
278 #endif | |
279 } |