Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5yuv.c @ 1327:d12a63a8d95a
Resolved bug #130
Use XFilterEvent() to handle dead-key composition under X11
Cleaned up the code in preparation for 1.3 API changes
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 04 Feb 2006 08:35:11 +0000 |
parents | c9b51268668f |
children | 450721ad5436 |
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 */ |
22 | |
23 /* This is the DirectDraw implementation of YUV video overlays */ | |
24 | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 | |
28 #include "SDL_error.h" | |
29 #include "SDL_video.h" | |
30 #include "SDL_dx5yuv_c.h" | |
31 #include "SDL_yuvfuncs.h" | |
32 | |
811
e06ec825242d
Don't use hardware overlay by default (seems much faster this way)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
33 //#define USE_DIRECTX_OVERLAY |
0 | 34 |
35 /* The functions used to manipulate software video overlays */ | |
36 static struct private_yuvhwfuncs dx5_yuvfuncs = { | |
37 DX5_LockYUVOverlay, | |
38 DX5_UnlockYUVOverlay, | |
39 DX5_DisplayYUVOverlay, | |
40 DX5_FreeYUVOverlay | |
41 }; | |
42 | |
43 struct private_yuvhwdata { | |
44 LPDIRECTDRAWSURFACE3 surface; | |
45 | |
46 /* These are just so we don't have to allocate them separately */ | |
47 Uint16 pitches[3]; | |
48 Uint8 *planes[3]; | |
49 }; | |
50 | |
51 | |
52 static LPDIRECTDRAWSURFACE3 CreateYUVSurface(_THIS, | |
53 int width, int height, Uint32 format) | |
54 { | |
55 HRESULT result; | |
56 LPDIRECTDRAWSURFACE dd_surface1; | |
57 LPDIRECTDRAWSURFACE3 dd_surface3; | |
58 DDSURFACEDESC ddsd; | |
59 | |
60 /* Set up the surface description */ | |
61 memset(&ddsd, 0, sizeof(ddsd)); | |
62 ddsd.dwSize = sizeof(ddsd); | |
63 ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT); | |
64 ddsd.dwWidth = width; | |
65 ddsd.dwHeight= height; | |
66 #ifdef USE_DIRECTX_OVERLAY | |
67 ddsd.ddsCaps.dwCaps = (DDSCAPS_OVERLAY|DDSCAPS_VIDEOMEMORY); | |
68 #else | |
69 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY); | |
70 #endif | |
71 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); | |
72 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; | |
73 ddsd.ddpfPixelFormat.dwFourCC = format; | |
74 | |
75 /* Create the DirectDraw video surface */ | |
76 result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL); | |
77 if ( result != DD_OK ) { | |
78 SetDDerror("DirectDraw2::CreateSurface", result); | |
79 return(NULL); | |
80 } | |
81 result = IDirectDrawSurface_QueryInterface(dd_surface1, | |
82 &IID_IDirectDrawSurface3, (LPVOID *)&dd_surface3); | |
83 IDirectDrawSurface_Release(dd_surface1); | |
84 if ( result != DD_OK ) { | |
85 SetDDerror("DirectDrawSurface::QueryInterface", result); | |
86 return(NULL); | |
87 } | |
88 | |
89 /* Make sure the surface format was set properly */ | |
90 memset(&ddsd, 0, sizeof(ddsd)); | |
91 ddsd.dwSize = sizeof(ddsd); | |
92 result = IDirectDrawSurface3_Lock(dd_surface3, NULL, | |
93 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
94 if ( result != DD_OK ) { | |
95 SetDDerror("DirectDrawSurface3::Lock", result); | |
96 IDirectDrawSurface_Release(dd_surface3); | |
97 return(NULL); | |
98 } | |
99 IDirectDrawSurface3_Unlock(dd_surface3, NULL); | |
100 | |
101 if ( !(ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC) || | |
102 (ddsd.ddpfPixelFormat.dwFourCC != format) ) { | |
103 SDL_SetError("DDraw didn't use requested FourCC format"); | |
104 IDirectDrawSurface_Release(dd_surface3); | |
105 return(NULL); | |
106 } | |
107 | |
108 /* We're ready to go! */ | |
109 return(dd_surface3); | |
110 } | |
111 | |
112 #ifdef DEBUG_YUV | |
113 static char *PrintFOURCC(Uint32 code) | |
114 { | |
115 static char buf[5]; | |
116 | |
117 buf[3] = code >> 24; | |
118 buf[2] = (code >> 16) & 0xFF; | |
119 buf[1] = (code >> 8) & 0xFF; | |
120 buf[0] = (code & 0xFF); | |
121 return(buf); | |
122 } | |
123 #endif | |
124 | |
125 SDL_Overlay *DX5_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) | |
126 { | |
127 SDL_Overlay *overlay; | |
128 struct private_yuvhwdata *hwdata; | |
129 | |
130 #ifdef DEBUG_YUV | |
131 DWORD numcodes; | |
132 DWORD *codes; | |
133 | |
134 printf("FOURCC format requested: 0x%x\n", PrintFOURCC(format)); | |
135 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, NULL); | |
136 if ( numcodes ) { | |
137 DWORD i; | |
138 codes = malloc(numcodes*sizeof(*codes)); | |
139 if ( codes ) { | |
140 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, codes); | |
141 for ( i=0; i<numcodes; ++i ) { | |
142 fprintf(stderr, "Code %d: 0x%x\n", i, PrintFOURCC(codes[i])); | |
143 } | |
144 free(codes); | |
145 } | |
146 } else { | |
147 fprintf(stderr, "No FOURCC codes supported\n"); | |
148 } | |
149 #endif | |
150 | |
151 /* Create the overlay structure */ | |
152 overlay = (SDL_Overlay *)malloc(sizeof *overlay); | |
153 if ( overlay == NULL ) { | |
154 SDL_OutOfMemory(); | |
155 return(NULL); | |
156 } | |
157 memset(overlay, 0, (sizeof *overlay)); | |
158 | |
159 /* Fill in the basic members */ | |
160 overlay->format = format; | |
161 overlay->w = width; | |
162 overlay->h = height; | |
163 | |
164 /* Set up the YUV surface function structure */ | |
165 overlay->hwfuncs = &dx5_yuvfuncs; | |
166 | |
167 /* Create the pixel data and lookup tables */ | |
168 hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata); | |
169 overlay->hwdata = hwdata; | |
170 if ( hwdata == NULL ) { | |
171 SDL_OutOfMemory(); | |
172 SDL_FreeYUVOverlay(overlay); | |
173 return(NULL); | |
174 } | |
175 hwdata->surface = CreateYUVSurface(this, width, height, format); | |
176 if ( hwdata->surface == NULL ) { | |
177 SDL_FreeYUVOverlay(overlay); | |
178 return(NULL); | |
179 } | |
180 overlay->hw_overlay = 1; | |
181 | |
182 /* Set up the plane pointers */ | |
183 overlay->pitches = hwdata->pitches; | |
184 overlay->pixels = hwdata->planes; | |
185 switch (format) { | |
186 case SDL_YV12_OVERLAY: | |
187 case SDL_IYUV_OVERLAY: | |
188 overlay->planes = 3; | |
33
81a7158fa836
Silly bug fix from Billy Biggs
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
189 break; |
0 | 190 default: |
191 overlay->planes = 1; | |
192 break; | |
193 } | |
194 | |
195 /* We're all done.. */ | |
196 return(overlay); | |
197 } | |
198 | |
199 int DX5_LockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
200 { | |
201 HRESULT result; | |
202 LPDIRECTDRAWSURFACE3 surface; | |
203 DDSURFACEDESC ddsd; | |
204 | |
205 surface = overlay->hwdata->surface; | |
206 memset(&ddsd, 0, sizeof(ddsd)); | |
207 ddsd.dwSize = sizeof(ddsd); | |
208 result = IDirectDrawSurface3_Lock(surface, NULL, | |
209 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
210 if ( result == DDERR_SURFACELOST ) { | |
211 result = IDirectDrawSurface3_Restore(surface); | |
212 result = IDirectDrawSurface3_Lock(surface, NULL, &ddsd, | |
213 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); | |
214 } | |
215 if ( result != DD_OK ) { | |
216 SetDDerror("DirectDrawSurface3::Lock", result); | |
217 return(-1); | |
218 } | |
219 | |
220 /* Find the pitch and offset values for the overlay */ | |
221 #if defined(NONAMELESSUNION) | |
222 overlay->pitches[0] = (Uint16)ddsd.u1.lPitch; | |
223 #else | |
224 overlay->pitches[0] = (Uint16)ddsd.lPitch; | |
225 #endif | |
226 overlay->pixels[0] = (Uint8 *)ddsd.lpSurface; | |
227 switch (overlay->format) { | |
228 case SDL_YV12_OVERLAY: | |
229 case SDL_IYUV_OVERLAY: | |
230 /* Add the two extra planes */ | |
231 overlay->pitches[1] = overlay->pitches[0] / 2; | |
232 overlay->pitches[2] = overlay->pitches[0] / 2; | |
233 overlay->pixels[1] = overlay->pixels[0] + | |
234 overlay->pitches[0] * overlay->h; | |
235 overlay->pixels[2] = overlay->pixels[1] + | |
236 overlay->pitches[1] * overlay->h / 2; | |
237 break; | |
238 default: | |
239 /* Only one plane, no worries */ | |
240 break; | |
241 } | |
242 return(0); | |
243 } | |
244 | |
245 void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
246 { | |
247 LPDIRECTDRAWSURFACE3 surface; | |
248 | |
249 surface = overlay->hwdata->surface; | |
250 IDirectDrawSurface3_Unlock(surface, NULL); | |
251 } | |
252 | |
253 int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) | |
254 { | |
255 HRESULT result; | |
256 LPDIRECTDRAWSURFACE3 surface; | |
257 RECT src, dst; | |
258 | |
259 surface = overlay->hwdata->surface; | |
260 src.top = 0; | |
261 src.bottom = overlay->h; | |
262 src.left = 0; | |
263 src.right = overlay->w; | |
264 dst.top = SDL_bounds.top+dstrect->y; | |
265 dst.left = SDL_bounds.left+dstrect->x; | |
266 dst.bottom = dst.top+dstrect->h; | |
267 dst.right = dst.left+dstrect->w; | |
268 #ifdef USE_DIRECTX_OVERLAY | |
269 result = IDirectDrawSurface3_UpdateOverlay(surface, &src, | |
270 SDL_primary, &dst, DDOVER_SHOW, NULL); | |
271 if ( result != DD_OK ) { | |
272 SetDDerror("DirectDrawSurface3::UpdateOverlay", result); | |
273 return(-1); | |
274 } | |
275 #else | |
276 result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src, | |
277 DDBLT_WAIT, NULL); | |
278 if ( result != DD_OK ) { | |
279 SetDDerror("DirectDrawSurface3::Blt", result); | |
280 return(-1); | |
281 } | |
282 #endif | |
283 return(0); | |
284 } | |
285 | |
286 void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) | |
287 { | |
288 struct private_yuvhwdata *hwdata; | |
289 | |
290 hwdata = overlay->hwdata; | |
291 if ( hwdata ) { | |
292 if ( hwdata->surface ) { | |
293 IDirectDrawSurface_Release(hwdata->surface); | |
294 } | |
295 free(hwdata); | |
296 } | |
297 } | |
298 |