Mercurial > sdl-ios-xcode
comparison src/video/quartz/SDL_QuartzYUV.m @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
35 #define yuv_width (this->hidden->yuv_width) | 35 #define yuv_width (this->hidden->yuv_width) |
36 #define yuv_height (this->hidden->yuv_height) | 36 #define yuv_height (this->hidden->yuv_height) |
37 #define yuv_port (this->hidden->yuv_port) | 37 #define yuv_port (this->hidden->yuv_port) |
38 | 38 |
39 | 39 |
40 static int QZ_LockYUV (_THIS, SDL_Overlay *overlay) { | 40 static int |
41 QZ_LockYUV (_THIS, SDL_Overlay * overlay) | |
42 { | |
41 | 43 |
42 return 0; | 44 return 0; |
43 } | 45 } |
44 | 46 |
45 static void QZ_UnlockYUV (_THIS, SDL_Overlay *overlay) { | 47 static void |
48 QZ_UnlockYUV (_THIS, SDL_Overlay * overlay) | |
49 { | |
46 | 50 |
47 ; | 51 ; |
48 } | 52 } |
49 | 53 |
50 static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { | 54 static int |
55 QZ_DisplayYUV (_THIS, SDL_Overlay * overlay, SDL_Rect * src, SDL_Rect * dst) | |
56 { | |
51 | 57 |
52 OSErr err; | 58 OSErr err; |
53 CodecFlags flags; | 59 CodecFlags flags; |
54 | 60 |
55 if (dst->x != 0 || dst->y != 0) { | 61 if (dst->x != 0 || dst->y != 0) { |
60 | 66 |
61 if (dst->w != yuv_width || dst->h != yuv_height) { | 67 if (dst->w != yuv_width || dst->h != yuv_height) { |
62 | 68 |
63 Fixed scale_x, scale_y; | 69 Fixed scale_x, scale_y; |
64 | 70 |
65 scale_x = FixDiv ( Long2Fix (dst->w), Long2Fix (overlay->w) ); | 71 scale_x = FixDiv (Long2Fix (dst->w), Long2Fix (overlay->w)); |
66 scale_y = FixDiv ( Long2Fix (dst->h), Long2Fix (overlay->h) ); | 72 scale_y = FixDiv (Long2Fix (dst->h), Long2Fix (overlay->h)); |
67 | 73 |
68 SetIdentityMatrix (yuv_matrix); | 74 SetIdentityMatrix (yuv_matrix); |
69 ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0), Long2Fix (0)); | 75 ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0), |
76 Long2Fix (0)); | |
70 | 77 |
71 SetDSequenceMatrix (yuv_seq, yuv_matrix); | 78 SetDSequenceMatrix (yuv_seq, yuv_matrix); |
72 | 79 |
73 yuv_width = dst->w; | 80 yuv_width = dst->w; |
74 yuv_height = dst->h; | 81 yuv_height = dst->h; |
75 } | 82 } |
76 | 83 |
77 if( ( err = DecompressSequenceFrameS( | 84 if ((err = DecompressSequenceFrameS (yuv_seq, |
78 yuv_seq, | 85 (void *) yuv_pixmap, |
79 (void*)yuv_pixmap, | |
80 sizeof (PlanarPixmapInfoYUV420), | 86 sizeof (PlanarPixmapInfoYUV420), |
81 codecFlagUseImageBuffer, &flags, nil ) != noErr ) ) | 87 codecFlagUseImageBuffer, &flags, |
82 { | 88 nil) != noErr)) { |
83 SDL_SetError ("DecompressSequenceFrameS failed"); | 89 SDL_SetError ("DecompressSequenceFrameS failed"); |
84 } | 90 } |
85 | 91 |
86 return err != noErr; | 92 return err != noErr; |
87 } | 93 } |
88 | 94 |
89 static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) { | 95 static void |
96 QZ_FreeHWYUV (_THIS, SDL_Overlay * overlay) | |
97 { | |
90 | 98 |
91 CDSequenceEnd (yuv_seq); | 99 CDSequenceEnd (yuv_seq); |
92 ExitMovies(); | 100 ExitMovies (); |
93 | 101 |
94 SDL_free (overlay->hwfuncs); | 102 SDL_free (overlay->hwfuncs); |
95 SDL_free (overlay->pitches); | 103 SDL_free (overlay->pitches); |
96 SDL_free (overlay->pixels); | 104 SDL_free (overlay->pixels); |
97 | 105 |
98 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { | 106 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { |
99 [ qz_window close ]; | 107 [qz_window close]; |
100 qz_window = nil; | 108 qz_window = nil; |
101 } | 109 } |
102 | 110 |
103 SDL_free (yuv_matrix); | 111 SDL_free (yuv_matrix); |
104 DisposeHandle ((Handle)yuv_idh); | 112 DisposeHandle ((Handle) yuv_idh); |
105 } | 113 } |
106 | 114 |
107 /* check for 16 byte alignment, bail otherwise */ | 115 /* check for 16 byte alignment, bail otherwise */ |
108 #define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0) | 116 #define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0) |
109 | 117 |
110 /* align a byte offset, return how much to add to make it a multiple of 16 */ | 118 /* align a byte offset, return how much to add to make it a multiple of 16 */ |
111 #define ALIGN(x) ((16 - (x & 15)) & 15) | 119 #define ALIGN(x) ((16 - (x & 15)) & 15) |
112 | 120 |
113 SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height, | 121 SDL_Overlay * |
114 Uint32 format, SDL_Surface *display) { | 122 QZ_CreateYUVOverlay (_THIS, int width, int height, |
123 Uint32 format, SDL_Surface * display) | |
124 { | |
115 | 125 |
116 Uint32 codec; | 126 Uint32 codec; |
117 OSStatus err; | 127 OSStatus err; |
118 CGrafPtr port; | 128 CGrafPtr port; |
119 SDL_Overlay *overlay; | 129 SDL_Overlay *overlay; |
120 | 130 |
121 if (format == SDL_YV12_OVERLAY || | 131 if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) { |
122 format == SDL_IYUV_OVERLAY) { | |
123 | 132 |
124 codec = kYUV420CodecType; | 133 codec = kYUV420CodecType; |
125 } | 134 } else { |
126 else { | |
127 SDL_SetError ("Hardware: unsupported video format"); | 135 SDL_SetError ("Hardware: unsupported video format"); |
128 return NULL; | 136 return NULL; |
129 } | 137 } |
130 | 138 |
131 yuv_idh = (ImageDescriptionHandle) NewHandleClear (sizeof(ImageDescription)); | 139 yuv_idh = |
140 (ImageDescriptionHandle) NewHandleClear (sizeof (ImageDescription)); | |
132 if (yuv_idh == NULL) { | 141 if (yuv_idh == NULL) { |
133 SDL_OutOfMemory(); | 142 SDL_OutOfMemory (); |
134 return NULL; | 143 return NULL; |
135 } | 144 } |
136 | 145 |
137 yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof(MatrixRecord)); | 146 yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof (MatrixRecord)); |
138 if (yuv_matrix == NULL) { | 147 if (yuv_matrix == NULL) { |
139 SDL_OutOfMemory(); | 148 SDL_OutOfMemory (); |
140 return NULL; | 149 return NULL; |
141 } | 150 } |
142 | 151 |
143 if ( EnterMovies() != noErr ) { | 152 if (EnterMovies () != noErr) { |
144 SDL_SetError ("Could not init QuickTime for YUV playback"); | 153 SDL_SetError ("Could not init QuickTime for YUV playback"); |
145 return NULL; | 154 return NULL; |
146 } | 155 } |
147 | 156 |
148 err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec); | 157 err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec); |
152 } | 161 } |
153 | 162 |
154 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { | 163 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { |
155 | 164 |
156 /* | 165 /* |
157 Acceleration requires a window to be present. | 166 Acceleration requires a window to be present. |
158 A CGrafPtr that points to the screen isn't good enough | 167 A CGrafPtr that points to the screen isn't good enough |
159 */ | 168 */ |
160 NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); | 169 NSRect content = |
161 | 170 NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); |
162 qz_window = [ [ SDL_QuartzWindow alloc ] | 171 |
163 initWithContentRect:content | 172 qz_window =[[SDL_QuartzWindow alloc] initWithContentRect: content styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer:NO]; |
164 styleMask:NSBorderlessWindowMask | |
165 backing:NSBackingStoreBuffered defer:NO ]; | |
166 | 173 |
167 if (qz_window == nil) { | 174 if (qz_window == nil) { |
168 SDL_SetError ("Could not create the Cocoa window"); | 175 SDL_SetError ("Could not create the Cocoa window"); |
169 return NULL; | 176 return NULL; |
170 } | 177 } |
171 | 178 |
172 [ qz_window setContentView:[ [ NSQuickDrawView alloc ] init ] ]; | 179 [qz_window setContentView:[[NSQuickDrawView alloc] init]]; |
173 [ qz_window setReleasedWhenClosed:YES ]; | 180 [qz_window setReleasedWhenClosed:YES]; |
174 [ qz_window center ]; | 181 [qz_window center]; |
175 [ qz_window setAcceptsMouseMovedEvents:YES ]; | 182 [qz_window setAcceptsMouseMovedEvents:YES]; |
176 [ qz_window setLevel:CGShieldingWindowLevel() ]; | 183 [qz_window setLevel:CGShieldingWindowLevel ()]; |
177 [ qz_window makeKeyAndOrderFront:nil ]; | 184 [qz_window makeKeyAndOrderFront:nil]; |
178 | 185 |
179 port = [ [ qz_window contentView ] qdPort ]; | 186 port =[[qz_window contentView] qdPort]; |
180 SetPort (port); | 187 SetPort (port); |
181 | 188 |
182 /* | 189 /* |
183 BUG: would like to remove white flash when window kicks in | 190 BUG: would like to remove white flash when window kicks in |
184 { | 191 { |
185 Rect r; | 192 Rect r; |
186 SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); | 193 SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); |
187 PaintRect (&r); | 194 PaintRect (&r); |
188 QDFlushPortBuffer (port, nil); | 195 QDFlushPortBuffer (port, nil); |
189 } | 196 } |
190 */ | 197 */ |
191 } | 198 } else { |
192 else { | 199 port =[window_view qdPort]; |
193 port = [ window_view qdPort ]; | |
194 SetPort (port); | 200 SetPort (port); |
195 } | 201 } |
196 | 202 |
197 SetIdentityMatrix (yuv_matrix); | 203 SetIdentityMatrix (yuv_matrix); |
198 | 204 |
199 HLock ((Handle)yuv_idh); | 205 HLock ((Handle) yuv_idh); |
200 | 206 |
201 (**yuv_idh).idSize = sizeof(ImageDescription); | 207 (**yuv_idh).idSize = sizeof (ImageDescription); |
202 (**yuv_idh).cType = codec; | 208 (**yuv_idh).cType = codec; |
203 (**yuv_idh).version = 1; | 209 (**yuv_idh).version = 1; |
204 (**yuv_idh).revisionLevel = 0; | 210 (**yuv_idh).revisionLevel = 0; |
205 (**yuv_idh).width = width; | 211 (**yuv_idh).width = width; |
206 (**yuv_idh).height = height; | 212 (**yuv_idh).height = height; |
207 (**yuv_idh).hRes = Long2Fix(72); | 213 (**yuv_idh).hRes = Long2Fix (72); |
208 (**yuv_idh).vRes = Long2Fix(72); | 214 (**yuv_idh).vRes = Long2Fix (72); |
209 (**yuv_idh).spatialQuality = codecLosslessQuality; | 215 (**yuv_idh).spatialQuality = codecLosslessQuality; |
210 (**yuv_idh).frameCount = 1; | 216 (**yuv_idh).frameCount = 1; |
211 (**yuv_idh).clutID = -1; | 217 (**yuv_idh).clutID = -1; |
212 (**yuv_idh).dataSize = 0; | 218 (**yuv_idh).dataSize = 0; |
213 (**yuv_idh).depth = 24; | 219 (**yuv_idh).depth = 24; |
214 | 220 |
215 HUnlock ((Handle)yuv_idh); | 221 HUnlock ((Handle) yuv_idh); |
216 | 222 |
217 err = DecompressSequenceBeginS ( | 223 err = DecompressSequenceBeginS (&yuv_seq, |
218 &yuv_seq, | |
219 yuv_idh, | 224 yuv_idh, |
220 NULL, | 225 NULL, |
221 0, | 226 0, |
222 port, | 227 port, |
223 NULL, | 228 NULL, |
224 NULL, | 229 NULL, |
225 yuv_matrix, | 230 yuv_matrix, |
226 0, | 231 0, |
227 NULL, | 232 NULL, |
228 codecFlagUseImageBuffer, | 233 codecFlagUseImageBuffer, |
229 codecLosslessQuality, | 234 codecLosslessQuality, yuv_codec); |
230 yuv_codec); | 235 |
231 | |
232 if (err != noErr) { | 236 if (err != noErr) { |
233 SDL_SetError ("Error trying to start YUV codec."); | 237 SDL_SetError ("Error trying to start YUV codec."); |
234 return NULL; | 238 return NULL; |
235 } | 239 } |
236 | 240 |
237 overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay)); | 241 overlay = (SDL_Overlay *) SDL_malloc (sizeof (*overlay)); |
238 if (overlay == NULL) { | 242 if (overlay == NULL) { |
239 SDL_OutOfMemory(); | 243 SDL_OutOfMemory (); |
240 return NULL; | 244 return NULL; |
241 } | 245 } |
242 | 246 |
243 overlay->format = format; | 247 overlay->format = format; |
244 overlay->w = width; | 248 overlay->w = width; |
245 overlay->h = height; | 249 overlay->h = height; |
246 overlay->planes = 3; | 250 overlay->planes = 3; |
247 overlay->hw_overlay = 1; | 251 overlay->hw_overlay = 1; |
248 { | 252 { |
249 int offset; | 253 int offset; |
250 Uint8 **pixels; | 254 Uint8 **pixels; |
251 Uint16 *pitches; | 255 Uint16 *pitches; |
252 int plane2, plane3; | 256 int plane2, plane3; |
253 | 257 |
254 if (format == SDL_IYUV_OVERLAY) { | 258 if (format == SDL_IYUV_OVERLAY) { |
255 | 259 |
256 plane2 = 1; /* Native codec format */ | 260 plane2 = 1; /* Native codec format */ |
257 plane3 = 2; | 261 plane3 = 2; |
258 } | 262 } else if (format == SDL_YV12_OVERLAY) { |
259 else if (format == SDL_YV12_OVERLAY) { | |
260 | 263 |
261 /* switch the U and V planes */ | 264 /* switch the U and V planes */ |
262 plane2 = 2; /* U plane maps to plane 3 */ | 265 plane2 = 2; /* U plane maps to plane 3 */ |
263 plane3 = 1; /* V plane maps to plane 2 */ | 266 plane3 = 1; /* V plane maps to plane 2 */ |
264 } | 267 } else { |
265 else { | 268 SDL_SetError ("Unsupported YUV format"); |
266 SDL_SetError("Unsupported YUV format"); | |
267 return NULL; | 269 return NULL; |
268 } | 270 } |
269 | 271 |
270 pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3); | 272 pixels = (Uint8 **) SDL_malloc (sizeof (*pixels) * 3); |
271 pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3); | 273 pitches = (Uint16 *) SDL_malloc (sizeof (*pitches) * 3); |
272 if (pixels == NULL || pitches == NULL) { | 274 if (pixels == NULL || pitches == NULL) { |
273 SDL_OutOfMemory(); | 275 SDL_OutOfMemory (); |
274 return NULL; | 276 return NULL; |
275 } | 277 } |
276 | 278 |
277 yuv_pixmap = (PlanarPixmapInfoYUV420*) | 279 yuv_pixmap = (PlanarPixmapInfoYUV420 *) |
278 SDL_malloc (sizeof(PlanarPixmapInfoYUV420) + | 280 SDL_malloc (sizeof (PlanarPixmapInfoYUV420) + |
279 (width * height * 2)); | 281 (width * height * 2)); |
280 if (yuv_pixmap == NULL) { | 282 if (yuv_pixmap == NULL) { |
281 SDL_OutOfMemory (); | 283 SDL_OutOfMemory (); |
282 return NULL; | 284 return NULL; |
283 } | 285 } |
284 | 286 |
285 /* CHECK_ALIGN(yuv_pixmap); */ | 287 /* CHECK_ALIGN(yuv_pixmap); */ |
286 offset = sizeof(PlanarPixmapInfoYUV420); | 288 offset = sizeof (PlanarPixmapInfoYUV420); |
287 /* offset += ALIGN(offset); */ | 289 /* offset += ALIGN(offset); */ |
288 /* CHECK_ALIGN(offset); */ | 290 /* CHECK_ALIGN(offset); */ |
289 | 291 |
290 pixels[0] = (Uint8*)yuv_pixmap + offset; | 292 pixels[0] = (Uint8 *) yuv_pixmap + offset; |
291 /* CHECK_ALIGN(pixels[0]); */ | 293 /* CHECK_ALIGN(pixels[0]); */ |
292 | 294 |
293 pitches[0] = width; | 295 pitches[0] = width; |
294 yuv_pixmap->componentInfoY.offset = offset; | 296 yuv_pixmap->componentInfoY.offset = offset; |
295 yuv_pixmap->componentInfoY.rowBytes = width; | 297 yuv_pixmap->componentInfoY.rowBytes = width; |
296 | 298 |
297 offset += width * height; | 299 offset += width * height; |
298 pixels[plane2] = (Uint8*)yuv_pixmap + offset; | 300 pixels[plane2] = (Uint8 *) yuv_pixmap + offset; |
299 pitches[plane2] = width / 2; | 301 pitches[plane2] = width / 2; |
300 yuv_pixmap->componentInfoCb.offset = offset; | 302 yuv_pixmap->componentInfoCb.offset = offset; |
301 yuv_pixmap->componentInfoCb.rowBytes = width / 2; | 303 yuv_pixmap->componentInfoCb.rowBytes = width / 2; |
302 | 304 |
303 offset += (width * height / 4); | 305 offset += (width * height / 4); |
304 pixels[plane3] = (Uint8*)yuv_pixmap + offset; | 306 pixels[plane3] = (Uint8 *) yuv_pixmap + offset; |
305 pitches[plane3] = width / 2; | 307 pitches[plane3] = width / 2; |
306 yuv_pixmap->componentInfoCr.offset = offset; | 308 yuv_pixmap->componentInfoCr.offset = offset; |
307 yuv_pixmap->componentInfoCr.rowBytes = width / 2; | 309 yuv_pixmap->componentInfoCr.rowBytes = width / 2; |
308 | 310 |
309 overlay->pixels = pixels; | 311 overlay->pixels = pixels; |
310 overlay->pitches = pitches; | 312 overlay->pitches = pitches; |
311 } | 313 } |
312 | 314 |
313 overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs)); | 315 overlay->hwfuncs = SDL_malloc (sizeof (*overlay->hwfuncs)); |
314 if (overlay->hwfuncs == NULL) { | 316 if (overlay->hwfuncs == NULL) { |
315 SDL_OutOfMemory(); | 317 SDL_OutOfMemory (); |
316 return NULL; | 318 return NULL; |
317 } | 319 } |
318 | 320 |
319 overlay->hwfuncs->Lock = QZ_LockYUV; | 321 overlay->hwfuncs->Lock = QZ_LockYUV; |
320 overlay->hwfuncs->Unlock = QZ_UnlockYUV; | 322 overlay->hwfuncs->Unlock = QZ_UnlockYUV; |
321 overlay->hwfuncs->Display = QZ_DisplayYUV; | 323 overlay->hwfuncs->Display = QZ_DisplayYUV; |
322 overlay->hwfuncs->FreeHW = QZ_FreeHWYUV; | 324 overlay->hwfuncs->FreeHW = QZ_FreeHWYUV; |
323 | 325 |
324 yuv_width = overlay->w; | 326 yuv_width = overlay->w; |
325 yuv_height = overlay->h; | 327 yuv_height = overlay->h; |
326 | 328 |
327 return overlay; | 329 return overlay; |
328 } | 330 } |