Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5yuv.c @ 1629:ef4a796e7f24
Fixed bug #55
From Christian Walther:
When writing my patch for #12, I ended up doing all sorts of changes to the way
application/window activating/deactivating is handled in the Quartz backend,
resulting in the attached patch. It does make the code a bit cleaner IMHO, but
as it might be regarded as a case of "if it ain't broken, don't fix it" I'd
like to hear other people's opinion about it. Please shout if some change
strikes you as unnecessary or wrong, and I'll explain the reasons behind it. As
far as I tested it, it does not introduce any new bugs, but I may well have
missed some.
- The most fundamental change (that triggered most of the others) is irrelevant
for the usual single-window SDL applications, it only affects the people who
are crazy enough to display other Cocoa windows alongside the SDL window (I'm
actually doing this currently, although the additional window only displays
debugging info and won't be present in the final product): Before, some things
were done on the application becoming active, some on the window becoming key,
and some on the window becoming main. Conceptually, all these actions belong to
the window becoming key, so that's what I implemented. However, since in a
single-window application these three events always happen together, the
previous implementation "ain't broken".
- This slightly changed the meaning of the SDL_APPMOUSEFOCUS flag from
SDL_GetAppState(): Before, it meant "window is main and mouse is inside window
(or mode is fullscreen)". Now, it means "window is key and mouse is inside
window (or mode is fullscreen)". It makes more sense to me that way. (See
http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html
for a discussion of what key and main windows are.) The other two flags are
unchanged: SDL_APPACTIVE = application is not hidden and window is not
minimized, SDL_APPINPUTFOCUS = window is key (or mode is fullscreen).
- As a side effect, the reorganization fixes the following two issues (and
maybe others) (but they could also be fixed in less invasive ways):
* A regression that was introduced in revision 1.42 of SDL_QuartzVideo.m
(http://libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzVideo.m.diff?r1=1.41&r2=1.42)
(from half-desirable to undesirable behavior):
Situation: While in windowed mode, hide the cursor using
SDL_ShowCursor(SDL_DISABLE), move the mouse outside of the window so that the
cursor becomes visible again, and SDL_SetVideoMode() to a fullscreen mode.
What happened before revision 1.42: The cursor is visible, but becomes
invisible as soon as the mouse is moved (half-desirable).
What happens in revision 1.42 and after (including current CVS): The cursor is
visible and stays visible (undesirable).
What happens after my patch: The cursor is invisible from the beginning
(desirable).
* When the cursor is hidden and grabbed, switch away from the application using
cmd-tab (which ungrabs and makes the cursor visible), move the cursor outside
of the SDL window, then cmd-tab back to the application. In 1.2.8 and in the
current CVS, the cursor is re-grabbed, but it stays visible (immovable in the
middle of the window). With my patch, the cursor is correctly re-grabbed and
hidden. (For some reason, it still doesn't work correctly if you switch back to
the application using the dock instead of cmd-tab. I haven't been able to
figure out why. I can step over [NSCursor hide] being called in the debugger,
but it seems to have no effect.)
- The patch includes my patch for #12 (it was easier to obtain using cvs diff
that way). If you apply both of them, you will end up with 6 duplicate lines in
SDL_QuartzEvents.m.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Apr 2006 14:17:48 +0000 |
parents | d910939febfa |
children | 51038e80ae59 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
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:
811
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:
811
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:
811
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
33
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* This is the DirectDraw implementation of YUV video overlays */ | |
25 | |
26 #include "SDL_video.h" | |
27 #include "SDL_dx5yuv_c.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "../SDL_yuvfuncs.h" |
0 | 29 |
811
e06ec825242d
Don't use hardware overlay by default (seems much faster this way)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
30 //#define USE_DIRECTX_OVERLAY |
0 | 31 |
32 /* The functions used to manipulate software video overlays */ | |
33 static struct private_yuvhwfuncs dx5_yuvfuncs = { | |
34 DX5_LockYUVOverlay, | |
35 DX5_UnlockYUVOverlay, | |
36 DX5_DisplayYUVOverlay, | |
37 DX5_FreeYUVOverlay | |
38 }; | |
39 | |
40 struct private_yuvhwdata { | |
41 LPDIRECTDRAWSURFACE3 surface; | |
42 | |
43 /* These are just so we don't have to allocate them separately */ | |
44 Uint16 pitches[3]; | |
45 Uint8 *planes[3]; | |
46 }; | |
47 | |
48 | |
49 static LPDIRECTDRAWSURFACE3 CreateYUVSurface(_THIS, | |
50 int width, int height, Uint32 format) | |
51 { | |
52 HRESULT result; | |
53 LPDIRECTDRAWSURFACE dd_surface1; | |
54 LPDIRECTDRAWSURFACE3 dd_surface3; | |
55 DDSURFACEDESC ddsd; | |
56 | |
57 /* Set up the surface description */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
58 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 59 ddsd.dwSize = sizeof(ddsd); |
60 ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT); | |
61 ddsd.dwWidth = width; | |
62 ddsd.dwHeight= height; | |
63 #ifdef USE_DIRECTX_OVERLAY | |
64 ddsd.ddsCaps.dwCaps = (DDSCAPS_OVERLAY|DDSCAPS_VIDEOMEMORY); | |
65 #else | |
66 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY); | |
67 #endif | |
68 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); | |
69 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; | |
70 ddsd.ddpfPixelFormat.dwFourCC = format; | |
71 | |
72 /* Create the DirectDraw video surface */ | |
73 result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL); | |
74 if ( result != DD_OK ) { | |
75 SetDDerror("DirectDraw2::CreateSurface", result); | |
76 return(NULL); | |
77 } | |
78 result = IDirectDrawSurface_QueryInterface(dd_surface1, | |
79 &IID_IDirectDrawSurface3, (LPVOID *)&dd_surface3); | |
80 IDirectDrawSurface_Release(dd_surface1); | |
81 if ( result != DD_OK ) { | |
82 SetDDerror("DirectDrawSurface::QueryInterface", result); | |
83 return(NULL); | |
84 } | |
85 | |
86 /* Make sure the surface format was set properly */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
87 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 88 ddsd.dwSize = sizeof(ddsd); |
89 result = IDirectDrawSurface3_Lock(dd_surface3, NULL, | |
90 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
91 if ( result != DD_OK ) { | |
92 SetDDerror("DirectDrawSurface3::Lock", result); | |
93 IDirectDrawSurface_Release(dd_surface3); | |
94 return(NULL); | |
95 } | |
96 IDirectDrawSurface3_Unlock(dd_surface3, NULL); | |
97 | |
98 if ( !(ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC) || | |
99 (ddsd.ddpfPixelFormat.dwFourCC != format) ) { | |
100 SDL_SetError("DDraw didn't use requested FourCC format"); | |
101 IDirectDrawSurface_Release(dd_surface3); | |
102 return(NULL); | |
103 } | |
104 | |
105 /* We're ready to go! */ | |
106 return(dd_surface3); | |
107 } | |
108 | |
109 #ifdef DEBUG_YUV | |
110 static char *PrintFOURCC(Uint32 code) | |
111 { | |
112 static char buf[5]; | |
113 | |
114 buf[3] = code >> 24; | |
115 buf[2] = (code >> 16) & 0xFF; | |
116 buf[1] = (code >> 8) & 0xFF; | |
117 buf[0] = (code & 0xFF); | |
118 return(buf); | |
119 } | |
120 #endif | |
121 | |
122 SDL_Overlay *DX5_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) | |
123 { | |
124 SDL_Overlay *overlay; | |
125 struct private_yuvhwdata *hwdata; | |
126 | |
127 #ifdef DEBUG_YUV | |
128 DWORD numcodes; | |
129 DWORD *codes; | |
130 | |
131 printf("FOURCC format requested: 0x%x\n", PrintFOURCC(format)); | |
132 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, NULL); | |
133 if ( numcodes ) { | |
134 DWORD i; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
135 codes = SDL_malloc(numcodes*sizeof(*codes)); |
0 | 136 if ( codes ) { |
137 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, codes); | |
138 for ( i=0; i<numcodes; ++i ) { | |
139 fprintf(stderr, "Code %d: 0x%x\n", i, PrintFOURCC(codes[i])); | |
140 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
141 SDL_free(codes); |
0 | 142 } |
143 } else { | |
144 fprintf(stderr, "No FOURCC codes supported\n"); | |
145 } | |
146 #endif | |
147 | |
148 /* Create the overlay structure */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
149 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); |
0 | 150 if ( overlay == NULL ) { |
151 SDL_OutOfMemory(); | |
152 return(NULL); | |
153 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
154 SDL_memset(overlay, 0, (sizeof *overlay)); |
0 | 155 |
156 /* Fill in the basic members */ | |
157 overlay->format = format; | |
158 overlay->w = width; | |
159 overlay->h = height; | |
160 | |
161 /* Set up the YUV surface function structure */ | |
162 overlay->hwfuncs = &dx5_yuvfuncs; | |
163 | |
164 /* Create the pixel data and lookup tables */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
165 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata); |
0 | 166 overlay->hwdata = hwdata; |
167 if ( hwdata == NULL ) { | |
168 SDL_OutOfMemory(); | |
169 SDL_FreeYUVOverlay(overlay); | |
170 return(NULL); | |
171 } | |
172 hwdata->surface = CreateYUVSurface(this, width, height, format); | |
173 if ( hwdata->surface == NULL ) { | |
174 SDL_FreeYUVOverlay(overlay); | |
175 return(NULL); | |
176 } | |
177 overlay->hw_overlay = 1; | |
178 | |
179 /* Set up the plane pointers */ | |
180 overlay->pitches = hwdata->pitches; | |
181 overlay->pixels = hwdata->planes; | |
182 switch (format) { | |
183 case SDL_YV12_OVERLAY: | |
184 case SDL_IYUV_OVERLAY: | |
185 overlay->planes = 3; | |
33
81a7158fa836
Silly bug fix from Billy Biggs
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
186 break; |
0 | 187 default: |
188 overlay->planes = 1; | |
189 break; | |
190 } | |
191 | |
192 /* We're all done.. */ | |
193 return(overlay); | |
194 } | |
195 | |
196 int DX5_LockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
197 { | |
198 HRESULT result; | |
199 LPDIRECTDRAWSURFACE3 surface; | |
200 DDSURFACEDESC ddsd; | |
201 | |
202 surface = overlay->hwdata->surface; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
203 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 204 ddsd.dwSize = sizeof(ddsd); |
205 result = IDirectDrawSurface3_Lock(surface, NULL, | |
206 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
207 if ( result == DDERR_SURFACELOST ) { | |
208 result = IDirectDrawSurface3_Restore(surface); | |
209 result = IDirectDrawSurface3_Lock(surface, NULL, &ddsd, | |
210 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); | |
211 } | |
212 if ( result != DD_OK ) { | |
213 SetDDerror("DirectDrawSurface3::Lock", result); | |
214 return(-1); | |
215 } | |
216 | |
217 /* Find the pitch and offset values for the overlay */ | |
218 #if defined(NONAMELESSUNION) | |
219 overlay->pitches[0] = (Uint16)ddsd.u1.lPitch; | |
220 #else | |
221 overlay->pitches[0] = (Uint16)ddsd.lPitch; | |
222 #endif | |
223 overlay->pixels[0] = (Uint8 *)ddsd.lpSurface; | |
224 switch (overlay->format) { | |
225 case SDL_YV12_OVERLAY: | |
226 case SDL_IYUV_OVERLAY: | |
227 /* Add the two extra planes */ | |
228 overlay->pitches[1] = overlay->pitches[0] / 2; | |
229 overlay->pitches[2] = overlay->pitches[0] / 2; | |
230 overlay->pixels[1] = overlay->pixels[0] + | |
231 overlay->pitches[0] * overlay->h; | |
232 overlay->pixels[2] = overlay->pixels[1] + | |
233 overlay->pitches[1] * overlay->h / 2; | |
234 break; | |
235 default: | |
236 /* Only one plane, no worries */ | |
237 break; | |
238 } | |
239 return(0); | |
240 } | |
241 | |
242 void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
243 { | |
244 LPDIRECTDRAWSURFACE3 surface; | |
245 | |
246 surface = overlay->hwdata->surface; | |
247 IDirectDrawSurface3_Unlock(surface, NULL); | |
248 } | |
249 | |
250 int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) | |
251 { | |
252 HRESULT result; | |
253 LPDIRECTDRAWSURFACE3 surface; | |
254 RECT src, dst; | |
255 | |
256 surface = overlay->hwdata->surface; | |
257 src.top = 0; | |
258 src.bottom = overlay->h; | |
259 src.left = 0; | |
260 src.right = overlay->w; | |
261 dst.top = SDL_bounds.top+dstrect->y; | |
262 dst.left = SDL_bounds.left+dstrect->x; | |
263 dst.bottom = dst.top+dstrect->h; | |
264 dst.right = dst.left+dstrect->w; | |
265 #ifdef USE_DIRECTX_OVERLAY | |
266 result = IDirectDrawSurface3_UpdateOverlay(surface, &src, | |
267 SDL_primary, &dst, DDOVER_SHOW, NULL); | |
268 if ( result != DD_OK ) { | |
269 SetDDerror("DirectDrawSurface3::UpdateOverlay", result); | |
270 return(-1); | |
271 } | |
272 #else | |
273 result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src, | |
274 DDBLT_WAIT, NULL); | |
275 if ( result != DD_OK ) { | |
276 SetDDerror("DirectDrawSurface3::Blt", result); | |
277 return(-1); | |
278 } | |
279 #endif | |
280 return(0); | |
281 } | |
282 | |
283 void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) | |
284 { | |
285 struct private_yuvhwdata *hwdata; | |
286 | |
287 hwdata = overlay->hwdata; | |
288 if ( hwdata ) { | |
289 if ( hwdata->surface ) { | |
290 IDirectDrawSurface_Release(hwdata->surface); | |
291 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
292 SDL_free(hwdata); |
0 | 293 } |
294 } | |
295 |