]> git.sesse.net Git - mlt/commitdiff
Fix leaking OS X Cocoa objects in SDL consumers.
authorDan Dennedy <dan@dennedy.org>
Tue, 18 May 2010 22:50:08 +0000 (15:50 -0700)
committerDan Dennedy <dan@dennedy.org>
Tue, 18 May 2010 22:50:08 +0000 (15:50 -0700)
src/modules/sdl/consumer_sdl_osx.h [new file with mode: 0644]
src/modules/sdl/consumer_sdl_osx.m [new file with mode: 0644]

diff --git a/src/modules/sdl/consumer_sdl_osx.h b/src/modules/sdl/consumer_sdl_osx.h
new file mode 100644 (file)
index 0000000..a3c7349
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * consumer_sdl_osx.m -- An OS X compatibility shim for SDL
+ * Copyright (C) 2010 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _CONSUMER_SDL_OSX_H_
+#define _CONSUMER_SDL_OSX_H_
+
+#ifdef __DARWIN__
+void* mlt_cocoa_autorelease_init();
+void  mlt_cocoa_autorelease_close( void* );
+
+#else
+static inline void *mlt_cocoa_autorelease_init()
+{
+       return NULL;
+}
+
+static inline void mlt_cocoa_autorelease_close(void*)
+{
+}
+#endif
+
+#endif
diff --git a/src/modules/sdl/consumer_sdl_osx.m b/src/modules/sdl/consumer_sdl_osx.m
new file mode 100644 (file)
index 0000000..742f616
--- /dev/null
@@ -0,0 +1,92 @@
+/*\r
+ * consumer_sdl_osx.m -- An OS X compatibility shim for SDL\r
+ * Copyright (C) 2010 Ushodaya Enterprises Limited\r
+ * Author: Dan Dennedy\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#import <Cocoa/Cocoa.h>\r
+\r
+void* mlt_cocoa_autorelease_init()\r
+{\r
+       return [[NSAutoreleasePool alloc] init];\r
+}\r
+\r
+void mlt_cocoa_autorelease_close( void* p )\r
+{\r
+       NSAutoreleasePool* pool = ( NSAutoreleasePool* ) p;\r
+       [pool release];\r
+}\r
+\r
+#if 0\r
+/* The code below is not used at this time - could not get it to work, but\r
+ * it is based on code from gruntster on the avidemux project team.\r
+ */\r
+\r
+#import <Carbon/Carbon.h>\r
+\r
+static NSWindow* nsWindow = nil;\r
+static NSQuickDrawView* nsView = nil;\r
+\r
+void sdl_cocoa_init(void* parent, int x, int y, int width, int height)\r
+{\r
+       NSRect contentRect;\r
+       contentRect = NSMakeRect(x, y, width, height);          \r
+\r
+       if (!nsWindow)\r
+       {\r
+               // initWithWindowRef always returns the same result for the same WindowRef\r
+               nsWindow = [[NSWindow alloc] initWithWindowRef:(WindowRef)parent];\r
+               [nsWindow setContentView:[[[NSView alloc] initWithFrame:contentRect] autorelease]];\r
+       }\r
+\r
+       if (!nsView)\r
+       {\r
+               nsView = [[NSQuickDrawView alloc] initWithFrame:contentRect];\r
+               [[nsWindow contentView] addSubview:nsView];\r
+               [nsView release];\r
+               [nsWindow orderOut:nil];        // very important, otherwise window won't be placed correctly on repeat showings\r
+               [nsWindow orderFront:nil];\r
+       }\r
+       else\r
+       {\r
+               [nsView setFrame:contentRect];\r
+               [[nsWindow contentView] setFrame:contentRect];\r
+       }\r
+\r
+       // finally, set SDL environment variables with all this nonsense\r
+       char SDL_windowhack[20];\r
+       sprintf(SDL_windowhack, "%d", (int)nsWindow);\r
+       setenv("SDL_NSWindowPointer", SDL_windowhack, 1);\r
+       sprintf(SDL_windowhack,"%d", (int)nsView);\r
+       setenv("SDL_NSQuickDrawViewPointer", SDL_windowhack, 1);\r
+}\r
+\r
+void sdl_cocoa_close(void)\r
+{\r
+  if (nsWindow)\r
+  {\r
+       // Reference count cannot fall below 2 because SDL releases the window when closing\r
+         // and again when reinitialising (even though this is our own window...).\r
+         if ([nsWindow retainCount] > 2)\r
+                 [nsWindow release];\r
+\r
+       // SDL takes care of all the destroying...a little too much, so make sure our Carbon\r
+         // window is still displayed (via its Cocoa wrapper)\r
+         [nsWindow makeKeyAndOrderFront:nil];\r
+        }\r
+}\r
+#endif\r