| 1 | Index: src/cdrom/macosx/CDPlayer.h |
| 2 | =================================================================== |
| 3 | --- src/cdrom/macosx/CDPlayer.h (revision 4718) |
| 4 | +++ src/cdrom/macosx/CDPlayer.h (working copy) |
| 5 | @@ -34,6 +34,10 @@ |
| 6 | #include "SDL_thread.h" |
| 7 | #include "SDL_mutex.h" |
| 8 | |
| 9 | +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 |
| 10 | +typedef SInt16 FSIORefNum; |
| 11 | +#endif |
| 12 | + |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | Index: src/video/quartz/SDL_QuartzVideo.h |
| 17 | =================================================================== |
| 18 | --- src/video/quartz/SDL_QuartzVideo.h (revision 4718) |
| 19 | +++ src/video/quartz/SDL_QuartzVideo.h (working copy) |
| 20 | @@ -93,7 +93,8 @@ |
| 21 | Uint32 warp_flag; /* boolean; notify to event loop that a warp just occured */ |
| 22 | Uint32 warp_ticks; /* timestamp when the warp occured */ |
| 23 | NSWindow *window; /* Cocoa window to implement the SDL window */ |
| 24 | - NSQuickDrawView *view; /* the window's view; draw 2D and OpenGL into this view */ |
| 25 | + NSView *view; /* the window's view; draw 2D and OpenGL into this view */ |
| 26 | + CGContextRef cg_context; /* CoreGraphics rendering context */ |
| 27 | SDL_Surface *resize_icon; /* icon for the resize badge, we have to draw it by hand */ |
| 28 | SDL_GrabMode current_grab_mode; /* default value is SDL_GRAB_OFF */ |
| 29 | SDL_Rect **client_mode_list; /* resolution list to pass back to client */ |
| 30 | @@ -113,7 +114,8 @@ |
| 31 | Uint8 *current_buffer; /* the buffer being copied to the screen */ |
| 32 | BOOL quit_thread; /* used to quit the async blitting thread */ |
| 33 | SInt32 system_version; /* used to dis-/enable workarounds depending on the system version */ |
| 34 | - |
| 35 | + |
| 36 | +#if SDL_LEGACY_QUICKDRAW |
| 37 | ImageDescriptionHandle yuv_idh; |
| 38 | MatrixRecordPtr yuv_matrix; |
| 39 | DecompressorComponent yuv_codec; |
| 40 | @@ -121,6 +123,7 @@ |
| 41 | PlanarPixmapInfoYUV420 *yuv_pixmap; |
| 42 | Sint16 yuv_width, yuv_height; |
| 43 | CGrafPtr yuv_port; |
| 44 | +#endif |
| 45 | |
| 46 | void *opengl_library; /* dynamically loaded OpenGL library. */ |
| 47 | } SDL_PrivateVideoData; |
| 48 | @@ -139,6 +142,7 @@ |
| 49 | #define mode_flags (this->hidden->flags) |
| 50 | #define qz_window (this->hidden->window) |
| 51 | #define window_view (this->hidden->view) |
| 52 | +#define cg_context (this->hidden->cg_context) |
| 53 | #define video_set (this->hidden->video_set) |
| 54 | #define warp_ticks (this->hidden->warp_ticks) |
| 55 | #define warp_flag (this->hidden->warp_flag) |
| 56 | @@ -156,6 +160,7 @@ |
| 57 | #define cursor_should_be_visible (this->hidden->cursor_should_be_visible) |
| 58 | #define cursor_visible (this->hidden->cursor_visible) |
| 59 | #define sw_buffers (this->hidden->sw_buffers) |
| 60 | +#define sw_contexts (this->hidden->sw_contexts) |
| 61 | #define thread (this->hidden->thread) |
| 62 | #define sem1 (this->hidden->sem1) |
| 63 | #define sem2 (this->hidden->sem2) |
| 64 | Index: src/video/quartz/SDL_QuartzGL.m |
| 65 | =================================================================== |
| 66 | --- src/video/quartz/SDL_QuartzGL.m (revision 4718) |
| 67 | +++ src/video/quartz/SDL_QuartzGL.m (working copy) |
| 68 | @@ -45,7 +45,8 @@ |
| 69 | @implementation NSOpenGLContext (CGLContextAccess) |
| 70 | - (CGLContextObj) cglContext; |
| 71 | { |
| 72 | - return _contextAuxiliary; |
| 73 | +return NULL; // !!! FIXME |
| 74 | + //return _contextAuxiliary; |
| 75 | } |
| 76 | @end |
| 77 | |
| 78 | Index: src/video/quartz/SDL_QuartzWindow.h |
| 79 | =================================================================== |
| 80 | --- src/video/quartz/SDL_QuartzWindow.h (revision 4718) |
| 81 | +++ src/video/quartz/SDL_QuartzWindow.h (working copy) |
| 82 | @@ -21,6 +21,10 @@ |
| 83 | */ |
| 84 | #include "SDL_config.h" |
| 85 | |
| 86 | +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 |
| 87 | +typedef unsigned int NSUInteger; |
| 88 | +#endif |
| 89 | + |
| 90 | /* Subclass of NSWindow to fix genie effect and support resize events */ |
| 91 | @interface SDL_QuartzWindow : NSWindow |
| 92 | - (void)miniaturize:(id)sender; |
| 93 | @@ -29,7 +33,7 @@ |
| 94 | - (void)appDidHide:(NSNotification*)note; |
| 95 | - (void)appWillUnhide:(NSNotification*)note; |
| 96 | - (void)appDidUnhide:(NSNotification*)note; |
| 97 | -- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; |
| 98 | +- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; |
| 99 | @end |
| 100 | |
| 101 | /* Delegate for our NSWindow to send SDLQuit() on close */ |
| 102 | Index: src/video/quartz/SDL_QuartzWM.m |
| 103 | =================================================================== |
| 104 | --- src/video/quartz/SDL_QuartzWM.m (revision 4718) |
| 105 | +++ src/video/quartz/SDL_QuartzWM.m (working copy) |
| 106 | @@ -171,11 +171,7 @@ |
| 107 | else { |
| 108 | |
| 109 | *p = [ window_view convertPoint:*p toView: nil ]; |
| 110 | - |
| 111 | - /* We need a workaround in OpenGL mode */ |
| 112 | - if ( SDL_VideoSurface->flags & SDL_OPENGL ) { |
| 113 | - p->y = [window_view frame].size.height - p->y; |
| 114 | - } |
| 115 | + p->y = [window_view frame].size.height - p->y; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | @@ -189,11 +185,7 @@ |
| 120 | else { |
| 121 | |
| 122 | *p = [ window_view convertPoint:*p fromView: nil ]; |
| 123 | - |
| 124 | - /* We need a workaround in OpenGL mode */ |
| 125 | - if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) { |
| 126 | - p->y = [window_view frame].size.height - p->y; |
| 127 | - } |
| 128 | + p->y = [window_view frame].size.height - p->y; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | Index: src/video/quartz/SDL_QuartzYUV.m |
| 133 | =================================================================== |
| 134 | --- src/video/quartz/SDL_QuartzYUV.m (revision 4718) |
| 135 | +++ src/video/quartz/SDL_QuartzYUV.m (working copy) |
| 136 | @@ -48,10 +48,15 @@ |
| 137 | } |
| 138 | |
| 139 | static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { |
| 140 | - |
| 141 | +#if SDL_LEGACY_QUICKDRAW |
| 142 | OSErr err; |
| 143 | CodecFlags flags; |
| 144 | + int h; |
| 145 | + char *p_dst, *p_src; |
| 146 | + PixMapHandle hPixMap; |
| 147 | + long theRowBytes; |
| 148 | |
| 149 | + |
| 150 | if (dst->x != 0 || dst->y != 0) { |
| 151 | |
| 152 | SDL_SetError ("Need a dst at (0,0)"); |
| 153 | @@ -81,27 +86,40 @@ |
| 154 | codecFlagUseImageBuffer, &flags, nil ) != noErr ) ) |
| 155 | { |
| 156 | SDL_SetError ("DecompressSequenceFrameS failed"); |
| 157 | + return TRUE; |
| 158 | } |
| 159 | |
| 160 | - return err != noErr; |
| 161 | + /* TODO: use CGContextDrawImage here too! Create two CGContextRefs the same way we |
| 162 | + create two buffers, replace current_buffer with current_context and set it |
| 163 | + appropriately in QZ_FlipDoubleBuffer. Use CTM instead of the above |
| 164 | + SetIdentityMatrix thing. */ |
| 165 | + hPixMap = GetGWorldPixMap(yuv_port); |
| 166 | + p_src = GetPixBaseAddr(hPixMap); |
| 167 | + theRowBytes = QTGetPixMapHandleRowBytes(hPixMap); |
| 168 | + p_dst = SDL_VideoSurface->pixels + SDL_VideoSurface->offset; |
| 169 | + for (h = dst->h; h--; ) { |
| 170 | + SDL_memcpy (p_dst, p_src, dst->w * 4); |
| 171 | + p_src += theRowBytes; |
| 172 | + p_dst += SDL_VideoSurface->pitch; |
| 173 | + } |
| 174 | + SDL_Flip (SDL_VideoSurface); |
| 175 | +#endif |
| 176 | + return FALSE; |
| 177 | } |
| 178 | |
| 179 | static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) { |
| 180 | - |
| 181 | +#if SDL_LEGACY_QUICKDRAW |
| 182 | CDSequenceEnd (yuv_seq); |
| 183 | ExitMovies(); |
| 184 | + DisposeGWorld(yuv_port); |
| 185 | |
| 186 | SDL_free (overlay->hwfuncs); |
| 187 | SDL_free (overlay->pitches); |
| 188 | SDL_free (overlay->pixels); |
| 189 | |
| 190 | - if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { |
| 191 | - [ qz_window close ]; |
| 192 | - qz_window = nil; |
| 193 | - } |
| 194 | - |
| 195 | SDL_free (yuv_matrix); |
| 196 | DisposeHandle ((Handle)yuv_idh); |
| 197 | +#endif |
| 198 | } |
| 199 | |
| 200 | /* check for 16 byte alignment, bail otherwise */ |
| 201 | @@ -112,11 +130,12 @@ |
| 202 | |
| 203 | SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height, |
| 204 | Uint32 format, SDL_Surface *display) { |
| 205 | - |
| 206 | + SDL_Overlay *overlay = NULL; |
| 207 | +#if SDL_LEGACY_QUICKDRAW |
| 208 | Uint32 codec; |
| 209 | OSStatus err; |
| 210 | CGrafPtr port; |
| 211 | - SDL_Overlay *overlay; |
| 212 | + Rect theBounds = {0, 0}; |
| 213 | |
| 214 | if (format == SDL_YV12_OVERLAY || |
| 215 | format == SDL_IYUV_OVERLAY) { |
| 216 | @@ -150,50 +169,21 @@ |
| 217 | SDL_SetError ("Could not find QuickTime codec for format"); |
| 218 | return NULL; |
| 219 | } |
| 220 | - |
| 221 | - if (SDL_VideoSurface->flags & SDL_FULLSCREEN) { |
| 222 | - |
| 223 | - /* |
| 224 | - Acceleration requires a window to be present. |
| 225 | - A CGrafPtr that points to the screen isn't good enough |
| 226 | - */ |
| 227 | - NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); |
| 228 | - |
| 229 | - qz_window = [ [ SDL_QuartzWindow alloc ] |
| 230 | - initWithContentRect:content |
| 231 | - styleMask:NSBorderlessWindowMask |
| 232 | - backing:NSBackingStoreBuffered defer:NO ]; |
| 233 | - |
| 234 | - if (qz_window == nil) { |
| 235 | - SDL_SetError ("Could not create the Cocoa window"); |
| 236 | - return NULL; |
| 237 | - } |
| 238 | - |
| 239 | - [ qz_window setContentView:[ [ NSQuickDrawView alloc ] init ] ]; |
| 240 | - [ qz_window setReleasedWhenClosed:YES ]; |
| 241 | - [ qz_window center ]; |
| 242 | - [ qz_window setAcceptsMouseMovedEvents:YES ]; |
| 243 | - [ qz_window setLevel:CGShieldingWindowLevel() ]; |
| 244 | - [ qz_window makeKeyAndOrderFront:nil ]; |
| 245 | - |
| 246 | - port = [ [ qz_window contentView ] qdPort ]; |
| 247 | - SetPort (port); |
| 248 | - |
| 249 | - /* |
| 250 | - BUG: would like to remove white flash when window kicks in |
| 251 | - { |
| 252 | - Rect r; |
| 253 | - SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); |
| 254 | - PaintRect (&r); |
| 255 | - QDFlushPortBuffer (port, nil); |
| 256 | - } |
| 257 | - */ |
| 258 | + |
| 259 | + theBounds.right = width; |
| 260 | + theBounds.bottom = height; |
| 261 | + yuv_port = NULL; |
| 262 | + |
| 263 | + err = QTNewGWorld(&yuv_port, k32ARGBPixelFormat, &theBounds, |
| 264 | + NULL, NULL, 0); |
| 265 | + |
| 266 | + if (err != noErr) { |
| 267 | + SDL_SetError ("Could not init QuickTime world"); |
| 268 | + return NULL; |
| 269 | } |
| 270 | - else { |
| 271 | - port = [ window_view qdPort ]; |
| 272 | - SetPort (port); |
| 273 | - } |
| 274 | |
| 275 | + LockPixels(GetGWorldPixMap(yuv_port)); |
| 276 | + |
| 277 | SetIdentityMatrix (yuv_matrix); |
| 278 | |
| 279 | HLock ((Handle)yuv_idh); |
| 280 | @@ -219,7 +209,7 @@ |
| 281 | yuv_idh, |
| 282 | NULL, |
| 283 | 0, |
| 284 | - port, |
| 285 | + yuv_port, |
| 286 | NULL, |
| 287 | NULL, |
| 288 | yuv_matrix, |
| 289 | @@ -231,11 +221,13 @@ |
| 290 | |
| 291 | if (err != noErr) { |
| 292 | SDL_SetError ("Error trying to start YUV codec."); |
| 293 | + DisposeGWorld(yuv_port); |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay)); |
| 298 | if (overlay == NULL) { |
| 299 | + DisposeGWorld(yuv_port); |
| 300 | SDL_OutOfMemory(); |
| 301 | return NULL; |
| 302 | } |
| 303 | @@ -263,6 +255,7 @@ |
| 304 | plane3 = 1; /* V plane maps to plane 2 */ |
| 305 | } |
| 306 | else { |
| 307 | + DisposeGWorld(yuv_port); |
| 308 | SDL_SetError("Unsupported YUV format"); |
| 309 | return NULL; |
| 310 | } |
| 311 | @@ -270,6 +263,7 @@ |
| 312 | pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3); |
| 313 | pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3); |
| 314 | if (pixels == NULL || pitches == NULL) { |
| 315 | + DisposeGWorld(yuv_port); |
| 316 | SDL_OutOfMemory(); |
| 317 | return NULL; |
| 318 | } |
| 319 | @@ -280,6 +274,7 @@ |
| 320 | SDL_malloc (sizeof(PlanarPixmapInfoYUV420) + |
| 321 | (width * height * 2)); |
| 322 | if (yuv_pixmap == NULL) { |
| 323 | + DisposeGWorld(yuv_port); |
| 324 | SDL_OutOfMemory (); |
| 325 | return NULL; |
| 326 | } |
| 327 | @@ -314,6 +309,7 @@ |
| 328 | |
| 329 | overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs)); |
| 330 | if (overlay->hwfuncs == NULL) { |
| 331 | + DisposeGWorld(yuv_port); |
| 332 | SDL_OutOfMemory(); |
| 333 | return NULL; |
| 334 | } |
| 335 | @@ -325,6 +321,7 @@ |
| 336 | |
| 337 | yuv_width = overlay->w; |
| 338 | yuv_height = overlay->h; |
| 339 | +#endif |
| 340 | |
| 341 | return overlay; |
| 342 | } |
| 343 | Index: src/video/quartz/SDL_QuartzVideo.m |
| 344 | =================================================================== |
| 345 | --- src/video/quartz/SDL_QuartzVideo.m (revision 4718) |
| 346 | +++ src/video/quartz/SDL_QuartzVideo.m (working copy) |
| 347 | @@ -38,7 +38,8 @@ |
| 348 | @implementation NSScreen (NSScreenAccess) |
| 349 | - (void) setFrame:(NSRect)frame; |
| 350 | { |
| 351 | - _frame = frame; |
| 352 | +// !!! FIXME |
| 353 | +// _frame = frame; |
| 354 | } |
| 355 | @end |
| 356 | |
| 357 | @@ -52,6 +53,8 @@ |
| 358 | - (void) doCommandBySelector:(SEL) myselector {} |
| 359 | @end |
| 360 | |
| 361 | +/* absent in 10.3.9. */ |
| 362 | +CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef); |
| 363 | |
| 364 | /* Bootstrap functions */ |
| 365 | static int QZ_Available (); |
| 366 | @@ -79,8 +82,6 @@ |
| 367 | static void QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects); |
| 368 | |
| 369 | static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects); |
| 370 | -static int QZ_LockWindow (_THIS, SDL_Surface *surface); |
| 371 | -static void QZ_UnlockWindow (_THIS, SDL_Surface *surface); |
| 372 | static void QZ_UpdateRects (_THIS, int num_rects, SDL_Rect *rects); |
| 373 | static void QZ_VideoQuit (_THIS); |
| 374 | |
| 375 | @@ -371,6 +372,12 @@ |
| 376 | this->LockHWSurface = NULL; |
| 377 | this->UnlockHWSurface = NULL; |
| 378 | |
| 379 | + if (cg_context) { |
| 380 | + CGContextFlush (cg_context); |
| 381 | + CGContextRelease (cg_context); |
| 382 | + cg_context = nil; |
| 383 | + } |
| 384 | + |
| 385 | /* Release fullscreen resources */ |
| 386 | if ( mode_flags & SDL_FULLSCREEN ) { |
| 387 | |
| 388 | @@ -487,7 +494,8 @@ |
| 389 | current->flags |= SDL_FULLSCREEN; |
| 390 | current->flags |= SDL_HWSURFACE; |
| 391 | current->flags |= SDL_PREALLOC; |
| 392 | - |
| 393 | + /* current->hwdata = (void *) CGDisplayGetDrawingContext (display_id); */ |
| 394 | + |
| 395 | this->UpdateRects = QZ_DirectUpdate; |
| 396 | this->LockHWSurface = QZ_LockHWSurface; |
| 397 | this->UnlockHWSurface = QZ_UnlockHWSurface; |
| 398 | @@ -538,6 +546,7 @@ |
| 399 | and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. ) |
| 400 | */ |
| 401 | /* Check for user-specified window and view */ |
| 402 | +#if SDL_LEGACY_QUICKDRAW |
| 403 | { |
| 404 | char *windowPtrString = getenv ("SDL_NSWindowPointer"); |
| 405 | char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer"); |
| 406 | @@ -561,12 +570,13 @@ |
| 407 | [ qz_window retain ]; |
| 408 | } |
| 409 | } |
| 410 | +#endif |
| 411 | /* Check if we should recreate the window */ |
| 412 | if (qz_window == nil) { |
| 413 | /* Manually create a window, avoids having a nib file resource */ |
| 414 | qz_window = [ [ SDL_QuartzWindow alloc ] |
| 415 | initWithContentRect:contentRect |
| 416 | - styleMask:nil |
| 417 | + styleMask:0 |
| 418 | backing:NSBackingStoreBuffered |
| 419 | defer:NO ]; |
| 420 | |
| 421 | @@ -695,6 +705,7 @@ |
| 422 | } |
| 423 | |
| 424 | /* Check for user-specified window and view */ |
| 425 | +#if SDL_LEGACY_QUICKDRAW |
| 426 | { |
| 427 | char *windowPtrString = getenv ("SDL_NSWindowPointer"); |
| 428 | char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer"); |
| 429 | @@ -727,7 +738,8 @@ |
| 430 | current->flags |= SDL_NOFRAME; |
| 431 | } |
| 432 | } |
| 433 | - |
| 434 | +#endif |
| 435 | + |
| 436 | /* Check if we should recreate the window */ |
| 437 | if (qz_window == nil) { |
| 438 | |
| 439 | @@ -809,46 +821,34 @@ |
| 440 | } |
| 441 | /* For 2D, we set the subview to an NSQuickDrawView */ |
| 442 | else { |
| 443 | - short qdbpp = 0; |
| 444 | + CGColorSpaceRef cgColorspace; |
| 445 | |
| 446 | /* Only recreate the view if it doesn't already exist */ |
| 447 | if (window_view == nil) { |
| 448 | |
| 449 | - window_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ]; |
| 450 | + window_view = [ [ NSView alloc ] initWithFrame:contentRect ]; |
| 451 | [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ]; |
| 452 | [ [ qz_window contentView ] addSubview:window_view ]; |
| 453 | [ window_view release ]; |
| 454 | [ qz_window makeKeyAndOrderFront:nil ]; |
| 455 | } |
| 456 | |
| 457 | - LockPortBits ( [ window_view qdPort ] ); |
| 458 | - current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) ); |
| 459 | - current->pitch = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) ); |
| 460 | - qdbpp = GetPixDepth ( GetPortPixMap ( [ window_view qdPort ] ) ); |
| 461 | - UnlockPortBits ( [ window_view qdPort ] ); |
| 462 | - |
| 463 | - /* QuickDraw may give a 16-bit shadow surface on 8-bit displays! */ |
| 464 | - *bpp = qdbpp; |
| 465 | - |
| 466 | + cgColorspace = CGColorSpaceCreateDeviceRGB(); |
| 467 | + current->pitch = 4 * current->w; |
| 468 | + current->pixels = SDL_malloc (current->h * current->pitch); |
| 469 | + |
| 470 | + cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h, |
| 471 | + 8, current->pitch, cgColorspace, |
| 472 | + kCGImageAlphaNoneSkipFirst); |
| 473 | + CGColorSpaceRelease (cgColorspace); |
| 474 | + |
| 475 | current->flags |= SDL_SWSURFACE; |
| 476 | - current->flags |= SDL_PREALLOC; |
| 477 | current->flags |= SDL_ASYNCBLIT; |
| 478 | + current->hwdata = (void *) cg_context; |
| 479 | |
| 480 | - /* |
| 481 | - current->pixels now points to the window's pixels |
| 482 | - We want it to point to the *view's* pixels |
| 483 | - */ |
| 484 | - { |
| 485 | - int vOffset = [ qz_window frame ].size.height - |
| 486 | - [ window_view frame ].size.height - [ window_view frame ].origin.y; |
| 487 | - |
| 488 | - int hOffset = [ window_view frame ].origin.x; |
| 489 | - |
| 490 | - current->pixels = (Uint8 *)current->pixels + (vOffset * current->pitch) + hOffset * (qdbpp/8); |
| 491 | - } |
| 492 | this->UpdateRects = QZ_UpdateRects; |
| 493 | - this->LockHWSurface = QZ_LockWindow; |
| 494 | - this->UnlockHWSurface = QZ_UnlockWindow; |
| 495 | + this->LockHWSurface = QZ_LockHWSurface; |
| 496 | + this->UnlockHWSurface = QZ_UnlockHWSurface; |
| 497 | } |
| 498 | |
| 499 | /* Save flags to ensure correct teardown */ |
| 500 | @@ -877,8 +877,8 @@ |
| 501 | } |
| 502 | /* Setup windowed video */ |
| 503 | else { |
| 504 | - /* Force bpp to the device's bpp */ |
| 505 | - bpp = device_bpp; |
| 506 | + /* Force bpp to 32 */ |
| 507 | + bpp = 32; |
| 508 | current = QZ_SetVideoWindowed (this, current, width, height, &bpp, flags); |
| 509 | if (current == NULL) |
| 510 | return NULL; |
| 511 | @@ -903,9 +903,15 @@ |
| 512 | return NULL; |
| 513 | case 32: /* (8)-8-8-8 ARGB */ |
| 514 | amask = 0x00000000; |
| 515 | +#ifdef __LITTLE_ENDIAN__ |
| 516 | + rmask = 0x0000FF00; |
| 517 | + gmask = 0x00FF0000; |
| 518 | + bmask = 0xFF000000; |
| 519 | +#else |
| 520 | rmask = 0x00FF0000; |
| 521 | gmask = 0x0000FF00; |
| 522 | bmask = 0x000000FF; |
| 523 | +#endif |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | @@ -1062,6 +1068,9 @@ |
| 528 | /* On error, skip VBL delay */ |
| 529 | ERROR: |
| 530 | |
| 531 | + /* TODO: use CGContextDrawImage here too! Create two CGContextRefs the same way we |
| 532 | + create two buffers, replace current_buffer with current_context and set it |
| 533 | + appropriately in QZ_FlipDoubleBuffer. */ |
| 534 | while ( h-- ) { |
| 535 | |
| 536 | SDL_memcpy (dst, src, len); |
| 537 | @@ -1105,254 +1114,7 @@ |
| 538 | #pragma unused(this,num_rects,rects) |
| 539 | } |
| 540 | |
| 541 | -/* |
| 542 | - The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com, |
| 543 | - who supplied sample code for Carbon. |
| 544 | -*/ |
| 545 | |
| 546 | -/*#define TEST_OBSCURED 1*/ |
| 547 | - |
| 548 | -#if TEST_OBSCURED |
| 549 | -#include "CGS.h" |
| 550 | -#endif |
| 551 | - |
| 552 | -static int QZ_IsWindowObscured (NSWindow *window) { |
| 553 | - |
| 554 | - |
| 555 | -#if TEST_OBSCURED |
| 556 | - |
| 557 | - /* |
| 558 | - In order to determine if a direct copy to the screen is possible, |
| 559 | - we must figure out if there are any windows covering ours (including shadows). |
| 560 | - This can be done by querying the window server about the on screen |
| 561 | - windows for their screen rectangle and window level. |
| 562 | - The procedure used below is puts accuracy before speed; however, it aims to call |
| 563 | - the window server the fewest number of times possible to keep things reasonable. |
| 564 | - In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW |
| 565 | - |
| 566 | - Notes: |
| 567 | - -Calls into the Window Server involve IPC which is slow. |
| 568 | - -Getting a rectangle seems slower than getting the window level |
| 569 | - -The window list we get back is in sorted order, top to bottom |
| 570 | - -On average, I suspect, most windows above ours are dock icon windows (hence optimization) |
| 571 | - -Some windows above ours are always there, and cannot move or obscure us (menu bar) |
| 572 | - |
| 573 | - Bugs: |
| 574 | - -no way (yet) to deactivate direct drawing when a window is dragged, |
| 575 | - or suddenly obscured, so drawing continues and can produce garbage |
| 576 | - We need some kind of locking mechanism on window movement to prevent this |
| 577 | - |
| 578 | - -deactivated normal windows use activated normal |
| 579 | - window shadows (slight inaccuraccy) |
| 580 | - */ |
| 581 | - |
| 582 | - /* Cache the connection to the window server */ |
| 583 | - static CGSConnectionID cgsConnection = (CGSConnectionID) -1; |
| 584 | - |
| 585 | - /* Cache the dock icon windows */ |
| 586 | - static CGSWindowID dockIcons[kMaxWindows]; |
| 587 | - static int numCachedDockIcons = 0; |
| 588 | - |
| 589 | - CGSWindowID windows[kMaxWindows]; |
| 590 | - CGSWindowCount i, count; |
| 591 | - CGSWindowLevel winLevel; |
| 592 | - CGSRect winRect; |
| 593 | - |
| 594 | - CGSRect contentRect; |
| 595 | - int windowNumber; |
| 596 | - int firstDockIcon; |
| 597 | - int dockIconCacheMiss; |
| 598 | - int windowContentOffset; |
| 599 | - |
| 600 | - int obscured = SDL_TRUE; |
| 601 | - |
| 602 | - if ( [ window isVisible ] ) { |
| 603 | - |
| 604 | - /* |
| 605 | - walk the window list looking for windows over top of |
| 606 | - (or casting a shadow on) ours |
| 607 | - */ |
| 608 | - |
| 609 | - /* |
| 610 | - Get a connection to the window server |
| 611 | - Should probably be moved out into SetVideoMode() or InitVideo() |
| 612 | - */ |
| 613 | - if (cgsConnection == (CGSConnectionID) -1) { |
| 614 | - cgsConnection = (CGSConnectionID) 0; |
| 615 | - cgsConnection = _CGSDefaultConnection (); |
| 616 | - } |
| 617 | - |
| 618 | - if (cgsConnection) { |
| 619 | - |
| 620 | - if ( ! [ window styleMask ] & NSBorderlessWindowMask ) |
| 621 | - windowContentOffset = 22; |
| 622 | - else |
| 623 | - windowContentOffset = 0; |
| 624 | - |
| 625 | - windowNumber = [ window windowNumber ]; |
| 626 | - |
| 627 | - /* The window list is sorted according to order on the screen */ |
| 628 | - count = 0; |
| 629 | - CGSGetOnScreenWindowList (cgsConnection, 0, kMaxWindows, windows, &count); |
| 630 | - CGSGetScreenRectForWindow (cgsConnection, windowNumber, &contentRect); |
| 631 | - |
| 632 | - /* adjust rect for window title bar (if present) */ |
| 633 | - contentRect.origin.y += windowContentOffset; |
| 634 | - contentRect.size.height -= windowContentOffset; |
| 635 | - |
| 636 | - firstDockIcon = -1; |
| 637 | - dockIconCacheMiss = SDL_FALSE; |
| 638 | - |
| 639 | - /* |
| 640 | - The first window is always an empty window with level kCGSWindowLevelTop |
| 641 | - so start at index 1 |
| 642 | - */ |
| 643 | - for (i = 1; i < count; i++) { |
| 644 | - |
| 645 | - /* If we reach our window in the list, it cannot be obscured */ |
| 646 | - if (windows[i] == windowNumber) { |
| 647 | - |
| 648 | - obscured = SDL_FALSE; |
| 649 | - break; |
| 650 | - } |
| 651 | - else { |
| 652 | - |
| 653 | - float shadowSide; |
| 654 | - float shadowTop; |
| 655 | - float shadowBottom; |
| 656 | - |
| 657 | - CGSGetWindowLevel (cgsConnection, windows[i], &winLevel); |
| 658 | - |
| 659 | - if (winLevel == kCGSWindowLevelDockIcon) { |
| 660 | - |
| 661 | - int j; |
| 662 | - |
| 663 | - if (firstDockIcon < 0) { |
| 664 | - |
| 665 | - firstDockIcon = i; |
| 666 | - |
| 667 | - if (numCachedDockIcons > 0) { |
| 668 | - |
| 669 | - for (j = 0; j < numCachedDockIcons; j++) { |
| 670 | - |
| 671 | - if (windows[i] == dockIcons[j]) |
| 672 | - i++; |
| 673 | - else |
| 674 | - break; |
| 675 | - } |
| 676 | - |
| 677 | - if (j != 0) { |
| 678 | - |
| 679 | - i--; |
| 680 | - |
| 681 | - if (j < numCachedDockIcons) { |
| 682 | - |
| 683 | - dockIconCacheMiss = SDL_TRUE; |
| 684 | - } |
| 685 | - } |
| 686 | - |
| 687 | - } |
| 688 | - } |
| 689 | - |
| 690 | - continue; |
| 691 | - } |
| 692 | - else if (winLevel == kCGSWindowLevelMenuIgnore |
| 693 | - /* winLevel == kCGSWindowLevelTop */) { |
| 694 | - |
| 695 | - continue; /* cannot obscure window */ |
| 696 | - } |
| 697 | - else if (winLevel == kCGSWindowLevelDockMenu || |
| 698 | - winLevel == kCGSWindowLevelMenu) { |
| 699 | - |
| 700 | - shadowSide = 18; |
| 701 | - shadowTop = 4; |
| 702 | - shadowBottom = 22; |
| 703 | - } |
| 704 | - else if (winLevel == kCGSWindowLevelUtility) { |
| 705 | - |
| 706 | - shadowSide = 8; |
| 707 | - shadowTop = 4; |
| 708 | - shadowBottom = 12; |
| 709 | - } |
| 710 | - else if (winLevel == kCGSWindowLevelNormal) { |
| 711 | - |
| 712 | - /* |
| 713 | - These numbers are for foreground windows, |
| 714 | - they are too big (but will work) for background windows |
| 715 | - */ |
| 716 | - shadowSide = 20; |
| 717 | - shadowTop = 10; |
| 718 | - shadowBottom = 24; |
| 719 | - } |
| 720 | - else if (winLevel == kCGSWindowLevelDock) { |
| 721 | - |
| 722 | - /* Create dock icon cache */ |
| 723 | - if (numCachedDockIcons != (i-firstDockIcon) || |
| 724 | - dockIconCacheMiss) { |
| 725 | - |
| 726 | - numCachedDockIcons = i - firstDockIcon; |
| 727 | - SDL_memcpy (dockIcons, &(windows[firstDockIcon]), |
| 728 | - numCachedDockIcons * sizeof(*windows)); |
| 729 | - } |
| 730 | - |
| 731 | - /* no shadow */ |
| 732 | - shadowSide = 0; |
| 733 | - shadowTop = 0; |
| 734 | - shadowBottom = 0; |
| 735 | - } |
| 736 | - else { |
| 737 | - |
| 738 | - /* |
| 739 | - kCGSWindowLevelDockLabel, |
| 740 | - kCGSWindowLevelDock, |
| 741 | - kOther??? |
| 742 | - */ |
| 743 | - |
| 744 | - /* no shadow */ |
| 745 | - shadowSide = 0; |
| 746 | - shadowTop = 0; |
| 747 | - shadowBottom = 0; |
| 748 | - } |
| 749 | - |
| 750 | - CGSGetScreenRectForWindow (cgsConnection, windows[i], &winRect); |
| 751 | - |
| 752 | - winRect.origin.x -= shadowSide; |
| 753 | - winRect.origin.y -= shadowTop; |
| 754 | - winRect.size.width += shadowSide; |
| 755 | - winRect.size.height += shadowBottom; |
| 756 | - |
| 757 | - if (NSIntersectsRect (contentRect, winRect)) { |
| 758 | - |
| 759 | - obscured = SDL_TRUE; |
| 760 | - break; |
| 761 | - } |
| 762 | - |
| 763 | - } /* window was not our window */ |
| 764 | - |
| 765 | - } /* iterate over windows */ |
| 766 | - |
| 767 | - } /* get cgsConnection */ |
| 768 | - |
| 769 | - } /* window is visible */ |
| 770 | - |
| 771 | - return obscured; |
| 772 | -#else |
| 773 | - return SDL_TRUE; |
| 774 | -#endif |
| 775 | -} |
| 776 | - |
| 777 | - |
| 778 | -/* Locking functions for the software window buffer */ |
| 779 | -static int QZ_LockWindow (_THIS, SDL_Surface *surface) { |
| 780 | - |
| 781 | - return LockPortBits ( [ window_view qdPort ] ); |
| 782 | -} |
| 783 | - |
| 784 | -static void QZ_UnlockWindow (_THIS, SDL_Surface *surface) { |
| 785 | - |
| 786 | - UnlockPortBits ( [ window_view qdPort ] ); |
| 787 | -} |
| 788 | - |
| 789 | /* Resize icon, BMP format */ |
| 790 | static const unsigned char QZ_ResizeIcon[] = { |
| 791 | 0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00, |
| 792 | @@ -1393,41 +1155,34 @@ |
| 793 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b |
| 794 | }; |
| 795 | |
| 796 | -static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) { |
| 797 | +static void QZ_DrawResizeIcon (_THIS) { |
| 798 | |
| 799 | /* Check if we should draw the resize icon */ |
| 800 | if (SDL_VideoSurface->flags & SDL_RESIZABLE) { |
| 801 | |
| 802 | - Rect icon; |
| 803 | - SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, |
| 804 | - SDL_VideoSurface->w, SDL_VideoSurface->h); |
| 805 | - |
| 806 | - if (RectInRgn (&icon, dirtyRegion)) { |
| 807 | + SDL_Rect icon_rect; |
| 808 | |
| 809 | - SDL_Rect icon_rect; |
| 810 | + /* Create the icon image */ |
| 811 | + if (resize_icon == NULL) { |
| 812 | + |
| 813 | + SDL_RWops *rw; |
| 814 | + SDL_Surface *tmp; |
| 815 | |
| 816 | - /* Create the icon image */ |
| 817 | - if (resize_icon == NULL) { |
| 818 | + rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon)); |
| 819 | + tmp = SDL_LoadBMP_RW (rw, SDL_TRUE); |
| 820 | + |
| 821 | + resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY); |
| 822 | + SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF); |
| 823 | |
| 824 | - SDL_RWops *rw; |
| 825 | - SDL_Surface *tmp; |
| 826 | - |
| 827 | - rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon)); |
| 828 | - tmp = SDL_LoadBMP_RW (rw, SDL_TRUE); |
| 829 | - |
| 830 | - resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY); |
| 831 | - SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF); |
| 832 | - |
| 833 | - SDL_FreeSurface (tmp); |
| 834 | - } |
| 835 | + SDL_FreeSurface (tmp); |
| 836 | + } |
| 837 | |
| 838 | - icon_rect.x = SDL_VideoSurface->w - 13; |
| 839 | - icon_rect.y = SDL_VideoSurface->h - 13; |
| 840 | - icon_rect.w = 13; |
| 841 | - icon_rect.h = 13; |
| 842 | + icon_rect.x = SDL_VideoSurface->w - 13; |
| 843 | + icon_rect.y = SDL_VideoSurface->h - 13; |
| 844 | + icon_rect.w = 13; |
| 845 | + icon_rect.h = 13; |
| 846 | |
| 847 | - SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect); |
| 848 | - } |
| 849 | + SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | @@ -1441,75 +1196,19 @@ |
| 854 | /* Do nothing if miniaturized */ |
| 855 | } |
| 856 | |
| 857 | - else if ( ! QZ_IsWindowObscured (qz_window) ) { |
| 858 | - |
| 859 | - /* Use direct copy to flush contents to the display */ |
| 860 | - CGrafPtr savePort; |
| 861 | - CGrafPtr dstPort, srcPort; |
| 862 | - const BitMap *dstBits, *srcBits; |
| 863 | - Rect dstRect, srcRect; |
| 864 | - Point offset; |
| 865 | - int i; |
| 866 | - |
| 867 | - GetPort (&savePort); |
| 868 | - |
| 869 | - dstPort = CreateNewPortForCGDisplayID ((UInt32)display_id); |
| 870 | - srcPort = [ window_view qdPort ]; |
| 871 | - |
| 872 | - offset.h = 0; |
| 873 | - offset.v = 0; |
| 874 | - SetPort (srcPort); |
| 875 | - LocalToGlobal (&offset); |
| 876 | - |
| 877 | - SetPort (dstPort); |
| 878 | - |
| 879 | - LockPortBits (dstPort); |
| 880 | - LockPortBits (srcPort); |
| 881 | - |
| 882 | - dstBits = GetPortBitMapForCopyBits (dstPort); |
| 883 | - srcBits = GetPortBitMapForCopyBits (srcPort); |
| 884 | - |
| 885 | - for (i = 0; i < numRects; i++) { |
| 886 | - |
| 887 | - SetRect (&srcRect, rects[i].x, rects[i].y, |
| 888 | - rects[i].x + rects[i].w, |
| 889 | - rects[i].y + rects[i].h); |
| 890 | - |
| 891 | - SetRect (&dstRect, |
| 892 | - rects[i].x + offset.h, |
| 893 | - rects[i].y + offset.v, |
| 894 | - rects[i].x + rects[i].w + offset.h, |
| 895 | - rects[i].y + rects[i].h + offset.v); |
| 896 | - |
| 897 | - CopyBits (srcBits, dstBits, |
| 898 | - &srcRect, &dstRect, srcCopy, NULL); |
| 899 | - |
| 900 | - } |
| 901 | - |
| 902 | - SetPort (savePort); |
| 903 | - } |
| 904 | else { |
| 905 | - /* Use QDFlushPortBuffer() to flush content to display */ |
| 906 | - int i; |
| 907 | - RgnHandle dirty = NewRgn (); |
| 908 | - RgnHandle temp = NewRgn (); |
| 909 | - |
| 910 | - SetEmptyRgn (dirty); |
| 911 | - |
| 912 | - /* Build the region of dirty rectangles */ |
| 913 | - for (i = 0; i < numRects; i++) { |
| 914 | - |
| 915 | - MacSetRectRgn (temp, rects[i].x, rects[i].y, |
| 916 | - rects[i].x + rects[i].w, rects[i].y + rects[i].h); |
| 917 | - MacUnionRgn (dirty, temp, dirty); |
| 918 | - } |
| 919 | - |
| 920 | - QZ_DrawResizeIcon (this, dirty); |
| 921 | + CGContextRef cgc = (CGContextRef) |
| 922 | + [[NSGraphicsContext graphicsContextWithWindow: qz_window] |
| 923 | + graphicsPort]; |
| 924 | + QZ_DrawResizeIcon (this); |
| 925 | + CGContextFlush (cg_context); |
| 926 | + CGImageRef image = CGBitmapContextCreateImage (cg_context); |
| 927 | + CGRect rectangle = CGRectMake (0,0,[window_view frame].size.width,[window_view frame].size.height); |
| 928 | |
| 929 | - /* Flush the dirty region */ |
| 930 | - QDFlushPortBuffer ( [ window_view qdPort ], dirty ); |
| 931 | - DisposeRgn (dirty); |
| 932 | - DisposeRgn (temp); |
| 933 | + CGContextDrawImage (cgc, rectangle, image); |
| 934 | + CGImageRelease(image); |
| 935 | + CGContextFlush (cgc); |
| 936 | + CGContextRelease (cgc); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | Index: src/video/quartz/SDL_QuartzWindow.m |
| 941 | =================================================================== |
| 942 | --- src/video/quartz/SDL_QuartzWindow.m (revision 4718) |
| 943 | +++ src/video/quartz/SDL_QuartzWindow.m (working copy) |
| 944 | @@ -125,31 +125,6 @@ |
| 945 | newViewFrame = [ window_view frame ]; |
| 946 | |
| 947 | SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height); |
| 948 | - |
| 949 | - /* If not OpenGL, we have to update the pixels and pitch */ |
| 950 | - if ( ! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) { |
| 951 | - |
| 952 | - CGrafPtr thePort = [ window_view qdPort ]; |
| 953 | - LockPortBits ( thePort ); |
| 954 | - |
| 955 | - SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) ); |
| 956 | - SDL_VideoSurface->pitch = GetPixRowBytes ( GetPortPixMap ( thePort ) ); |
| 957 | - |
| 958 | - /* |
| 959 | - SDL_VideoSurface->pixels now points to the window's pixels |
| 960 | - We want it to point to the *view's* pixels |
| 961 | - */ |
| 962 | - { |
| 963 | - int vOffset = [ qz_window frame ].size.height - |
| 964 | - newViewFrame.size.height - newViewFrame.origin.y; |
| 965 | - |
| 966 | - int hOffset = newViewFrame.origin.x; |
| 967 | - |
| 968 | - SDL_VideoSurface->pixels = (Uint8 *)SDL_VideoSurface->pixels + (vOffset * SDL_VideoSurface->pitch) + hOffset * (device_bpp/8); |
| 969 | - } |
| 970 | - |
| 971 | - UnlockPortBits ( thePort ); |
| 972 | - } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | @@ -183,7 +158,7 @@ |
| 977 | SDL_PrivateAppActive (1, SDL_APPACTIVE); |
| 978 | } |
| 979 | |
| 980 | -- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag |
| 981 | +- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag |
| 982 | { |
| 983 | /* Make our window subclass receive these application notifications */ |
| 984 | [ [ NSNotificationCenter defaultCenter ] addObserver:self |
| 985 | Index: configure.in |
| 986 | =================================================================== |
| 987 | --- configure.in (revision 4718) |
| 988 | +++ configure.in (working copy) |
| 989 | @@ -2697,7 +2697,8 @@ |
| 990 | fi |
| 991 | if test x$enable_video_carbon = xyes -o x$enable_video_cocoa = xyes; then |
| 992 | # The Cocoa backend still needs Carbon, and the YUV code QuickTime |
| 993 | - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuickTime -Wl,-framework,ApplicationServices" |
| 994 | + dnl EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuickTime -Wl,-framework,ApplicationServices" |
| 995 | + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,ApplicationServices" |
| 996 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon" |
| 997 | fi |
| 998 | # If either the audio or CD driver is used, add the AudioUnit framework |