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 48107a602fd2121f
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
     1.1 --- a/TODO	Mon Jul 26 17:27:04 2010 -0400
     1.2 +++ b/TODO	Mon Jul 26 20:41:45 2010 -0400
     1.3 @@ -1,20 +1,21 @@
     1.4  Eli Gottlieb's checklist for the GSOC shaped windows project.  Dated July 9, 2010.
     1.5  1. Enable proper linking of the X11 implementation and test it.
     1.6 ---> Find the place in the build system for platform-specific linking flags.  STATUS: BLOODY IMPOSSIBLE.
     1.7 ---> Add a linker flag to bring in libXext.a. STATUS: WILL BE SIMPLE ONCE PREVIOUS STEP IS ACCOMPLISHED (kshemashiach yagia).
     1.8 +--> Find the place in the build system for platform-specific linking flags.  STATUS: DONE
     1.9 +--> Add a linker flag to bring in libXext.a. STATUS: DONE.
    1.10  2. Build the Win32 implementation of shaped-windows functionality.
    1.11  --> Add driver functions to the SDL_ShapeDriver in the Win32 driver's SDL_DisplayDevice at the proper point in the code.  STATUS: CHECK.
    1.12  --> Add a hook in the Windows resize-window code to call Win32_ResizeWindowShape().  STATUS: CHECK.
    1.13 +--> Get the Windows code to build and run properly.  STATUS: IN PROGRESS.
    1.14  3. Enable building the testeyes program.
    1.15  --> Reprogram it to use the latest shaped-windows API.  STATUS: CHECK.
    1.16 ---> 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.
    1.17 ---> Debug testeyes and the platform-specific shaped-window implementations in tandem.  STATUS: TO BEGIN, CURRENT SPRINT.
    1.18 -4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: NEXT SPRINT.
    1.19 ---> Locate (once more) the API documentation for shaped windows under Cocoa.
    1.20 ---> Design and encode a version of SDL_ShapeData for Cocoa.
    1.21 ---> Write Cocoa_CreateShaper().
    1.22 ---> Write Cocoa_ResizeWindowShape().
    1.23 ---> Write Cocoa_SetWindowShape().
    1.24 +--> Get it, along with the rest of the test suite in my branch, building successfully.  STATUS: DONE.
    1.25 +--> Debug testeyes and the platform-specific shaped-window implementations in tandem.  STATUS: IN PROGRESS.
    1.26 +4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: IN PROGRESS
    1.27 +--> Locate (once more) the API documentation for shaped windows under Cocoa.  STATUS: NEARLY FINISHED.
    1.28 +--> Design and encode a version of SDL_ShapeData for Cocoa.  STATUS: IN PROGRESS.
    1.29 +--> Write Cocoa_CreateShaper().  STATUS: IN PROGRESS.
    1.30 +--> Write Cocoa_ResizeWindowShape().  STATUS: IN PROGRESS.
    1.31 +--> Write Cocoa_SetWindowShape().  STATUS: IN PROGRESS.
    1.32  --> If necessary, implement functionality adjunct to SDL_CalculateShapeBitmap() for Cocoa usage.
    1.33  5. Use testeyes to debug all implementations. STATUS: SPRINT + 2.
    1.34  --> Debug Cocoa implementation.
     2.1 --- a/src/video/SDL_shape.c	Mon Jul 26 17:27:04 2010 -0400
     2.2 +++ b/src/video/SDL_shape.c	Mon Jul 26 20:41:45 2010 -0400
     2.3 @@ -28,11 +28,8 @@
     2.4  #include "SDL_surface.h"
     2.5  #include "SDL_shape.h"
     2.6  
     2.7 -extern SDL_VideoDisplay* SDL_ThisDisplay();
     2.8 -
     2.9  SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
    2.10 -	SDL_VideoDisplay* display = SDL_ThisDisplay();
    2.11 -	SDL_Window *result = display->device->shape_driver.CreateShapedWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
    2.12 +	SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
    2.13  	if(result != NULL) {
    2.14  		result->shaper = result->display->device->shape_driver.CreateShaper(result);
    2.15  		if(result->shaper != NULL) {
     3.1 --- a/src/video/SDL_sysvideo.h	Mon Jul 26 17:27:04 2010 -0400
     3.2 +++ b/src/video/SDL_sysvideo.h	Mon Jul 26 20:41:45 2010 -0400
     3.3 @@ -156,7 +156,6 @@
     3.4  /* Define the SDL shape driver structure */
     3.5  struct SDL_ShapeDriver
     3.6  {
     3.7 -    SDL_Window *(*CreateShapedWindow)(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags);
     3.8      SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
     3.9      int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
    3.10      int (*ResizeWindowShape)(SDL_Window *window);
     4.1 --- a/src/video/SDL_video.c	Mon Jul 26 17:27:04 2010 -0400
     4.2 +++ b/src/video/SDL_video.c	Mon Jul 26 20:41:45 2010 -0400
     4.3 @@ -105,10 +105,6 @@
     4.4  
     4.5  static SDL_VideoDevice *_this = NULL;
     4.6  
     4.7 -SDL_VideoDisplay* SDL_ThisDisplay() {
     4.8 -    return SDL_CurrentDisplay;
     4.9 -}
    4.10 -
    4.11  #define CHECK_WINDOW_MAGIC(window, retval) \
    4.12      if (!_this) { \
    4.13          SDL_UninitializedVideo(); \
     5.1 --- a/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 17:27:04 2010 -0400
     5.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 20:41:45 2010 -0400
     5.3 @@ -21,5 +21,22 @@
     5.4  */
     5.5  
     5.6  #include "SDL_shape.h"
     5.7 +#include "SDL_cocoashape.h"
     5.8  
     5.9 -/* Functions implementing shaped windows for Cocoa will be implemented when the API is decided on. */
    5.10 +SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) {
    5.11 +	SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
    5.12 +	[data->nswindow setAlpha:1.0];
    5.13 +	[data->nswindow setOpaque:YES];
    5.14 +	SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
    5.15 +	result->window = window;
    5.16 +	result->mode.mode = ShapeModeDefault;
    5.17 +	result->mode.parameters.binarizationCutoff = 1;
    5.18 +	result->usershownflag = 0;
    5.19 +	window->shaper = result;
    5.20 +	int resized_properly = Cocoa_ResizeWindowShape(window);
    5.21 +	assert(resized_properly == 0);
    5.22 +	return result;
    5.23 +}
    5.24 +
    5.25 +extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
    5.26 +extern int Cocoa_ResizeWindowShape(SDL_Window *window);
     6.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Mon Jul 26 17:27:04 2010 -0400
     6.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Mon Jul 26 20:41:45 2010 -0400
     6.3 @@ -92,6 +92,11 @@
     6.4      device->SetWindowGrab = Cocoa_SetWindowGrab;
     6.5      device->DestroyWindow = Cocoa_DestroyWindow;
     6.6      device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
     6.7 +    
     6.8 +    device->shape_driver.CreateShaper = Cocoa_CreateShaper;
     6.9 +    device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
    6.10 +    device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
    6.11 +    
    6.12  #ifdef SDL_VIDEO_OPENGL_CGL
    6.13      device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
    6.14      device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
     7.1 --- a/src/video/win32/SDL_win32video.c	Mon Jul 26 17:27:04 2010 -0400
     7.2 +++ b/src/video/win32/SDL_win32video.c	Mon Jul 26 20:41:45 2010 -0400
     7.3 @@ -185,7 +185,6 @@
     7.4      device->DestroyWindow = WIN_DestroyWindow;
     7.5      device->GetWindowWMInfo = WIN_GetWindowWMInfo;
     7.6      
     7.7 -    device->shape_driver.CreateShapedWindow = Win32_CreateShapedWindow;
     7.8      device->shape_driver.CreateShaper = Win32_CreateShaper;
     7.9      device->shape_driver.SetWindowShape = Win32_SetWindowShape;
    7.10      device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
     8.1 --- a/src/video/x11/SDL_x11video.c	Mon Jul 26 17:27:04 2010 -0400
     8.2 +++ b/src/video/x11/SDL_x11video.c	Mon Jul 26 20:41:45 2010 -0400
     8.3 @@ -203,7 +203,6 @@
     8.4      device->SetWindowGrab = X11_SetWindowGrab;
     8.5      device->DestroyWindow = X11_DestroyWindow;
     8.6      device->GetWindowWMInfo = X11_GetWindowWMInfo;
     8.7 -    device->shape_driver.CreateShapedWindow = X11_CreateShapedWindow;
     8.8      device->shape_driver.CreateShaper = X11_CreateShaper;
     8.9      device->shape_driver.SetWindowShape = X11_SetWindowShape;
    8.10      device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;