`@autoreleasepool` is the newer (although still 10+ years old) way of creating ObjC autorelease pools. It allows simpler control flow, is possibly more efficient, and is a prerequisite to adopting ARC (no immediate plans for that, but it could happen in the future).
I didn't add an indentation level for `@autoreleasepool` blocks covering a whole function (the common case by far), but did indent smaller blocks.
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/winemac.drv/cocoa_app.m | 64 +++++++++--------- dlls/winemac.drv/cocoa_clipboard.m | 5 +- dlls/winemac.drv/cocoa_display.m | 21 +++--- dlls/winemac.drv/cocoa_event.m | 57 ++++++++-------- dlls/winemac.drv/cocoa_main.m | 54 ++++++++------- dlls/winemac.drv/cocoa_opengl.m | 29 ++++---- dlls/winemac.drv/cocoa_window.m | 105 +++++++++++++++-------------- 7 files changed, 172 insertions(+), 163 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m index 5a6a3e01005..5b5050f70fa 100644 --- a/dlls/winemac.drv/cocoa_app.m +++ b/dlls/winemac.drv/cocoa_app.m @@ -333,14 +333,15 @@ static NSString* WineLocalizedString(unsigned int stringID) { if (processEvents) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny - untilDate:timeout - inMode:NSDefaultRunLoopMode - dequeue:YES]; - if (event) - [NSApp sendEvent:event]; - [pool release]; + @autoreleasepool + { + NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny + untilDate:timeout + inMode:NSDefaultRunLoopMode + dequeue:YES]; + if (event) + [NSApp sendEvent:event]; + } } else [[NSRunLoop currentRunLoop] runMode:WineAppWaitQueryResponseMode beforeDate:timeout]; @@ -2281,34 +2282,34 @@ static NSString* WineLocalizedString(unsigned int stringID) */ static void PerformRequest(void *info) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineApplicationController* controller = [WineApplicationController sharedController];
for (;;) { - __block dispatch_block_t block; - - dispatch_sync(controller->requestsManipQueue, ^{ - if ([controller->requests count]) - { - block = (dispatch_block_t)[[controller->requests objectAtIndex:0] retain]; - [controller->requests removeObjectAtIndex:0]; - } - else - block = nil; - }); + @autoreleasepool + { + __block dispatch_block_t block;
- if (!block) - break; + dispatch_sync(controller->requestsManipQueue, ^{ + if ([controller->requests count]) + { + block = (dispatch_block_t)[[controller->requests objectAtIndex:0] retain]; + [controller->requests removeObjectAtIndex:0]; + } + else + block = nil; + });
- block(); - [block release]; + if (!block) + break;
- [pool release]; - pool = [[NSAutoreleasePool alloc] init]; + block(); + [block release]; + } } - - [pool release]; +} }
/*********************************************************************** @@ -2347,13 +2348,12 @@ void LogError(const char* func, NSString* format, ...) */ void LogErrorv(const char* func, NSString* format, va_list args) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - +@autoreleasepool +{ NSString* message = [[NSString alloc] initWithFormat:format arguments:args]; fprintf(stderr, "err:%s:%s", func, [message UTF8String]); [message release]; - - [pool release]; +} }
/*********************************************************************** diff --git a/dlls/winemac.drv/cocoa_clipboard.m b/dlls/winemac.drv/cocoa_clipboard.m index 30f3097c3d2..c2a2dac4909 100644 --- a/dlls/winemac.drv/cocoa_clipboard.m +++ b/dlls/winemac.drv/cocoa_clipboard.m @@ -87,10 +87,11 @@ int macdrv_has_pasteboard_changed(void) * releasing the returned array with CFRelease(). */ CFArrayRef macdrv_copy_pasteboard_types(CFTypeRef pasteboard) +{ +@autoreleasepool { NSPasteboard* pb = (NSPasteboard*)pasteboard; __block CFArrayRef ret = NULL; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
dispatch_once(&BitmapOutputTypesInitOnce, ^{ NSArray* bitmapFileTypes = [NSArray arrayWithObjects: @@ -138,9 +139,9 @@ CFArrayRef macdrv_copy_pasteboard_types(CFTypeRef pasteboard) } });
- [pool release]; return ret; } +}
/*********************************************************************** diff --git a/dlls/winemac.drv/cocoa_display.m b/dlls/winemac.drv/cocoa_display.m index 81c92f63448..5932e8070b1 100644 --- a/dlls/winemac.drv/cocoa_display.m +++ b/dlls/winemac.drv/cocoa_display.m @@ -57,9 +57,10 @@ static inline void convert_display_rect(CGRect* out_rect, NSRect in_rect, * Returns non-zero on failure and *displays and *count are unchanged. */ int macdrv_get_displays(struct macdrv_display** displays, int* count) +{ +@autoreleasepool { int ret = -1; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray* screens = [NSScreen screens]; if (screens) @@ -95,9 +96,9 @@ int macdrv_get_displays(struct macdrv_display** displays, int* count) } }
- [pool release]; return ret; } +}
/*********************************************************************** @@ -190,12 +191,13 @@ done: * Returns non-zero value on failure. */ static int macdrv_get_gpu_info_from_entry(struct macdrv_gpu* gpu, io_registry_entry_t entry) +{ +@autoreleasepool { io_registry_entry_t parent_entry; io_registry_entry_t gpu_entry; kern_return_t result; int ret = -1; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
gpu_entry = entry; while (![@"IOPCIDevice" isEqualToString:[(NSString*)IOObjectCopyClass(gpu_entry) autorelease]]) @@ -211,7 +213,6 @@ static int macdrv_get_gpu_info_from_entry(struct macdrv_gpu* gpu, io_registry_en } else if (result != kIOReturnSuccess) { - [pool release]; return ret; }
@@ -232,9 +233,9 @@ static int macdrv_get_gpu_info_from_entry(struct macdrv_gpu* gpu, io_registry_en done: if (gpu_entry != entry) IOObjectRelease(gpu_entry); - [pool release]; return ret; } +}
#ifdef HAVE_MTLDEVICE_REGISTRYID
@@ -297,6 +298,8 @@ static int macdrv_get_gpu_info_from_mtldevice(struct macdrv_gpu* gpu, id<MTLDevi * Returns non-zero value on failure with parameters unchanged and zero on success. */ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count) +{ +@autoreleasepool { struct macdrv_gpu* gpus = NULL; struct macdrv_gpu primary_gpu; @@ -305,7 +308,6 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count) int primary_index = 0, i; int gpu_count = 0; int ret = -1; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
/* Test if Metal is available */ if (&MTLCopyAllDevices == NULL) @@ -364,9 +366,9 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count) done: if (ret) macdrv_free_gpus(gpus); - [pool release]; return ret; } +}
/*********************************************************************** * macdrv_get_gpu_info_from_display_id_using_metal @@ -376,10 +378,11 @@ done: * Returns non-zero value on failure. */ static int macdrv_get_gpu_info_from_display_id_using_metal(struct macdrv_gpu* gpu, CGDirectDisplayID display_id) +{ +@autoreleasepool { id<MTLDevice> device; int ret = -1; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
/* Test if Metal is available */ if (&CGDirectDisplayCopyCurrentMetalDevice == NULL) @@ -390,9 +393,9 @@ static int macdrv_get_gpu_info_from_display_id_using_metal(struct macdrv_gpu* gp ret = macdrv_get_gpu_info_from_registry_id(gpu, device.registryID);
done: - [pool release]; return ret; } +}
#else
diff --git a/dlls/winemac.drv/cocoa_event.m b/dlls/winemac.drv/cocoa_event.m index 24f69b17a0a..1797d69f305 100644 --- a/dlls/winemac.drv/cocoa_event.m +++ b/dlls/winemac.drv/cocoa_event.m @@ -292,7 +292,8 @@ static const OSType WineHotKeySignature = 'Wine';
- (void) discardEventsPassingTest:(BOOL (^)(macdrv_event* event))block { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + @autoreleasepool + { NSIndexSet* indexes;
[eventsLock lock]; @@ -305,8 +306,7 @@ static const OSType WineHotKeySignature = 'Wine'; [events removeObjectsAtIndexes:indexes];
[eventsLock unlock]; - - [pool release]; + } }
- (void) discardEventsMatchingMask:(macdrv_event_mask)mask forWindow:(NSWindow*)window @@ -494,7 +494,8 @@ static const OSType WineHotKeySignature = 'Wine'; */ void OnMainThread(dispatch_block_t block) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary]; WineEventQueue* queue = [threadDict objectForKey:WineEventQueueThreadDictionaryKey]; dispatch_semaphore_t semaphore = NULL; @@ -523,21 +524,19 @@ void OnMainThread(dispatch_block_t block) { while (!finished) { - MacDrvEvent* macDrvEvent; - struct kevent kev; - - while (!finished && - (macDrvEvent = [queue getEventMatchingMask:event_mask_for_type(QUERY_EVENT)])) + @autoreleasepool { - queue->event_handler(macDrvEvent->event); - } + MacDrvEvent* macDrvEvent; + struct kevent kev;
- if (!finished) - { - [pool release]; - pool = [[NSAutoreleasePool alloc] init]; + while (!finished && + (macDrvEvent = [queue getEventMatchingMask:event_mask_for_type(QUERY_EVENT)])) + { + queue->event_handler(macDrvEvent->event); + }
- kevent(queue->kq, NULL, 0, &kev, 1, NULL); + if (!finished) + kevent(queue->kq, NULL, 0, &kev, 1, NULL); } } } @@ -546,8 +545,7 @@ void OnMainThread(dispatch_block_t block) dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); dispatch_release(semaphore); } - - [pool release]; +} }
@@ -559,7 +557,8 @@ void OnMainThread(dispatch_block_t block) */ macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
WineEventQueue* queue = [threadDict objectForKey:WineEventQueueThreadDictionaryKey]; @@ -575,9 +574,9 @@ macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler) } }
- [pool release]; return (macdrv_event_queue)queue; } +}
/*********************************************************************** * macdrv_destroy_event_queue @@ -587,14 +586,14 @@ macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler) */ void macdrv_destroy_event_queue(macdrv_event_queue queue) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineEventQueue* q = (WineEventQueue*)queue; NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
[[WineApplicationController sharedController] unregisterEventQueue:q]; [threadDict removeObjectForKey:WineEventQueueThreadDictionaryKey]; - - [pool release]; +} }
/*********************************************************************** @@ -622,16 +621,17 @@ int macdrv_get_event_queue_fd(macdrv_event_queue queue) int macdrv_copy_event_from_queue(macdrv_event_queue queue, macdrv_event_mask mask, macdrv_event **event) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineEventQueue* q = (WineEventQueue*)queue;
MacDrvEvent* macDrvEvent = [q getEventMatchingMask:mask]; if (macDrvEvent) *event = macdrv_retain_event(macDrvEvent->event);
- [pool release]; return (macDrvEvent != nil); } +}
/*********************************************************************** * macdrv_create_event @@ -665,11 +665,11 @@ macdrv_event* macdrv_retain_event(macdrv_event *event) * objects, held by the event and deallocates it */ void macdrv_release_event(macdrv_event *event) +{ +@autoreleasepool { if (OSAtomicDecrement32Barrier(&event->refs) <= 0) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - switch (event->type) { case IM_SET_TEXT: @@ -691,10 +691,9 @@ void macdrv_release_event(macdrv_event *event)
[(WineWindow*)event->window release]; free(event); - - [pool release]; } } +}
/*********************************************************************** * macdrv_create_query diff --git a/dlls/winemac.drv/cocoa_main.m b/dlls/winemac.drv/cocoa_main.m index 6682f98759b..73a2514a61a 100644 --- a/dlls/winemac.drv/cocoa_main.m +++ b/dlls/winemac.drv/cocoa_main.m @@ -64,35 +64,37 @@ static void run_cocoa_app(void* info) NSConditionLock* lock = startup_info->lock; BOOL created_app = FALSE;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - if (!NSApp) - { - [WineApplication sharedApplication]; - created_app = TRUE; - } - - if ([NSApp respondsToSelector:@selector(setWineController:)]) + @autoreleasepool { - WineApplicationController* controller = [WineApplicationController sharedController]; - [NSApp setWineController:controller]; - [controller computeEventTimeAdjustmentFromTicks:startup_info->tickcount uptime:startup_info->uptime_ns]; - startup_info->success = TRUE; - } + if (!NSApp) + { + [WineApplication sharedApplication]; + created_app = TRUE; + }
- /* Retain the lock while we're using it, so macdrv_start_cocoa_app() - doesn't deallocate it in the middle of us unlocking it. */ - [lock retain]; - [lock lock]; - [lock unlockWithCondition:COCOA_APP_RUNNING]; - [lock release]; + if ([NSApp respondsToSelector:@selector(setWineController:)]) + { + WineApplicationController* controller = [WineApplicationController sharedController]; + [NSApp setWineController:controller]; + [controller computeEventTimeAdjustmentFromTicks:startup_info->tickcount uptime:startup_info->uptime_ns]; + startup_info->success = TRUE; + }
- [pool release]; + /* Retain the lock while we're using it, so macdrv_start_cocoa_app() + doesn't deallocate it in the middle of us unlocking it. */ + [lock retain]; + [lock lock]; + [lock unlockWithCondition:COCOA_APP_RUNNING]; + [lock release]; + }
if (created_app && startup_info->success) { - /* Never returns */ - [NSApp run]; + @autoreleasepool + { + /* Never returns */ + [NSApp run]; + } } }
@@ -105,6 +107,8 @@ static void run_cocoa_app(void* info) * Returns 0 on success, non-zero on failure. */ int macdrv_start_cocoa_app(unsigned long long tickcount) +{ +@autoreleasepool { int ret = -1; CFRunLoopSourceRef source; @@ -114,8 +118,6 @@ int macdrv_start_cocoa_app(unsigned long long tickcount) NSDate* timeLimit; CFRunLoopSourceContext source_context = { 0 };
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - /* Make sure Cocoa is in multi-threading mode by detaching a do-nothing thread. */ [NSThread detachNewThreadSelector:@selector(self) @@ -151,6 +153,6 @@ int macdrv_start_cocoa_app(unsigned long long tickcount) if (source) CFRelease(source); [startup_info.lock release]; - [pool release]; return ret; } +} diff --git a/dlls/winemac.drv/cocoa_opengl.m b/dlls/winemac.drv/cocoa_opengl.m index ce8788b4269..43574972600 100644 --- a/dlls/winemac.drv/cocoa_opengl.m +++ b/dlls/winemac.drv/cocoa_opengl.m @@ -242,14 +242,15 @@ */ macdrv_opengl_context macdrv_create_opengl_context(void* cglctx) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineOpenGLContext *context;
context = [[WineOpenGLContext alloc] initWithCGLContextObj:cglctx];
- [pool release]; return (macdrv_opengl_context)context; } +}
/*********************************************************************** * macdrv_dispose_opengl_context @@ -259,13 +260,13 @@ macdrv_opengl_context macdrv_create_opengl_context(void* cglctx) */ void macdrv_dispose_opengl_context(macdrv_opengl_context c) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineOpenGLContext *context = (WineOpenGLContext*)c;
[context removeFromViews:YES]; [context release]; - - [pool release]; +} }
/*********************************************************************** @@ -273,7 +274,8 @@ void macdrv_dispose_opengl_context(macdrv_opengl_context c) */ void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v, CGRect r) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineOpenGLContext *context = (WineOpenGLContext*)c; NSView* view = (NSView*)v;
@@ -328,8 +330,7 @@ void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v, CGRect if (context) [context removeFromViews:YES]; } - - [pool release]; +} }
/*********************************************************************** @@ -337,7 +338,8 @@ void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v, CGRect */ void macdrv_update_opengl_context(macdrv_opengl_context c) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineOpenGLContext *context = (WineOpenGLContext*)c;
if (context.needsUpdate) @@ -367,8 +369,7 @@ void macdrv_update_opengl_context(macdrv_opengl_context c) [context resetSurfaceIfBackingSizeChanged]; } } - - [pool release]; +} }
/*********************************************************************** @@ -379,11 +380,11 @@ void macdrv_update_opengl_context(macdrv_opengl_context c) */ void macdrv_flush_opengl_context(macdrv_opengl_context c) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineOpenGLContext *context = (WineOpenGLContext*)c;
macdrv_update_opengl_context(c); [context flushBuffer]; - - [pool release]; +} } diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index cc9a9e13c2b..4109377527c 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -3282,7 +3282,8 @@ macdrv_window macdrv_create_cocoa_window(const struct macdrv_window_features* wf */ void macdrv_destroy_cocoa_window(macdrv_window w) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ @@ -3292,8 +3293,7 @@ void macdrv_destroy_cocoa_window(macdrv_window w) }); [window.queue discardEventsMatchingMask:-1 forWindow:window]; [window release]; - - [pool release]; +} }
/*********************************************************************** @@ -3345,7 +3345,8 @@ void macdrv_set_cocoa_window_state(macdrv_window w, void macdrv_set_cocoa_window_title(macdrv_window w, const unsigned short* title, size_t length) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w; NSString* titleString;
@@ -3358,8 +3359,7 @@ void macdrv_set_cocoa_window_title(macdrv_window w, const unsigned short* title, if ([window isOrderedIn] && ![window isExcludedFromWindowsMenu]) [NSApp changeWindowsItem:window title:titleString filename:NO]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3454,15 +3454,15 @@ void macdrv_set_cocoa_parent_window(macdrv_window w, macdrv_window parent) */ void macdrv_set_window_surface(macdrv_window w, void *surface, pthread_mutex_t *mutex) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ window.surface = surface; window.surface_mutex = mutex; }); - - [pool release]; +} }
/*********************************************************************** @@ -3473,14 +3473,14 @@ void macdrv_set_window_surface(macdrv_window w, void *surface, pthread_mutex_t * */ void macdrv_window_needs_display(macdrv_window w, CGRect rect) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThreadAsync(^{ [[window contentView] setNeedsDisplayInRect:NSRectFromCGRect(cgrect_mac_from_win(rect))]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3491,7 +3491,8 @@ void macdrv_window_needs_display(macdrv_window w, CGRect rect) */ void macdrv_set_window_shape(macdrv_window w, const CGRect *rects, int count) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ @@ -3512,8 +3513,7 @@ void macdrv_set_window_shape(macdrv_window w, const CGRect *rects, int count) CGPathRelease(path); } }); - - [pool release]; +} }
/*********************************************************************** @@ -3521,12 +3521,12 @@ void macdrv_set_window_shape(macdrv_window w, const CGRect *rects, int count) */ void macdrv_set_window_alpha(macdrv_window w, CGFloat alpha) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
[window setAlphaValue:alpha]; - - [pool release]; +} }
/*********************************************************************** @@ -3535,7 +3535,8 @@ void macdrv_set_window_alpha(macdrv_window w, CGFloat alpha) void macdrv_set_window_color_key(macdrv_window w, CGFloat keyRed, CGFloat keyGreen, CGFloat keyBlue) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ @@ -3545,8 +3546,7 @@ void macdrv_set_window_color_key(macdrv_window w, CGFloat keyRed, CGFloat keyGre window.colorKeyBlue = keyBlue; [window checkTransparency]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3554,15 +3554,15 @@ void macdrv_set_window_color_key(macdrv_window w, CGFloat keyRed, CGFloat keyGre */ void macdrv_clear_window_color_key(macdrv_window w) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ window.colorKeyed = FALSE; [window checkTransparency]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3570,15 +3570,15 @@ void macdrv_clear_window_color_key(macdrv_window w) */ void macdrv_window_use_per_pixel_alpha(macdrv_window w, int use_per_pixel_alpha) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineWindow* window = (WineWindow*)w;
OnMainThread(^{ window.usePerPixelAlpha = use_per_pixel_alpha; [window checkTransparency]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3620,7 +3620,8 @@ void macdrv_set_window_min_max_sizes(macdrv_window w, CGSize min_size, CGSize ma */ macdrv_view macdrv_create_view(CGRect rect) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ __block WineContentView* view;
if (CGRectIsNull(rect)) rect = CGRectZero; @@ -3642,9 +3643,9 @@ macdrv_view macdrv_create_view(CGRect rect) object:NSApp]; });
- [pool release]; return (macdrv_view)view; } +}
/*********************************************************************** * macdrv_dispose_view @@ -3653,7 +3654,8 @@ macdrv_view macdrv_create_view(CGRect rect) */ void macdrv_dispose_view(macdrv_view v) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v;
OnMainThread(^{ @@ -3670,8 +3672,7 @@ void macdrv_dispose_view(macdrv_view v) [view release]; [window updateForGLSubviews]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3679,7 +3680,8 @@ void macdrv_dispose_view(macdrv_view v) */ void macdrv_set_view_frame(macdrv_view v, CGRect rect) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v;
if (CGRectIsNull(rect)) rect = CGRectZero; @@ -3707,8 +3709,7 @@ void macdrv_set_view_frame(macdrv_view v, CGRect rect) [(WineWindow*)[view window] updateForGLSubviews]; } }); - - [pool release]; +} }
/*********************************************************************** @@ -3721,7 +3722,8 @@ void macdrv_set_view_frame(macdrv_view v, CGRect rect) */ void macdrv_set_view_superview(macdrv_view v, macdrv_view s, macdrv_window w, macdrv_view p, macdrv_view n) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v; WineContentView* superview = (WineContentView*)s; WineWindow* window = (WineWindow*)w; @@ -3762,8 +3764,7 @@ void macdrv_set_view_superview(macdrv_view v, macdrv_view s, macdrv_window w, ma [newWindow updateForGLSubviews]; } }); - - [pool release]; +} }
/*********************************************************************** @@ -3771,15 +3772,15 @@ void macdrv_set_view_superview(macdrv_view v, macdrv_view s, macdrv_window w, ma */ void macdrv_set_view_hidden(macdrv_view v, int hidden) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v;
OnMainThreadAsync(^{ [view setHidden:hidden]; [(WineWindow*)view.window updateForGLSubviews]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3789,15 +3790,15 @@ void macdrv_set_view_hidden(macdrv_view v, int hidden) */ void macdrv_add_view_opengl_context(macdrv_view v, macdrv_opengl_context c) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v; WineOpenGLContext *context = (WineOpenGLContext*)c;
OnMainThread(^{ [view addGLContext:context]; }); - - [pool release]; +} }
/*********************************************************************** @@ -3807,18 +3808,20 @@ void macdrv_add_view_opengl_context(macdrv_view v, macdrv_opengl_context c) */ void macdrv_remove_view_opengl_context(macdrv_view v, macdrv_opengl_context c) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ WineContentView* view = (WineContentView*)v; WineOpenGLContext *context = (WineOpenGLContext*)c;
OnMainThreadAsync(^{ [view removeGLContext:context]; }); - - [pool release]; +} }
macdrv_metal_device macdrv_create_metal_device(void) +{ +@autoreleasepool { macdrv_metal_device ret;
@@ -3827,17 +3830,17 @@ macdrv_metal_device macdrv_create_metal_device(void) return NULL; #endif
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; ret = (macdrv_metal_device)MTLCreateSystemDefaultDevice(); - [pool release]; return ret; } +}
void macdrv_release_metal_device(macdrv_metal_device d) { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; +@autoreleasepool +{ [(id<MTLDevice>)d release]; - [pool release]; +} }
macdrv_metal_view macdrv_view_create_metal_view(macdrv_view v, macdrv_metal_device d)
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/winemac.drv/cocoa_display.m | 36 +++++++++++++------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_display.m b/dlls/winemac.drv/cocoa_display.m index 5932e8070b1..2f3d86b51d5 100644 --- a/dlls/winemac.drv/cocoa_display.m +++ b/dlls/winemac.drv/cocoa_display.m @@ -60,8 +60,6 @@ int macdrv_get_displays(struct macdrv_display** displays, int* count) { @autoreleasepool { - int ret = -1; - NSArray* screens = [NSScreen screens]; if (screens) { @@ -92,11 +90,11 @@ int macdrv_get_displays(struct macdrv_display** displays, int* count)
*displays = disps; *count = num_screens; - ret = 0; + return 0; } }
- return ret; + return -1; } }
@@ -307,25 +305,24 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count) BOOL hide_integrated = FALSE; int primary_index = 0, i; int gpu_count = 0; - int ret = -1;
/* Test if Metal is available */ if (&MTLCopyAllDevices == NULL) - goto done; + return -1; NSArray<id<MTLDevice>>* devices = [MTLCopyAllDevices() autorelease]; if (!devices.count || ![devices[0] respondsToSelector:@selector(registryID)]) - goto done; + return -1;
gpus = calloc(devices.count, sizeof(*gpus)); if (!gpus) - goto done; + return -1;
/* Use MTLCreateSystemDefaultDevice instead of CGDirectDisplayCopyCurrentMetalDevice(CGMainDisplayID()) to get * the primary GPU because we need to hide the integrated GPU for an automatic graphic switching pair to avoid apps * using the integrated GPU. This is the behavior of Windows on a Mac. */ primary_device = [MTLCreateSystemDefaultDevice() autorelease]; if (macdrv_get_gpu_info_from_mtldevice(&primary_gpu, primary_device)) - goto done; + goto fail;
/* Hide the integrated GPU if the system default device is a dedicated GPU */ if (!primary_device.isLowPower) @@ -337,7 +334,7 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count) for (i = 0; i < devices.count; i++) { if (macdrv_get_gpu_info_from_mtldevice(&gpus[gpu_count], devices[i])) - goto done; + goto fail;
if (hide_integrated && devices[i].isLowPower) { @@ -362,11 +359,10 @@ static int macdrv_get_gpus_from_metal(struct macdrv_gpu** new_gpus, int* count)
*new_gpus = gpus; *count = gpu_count; - ret = 0; -done: - if (ret) - macdrv_free_gpus(gpus); - return ret; + return 0; +fail: + macdrv_free_gpus(gpus); + return -1; } }
@@ -382,18 +378,16 @@ static int macdrv_get_gpu_info_from_display_id_using_metal(struct macdrv_gpu* gp @autoreleasepool { id<MTLDevice> device; - int ret = -1;
/* Test if Metal is available */ if (&CGDirectDisplayCopyCurrentMetalDevice == NULL) - goto done; + return -1;
device = [CGDirectDisplayCopyCurrentMetalDevice(display_id) autorelease]; if (device && [device respondsToSelector:@selector(registryID)]) - ret = macdrv_get_gpu_info_from_registry_id(gpu, device.registryID); - -done: - return ret; + return macdrv_get_gpu_info_from_registry_id(gpu, device.registryID); + else + return -1; } }