annotate src/video/x11/SDL_x11shape.c @ 4822:55f32099a4b5

Worked on Windows implementation and the quad-trees.
author egottlieb
date Mon, 02 Aug 2010 01:54:59 -0400
parents c68e7490e4cf
children 0c82f20327ec 1f9915666afd
rev   line source
4777
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
1 /*
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
3 Copyright (C) 2010 Eli Gottlieb
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
4
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
9
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
14
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
18
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
19 Eli Gottlieb
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
20 eligottlieb@gmail.com
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
21 */
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
22
4786
175da36d1342 Fixed up shape files as best I can.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
23 #include <assert.h>
4794
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
24 #include "SDL_x11video.h"
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
25 #include "SDL_x11shape.h"
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
26 #include "SDL_x11window.h"
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
27
4809
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4807
diff changeset
28 SDL_Window* X11_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4807
diff changeset
29 return SDL_CreateWindow(title,x,y,w,h,flags);
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4807
diff changeset
30 }
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4807
diff changeset
31
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
32 SDL_WindowShaper* X11_CreateShaper(SDL_Window* window) {
4791
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
33 SDL_WindowShaper* result = NULL;
4794
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
34
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
35 #if SDL_VIDEO_DRIVER_X11_XSHAPE
4791
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
36 if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
37 result = malloc(sizeof(SDL_WindowShaper));
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
38 result->window = window;
4807
c9eb95f29770 Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
39 result->mode.mode = ShapeModeDefault;
c9eb95f29770 Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
40 result->mode.parameters.binarizationCutoff = 1;
4791
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
41 result->usershownflag = 0;
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4794
diff changeset
42 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4794
diff changeset
43 result->driverdata = data;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4794
diff changeset
44 data->bitmapsize = 0;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4794
diff changeset
45 data->bitmap = NULL;
4791
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
46 window->shaper = result;
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
47 int resized_properly = X11_ResizeWindowShape(window);
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
48 assert(resized_properly == 0);
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
49 }
4794
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
50 #endif
4791
e07cd9e86d7a Make sure we have XShape symbols before we allow a shaped window.
Ryan C. Gordon <icculus@icculus.org>
parents: 4789
diff changeset
51
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
52 return result;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
53 }
4777
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
54
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
55 int X11_ResizeWindowShape(SDL_Window* window) {
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
56 SDL_ShapeData* data = window->shaper->driverdata;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
57 assert(data != NULL);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
58
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
59 unsigned int bitmapsize = window->w / 8;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
60 if(window->w % 8 > 0)
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
61 bitmapsize += 1;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
62 bitmapsize *= window->h;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
63 if(data->bitmapsize != bitmapsize || data->bitmap == NULL) {
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
64 data->bitmapsize = bitmapsize;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
65 if(data->bitmap != NULL)
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
66 free(data->bitmap);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
67 data->bitmap = malloc(data->bitmapsize);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
68 if(data->bitmap == NULL) {
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
69 SDL_SetError("Could not allocate memory for shaped-window bitmap.");
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
70 return -1;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
71 }
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
72 }
4817
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
73 memset(data->bitmap,0,data->bitmapsize);
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
74
4802
f14a8c05f5bb Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4795
diff changeset
75 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
76
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
77 return 0;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
78 }
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
79
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
80 int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
4787
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4786
diff changeset
81 if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4786
diff changeset
82 return -1;
4794
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
83
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
84 #if SDL_VIDEO_DRIVER_X11_XSHAPE
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
85 if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)))
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
86 return -2;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
87 if(shape->w != shaper->window->w || shape->h != shaper->window->h)
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
88 return -3;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
89 SDL_ShapeData *data = shaper->driverdata;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
90
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4784
diff changeset
91 /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
4817
c68e7490e4cf Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
92 SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8);
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
93
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
94 SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
95 Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
96
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
97 XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
98 XSync(windowdata->videodata->display,False);
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
99
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
100 XFreePixmap(windowdata->videodata->display,shapemask);
4794
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
101 #endif
e562160a873f Check configure-defined macro before doing _anything_ with XShape.
Ryan C. Gordon <icculus@icculus.org>
parents: 4791
diff changeset
102
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
103 return 0;
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
104 }