Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbmatrox.c @ 1400:5abff0870de2
Date: Mon, 20 Feb 2006 19:54:51 -0500
From: Brian Barnes
Subject: [SDL] Fix for FSAA OS X bug -- Please fix in CVS Code
I stopped complaining and went in an fixed the bug myself :) SDL
always dies if you try to use FSAA on Mac OS X, the problem is in the
file:
SDL_QuartzGL.m
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 02:42:05 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
0 | 22 |
23 #include "SDL_video.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
24 #include "../SDL_blit.h" |
0 | 25 #include "SDL_fbmatrox.h" |
26 #include "matrox_mmio.h" | |
27 | |
28 | |
29 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */ | |
30 static void WaitVBL(_THIS) | |
31 { | |
32 int count; | |
33 | |
34 /* find start of retrace */ | |
35 mga_waitidle(); | |
36 while ( (mga_in8(0x1FDA) & 0x08) ) | |
37 ; | |
38 while ( !(mga_in8(0x1FDA) & 0x08) ) | |
39 ; | |
40 /* wait until we're past the start */ | |
41 count = mga_in32(0x1E20) + 2; | |
42 while ( mga_in32(0x1E20) < count ) | |
43 ; | |
44 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
45 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
46 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
47 mga_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
48 } |
0 | 49 |
50 /* Sets video mem colorkey and accelerated blit function */ | |
51 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
52 { | |
53 return(0); | |
54 } | |
55 | |
56 /* Sets per surface hardware alpha value */ | |
20 | 57 #if 0 |
0 | 58 static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value) |
59 { | |
60 return(0); | |
61 } | |
20 | 62 #endif |
0 | 63 |
64 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
65 { | |
66 int dstX, dstY; | |
67 Uint32 fxbndry; | |
68 Uint32 ydstlen; | |
69 Uint32 fillop; | |
70 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
71 /* 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
|
72 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
73 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
74 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
75 |
0 | 76 switch (dst->format->BytesPerPixel) { |
77 case 1: | |
78 color |= (color<<8); | |
79 case 2: | |
80 color |= (color<<16); | |
81 break; | |
82 } | |
83 | |
84 /* 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
|
85 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 86 |
87 /* Adjust for the current rectangle */ | |
88 dstX += rect->x; | |
89 dstY += rect->y; | |
90 | |
91 /* Set up the X boundaries */ | |
92 fxbndry = (dstX | ((dstX+rect->w) << 16)); | |
93 | |
94 /* Set up the Y boundaries */ | |
95 ydstlen = (rect->h | (dstY << 16)); | |
96 | |
97 /* Set up for color fill operation */ | |
98 fillop = MGADWG_TRAP | MGADWG_SOLID | | |
99 MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO; | |
100 | |
101 /* Execute the operations! */ | |
102 mga_wait(5); | |
103 mga_out32(MGAREG_DWGCTL, fillop | MGADWG_REPLACE); | |
104 mga_out32(MGAREG_FCOL, color); | |
105 mga_out32(MGAREG_FXBNDRY, fxbndry); | |
106 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
|
107 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
108 FB_AddBusySurface(dst); |
0 | 109 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
110 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
111 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
112 } |
0 | 113 return(0); |
114 } | |
115 | |
116 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
117 SDL_Surface *dst, SDL_Rect *dstrect) | |
118 { | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
119 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
|
120 int pitch, w, h; |
0 | 121 int srcX, srcY; |
122 int dstX, dstY; | |
123 Uint32 sign; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
124 Uint32 start, stop; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
125 int skip; |
0 | 126 Uint32 blitop; |
127 | |
128 /* FIXME: For now, only blit to display surface */ | |
129 if ( dst->pitch != SDL_VideoSurface->pitch ) { | |
130 return(src->map->sw_blit(src, srcrect, dst, dstrect)); | |
131 } | |
132 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
133 /* 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
|
134 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
135 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
136 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
137 |
0 | 138 /* 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
|
139 w = dstrect->w; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
140 h = dstrect->h; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
141 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
|
142 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 143 |
144 /* Adjust for the current blit rectangles */ | |
145 srcX += srcrect->x; | |
146 srcY += srcrect->y; | |
147 dstX += dstrect->x; | |
148 dstY += dstrect->y; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
149 pitch = dst->pitch/dst->format->BytesPerPixel; |
0 | 150 |
151 /* Set up the blit direction (sign) flags */ | |
152 sign = 0; | |
153 if ( srcX < dstX ) { | |
154 sign |= 1; | |
155 } | |
156 if ( srcY < dstY ) { | |
157 sign |= 4; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
158 srcY += (h - 1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
159 dstY += (h - 1); |
0 | 160 } |
161 | |
162 /* 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
|
163 stop = start = (srcY * pitch) + srcX; |
0 | 164 if ( srcX < dstX ) { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
165 start += (w - 1); |
0 | 166 } else { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
167 stop += (w - 1); |
0 | 168 } |
169 if ( srcY < dstY ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
170 skip = -pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
171 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
172 skip = pitch; |
0 | 173 } |
174 | |
175 /* Set up the blit operation */ | |
176 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
177 Uint32 colorkey; | |
178 | |
179 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
180 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) | | |
181 MGADWG_TRANSC; | |
182 | |
183 colorkey = src->format->colorkey; | |
184 switch (dst->format->BytesPerPixel) { | |
185 case 1: | |
186 colorkey |= (colorkey<<8); | |
187 case 2: | |
188 colorkey |= (colorkey<<16); | |
189 break; | |
190 } | |
191 mga_wait(2); | |
192 mga_out32(MGAREG_FCOL, colorkey); | |
193 mga_out32(MGAREG_BCOL, 0xFFFFFFFF); | |
194 } else { | |
195 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
196 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16); | |
197 } | |
198 mga_wait(7); | |
199 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
|
200 mga_out32(MGAREG_AR3, start); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
201 mga_out32(MGAREG_AR0, stop); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
202 mga_out32(MGAREG_AR5, skip); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
203 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
|
204 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h); |
0 | 205 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop); |
206 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
207 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
208 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
209 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
210 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
211 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
212 } |
0 | 213 return(0); |
214 } | |
215 | |
216 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
217 { | |
218 int accelerated; | |
219 | |
220 /* Set initial acceleration on */ | |
221 src->flags |= SDL_HWACCEL; | |
222 | |
223 /* Set the surface attributes */ | |
224 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
225 if ( ! this->info.blit_hw_A ) { | |
226 src->flags &= ~SDL_HWACCEL; | |
227 } | |
228 } | |
229 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
230 if ( ! this->info.blit_hw_CC ) { | |
231 src->flags &= ~SDL_HWACCEL; | |
232 } | |
233 } | |
234 | |
235 /* Check to see if final surface blit is accelerated */ | |
236 accelerated = !!(src->flags & SDL_HWACCEL); | |
237 if ( accelerated ) { | |
238 src->map->hw_blit = HWAccelBlit; | |
239 } | |
240 return(accelerated); | |
241 } | |
242 | |
243 void FB_MatroxAccel(_THIS, __u32 card) | |
244 { | |
245 /* We have hardware accelerated surface functions */ | |
246 this->CheckHWBlit = CheckHWBlit; | |
247 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
248 wait_idle = WaitIdle; |
0 | 249 |
250 /* The Matrox has an accelerated color fill */ | |
251 this->info.blit_fill = 1; | |
252 this->FillHWRect = FillHWRect; | |
253 | |
254 /* The Matrox has accelerated normal and colorkey blits. */ | |
255 this->info.blit_hw = 1; | |
256 /* The Millenium I appears to do the colorkey test a word | |
257 at a time, and the transparency is intverted. (?) | |
258 */ | |
259 if ( card != FB_ACCEL_MATROX_MGA2064W ) { | |
260 this->info.blit_hw_CC = 1; | |
261 this->SetHWColorKey = SetHWColorKey; | |
262 } | |
263 | |
264 #if 0 /* Not yet implemented? */ | |
265 /* The Matrox G200/G400 has an accelerated alpha blit */ | |
266 if ( (card == FB_ACCEL_MATROX_MGAG200) | |
267 || (card == FB_ACCEL_MATROX_MGAG400) | |
268 ) { | |
269 this->info.blit_hw_A = 1; | |
270 this->SetHWAlpha = SetHWAlpha; | |
271 } | |
272 #endif | |
273 } |