From bcfdeff4e888db07cc59f67925d0b5898d34736c Mon Sep 17 00:00:00 2001 From: Eli Gottlieb Date: Mon, 26 Jul 2010 20:41:45 -0400 Subject: [PATCH] OK, it appears that dramatic hacks are not necessary to make Cocoa work... --- TODO | 21 +++++++++++---------- src/video/SDL_shape.c | 5 +---- src/video/SDL_sysvideo.h | 1 - src/video/SDL_video.c | 4 ---- src/video/cocoa/SDL_cocoashape.m | 19 ++++++++++++++++++- src/video/cocoa/SDL_cocoavideo.m | 5 +++++ src/video/win32/SDL_win32video.c | 1 - src/video/x11/SDL_x11video.c | 1 - 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index f7ffa6b94..d22dff451 100644 --- a/TODO +++ b/TODO @@ -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. diff --git a/src/video/SDL_shape.c b/src/video/SDL_shape.c index fea819d97..3affe1fd4 100644 --- a/src/video/SDL_shape.c +++ b/src/video/SDL_shape.c @@ -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) { diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 919ab3421..b8508740a 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -156,7 +156,6 @@ struct SDL_WindowShaper /* 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); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 7ae4f274f..8ac0d1d4c 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -105,10 +105,6 @@ static VideoBootStrap *bootstrap[] = { static SDL_VideoDevice *_this = NULL; -SDL_VideoDisplay* SDL_ThisDisplay() { - return SDL_CurrentDisplay; -} - #define CHECK_WINDOW_MAGIC(window, retval) \ if (!_this) { \ SDL_UninitializedVideo(); \ diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index aabebd02b..6317e5b05 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -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); diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 86e19fda7..ddc8742fc 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -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; diff --git a/src/video/win32/SDL_win32video.c b/src/video/win32/SDL_win32video.c index 82ec69cbc..4e7dc3f5b 100644 --- a/src/video/win32/SDL_win32video.c +++ b/src/video/win32/SDL_win32video.c @@ -185,7 +185,6 @@ WIN_CreateDevice(int devindex) 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; diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 28a85e0e6..b320aaafe 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -203,7 +203,6 @@ X11_CreateDevice(int devindex) 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;