Commit 0fbf84d6 authored by Ken Martin's avatar Ken Martin Committed by Code Review

Merge topic 'cocoa-arc' into master

dd3f20db Added partial/initial support for Cocoa ARC memory management
parents 088ff85d dd3f20db
......@@ -34,6 +34,22 @@ PURPOSE. See the above copyright notice for more information.
#define __has_feature(x) 0
#endif
// Create handy #defines that indicate the Objective-C memory management model.
// Manual Retain Release, Automatic Reference Counting, or Garbage Collection.
#if defined(__OBJC_GC__)
#define VTK_OBJC_IS_MRR 0
#define VTK_OBJC_IS_ARC 0
#define VTK_OBJC_IS_GC 1
#elif __has_feature(objc_arc)
#define VTK_OBJC_IS_MRR 0
#define VTK_OBJC_IS_ARC 1
#define VTK_OBJC_IS_GC 0
#else
#define VTK_OBJC_IS_MRR 1
#define VTK_OBJC_IS_ARC 0
#define VTK_OBJC_IS_GC 0
#endif
#if __has_feature(objc_arc)
#error VTK does not yet support ARC memory management
#endif
......
......@@ -21,7 +21,7 @@ PURPOSE. See the above copyright notice for more information.
// To use this class, build VTK with VTK_USE_COCOA turned ON (this is
// the default).
// This class can be used by 32 and 64 bit processes, and either in
// garbage collected or reference counted modes. ARC is not supported.
// garbage collected or reference counted modes. ARC is not yet supported.
// vtkCocoaRenderWindow uses Objective-C++, and the OpenGL and
// Cocoa APIs. This class's default behaviour is to create an NSWindow and
// a vtkCocoaGLView which are used together to draw all VTK content.
......
......@@ -828,7 +828,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
[parent addSubview:glView];
this->SetWindowId(glView);
this->ViewCreated = 1;
#if VTK_OBJC_IS_MRR
[glView release];
#endif
}
else
{
......@@ -842,7 +844,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
this->SetWindowId(glView);
this->ViewCreated = 1;
[glView setVTKRenderWindow:this];
#if VTK_OBJC_IS_MRR
[glView release];
#endif
}
}
......@@ -883,7 +887,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
vtkCocoaServer *server = [[vtkCocoaServer alloc] initWithRenderWindow:this];
this->SetCocoaServer(reinterpret_cast<void *>(server));
[server start];
#if VTK_OBJC_IS_MRR
[server release];
#endif
}
//----------------------------------------------------------------------------
......@@ -954,8 +960,10 @@ void vtkCocoaRenderWindow::CreateGLContext()
[pixelFormat self]; // prevent premature collection under GC.
[context self]; // prevent premature collection under GC.
#if VTK_OBJC_IS_MRR
[pixelFormat release];
[context release];
#endif
}
//----------------------------------------------------------------------------
......
......@@ -152,7 +152,9 @@ static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
selector:@selector(timerFired:)
userInfo:nil
repeats:repeating];
#if VTK_OBJC_IS_MRR
[_timer retain];
#endif
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:_timer forMode:NSDefaultRunLoopMode];
......@@ -163,7 +165,9 @@ static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
- (void)stopTimer
{
[_timer invalidate];
#if VTK_OBJC_IS_MRR
[_timer release];
#endif
_timer = nil;
}
......@@ -339,6 +343,9 @@ int vtkCocoaRenderWindowInteractor::InternalCreateTimer(int timerId,
[timerDict setObject:cocoaTimer forKey:timerIdAsStr];
[cocoaTimer startTimerWithInterval:((NSTimeInterval)duration/1000.0)
repeating:repeating];
#if VTK_OBJC_IS_MRR
[cocoaTimer release];
#endif
// In this implementation, timerId and platformTimerId are the same
int platformTimerId = timerId;
......@@ -356,12 +363,11 @@ int vtkCocoaRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
NSString *timerIdAsStr = [NSString stringWithFormat:@"%i", timerId];
NSMutableDictionary *timerDict = (NSMutableDictionary*)(this->GetTimerDictionary());
vtkCocoaTimer* cocoaTimer = [timerDict objectForKey:timerIdAsStr];
[timerDict removeObjectForKey:timerIdAsStr];
if (nil != cocoaTimer)
{
[cocoaTimer stopTimer];
[cocoaTimer release];
[timerDict removeObjectForKey:timerIdAsStr];
return 1; // success
}
else
......
......@@ -34,6 +34,22 @@ PURPOSE. See the above copyright notice for more information.
#define __has_feature(x) 0
#endif
// Create handy #defines that indicate the Objective-C memory management model.
// Manual Retain Release, Automatic Reference Counting, or Garbage Collection.
#if defined(__OBJC_GC__)
#define VTK_OBJC_IS_MRR 0
#define VTK_OBJC_IS_ARC 0
#define VTK_OBJC_IS_GC 1
#elif __has_feature(objc_arc)
#define VTK_OBJC_IS_MRR 0
#define VTK_OBJC_IS_ARC 1
#define VTK_OBJC_IS_GC 0
#else
#define VTK_OBJC_IS_MRR 1
#define VTK_OBJC_IS_ARC 0
#define VTK_OBJC_IS_GC 0
#endif
#if __has_feature(objc_arc)
#error VTK does not yet support ARC memory management
#endif
......
......@@ -21,7 +21,7 @@ PURPOSE. See the above copyright notice for more information.
// To use this class, build VTK with VTK_USE_COCOA turned ON (this is
// the default).
// This class can be used by 32 and 64 bit processes, and either in
// garbage collected or reference counted modes. ARC is not supported.
// garbage collected or reference counted modes. ARC is not yet supported.
// vtkCocoaRenderWindow uses Objective-C++, and the OpenGL and
// Cocoa APIs. This class's default behaviour is to create an NSWindow and
// a vtkCocoaGLView which are used together to draw all VTK content.
......
......@@ -809,7 +809,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
[parent addSubview:glView];
this->SetWindowId(glView);
this->ViewCreated = 1;
#if VTK_OBJC_IS_MRR
[glView release];
#endif
}
else
{
......@@ -823,7 +825,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
this->SetWindowId(glView);
this->ViewCreated = 1;
[glView setVTKRenderWindow:this];
#if VTK_OBJC_IS_MRR
[glView release];
#endif
}
}
......@@ -864,7 +868,9 @@ void vtkCocoaRenderWindow::CreateAWindow()
vtkCocoaServer *server = [[vtkCocoaServer alloc] initWithRenderWindow:this];
this->SetCocoaServer(reinterpret_cast<void *>(server));
[server start];
#if VTK_OBJC_IS_MRR
[server release];
#endif
}
//----------------------------------------------------------------------------
......@@ -935,8 +941,10 @@ void vtkCocoaRenderWindow::CreateGLContext()
[pixelFormat self]; // prevent premature collection under GC.
[context self]; // prevent premature collection under GC.
#if VTK_OBJC_IS_MRR
[pixelFormat release];
[context release];
#endif
}
//----------------------------------------------------------------------------
......
......@@ -152,7 +152,9 @@ static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
selector:@selector(timerFired:)
userInfo:nil
repeats:repeating];
#if VTK_OBJC_IS_MRR
[_timer retain];
#endif
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:_timer forMode:NSDefaultRunLoopMode];
......@@ -163,7 +165,9 @@ static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
- (void)stopTimer
{
[_timer invalidate];
#if VTK_OBJC_IS_MRR
[_timer release];
#endif
_timer = nil;
}
......@@ -339,6 +343,9 @@ int vtkCocoaRenderWindowInteractor::InternalCreateTimer(int timerId,
[timerDict setObject:cocoaTimer forKey:timerIdAsStr];
[cocoaTimer startTimerWithInterval:((NSTimeInterval)duration/1000.0)
repeating:repeating];
#if VTK_OBJC_IS_MRR
[cocoaTimer release];
#endif
// In this implementation, timerId and platformTimerId are the same
int platformTimerId = timerId;
......@@ -356,12 +363,11 @@ int vtkCocoaRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
NSString *timerIdAsStr = [NSString stringWithFormat:@"%i", timerId];
NSMutableDictionary *timerDict = (NSMutableDictionary*)(this->GetTimerDictionary());
vtkCocoaTimer* cocoaTimer = [timerDict objectForKey:timerIdAsStr];
[timerDict removeObjectForKey:timerIdAsStr];
if (nil != cocoaTimer)
{
[cocoaTimer stopTimer];
[cocoaTimer release];
[timerDict removeObjectForKey:timerIdAsStr];
return 1; // success
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment