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