Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbmatrox.c @ 106:63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Fixed matrox blit bug where src Y less than dst Y
Fixed hardware surface init when no resolution change
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Fri, 13 Jul 2001 10:19:51 +0000 |
parents | 3dc008dc229d |
children | 5a9c36a45db1 |
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 | |
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 /* 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 | |
77 switch (dst->format->BytesPerPixel) { | |
78 case 1: | |
79 color |= (color<<8); | |
80 case 2: | |
81 color |= (color<<16); | |
82 break; | |
83 } | |
84 | |
85 /* 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
|
86 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 87 |
88 /* Adjust for the current rectangle */ | |
89 dstX += rect->x; | |
90 dstY += rect->y; | |
91 | |
92 /* Set up the X boundaries */ | |
93 fxbndry = (dstX | ((dstX+rect->w) << 16)); | |
94 | |
95 /* Set up the Y boundaries */ | |
96 ydstlen = (rect->h | (dstY << 16)); | |
97 | |
98 /* Set up for color fill operation */ | |
99 fillop = MGADWG_TRAP | MGADWG_SOLID | | |
100 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO; | |
101 | |
102 /* Execute the operations! */ | |
103 mga_wait(5); | |
104 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE); | |
105 mga_out32(MGAREG_FCOL, color); | |
106 mga_out32(MGAREG_FXBNDRY, fxbndry); | |
107 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
|
108 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
109 FB_AddBusySurface(dst); |
0 | 110 |
111 return(0); | |
112 } | |
113 | |
114 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
115 SDL_Surface *dst, SDL_Rect *dstrect) | |
116 { | |
117 SDL_VideoDevice *this; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
118 int pitch, w, h; |
0 | 119 int srcX, srcY; |
120 int dstX, dstY; | |
121 Uint32 sign; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
122 Uint32 start, stop; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
123 int skip; |
0 | 124 Uint32 blitop; |
125 | |
126 /* FIXME: For now, only blit to display surface */ | |
127 if ( dst->pitch != SDL_VideoSurface->pitch ) { | |
128 return(src->map->sw_blit(src, srcrect, dst, dstrect)); | |
129 } | |
130 | |
131 /* Calculate source and destination base coordinates (in pixels) */ | |
132 this = current_video; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
133 w = dstrect->w; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
134 h = dstrect->h; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
135 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
|
136 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 137 |
138 /* Adjust for the current blit rectangles */ | |
139 srcX += srcrect->x; | |
140 srcY += srcrect->y; | |
141 dstX += dstrect->x; | |
142 dstY += dstrect->y; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
143 pitch = dst->pitch/dst->format->BytesPerPixel; |
0 | 144 |
145 /* Set up the blit direction (sign) flags */ | |
146 sign = 0; | |
147 if ( srcX < dstX ) { | |
148 sign |= 1; | |
149 } | |
150 if ( srcY < dstY ) { | |
151 sign |= 4; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
152 srcY += (h - 1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
153 dstY += (h - 1); |
0 | 154 } |
155 | |
156 /* 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
|
157 stop = start = (srcY * pitch) + srcX; |
0 | 158 if ( srcX < dstX ) { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
159 start += (w - 1); |
0 | 160 } else { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
161 stop += (w - 1); |
0 | 162 } |
163 if ( srcY < dstY ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
164 skip = -pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
165 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
166 skip = pitch; |
0 | 167 } |
168 | |
169 /* Set up the blit operation */ | |
170 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
171 Uint32 colorkey; | |
172 | |
173 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
174 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) | | |
175 MGADWG_TRANSC; | |
176 | |
177 colorkey = src->format->colorkey; | |
178 switch (dst->format->BytesPerPixel) { | |
179 case 1: | |
180 colorkey |= (colorkey<<8); | |
181 case 2: | |
182 colorkey |= (colorkey<<16); | |
183 break; | |
184 } | |
185 mga_wait(2); | |
186 mga_out32(MGAREG_FCOL, colorkey); | |
187 mga_out32(MGAREG_BCOL, 0xFFFFFFFF); | |
188 } else { | |
189 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
190 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16); | |
191 } | |
192 mga_wait(7); | |
193 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
|
194 mga_out32(MGAREG_AR3, start); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
195 mga_out32(MGAREG_AR0, stop); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
196 mga_out32(MGAREG_AR5, skip); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
197 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
|
198 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h); |
0 | 199 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop); |
200 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
201 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
202 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
203 |
0 | 204 return(0); |
205 } | |
206 | |
207 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
208 { | |
209 int accelerated; | |
210 | |
211 /* Set initial acceleration on */ | |
212 src->flags |= SDL_HWACCEL; | |
213 | |
214 /* Set the surface attributes */ | |
215 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
216 if ( ! this->info.blit_hw_A ) { | |
217 src->flags &= ~SDL_HWACCEL; | |
218 } | |
219 } | |
220 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
221 if ( ! this->info.blit_hw_CC ) { | |
222 src->flags &= ~SDL_HWACCEL; | |
223 } | |
224 } | |
225 | |
226 /* Check to see if final surface blit is accelerated */ | |
227 accelerated = !!(src->flags & SDL_HWACCEL); | |
228 if ( accelerated ) { | |
229 src->map->hw_blit = HWAccelBlit; | |
230 } | |
231 return(accelerated); | |
232 } | |
233 | |
234 void FB_MatroxAccel(_THIS, __u32 card) | |
235 { | |
236 /* We have hardware accelerated surface functions */ | |
237 this->CheckHWBlit = CheckHWBlit; | |
238 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
239 wait_idle = WaitIdle; |
0 | 240 |
241 /* The Matrox has an accelerated color fill */ | |
242 this->info.blit_fill = 1; | |
243 this->FillHWRect = FillHWRect; | |
244 | |
245 /* The Matrox has accelerated normal and colorkey blits. */ | |
246 this->info.blit_hw = 1; | |
247 /* The Millenium I appears to do the colorkey test a word | |
248 at a time, and the transparency is intverted. (?) | |
249 */ | |
250 if ( card != FB_ACCEL_MATROX_MGA2064W ) { | |
251 this->info.blit_hw_CC = 1; | |
252 this->SetHWColorKey = SetHWColorKey; | |
253 } | |
254 | |
255 #if 0 /* Not yet implemented? */ | |
256 /* The Matrox G200/G400 has an accelerated alpha blit */ | |
257 if ( (card == FB_ACCEL_MATROX_MGAG200) | |
258 || (card == FB_ACCEL_MATROX_MGAG400) | |
259 ) { | |
260 this->info.blit_hw_A = 1; | |
261 this->SetHWAlpha = SetHWAlpha; | |
262 } | |
263 #endif | |
264 } |