OK, it appears that dramatic hacks are not necessary to make Cocoa work...
authorEli Gottlieb <eligottlieb@gmail.com>
Mon, 26 Jul 2010 20:41:45 -0400
changeset 4810 7a602fd2121f
parent 4809 329708ffe2a7
child 4811 d79939f20c45
OK, it appears that dramatic hacks are not necessary to make Cocoa work...
TODO
src/video/SDL_shape.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoavideo.m
src/video/win32/SDL_win32video.c
src/video/x11/SDL_x11video.c
--- a/TODO	Mon Jul 26 17:27:04 2010 -0400
+++ b/TODO	Mon Jul 26 20:41:45 2010 -0400
@@ -1,20 +1,21 @@
 Eli Gottlieb's checklist for the GSOC shaped windows project.  Dated July 9, 2010.
 1. Enable proper linking of the X11 implementation and test it.
---> Find the place in the build system for platform-specific linking flags.  STATUS: BLOODY IMPOSSIBLE.
---> Add a linker flag to bring in libXext.a. STATUS: WILL BE SIMPLE ONCE PREVIOUS STEP IS ACCOMPLISHED (kshemashiach yagia).
+--> Find the place in the build system for platform-specific linking flags.  STATUS: DONE
+--> Add a linker flag to bring in libXext.a. STATUS: DONE.
 2. Build the Win32 implementation of shaped-windows functionality.
 --> Add driver functions to the SDL_ShapeDriver in the Win32 driver's SDL_DisplayDevice at the proper point in the code.  STATUS: CHECK.
 --> Add a hook in the Windows resize-window code to call Win32_ResizeWindowShape().  STATUS: CHECK.
+--> Get the Windows code to build and run properly.  STATUS: IN PROGRESS.
 3. Enable building the testeyes program.
 --> Reprogram it to use the latest shaped-windows API.  STATUS: CHECK.
---> Get it, along with the rest of the test suite in my branch, building successfully.  STATUS: REQUIRES X11 IMPLEMENTATION TO LINK PROPERLY AND/OR A BUILD-BUDDY BUILDING AND RUNNING THE TEST FOR ME.
---> Debug testeyes and the platform-specific shaped-window implementations in tandem.  STATUS: TO BEGIN, CURRENT SPRINT.
-4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: NEXT SPRINT.
---> Locate (once more) the API documentation for shaped windows under Cocoa.
---> Design and encode a version of SDL_ShapeData for Cocoa.
---> Write Cocoa_CreateShaper().
---> Write Cocoa_ResizeWindowShape().
---> Write Cocoa_SetWindowShape().
+--> Get it, along with the rest of the test suite in my branch, building successfully.  STATUS: DONE.
+--> Debug testeyes and the platform-specific shaped-window implementations in tandem.  STATUS: IN PROGRESS.
+4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: IN PROGRESS
+--> Locate (once more) the API documentation for shaped windows under Cocoa.  STATUS: NEARLY FINISHED.
+--> Design and encode a version of SDL_ShapeData for Cocoa.  STATUS: IN PROGRESS.
+--> Write Cocoa_CreateShaper().  STATUS: IN PROGRESS.
+--> Write Cocoa_ResizeWindowShape().  STATUS: IN PROGRESS.
+--> Write Cocoa_SetWindowShape().  STATUS: IN PROGRESS.
 --> If necessary, implement functionality adjunct to SDL_CalculateShapeBitmap() for Cocoa usage.
 5. Use testeyes to debug all implementations. STATUS: SPRINT + 2.
 --> Debug Cocoa implementation.
--- a/src/video/SDL_shape.c	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/SDL_shape.c	Mon Jul 26 20:41:45 2010 -0400
@@ -28,11 +28,8 @@
 #include "SDL_surface.h"
 #include "SDL_shape.h"
 
-extern SDL_VideoDisplay* SDL_ThisDisplay();
-
 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
-	SDL_VideoDisplay* display = SDL_ThisDisplay();
-	SDL_Window *result = display->device->shape_driver.CreateShapedWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
+	SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
 	if(result != NULL) {
 		result->shaper = result->display->device->shape_driver.CreateShaper(result);
 		if(result->shaper != NULL) {
--- a/src/video/SDL_sysvideo.h	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/SDL_sysvideo.h	Mon Jul 26 20:41:45 2010 -0400
@@ -156,7 +156,6 @@
 /* Define the SDL shape driver structure */
 struct SDL_ShapeDriver
 {
-    SDL_Window *(*CreateShapedWindow)(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags);
     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
     int (*ResizeWindowShape)(SDL_Window *window);
--- a/src/video/SDL_video.c	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/SDL_video.c	Mon Jul 26 20:41:45 2010 -0400
@@ -105,10 +105,6 @@
 
 static SDL_VideoDevice *_this = NULL;
 
-SDL_VideoDisplay* SDL_ThisDisplay() {
-    return SDL_CurrentDisplay;
-}
-
 #define CHECK_WINDOW_MAGIC(window, retval) \
     if (!_this) { \
         SDL_UninitializedVideo(); \
--- a/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 20:41:45 2010 -0400
@@ -21,5 +21,22 @@
 */
 
 #include "SDL_shape.h"
+#include "SDL_cocoashape.h"
 
-/* Functions implementing shaped windows for Cocoa will be implemented when the API is decided on. */
+SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) {
+	SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
+	[data->nswindow setAlpha:1.0];
+	[data->nswindow setOpaque:YES];
+	SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
+	result->window = window;
+	result->mode.mode = ShapeModeDefault;
+	result->mode.parameters.binarizationCutoff = 1;
+	result->usershownflag = 0;
+	window->shaper = result;
+	int resized_properly = Cocoa_ResizeWindowShape(window);
+	assert(resized_properly == 0);
+	return result;
+}
+
+extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
+extern int Cocoa_ResizeWindowShape(SDL_Window *window);
--- a/src/video/cocoa/SDL_cocoavideo.m	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/cocoa/SDL_cocoavideo.m	Mon Jul 26 20:41:45 2010 -0400
@@ -92,6 +92,11 @@
     device->SetWindowGrab = Cocoa_SetWindowGrab;
     device->DestroyWindow = Cocoa_DestroyWindow;
     device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
+    
+    device->shape_driver.CreateShaper = Cocoa_CreateShaper;
+    device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
+    device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
+    
 #ifdef SDL_VIDEO_OPENGL_CGL
     device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
     device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
--- a/src/video/win32/SDL_win32video.c	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/win32/SDL_win32video.c	Mon Jul 26 20:41:45 2010 -0400
@@ -185,7 +185,6 @@
     device->DestroyWindow = WIN_DestroyWindow;
     device->GetWindowWMInfo = WIN_GetWindowWMInfo;
     
-    device->shape_driver.CreateShapedWindow = Win32_CreateShapedWindow;
     device->shape_driver.CreateShaper = Win32_CreateShaper;
     device->shape_driver.SetWindowShape = Win32_SetWindowShape;
     device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
--- a/src/video/x11/SDL_x11video.c	Mon Jul 26 17:27:04 2010 -0400
+++ b/src/video/x11/SDL_x11video.c	Mon Jul 26 20:41:45 2010 -0400
@@ -203,7 +203,6 @@
     device->SetWindowGrab = X11_SetWindowGrab;
     device->DestroyWindow = X11_DestroyWindow;
     device->GetWindowWMInfo = X11_GetWindowWMInfo;
-    device->shape_driver.CreateShapedWindow = X11_CreateShapedWindow;
     device->shape_driver.CreateShaper = X11_CreateShaper;
     device->shape_driver.SetWindowShape = X11_SetWindowShape;
     device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;