Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbmatrox.c @ 1348:40d0975c1769
Date: Mon, 6 Feb 2006 11:41:04 -0500
From: "mystml@adinet.com.uy"
Subject: [SDL] ALT-F4 using DirectX
My game isn't getting SDL_QUIT when I press ALT-F4 using the DirectX
driver; it does get SDL_QUIT when I press the red X in the window.
I tracked this down to DX5_HandleMessage() in SDL_dx5events.c;
WM_SYSKEYDOWN is being trapped and ignored which causes Windows not to post
a WM_CLOSE, hence no SDL_QUIT is being generated.
The relevant code is this :
/* The keyboard is handled via DirectInput */
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_KEYDOWN: {
/* Ignore windows keyboard messages */;
}
return(0);
If I comment the WM_SYSKEYDOWN case, it falls through DefWindowProc() and
ALT-F4 starts working again.
I'm not sure about the best way to fix this. One option is handling ALT-F4
as a particular case somehow, but doesn't sound good. Another option would
be to handle WM_SYSKEYDOWN separately and breaking instead of returning 0,
so processing falls through and goes to DefWindowProc which does The Right
Thing (TM). This seems to be the minimal change that makes ALT-F4 work and
normal keyboard input continues to work.
Does this sound reasonable? Am I overlooking anything? Do I submit a patch?
--Gabriel
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 08 Feb 2006 17:19:43 +0000 |
parents | c9b51268668f |
children | c71e05b4dc2e |
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_types.h" | |
24 #include "SDL_video.h" | |
25 #include "SDL_blit.h" | |
26 #include "SDL_fbmatrox.h" | |
27 #include "matrox_mmio.h" | |
28 | |
29 | |
30 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */ | |
31 static void WaitVBL(_THIS) | |
32 { | |
33 int count; | |
34 | |
35 /* find start of retrace */ | |
36 mga_waitidle(); | |
37 while ( (mga_in8(0x1FDA) & 0x08) ) | |
38 ; | |
39 while ( !(mga_in8(0x1FDA) & 0x08) ) | |
40 ; | |
41 /* wait until we're past the start */ | |
42 count = mga_in32(0x1E20) + 2; | |
43 while ( mga_in32(0x1E20) < count ) | |
44 ; | |
45 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
46 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
47 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
48 mga_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
49 } |
0 | 50 |
51 /* Sets video mem colorkey and accelerated blit function */ | |
52 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
53 { | |
54 return(0); | |
55 } | |
56 | |
57 /* Sets per surface hardware alpha value */ | |
20 | 58 #if 0 |
0 | 59 static int SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value) |
60 { | |
61 return(0); | |
62 } | |
20 | 63 #endif |
0 | 64 |
65 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
66 { | |
67 int dstX, dstY; | |
68 Uint32 fxbndry; | |
69 Uint32 ydstlen; | |
70 Uint32 fillop; | |
71 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
72 /* 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
|
73 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
74 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
75 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
76 |
0 | 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 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
111 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
112 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
113 } |
0 | 114 return(0); |
115 } | |
116 | |
117 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
118 SDL_Surface *dst, SDL_Rect *dstrect) | |
119 { | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
120 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
|
121 int pitch, w, h; |
0 | 122 int srcX, srcY; |
123 int dstX, dstY; | |
124 Uint32 sign; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
125 Uint32 start, stop; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
126 int skip; |
0 | 127 Uint32 blitop; |
128 | |
129 /* FIXME: For now, only blit to display surface */ | |
130 if ( dst->pitch != SDL_VideoSurface->pitch ) { | |
131 return(src->map->sw_blit(src, srcrect, dst, dstrect)); | |
132 } | |
133 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
134 /* 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
|
135 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
136 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
137 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
138 |
0 | 139 /* 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
|
140 w = dstrect->w; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
141 h = dstrect->h; |
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, src, &srcX, &srcY); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
143 FB_dst_to_xy(this, dst, &dstX, &dstY); |
0 | 144 |
145 /* Adjust for the current blit rectangles */ | |
146 srcX += srcrect->x; | |
147 srcY += srcrect->y; | |
148 dstX += dstrect->x; | |
149 dstY += dstrect->y; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
150 pitch = dst->pitch/dst->format->BytesPerPixel; |
0 | 151 |
152 /* Set up the blit direction (sign) flags */ | |
153 sign = 0; | |
154 if ( srcX < dstX ) { | |
155 sign |= 1; | |
156 } | |
157 if ( srcY < dstY ) { | |
158 sign |= 4; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
159 srcY += (h - 1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
160 dstY += (h - 1); |
0 | 161 } |
162 | |
163 /* 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
|
164 stop = start = (srcY * pitch) + srcX; |
0 | 165 if ( srcX < dstX ) { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
166 start += (w - 1); |
0 | 167 } else { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
168 stop += (w - 1); |
0 | 169 } |
170 if ( srcY < dstY ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
171 skip = -pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
172 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
173 skip = pitch; |
0 | 174 } |
175 | |
176 /* Set up the blit operation */ | |
177 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
178 Uint32 colorkey; | |
179 | |
180 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
181 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16) | | |
182 MGADWG_TRANSC; | |
183 | |
184 colorkey = src->format->colorkey; | |
185 switch (dst->format->BytesPerPixel) { | |
186 case 1: | |
187 colorkey |= (colorkey<<8); | |
188 case 2: | |
189 colorkey |= (colorkey<<16); | |
190 break; | |
191 } | |
192 mga_wait(2); | |
193 mga_out32(MGAREG_FCOL, colorkey); | |
194 mga_out32(MGAREG_BCOL, 0xFFFFFFFF); | |
195 } else { | |
196 blitop = MGADWG_BFCOL | MGADWG_BITBLT | | |
197 MGADWG_SHIFTZERO | MGADWG_RSTR | (0x0C << 16); | |
198 } | |
199 mga_wait(7); | |
200 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
|
201 mga_out32(MGAREG_AR3, start); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
202 mga_out32(MGAREG_AR0, stop); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
203 mga_out32(MGAREG_AR5, skip); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
204 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
|
205 mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h); |
0 | 206 mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop); |
207 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
208 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
209 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
210 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
211 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
212 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
213 } |
0 | 214 return(0); |
215 } | |
216 | |
217 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
218 { | |
219 int accelerated; | |
220 | |
221 /* Set initial acceleration on */ | |
222 src->flags |= SDL_HWACCEL; | |
223 | |
224 /* Set the surface attributes */ | |
225 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
226 if ( ! this->info.blit_hw_A ) { | |
227 src->flags &= ~SDL_HWACCEL; | |
228 } | |
229 } | |
230 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
231 if ( ! this->info.blit_hw_CC ) { | |
232 src->flags &= ~SDL_HWACCEL; | |
233 } | |
234 } | |
235 | |
236 /* Check to see if final surface blit is accelerated */ | |
237 accelerated = !!(src->flags & SDL_HWACCEL); | |
238 if ( accelerated ) { | |
239 src->map->hw_blit = HWAccelBlit; | |
240 } | |
241 return(accelerated); | |
242 } | |
243 | |
244 void FB_MatroxAccel(_THIS, __u32 card) | |
245 { | |
246 /* We have hardware accelerated surface functions */ | |
247 this->CheckHWBlit = CheckHWBlit; | |
248 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
20
diff
changeset
|
249 wait_idle = WaitIdle; |
0 | 250 |
251 /* The Matrox has an accelerated color fill */ | |
252 this->info.blit_fill = 1; | |
253 this->FillHWRect = FillHWRect; | |
254 | |
255 /* The Matrox has accelerated normal and colorkey blits. */ | |
256 this->info.blit_hw = 1; | |
257 /* The Millenium I appears to do the colorkey test a word | |
258 at a time, and the transparency is intverted. (?) | |
259 */ | |
260 if ( card != FB_ACCEL_MATROX_MGA2064W ) { | |
261 this->info.blit_hw_CC = 1; | |
262 this->SetHWColorKey = SetHWColorKey; | |
263 } | |
264 | |
265 #if 0 /* Not yet implemented? */ | |
266 /* The Matrox G200/G400 has an accelerated alpha blit */ | |
267 if ( (card == FB_ACCEL_MATROX_MGAG200) | |
268 || (card == FB_ACCEL_MATROX_MGAG400) | |
269 ) { | |
270 this->info.blit_hw_A = 1; | |
271 this->SetHWAlpha = SetHWAlpha; | |
272 } | |
273 #endif | |
274 } |