Merged Nathan Heisey's Haiku work into the main SDL 1.3 branch.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 15 Sep 2011 23:51:07 -0400
changeset 5941e4e18a80be61
parent 5912 98471d04c8db
parent 5940 377e870b3f49
child 5942 00b695dde4bf
Merged Nathan Heisey's Haiku work into the main SDL 1.3 branch.

This was a Google Summer of Code 2011 project, sponsored by the Haiku project.

We thank Nathan and the other Haiku developers for their support!
configure.in
src/SDL_compat.c
src/video/bwindow/SDL_BView.h
src/video/bwindow/SDL_lowvideo.h
src/video/bwindow/SDL_sysevents.cc
src/video/bwindow/SDL_sysevents_c.h
src/video/bwindow/SDL_sysmouse.cc
src/video/bwindow/SDL_sysmouse_c.h
src/video/bwindow/SDL_sysvideo.cc
src/video/bwindow/SDL_syswm.cc
src/video/bwindow/SDL_syswm_c.h
src/video/bwindow/SDL_sysyuv.cc
src/video/bwindow/SDL_sysyuv.h
     2.1 --- a/src/SDL_compat.c	Thu Sep 15 08:21:54 2011 -0700
     2.2 +++ b/src/SDL_compat.c	Thu Sep 15 23:51:07 2011 -0400
     2.3 @@ -849,7 +849,7 @@
     2.4      /* Copy the old bits out */
     2.5      length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
     2.6      pixels = SDL_malloc(SDL_PublicSurface->h * length);
     2.7 -    if (pixels) {
     2.8 +    if (pixels && SDL_PublicSurface->pixels) {
     2.9          src = (Uint8*)SDL_PublicSurface->pixels;
    2.10          dst = (Uint8*)pixels;
    2.11          for (row = 0; row < SDL_PublicSurface->h; ++row) {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main/beos/SDL_BApp.h	Thu Sep 15 23:51:07 2011 -0400
     3.3 @@ -0,0 +1,377 @@
     3.4 +/*
     3.5 +  Simple DirectMedia Layer
     3.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3.7 +
     3.8 +  This software is provided 'as-is', without any express or implied
     3.9 +  warranty.  In no event will the authors be held liable for any damages
    3.10 +  arising from the use of this software.
    3.11 +
    3.12 +  Permission is granted to anyone to use this software for any purpose,
    3.13 +  including commercial applications, and to alter it and redistribute it
    3.14 +  freely, subject to the following restrictions:
    3.15 +
    3.16 +  1. The origin of this software must not be misrepresented; you must not
    3.17 +     claim that you wrote the original software. If you use this software
    3.18 +     in a product, an acknowledgment in the product documentation would be
    3.19 +     appreciated but is not required.
    3.20 +  2. Altered source versions must be plainly marked as such, and must not be
    3.21 +     misrepresented as being the original software.
    3.22 +  3. This notice may not be removed or altered from any source distribution.
    3.23 +*/
    3.24 +#ifndef SDL_BAPP_H
    3.25 +#define SDL_BAPP_H
    3.26 +
    3.27 +#include <InterfaceKit.h>
    3.28 +#include <OpenGLKit.h>
    3.29 +
    3.30 +#include "../../video/bwindow/SDL_bkeyboard.h"
    3.31 +
    3.32 +
    3.33 +#ifdef __cplusplus
    3.34 +extern "C" {
    3.35 +#endif
    3.36 +
    3.37 +#include "SDL_config.h"
    3.38 +
    3.39 +#include "SDL_video.h"
    3.40 +
    3.41 +/* Local includes */
    3.42 +#include "../../events/SDL_events_c.h"
    3.43 +#include "../../video/bwindow/SDL_bkeyboard.h"
    3.44 +#include "../../video/bwindow/SDL_bframebuffer.h"
    3.45 +
    3.46 +#ifdef __cplusplus
    3.47 +}
    3.48 +#endif
    3.49 +
    3.50 +#include <vector>
    3.51 +
    3.52 +
    3.53 +
    3.54 +
    3.55 +/* Forward declarations */
    3.56 +class SDL_BWin;
    3.57 +
    3.58 +/* Message constants */
    3.59 +enum ToSDL {
    3.60 +	/* Intercepted by BWindow on its way to BView */
    3.61 +	BAPP_MOUSE_MOVED,
    3.62 +	BAPP_MOUSE_BUTTON,
    3.63 +	BAPP_MOUSE_WHEEL,
    3.64 +	BAPP_KEY,
    3.65 +	BAPP_REPAINT,           /* from _UPDATE_ */
    3.66 +	/* From BWindow */
    3.67 +	BAPP_MAXIMIZE,          /* from B_ZOOM */
    3.68 +	BAPP_MINIMIZE,
    3.69 +	BAPP_RESTORE,			/* TODO: IMPLEMENT! */
    3.70 +	BAPP_SHOW,
    3.71 +	BAPP_HIDE,
    3.72 +	BAPP_MOUSE_FOCUS,		/* caused by MOUSE_MOVE */
    3.73 +	BAPP_KEYBOARD_FOCUS,	/* from WINDOW_ACTIVATED */
    3.74 +	BAPP_WINDOW_CLOSE_REQUESTED,
    3.75 +	BAPP_WINDOW_MOVED,
    3.76 +	BAPP_WINDOW_RESIZED,
    3.77 +	BAPP_SCREEN_CHANGED
    3.78 +};
    3.79 +
    3.80 +
    3.81 +
    3.82 +/* Create a descendant of BApplication */
    3.83 +class SDL_BApp : public BApplication {
    3.84 +public:
    3.85 +	SDL_BApp(const char* signature) :
    3.86 +		BApplication(signature) {
    3.87 +		_current_context = NULL;
    3.88 +	}
    3.89 +	
    3.90 +	
    3.91 +	virtual ~SDL_BApp() {
    3.92 +	}
    3.93 +	
    3.94 +	
    3.95 +	
    3.96 +		/* Event-handling functions */
    3.97 +	virtual void MessageReceived(BMessage* message) {
    3.98 +		/* Sort out SDL-related messages */
    3.99 +        switch ( message->what ) {
   3.100 +        case BAPP_MOUSE_MOVED:
   3.101 +        	_HandleMouseMove(message);
   3.102 +        	break;
   3.103 +
   3.104 +		case BAPP_MOUSE_BUTTON:
   3.105 +			_HandleMouseButton(message);
   3.106 +			break;
   3.107 +			
   3.108 +		case BAPP_MOUSE_WHEEL:
   3.109 +			_HandleMouseWheel(message);
   3.110 +			break;
   3.111 +			
   3.112 +		case BAPP_KEY:
   3.113 +			_HandleKey(message);
   3.114 +			break;
   3.115 +
   3.116 +		case BAPP_REPAINT:
   3.117 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_EXPOSED);
   3.118 +			break;
   3.119 +			
   3.120 +		case BAPP_MAXIMIZE:
   3.121 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MAXIMIZED);
   3.122 +			break;
   3.123 +			
   3.124 +		case BAPP_MINIMIZE:
   3.125 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MINIMIZED);
   3.126 +			break;
   3.127 +			
   3.128 +		case BAPP_SHOW:
   3.129 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_SHOWN);
   3.130 +			break;
   3.131 +			
   3.132 +		case BAPP_HIDE:
   3.133 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_HIDDEN);
   3.134 +			break;
   3.135 +			
   3.136 +		case BAPP_MOUSE_FOCUS:
   3.137 +			_HandleMouseFocus(message);
   3.138 +			break;
   3.139 +			
   3.140 +		case BAPP_KEYBOARD_FOCUS:
   3.141 +			_HandleKeyboardFocus(message);
   3.142 +			break;
   3.143 +			
   3.144 +		case BAPP_WINDOW_CLOSE_REQUESTED:
   3.145 +			_HandleBasicWindowEvent(message, SDL_WINDOWEVENT_CLOSE);
   3.146 +			break;
   3.147 +			
   3.148 +		case BAPP_WINDOW_MOVED:
   3.149 +			_HandleWindowMoved(message);
   3.150 +			break;
   3.151 +			
   3.152 +		case BAPP_WINDOW_RESIZED:
   3.153 +			_HandleWindowResized(message);
   3.154 +			break;
   3.155 +			
   3.156 +		case BAPP_SCREEN_CHANGED:
   3.157 +			/* TODO: Handle screen resize or workspace change */
   3.158 +			break;
   3.159 +
   3.160 +        default:
   3.161 +           BApplication::MessageReceived(message);
   3.162 +           break;
   3.163 +        }
   3.164 +    }
   3.165 +    
   3.166 +    /* Window creation/destruction methods */
   3.167 +    int32 GetID(SDL_Window *win) {
   3.168 +    	int32 i;
   3.169 +    	for(i = 0; i < _GetNumWindowSlots(); ++i) {
   3.170 +    		if( GetSDLWindow(i) == NULL ) {
   3.171 +    			_SetSDLWindow(win, i);
   3.172 +    			return i;
   3.173 +    		}
   3.174 +    	}
   3.175 +    	
   3.176 +    	/* Expand the vector if all slots are full */
   3.177 +    	if( i == _GetNumWindowSlots() ) {
   3.178 +    		_PushBackWindow(win);
   3.179 +    		return i;
   3.180 +    	}
   3.181 +    }
   3.182 +    
   3.183 +    /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here.  Is
   3.184 +       there another way to do this? */
   3.185 +    void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */
   3.186 +    
   3.187 +    
   3.188 +	SDL_Window *GetSDLWindow(int32 winID) {
   3.189 +		return _window_map[winID];
   3.190 +	}
   3.191 +    
   3.192 +    void SetCurrentContext(BGLView *newContext) {
   3.193 +    	if(_current_context)
   3.194 +    		_current_context->UnlockGL();
   3.195 +    	_current_context = newContext;
   3.196 +    	_current_context->LockGL();
   3.197 +    }
   3.198 +private:
   3.199 +	/* Event management */
   3.200 +	void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) {
   3.201 +		SDL_Window *win;
   3.202 +		int32 winID;
   3.203 +		if(
   3.204 +			!_GetWinID(msg, &winID)
   3.205 +		) {
   3.206 +			return;
   3.207 +		}
   3.208 +		win = GetSDLWindow(winID);
   3.209 +		SDL_SendWindowEvent(win, sdlEventType, 0, 0);
   3.210 +	}
   3.211 +	
   3.212 +	void _HandleMouseMove(BMessage *msg) {
   3.213 +		SDL_Window *win;
   3.214 +		int32 winID;
   3.215 +		int32 x = 0, y = 0;
   3.216 +		if(	
   3.217 +			!_GetWinID(msg, &winID) ||
   3.218 +			msg->FindInt32("x", &x) != B_OK || /* x movement */
   3.219 +			msg->FindInt32("y", &y) != B_OK    /* y movement */
   3.220 +		) {
   3.221 +			return;
   3.222 +		}
   3.223 +		win = GetSDLWindow(winID);
   3.224 +		SDL_SendMouseMotion(win, 0, x, y);
   3.225 +		
   3.226 +		/* Tell the application that the mouse passed over, redraw needed */
   3.227 +		BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
   3.228 +	}
   3.229 +	
   3.230 +	void _HandleMouseButton(BMessage *msg) {
   3.231 +		SDL_Window *win;
   3.232 +		int32 winID;
   3.233 +		int32 button, state;	/* left/middle/right, pressed/released */
   3.234 +		if(
   3.235 +			!_GetWinID(msg, &winID) ||
   3.236 +			msg->FindInt32("button-id", &button) != B_OK ||
   3.237 +			msg->FindInt32("button-state", &state) != B_OK
   3.238 +		) {
   3.239 +			return;
   3.240 +		}
   3.241 +		win = GetSDLWindow(winID);
   3.242 +		SDL_SendMouseButton(win, state, button);
   3.243 +	}
   3.244 +	
   3.245 +	void _HandleMouseWheel(BMessage *msg) {
   3.246 +		SDL_Window *win;
   3.247 +		int32 winID;
   3.248 +		int32 xTicks, yTicks;
   3.249 +		if(
   3.250 +			!_GetWinID(msg, &winID) ||
   3.251 +			msg->FindInt32("xticks", &xTicks) != B_OK ||
   3.252 +			msg->FindInt32("yticks", &yTicks) != B_OK
   3.253 +		) {
   3.254 +			return;
   3.255 +		}
   3.256 +		win = GetSDLWindow(winID);
   3.257 +		SDL_SendMouseWheel(win, xTicks, yTicks);
   3.258 +	}
   3.259 +	
   3.260 +	void _HandleKey(BMessage *msg) {
   3.261 +		int32 scancode, state;	/* scancode, pressed/released */
   3.262 +		if(
   3.263 +			msg->FindInt32("key-state", &state) != B_OK ||
   3.264 +			msg->FindInt32("key-scancode", &scancode) != B_OK
   3.265 +		) {
   3.266 +			return;
   3.267 +		}
   3.268 +		
   3.269 +		/* Make sure this isn't a repeated event (key pressed and held) */
   3.270 +		if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
   3.271 +			return;
   3.272 +		}
   3.273 +		BE_SetKeyState(scancode, state);
   3.274 +		SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
   3.275 +	}
   3.276 +	
   3.277 +	void _HandleMouseFocus(BMessage *msg) {
   3.278 +		SDL_Window *win;
   3.279 +		int32 winID;
   3.280 +		bool bSetFocus;	/* If false, lose focus */
   3.281 +		if(
   3.282 +			!_GetWinID(msg, &winID) ||
   3.283 +			msg->FindBool("focusGained", &bSetFocus) != B_OK
   3.284 +		) {
   3.285 +			return;
   3.286 +		}
   3.287 +		win = GetSDLWindow(winID);
   3.288 +		if(bSetFocus) {
   3.289 +			SDL_SetMouseFocus(win);
   3.290 +		} else if(SDL_GetMouseFocus() == win) {
   3.291 +			/* Only lose all focus if this window was the current focus */
   3.292 +			SDL_SetMouseFocus(NULL);
   3.293 +		}
   3.294 +	}
   3.295 +	
   3.296 +	void _HandleKeyboardFocus(BMessage *msg) {
   3.297 +		SDL_Window *win;
   3.298 +		int32 winID;
   3.299 +		bool bSetFocus;	/* If false, lose focus */
   3.300 +		if(
   3.301 +			!_GetWinID(msg, &winID) ||
   3.302 +			msg->FindBool("focusGained", &bSetFocus) != B_OK
   3.303 +		) {
   3.304 +			return;
   3.305 +		}
   3.306 +		win = GetSDLWindow(winID);
   3.307 +		if(bSetFocus) {
   3.308 +			SDL_SetKeyboardFocus(win);
   3.309 +		} else if(SDL_GetKeyboardFocus() == win) {
   3.310 +			/* Only lose all focus if this window was the current focus */
   3.311 +			SDL_SetKeyboardFocus(NULL);
   3.312 +		}
   3.313 +	}
   3.314 +	
   3.315 +	void _HandleWindowMoved(BMessage *msg) {
   3.316 +		SDL_Window *win;
   3.317 +		int32 winID;
   3.318 +		int32 xPos, yPos;
   3.319 +		/* Get the window id and new x/y position of the window */
   3.320 +		if(
   3.321 +			!_GetWinID(msg, &winID) ||
   3.322 +			msg->FindInt32("window-x", &xPos) != B_OK ||
   3.323 +			msg->FindInt32("window-y", &yPos) != B_OK
   3.324 +		) {
   3.325 +			return;
   3.326 +		}
   3.327 +		win = GetSDLWindow(winID);
   3.328 +		SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
   3.329 +	}
   3.330 +	
   3.331 +	void _HandleWindowResized(BMessage *msg) {
   3.332 +		SDL_Window *win;
   3.333 +		int32 winID;
   3.334 +		int32 w, h;
   3.335 +		/* Get the window id ]and new x/y position of the window */
   3.336 +		if(
   3.337 +			!_GetWinID(msg, &winID) ||
   3.338 +			msg->FindInt32("window-w", &w) != B_OK ||
   3.339 +			msg->FindInt32("window-h", &h) != B_OK
   3.340 +		) {
   3.341 +			return;
   3.342 +		}
   3.343 +		win = GetSDLWindow(winID);
   3.344 +		SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);
   3.345 +	}
   3.346 +
   3.347 +	bool _GetWinID(BMessage *msg, int32 *winID) {
   3.348 +		return msg->FindInt32("window-id", winID) == B_OK;
   3.349 +	}
   3.350 +
   3.351 +
   3.352 +
   3.353 +	/* Vector functions: Wraps vector stuff in case we need to change 
   3.354 +	   implementation */
   3.355 +	void _SetSDLWindow(SDL_Window *win, int32 winID) {
   3.356 +		_window_map[winID] = win;
   3.357 +	}
   3.358 +	
   3.359 +	int32 _GetNumWindowSlots() {
   3.360 +		return _window_map.size();
   3.361 +	}
   3.362 +	
   3.363 +	
   3.364 +	void _PopBackWindow() {
   3.365 +		_window_map.pop_back();
   3.366 +	}
   3.367 +
   3.368 +	void _PushBackWindow(SDL_Window *win) {
   3.369 +		_window_map.push_back(win);
   3.370 +	}
   3.371 +
   3.372 +
   3.373 +	/* Members */
   3.374 +	vector<SDL_Window*> _window_map; /* Keeps track of SDL_Windows by index-id*/
   3.375 +
   3.376 +	display_mode *_saved_mode;
   3.377 +	BGLView      *_current_context;
   3.378 +};
   3.379 +
   3.380 +#endif
     4.1 --- a/src/main/beos/SDL_BeApp.cc	Thu Sep 15 08:21:54 2011 -0700
     4.2 +++ b/src/main/beos/SDL_BeApp.cc	Thu Sep 15 23:51:07 2011 -0400
     4.3 @@ -27,11 +27,17 @@
     4.4  #include <storage/Entry.h>
     4.5  #include <unistd.h>
     4.6  
     4.7 +#include "SDL_BApp.h"	/* SDL_BApp class definition */
     4.8  #include "SDL_BeApp.h"
     4.9  #include "SDL_thread.h"
    4.10  #include "SDL_timer.h"
    4.11  #include "SDL_error.h"
    4.12  
    4.13 +#include "../../video/bwindow/SDL_BWin.h"
    4.14 +
    4.15 +#ifdef __cplusplus
    4.16 +extern "C" {
    4.17 +#endif
    4.18  /* Flag to tell whether or not the Be application is active or not */
    4.19  int SDL_BeAppActive = 0;
    4.20  static SDL_Thread *SDL_AppThread = NULL;
    4.21 @@ -41,7 +47,7 @@
    4.22  {
    4.23      BApplication *App;
    4.24  
    4.25 -    App = new BApplication("application/x-SDL-executable");
    4.26 +    App = new SDL_BApp("application/x-SDL-executable");
    4.27  
    4.28      App->Run();
    4.29      delete App;
    4.30 @@ -110,4 +116,18 @@
    4.31      }
    4.32  }
    4.33  
    4.34 +
    4.35  /* vi: set ts=4 sw=4 expandtab: */
    4.36 +#ifdef __cplusplus
    4.37 +}
    4.38 +#endif
    4.39 +
    4.40 +/* SDL_BApp functions */
    4.41 +void SDL_BApp::ClearID(SDL_BWin *bwin) {
    4.42 +	_SetSDLWindow(NULL, bwin->GetID());
    4.43 +	int32 i = _GetNumWindowSlots() - 1;
    4.44 +	while(i >= 0 && GetSDLWindow(i) == NULL) {
    4.45 +		_PopBackWindow();
    4.46 +		--i;
    4.47 +	}
    4.48 +}
     5.1 --- a/src/main/beos/SDL_BeApp.h	Thu Sep 15 08:21:54 2011 -0700
     5.2 +++ b/src/main/beos/SDL_BeApp.h	Thu Sep 15 23:51:07 2011 -0400
     5.3 @@ -20,6 +20,10 @@
     5.4  */
     5.5  #include "SDL_config.h"
     5.6  
     5.7 +
     5.8 +#ifdef __cplusplus
     5.9 +extern "C" {
    5.10 +#endif
    5.11  /* Handle the BeApp specific portions of the application */
    5.12  
    5.13  /* Initialize the Be Application, if it's not already started */
    5.14 @@ -31,3 +35,7 @@
    5.15  /* Flag to tell whether the app is active or not */
    5.16  extern int SDL_BeAppActive;
    5.17  /* vi: set ts=4 sw=4 expandtab: */
    5.18 +
    5.19 +#ifdef __cplusplus
    5.20 +}
    5.21 +#endif
     6.1 --- a/src/power/beos/SDL_syspower.c	Thu Sep 15 08:21:54 2011 -0700
     6.2 +++ b/src/power/beos/SDL_syspower.c	Thu Sep 15 23:51:07 2011 -0400
     6.3 @@ -50,7 +50,8 @@
     6.4      uint8 battery_flags;
     6.5      uint8 battery_life;
     6.6      uint32 battery_time;
     6.7 -
     6.8 +	int rc;	/* FIXME: This was undefined before; not sure what type it is */
     6.9 +	
    6.10      if (fd == -1) {
    6.11          return SDL_FALSE;       /* maybe some other method will work? */
    6.12      }
    6.13 @@ -77,7 +78,9 @@
    6.14          if (battery_status == 0xFF) {
    6.15              battery_flags = 0xFF;
    6.16          } else {
    6.17 -            battery_flags = (1 << status.battery_status);
    6.18 +            battery_flags = (1 << battery_status); /* FIXME: Used to be
    6.19 +            										  status.battery_status,
    6.20 +            										  not sure why */
    6.21          }
    6.22      }
    6.23  
     7.1 --- a/src/thread/beos/SDL_systhread.c	Thu Sep 15 08:21:54 2011 -0700
     7.2 +++ b/src/thread/beos/SDL_systhread.c	Thu Sep 15 23:51:07 2011 -0400
     7.3 @@ -90,7 +90,7 @@
     7.4  }
     7.5  
     7.6  int
     7.7 -SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority)
     7.8 +SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
     7.9  {
    7.10      int32 value;
    7.11  
     8.1 --- a/src/video/bwindow/SDL_BView.h	Thu Sep 15 08:21:54 2011 -0700
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,120 +0,0 @@
     8.4 -/*
     8.5 -  Simple DirectMedia Layer
     8.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     8.7 -
     8.8 -  This software is provided 'as-is', without any express or implied
     8.9 -  warranty.  In no event will the authors be held liable for any damages
    8.10 -  arising from the use of this software.
    8.11 -
    8.12 -  Permission is granted to anyone to use this software for any purpose,
    8.13 -  including commercial applications, and to alter it and redistribute it
    8.14 -  freely, subject to the following restrictions:
    8.15 -
    8.16 -  1. The origin of this software must not be misrepresented; you must not
    8.17 -     claim that you wrote the original software. If you use this software
    8.18 -     in a product, an acknowledgment in the product documentation would be
    8.19 -     appreciated but is not required.
    8.20 -  2. Altered source versions must be plainly marked as such, and must not be
    8.21 -     misrepresented as being the original software.
    8.22 -  3. This notice may not be removed or altered from any source distribution.
    8.23 -*/
    8.24 -#include "SDL_config.h"
    8.25 -
    8.26 -#ifndef _SDL_BView_h
    8.27 -#define _SDL_BView_h
    8.28 -
    8.29 -/* This is the event handling and graphics update portion of SDL_BWin */
    8.30 -
    8.31 -extern "C"
    8.32 -{
    8.33 -#include "../../events/SDL_events_c.h"
    8.34 -};
    8.35 -
    8.36 -class SDL_BView:public BView
    8.37 -{
    8.38 -  public:
    8.39 -    SDL_BView(BRect frame):BView(frame, "SDL View", B_FOLLOW_ALL_SIDES,
    8.40 -                                 (B_WILL_DRAW | B_FRAME_EVENTS))
    8.41 -    {
    8.42 -        image = NULL;
    8.43 -        xoff = yoff = 0;
    8.44 -        SetViewColor(0, 0, 0, 0);
    8.45 -        SetHighColor(0, 0, 0, 0);
    8.46 -    }
    8.47 -    virtual ~ SDL_BView()
    8.48 -    {
    8.49 -        SetBitmap(NULL);
    8.50 -    }
    8.51 -    /* Set drawing offsets for fullscreen mode */
    8.52 -    virtual void SetXYOffset(int x, int y)
    8.53 -    {
    8.54 -        xoff = x;
    8.55 -        yoff = y;
    8.56 -    }
    8.57 -    virtual void GetXYOffset(int &x, int &y)
    8.58 -    {
    8.59 -        x = xoff;
    8.60 -        y = yoff;
    8.61 -    }
    8.62 -    /* The view changed size. If it means we're in fullscreen, we
    8.63 -     * draw a nice black box in the entire view to get black borders.
    8.64 -     */
    8.65 -    virtual void FrameResized(float width, float height)
    8.66 -    {
    8.67 -        BRect bounds;
    8.68 -        bounds.top = bounds.left = 0;
    8.69 -        bounds.right = width;
    8.70 -        bounds.bottom = height;
    8.71 -        /* Fill the entire view with black */
    8.72 -        FillRect(bounds, B_SOLID_HIGH);
    8.73 -        /* And if there's an image, redraw it. */
    8.74 -        if (image) {
    8.75 -            bounds = image->Bounds();
    8.76 -            Draw(bounds);
    8.77 -        }
    8.78 -    }
    8.79 -
    8.80 -    /* Drawing portion of this complete breakfast. :) */
    8.81 -    virtual void SetBitmap(BBitmap * bitmap)
    8.82 -    {
    8.83 -        if (image) {
    8.84 -            delete image;
    8.85 -        }
    8.86 -        image = bitmap;
    8.87 -    }
    8.88 -    virtual void Draw(BRect updateRect)
    8.89 -    {
    8.90 -        if (image) {
    8.91 -            if (xoff || yoff) {
    8.92 -                BRect dest;
    8.93 -                dest.top = updateRect.top + yoff;
    8.94 -                dest.left = updateRect.left + xoff;
    8.95 -                dest.bottom = updateRect.bottom + yoff;
    8.96 -                dest.right = updateRect.right + xoff;
    8.97 -                DrawBitmap(image, updateRect, dest);
    8.98 -            } else {
    8.99 -                DrawBitmap(image, updateRect, updateRect);
   8.100 -            }
   8.101 -        }
   8.102 -    }
   8.103 -    virtual void DrawAsync(BRect updateRect)
   8.104 -    {
   8.105 -        if (xoff || yoff) {
   8.106 -            BRect dest;
   8.107 -            dest.top = updateRect.top + yoff;
   8.108 -            dest.left = updateRect.left + xoff;
   8.109 -            dest.bottom = updateRect.bottom + yoff;
   8.110 -            dest.right = updateRect.right + xoff;;
   8.111 -            DrawBitmapAsync(image, updateRect, dest);
   8.112 -        } else {
   8.113 -            DrawBitmapAsync(image, updateRect, updateRect);
   8.114 -        }
   8.115 -    }
   8.116 -
   8.117 -  private:
   8.118 -    BBitmap * image;
   8.119 -    int xoff, yoff;
   8.120 -};
   8.121 -
   8.122 -#endif /* _SDL_BView_h */
   8.123 -/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/bwindow/SDL_BWin.h	Thu Sep 15 08:21:54 2011 -0700
     9.2 +++ b/src/video/bwindow/SDL_BWin.h	Thu Sep 15 23:51:07 2011 -0400
     9.3 @@ -22,7 +22,18 @@
     9.4  #ifndef _SDL_BWin_h
     9.5  #define _SDL_BWin_h
     9.6  
     9.7 +#ifdef __cplusplus
     9.8 +extern "C" {
     9.9 +#endif
    9.10 +
    9.11  #include "SDL_config.h"
    9.12 +#include "SDL.h"
    9.13 +#include "SDL_syswm.h"
    9.14 +#include "SDL_bframebuffer.h"
    9.15 +
    9.16 +#ifdef __cplusplus
    9.17 +}
    9.18 +#endif
    9.19  
    9.20  #include <stdio.h>
    9.21  #include <AppKit.h>
    9.22 @@ -31,537 +42,311 @@
    9.23  #if SDL_VIDEO_OPENGL
    9.24  #include <be/opengl/GLView.h>
    9.25  #endif
    9.26 -#include <support/UTF8.h>
    9.27 +#include "SDL_events.h"
    9.28 +#include "../../main/beos/SDL_BApp.h"
    9.29 +
    9.30  
    9.31 -#include "../../main/beos/SDL_BeApp.h"
    9.32 -#include "SDL_events.h"
    9.33 -#include "SDL_BView.h"
    9.34 +enum WinCommands {
    9.35 +	BWIN_MOVE_WINDOW,
    9.36 +	BWIN_RESIZE_WINDOW,
    9.37 +	BWIN_SHOW_WINDOW,
    9.38 +	BWIN_HIDE_WINDOW,
    9.39 +	BWIN_MAXIMIZE_WINDOW,
    9.40 +	BWIN_MINIMIZE_WINDOW,
    9.41 +	BWIN_RESTORE_WINDOW,
    9.42 +	BWIN_SET_TITLE,
    9.43 +	BWIN_FULLSCREEN
    9.44 +};
    9.45  
    9.46 -extern "C"
    9.47 -{
    9.48 -#include "../../events/SDL_events_c.h"
    9.49 -};
    9.50  
    9.51  class SDL_BWin:public BDirectWindow
    9.52  {
    9.53    public:
    9.54 -    SDL_BWin(BRect bounds):BDirectWindow(bounds, "Untitled",
    9.55 -                                         B_TITLED_WINDOW, 0)
    9.56 +  	/* Constructor/Destructor */
    9.57 +    SDL_BWin(BRect bounds, uint32 flags):BDirectWindow(bounds, "Untitled",
    9.58 +                                         B_TITLED_WINDOW, flags)
    9.59      {
    9.60 -        InitKeyboard();
    9.61 -        last_buttons = 0;
    9.62 +        _last_buttons = 0;
    9.63  
    9.64 -        the_view = NULL;
    9.65  #if SDL_VIDEO_OPENGL
    9.66 -        SDL_GLView = NULL;
    9.67 +        _SDL_GLView = NULL;
    9.68  #endif
    9.69 -        SDL_View = NULL;
    9.70 -        Unlock();
    9.71 -        shown = false;
    9.72 -        inhibit_resize = false;
    9.73 +        _shown = false;
    9.74 +        _inhibit_resize = false;
    9.75 +        _mouse_focused = false;
    9.76 +        _prev_frame = NULL;
    9.77 +
    9.78 +        /* Handle framebuffer stuff */
    9.79 +        _connected = _connection_disabled = false;
    9.80 +        _buffer_created = _buffer_dirty = false;
    9.81 +        _trash_window_buffer = false;
    9.82 +        _buffer_locker = new BLocker();
    9.83 +        _bitmap = NULL;
    9.84 +#ifdef DRAWTHREAD
    9.85 +        _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
    9.86 +        					B_NORMAL_PRIORITY, (void*) this);
    9.87 +        resume_thread(_draw_thread_id);
    9.88 +#endif
    9.89      }
    9.90  
    9.91      virtual ~ SDL_BWin()
    9.92      {
    9.93          Lock();
    9.94 -        if (the_view) {
    9.95 +        _connection_disabled = true;
    9.96 +        int32 result;
    9.97 +        
    9.98  #if SDL_VIDEO_OPENGL
    9.99 -            if (the_view == SDL_GLView) {
   9.100 -                SDL_GLView->UnlockGL();
   9.101 -            }
   9.102 -#endif
   9.103 -            RemoveChild(the_view);
   9.104 -            the_view = NULL;
   9.105 +        if (_SDL_GLView) {
   9.106 +            _SDL_GLView->UnlockGL();
   9.107 +            RemoveChild(_SDL_GLView);	/* Why was this outside the if
   9.108 +            								statement before? */
   9.109          }
   9.110 +        
   9.111 +#endif    
   9.112          Unlock();
   9.113  #if SDL_VIDEO_OPENGL
   9.114 -        if (SDL_GLView) {
   9.115 -            delete SDL_GLView;
   9.116 -        }
   9.117 -#endif
   9.118 -        if (SDL_View) {
   9.119 -            delete SDL_View;
   9.120 -        }
   9.121 -    }
   9.122 -
   9.123 -    virtual void InitKeyboard(void)
   9.124 -    {
   9.125 -        for (uint i = 0; i < SDL_TABLESIZE(keymap); ++i)
   9.126 -            keymap[i] = SDLK_UNKNOWN;
   9.127 -
   9.128 -        keymap[0x01] = SDLK_ESCAPE;
   9.129 -        keymap[B_F1_KEY] = SDLK_F1;
   9.130 -        keymap[B_F2_KEY] = SDLK_F2;
   9.131 -        keymap[B_F3_KEY] = SDLK_F3;
   9.132 -        keymap[B_F4_KEY] = SDLK_F4;
   9.133 -        keymap[B_F5_KEY] = SDLK_F5;
   9.134 -        keymap[B_F6_KEY] = SDLK_F6;
   9.135 -        keymap[B_F7_KEY] = SDLK_F7;
   9.136 -        keymap[B_F8_KEY] = SDLK_F8;
   9.137 -        keymap[B_F9_KEY] = SDLK_F9;
   9.138 -        keymap[B_F10_KEY] = SDLK_F10;
   9.139 -        keymap[B_F11_KEY] = SDLK_F11;
   9.140 -        keymap[B_F12_KEY] = SDLK_F12;
   9.141 -        keymap[B_PRINT_KEY] = SDLK_PRINTSCREEN;
   9.142 -        keymap[B_SCROLL_KEY] = SDLK_SCROLLLOCK;
   9.143 -        keymap[B_PAUSE_KEY] = SDLK_PAUSE;
   9.144 -        keymap[0x11] = SDLK_BACKQUOTE;
   9.145 -        keymap[0x12] = SDLK_1;
   9.146 -        keymap[0x13] = SDLK_2;
   9.147 -        keymap[0x14] = SDLK_3;
   9.148 -        keymap[0x15] = SDLK_4;
   9.149 -        keymap[0x16] = SDLK_5;
   9.150 -        keymap[0x17] = SDLK_6;
   9.151 -        keymap[0x18] = SDLK_7;
   9.152 -        keymap[0x19] = SDLK_8;
   9.153 -        keymap[0x1a] = SDLK_9;
   9.154 -        keymap[0x1b] = SDLK_0;
   9.155 -        keymap[0x1c] = SDLK_MINUS;
   9.156 -        keymap[0x1d] = SDLK_EQUALS;
   9.157 -        keymap[0x1e] = SDLK_BACKSPACE;
   9.158 -        keymap[0x1f] = SDLK_INSERT;
   9.159 -        keymap[0x20] = SDLK_HOME;
   9.160 -        keymap[0x21] = SDLK_PAGEUP;
   9.161 -        keymap[0x22] = SDLK_NUMLOCKCLEAR;
   9.162 -        keymap[0x23] = SDLK_KP_DIVIDE;
   9.163 -        keymap[0x24] = SDLK_KP_MULTIPLY;
   9.164 -        keymap[0x25] = SDLK_KP_MINUS;
   9.165 -        keymap[0x26] = SDLK_TAB;
   9.166 -        keymap[0x27] = SDLK_q;
   9.167 -        keymap[0x28] = SDLK_w;
   9.168 -        keymap[0x29] = SDLK_e;
   9.169 -        keymap[0x2a] = SDLK_r;
   9.170 -        keymap[0x2b] = SDLK_t;
   9.171 -        keymap[0x2c] = SDLK_y;
   9.172 -        keymap[0x2d] = SDLK_u;
   9.173 -        keymap[0x2e] = SDLK_i;
   9.174 -        keymap[0x2f] = SDLK_o;
   9.175 -        keymap[0x30] = SDLK_p;
   9.176 -        keymap[0x31] = SDLK_LEFTBRACKET;
   9.177 -        keymap[0x32] = SDLK_RIGHTBRACKET;
   9.178 -        keymap[0x33] = SDLK_BACKSLASH;
   9.179 -        keymap[0x34] = SDLK_DELETE;
   9.180 -        keymap[0x35] = SDLK_END;
   9.181 -        keymap[0x36] = SDLK_PAGEDOWN;
   9.182 -        keymap[0x37] = SDLK_KP_7;
   9.183 -        keymap[0x38] = SDLK_KP_8;
   9.184 -        keymap[0x39] = SDLK_KP_9;
   9.185 -        keymap[0x3a] = SDLK_KP_PLUS;
   9.186 -        keymap[0x3b] = SDLK_CAPSLOCK;
   9.187 -        keymap[0x3c] = SDLK_a;
   9.188 -        keymap[0x3d] = SDLK_s;
   9.189 -        keymap[0x3e] = SDLK_d;
   9.190 -        keymap[0x3f] = SDLK_f;
   9.191 -        keymap[0x40] = SDLK_g;
   9.192 -        keymap[0x41] = SDLK_h;
   9.193 -        keymap[0x42] = SDLK_j;
   9.194 -        keymap[0x43] = SDLK_k;
   9.195 -        keymap[0x44] = SDLK_l;
   9.196 -        keymap[0x45] = SDLK_SEMICOLON;
   9.197 -        keymap[0x46] = SDLK_QUOTE;
   9.198 -        keymap[0x47] = SDLK_RETURN;
   9.199 -        keymap[0x48] = SDLK_KP_4;
   9.200 -        keymap[0x49] = SDLK_KP_5;
   9.201 -        keymap[0x4a] = SDLK_KP_6;
   9.202 -        keymap[0x4b] = SDLK_LSHIFT;
   9.203 -        keymap[0x4c] = SDLK_z;
   9.204 -        keymap[0x4d] = SDLK_x;
   9.205 -        keymap[0x4e] = SDLK_c;
   9.206 -        keymap[0x4f] = SDLK_v;
   9.207 -        keymap[0x50] = SDLK_b;
   9.208 -        keymap[0x51] = SDLK_n;
   9.209 -        keymap[0x52] = SDLK_m;
   9.210 -        keymap[0x53] = SDLK_COMMA;
   9.211 -        keymap[0x54] = SDLK_PERIOD;
   9.212 -        keymap[0x55] = SDLK_SLASH;
   9.213 -        keymap[0x56] = SDLK_RSHIFT;
   9.214 -        keymap[0x57] = SDLK_UP;
   9.215 -        keymap[0x58] = SDLK_KP_1;
   9.216 -        keymap[0x59] = SDLK_KP_2;
   9.217 -        keymap[0x5a] = SDLK_KP_3;
   9.218 -        keymap[0x5b] = SDLK_KP_ENTER;
   9.219 -        keymap[0x5c] = SDLK_LCTRL;
   9.220 -        keymap[0x5d] = SDLK_LALT;
   9.221 -        keymap[0x5e] = SDLK_SPACE;
   9.222 -        keymap[0x5f] = SDLK_RALT;
   9.223 -        keymap[0x60] = SDLK_RCTRL;
   9.224 -        keymap[0x61] = SDLK_LEFT;
   9.225 -        keymap[0x62] = SDLK_DOWN;
   9.226 -        keymap[0x63] = SDLK_RIGHT;
   9.227 -        keymap[0x64] = SDLK_KP_0;
   9.228 -        keymap[0x65] = SDLK_KP_PERIOD;
   9.229 -        keymap[0x66] = SDLK_LGUI;
   9.230 -        keymap[0x67] = SDLK_RGUI;
   9.231 -        keymap[0x68] = SDLK_MENU;
   9.232 -        keymap[0x69] = SDLK_2; //SDLK_EURO;
   9.233 -        keymap[0x6a] = SDLK_KP_EQUALS;
   9.234 -        keymap[0x6b] = SDLK_POWER;
   9.235 -    }
   9.236 -
   9.237 -    /* Override the Show() method so we can tell when we've been shown */
   9.238 -    virtual void Show(void)
   9.239 -    {
   9.240 -        BWindow::Show();
   9.241 -        shown = true;
   9.242 -    }
   9.243 -    virtual bool Shown(void)
   9.244 -    {
   9.245 -        return (shown);
   9.246 -    }
   9.247 -    /* If called, the next resize event will not be forwarded to SDL. */
   9.248 -    virtual void InhibitResize(void)
   9.249 -    {
   9.250 -        inhibit_resize = true;
   9.251 -    }
   9.252 -    /* Handle resizing of the window */
   9.253 -    virtual void FrameResized(float width, float height)
   9.254 -    {
   9.255 -        if (inhibit_resize)
   9.256 -            inhibit_resize = false;
   9.257 -        else
   9.258 -            SDL_PrivateResize((int) width, (int) height);
   9.259 -    }
   9.260 -    virtual int CreateView(Uint32 flags, Uint32 gl_flags)
   9.261 -    {
   9.262 -        int retval;
   9.263 -
   9.264 -        retval = 0;
   9.265 -        Lock();
   9.266 -        if (flags & SDL_INTERNALOPENGL) {
   9.267 -#if SDL_VIDEO_OPENGL
   9.268 -            if (SDL_GLView == NULL) {
   9.269 -                SDL_GLView = new BGLView(Bounds(), "SDL GLView",
   9.270 -                                         B_FOLLOW_ALL_SIDES,
   9.271 -                                         (B_WILL_DRAW | B_FRAME_EVENTS),
   9.272 -                                         gl_flags);
   9.273 -            }
   9.274 -            if (the_view != SDL_GLView) {
   9.275 -                if (the_view) {
   9.276 -                    RemoveChild(the_view);
   9.277 -                }
   9.278 -                AddChild(SDL_GLView);
   9.279 -                SDL_GLView->LockGL();
   9.280 -                the_view = SDL_GLView;
   9.281 -            }
   9.282 -#else
   9.283 -            SDL_SetError("OpenGL support not enabled");
   9.284 -            retval = -1;
   9.285 -#endif
   9.286 -        } else {
   9.287 -            if (SDL_View == NULL) {
   9.288 -                SDL_View = new SDL_BView(Bounds());
   9.289 -            }
   9.290 -            if (the_view != SDL_View) {
   9.291 -                if (the_view) {
   9.292 -#if SDL_VIDEO_OPENGL
   9.293 -                    if (the_view == SDL_GLView) {
   9.294 -                        SDL_GLView->UnlockGL();
   9.295 -                    }
   9.296 -#endif
   9.297 -                    RemoveChild(the_view);
   9.298 -                }
   9.299 -                AddChild(SDL_View);
   9.300 -                the_view = SDL_View;
   9.301 -            }
   9.302 -        }
   9.303 -        Unlock();
   9.304 -        return (retval);
   9.305 -    }
   9.306 -    virtual void SetBitmap(BBitmap * bitmap)
   9.307 -    {
   9.308 -        SDL_View->SetBitmap(bitmap);
   9.309 -    }
   9.310 -    virtual void SetXYOffset(int x, int y)
   9.311 -    {
   9.312 -#if SDL_VIDEO_OPENGL
   9.313 -        if (the_view == SDL_GLView) {
   9.314 -            return;
   9.315 +        if (_SDL_GLView) {
   9.316 +            delete _SDL_GLView;
   9.317          }
   9.318  #endif
   9.319 -        SDL_View->SetXYOffset(x, y);
   9.320 -    }
   9.321 -    virtual void GetXYOffset(int &x, int &y)
   9.322 -    {
   9.323 -#if SDL_VIDEO_OPENGL
   9.324 -        if (the_view == SDL_GLView) {
   9.325 -            x = 0;
   9.326 -            y = 0;
   9.327 -            return;
   9.328 -        }
   9.329 +        
   9.330 +        /* Clean up framebuffer stuff */
   9.331 +        _buffer_locker->Lock();
   9.332 +#ifdef DRAWTHREAD
   9.333 +        wait_for_thread(_draw_thread_id, &result);
   9.334  #endif
   9.335 -        SDL_View->GetXYOffset(x, y);
   9.336 -    }
   9.337 -    virtual bool BeginDraw(void)
   9.338 -    {
   9.339 -        return (Lock());
   9.340 +        free(_clips);
   9.341 +        delete _buffer_locker;
   9.342      }
   9.343 -    virtual void DrawAsync(BRect updateRect)
   9.344 -    {
   9.345 -        SDL_View->DrawAsync(updateRect);
   9.346 -    }
   9.347 -    virtual void EndDraw(void)
   9.348 -    {
   9.349 -        SDL_View->Sync();
   9.350 +    
   9.351 +
   9.352 +    /* * * * * OpenGL functionality * * * * */
   9.353 +#if SDL_VIDEO_OPENGL
   9.354 +    virtual BGLView *CreateGLView(Uint32 gl_flags) {
   9.355 +        Lock();
   9.356 +        if (_SDL_GLView == NULL) {
   9.357 +            _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
   9.358 +                                     B_FOLLOW_ALL_SIDES,
   9.359 +                                     (B_WILL_DRAW | B_FRAME_EVENTS),
   9.360 +                                     gl_flags);
   9.361 +        }
   9.362 +        AddChild(_SDL_GLView);
   9.363 +        _SDL_GLView->EnableDirectMode(true);
   9.364 +        _SDL_GLView->LockGL();	/* "New" GLViews are created */
   9.365          Unlock();
   9.366 +        return (_SDL_GLView);
   9.367      }
   9.368 -#if SDL_VIDEO_OPENGL
   9.369 -    virtual void SwapBuffers(void)
   9.370 -    {
   9.371 -        SDL_GLView->UnlockGL();
   9.372 -        SDL_GLView->LockGL();
   9.373 -        SDL_GLView->SwapBuffers();
   9.374 +    
   9.375 +    virtual void RemoveGLView() {
   9.376 +    	Lock();
   9.377 +    	if(_SDL_GLView) {
   9.378 +    		_SDL_GLView->UnlockGL();
   9.379 +    		RemoveChild(_SDL_GLView);
   9.380 +    	}
   9.381 +    	Unlock();
   9.382      }
   9.383 +    
   9.384 +    virtual void SwapBuffers(void) {
   9.385 +		_SDL_GLView->UnlockGL();
   9.386 +		_SDL_GLView->LockGL();
   9.387 +		_SDL_GLView->SwapBuffers();
   9.388 +	}
   9.389  #endif
   9.390 -    virtual BView *View(void)
   9.391 -    {
   9.392 -        return (the_view);
   9.393 -    }
   9.394 +    
   9.395 +    /* * * * * Framebuffering* * * * */
   9.396 +    virtual void DirectConnected(direct_buffer_info *info) {
   9.397 +    	if(!_connected && _connection_disabled) {
   9.398 +    		return;
   9.399 +    	}
   9.400 +
   9.401 +		/* Determine if the pixel buffer is usable after this update */
   9.402 +		_trash_window_buffer =		_trash_window_buffer
   9.403 +								|| ((info->buffer_state & B_BUFFER_RESIZED)
   9.404 +    							|| (info->buffer_state & B_BUFFER_RESET)
   9.405 +    							|| (info->driver_state == B_MODE_CHANGED));
   9.406 +    	LockBuffer();
   9.407 +
   9.408 +    	switch(info->buffer_state & B_DIRECT_MODE_MASK) {
   9.409 +    	case B_DIRECT_START:
   9.410 +    		_connected = true;
   9.411  
   9.412 -    /* Hook functions -- overridden */
   9.413 -    virtual void Minimize(bool minimize)
   9.414 -    {
   9.415 -        /* This is only called when mimimized, not when restored */
   9.416 -        //SDL_PrivateAppActive(minimize, SDL_APPACTIVE);
   9.417 -        BWindow::Minimize(minimize);
   9.418 -    }
   9.419 -    virtual void WindowActivated(bool active)
   9.420 -    {
   9.421 -        SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS);
   9.422 +    	case B_DIRECT_MODIFY:
   9.423 +    		if(_clips) {
   9.424 +    			free(_clips);
   9.425 +    			_clips = NULL;
   9.426 +    		}
   9.427 +    		
   9.428 +    		_num_clips = info->clip_list_count;
   9.429 +    		_clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
   9.430 +    		if(_clips) {
   9.431 +    			memcpy(_clips, info->clip_list,
   9.432 +    				_num_clips*sizeof(clipping_rect));
   9.433 +    			
   9.434 +    			_bits = (uint8*) info->bits;
   9.435 +    			_row_bytes = info->bytes_per_row;
   9.436 +    			_bounds = info->window_bounds;
   9.437 +    			_bytes_per_px = info->bits_per_pixel / 8;
   9.438 +    			_buffer_dirty = true;
   9.439 +    		}
   9.440 +    		break;
   9.441 +
   9.442 +    	case B_DIRECT_STOP:
   9.443 +    		_connected = false;
   9.444 +    		break;
   9.445 +    	}
   9.446 +#if SDL_VIDEO_OPENGL
   9.447 +		if(_SDL_GLView) {
   9.448 +			_SDL_GLView->DirectConnected(info);
   9.449 +		}
   9.450 +#endif
   9.451 +    	
   9.452 +    	
   9.453 +    	/* Call the base object directconnected */
   9.454 +    	BDirectWindow::DirectConnected(info);
   9.455 +    	
   9.456 +    	UnlockBuffer();
   9.457 +    	
   9.458      }
   9.459 -    virtual bool QuitRequested(void)
   9.460 -    {
   9.461 -        if (SDL_BeAppActive > 0) {
   9.462 -            SDL_PrivateQuit();
   9.463 -            /* We don't ever actually close the window here because
   9.464 -               the application should respond to the quit request,
   9.465 -               or ignore it as desired.
   9.466 -             */
   9.467 -            return (false);
   9.468 -        }
   9.469 -        return (true);          /* Close the app window */
   9.470 +    
   9.471 +    
   9.472 +    
   9.473 +    
   9.474 +    /* * * * * Event sending * * * * */
   9.475 +    /* Hook functions */
   9.476 +    virtual void FrameMoved(BPoint origin) {
   9.477 +    	/* Post a message to the BApp so that it can handle the window event */
   9.478 +    	BMessage msg(BAPP_WINDOW_MOVED);
   9.479 +		msg.AddInt32("window-x", (int)origin.x);
   9.480 +		msg.AddInt32("window-y", (int)origin.y);
   9.481 +    	_PostWindowEvent(msg);
   9.482 +		
   9.483 +		/* Perform normal hook operations */
   9.484 +    	BDirectWindow::FrameMoved(origin);
   9.485      }
   9.486 -    virtual void Quit()
   9.487 -    {
   9.488 -        if (!IsLocked())
   9.489 -            Lock();
   9.490 -        BDirectWindow::Quit();
   9.491 +    
   9.492 +    virtual void FrameResized(float width, float height) {
   9.493 +    	/* Post a message to the BApp so that it can handle the window event */
   9.494 +    	BMessage msg(BAPP_WINDOW_RESIZED);
   9.495 +
   9.496 +		msg.AddInt32("window-w", (int)width + 1);
   9.497 +		msg.AddInt32("window-h", (int)height + 1);
   9.498 +    	_PostWindowEvent(msg);
   9.499 +		
   9.500 +		/* Perform normal hook operations */
   9.501 +    	BDirectWindow::FrameResized(width, height);
   9.502      }
   9.503  
   9.504 -    virtual int16 Translate2Unicode(const char *buf)
   9.505 -    {
   9.506 -        int32 state, srclen, dstlen;
   9.507 -        unsigned char destbuf[2];
   9.508 -        Uint16 unicode = 0;
   9.509 -
   9.510 -        if ((uchar) buf[0] > 127) {
   9.511 -            state = 0;
   9.512 -            srclen = SDL_strlen(buf);
   9.513 -            dstlen = sizeof(destbuf);
   9.514 -            convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen,
   9.515 -                              (char *) destbuf, &dstlen, &state);
   9.516 -            unicode = destbuf[0];
   9.517 -            unicode <<= 8;
   9.518 -            unicode |= destbuf[1];
   9.519 -        } else
   9.520 -            unicode = buf[0];
   9.521 +	virtual bool QuitRequested() {
   9.522 +    	BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED);
   9.523 +    	_PostWindowEvent(msg);
   9.524  
   9.525 -        /* For some reason function keys map to control characters */
   9.526 -# define CTRL(X)	((X)-'@')
   9.527 -        switch (unicode) {
   9.528 -        case CTRL('A'):
   9.529 -        case CTRL('B'):
   9.530 -        case CTRL('C'):
   9.531 -        case CTRL('D'):
   9.532 -        case CTRL('E'):
   9.533 -        case CTRL('K'):
   9.534 -        case CTRL('L'):
   9.535 -        case CTRL('P'):
   9.536 -            if (!(SDL_GetModState() & KMOD_CTRL))
   9.537 -                unicode = 0;
   9.538 -            break;
   9.539 -            /* Keyboard input maps newline to carriage return */
   9.540 -        case '\n':
   9.541 -            unicode = '\r';
   9.542 -            break;
   9.543 -        default:
   9.544 -            break;
   9.545 -        }
   9.546 +    	/* We won't allow a quit unless asked by DestroyWindow() */
   9.547 +    	return false;	
   9.548 +    }
   9.549 +    
   9.550 +    virtual void WindowActivated(bool active) {
   9.551 +    	BMessage msg(BAPP_KEYBOARD_FOCUS);	/* Mouse focus sold separately */
   9.552 +    	_PostWindowEvent(msg);
   9.553 +    }
   9.554 +    
   9.555 +    virtual void Zoom(BPoint origin,
   9.556 +				float width,
   9.557 +				float height) {
   9.558 +		BMessage msg(BAPP_MAXIMIZE);	/* Closest thing to maximization Haiku has */
   9.559 +    	_PostWindowEvent(msg);
   9.560 +    	
   9.561 +    	/* Before the window zooms, record its size */
   9.562 +    	if( !_prev_frame )
   9.563 +    		_prev_frame = new BRect(Frame());
   9.564  
   9.565 -        return unicode;
   9.566 +    	/* Perform normal hook operations */
   9.567 +    	BDirectWindow::Zoom(origin, width, height);
   9.568 +    }
   9.569 +    
   9.570 +    /* Member functions */
   9.571 +    virtual void Show() {
   9.572 +    	while(IsHidden()) {
   9.573 +    		BDirectWindow::Show();
   9.574 +    	}
   9.575 +    	_shown = true;
   9.576 +
   9.577 +    	BMessage msg(BAPP_SHOW);
   9.578 +    	_PostWindowEvent(msg);
   9.579 +    }
   9.580 +    
   9.581 +    virtual void Hide() {
   9.582 +    	BDirectWindow::Hide();
   9.583 +    	_shown = false;
   9.584 +
   9.585 +    	BMessage msg(BAPP_HIDE);
   9.586 +    	_PostWindowEvent(msg);
   9.587      }
   9.588  
   9.589 +    virtual void Minimize(bool minimize) {
   9.590 +    	BDirectWindow::Minimize(minimize);
   9.591 +    	int32 minState = (minimize ? BAPP_MINIMIZE : BAPP_RESTORE);
   9.592 +    	
   9.593 +    	BMessage msg(minState);
   9.594 +    	_PostWindowEvent(msg);
   9.595 +    }
   9.596 +    
   9.597 +    
   9.598 +    /* BView message interruption */
   9.599      virtual void DispatchMessage(BMessage * msg, BHandler * target)
   9.600      {
   9.601 +        BPoint where;	/* Used by mouse moved */
   9.602 +        int32 buttons;	/* Used for mouse button events */
   9.603 +        int32 key;		/* Used for key events */
   9.604 +        
   9.605          switch (msg->what) {
   9.606          case B_MOUSE_MOVED:
   9.607 -            {
   9.608 -                BPoint where;
   9.609 -                int32 transit;
   9.610 -                if (msg->FindPoint("where", &where) == B_OK
   9.611 -                    && msg->FindInt32("be:transit", &transit) == B_OK) {
   9.612 -                    if (transit == B_EXITED_VIEW) {
   9.613 -                        if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
   9.614 -                            SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   9.615 -                            be_app->SetCursor(B_HAND_CURSOR);
   9.616 -                        }
   9.617 -                    } else {
   9.618 -                        int x, y;
   9.619 -                        if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
   9.620 -                            SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   9.621 -                            SDL_SetCursor(NULL);
   9.622 -                        }
   9.623 -                        GetXYOffset(x, y);
   9.624 -                        x = (int) where.x - x;
   9.625 -                        y = (int) where.y - y;
   9.626 -                        SDL_PrivateMouseMotion(0, 0, x, y);
   9.627 -                    }
   9.628 -                }
   9.629 -                break;
   9.630 +            where;
   9.631 +            int32 transit;
   9.632 +            if (msg->FindPoint("where", &where) == B_OK
   9.633 +                && msg->FindInt32("be:transit", &transit) == B_OK) {
   9.634 +            	_MouseMotionEvent(where, transit);
   9.635              }
   9.636 +            
   9.637 +            /* FIXME: Apparently a button press/release event might be dropped
   9.638 +               if made before before a different button is released.  Does
   9.639 +               B_MOUSE_MOVED have the data needed to check if a mouse button
   9.640 +               state has changed? */
   9.641 +            if (msg->FindInt32("buttons", &buttons) == B_OK) {
   9.642 +				_MouseButtonEvent(buttons);
   9.643 +            }
   9.644 +            break;
   9.645  
   9.646          case B_MOUSE_DOWN:
   9.647 -            {
   9.648 -                /*      it looks like mouse down is send only for first clicked
   9.649 -                   button, each next is not send while last one is holded */
   9.650 -                int32 buttons;
   9.651 -                int sdl_buttons = 0;
   9.652 -                if (msg->FindInt32("buttons", &buttons) == B_OK) {
   9.653 -                    /* Add any mouse button events */
   9.654 -                    if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   9.655 -                        sdl_buttons |= SDL_BUTTON_LEFT;
   9.656 -                    }
   9.657 -                    if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   9.658 -                        sdl_buttons |= SDL_BUTTON_RIGHT;
   9.659 -                    }
   9.660 -                    if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   9.661 -                        sdl_buttons |= SDL_BUTTON_MIDDLE;
   9.662 -                    }
   9.663 -                    SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
   9.664 -
   9.665 -                    last_buttons = buttons;
   9.666 -                }
   9.667 -                break;
   9.668 +        case B_MOUSE_UP:
   9.669 +            /* _MouseButtonEvent() detects any and all buttons that may have
   9.670 +               changed state, as well as that button's new state */
   9.671 +            if (msg->FindInt32("buttons", &buttons) == B_OK) {
   9.672 +				_MouseButtonEvent(buttons);
   9.673              }
   9.674 -
   9.675 -        case B_MOUSE_UP:
   9.676 -            {
   9.677 -                /*      mouse up doesn't give which button was released,
   9.678 -                   only state of buttons (after release, so it's always = 0),
   9.679 -                   which is not what we need ;]
   9.680 -                   So we need to store button in mouse down, and restore
   9.681 -                   in mouse up :(
   9.682 -                   mouse up is (similarly to mouse down) send only for
   9.683 -                   first button down (ie. it's no send if we click another button
   9.684 -                   without releasing previous one first) - but that's probably
   9.685 -                   because of how drivers are written?, not BeOS itself. */
   9.686 -                int32 buttons;
   9.687 -                int sdl_buttons = 0;
   9.688 -                if (msg->FindInt32("buttons", &buttons) == B_OK) {
   9.689 -                    /* Add any mouse button events */
   9.690 -                    if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   9.691 -                        sdl_buttons |= SDL_BUTTON_LEFT;
   9.692 -                    }
   9.693 -                    if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   9.694 -                        sdl_buttons |= SDL_BUTTON_RIGHT;
   9.695 -                    }
   9.696 -                    if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   9.697 -                        sdl_buttons |= SDL_BUTTON_MIDDLE;
   9.698 -                    }
   9.699 -                    SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
   9.700 -
   9.701 -                    last_buttons = buttons;
   9.702 -                }
   9.703 -                break;
   9.704 -            }
   9.705 +            break;
   9.706  
   9.707          case B_MOUSE_WHEEL_CHANGED:
   9.708 -            {
   9.709 -                float x, y;
   9.710 -                x = y = 0;
   9.711 -                if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
   9.712 -                    && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   9.713 -                    if (x < 0 || y < 0) {
   9.714 -                        SDL_PrivateMouseButton(SDL_PRESSED,
   9.715 -                                               SDL_BUTTON_WHEELDOWN, 0, 0);
   9.716 -                        SDL_PrivateMouseButton(SDL_RELEASED,
   9.717 -                                               SDL_BUTTON_WHEELDOWN, 0, 0);
   9.718 -                    } else if (x > 0 || y > 0) {
   9.719 -                        SDL_PrivateMouseButton(SDL_PRESSED,
   9.720 -                                               SDL_BUTTON_WHEELUP, 0, 0);
   9.721 -                        SDL_PrivateMouseButton(SDL_RELEASED,
   9.722 -                                               SDL_BUTTON_WHEELUP, 0, 0);
   9.723 -                    }
   9.724 -                }
   9.725 -                break;
   9.726 -            }
   9.727 +        	float x, y;
   9.728 +        	if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
   9.729 +        		&& msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   9.730 +        			_MouseWheelEvent((int)x, (int)y);
   9.731 +        	}
   9.732 +        	break;
   9.733  
   9.734          case B_KEY_DOWN:
   9.735          case B_UNMAPPED_KEY_DOWN:      /* modifier keys are unmapped */
   9.736 -            {
   9.737 -                int32 key;
   9.738 -                int32 modifiers;
   9.739 -                int32 key_repeat;
   9.740 -                /* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
   9.741 -                if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK
   9.742 -                    && key_repeat > 0)
   9.743 -                    break;
   9.744 -
   9.745 -                if (msg->FindInt32("key", &key) == B_OK
   9.746 -                    && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   9.747 -                    SDL_Keysym keysym;
   9.748 -                    keysym.scancode = key;
   9.749 -                    if ((key > 0) && (key < 128)) {
   9.750 -                        keysym.sym = keymap[key];
   9.751 -                    } else {
   9.752 -                        keysym.sym = SDLK_UNKNOWN;
   9.753 -                    }
   9.754 -                    /*      FIX THIS?
   9.755 -                       it seems SDL_PrivateKeyboard() changes mod value
   9.756 -                       anyway, and doesn't care about what we setup here */
   9.757 -                    keysym.mod = KMOD_NONE;
   9.758 -                    keysym.unicode = 0;
   9.759 -                    if (SDL_TranslateUNICODE) {
   9.760 -                        const char *bytes;
   9.761 -                        if (msg->FindString("bytes", &bytes) == B_OK) {
   9.762 -                            /*      FIX THIS?
   9.763 -                               this cares only about first "letter",
   9.764 -                               so if someone maps some key to print
   9.765 -                               "BeOS rulez!" only "B" will be used. */
   9.766 -                            keysym.unicode = Translate2Unicode(bytes);
   9.767 -                        }
   9.768 -                    }
   9.769 -                    SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   9.770 -                }
   9.771 -                break;
   9.772 -            }
   9.773 +        	if (msg->FindInt32("key", &key) == B_OK) {
   9.774 +        		_KeyEvent((SDL_Scancode)key, SDL_PRESSED);
   9.775 +        	}
   9.776 +        	break;
   9.777  
   9.778          case B_KEY_UP:
   9.779          case B_UNMAPPED_KEY_UP:        /* modifier keys are unmapped */
   9.780 -            {
   9.781 -                int32 key;
   9.782 -                int32 modifiers;
   9.783 -                if (msg->FindInt32("key", &key) == B_OK
   9.784 -                    && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   9.785 -                    SDL_Keysym keysym;
   9.786 -                    keysym.scancode = key;
   9.787 -                    if ((key > 0) && (key < 128)) {
   9.788 -                        keysym.sym = keymap[key];
   9.789 -                    } else {
   9.790 -                        keysym.sym = SDLK_UNKNOWN;
   9.791 -                    }
   9.792 -                    keysym.mod = KMOD_NONE;     /* FIX THIS? */
   9.793 -                    keysym.unicode = 0;
   9.794 -                    if (SDL_TranslateUNICODE) {
   9.795 -                        const char *bytes;
   9.796 -                        if (msg->FindString("bytes", &bytes) == B_OK) {
   9.797 -                            keysym.unicode = Translate2Unicode(bytes);
   9.798 -                        }
   9.799 -                    }
   9.800 -                    SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   9.801 -                }
   9.802 -                break;
   9.803 +        	if (msg->FindInt32("key", &key) == B_OK) {
   9.804 +            	_KeyEvent(key, SDL_RELEASED);
   9.805              }
   9.806 -
   9.807 +            break;
   9.808 +        	
   9.809          default:
   9.810              /* move it after switch{} so it's always handled
   9.811                 that way we keep BeOS feautures like:
   9.812 @@ -571,22 +356,271 @@
   9.813              //BDirectWindow::DispatchMessage(msg, target);
   9.814              break;
   9.815          }
   9.816 +
   9.817          BDirectWindow::DispatchMessage(msg, target);
   9.818      }
   9.819 +    
   9.820 +    /* Handle command messages */
   9.821 +    virtual void MessageReceived(BMessage* message) {
   9.822 +    	switch (message->what) {
   9.823 +    		/* Handle commands from SDL */
   9.824 +    		case BWIN_SET_TITLE:
   9.825 +    			_SetTitle(message);
   9.826 +    			break;
   9.827 +    		case BWIN_MOVE_WINDOW: 
   9.828 +    			_MoveTo(message);
   9.829 +    			break;
   9.830 +    		case BWIN_RESIZE_WINDOW:
   9.831 +    			_ResizeTo(message);
   9.832 +    			break;
   9.833 +    		case BWIN_SHOW_WINDOW:
   9.834 +    			Show();
   9.835 +    			break;
   9.836 +    		case BWIN_HIDE_WINDOW:
   9.837 +    			Hide();
   9.838 +    			break;
   9.839 +    		case BWIN_MAXIMIZE_WINDOW:
   9.840 +    			BWindow::Zoom();
   9.841 +    			break;
   9.842 +			case BWIN_MINIMIZE_WINDOW:
   9.843 +				Minimize(true);
   9.844 +    			break;
   9.845 +    		case BWIN_RESTORE_WINDOW:
   9.846 +    			_Restore();
   9.847 +    			break;
   9.848 +    		case BWIN_FULLSCREEN:
   9.849 +    			_SetFullScreen(message);
   9.850 +    			break;
   9.851 +    		default:
   9.852 +    			/* Perform normal message handling */
   9.853 +    			BDirectWindow::MessageReceived(message);
   9.854 +    			break;
   9.855 +    	}
   9.856 +
   9.857 +    }
   9.858 +    
   9.859 +    
   9.860 +
   9.861 +	/* Accessor methods */
   9.862 +	bool IsShown() { return _shown; }
   9.863 +	int32 GetID() { return _id; }
   9.864 +	uint32 GetRowBytes() { return _row_bytes; }
   9.865 +	int32 GetFbX() { return _bounds.left; }
   9.866 +	int32 GetFbY() { return _bounds.top; }
   9.867 +	bool ConnectionEnabled() { return !_connection_disabled; }
   9.868 +	bool Connected() { return _connected; }
   9.869 +	clipping_rect *GetClips() { return _clips; }
   9.870 +	int32 GetNumClips() { return _num_clips; }
   9.871 +	uint8* GetBufferPx() { return _bits; }
   9.872 +	int32 GetBytesPerPx() { return _bytes_per_px; }
   9.873 +	bool CanTrashWindowBuffer() { return _trash_window_buffer; }
   9.874 +	bool BufferExists() { return _buffer_created; }
   9.875 +	bool BufferIsDirty() { return _buffer_dirty; }
   9.876 +	BBitmap *GetBitmap() { return _bitmap; }
   9.877 +#if SDL_VIDEO_OPENGL
   9.878 +	BGLView *GetGLView() { return _SDL_GLView; }
   9.879 +#endif
   9.880 +	
   9.881 +	/* Setter methods */
   9.882 +	void SetID(int32 id) { _id = id; }
   9.883 +	void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
   9.884 +	void LockBuffer() {	_buffer_locker->Lock(); }
   9.885 +	void UnlockBuffer() { _buffer_locker->Unlock(); }
   9.886 +	void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
   9.887 +	void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; 	}
   9.888 +	void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; }
   9.889 +	
   9.890 +	
   9.891 +private:
   9.892 +	/* Event redirection */
   9.893 +    void _MouseMotionEvent(BPoint &where, int32 transit) {
   9.894 +    	if(transit == B_EXITED_VIEW) {
   9.895 +    		/* Change mouse focus */
   9.896 +    		if(_mouse_focused) {
   9.897 +    			_MouseFocusEvent(false);
   9.898 +    		}
   9.899 +    	} else {
   9.900 +    		static int x = 0, y = 0;
   9.901 +    		/* Change mouse focus */
   9.902 +    		if (!_mouse_focused) {
   9.903 +    			_MouseFocusEvent(true);
   9.904 +    		}
   9.905 +    		BMessage msg(BAPP_MOUSE_MOVED);
   9.906 +    		msg.AddInt32("x", (int)where.x);
   9.907 +    		msg.AddInt32("y", (int)where.y);
   9.908 + 		
   9.909 +    		_PostWindowEvent(msg);
   9.910 +    	}
   9.911 +    }
   9.912 +    
   9.913 +    void _MouseFocusEvent(bool focusGained) {
   9.914 +    	_mouse_focused = focusGained;
   9.915 +    	BMessage msg(BAPP_MOUSE_FOCUS);
   9.916 +    	msg.AddBool("focusGained", focusGained);
   9.917 +    	_PostWindowEvent(msg);
   9.918 +    	
   9.919 +//FIXME: Why were these here?
   9.920 +// if false: be_app->SetCursor(B_HAND_CURSOR);
   9.921 +// if true:  SDL_SetCursor(NULL);
   9.922 +    }
   9.923 +    
   9.924 +    void _MouseButtonEvent(int32 buttons) {
   9.925 +    	int32 buttonStateChange = buttons ^ _last_buttons;
   9.926 +    	
   9.927 +    	/* Make sure at least one button has changed state */ 
   9.928 +    	if( !(buttonStateChange) ) {
   9.929 +    		return;
   9.930 +    	}
   9.931 +    	
   9.932 +    	/* Add any mouse button events */
   9.933 +    	if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
   9.934 +    		_SendMouseButton(SDL_BUTTON_LEFT, buttons &
   9.935 +    			B_PRIMARY_MOUSE_BUTTON);
   9.936 +    	}
   9.937 +    	if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
   9.938 +    		_SendMouseButton(SDL_BUTTON_RIGHT, buttons &
   9.939 +    			B_PRIMARY_MOUSE_BUTTON);
   9.940 +    	}
   9.941 +    	if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
   9.942 +    		_SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
   9.943 +    			B_PRIMARY_MOUSE_BUTTON);
   9.944 +    	}
   9.945 +    	
   9.946 +    	_last_buttons = buttons;
   9.947 +    }
   9.948 +    
   9.949 +    void _SendMouseButton(int32 button, int32 state) {
   9.950 +    	BMessage msg(BAPP_MOUSE_BUTTON);
   9.951 +    	msg.AddInt32("button-id", button);
   9.952 +    	msg.AddInt32("button-state", state);
   9.953 +    	_PostWindowEvent(msg);
   9.954 +    }
   9.955 +    
   9.956 +    void _MouseWheelEvent(int32 x, int32 y) {
   9.957 +    	/* Create a message to pass along to the BeApp thread */
   9.958 +    	BMessage msg(BAPP_MOUSE_WHEEL);
   9.959 +    	msg.AddInt32("xticks", x);
   9.960 +    	msg.AddInt32("yticks", y);
   9.961 +    	_PostWindowEvent(msg);
   9.962 +    }
   9.963 +    
   9.964 +    void _KeyEvent(int32 keyCode, int32 keyState) {
   9.965 +    	/* Create a message to pass along to the BeApp thread */
   9.966 +    	BMessage msg(BAPP_KEY);
   9.967 +    	msg.AddInt32("key-state", keyState);
   9.968 +    	msg.AddInt32("key-scancode", keyCode);
   9.969 +    	be_app->PostMessage(&msg);
   9.970 +    	/* Apparently SDL only uses the scancode */
   9.971 +    }
   9.972 +    
   9.973 +    void _RepaintEvent() {
   9.974 +    	/* Force a repaint: Call the SDL exposed event */
   9.975 +    	BMessage msg(BAPP_REPAINT);
   9.976 +    	_PostWindowEvent(msg);
   9.977 +    }
   9.978 +    void _PostWindowEvent(BMessage &msg) {
   9.979 +    	msg.AddInt32("window-id", _id);
   9.980 +    	be_app->PostMessage(&msg);
   9.981 +    }
   9.982 +    
   9.983 +	/* Command methods (functions called upon by SDL) */
   9.984 +    void _SetTitle(BMessage *msg) {
   9.985 +    	const char *title;
   9.986 +    	if(
   9.987 +			msg->FindString("window-title", &title) != B_OK
   9.988 +		) {
   9.989 +			return;
   9.990 +		}
   9.991 +		SetTitle(title);
   9.992 +    }
   9.993 +    
   9.994 +    void _MoveTo(BMessage *msg) {
   9.995 +    	int32 x, y;
   9.996 +    	if(
   9.997 +			msg->FindInt32("window-x", &x) != B_OK ||
   9.998 +			msg->FindInt32("window-y", &y) != B_OK
   9.999 +		) {
  9.1000 +			return;
  9.1001 +		}
  9.1002 +		MoveTo(x, y);
  9.1003 +    }
  9.1004 +    
  9.1005 +    void _ResizeTo(BMessage *msg) {
  9.1006 +    	int32 w, h;
  9.1007 +    	if(
  9.1008 +			msg->FindInt32("window-w", &w) != B_OK ||
  9.1009 +			msg->FindInt32("window-h", &h) != B_OK
  9.1010 +		) {
  9.1011 +			return;
  9.1012 +		}
  9.1013 +    	ResizeTo(w, h);
  9.1014 +    }
  9.1015 +    
  9.1016 +    void _Restore() {
  9.1017 +    	if(IsMinimized()) {
  9.1018 +    		Minimize(false);
  9.1019 +    	} else if(IsHidden()) {
  9.1020 +    		Show();
  9.1021 +    	} else if(_prev_frame != NULL) {	/* Zoomed */
  9.1022 +    		MoveTo(_prev_frame->left, _prev_frame->top);
  9.1023 +    		ResizeTo(_prev_frame->Width(), _prev_frame->Height());
  9.1024 +    	}
  9.1025 +    }
  9.1026  
  9.1027 -  private:
  9.1028 +    void _SetFullScreen(BMessage *msg) {
  9.1029 +    	bool fullscreen;
  9.1030 +    	if(
  9.1031 +			msg->FindBool("fullscreen", &fullscreen) != B_OK
  9.1032 +		) {
  9.1033 +			return;
  9.1034 +    	}
  9.1035 +    	SetFullScreen(fullscreen);
  9.1036 +    }
  9.1037 +    
  9.1038 +    /* Members */
  9.1039  #if SDL_VIDEO_OPENGL
  9.1040 -    BGLView * SDL_GLView;
  9.1041 +    BGLView * _SDL_GLView;
  9.1042  #endif
  9.1043 -    SDL_BView *SDL_View;
  9.1044 -    BView *the_view;
  9.1045 -
  9.1046 -    bool shown;
  9.1047 -    bool inhibit_resize;
  9.1048 -
  9.1049 -    int32 last_buttons;
  9.1050 -    SDL_Keycode keymap[128];
  9.1051 +    
  9.1052 +    int32 _last_buttons;
  9.1053 +    int32 _id;	/* Window id used by SDL_BApp */
  9.1054 +    bool  _mouse_focused;		/* Does this window have mouse focus? */
  9.1055 +    bool  _shown;
  9.1056 +    bool  _inhibit_resize;
  9.1057 +    
  9.1058 +    BRect *_prev_frame;	/* Previous position and size of the window */
  9.1059 +    
  9.1060 +    /* Framebuffer members */
  9.1061 +    bool			_connected,
  9.1062 +    				_connection_disabled,
  9.1063 +    				_buffer_created,
  9.1064 +    				_buffer_dirty,
  9.1065 +    				_trash_window_buffer;
  9.1066 +    uint8		   *_bits;
  9.1067 +    uint32			_row_bytes;
  9.1068 +    clipping_rect	_bounds;
  9.1069 +    BLocker 	   *_buffer_locker;
  9.1070 +    clipping_rect  *_clips;
  9.1071 +    int32			_num_clips;
  9.1072 +    int32			_bytes_per_px;
  9.1073 +    thread_id		_draw_thread_id;
  9.1074 +    
  9.1075 +    BBitmap		   *_bitmap;
  9.1076  };
  9.1077  
  9.1078 -#endif /* _SDL_BWin_h */
  9.1079 -/* vi: set ts=4 sw=4 expandtab: */
  9.1080 +
  9.1081 +/* FIXME:
  9.1082 + * An explanation of framebuffer flags.
  9.1083 + *
  9.1084 + * _connected -           Original variable used to let the drawing thread know
  9.1085 + *                         when changes are being made to the other framebuffer
  9.1086 + *                         members.
  9.1087 + * _connection_disabled - Used to signal to the drawing thread that the window
  9.1088 + *                         is closing, and the thread should exit.
  9.1089 + * _buffer_created -      True if the current buffer is valid
  9.1090 + * _buffer_dirty -        True if the window should be redrawn.
  9.1091 + * _trash_window_buffer - True if the window buffer needs to be trashed partway
  9.1092 + *                         through a draw cycle.  Occurs when the previous
  9.1093 + *                         buffer provided by DirectConnected() is invalidated.
  9.1094 + */
  9.1095 +#endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/bwindow/SDL_bclipboard.cc	Thu Sep 15 23:51:07 2011 -0400
    10.3 @@ -0,0 +1,99 @@
    10.4 +/*
    10.5 +  Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    10.7 +
    10.8 +  This software is provided 'as-is', without any express or implied
    10.9 +  warranty.  In no event will the authors be held liable for any damages
   10.10 +  arising from the use of this software.
   10.11 +
   10.12 +  Permission is granted to anyone to use this software for any purpose,
   10.13 +  including commercial applications, and to alter it and redistribute it
   10.14 +  freely, subject to the following restrictions:
   10.15 +
   10.16 +  1. The origin of this software must not be misrepresented; you must not
   10.17 +     claim that you wrote the original software. If you use this software
   10.18 +     in a product, an acknowledgment in the product documentation would be
   10.19 +     appreciated but is not required.
   10.20 +  2. Altered source versions must be plainly marked as such, and must not be
   10.21 +     misrepresented as being the original software.
   10.22 +  3. This notice may not be removed or altered from any source distribution.
   10.23 +*/
   10.24 +
   10.25 +
   10.26 +/* BWindow based framebuffer implementation */
   10.27 +#include "SDL_config.h"
   10.28 +
   10.29 +#include <unistd.h>
   10.30 +#include <TypeConstants.h>
   10.31 +
   10.32 +#include "SDL_BWin.h"
   10.33 +#include "SDL_timer.h"
   10.34 +#include "../SDL_sysvideo.h"
   10.35 +
   10.36 +#ifdef __cplusplus
   10.37 +extern "C" {
   10.38 +#endif
   10.39 +
   10.40 +int BE_SetClipboardText(_THIS, const char *text) {
   10.41 +	BMessage *clip = NULL;
   10.42 +	if(be_clipboard->Lock()) {
   10.43 +		be_clipboard->Clear();
   10.44 +		if((clip = be_clipboard->Data())) {
   10.45 +			/* Presumably the string of characters is ascii-format */
   10.46 +			ssize_t asciiLength = 0;
   10.47 +			for(; text[asciiLength] != 0; ++asciiLength) {}
   10.48 +			clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength);
   10.49 +			be_clipboard->Commit();
   10.50 +		}
   10.51 +		be_clipboard->Unlock();
   10.52 +	}
   10.53 +}
   10.54 +
   10.55 +char *BE_GetClipboardText(_THIS) {
   10.56 +	BMessage *clip = NULL;
   10.57 +	const char *text;
   10.58 +	ssize_t length;
   10.59 +	if(be_clipboard->Lock()) {
   10.60 +		if((clip = be_clipboard->Data())) {
   10.61 +			/* Presumably the string of characters is ascii-format */
   10.62 +			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
   10.63 +				&length);
   10.64 +		} else {
   10.65 +			be_clipboard->Unlock();
   10.66 +			return NULL;
   10.67 +		}
   10.68 +		be_clipboard->Unlock();
   10.69 +	} else {
   10.70 +		return NULL;
   10.71 +	}
   10.72 +	
   10.73 +	/* Copy the data and pass on to SDL */
   10.74 +	char *result = (char*)SDL_calloc(1, sizeof(char*)*length);
   10.75 +	SDL_strlcpy(result, text, length);
   10.76 +	
   10.77 +	return result;
   10.78 +}
   10.79 +
   10.80 +SDL_bool BE_HasClipboardText(_THIS) {
   10.81 +	BMessage *clip = NULL;
   10.82 +	const char *text;
   10.83 +	ssize_t length;
   10.84 +	SDL_bool retval = SDL_FALSE;
   10.85 +	
   10.86 +	if(be_clipboard->Lock()) {
   10.87 +		if((clip = be_clipboard->Data())) {
   10.88 +			/* Presumably the string of characters is ascii-format */
   10.89 +			clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
   10.90 +				&length);
   10.91 +			if( text ) retval = SDL_TRUE;
   10.92 +		}
   10.93 +		be_clipboard->Unlock();
   10.94 +	}
   10.95 +	return retval;
   10.96 +
   10.97 +}
   10.98 +
   10.99 +#ifdef __cplusplus
  10.100 +}					/* Extern C */
  10.101 +#endif
  10.102 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/bwindow/SDL_bclipboard.h	Thu Sep 15 23:51:07 2011 -0400
    11.3 @@ -0,0 +1,31 @@
    11.4 +/*
    11.5 +  Simple DirectMedia Layer
    11.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    11.7 +
    11.8 +  This software is provided 'as-is', without any express or implied
    11.9 +  warranty.  In no event will the authors be held liable for any damages
   11.10 +  arising from the use of this software.
   11.11 +
   11.12 +  Permission is granted to anyone to use this software for any purpose,
   11.13 +  including commercial applications, and to alter it and redistribute it
   11.14 +  freely, subject to the following restrictions:
   11.15 +
   11.16 +  1. The origin of this software must not be misrepresented; you must not
   11.17 +     claim that you wrote the original software. If you use this software
   11.18 +     in a product, an acknowledgment in the product documentation would be
   11.19 +     appreciated but is not required.
   11.20 +  2. Altered source versions must be plainly marked as such, and must not be
   11.21 +     misrepresented as being the original software.
   11.22 +  3. This notice may not be removed or altered from any source distribution.
   11.23 +*/
   11.24 +
   11.25 +#include "SDL_config.h"
   11.26 +
   11.27 +#ifndef SDL_BCLIPBOARD_H
   11.28 +#define SDL_BCLIPBOARD_H
   11.29 +
   11.30 +extern int BE_SetClipboardText(_THIS, const char *text);
   11.31 +extern char *BE_GetClipboardText(_THIS);
   11.32 +extern SDL_bool BE_HasClipboardText(_THIS);
   11.33 +
   11.34 +#endif
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/bwindow/SDL_bevents.cc	Thu Sep 15 23:51:07 2011 -0400
    12.3 @@ -0,0 +1,34 @@
    12.4 +/*
    12.5 +  Simple DirectMedia Layer
    12.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    12.7 +
    12.8 +  This software is provided 'as-is', without any express or implied
    12.9 +  warranty.  In no event will the authors be held liable for any damages
   12.10 +  arising from the use of this software.
   12.11 +
   12.12 +  Permission is granted to anyone to use this software for any purpose,
   12.13 +  including commercial applications, and to alter it and redistribute it
   12.14 +  freely, subject to the following restrictions:
   12.15 +
   12.16 +  1. The origin of this software must not be misrepresented; you must not
   12.17 +     claim that you wrote the original software. If you use this software
   12.18 +     in a product, an acknowledgment in the product documentation would be
   12.19 +     appreciated but is not required.
   12.20 +  2. Altered source versions must be plainly marked as such, and must not be
   12.21 +     misrepresented as being the original software.
   12.22 +  3. This notice may not be removed or altered from any source distribution.
   12.23 +*/
   12.24 +
   12.25 +#include "SDL_bevents.h"
   12.26 +
   12.27 +#ifdef __cplusplus
   12.28 +extern "C" {
   12.29 +#endif
   12.30 +
   12.31 +void BE_PumpEvents(_THIS) {
   12.32 +	/* Since the event thread is its own thread, this isn't really necessary */
   12.33 +}
   12.34 +
   12.35 +#ifdef __cplusplus
   12.36 +}
   12.37 +#endif
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/bwindow/SDL_bevents.h	Thu Sep 15 23:51:07 2011 -0400
    13.3 @@ -0,0 +1,37 @@
    13.4 +/*
    13.5 +  Simple DirectMedia Layer
    13.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    13.7 +
    13.8 +  This software is provided 'as-is', without any express or implied
    13.9 +  warranty.  In no event will the authors be held liable for any damages
   13.10 +  arising from the use of this software.
   13.11 +
   13.12 +  Permission is granted to anyone to use this software for any purpose,
   13.13 +  including commercial applications, and to alter it and redistribute it
   13.14 +  freely, subject to the following restrictions:
   13.15 +
   13.16 +  1. The origin of this software must not be misrepresented; you must not
   13.17 +     claim that you wrote the original software. If you use this software
   13.18 +     in a product, an acknowledgment in the product documentation would be
   13.19 +     appreciated but is not required.
   13.20 +  2. Altered source versions must be plainly marked as such, and must not be
   13.21 +     misrepresented as being the original software.
   13.22 +  3. This notice may not be removed or altered from any source distribution.
   13.23 +*/	
   13.24 +
   13.25 +#ifndef SDL_BEVENTS_H
   13.26 +#define SDL_BEVENTS_H
   13.27 +
   13.28 +#include "../SDL_sysvideo.h"
   13.29 +
   13.30 +#ifdef __cplusplus
   13.31 +extern "C" {
   13.32 +#endif
   13.33 +
   13.34 +extern void BE_PumpEvents(_THIS);
   13.35 +
   13.36 +#ifdef __cplusplus
   13.37 +}
   13.38 +#endif
   13.39 +
   13.40 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/video/bwindow/SDL_bframebuffer.cc	Thu Sep 15 23:51:07 2011 -0400
    14.3 @@ -0,0 +1,251 @@
    14.4 +/*
    14.5 +  Simple DirectMedia Layer
    14.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    14.7 +
    14.8 +  This software is provided 'as-is', without any express or implied
    14.9 +  warranty.  In no event will the authors be held liable for any damages
   14.10 +  arising from the use of this software.
   14.11 +
   14.12 +  Permission is granted to anyone to use this software for any purpose,
   14.13 +  including commercial applications, and to alter it and redistribute it
   14.14 +  freely, subject to the following restrictions:
   14.15 +
   14.16 +  1. The origin of this software must not be misrepresented; you must not
   14.17 +     claim that you wrote the original software. If you use this software
   14.18 +     in a product, an acknowledgment in the product documentation would be
   14.19 +     appreciated but is not required.
   14.20 +  2. Altered source versions must be plainly marked as such, and must not be
   14.21 +     misrepresented as being the original software.
   14.22 +  3. This notice may not be removed or altered from any source distribution.
   14.23 +*/
   14.24 +
   14.25 +#include "SDL_bframebuffer.h"
   14.26 +
   14.27 +#include <AppKit.h>
   14.28 +#include <InterfaceKit.h>
   14.29 +#include "SDL_bmodes.h"
   14.30 +#include "SDL_BWin.h"
   14.31 +
   14.32 +#include "../../main/beos/SDL_BApp.h"
   14.33 +
   14.34 +#ifdef __cplusplus
   14.35 +extern "C" {
   14.36 +#endif
   14.37 +
   14.38 +int32 BE_UpdateOnce(SDL_Window *window);
   14.39 +
   14.40 +static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
   14.41 +	return ((SDL_BWin*)(window->driverdata));
   14.42 +}
   14.43 +
   14.44 +static inline SDL_BApp *_GetBeApp() {
   14.45 +	return ((SDL_BApp*)be_app);
   14.46 +}
   14.47 +
   14.48 +int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   14.49 +                                       Uint32 * format,
   14.50 +                                       void ** pixels, int *pitch) {
   14.51 +	SDL_BWin *bwin = _ToBeWin(window);
   14.52 +	BScreen bscreen;
   14.53 +	if(!bscreen.IsValid()) {
   14.54 +		return -1;
   14.55 +	}
   14.56 +
   14.57 +	while(!bwin->Connected()) { snooze(100); }
   14.58 +	
   14.59 +	/* Make sure we have exclusive access to frame buffer data */
   14.60 +	bwin->LockBuffer();
   14.61 +
   14.62 +	/* format */
   14.63 +	display_mode bmode;
   14.64 +	bscreen.GetMode(&bmode);
   14.65 +	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode.space);
   14.66 +	*format = BE_BPPToSDLPxFormat(bpp);
   14.67 +
   14.68 +	/* Create the new bitmap object */
   14.69 +	BBitmap *bitmap = bwin->GetBitmap();
   14.70 +
   14.71 +	if(bitmap) {
   14.72 +		delete bitmap;
   14.73 +	}
   14.74 +	bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
   14.75 +			false,	/* Views not accepted */
   14.76 +			true);	/* Contiguous memory required */
   14.77 +			
   14.78 +	if(bitmap->InitCheck() != B_OK) {
   14.79 +		SDL_SetError("Could not initialize back buffer!\n");
   14.80 +		return -1;
   14.81 +	}
   14.82 +
   14.83 +
   14.84 +	bwin->SetBitmap(bitmap);
   14.85 +	
   14.86 +	/* Set the pixel pointer */
   14.87 +	*pixels = bitmap->Bits();
   14.88 +
   14.89 +	/* pitch = width of window, in bytes */
   14.90 +	*pitch = bitmap->BytesPerRow();
   14.91 +
   14.92 +	bwin->SetBufferExists(true);
   14.93 +	bwin->SetTrashBuffer(false);
   14.94 +	bwin->UnlockBuffer();
   14.95 +	return 0;
   14.96 +}
   14.97 +
   14.98 +
   14.99 +
  14.100 +int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
  14.101 +                                      SDL_Rect * rects, int numrects) {
  14.102 +	if(!window)
  14.103 +		return 0;
  14.104 +
  14.105 +	SDL_BWin *bwin = _ToBeWin(window);
  14.106 +
  14.107 +#ifdef DRAWTHREAD	
  14.108 +	bwin->LockBuffer();
  14.109 +	bwin->SetBufferDirty(true);
  14.110 +	bwin->UnlockBuffer();
  14.111 +#else
  14.112 +	bwin->SetBufferDirty(true);
  14.113 +	BE_UpdateOnce(window);
  14.114 +#endif
  14.115 +
  14.116 +	return 0;
  14.117 +}
  14.118 +
  14.119 +int32 BE_DrawThread(void *data) {
  14.120 +	SDL_BWin *bwin = (SDL_BWin*)data;
  14.121 +	SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID());
  14.122 +	
  14.123 +	BScreen bscreen;
  14.124 +	if(!bscreen.IsValid()) {
  14.125 +		return -1;
  14.126 +	}
  14.127 +
  14.128 +	while(bwin->ConnectionEnabled()) {
  14.129 +		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
  14.130 +			bwin->LockBuffer();
  14.131 +			BBitmap *bitmap = NULL;
  14.132 +			bitmap = bwin->GetBitmap();
  14.133 +			int32 windowPitch = bitmap->BytesPerRow();
  14.134 +			int32 bufferPitch = bwin->GetRowBytes();
  14.135 +			uint8 *windowpx;
  14.136 +			uint8 *bufferpx;
  14.137 +
  14.138 +			int32 BPP = bwin->GetBytesPerPx();
  14.139 +			int32 windowSub = bwin->GetFbX() * BPP +
  14.140 +						  bwin->GetFbY() * windowPitch;
  14.141 +			clipping_rect *clips = bwin->GetClips();
  14.142 +			int32 numClips = bwin->GetNumClips();
  14.143 +			int i, y;
  14.144 +
  14.145 +			/* Blit each clipping rectangle */
  14.146 +			bscreen.WaitForRetrace();
  14.147 +			for(i = 0; i < numClips; ++i) {
  14.148 +				clipping_rect rc = clips[i];
  14.149 +				/* Get addresses of the start of each clipping rectangle */
  14.150 +				int32 width = clips[i].right - clips[i].left + 1;
  14.151 +				int32 height = clips[i].bottom - clips[i].top + 1;
  14.152 +				bufferpx = bwin->GetBufferPx() + 
  14.153 +					clips[i].top * bufferPitch + clips[i].left * BPP;
  14.154 +				windowpx = (uint8*)bitmap->Bits() + 
  14.155 +					clips[i].top * windowPitch + clips[i].left * BPP -
  14.156 +					windowSub;
  14.157 +
  14.158 +				/* Copy each row of pixels from the window buffer into the frame
  14.159 +				   buffer */
  14.160 +				for(y = 0; y < height; ++y)
  14.161 +				{
  14.162 +
  14.163 +					if(bwin->CanTrashWindowBuffer()) {
  14.164 +						goto escape;	/* Break out before the buffer is killed */
  14.165 +					}
  14.166 +
  14.167 +					memcpy(bufferpx, windowpx, width * BPP);
  14.168 +					bufferpx += bufferPitch;
  14.169 +					windowpx += windowPitch;
  14.170 +				}
  14.171 +			}
  14.172 +
  14.173 +			bwin->SetBufferDirty(false);
  14.174 +escape:
  14.175 +			bwin->UnlockBuffer();
  14.176 +		} else {
  14.177 +			snooze(16000);
  14.178 +		}
  14.179 +	}
  14.180 +	
  14.181 +	return B_OK;
  14.182 +}
  14.183 +
  14.184 +void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
  14.185 +	SDL_BWin *bwin = _ToBeWin(window);
  14.186 +	
  14.187 +	bwin->LockBuffer();
  14.188 +	
  14.189 +	/* Free and clear the window buffer */
  14.190 +	BBitmap *bitmap = bwin->GetBitmap();
  14.191 +	delete bitmap;
  14.192 +	bwin->SetBitmap(NULL);
  14.193 +	bwin->SetBufferExists(false);
  14.194 +	bwin->UnlockBuffer();
  14.195 +}
  14.196 +
  14.197 +
  14.198 +/*
  14.199 + * TODO:
  14.200 + * This was written to test if certain errors were caused by threading issues.
  14.201 + * The specific issues have since become rare enough that they may have been
  14.202 + * solved, but I doubt it- they were pretty sporadic before now.
  14.203 + */
  14.204 +int32 BE_UpdateOnce(SDL_Window *window) {
  14.205 +	SDL_BWin *bwin = _ToBeWin(window);
  14.206 +	BScreen bscreen;
  14.207 +	if(!bscreen.IsValid()) {
  14.208 +		return -1;
  14.209 +	}
  14.210 +
  14.211 +	if(bwin->ConnectionEnabled() && bwin->Connected()) {
  14.212 +		bwin->LockBuffer();
  14.213 +		int32 windowPitch = window->surface->pitch;
  14.214 +		int32 bufferPitch = bwin->GetRowBytes();
  14.215 +		uint8 *windowpx;
  14.216 +		uint8 *bufferpx;
  14.217 +
  14.218 +		int32 BPP = bwin->GetBytesPerPx();
  14.219 +		uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
  14.220 +		int32 windowSub = bwin->GetFbX() * BPP +
  14.221 +						  bwin->GetFbY() * windowPitch;
  14.222 +		clipping_rect *clips = bwin->GetClips();
  14.223 +		int32 numClips = bwin->GetNumClips();
  14.224 +		int i, y;
  14.225 +
  14.226 +		/* Blit each clipping rectangle */
  14.227 +		bscreen.WaitForRetrace();
  14.228 +		for(i = 0; i < numClips; ++i) {
  14.229 +			clipping_rect rc = clips[i];
  14.230 +			/* Get addresses of the start of each clipping rectangle */
  14.231 +			int32 width = clips[i].right - clips[i].left + 1;
  14.232 +			int32 height = clips[i].bottom - clips[i].top + 1;
  14.233 +			bufferpx = bwin->GetBufferPx() + 
  14.234 +				clips[i].top * bufferPitch + clips[i].left * BPP;
  14.235 +			windowpx = windowBaseAddress + 
  14.236 +				clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
  14.237 +
  14.238 +			/* Copy each row of pixels from the window buffer into the frame
  14.239 +			   buffer */
  14.240 +			for(y = 0; y < height; ++y)
  14.241 +			{
  14.242 +				memcpy(bufferpx, windowpx, width * BPP);
  14.243 +				bufferpx += bufferPitch;
  14.244 +				windowpx += windowPitch;
  14.245 +			}
  14.246 +		}
  14.247 +		bwin->UnlockBuffer();
  14.248 +	}
  14.249 +	return 0;
  14.250 +}
  14.251 +
  14.252 +#ifdef __cplusplus
  14.253 +}
  14.254 +#endif
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/video/bwindow/SDL_bframebuffer.h	Thu Sep 15 23:51:07 2011 -0400
    15.3 @@ -0,0 +1,45 @@
    15.4 +/*
    15.5 +  Simple DirectMedia Layer
    15.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    15.7 +
    15.8 +  This software is provided 'as-is', without any express or implied
    15.9 +  warranty.  In no event will the authors be held liable for any damages
   15.10 +  arising from the use of this software.
   15.11 +
   15.12 +  Permission is granted to anyone to use this software for any purpose,
   15.13 +  including commercial applications, and to alter it and redistribute it
   15.14 +  freely, subject to the following restrictions:
   15.15 +
   15.16 +  1. The origin of this software must not be misrepresented; you must not
   15.17 +     claim that you wrote the original software. If you use this software
   15.18 +     in a product, an acknowledgment in the product documentation would be
   15.19 +     appreciated but is not required.
   15.20 +  2. Altered source versions must be plainly marked as such, and must not be
   15.21 +     misrepresented as being the original software.
   15.22 +  3. This notice may not be removed or altered from any source distribution.
   15.23 +*/
   15.24 +
   15.25 +#ifndef SDL_BFRAMEBUFFER_H
   15.26 +#define SDL_BFRAMEBUFFER_H
   15.27 +#include <SupportDefs.h>
   15.28 +#ifdef __cplusplus
   15.29 +extern "C" {
   15.30 +#endif
   15.31 +
   15.32 +#define DRAWTHREAD
   15.33 +
   15.34 +#include "../SDL_sysvideo.h"
   15.35 +
   15.36 +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   15.37 +                                       Uint32 * format,
   15.38 +                                       void ** pixels, int *pitch);
   15.39 +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   15.40 +                                       SDL_Rect * rects, int numrects);
   15.41 +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   15.42 +extern int32 BE_DrawThread(void *data);
   15.43 +
   15.44 +#ifdef __cplusplus
   15.45 +}
   15.46 +#endif
   15.47 +
   15.48 +#endif
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/bwindow/SDL_bkeyboard.cc	Thu Sep 15 23:51:07 2011 -0400
    16.3 @@ -0,0 +1,184 @@
    16.4 +/*
    16.5 +    SDL - Simple DirectMedia Layer
    16.6 +    Copyright (C) 1997-2009 Sam Lantinga
    16.7 +
    16.8 +    This library is free software; you can redistribute it and/or
    16.9 +    modify it under the terms of the GNU Lesser General Public
   16.10 +    License as published by the Free Software Foundation; either
   16.11 +    version 2.1 of the License, or (at your option) any later version.
   16.12 +
   16.13 +    This library is distributed in the hope that it will be useful,
   16.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 +    Lesser General Public License for more details.
   16.17 +
   16.18 +    You should have received a copy of the GNU Lesser General Public
   16.19 +    License along with this library; if not, write to the Free Software
   16.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16.21 +
   16.22 +    Sam Lantinga
   16.23 +    slouken@libsdl.org
   16.24 +*/
   16.25 +
   16.26 +#include <SupportDefs.h>
   16.27 +#include <support/UTF8.h>
   16.28 +
   16.29 +#ifdef __cplusplus
   16.30 +extern "C" {
   16.31 +#endif
   16.32 +
   16.33 +#include "SDL_events.h"
   16.34 +#include "SDL_keycode.h"
   16.35 +
   16.36 +#include "SDL_bkeyboard.h"
   16.37 +
   16.38 +
   16.39 +#define KEYMAP_SIZE 128
   16.40 +
   16.41 +
   16.42 +static SDL_Scancode keymap[KEYMAP_SIZE];
   16.43 +static int8 keystate[KEYMAP_SIZE];
   16.44 +
   16.45 +void BE_InitOSKeymap() {
   16.46 +		for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
   16.47 +			keymap[i] = SDL_SCANCODE_UNKNOWN;
   16.48 +		}
   16.49 +
   16.50 +		for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
   16.51 +			keystate[i] = SDL_RELEASED;
   16.52 +		}
   16.53 +
   16.54 +		keymap[0x01]		= SDL_GetScancodeFromKey(SDLK_ESCAPE);
   16.55 +		keymap[B_F1_KEY]	= SDL_GetScancodeFromKey(SDLK_F1);
   16.56 +		keymap[B_F2_KEY]	= SDL_GetScancodeFromKey(SDLK_F2);
   16.57 +		keymap[B_F3_KEY]	= SDL_GetScancodeFromKey(SDLK_F3);
   16.58 +		keymap[B_F4_KEY]	= SDL_GetScancodeFromKey(SDLK_F4);
   16.59 +		keymap[B_F5_KEY]	= SDL_GetScancodeFromKey(SDLK_F5);
   16.60 +		keymap[B_F6_KEY]	= SDL_GetScancodeFromKey(SDLK_F6);
   16.61 +		keymap[B_F7_KEY]	= SDL_GetScancodeFromKey(SDLK_F7);
   16.62 +		keymap[B_F8_KEY]	= SDL_GetScancodeFromKey(SDLK_F8);
   16.63 +		keymap[B_F9_KEY]	= SDL_GetScancodeFromKey(SDLK_F9);
   16.64 +		keymap[B_F10_KEY]	= SDL_GetScancodeFromKey(SDLK_F10);
   16.65 +		keymap[B_F11_KEY]	= SDL_GetScancodeFromKey(SDLK_F11);
   16.66 +		keymap[B_F12_KEY]	= SDL_GetScancodeFromKey(SDLK_F12);
   16.67 +		keymap[B_PRINT_KEY]	= SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
   16.68 +		keymap[B_SCROLL_KEY]	= SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
   16.69 +		keymap[B_PAUSE_KEY]	= SDL_GetScancodeFromKey(SDLK_PAUSE);
   16.70 +		keymap[0x11]		= SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
   16.71 +		keymap[0x12]		= SDL_GetScancodeFromKey(SDLK_1);
   16.72 +		keymap[0x13]		= SDL_GetScancodeFromKey(SDLK_2);
   16.73 +		keymap[0x14]		= SDL_GetScancodeFromKey(SDLK_3);
   16.74 +		keymap[0x15]		= SDL_GetScancodeFromKey(SDLK_4);
   16.75 +		keymap[0x16]		= SDL_GetScancodeFromKey(SDLK_5);
   16.76 +		keymap[0x17]		= SDL_GetScancodeFromKey(SDLK_6);
   16.77 +		keymap[0x18]		= SDL_GetScancodeFromKey(SDLK_7);
   16.78 +		keymap[0x19]		= SDL_GetScancodeFromKey(SDLK_8);
   16.79 +		keymap[0x1a]		= SDL_GetScancodeFromKey(SDLK_9);
   16.80 +		keymap[0x1b]		= SDL_GetScancodeFromKey(SDLK_0);
   16.81 +		keymap[0x1c]		= SDL_GetScancodeFromKey(SDLK_MINUS);
   16.82 +		keymap[0x1d]		= SDL_GetScancodeFromKey(SDLK_EQUALS);
   16.83 +		keymap[0x1e]		= SDL_GetScancodeFromKey(SDLK_BACKSPACE);
   16.84 +		keymap[0x1f]		= SDL_GetScancodeFromKey(SDLK_INSERT);
   16.85 +		keymap[0x20]		= SDL_GetScancodeFromKey(SDLK_HOME);
   16.86 +		keymap[0x21]		= SDL_GetScancodeFromKey(SDLK_PAGEUP);
   16.87 +		keymap[0x22]		= SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
   16.88 +		keymap[0x23]		= SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
   16.89 +		keymap[0x24]		= SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
   16.90 +		keymap[0x25]		= SDL_GetScancodeFromKey(SDLK_KP_MINUS);
   16.91 +		keymap[0x26]		= SDL_GetScancodeFromKey(SDLK_TAB);
   16.92 +		keymap[0x27]		= SDL_GetScancodeFromKey(SDLK_q);
   16.93 +		keymap[0x28]		= SDL_GetScancodeFromKey(SDLK_w);
   16.94 +		keymap[0x29]		= SDL_GetScancodeFromKey(SDLK_e);
   16.95 +		keymap[0x2a]		= SDL_GetScancodeFromKey(SDLK_r);
   16.96 +		keymap[0x2b]		= SDL_GetScancodeFromKey(SDLK_t);
   16.97 +		keymap[0x2c]		= SDL_GetScancodeFromKey(SDLK_y);
   16.98 +		keymap[0x2d]		= SDL_GetScancodeFromKey(SDLK_u);
   16.99 +		keymap[0x2e]		= SDL_GetScancodeFromKey(SDLK_i);
  16.100 +		keymap[0x2f]		= SDL_GetScancodeFromKey(SDLK_o);
  16.101 +		keymap[0x30]		= SDL_GetScancodeFromKey(SDLK_p);
  16.102 +		keymap[0x31]		= SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
  16.103 +		keymap[0x32]		= SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
  16.104 +		keymap[0x33]		= SDL_GetScancodeFromKey(SDLK_BACKSLASH);
  16.105 +		keymap[0x34]		= SDL_GetScancodeFromKey(SDLK_DELETE);
  16.106 +		keymap[0x35]		= SDL_GetScancodeFromKey(SDLK_END);
  16.107 +		keymap[0x36]		= SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
  16.108 +		keymap[0x37]		= SDL_GetScancodeFromKey(SDLK_KP_7);
  16.109 +		keymap[0x38]		= SDL_GetScancodeFromKey(SDLK_KP_8);
  16.110 +		keymap[0x39]		= SDL_GetScancodeFromKey(SDLK_KP_9);
  16.111 +		keymap[0x3a]		= SDL_GetScancodeFromKey(SDLK_KP_PLUS);
  16.112 +		keymap[0x3b]		= SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
  16.113 +		keymap[0x3c]		= SDL_GetScancodeFromKey(SDLK_a);
  16.114 +		keymap[0x3d]		= SDL_GetScancodeFromKey(SDLK_s);
  16.115 +		keymap[0x3e]		= SDL_GetScancodeFromKey(SDLK_d);
  16.116 +		keymap[0x3f]		= SDL_GetScancodeFromKey(SDLK_f);
  16.117 +		keymap[0x40]		= SDL_GetScancodeFromKey(SDLK_g);
  16.118 +		keymap[0x41]		= SDL_GetScancodeFromKey(SDLK_h);
  16.119 +		keymap[0x42]		= SDL_GetScancodeFromKey(SDLK_j);
  16.120 +		keymap[0x43]		= SDL_GetScancodeFromKey(SDLK_k);
  16.121 +		keymap[0x44]		= SDL_GetScancodeFromKey(SDLK_l);
  16.122 +		keymap[0x45]		= SDL_GetScancodeFromKey(SDLK_SEMICOLON);
  16.123 +		keymap[0x46]		= SDL_GetScancodeFromKey(SDLK_QUOTE);
  16.124 +		keymap[0x47]		= SDL_GetScancodeFromKey(SDLK_RETURN);
  16.125 +		keymap[0x48]		= SDL_GetScancodeFromKey(SDLK_KP_4);
  16.126 +		keymap[0x49]		= SDL_GetScancodeFromKey(SDLK_KP_5);
  16.127 +		keymap[0x4a]		= SDL_GetScancodeFromKey(SDLK_KP_6);
  16.128 +		keymap[0x4b]		= SDL_GetScancodeFromKey(SDLK_LSHIFT);
  16.129 +		keymap[0x4c]		= SDL_GetScancodeFromKey(SDLK_z);
  16.130 +		keymap[0x4d]		= SDL_GetScancodeFromKey(SDLK_x);
  16.131 +		keymap[0x4e]		= SDL_GetScancodeFromKey(SDLK_c);
  16.132 +		keymap[0x4f]		= SDL_GetScancodeFromKey(SDLK_v);
  16.133 +		keymap[0x50]		= SDL_GetScancodeFromKey(SDLK_b);
  16.134 +		keymap[0x51]		= SDL_GetScancodeFromKey(SDLK_n);
  16.135 +		keymap[0x52]		= SDL_GetScancodeFromKey(SDLK_m);
  16.136 +		keymap[0x53]		= SDL_GetScancodeFromKey(SDLK_COMMA);
  16.137 +		keymap[0x54]		= SDL_GetScancodeFromKey(SDLK_PERIOD);
  16.138 +		keymap[0x55]		= SDL_GetScancodeFromKey(SDLK_SLASH);
  16.139 +		keymap[0x56]		= SDL_GetScancodeFromKey(SDLK_RSHIFT);
  16.140 +		keymap[0x57]		= SDL_GetScancodeFromKey(SDLK_UP);
  16.141 +		keymap[0x58]		= SDL_GetScancodeFromKey(SDLK_KP_1);
  16.142 +		keymap[0x59]		= SDL_GetScancodeFromKey(SDLK_KP_2);
  16.143 +		keymap[0x5a]		= SDL_GetScancodeFromKey(SDLK_KP_3);
  16.144 +		keymap[0x5b]		= SDL_GetScancodeFromKey(SDLK_KP_ENTER);
  16.145 +		keymap[0x5c]		= SDL_GetScancodeFromKey(SDLK_LCTRL);
  16.146 +		keymap[0x5d]		= SDL_GetScancodeFromKey(SDLK_LALT);
  16.147 +		keymap[0x5e]		= SDL_GetScancodeFromKey(SDLK_SPACE);
  16.148 +		keymap[0x5f]		= SDL_GetScancodeFromKey(SDLK_RALT);
  16.149 +		keymap[0x60]		= SDL_GetScancodeFromKey(SDLK_RCTRL);
  16.150 +		keymap[0x61]		= SDL_GetScancodeFromKey(SDLK_LEFT);
  16.151 +		keymap[0x62]		= SDL_GetScancodeFromKey(SDLK_DOWN);
  16.152 +		keymap[0x63]		= SDL_GetScancodeFromKey(SDLK_RIGHT);
  16.153 +		keymap[0x64]		= SDL_GetScancodeFromKey(SDLK_KP_0);
  16.154 +		keymap[0x65]		= SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
  16.155 +		keymap[0x66]		= SDL_GetScancodeFromKey(SDLK_LGUI);
  16.156 +		keymap[0x67]		= SDL_GetScancodeFromKey(SDLK_RGUI);
  16.157 +		keymap[0x68]		= SDL_GetScancodeFromKey(SDLK_MENU);
  16.158 +		keymap[0x69]		= SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
  16.159 +		keymap[0x6a]		= SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
  16.160 +		keymap[0x6b]		= SDL_GetScancodeFromKey(SDLK_POWER);
  16.161 +}
  16.162 +
  16.163 +SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
  16.164 +	if(bkey > 0 && bkey < SDL_TABLESIZE(keymap)) {
  16.165 +		return keymap[bkey];
  16.166 +	} else {
  16.167 +		return SDL_SCANCODE_UNKNOWN;
  16.168 +	}
  16.169 +}
  16.170 +
  16.171 +int8 BE_GetKeyState(int32 bkey) {
  16.172 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  16.173 +		return keystate[bkey];
  16.174 +	} else {
  16.175 +		return SDL_RELEASED;
  16.176 +	}
  16.177 +}
  16.178 +
  16.179 +void BE_SetKeyState(int32 bkey, int8 state) {
  16.180 +	if(bkey > 0 && bkey < KEYMAP_SIZE) {
  16.181 +		keystate[bkey] = state;
  16.182 +	}
  16.183 +}
  16.184 +
  16.185 +#ifdef __cplusplus
  16.186 +}
  16.187 +#endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/bwindow/SDL_bkeyboard.h	Thu Sep 15 23:51:07 2011 -0400
    17.3 @@ -0,0 +1,43 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997-2009 Sam Lantinga
    17.7 +
    17.8 +    This library is free software; you can redistribute it and/or
    17.9 +    modify it under the terms of the GNU Lesser General Public
   17.10 +    License as published by the Free Software Foundation; either
   17.11 +    version 2.1 of the License, or (at your option) any later version.
   17.12 +
   17.13 +    This library is distributed in the hope that it will be useful,
   17.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 +    Lesser General Public License for more details.
   17.17 +
   17.18 +    You should have received a copy of the GNU Lesser General Public
   17.19 +    License along with this library; if not, write to the Free Software
   17.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17.21 +
   17.22 +    Sam Lantinga
   17.23 +    slouken@libsdl.org
   17.24 +*/
   17.25 +
   17.26 +#ifndef SDL_BKEYBOARD_H
   17.27 +#define SDL_BKEYBOARD_H
   17.28 +
   17.29 +#include <SupportDefs.h>
   17.30 +
   17.31 +#ifdef __cplusplus
   17.32 +extern "C" {
   17.33 +#endif
   17.34 +
   17.35 +#include "../../../include/SDL_keyboard.h"
   17.36 +
   17.37 +extern void BE_InitOSKeymap();
   17.38 +extern SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey);
   17.39 +extern int8 BE_GetKeyState(int32 bkey);
   17.40 +extern void BE_SetKeyState(int32 bkey, int8 state);
   17.41 +
   17.42 +#ifdef __cplusplus
   17.43 +}
   17.44 +#endif
   17.45 +
   17.46 +#endif
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/bwindow/SDL_bmodes.cc	Thu Sep 15 23:51:07 2011 -0400
    18.3 @@ -0,0 +1,324 @@
    18.4 +/*
    18.5 +  Simple DirectMedia Layer
    18.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    18.7 +
    18.8 +  This software is provided 'as-is', without any express or implied
    18.9 +  warranty.  In no event will the authors be held liable for any damages
   18.10 +  arising from the use of this software.
   18.11 +
   18.12 +  Permission is granted to anyone to use this software for any purpose,
   18.13 +  including commercial applications, and to alter it and redistribute it
   18.14 +  freely, subject to the following restrictions:
   18.15 +
   18.16 +  1. The origin of this software must not be misrepresented; you must not
   18.17 +     claim that you wrote the original software. If you use this software
   18.18 +     in a product, an acknowledgment in the product documentation would be
   18.19 +     appreciated but is not required.
   18.20 +  2. Altered source versions must be plainly marked as such, and must not be
   18.21 +     misrepresented as being the original software.
   18.22 +  3. This notice may not be removed or altered from any source distribution.
   18.23 +*/
   18.24 +
   18.25 +
   18.26 +
   18.27 +#include <AppKit.h>
   18.28 +#include <InterfaceKit.h>
   18.29 +#include "SDL_bmodes.h"
   18.30 +#include "SDL_BWin.h"
   18.31 +
   18.32 +#if SDL_VIDEO_OPENGL
   18.33 +#include "SDL_bopengl.h"
   18.34 +#endif
   18.35 +
   18.36 +#include "../../main/beos/SDL_BApp.h"
   18.37 +
   18.38 +#ifdef __cplusplus
   18.39 +extern "C" {
   18.40 +#endif
   18.41 +
   18.42 +
   18.43 +#define WRAP_BMODE 1 /* FIXME: Some debate as to whether this is necessary */
   18.44 +
   18.45 +#if WRAP_BMODE
   18.46 +/* This wrapper is here so that the driverdata can be freed without freeing
   18.47 +   the display_mode structure */
   18.48 +typedef struct SDL_DisplayModeData {
   18.49 +	display_mode *bmode;
   18.50 +};
   18.51 +#endif
   18.52 +
   18.53 +static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
   18.54 +	return ((SDL_BWin*)(window->driverdata));
   18.55 +}
   18.56 +
   18.57 +static inline SDL_BApp *_GetBeApp() {
   18.58 +	return ((SDL_BApp*)be_app);
   18.59 +}
   18.60 +
   18.61 +static inline display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
   18.62 +#if WRAP_BMODE
   18.63 +	return ((SDL_DisplayModeData*)mode->driverdata)->bmode;
   18.64 +#else
   18.65 +	return (display_mode*)(mode->driverdata);
   18.66 +#endif
   18.67 +}
   18.68 +
   18.69 +/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */
   18.70 +static float get_refresh_rate(display_mode &mode) {
   18.71 +	return float(mode.timing.pixel_clock * 1000)
   18.72 +		/ float(mode.timing.h_total * mode.timing.v_total);
   18.73 +}
   18.74 +
   18.75 +
   18.76 +#if 0
   18.77 +/* TODO:
   18.78 + * This is a useful debugging tool.  Uncomment and insert into code as needed.
   18.79 + */
   18.80 +void _SpoutModeData(display_mode *bmode) {
   18.81 +	printf("BMode:\n");
   18.82 +	printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
   18.83 +	printf("\th,v = (%i,%i)\n", bmode->h_display_start, 
   18.84 +			bmode->v_display_start);
   18.85 +	if(bmode->flags) {
   18.86 +		printf("\tFlags:\n");
   18.87 +		if(bmode->flags & B_SCROLL) {
   18.88 +			printf("\t\tB_SCROLL\n");
   18.89 +		}
   18.90 +		if(bmode->flags & B_8_BIT_DAC) {
   18.91 +			printf("\t\tB_8_BIT_DAC\n");
   18.92 +		}
   18.93 +		if(bmode->flags & B_HARDWARE_CURSOR) {
   18.94 +			printf("\t\tB_HARDWARE_CURSOR\n");
   18.95 +		}
   18.96 +		if(bmode->flags & B_PARALLEL_ACCESS) {
   18.97 +			printf("\t\tB_PARALLEL_ACCESS\n");
   18.98 +		}
   18.99 +		if(bmode->flags & B_DPMS) {
  18.100 +			printf("\t\tB_DPMS\n");
  18.101 +		}
  18.102 +		if(bmode->flags & B_IO_FB_NA) {
  18.103 +			printf("\t\tB_IO_FB_NA\n");
  18.104 +		}
  18.105 +	}
  18.106 +	printf("\tTiming:\n");
  18.107 +	printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock);
  18.108 +	printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n",
  18.109 +		bmode->timing.h_display, bmode->timing.h_sync_start,
  18.110 +		bmode->timing.h_sync_end, bmode->timing.h_total);
  18.111 +	printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n",
  18.112 +		bmode->timing.v_display, bmode->timing.v_sync_start,
  18.113 +		bmode->timing.v_sync_end, bmode->timing.v_total);
  18.114 +	if(bmode->timing.flags) {
  18.115 +		printf("\t\tFlags:\n");
  18.116 +		if(bmode->timing.flags & B_BLANK_PEDESTAL) {
  18.117 +			printf("\t\t\tB_BLANK_PEDESTAL\n");
  18.118 +		}
  18.119 +		if(bmode->timing.flags & B_TIMING_INTERLACED) {
  18.120 +			printf("\t\t\tB_TIMING_INTERLACED\n");
  18.121 +		}
  18.122 +		if(bmode->timing.flags & B_POSITIVE_HSYNC) {
  18.123 +			printf("\t\t\tB_POSITIVE_HSYNC\n");
  18.124 +		}
  18.125 +		if(bmode->timing.flags & B_POSITIVE_VSYNC) {
  18.126 +			printf("\t\t\tB_POSITIVE_VSYNC\n");
  18.127 +		}
  18.128 +		if(bmode->timing.flags & B_SYNC_ON_GREEN) {
  18.129 +			printf("\t\t\tB_SYNC_ON_GREEN\n");
  18.130 +		}
  18.131 +	}
  18.132 +}
  18.133 +#endif
  18.134 +
  18.135 +
  18.136 +
  18.137 +int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace)
  18.138 +{
  18.139 +	int bitsperpixel;
  18.140 +
  18.141 +	bitsperpixel = 0;
  18.142 +	switch (colorspace) {
  18.143 +	    case B_CMAP8:
  18.144 +		bitsperpixel = 8;
  18.145 +		break;
  18.146 +	    case B_RGB15:
  18.147 +	    case B_RGBA15:
  18.148 +	    case B_RGB15_BIG:
  18.149 +	    case B_RGBA15_BIG:
  18.150 +		bitsperpixel = 15;
  18.151 +		break;
  18.152 +	    case B_RGB16:
  18.153 +	    case B_RGB16_BIG:
  18.154 +		bitsperpixel = 16;
  18.155 +		break;
  18.156 +	    case B_RGB32:
  18.157 +	    case B_RGBA32:
  18.158 +	    case B_RGB32_BIG:
  18.159 +	    case B_RGBA32_BIG:
  18.160 +		bitsperpixel = 32;
  18.161 +		break;
  18.162 +	    default:
  18.163 +		break;
  18.164 +	}
  18.165 +	return(bitsperpixel);
  18.166 +}
  18.167 +
  18.168 +int32 BE_BPPToSDLPxFormat(int32 bpp) {
  18.169 +	/* Translation taken from SDL_windowsmodes.c */
  18.170 +	switch (bpp) {
  18.171 +	case 32:
  18.172 +		return SDL_PIXELFORMAT_RGB888;
  18.173 +		break;
  18.174 +	case 24:	/* May not be supported by Haiku */
  18.175 +		return SDL_PIXELFORMAT_RGB24;
  18.176 +		break;
  18.177 +	case 16:
  18.178 +		return SDL_PIXELFORMAT_RGB565;
  18.179 +		break;
  18.180 +	case 15:
  18.181 +		return SDL_PIXELFORMAT_RGB555;
  18.182 +		break;
  18.183 +	case 8:
  18.184 +		return SDL_PIXELFORMAT_INDEX8;
  18.185 +		break;
  18.186 +	case 4:		/* May not be supported by Haiku */
  18.187 +		return SDL_PIXELFORMAT_INDEX4LSB;
  18.188 +		break;
  18.189 +	}
  18.190 +}
  18.191 +
  18.192 +static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
  18.193 +		SDL_DisplayMode *mode) {
  18.194 +	mode->w = bmode->virtual_width;
  18.195 +	mode->h = bmode->virtual_height;
  18.196 +	mode->refresh_rate = (int)get_refresh_rate(*bmode);
  18.197 +
  18.198 +#if WRAP_BMODE
  18.199 +	SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1,
  18.200 +		sizeof(SDL_DisplayModeData));
  18.201 +	data->bmode = bmode;
  18.202 +	
  18.203 +	mode->driverdata = data;
  18.204 +
  18.205 +#else
  18.206 +
  18.207 +	mode->driverdata = bmode;
  18.208 +#endif
  18.209 +
  18.210 +	/* Set the format */
  18.211 +	int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode->space);
  18.212 +	mode->format = BE_BPPToSDLPxFormat(bpp);
  18.213 +}
  18.214 +
  18.215 +/* Later, there may be more than one monitor available */
  18.216 +static void _AddDisplay(BScreen *screen) {
  18.217 +	SDL_VideoDisplay display;
  18.218 +	SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1,
  18.219 +		sizeof(SDL_DisplayMode));
  18.220 +	display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
  18.221 +	screen->GetMode(bmode);
  18.222 +
  18.223 +	_BDisplayModeToSdlDisplayMode(bmode, mode);
  18.224 +	
  18.225 +	SDL_zero(display);
  18.226 +	display.desktop_mode = *mode;
  18.227 +	display.current_mode = *mode;
  18.228 +	
  18.229 +	SDL_AddVideoDisplay(&display);
  18.230 +}
  18.231 +
  18.232 +/*
  18.233 + * Functions called by SDL
  18.234 + */
  18.235 +
  18.236 +int BE_InitModes(_THIS) {
  18.237 +	BScreen screen;
  18.238 +
  18.239 +	/* TODO: When Haiku supports multiple display screens, call
  18.240 +	   _AddDisplayScreen() for each of them. */
  18.241 +	_AddDisplay(&screen);
  18.242 +}
  18.243 +
  18.244 +int BE_QuitModes(_THIS) {
  18.245 +	/* FIXME: Nothing really needs to be done here at the moment? */
  18.246 +	return 0;
  18.247 +}
  18.248 +
  18.249 +
  18.250 +int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) {
  18.251 +	BScreen bscreen;
  18.252 +	BRect rc = bscreen.Frame();
  18.253 +	rect->x = (int)rc.left;
  18.254 +	rect->y = (int)rc.top;
  18.255 +	rect->w = (int)rc.Width() + 1;
  18.256 +	rect->h = (int)rc.Height() + 1;
  18.257 +	return 0;
  18.258 +}
  18.259 +
  18.260 +void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
  18.261 +	/* Get the current screen */
  18.262 +	BScreen bscreen;
  18.263 +
  18.264 +	/* Iterate through all of the modes */
  18.265 +	SDL_DisplayMode mode;
  18.266 +	display_mode this_bmode;
  18.267 +	display_mode *bmodes;
  18.268 +	uint32 count, i;
  18.269 +	
  18.270 +	/* Get graphics-hardware supported modes */
  18.271 +	bscreen.GetModeList(&bmodes, &count);
  18.272 +	bscreen.GetMode(&this_bmode);
  18.273 +	
  18.274 +	for(i = 0; i < count; ++i) {
  18.275 +		//FIXME: Apparently there are errors with colorspace changes
  18.276 +		if (bmodes[i].space == this_bmode.space) {
  18.277 +			_BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
  18.278 +			SDL_AddDisplayMode(display, &mode);
  18.279 +		}
  18.280 +	}
  18.281 +	free(bmodes);
  18.282 +}
  18.283 +
  18.284 +
  18.285 +int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
  18.286 +	/* Get the current screen */
  18.287 +	BScreen bscreen;
  18.288 +	if(!bscreen.IsValid()) {
  18.289 +		printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
  18.290 +	}
  18.291 +
  18.292 +	/* Set the mode using the driver data */
  18.293 +	display_mode *bmode = _ExtractBMode(mode);
  18.294 +
  18.295 +
  18.296 +	/* FIXME: Is the first option always going to be the right one? */
  18.297 +	uint32 c = 0, i;
  18.298 +	display_mode *bmode_list;
  18.299 +	bscreen.GetModeList(&bmode_list, &c);
  18.300 +	for(i = 0; i < c; ++i) {
  18.301 +		if(	bmode_list[i].space == bmode->space &&
  18.302 +			bmode_list[i].virtual_width == bmode->virtual_width &&
  18.303 +			bmode_list[i].virtual_height == bmode->virtual_height ) {
  18.304 +				bmode = &bmode_list[i];
  18.305 +				break;
  18.306 +		}
  18.307 +	}
  18.308 +
  18.309 +	if(bscreen.SetMode(bmode) != B_OK) {
  18.310 +		SDL_SetError("Bad video mode\n");
  18.311 +		return -1;
  18.312 +	}
  18.313 +	
  18.314 +	free(bmode_list);
  18.315 +	
  18.316 +#if SDL_VIDEO_OPENGL
  18.317 +	/* FIXME: Is there some way to reboot the OpenGL context?  This doesn't
  18.318 +	   help */
  18.319 +//	BE_GL_RebootContexts(_this);
  18.320 +#endif
  18.321 +
  18.322 +	return 0;
  18.323 +}
  18.324 +
  18.325 +#ifdef __cplusplus
  18.326 +}
  18.327 +#endif
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/bwindow/SDL_bmodes.h	Thu Sep 15 23:51:07 2011 -0400
    19.3 @@ -0,0 +1,46 @@
    19.4 +/*
    19.5 +  Simple DirectMedia Layer
    19.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    19.7 +
    19.8 +  This software is provided 'as-is', without any express or implied
    19.9 +  warranty.  In no event will the authors be held liable for any damages
   19.10 +  arising from the use of this software.
   19.11 +
   19.12 +  Permission is granted to anyone to use this software for any purpose,
   19.13 +  including commercial applications, and to alter it and redistribute it
   19.14 +  freely, subject to the following restrictions:
   19.15 +
   19.16 +  1. The origin of this software must not be misrepresented; you must not
   19.17 +     claim that you wrote the original software. If you use this software
   19.18 +     in a product, an acknowledgment in the product documentation would be
   19.19 +     appreciated but is not required.
   19.20 +  2. Altered source versions must be plainly marked as such, and must not be
   19.21 +     misrepresented as being the original software.
   19.22 +  3. This notice may not be removed or altered from any source distribution.
   19.23 +*/
   19.24 +
   19.25 +#ifndef SDL_BMODES_H
   19.26 +#define SDL_BMODES_H
   19.27 +
   19.28 +#ifdef __cplusplus
   19.29 +extern "C" {
   19.30 +#endif
   19.31 +
   19.32 +#include "../SDL_sysvideo.h"
   19.33 +
   19.34 +extern int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace);
   19.35 +extern int32 BE_BPPToSDLPxFormat(int32 bpp);
   19.36 +
   19.37 +extern int BE_InitModes(_THIS);
   19.38 +extern int BE_QuitModes(_THIS);
   19.39 +extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display,
   19.40 +	SDL_Rect *rect);
   19.41 +extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
   19.42 +extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
   19.43 +	SDL_DisplayMode *mode);
   19.44 +
   19.45 +#ifdef __cplusplus
   19.46 +}
   19.47 +#endif
   19.48 +
   19.49 +#endif
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/bwindow/SDL_bopengl.cc	Thu Sep 15 23:51:07 2011 -0400
    20.3 @@ -0,0 +1,218 @@
    20.4 +/*
    20.5 +  Simple DirectMedia Layer
    20.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    20.7 +
    20.8 +  This software is provided 'as-is', without any express or implied
    20.9 +  warranty.  In no event will the authors be held liable for any damages
   20.10 +  arising from the use of this software.
   20.11 +
   20.12 +  Permission is granted to anyone to use this software for any purpose,
   20.13 +  including commercial applications, and to alter it and redistribute it
   20.14 +  freely, subject to the following restrictions:
   20.15 +
   20.16 +  1. The origin of this software must not be misrepresented; you must not
   20.17 +     claim that you wrote the original software. If you use this software
   20.18 +     in a product, an acknowledgment in the product documentation would be
   20.19 +     appreciated but is not required.
   20.20 +  2. Altered source versions must be plainly marked as such, and must not be
   20.21 +     misrepresented as being the original software.
   20.22 +  3. This notice may not be removed or altered from any source distribution.
   20.23 +*/
   20.24 +
   20.25 +#include "SDL_bopengl.h"
   20.26 +
   20.27 +#include <unistd.h>
   20.28 +#include <KernelKit.h>
   20.29 +#include <OpenGLKit.h>
   20.30 +#include "SDL_BWin.h"
   20.31 +#include "../../main/beos/SDL_BApp.h"
   20.32 +
   20.33 +#ifdef __cplusplus
   20.34 +extern "C" {
   20.35 +#endif
   20.36 +
   20.37 +
   20.38 +#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
   20.39 +
   20.40 +static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
   20.41 +	return ((SDL_BWin*)(window->driverdata));
   20.42 +}
   20.43 +
   20.44 +static inline SDL_BApp *_GetBeApp() {
   20.45 +	return ((SDL_BApp*)be_app);
   20.46 +}
   20.47 +
   20.48 +/* Passing a NULL path means load pointers from the application */
   20.49 +int BE_GL_LoadLibrary(_THIS, const char *path)
   20.50 +{
   20.51 +/* FIXME: Is this working correctly? */
   20.52 +	image_info info;
   20.53 +			int32 cookie = 0;
   20.54 +	while (get_next_image_info(0, &cookie, &info) == B_OK) {
   20.55 +		void *location = NULL;
   20.56 +		if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
   20.57 +				&location) == B_OK) {
   20.58 +
   20.59 +			_this->gl_config.dll_handle = (void *) info.id;
   20.60 +			_this->gl_config.driver_loaded = 1;
   20.61 +			SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
   20.62 +					SDL_arraysize(_this->gl_config.driver_path));
   20.63 +		}
   20.64 +	}
   20.65 +}
   20.66 +
   20.67 +void *BE_GL_GetProcAddress(_THIS, const char *proc)
   20.68 +{
   20.69 +	if (_this->gl_config.dll_handle != NULL) {
   20.70 +		void *location = NULL;
   20.71 +		status_t err;
   20.72 +		if ((err =
   20.73 +			get_image_symbol((image_id) _this->gl_config.dll_handle,
   20.74 +                              proc, B_SYMBOL_TYPE_ANY,
   20.75 +                              &location)) == B_OK) {
   20.76 +            return location;
   20.77 +        } else {
   20.78 +                SDL_SetError("Couldn't find OpenGL symbol");
   20.79 +                return NULL;
   20.80 +        }
   20.81 +	} else {
   20.82 +		SDL_SetError("OpenGL library not loaded");
   20.83 +		return NULL;
   20.84 +	}
   20.85 +}
   20.86 +
   20.87 +
   20.88 +
   20.89 +
   20.90 +void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
   20.91 +    _ToBeWin(window)->SwapBuffers();
   20.92 +}
   20.93 +
   20.94 +int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
   20.95 +	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
   20.96 +	return 0;
   20.97 +}
   20.98 +
   20.99 +
  20.100 +SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
  20.101 +	/* FIXME: Not sure what flags should be included here; may want to have
  20.102 +	   most of them */
  20.103 +	SDL_BWin *bwin = _ToBeWin(window);
  20.104 +	bwin->CreateGLView(BGL_FLAGS);
  20.105 +	return (SDL_GLContext)(bwin);
  20.106 +}
  20.107 +
  20.108 +void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
  20.109 +	/* Currently, automatically unlocks the view */
  20.110 +	((SDL_BWin*)context)->RemoveGLView();
  20.111 +}
  20.112 +
  20.113 +
  20.114 +int BE_GL_SetSwapInterval(_THIS, int interval) {
  20.115 +	/* TODO: Implement this, if necessary? */
  20.116 +	return 0;
  20.117 +}
  20.118 +
  20.119 +int BE_GL_GetSwapInterval(_THIS) {
  20.120 +	/* TODO: Implement this, if necessary? */
  20.121 +	return 0;
  20.122 +}
  20.123 +
  20.124 +
  20.125 +void BE_GL_UnloadLibrary(_THIS) {
  20.126 +	/* TODO: Implement this, if necessary? */
  20.127 +}
  20.128 +
  20.129 +
  20.130 +/* FIXME: This function is meant to clear the OpenGL context when the video
  20.131 +   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
  20.132 +   currently in use. */
  20.133 +void BE_GL_RebootContexts(_THIS) {
  20.134 +	SDL_Window *window = _this->windows;
  20.135 +	while(window) {
  20.136 +		SDL_BWin *bwin = _ToBeWin(window);
  20.137 +		if(bwin->GetGLView()) {
  20.138 +			bwin->LockLooper();
  20.139 +			bwin->RemoveGLView();
  20.140 +			bwin->CreateGLView(BGL_FLAGS);
  20.141 +			bwin->UnlockLooper();
  20.142 +		}
  20.143 +		window = window->next;
  20.144 +	}
  20.145 +}
  20.146 +
  20.147 +
  20.148 +#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
  20.149 +
  20.150 +    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
  20.151 +    {
  20.152 +        /*
  20.153 +           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
  20.154 +         */
  20.155 +        switch (attrib) {
  20.156 +        case SDL_GL_RED_SIZE:
  20.157 +            glGetIntegerv(GL_RED_BITS, (GLint *) value);
  20.158 +            break;
  20.159 +        case SDL_GL_GREEN_SIZE:
  20.160 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
  20.161 +            break;
  20.162 +        case SDL_GL_BLUE_SIZE:
  20.163 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
  20.164 +            break;
  20.165 +        case SDL_GL_ALPHA_SIZE:
  20.166 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
  20.167 +            break;
  20.168 +        case SDL_GL_DOUBLEBUFFER:
  20.169 +            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
  20.170 +            break;
  20.171 +        case SDL_GL_BUFFER_SIZE:
  20.172 +            int v;
  20.173 +            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
  20.174 +            *value = v;
  20.175 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
  20.176 +            *value += v;
  20.177 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
  20.178 +            *value += v;
  20.179 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
  20.180 +            *value += v;
  20.181 +            break;
  20.182 +        case SDL_GL_DEPTH_SIZE:
  20.183 +            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
  20.184 +            break;
  20.185 +        case SDL_GL_STENCIL_SIZE:
  20.186 +            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
  20.187 +            break;
  20.188 +        case SDL_GL_ACCUM_RED_SIZE:
  20.189 +            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
  20.190 +            break;
  20.191 +        case SDL_GL_ACCUM_GREEN_SIZE:
  20.192 +            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
  20.193 +            break;
  20.194 +        case SDL_GL_ACCUM_BLUE_SIZE:
  20.195 +            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
  20.196 +            break;
  20.197 +        case SDL_GL_ACCUM_ALPHA_SIZE:
  20.198 +            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
  20.199 +            break;
  20.200 +        case SDL_GL_STEREO:
  20.201 +        case SDL_GL_MULTISAMPLEBUFFERS:
  20.202 +        case SDL_GL_MULTISAMPLESAMPLES:
  20.203 +        default:
  20.204 +            *value = 0;
  20.205 +            return (-1);
  20.206 +        }
  20.207 +        return 0;
  20.208 +    }
  20.209 +
  20.210 +#endif
  20.211 +
  20.212 +
  20.213 +
  20.214 +
  20.215 +
  20.216 +
  20.217 +
  20.218 +
  20.219 +#ifdef __cplusplus
  20.220 +}
  20.221 +#endif
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/bwindow/SDL_bopengl.h	Thu Sep 15 23:51:07 2011 -0400
    21.3 @@ -0,0 +1,49 @@
    21.4 +/*
    21.5 +  Simple DirectMedia Layer
    21.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    21.7 +
    21.8 +  This software is provided 'as-is', without any express or implied
    21.9 +  warranty.  In no event will the authors be held liable for any damages
   21.10 +  arising from the use of this software.
   21.11 +
   21.12 +  Permission is granted to anyone to use this software for any purpose,
   21.13 +  including commercial applications, and to alter it and redistribute it
   21.14 +  freely, subject to the following restrictions:
   21.15 +
   21.16 +  1. The origin of this software must not be misrepresented; you must not
   21.17 +     claim that you wrote the original software. If you use this software
   21.18 +     in a product, an acknowledgment in the product documentation would be
   21.19 +     appreciated but is not required.
   21.20 +  2. Altered source versions must be plainly marked as such, and must not be
   21.21 +     misrepresented as being the original software.
   21.22 +  3. This notice may not be removed or altered from any source distribution.
   21.23 +*/
   21.24 +
   21.25 +#ifndef SDL_BOPENGL_H
   21.26 +#define SDL_BOPENGL_H
   21.27 +
   21.28 +#ifdef __cplusplus
   21.29 +extern "C" {
   21.30 +#endif
   21.31 +
   21.32 +#include "../SDL_sysvideo.h"
   21.33 +
   21.34 +
   21.35 +extern int BE_GL_LoadLibrary(_THIS, const char *path);					//FIXME
   21.36 +extern void *BE_GL_GetProcAddress(_THIS, const char *proc);				//FIXME
   21.37 +extern void BE_GL_UnloadLibrary(_THIS);									//TODO
   21.38 +extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window,
   21.39 +                              SDL_GLContext context);
   21.40 +extern int BE_GL_SetSwapInterval(_THIS, int interval);					//TODO
   21.41 +extern int BE_GL_GetSwapInterval(_THIS);								//TODO
   21.42 +extern void BE_GL_SwapWindow(_THIS, SDL_Window * window);
   21.43 +extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window);
   21.44 +extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context);
   21.45 +
   21.46 +extern void BE_GL_RebootContexts(_THIS);
   21.47 +
   21.48 +#ifdef __cplusplus
   21.49 +}
   21.50 +#endif
   21.51 +
   21.52 +#endif
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/video/bwindow/SDL_bvideo.cc	Thu Sep 15 23:51:07 2011 -0400
    22.3 @@ -0,0 +1,170 @@
    22.4 +/*
    22.5 +  Simple DirectMedia Layer
    22.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    22.7 +
    22.8 +  This software is provided 'as-is', without any express or implied
    22.9 +  warranty.  In no event will the authors be held liable for any damages
   22.10 +  arising from the use of this software.
   22.11 +
   22.12 +  Permission is granted to anyone to use this software for any purpose,
   22.13 +  including commercial applications, and to alter it and redistribute it
   22.14 +  freely, subject to the following restrictions:
   22.15 +
   22.16 +  1. The origin of this software must not be misrepresented; you must not
   22.17 +     claim that you wrote the original software. If you use this software
   22.18 +     in a product, an acknowledgment in the product documentation would be
   22.19 +     appreciated but is not required.
   22.20 +  2. Altered source versions must be plainly marked as such, and must not be
   22.21 +     misrepresented as being the original software.
   22.22 +  3. This notice may not be removed or altered from any source distribution.
   22.23 +*/
   22.24 +
   22.25 +
   22.26 +
   22.27 +
   22.28 +#ifdef __cplusplus
   22.29 +extern "C" {
   22.30 +#endif
   22.31 +
   22.32 +#include "SDL_bkeyboard.h"
   22.33 +#include "SDL_bwindow.h"
   22.34 +#include "SDL_bclipboard.h"
   22.35 +#include "SDL_bvideo.h"
   22.36 +#include "SDL_bopengl.h"
   22.37 +#include "SDL_bmodes.h"
   22.38 +#include "SDL_bframebuffer.h"
   22.39 +#include "SDL_bevents.h"
   22.40 +
   22.41 +/* FIXME: Undefined functions */
   22.42 +//    #define BE_PumpEvents NULL
   22.43 +    #define BE_StartTextInput NULL
   22.44 +    #define BE_StopTextInput NULL
   22.45 +    #define BE_SetTextInputRect NULL
   22.46 +
   22.47 +//    #define BE_DeleteDevice NULL
   22.48 +
   22.49 +/* End undefined functions */
   22.50 +
   22.51 +static SDL_VideoDevice *
   22.52 +BE_CreateDevice(int devindex)
   22.53 +{
   22.54 +    SDL_VideoDevice *device;
   22.55 +    /*SDL_VideoData *data;*/
   22.56 +
   22.57 +    /* Initialize all variables that we clean on shutdown */
   22.58 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   22.59 +
   22.60 +    device->driverdata = NULL; /* FIXME: Is this the cause of some of the
   22.61 +    							  SDL_Quit() errors? */
   22.62 +
   22.63 +/* TODO: Figure out if any initialization needs to go here */
   22.64 +
   22.65 +    /* Set the function pointers */
   22.66 +    device->VideoInit = BE_VideoInit;
   22.67 +    device->VideoQuit = BE_VideoQuit;
   22.68 +    device->GetDisplayBounds = BE_GetDisplayBounds;
   22.69 +    device->GetDisplayModes = BE_GetDisplayModes;
   22.70 +    device->SetDisplayMode = BE_SetDisplayMode;
   22.71 +    device->PumpEvents = BE_PumpEvents;
   22.72 +
   22.73 +    device->CreateWindow = BE_CreateWindow;
   22.74 +    device->CreateWindowFrom = BE_CreateWindowFrom;
   22.75 +    device->SetWindowTitle = BE_SetWindowTitle;
   22.76 +    device->SetWindowIcon = BE_SetWindowIcon;
   22.77 +    device->SetWindowPosition = BE_SetWindowPosition;
   22.78 +    device->SetWindowSize = BE_SetWindowSize;
   22.79 +    device->ShowWindow = BE_ShowWindow;
   22.80 +    device->HideWindow = BE_HideWindow;
   22.81 +    device->RaiseWindow = BE_RaiseWindow;
   22.82 +    device->MaximizeWindow = BE_MaximizeWindow;
   22.83 +    device->MinimizeWindow = BE_MinimizeWindow;
   22.84 +    device->RestoreWindow = BE_RestoreWindow;
   22.85 +    device->SetWindowFullscreen = BE_SetWindowFullscreen;
   22.86 +    device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
   22.87 +    device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
   22.88 +    device->SetWindowGrab = BE_SetWindowGrab;
   22.89 +    device->DestroyWindow = BE_DestroyWindow;
   22.90 +    device->GetWindowWMInfo = BE_GetWindowWMInfo;
   22.91 +    device->CreateWindowFramebuffer = BE_CreateWindowFramebuffer;
   22.92 +    device->UpdateWindowFramebuffer = BE_UpdateWindowFramebuffer;
   22.93 +    device->DestroyWindowFramebuffer = BE_DestroyWindowFramebuffer;
   22.94 +    
   22.95 +    device->shape_driver.CreateShaper = NULL;
   22.96 +    device->shape_driver.SetWindowShape = NULL;
   22.97 +    device->shape_driver.ResizeWindowShape = NULL;
   22.98 +
   22.99 +
  22.100 +    device->GL_LoadLibrary = BE_GL_LoadLibrary;
  22.101 +    device->GL_GetProcAddress = BE_GL_GetProcAddress;
  22.102 +    device->GL_UnloadLibrary = BE_GL_UnloadLibrary;
  22.103 +    device->GL_CreateContext = BE_GL_CreateContext;
  22.104 +    device->GL_MakeCurrent = BE_GL_MakeCurrent;
  22.105 +    device->GL_SetSwapInterval = BE_GL_SetSwapInterval;
  22.106 +    device->GL_GetSwapInterval = BE_GL_GetSwapInterval;
  22.107 +    device->GL_SwapWindow = BE_GL_SwapWindow;
  22.108 +    device->GL_DeleteContext = BE_GL_DeleteContext;
  22.109 +
  22.110 +    device->StartTextInput = BE_StartTextInput;
  22.111 +    device->StopTextInput = BE_StopTextInput;
  22.112 +    device->SetTextInputRect = BE_SetTextInputRect;
  22.113 +
  22.114 +    device->SetClipboardText = BE_SetClipboardText;
  22.115 +    device->GetClipboardText = BE_GetClipboardText;
  22.116 +    device->HasClipboardText = BE_HasClipboardText;
  22.117 +
  22.118 +    device->free = BE_DeleteDevice;
  22.119 +
  22.120 +    return device;
  22.121 +}
  22.122 +
  22.123 +VideoBootStrap BWINDOW_bootstrap = {
  22.124 +	"bwindow", "BDirectWindow graphics",
  22.125 +	BE_Available, BE_CreateDevice
  22.126 +};
  22.127 +
  22.128 +void BE_DeleteDevice(SDL_VideoDevice * device)
  22.129 +{
  22.130 +	SDL_free(device->driverdata);
  22.131 +	SDL_free(device);
  22.132 +}
  22.133 +
  22.134 +int BE_VideoInit(_THIS)
  22.135 +{
  22.136 +	/* Initialize the Be Application for appserver interaction */
  22.137 +	if (SDL_InitBeApp() < 0) {
  22.138 +		return -1;
  22.139 +	}
  22.140 +	
  22.141 +	/* Initialize video modes */
  22.142 +	BE_InitModes(_this);
  22.143 +
  22.144 +	/* Init the keymap */
  22.145 +	BE_InitOSKeymap();
  22.146 +	
  22.147 +	
  22.148 +#if SDL_VIDEO_OPENGL
  22.149 +        /* testgl application doesn't load library, just tries to load symbols */
  22.150 +        /* is it correct? if so we have to load library here */
  22.151 +    BE_GL_LoadLibrary(_this, NULL);
  22.152 +#endif
  22.153 +
  22.154 +        /* We're done! */
  22.155 +    return (0);
  22.156 +}
  22.157 +
  22.158 +int BE_Available(void)
  22.159 +{
  22.160 +    return (1);
  22.161 +}
  22.162 +
  22.163 +void BE_VideoQuit(_THIS)
  22.164 +{
  22.165 +
  22.166 +    BE_QuitModes(_this);
  22.167 +
  22.168 +    SDL_QuitBeApp();
  22.169 +}
  22.170 +
  22.171 +#ifdef __cplusplus
  22.172 +}
  22.173 +#endif
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/video/bwindow/SDL_bvideo.h	Thu Sep 15 23:51:07 2011 -0400
    23.3 @@ -0,0 +1,42 @@
    23.4 +/*
    23.5 +  Simple DirectMedia Layer
    23.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    23.7 +
    23.8 +  This software is provided 'as-is', without any express or implied
    23.9 +  warranty.  In no event will the authors be held liable for any damages
   23.10 +  arising from the use of this software.
   23.11 +
   23.12 +  Permission is granted to anyone to use this software for any purpose,
   23.13 +  including commercial applications, and to alter it and redistribute it
   23.14 +  freely, subject to the following restrictions:
   23.15 +
   23.16 +  1. The origin of this software must not be misrepresented; you must not
   23.17 +     claim that you wrote the original software. If you use this software
   23.18 +     in a product, an acknowledgment in the product documentation would be
   23.19 +     appreciated but is not required.
   23.20 +  2. Altered source versions must be plainly marked as such, and must not be
   23.21 +     misrepresented as being the original software.
   23.22 +  3. This notice may not be removed or altered from any source distribution.
   23.23 +*/
   23.24 +
   23.25 +#ifndef BVIDEO_H
   23.26 +#define BVIDEO_H
   23.27 +
   23.28 +#ifdef __cplusplus
   23.29 +extern "C" {
   23.30 +#endif
   23.31 +
   23.32 +#include "../../main/beos/SDL_BeApp.h"
   23.33 +#include "../SDL_sysvideo.h"
   23.34 +
   23.35 +
   23.36 +extern void BE_VideoQuit(_THIS);
   23.37 +extern int BE_VideoInit(_THIS);
   23.38 +extern void BE_DeleteDevice(_THIS);
   23.39 +extern int BE_Available(void);
   23.40 +
   23.41 +#ifdef __cplusplus
   23.42 +}
   23.43 +#endif
   23.44 +
   23.45 +#endif
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/video/bwindow/SDL_bwindow.cc	Thu Sep 15 23:51:07 2011 -0400
    24.3 @@ -0,0 +1,212 @@
    24.4 +/*
    24.5 +  Simple DirectMedia Layer
    24.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    24.7 +
    24.8 +  This software is provided 'as-is', without any express or implied
    24.9 +  warranty.  In no event will the authors be held liable for any damages
   24.10 +  arising from the use of this software.
   24.11 +
   24.12 +  Permission is granted to anyone to use this software for any purpose,
   24.13 +  including commercial applications, and to alter it and redistribute it
   24.14 +  freely, subject to the following restrictions:
   24.15 +
   24.16 +  1. The origin of this software must not be misrepresented; you must not
   24.17 +     claim that you wrote the original software. If you use this software
   24.18 +     in a product, an acknowledgment in the product documentation would be
   24.19 +     appreciated but is not required.
   24.20 +  2. Altered source versions must be plainly marked as such, and must not be
   24.21 +     misrepresented as being the original software.
   24.22 +  3. This notice may not be removed or altered from any source distribution.
   24.23 +*/
   24.24 +#include "SDL_config.h"
   24.25 +#include "../SDL_sysvideo.h"
   24.26 +
   24.27 +#include "SDL_BWin.h"
   24.28 +#include <new>
   24.29 +
   24.30 +/* Define a path to window's BWIN data */
   24.31 +#ifdef __cplusplus
   24.32 +extern "C" {
   24.33 +#endif
   24.34 +
   24.35 +static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
   24.36 +	return ((SDL_BWin*)(window->driverdata));
   24.37 +}
   24.38 +
   24.39 +static inline SDL_BApp *_GetBeApp() {
   24.40 +	return ((SDL_BApp*)be_app);
   24.41 +}
   24.42 +
   24.43 +static int _InitWindow(_THIS, SDL_Window *window) {
   24.44 +	uint32 flags = 0;
   24.45 +	BRect bounds(
   24.46 +        window->x,
   24.47 +        window->y,
   24.48 +        window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
   24.49 +        window->y + window->h - 1
   24.50 +    );
   24.51 +    
   24.52 +    if(window->flags & SDL_WINDOW_FULLSCREEN) {
   24.53 +    	/* TODO: Add support for this flag */
   24.54 +    	printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
   24.55 +    }
   24.56 +    if(window->flags & SDL_WINDOW_OPENGL) {
   24.57 +    	/* TODO: Add support for this flag */
   24.58 +    }
   24.59 +    if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
   24.60 +    	flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
   24.61 +    }
   24.62 +    if(window->flags & SDL_WINDOW_BORDERLESS) {
   24.63 +    	/* TODO: Add support for this flag */
   24.64 +    }
   24.65 +
   24.66 +    SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, flags);
   24.67 +    if(bwin == NULL)
   24.68 +    	return ENOMEM;
   24.69 +
   24.70 +    window->driverdata = bwin;
   24.71 +    int32 winID = _GetBeApp()->GetID(window);
   24.72 +    bwin->SetID(winID);
   24.73 +
   24.74 +    return 0;
   24.75 +}
   24.76 +
   24.77 +int BE_CreateWindow(_THIS, SDL_Window *window) {
   24.78 +	if(_InitWindow(_this, window) == ENOMEM)
   24.79 +		return ENOMEM;
   24.80 +	
   24.81 +	/* Start window loop */
   24.82 +    _ToBeWin(window)->Show();
   24.83 +    return 0;
   24.84 +}
   24.85 +
   24.86 +int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
   24.87 +
   24.88 +	SDL_BWin *otherBWin = (SDL_BWin*)data;
   24.89 +	if(!otherBWin->LockLooper())
   24.90 +		return -1;
   24.91 +	
   24.92 +	/* Create the new window and initialize its members */
   24.93 +	window->x = (int)otherBWin->Frame().left;
   24.94 +	window->y = (int)otherBWin->Frame().top;
   24.95 +	window->w = (int)otherBWin->Frame().Width();
   24.96 +	window->h = (int)otherBWin->Frame().Height();
   24.97 +	
   24.98 +	/* Set SDL flags */
   24.99 +	if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
  24.100 +		window->flags |= SDL_WINDOW_RESIZABLE;
  24.101 +	}
  24.102 +	
  24.103 +	/* If we are out of memory, return the error code */
  24.104 +	if(_InitWindow(_this, window) == ENOMEM)
  24.105 +		return ENOMEM;
  24.106 +	
  24.107 +	/* TODO: Add any other SDL-supported window attributes here */
  24.108 +    _ToBeWin(window)->SetTitle(otherBWin->Title());
  24.109 +    
  24.110 +    /* Start window loop and unlock the other window */
  24.111 +    _ToBeWin(window)->Show();
  24.112 +    
  24.113 +    otherBWin->UnlockLooper();
  24.114 +    return 0;
  24.115 +}
  24.116 +
  24.117 +void BE_SetWindowTitle(_THIS, SDL_Window * window) {
  24.118 +	BMessage msg(BWIN_SET_TITLE);
  24.119 +	msg.AddString("window-title", window->title);
  24.120 +	_ToBeWin(window)->PostMessage(&msg);
  24.121 +}
  24.122 +
  24.123 +void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
  24.124 +	/* FIXME: Icons not supported by BeOs/Haiku */
  24.125 +}
  24.126 +
  24.127 +void BE_SetWindowPosition(_THIS, SDL_Window * window) {
  24.128 +	BMessage msg(BWIN_MOVE_WINDOW);
  24.129 +	msg.AddInt32("window-x", window->x);
  24.130 +	msg.AddInt32("window-y", window->y);
  24.131 +	_ToBeWin(window)->PostMessage(&msg);
  24.132 +}
  24.133 +
  24.134 +void BE_SetWindowSize(_THIS, SDL_Window * window) {
  24.135 +	BMessage msg(BWIN_RESIZE_WINDOW);
  24.136 +	msg.AddInt32("window-w", window->w - 1);
  24.137 +	msg.AddInt32("window-h", window->h - 1);
  24.138 +	_ToBeWin(window)->PostMessage(&msg);
  24.139 +}
  24.140 +
  24.141 +void BE_ShowWindow(_THIS, SDL_Window * window) {
  24.142 +	BMessage msg(BWIN_SHOW_WINDOW);
  24.143 +	_ToBeWin(window)->PostMessage(&msg);
  24.144 +}
  24.145 +
  24.146 +void BE_HideWindow(_THIS, SDL_Window * window) {
  24.147 +	BMessage msg(BWIN_HIDE_WINDOW);
  24.148 +	_ToBeWin(window)->PostMessage(&msg);
  24.149 +}
  24.150 +
  24.151 +void BE_RaiseWindow(_THIS, SDL_Window * window) {
  24.152 +	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
  24.153 +	_ToBeWin(window)->PostMessage(&msg);
  24.154 +}
  24.155 +
  24.156 +void BE_MaximizeWindow(_THIS, SDL_Window * window) {
  24.157 +	BMessage msg(BWIN_MAXIMIZE_WINDOW);
  24.158 +	_ToBeWin(window)->PostMessage(&msg);
  24.159 +}
  24.160 +
  24.161 +void BE_MinimizeWindow(_THIS, SDL_Window * window) {
  24.162 +	BMessage msg(BWIN_MINIMIZE_WINDOW);
  24.163 +	_ToBeWin(window)->PostMessage(&msg);
  24.164 +}
  24.165 +
  24.166 +void BE_RestoreWindow(_THIS, SDL_Window * window) {
  24.167 +	BMessage msg(BWIN_RESTORE_WINDOW);
  24.168 +	_ToBeWin(window)->PostMessage(&msg);
  24.169 +}
  24.170 +
  24.171 +void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
  24.172 +		SDL_VideoDisplay * display, SDL_bool fullscreen) {
  24.173 +	/* Haiku tracks all video display information */
  24.174 +	BMessage msg(BWIN_FULLSCREEN);
  24.175 +	msg.AddBool("fullscreen", fullscreen);
  24.176 +	_ToBeWin(window)->PostMessage(&msg);
  24.177 +	
  24.178 +}
  24.179 +
  24.180 +int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
  24.181 +	/* FIXME: Not BeOs/Haiku supported */
  24.182 +	return -1;
  24.183 +}
  24.184 +
  24.185 +int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
  24.186 +	/* FIXME: Not BeOs/Haiku supported */
  24.187 +	return -1;
  24.188 +}
  24.189 +
  24.190 +
  24.191 +void BE_SetWindowGrab(_THIS, SDL_Window * window) {
  24.192 +	/* TODO: Implement this! */
  24.193 +}
  24.194 +
  24.195 +void BE_DestroyWindow(_THIS, SDL_Window * window) {
  24.196 +	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
  24.197 +	_GetBeApp()->ClearID(_ToBeWin(window));
  24.198 +	_ToBeWin(window)->Quit();
  24.199 +	window->driverdata = NULL;
  24.200 +}
  24.201 +
  24.202 +SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
  24.203 +                                    struct SDL_SysWMinfo *info) {
  24.204 +	/* FIXME: What is the point of this? What information should be included? */
  24.205 +	return SDL_FALSE;
  24.206 +}
  24.207 +
  24.208 +
  24.209 +
  24.210 +
  24.211 + 
  24.212 +#ifdef __cplusplus
  24.213 +}
  24.214 +#endif
  24.215 +
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/video/bwindow/SDL_bwindow.h	Thu Sep 15 23:51:07 2011 -0400
    25.3 @@ -0,0 +1,52 @@
    25.4 +/*
    25.5 +  Simple DirectMedia Layer
    25.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    25.7 +
    25.8 +  This software is provided 'as-is', without any express or implied
    25.9 +  warranty.  In no event will the authors be held liable for any damages
   25.10 +  arising from the use of this software.
   25.11 +
   25.12 +  Permission is granted to anyone to use this software for any purpose,
   25.13 +  including commercial applications, and to alter it and redistribute it
   25.14 +  freely, subject to the following restrictions:
   25.15 +
   25.16 +  1. The origin of this software must not be misrepresented; you must not
   25.17 +     claim that you wrote the original software. If you use this software
   25.18 +     in a product, an acknowledgment in the product documentation would be
   25.19 +     appreciated but is not required.
   25.20 +  2. Altered source versions must be plainly marked as such, and must not be
   25.21 +     misrepresented as being the original software.
   25.22 +  3. This notice may not be removed or altered from any source distribution.
   25.23 +*/
   25.24 +
   25.25 +#ifndef SDL_BWINDOW_H
   25.26 +#define SDL_BWINDOW_H
   25.27 +
   25.28 +
   25.29 +#include "../SDL_sysvideo.h"
   25.30 +
   25.31 +
   25.32 +extern int BE_CreateWindow(_THIS, SDL_Window *window);
   25.33 +extern int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
   25.34 +extern void BE_SetWindowTitle(_THIS, SDL_Window * window);
   25.35 +extern void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
   25.36 +extern void BE_SetWindowPosition(_THIS, SDL_Window * window);
   25.37 +extern void BE_SetWindowSize(_THIS, SDL_Window * window);
   25.38 +extern void BE_ShowWindow(_THIS, SDL_Window * window);
   25.39 +extern void BE_HideWindow(_THIS, SDL_Window * window);
   25.40 +extern void BE_RaiseWindow(_THIS, SDL_Window * window);
   25.41 +extern void BE_MaximizeWindow(_THIS, SDL_Window * window);
   25.42 +extern void BE_MinimizeWindow(_THIS, SDL_Window * window);
   25.43 +extern void BE_RestoreWindow(_THIS, SDL_Window * window);
   25.44 +extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   25.45 +extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
   25.46 +extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
   25.47 +extern void BE_SetWindowGrab(_THIS, SDL_Window * window);
   25.48 +extern void BE_DestroyWindow(_THIS, SDL_Window * window);
   25.49 +extern SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
   25.50 +                                    struct SDL_SysWMinfo *info);
   25.51 +
   25.52 +
   25.53 +
   25.54 +#endif
   25.55 +
    26.1 --- a/src/video/bwindow/SDL_lowvideo.h	Thu Sep 15 08:21:54 2011 -0700
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,59 +0,0 @@
    26.4 -/*
    26.5 -  Simple DirectMedia Layer
    26.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    26.7 -
    26.8 -  This software is provided 'as-is', without any express or implied
    26.9 -  warranty.  In no event will the authors be held liable for any damages
   26.10 -  arising from the use of this software.
   26.11 -
   26.12 -  Permission is granted to anyone to use this software for any purpose,
   26.13 -  including commercial applications, and to alter it and redistribute it
   26.14 -  freely, subject to the following restrictions:
   26.15 -
   26.16 -  1. The origin of this software must not be misrepresented; you must not
   26.17 -     claim that you wrote the original software. If you use this software
   26.18 -     in a product, an acknowledgment in the product documentation would be
   26.19 -     appreciated but is not required.
   26.20 -  2. Altered source versions must be plainly marked as such, and must not be
   26.21 -     misrepresented as being the original software.
   26.22 -  3. This notice may not be removed or altered from any source distribution.
   26.23 -*/
   26.24 -#include "SDL_config.h"
   26.25 -
   26.26 -#ifndef _SDL_lowvideo_h
   26.27 -#define _SDL_lowvideo_h
   26.28 -
   26.29 -#include "SDL_BWin.h"
   26.30 -#include "SDL_mouse.h"
   26.31 -#include "../SDL_sysvideo.h"
   26.32 -
   26.33 -/* Hidden "this" pointer for the video functions */
   26.34 -#define _THIS	SDL_VideoDevice *_this
   26.35 -
   26.36 -/* Private display data */
   26.37 -struct SDL_PrivateVideoData
   26.38 -{
   26.39 -    /* The main window */
   26.40 -    SDL_BWin *SDL_Win;
   26.41 -
   26.42 -    /* The fullscreen mode list */
   26.43 -    display_mode saved_mode;
   26.44 -#define NUM_MODELISTS	4       /* 8, 16, 24, and 32 bits-per-pixel */
   26.45 -    int SDL_nummodes[NUM_MODELISTS];
   26.46 -    SDL_Rect **SDL_modelist[NUM_MODELISTS];
   26.47 -
   26.48 -    /* A completely clear cursor */
   26.49 -    WMcursor *BlankCursor;
   26.50 -
   26.51 -    SDL_Overlay *overlay;
   26.52 -};
   26.53 -/* Old variable names */
   26.54 -#define SDL_Win		(_this->hidden->SDL_Win)
   26.55 -#define saved_mode	(_this->hidden->saved_mode)
   26.56 -#define SDL_nummodes	(_this->hidden->SDL_nummodes)
   26.57 -#define SDL_modelist	(_this->hidden->SDL_modelist)
   26.58 -#define SDL_BlankCursor	(_this->hidden->BlankCursor)
   26.59 -#define current_overlay (_this->hidden->overlay)
   26.60 -
   26.61 -#endif /* _SDL_lowvideo_h */
   26.62 -/* vi: set ts=4 sw=4 expandtab: */
    27.1 --- a/src/video/bwindow/SDL_sysevents.cc	Thu Sep 15 08:21:54 2011 -0700
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,48 +0,0 @@
    27.4 -/*
    27.5 -  Simple DirectMedia Layer
    27.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    27.7 -
    27.8 -  This software is provided 'as-is', without any express or implied
    27.9 -  warranty.  In no event will the authors be held liable for any damages
   27.10 -  arising from the use of this software.
   27.11 -
   27.12 -  Permission is granted to anyone to use this software for any purpose,
   27.13 -  including commercial applications, and to alter it and redistribute it
   27.14 -  freely, subject to the following restrictions:
   27.15 -
   27.16 -  1. The origin of this software must not be misrepresented; you must not
   27.17 -     claim that you wrote the original software. If you use this software
   27.18 -     in a product, an acknowledgment in the product documentation would be
   27.19 -     appreciated but is not required.
   27.20 -  2. Altered source versions must be plainly marked as such, and must not be
   27.21 -     misrepresented as being the original software.
   27.22 -  3. This notice may not be removed or altered from any source distribution.
   27.23 -*/
   27.24 -#include "SDL_config.h"
   27.25 -
   27.26 -#include <support/UTF8.h>
   27.27 -#include <stdio.h>
   27.28 -#include <string.h>
   27.29 -#include "SDL_error.h"
   27.30 -#include "SDL_events.h"
   27.31 -#include "SDL_BWin.h"
   27.32 -#include "SDL_lowvideo.h"
   27.33 -
   27.34 -extern "C"
   27.35 -{
   27.36 -
   27.37 -#include "../../events/SDL_sysevents.h"
   27.38 -#include "../../events/SDL_events_c.h"
   27.39 -#include "SDL_sysevents_c.h"
   27.40 -
   27.41 -    void BE_PumpEvents(_THIS)
   27.42 -    {
   27.43 -    }
   27.44 -
   27.45 -    void BE_InitOSKeymap(_THIS)
   27.46 -    {
   27.47 -    }
   27.48 -
   27.49 -};                              /* Extern C */
   27.50 -
   27.51 -/* vi: set ts=4 sw=4 expandtab: */
    28.1 --- a/src/video/bwindow/SDL_sysevents_c.h	Thu Sep 15 08:21:54 2011 -0700
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,31 +0,0 @@
    28.4 -/*
    28.5 -  Simple DirectMedia Layer
    28.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    28.7 -
    28.8 -  This software is provided 'as-is', without any express or implied
    28.9 -  warranty.  In no event will the authors be held liable for any damages
   28.10 -  arising from the use of this software.
   28.11 -
   28.12 -  Permission is granted to anyone to use this software for any purpose,
   28.13 -  including commercial applications, and to alter it and redistribute it
   28.14 -  freely, subject to the following restrictions:
   28.15 -
   28.16 -  1. The origin of this software must not be misrepresented; you must not
   28.17 -     claim that you wrote the original software. If you use this software
   28.18 -     in a product, an acknowledgment in the product documentation would be
   28.19 -     appreciated but is not required.
   28.20 -  2. Altered source versions must be plainly marked as such, and must not be
   28.21 -     misrepresented as being the original software.
   28.22 -  3. This notice may not be removed or altered from any source distribution.
   28.23 -*/
   28.24 -#include "SDL_config.h"
   28.25 -
   28.26 -#include "SDL_lowvideo.h"
   28.27 -
   28.28 -/* Variables and functions exported by SDL_sysevents.c to other parts 
   28.29 -   of the native video subsystem (SDL_sysvideo.c)
   28.30 -*/
   28.31 -
   28.32 -extern void BE_InitOSKeymap(_THIS);
   28.33 -extern void BE_PumpEvents(_THIS);
   28.34 -/* vi: set ts=4 sw=4 expandtab: */
    29.1 --- a/src/video/bwindow/SDL_sysmouse.cc	Thu Sep 15 08:21:54 2011 -0700
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,144 +0,0 @@
    29.4 -/*
    29.5 -  Simple DirectMedia Layer
    29.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    29.7 -
    29.8 -  This software is provided 'as-is', without any express or implied
    29.9 -  warranty.  In no event will the authors be held liable for any damages
   29.10 -  arising from the use of this software.
   29.11 -
   29.12 -  Permission is granted to anyone to use this software for any purpose,
   29.13 -  including commercial applications, and to alter it and redistribute it
   29.14 -  freely, subject to the following restrictions:
   29.15 -
   29.16 -  1. The origin of this software must not be misrepresented; you must not
   29.17 -     claim that you wrote the original software. If you use this software
   29.18 -     in a product, an acknowledgment in the product documentation would be
   29.19 -     appreciated but is not required.
   29.20 -  2. Altered source versions must be plainly marked as such, and must not be
   29.21 -     misrepresented as being the original software.
   29.22 -  3. This notice may not be removed or altered from any source distribution.
   29.23 -*/
   29.24 -#include "SDL_config.h"
   29.25 -
   29.26 -#include <AppKit.h>
   29.27 -#include <GameKit.h>
   29.28 -
   29.29 -#include "SDL_BWin.h"
   29.30 -
   29.31 -extern "C"
   29.32 -{
   29.33 -
   29.34 -#include "SDL_sysmouse_c.h"
   29.35 -
   29.36 -/* Convert bits to padded bytes */
   29.37 -#define PADDED_BITS(bits)  ((bits+7)/8)
   29.38 -
   29.39 -/* The implementation dependent data for the window manager cursor */
   29.40 -    struct WMcursor
   29.41 -    {
   29.42 -        char *bits;
   29.43 -    };
   29.44 -
   29.45 -/* Can this be done in the BeOS? */
   29.46 -    WMcursor *BE_CreateWMCursor(_THIS,
   29.47 -                                Uint8 * data, Uint8 * mask, int w, int h,
   29.48 -                                int hot_x, int hot_y)
   29.49 -    {
   29.50 -        WMcursor *cursor;
   29.51 -        int allowed_x;
   29.52 -        int allowed_y;
   29.53 -        int run, pad, i;
   29.54 -        char *cptr;
   29.55 -
   29.56 -          allowed_x = 16;       /* BeOS limitation */
   29.57 -          allowed_y = 16;       /* BeOS limitation */
   29.58 -        if ((w > allowed_x) || (h > allowed_y))
   29.59 -        {
   29.60 -            SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
   29.61 -                         allowed_x, allowed_y);
   29.62 -            return (NULL);
   29.63 -        }
   29.64 -
   29.65 -        /* Allocate the cursor */
   29.66 -        cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
   29.67 -        if (cursor == NULL) {
   29.68 -            SDL_OutOfMemory();
   29.69 -            return (NULL);
   29.70 -        }
   29.71 -        cursor->bits =
   29.72 -            (char *) SDL_malloc(4 + 2 * ((allowed_x / 8) * allowed_y));
   29.73 -        if (cursor->bits == NULL) {
   29.74 -            SDL_free(cursor);
   29.75 -            SDL_OutOfMemory();
   29.76 -            return (NULL);
   29.77 -        }
   29.78 -        cursor->bits[0] = allowed_y;    /* Size of the cursor */
   29.79 -        cursor->bits[1] = 1;    /* Bit depth of cursor */
   29.80 -        cursor->bits[2] = hot_y;
   29.81 -        cursor->bits[3] = hot_x;
   29.82 -        cptr = &cursor->bits[4];
   29.83 -
   29.84 -        /* Pad out to the normal cursor size */
   29.85 -        run = PADDED_BITS(w);
   29.86 -        pad = PADDED_BITS(allowed_x) - run;
   29.87 -        for (i = 0; i < h; ++i) {
   29.88 -            SDL_memcpy(cptr, data, run);
   29.89 -            SDL_memset(cptr + run, 0, pad);
   29.90 -            data += run;
   29.91 -            cptr += (run + pad);
   29.92 -        }
   29.93 -        for (; i < allowed_y; ++i) {
   29.94 -            SDL_memset(cptr, 0, run + pad);
   29.95 -            cptr += (run + pad);
   29.96 -        }
   29.97 -        for (i = 0; i < h; ++i) {
   29.98 -            /* FIXME: The mask should be OR'd with the data to turn 
   29.99 -               inverted color pixels black, since inverted color pixels
  29.100 -               aren't supported under BeOS.
  29.101 -             */
  29.102 -            SDL_memcpy(cptr, mask, run);
  29.103 -            SDL_memset(cptr + run, 0, pad);
  29.104 -            mask += run;
  29.105 -            cptr += (run + pad);
  29.106 -        }
  29.107 -        for (; i < allowed_y; ++i) {
  29.108 -            SDL_memset(cptr, 0, run + pad);
  29.109 -            cptr += (run + pad);
  29.110 -        }
  29.111 -        return (cursor);
  29.112 -    }
  29.113 -
  29.114 -    int BE_ShowWMCursor(_THIS, WMcursor * cursor)
  29.115 -    {
  29.116 -        if (be_app->Lock()) {
  29.117 -            if (cursor == NULL) {
  29.118 -                if (SDL_BlankCursor != NULL) {
  29.119 -                    be_app->SetCursor(SDL_BlankCursor->bits);
  29.120 -                }
  29.121 -            } else {
  29.122 -                be_app->SetCursor(cursor->bits);
  29.123 -            }
  29.124 -            be_app->Unlock();
  29.125 -        }
  29.126 -        return (1);
  29.127 -    }
  29.128 -
  29.129 -    void BE_FreeWMCursor(_THIS, WMcursor * cursor)
  29.130 -    {
  29.131 -        SDL_free(cursor->bits);
  29.132 -        SDL_free(cursor);
  29.133 -    }
  29.134 -
  29.135 -/* Implementation by Christian Bauer <cbauer@student.physik.uni-mainz.de> */
  29.136 -    void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
  29.137 -    {
  29.138 -        BPoint pt(x, y);
  29.139 -        SDL_Win->Lock();
  29.140 -        SDL_Win->ConvertToScreen(&pt);
  29.141 -        SDL_Win->Unlock();
  29.142 -        set_mouse_position((int32) pt.x, (int32) pt.y);
  29.143 -    }
  29.144 -
  29.145 -};                              /* Extern C */
  29.146 -
  29.147 -/* vi: set ts=4 sw=4 expandtab: */
    30.1 --- a/src/video/bwindow/SDL_sysmouse_c.h	Thu Sep 15 08:21:54 2011 -0700
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,32 +0,0 @@
    30.4 -/*
    30.5 -  Simple DirectMedia Layer
    30.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    30.7 -
    30.8 -  This software is provided 'as-is', without any express or implied
    30.9 -  warranty.  In no event will the authors be held liable for any damages
   30.10 -  arising from the use of this software.
   30.11 -
   30.12 -  Permission is granted to anyone to use this software for any purpose,
   30.13 -  including commercial applications, and to alter it and redistribute it
   30.14 -  freely, subject to the following restrictions:
   30.15 -
   30.16 -  1. The origin of this software must not be misrepresented; you must not
   30.17 -     claim that you wrote the original software. If you use this software
   30.18 -     in a product, an acknowledgment in the product documentation would be
   30.19 -     appreciated but is not required.
   30.20 -  2. Altered source versions must be plainly marked as such, and must not be
   30.21 -     misrepresented as being the original software.
   30.22 -  3. This notice may not be removed or altered from any source distribution.
   30.23 -*/
   30.24 -#include "SDL_config.h"
   30.25 -
   30.26 -#include "SDL_lowvideo.h"
   30.27 -
   30.28 -/* Functions to be exported */
   30.29 -extern void BE_FreeWMCursor(_THIS, WMcursor * cursor);
   30.30 -extern WMcursor *BE_CreateWMCursor(_THIS,
   30.31 -                                   Uint8 * data, Uint8 * mask, int w, int h,
   30.32 -                                   int hot_x, int hot_y);
   30.33 -extern int BE_ShowWMCursor(_THIS, WMcursor * cursor);
   30.34 -extern void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
   30.35 -/* vi: set ts=4 sw=4 expandtab: */
    31.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Thu Sep 15 08:21:54 2011 -0700
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,861 +0,0 @@
    31.4 -/*
    31.5 -  Simple DirectMedia Layer
    31.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    31.7 -
    31.8 -  This software is provided 'as-is', without any express or implied
    31.9 -  warranty.  In no event will the authors be held liable for any damages
   31.10 -  arising from the use of this software.
   31.11 -
   31.12 -  Permission is granted to anyone to use this software for any purpose,
   31.13 -  including commercial applications, and to alter it and redistribute it
   31.14 -  freely, subject to the following restrictions:
   31.15 -
   31.16 -  1. The origin of this software must not be misrepresented; you must not
   31.17 -     claim that you wrote the original software. If you use this software
   31.18 -     in a product, an acknowledgment in the product documentation would be
   31.19 -     appreciated but is not required.
   31.20 -  2. Altered source versions must be plainly marked as such, and must not be
   31.21 -     misrepresented as being the original software.
   31.22 -  3. This notice may not be removed or altered from any source distribution.
   31.23 -*/
   31.24 -#include "SDL_config.h"
   31.25 -
   31.26 -/* BWindow based framebuffer implementation */
   31.27 -
   31.28 -#include <unistd.h>
   31.29 -
   31.30 -#include "SDL_BWin.h"
   31.31 -#include "SDL_timer.h"
   31.32 -
   31.33 -extern "C"
   31.34 -{
   31.35 -
   31.36 -#include "../SDL_sysvideo.h"
   31.37 -#include "../../events/SDL_events_c.h"
   31.38 -#include "SDL_sysevents_c.h"
   31.39 -#include "SDL_sysmouse_c.h"
   31.40 -#include "SDL_syswm_c.h"
   31.41 -#include "SDL_lowvideo.h"
   31.42 -#include "../SDL_yuvfuncs.h"
   31.43 -#include "SDL_sysyuv.h"
   31.44 -#include "../blank_cursor.h"
   31.45 -
   31.46 -#define BEOS_HIDDEN_SIZE	32      /* starting hidden window size */
   31.47 -
   31.48 -/* Initialization/Query functions */
   31.49 -    static int BE_VideoInit(_THIS, SDL_PixelFormat * vformat);
   31.50 -    static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format,
   31.51 -                                   Uint32 flags);
   31.52 -    static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current,
   31.53 -                                        int width, int height, int bpp,
   31.54 -                                        Uint32 flags);
   31.55 -    static void BE_UpdateMouse(_THIS);
   31.56 -    static int BE_SetColors(_THIS, int firstcolor, int ncolors,
   31.57 -                            SDL_Color * colors);
   31.58 -    static void BE_VideoQuit(_THIS);
   31.59 -
   31.60 -/* Hardware surface functions */
   31.61 -    static int BE_AllocHWSurface(_THIS, SDL_Surface * surface);
   31.62 -    static int BE_LockHWSurface(_THIS, SDL_Surface * surface);
   31.63 -    static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface);
   31.64 -    static void BE_FreeHWSurface(_THIS, SDL_Surface * surface);
   31.65 -
   31.66 -    static int BE_ToggleFullScreen(_THIS, int fullscreen);
   31.67 -    static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height,
   31.68 -                                            Uint32 format,
   31.69 -                                            SDL_Surface * display);
   31.70 -
   31.71 -/* OpenGL functions */
   31.72 -#if SDL_VIDEO_OPENGL
   31.73 -    static int BE_GL_LoadLibrary(_THIS, const char *path);
   31.74 -    static void *BE_GL_GetProcAddress(_THIS, const char *proc);
   31.75 -    static int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
   31.76 -    static int BE_GL_MakeCurrent(_THIS);
   31.77 -    static void BE_GL_SwapBuffers(_THIS);
   31.78 -#endif
   31.79 -
   31.80 -/* FB driver bootstrap functions */
   31.81 -
   31.82 -    static int BE_Available(void)
   31.83 -    {
   31.84 -        return (1);
   31.85 -    }
   31.86 -
   31.87 -    static void BE_DeleteDevice(SDL_VideoDevice * device)
   31.88 -    {
   31.89 -        SDL_free(device->hidden);
   31.90 -        SDL_free(device);
   31.91 -    }
   31.92 -
   31.93 -    static SDL_VideoDevice *BE_CreateDevice(int devindex)
   31.94 -    {
   31.95 -        SDL_VideoDevice *device;
   31.96 -
   31.97 -        /* Initialize all variables that we clean on shutdown */
   31.98 -        device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
   31.99 -        if (device) {
  31.100 -            SDL_memset(device, 0, (sizeof *device));
  31.101 -            device->hidden = (struct SDL_PrivateVideoData *)
  31.102 -                SDL_malloc((sizeof *device->hidden));
  31.103 -        }
  31.104 -        if ((device == NULL) || (device->hidden == NULL)) {
  31.105 -            SDL_OutOfMemory();
  31.106 -            if (device) {
  31.107 -                SDL_free(device);
  31.108 -            }
  31.109 -            return (0);
  31.110 -        }
  31.111 -        SDL_memset(device->hidden, 0, (sizeof *device->hidden));
  31.112 -
  31.113 -        /* Set the function pointers */
  31.114 -        /* Initialization/Query functions */
  31.115 -        device->VideoInit = BE_VideoInit;
  31.116 -        device->ListModes = BE_ListModes;
  31.117 -        device->SetVideoMode = BE_SetVideoMode;
  31.118 -        device->ToggleFullScreen = BE_ToggleFullScreen;
  31.119 -        device->UpdateMouse = BE_UpdateMouse;
  31.120 -        device->CreateYUVOverlay = BE_CreateYUVOverlay;
  31.121 -        device->SetColors = BE_SetColors;
  31.122 -        device->UpdateRects = NULL;
  31.123 -        device->VideoQuit = BE_VideoQuit;
  31.124 -        /* Hardware acceleration functions */
  31.125 -        device->AllocHWSurface = BE_AllocHWSurface;
  31.126 -        device->CheckHWBlit = NULL;
  31.127 -        device->FillHWRect = NULL;
  31.128 -        device->SetHWColorKey = NULL;
  31.129 -        device->SetHWAlpha = NULL;
  31.130 -        device->LockHWSurface = BE_LockHWSurface;
  31.131 -        device->UnlockHWSurface = BE_UnlockHWSurface;
  31.132 -        device->FlipHWSurface = NULL;
  31.133 -        device->FreeHWSurface = BE_FreeHWSurface;
  31.134 -#if SDL_VIDEO_OPENGL
  31.135 -        /* OpenGL support */
  31.136 -        device->GL_LoadLibrary = BE_GL_LoadLibrary;
  31.137 -        device->GL_GetProcAddress = BE_GL_GetProcAddress;
  31.138 -        device->GL_GetAttribute = BE_GL_GetAttribute;
  31.139 -        device->GL_MakeCurrent = BE_GL_MakeCurrent;
  31.140 -        device->GL_SwapBuffers = BE_GL_SwapBuffers;
  31.141 -#endif
  31.142 -        /* Window manager functions */
  31.143 -        device->SetCaption = BE_SetWMCaption;
  31.144 -        device->SetIcon = NULL;
  31.145 -        device->IconifyWindow = BE_IconifyWindow;
  31.146 -        device->GrabInput = NULL;
  31.147 -        device->GetWMInfo = BE_GetWMInfo;
  31.148 -        /* Cursor manager functions */
  31.149 -        device->FreeWMCursor = BE_FreeWMCursor;
  31.150 -        device->CreateWMCursor = BE_CreateWMCursor;
  31.151 -        device->ShowWMCursor = BE_ShowWMCursor;
  31.152 -        device->WarpWMCursor = BE_WarpWMCursor;
  31.153 -        device->MoveWMCursor = NULL;
  31.154 -        device->CheckMouseMode = NULL;
  31.155 -        /* Event manager functions */
  31.156 -        device->InitOSKeymap = BE_InitOSKeymap;
  31.157 -        device->PumpEvents = BE_PumpEvents;
  31.158 -
  31.159 -        device->free = BE_DeleteDevice;
  31.160 -
  31.161 -        /* Set the driver flags */
  31.162 -        device->handles_any_size = 1;
  31.163 -
  31.164 -        return device;
  31.165 -    }
  31.166 -
  31.167 -    VideoBootStrap BWINDOW_bootstrap = {
  31.168 -        "bwindow", "BDirectWindow graphics",
  31.169 -        BE_Available, BE_CreateDevice
  31.170 -    };
  31.171 -
  31.172 -    static inline int ColorSpaceToBitsPerPixel(uint32 colorspace)
  31.173 -    {
  31.174 -        int bitsperpixel;
  31.175 -
  31.176 -        bitsperpixel = 0;
  31.177 -        switch (colorspace) {
  31.178 -        case B_CMAP8:
  31.179 -            bitsperpixel = 8;
  31.180 -            break;
  31.181 -        case B_RGB15:
  31.182 -        case B_RGBA15:
  31.183 -        case B_RGB15_BIG:
  31.184 -        case B_RGBA15_BIG:
  31.185 -            bitsperpixel = 15;
  31.186 -            break;
  31.187 -        case B_RGB16:
  31.188 -        case B_RGB16_BIG:
  31.189 -            bitsperpixel = 16;
  31.190 -            break;
  31.191 -        case B_RGB32:
  31.192 -        case B_RGBA32:
  31.193 -        case B_RGB32_BIG:
  31.194 -        case B_RGBA32_BIG:
  31.195 -            bitsperpixel = 32;
  31.196 -            break;
  31.197 -        default:
  31.198 -            break;
  31.199 -        }
  31.200 -        return (bitsperpixel);
  31.201 -    }
  31.202 -
  31.203 -/* Function to sort the display_list in bscreen */
  31.204 -    static int CompareModes(const void *A, const void *B)
  31.205 -    {
  31.206 -        const display_mode *a = (display_mode *) A;
  31.207 -        const display_mode *b = (display_mode *) B;
  31.208 -
  31.209 -        if (a->space == b->space) {
  31.210 -            return ((b->virtual_width * b->virtual_height) -
  31.211 -                    (a->virtual_width * a->virtual_height));
  31.212 -        } else {
  31.213 -            return (ColorSpaceToBitsPerPixel(b->space) -
  31.214 -                    ColorSpaceToBitsPerPixel(a->space));
  31.215 -        }
  31.216 -    }
  31.217 -
  31.218 -/* Yes, this isn't the fastest it could be, but it works nicely */
  31.219 -    static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h)
  31.220 -    {
  31.221 -        SDL_Rect *mode;
  31.222 -        int i;
  31.223 -        int next_mode;
  31.224 -
  31.225 -        /* Check to see if we already have this mode */
  31.226 -        if (SDL_nummodes[index] > 0) {
  31.227 -            for (i = SDL_nummodes[index] - 1; i >= 0; --i) {
  31.228 -                mode = SDL_modelist[index][i];
  31.229 -                if ((mode->w == w) && (mode->h == h)) {
  31.230 -#ifdef BWINDOW_DEBUG
  31.231 -                    fprintf(stderr,
  31.232 -                            "We already have mode %dx%d at %d bytes per pixel\n",
  31.233 -                            w, h, index + 1);
  31.234 -#endif
  31.235 -                    return (0);
  31.236 -                }
  31.237 -            }
  31.238 -        }
  31.239 -
  31.240 -        /* Set up the new video mode rectangle */
  31.241 -        mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
  31.242 -        if (mode == NULL) {
  31.243 -            SDL_OutOfMemory();
  31.244 -            return (-1);
  31.245 -        }
  31.246 -        mode->x = 0;
  31.247 -        mode->y = 0;
  31.248 -        mode->w = w;
  31.249 -        mode->h = h;
  31.250 -#ifdef BWINDOW_DEBUG
  31.251 -        fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h,
  31.252 -                index + 1);
  31.253 -#endif
  31.254 -
  31.255 -        /* Allocate the new list of modes, and fill in the new mode */
  31.256 -        next_mode = SDL_nummodes[index];
  31.257 -        SDL_modelist[index] = (SDL_Rect **)
  31.258 -            SDL_realloc(SDL_modelist[index],
  31.259 -                        (1 + next_mode + 1) * sizeof(SDL_Rect *));
  31.260 -        if (SDL_modelist[index] == NULL) {
  31.261 -            SDL_OutOfMemory();
  31.262 -            SDL_nummodes[index] = 0;
  31.263 -            SDL_free(mode);
  31.264 -            return (-1);
  31.265 -        }
  31.266 -        SDL_modelist[index][next_mode] = mode;
  31.267 -        SDL_modelist[index][next_mode + 1] = NULL;
  31.268 -        SDL_nummodes[index]++;
  31.269 -
  31.270 -        return (0);
  31.271 -    }
  31.272 -
  31.273 -    int BE_VideoInit(_THIS, SDL_PixelFormat * vformat)
  31.274 -    {
  31.275 -        display_mode *modes;
  31.276 -        uint32 i, nmodes;
  31.277 -        int bpp;
  31.278 -        BRect bounds;
  31.279 -
  31.280 -        /* Initialize the Be Application for appserver interaction */
  31.281 -        if (SDL_InitBeApp() < 0) {
  31.282 -            return (-1);
  31.283 -        }
  31.284 -
  31.285 -        /* It is important that this be created after SDL_InitBeApp() */
  31.286 -        BScreen bscreen;
  31.287 -
  31.288 -        /* Save the current display mode */
  31.289 -        bscreen.GetMode(&saved_mode);
  31.290 -        _this->info.current_w = saved_mode.virtual_width;
  31.291 -        _this->info.current_h = saved_mode.virtual_height;
  31.292 -
  31.293 -        /* Determine the screen depth */
  31.294 -        vformat->BitsPerPixel =
  31.295 -            ColorSpaceToBitsPerPixel(bscreen.ColorSpace());
  31.296 -        if (vformat->BitsPerPixel == 0) {
  31.297 -            SDL_SetError("Unknown BScreen colorspace: 0x%x",
  31.298 -                         bscreen.ColorSpace());
  31.299 -            return (-1);
  31.300 -        }
  31.301 -
  31.302 -        /* Get the video modes we can switch to in fullscreen mode */
  31.303 -        bscreen.GetModeList(&modes, &nmodes);
  31.304 -        SDL_qsort(modes, nmodes, sizeof *modes, CompareModes);
  31.305 -        for (i = 0; i < nmodes; ++i) {
  31.306 -            bpp = ColorSpaceToBitsPerPixel(modes[i].space);
  31.307 -            //if ( bpp != 0 ) { // There are bugs in changing colorspace
  31.308 -            if (modes[i].space == saved_mode.space) {
  31.309 -                BE_AddMode(_this, ((bpp + 7) / 8) - 1,
  31.310 -                           modes[i].virtual_width, modes[i].virtual_height);
  31.311 -            }
  31.312 -        }
  31.313 -
  31.314 -        /* Create the window and view */
  31.315 -        bounds.top = 0;
  31.316 -        bounds.left = 0;
  31.317 -        bounds.right = BEOS_HIDDEN_SIZE;
  31.318 -        bounds.bottom = BEOS_HIDDEN_SIZE;
  31.319 -        SDL_Win = new SDL_BWin(bounds);
  31.320 -
  31.321 -#if SDL_VIDEO_OPENGL
  31.322 -        /* testgl application doesn't load library, just tries to load symbols */
  31.323 -        /* is it correct? if so we have to load library here */
  31.324 -        BE_GL_LoadLibrary(_this, NULL);
  31.325 -#endif
  31.326 -
  31.327 -        /* Create the clear cursor */
  31.328 -        SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask,
  31.329 -                                            BLANK_CWIDTH, BLANK_CHEIGHT,
  31.330 -                                            BLANK_CHOTX, BLANK_CHOTY);
  31.331 -
  31.332 -        /* Fill in some window manager capabilities */
  31.333 -        _this->info.wm_available = 1;
  31.334 -
  31.335 -        /* We're done! */
  31.336 -        return (0);
  31.337 -    }
  31.338 -
  31.339 -/* We support any dimension at our bit-depth */
  31.340 -    SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
  31.341 -    {
  31.342 -        SDL_Rect **modes;
  31.343 -
  31.344 -        modes = ((SDL_Rect **) 0);
  31.345 -        if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  31.346 -            modes = SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
  31.347 -        } else {
  31.348 -            if (format->BitsPerPixel == _this->screen->format->BitsPerPixel) {
  31.349 -                modes = ((SDL_Rect **) - 1);
  31.350 -            }
  31.351 -        }
  31.352 -        return (modes);
  31.353 -    }
  31.354 -
  31.355 -/* Various screen update functions available */
  31.356 -    static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects);
  31.357 -
  31.358 -
  31.359 -/* Find the closest display mode for fullscreen */
  31.360 -    static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp,
  31.361 -                                     display_mode * mode)
  31.362 -    {
  31.363 -        BScreen bscreen;
  31.364 -        uint32 i, nmodes;
  31.365 -        SDL_Rect **modes;
  31.366 -        display_mode *dmodes;
  31.367 -        display_mode current;
  31.368 -        float current_refresh;
  31.369 -        bscreen.GetMode(&current);
  31.370 -        current_refresh = (1000 * current.timing.pixel_clock) /
  31.371 -            (current.timing.h_total * current.timing.v_total);
  31.372 -
  31.373 -        modes = SDL_modelist[((bpp + 7) / 8) - 1];
  31.374 -
  31.375 -        bool exactmatch = false;
  31.376 -        for (uint32 x = 0; modes[x]; x++) {
  31.377 -            if (modes[x]->w == width && modes[x]->h == height) {
  31.378 -                exactmatch = true;
  31.379 -                i = x;
  31.380 -                break;
  31.381 -            }
  31.382 -        }
  31.383 -        if (!exactmatch) {
  31.384 -            for (i = 0; modes[i] && (modes[i]->w > width) &&
  31.385 -                 (modes[i]->h > height); ++i) {
  31.386 -                /* still looking */
  31.387 -            }
  31.388 -            if (!modes[i] || (modes[i]->w < width) || (modes[i]->h < height)) {
  31.389 -                /* We went too far */
  31.390 -                --i;
  31.391 -            }
  31.392 -        }
  31.393 -        width = modes[i]->w;
  31.394 -        height = modes[i]->h;
  31.395 -        bscreen.GetModeList(&dmodes, &nmodes);
  31.396 -        for (i = 0; i < nmodes; ++i) {
  31.397 -            if ((bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) &&
  31.398 -                (width == dmodes[i].virtual_width) &&
  31.399 -                (height == dmodes[i].virtual_height)) {
  31.400 -                break;
  31.401 -            }
  31.402 -        }
  31.403 -        if (i != nmodes) {
  31.404 -            *mode = dmodes[i];
  31.405 -            if ((mode->virtual_width <= current.virtual_width) &&
  31.406 -                (mode->virtual_height <= current.virtual_height)) {
  31.407 -                float new_refresh = (1000 * mode->timing.pixel_clock) /
  31.408 -                    (mode->timing.h_total * mode->timing.v_total);
  31.409 -                if (new_refresh < current_refresh) {
  31.410 -                    mode->timing.pixel_clock =
  31.411 -                        (uint32) ((mode->timing.h_total *
  31.412 -                                   mode->timing.v_total) *
  31.413 -                                  current_refresh / 1000);
  31.414 -                }
  31.415 -            }
  31.416 -            return true;
  31.417 -        } else {
  31.418 -            return false;
  31.419 -        }
  31.420 -    }
  31.421 -
  31.422 -    static int BE_SetFullScreen(_THIS, SDL_Surface * screen, int fullscreen)
  31.423 -    {
  31.424 -        int was_fullscreen;
  31.425 -        bool needs_unlock;
  31.426 -        BScreen bscreen;
  31.427 -        BRect bounds;
  31.428 -        display_mode mode;
  31.429 -        int width, height, bpp;
  31.430 -
  31.431 -        /* Set the fullscreen mode */
  31.432 -        was_fullscreen = SDL_Win->IsFullScreen();
  31.433 -        SDL_Win->SetFullScreen(fullscreen);
  31.434 -        fullscreen = SDL_Win->IsFullScreen();
  31.435 -
  31.436 -        width = screen->w;
  31.437 -        height = screen->h;
  31.438 -
  31.439 -        /* Set the appropriate video mode */
  31.440 -        if (fullscreen) {
  31.441 -            bpp = screen->format->BitsPerPixel;
  31.442 -            bscreen.GetMode(&mode);
  31.443 -            if ((bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
  31.444 -                (width != mode.virtual_width) ||
  31.445 -                (height != mode.virtual_height)) {
  31.446 -                if (BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
  31.447 -                    bscreen.SetMode(&mode);
  31.448 -                    /* This simply stops the next resize event from being
  31.449 -                     * sent to the SDL handler.
  31.450 -                     */
  31.451 -                    SDL_Win->InhibitResize();
  31.452 -                } else {
  31.453 -                    fullscreen = 0;
  31.454 -                    SDL_Win->SetFullScreen(fullscreen);
  31.455 -                }
  31.456 -            }
  31.457 -        }
  31.458 -        if (was_fullscreen && !fullscreen) {
  31.459 -            bscreen.SetMode(&saved_mode);
  31.460 -        }
  31.461 -
  31.462 -        if (SDL_Win->Lock()) {
  31.463 -            int xoff, yoff;
  31.464 -            if (SDL_Win->Shown()) {
  31.465 -                needs_unlock = 1;
  31.466 -                SDL_Win->Hide();
  31.467 -            } else {
  31.468 -                needs_unlock = 0;
  31.469 -            }
  31.470 -            /* This resizes the window and view area, but inhibits resizing
  31.471 -             * of the BBitmap due to the InhibitResize call above. Thus the
  31.472 -             * bitmap (pixel data) never changes.
  31.473 -             */
  31.474 -            SDL_Win->ResizeTo(width, height);
  31.475 -            bounds = bscreen.Frame();
  31.476 -            /* Calculate offsets - used either to center window
  31.477 -             * (windowed mode) or to set drawing offsets (fullscreen mode)
  31.478 -             */
  31.479 -            xoff = (bounds.IntegerWidth() - width) / 2;
  31.480 -            yoff = (bounds.IntegerHeight() - height) / 2;
  31.481 -            if (fullscreen) {
  31.482 -                /* Set offset for drawing */
  31.483 -                SDL_Win->SetXYOffset(xoff, yoff);
  31.484 -            } else {
  31.485 -                /* Center window and reset the drawing offset */
  31.486 -                SDL_Win->SetXYOffset(0, 0);
  31.487 -            }
  31.488 -            if (!needs_unlock || was_fullscreen) {
  31.489 -                /* Center the window the first time */
  31.490 -                SDL_Win->MoveTo(xoff > 0 ? (float) xoff : 0.0f,
  31.491 -                                yoff > 0 ? (float) yoff : 0.0f);
  31.492 -            }
  31.493 -            SDL_Win->Show();
  31.494 -
  31.495 -            /* Unlock the window manually after the first Show() */
  31.496 -            if (needs_unlock) {
  31.497 -                SDL_Win->Unlock();
  31.498 -            }
  31.499 -        }
  31.500 -
  31.501 -        /* Set the fullscreen flag in the screen surface */
  31.502 -        if (fullscreen) {
  31.503 -            screen->flags |= SDL_FULLSCREEN;
  31.504 -        } else {
  31.505 -            screen->flags &= ~SDL_FULLSCREEN;
  31.506 -        }
  31.507 -        return (1);
  31.508 -    }
  31.509 -
  31.510 -    static int BE_ToggleFullScreen(_THIS, int fullscreen)
  31.511 -    {
  31.512 -        return BE_SetFullScreen(_this, _this->screen, fullscreen);
  31.513 -    }
  31.514 -
  31.515 -/* FIXME: check return values and cleanup here */
  31.516 -    SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current,
  31.517 -                                 int width, int height, int bpp, Uint32 flags)
  31.518 -    {
  31.519 -        BScreen bscreen;
  31.520 -        BBitmap *bbitmap;
  31.521 -        BRect bounds;
  31.522 -        Uint32 gl_flags = 0;
  31.523 -
  31.524 -        /* Only RGB works on r5 currently */
  31.525 -        gl_flags = BGL_RGB;
  31.526 -        if (_this->gl_config.double_buffer)
  31.527 -            gl_flags |= BGL_DOUBLE;
  31.528 -        else
  31.529 -            gl_flags |= BGL_SINGLE;
  31.530 -        if (_this->gl_config.alpha_size > 0 || bpp == 32)
  31.531 -            gl_flags |= BGL_ALPHA;
  31.532 -        if (_this->gl_config.depth_size > 0)
  31.533 -            gl_flags |= BGL_DEPTH;
  31.534 -        if (_this->gl_config.stencil_size > 0)
  31.535 -            gl_flags |= BGL_STENCIL;
  31.536 -        if (_this->gl_config.accum_red_size > 0
  31.537 -            || _this->gl_config.accum_green_size > 0
  31.538 -            || _this->gl_config.accum_blue_size > 0
  31.539 -            || _this->gl_config.accum_alpha_size > 0)
  31.540 -            gl_flags |= BGL_ACCUM;
  31.541 -
  31.542 -        /* Create the view for this window, using found flags */
  31.543 -        if (SDL_Win->CreateView(flags, gl_flags) < 0) {
  31.544 -            return (NULL);
  31.545 -        }
  31.546 -
  31.547 -        current->flags = 0;     /* Clear flags */
  31.548 -        current->w = width;
  31.549 -        current->h = height;
  31.550 -        SDL_Win->SetType(B_TITLED_WINDOW);
  31.551 -        if (flags & SDL_NOFRAME) {
  31.552 -            current->flags |= SDL_NOFRAME;
  31.553 -            SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK);
  31.554 -        } else {
  31.555 -            if ((flags & SDL_RESIZABLE) && !(flags & SDL_INTERNALOPENGL)) {
  31.556 -                current->flags |= SDL_RESIZABLE;
  31.557 -                /* We don't want opaque resizing (TM). :-) */
  31.558 -                SDL_Win->SetFlags(B_OUTLINE_RESIZE);
  31.559 -            } else {
  31.560 -                SDL_Win->SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
  31.561 -            }
  31.562 -        }
  31.563 -
  31.564 -        if (flags & SDL_INTERNALOPENGL) {
  31.565 -            current->flags |= SDL_INTERNALOPENGL;
  31.566 -            current->pitch = 0;
  31.567 -            current->pixels = NULL;
  31.568 -            _this->UpdateRects = NULL;
  31.569 -        } else {
  31.570 -            /* Create the BBitmap framebuffer */
  31.571 -            bounds.top = 0;
  31.572 -            bounds.left = 0;
  31.573 -            bounds.right = width - 1;
  31.574 -            bounds.bottom = height - 1;
  31.575 -            bbitmap = new BBitmap(bounds, bscreen.ColorSpace());
  31.576 -            if (!bbitmap->IsValid()) {
  31.577 -                SDL_SetError("Couldn't create screen bitmap");
  31.578 -                delete bbitmap;
  31.579 -                return (NULL);
  31.580 -            }
  31.581 -            current->pitch = bbitmap->BytesPerRow();
  31.582 -            current->pixels = (void *) bbitmap->Bits();
  31.583 -            SDL_Win->SetBitmap(bbitmap);
  31.584 -            _this->UpdateRects = BE_NormalUpdate;
  31.585 -        }
  31.586 -
  31.587 -        /* Set the correct fullscreen mode */
  31.588 -        BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0);
  31.589 -
  31.590 -        /* We're done */
  31.591 -        return (current);
  31.592 -    }
  31.593 -
  31.594 -/* Update the current mouse state and position */
  31.595 -    void BE_UpdateMouse(_THIS)
  31.596 -    {
  31.597 -        BPoint point;
  31.598 -        uint32 buttons;
  31.599 -
  31.600 -        if (SDL_Win->Lock()) {
  31.601 -            /* Get new input state, if still active */
  31.602 -            if (SDL_Win->IsActive()) {
  31.603 -                (SDL_Win->View())->GetMouse(&point, &buttons, true);
  31.604 -            } else {
  31.605 -                point.x = -1;
  31.606 -                point.y = -1;
  31.607 -            }
  31.608 -            SDL_Win->Unlock();
  31.609 -
  31.610 -            if ((point.x >= 0) && (point.x < SDL_VideoSurface->w) &&
  31.611 -                (point.y >= 0) && (point.y < SDL_VideoSurface->h)) {
  31.612 -                SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
  31.613 -                SDL_PrivateMouseMotion(0, 0,
  31.614 -                                       (Sint16) point.x, (Sint16) point.y);
  31.615 -            } else {
  31.616 -                SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
  31.617 -            }
  31.618 -        }
  31.619 -    }
  31.620 -
  31.621 -/* We don't actually allow hardware surfaces other than the main one */
  31.622 -    static int BE_AllocHWSurface(_THIS, SDL_Surface * surface)
  31.623 -    {
  31.624 -        return (-1);
  31.625 -    }
  31.626 -    static void BE_FreeHWSurface(_THIS, SDL_Surface * surface)
  31.627 -    {
  31.628 -        return;
  31.629 -    }
  31.630 -    static int BE_LockHWSurface(_THIS, SDL_Surface * surface)
  31.631 -    {
  31.632 -        return (0);
  31.633 -    }
  31.634 -    static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface)
  31.635 -    {
  31.636 -        return;
  31.637 -    }
  31.638 -
  31.639 -    static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
  31.640 -    {
  31.641 -        if (SDL_Win->BeginDraw()) {
  31.642 -            int i;
  31.643 -
  31.644 -            for (i = 0; i < numrects; ++i) {
  31.645 -                BRect rect;
  31.646 -
  31.647 -                rect.top = rects[i].y;
  31.648 -                rect.left = rects[i].x;
  31.649 -                rect.bottom = rect.top + rects[i].h - 1;
  31.650 -                rect.right = rect.left + rects[i].w - 1;
  31.651 -                SDL_Win->DrawAsync(rect);
  31.652 -            }
  31.653 -            SDL_Win->EndDraw();
  31.654 -        }
  31.655 -    }
  31.656 -
  31.657 -#if SDL_VIDEO_OPENGL
  31.658 -/* Passing a NULL path means load pointers from the application */
  31.659 -    int BE_GL_LoadLibrary(_THIS, const char *path)
  31.660 -    {
  31.661 -        if (path == NULL) {
  31.662 -            if (_this->gl_config.dll_handle == NULL) {
  31.663 -                image_info info;
  31.664 -                int32 cookie = 0;
  31.665 -                while (get_next_image_info(0, &cookie, &info) == B_OK) {
  31.666 -                    void *location = NULL;
  31.667 -                    if (get_image_symbol
  31.668 -                        ((image_id) cookie, "glBegin",
  31.669 -                         B_SYMBOL_TYPE_ANY, &location) == B_OK) {
  31.670 -                        _this->gl_config.dll_handle = (void *) cookie;
  31.671 -                        _this->gl_config.driver_loaded = 1;
  31.672 -                        SDL_strlcpy(_this->gl_config.driver_path,
  31.673 -                                    "libGL.so",
  31.674 -                                    SDL_arraysize(_this->
  31.675 -                                                  gl_config.driver_path));
  31.676 -                    }
  31.677 -                }
  31.678 -            }
  31.679 -        } else {
  31.680 -            /*
  31.681 -               FIXME None of BeOS libGL.so implementations have exported functions 
  31.682 -               to load BGLView, which should be reloaded from new lib.
  31.683 -               So for now just "load" linked libGL.so :(
  31.684 -             */
  31.685 -            if (_this->gl_config.dll_handle == NULL) {
  31.686 -                return BE_GL_LoadLibrary(_this, NULL);
  31.687 -            }
  31.688 -
  31.689 -            /* Unload old first */
  31.690 -            /*if (_this->gl_config.dll_handle != NULL) { */
  31.691 -            /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */
  31.692 -            /*      image_info info;
  31.693 -               if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) {
  31.694 -               if (info.type != B_APP_IMAGE) {
  31.695 -               unload_add_on((image_id)_this->gl_config.dll_handle);
  31.696 -               }
  31.697 -               }
  31.698 -
  31.699 -               }
  31.700 -
  31.701 -               if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
  31.702 -               _this->gl_config.driver_loaded = 1;
  31.703 -               SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
  31.704 -               } */
  31.705 -        }
  31.706 -
  31.707 -        if (_this->gl_config.dll_handle != NULL) {
  31.708 -            return 0;
  31.709 -        } else {
  31.710 -            _this->gl_config.dll_handle = NULL;
  31.711 -            _this->gl_config.driver_loaded = 0;
  31.712 -            *_this->gl_config.driver_path = '\0';
  31.713 -            return -1;
  31.714 -        }
  31.715 -    }
  31.716 -
  31.717 -    void *BE_GL_GetProcAddress(_THIS, const char *proc)
  31.718 -    {
  31.719 -        if (_this->gl_config.dll_handle != NULL) {
  31.720 -            void *location = NULL;
  31.721 -            status_t err;
  31.722 -            if ((err =
  31.723 -                 get_image_symbol((image_id) _this->gl_config.dll_handle,
  31.724 -                                  proc, B_SYMBOL_TYPE_ANY,
  31.725 -                                  &location)) == B_OK) {
  31.726 -                return location;
  31.727 -            } else {
  31.728 -                SDL_SetError("Couldn't find OpenGL symbol");
  31.729 -                return NULL;
  31.730 -            }
  31.731 -        } else {
  31.732 -            SDL_SetError("OpenGL library not loaded");
  31.733 -            return NULL;
  31.734 -        }
  31.735 -    }
  31.736 -
  31.737 -    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
  31.738 -    {
  31.739 -        /*
  31.740 -           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
  31.741 -         */
  31.742 -        switch (attrib) {
  31.743 -        case SDL_GL_RED_SIZE:
  31.744 -            glGetIntegerv(GL_RED_BITS, (GLint *) value);
  31.745 -            break;
  31.746 -        case SDL_GL_GREEN_SIZE:
  31.747 -            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
  31.748 -            break;
  31.749 -        case SDL_GL_BLUE_SIZE:
  31.750 -            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
  31.751 -            break;
  31.752 -        case SDL_GL_ALPHA_SIZE:
  31.753 -            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
  31.754 -            break;
  31.755 -        case SDL_GL_DOUBLEBUFFER:
  31.756 -            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
  31.757 -            break;
  31.758 -        case SDL_GL_BUFFER_SIZE:
  31.759 -            int v;
  31.760 -            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
  31.761 -            *value = v;
  31.762 -            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
  31.763 -            *value += v;
  31.764 -            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
  31.765 -            *value += v;
  31.766 -            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
  31.767 -            *value += v;
  31.768 -            break;
  31.769 -        case SDL_GL_DEPTH_SIZE:
  31.770 -            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
  31.771 -            break;
  31.772 -        case SDL_GL_STENCIL_SIZE:
  31.773 -            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
  31.774 -            break;
  31.775 -        case SDL_GL_ACCUM_RED_SIZE:
  31.776 -            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
  31.777 -            break;
  31.778 -        case SDL_GL_ACCUM_GREEN_SIZE:
  31.779 -            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
  31.780 -            break;
  31.781 -        case SDL_GL_ACCUM_BLUE_SIZE:
  31.782 -            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
  31.783 -            break;
  31.784 -        case SDL_GL_ACCUM_ALPHA_SIZE:
  31.785 -            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
  31.786 -            break;
  31.787 -        case SDL_GL_STEREO:
  31.788 -        case SDL_GL_MULTISAMPLEBUFFERS:
  31.789 -        case SDL_GL_MULTISAMPLESAMPLES:
  31.790 -        default:
  31.791 -            *value = 0;
  31.792 -            return (-1);
  31.793 -        }
  31.794 -        return 0;
  31.795 -    }
  31.796 -
  31.797 -    int BE_GL_MakeCurrent(_THIS)
  31.798 -    {
  31.799 -        /* FIXME: should we glview->unlock and then glview->lock()? */
  31.800 -        return 0;
  31.801 -    }
  31.802 -
  31.803 -    void BE_GL_SwapBuffers(_THIS)
  31.804 -    {
  31.805 -        SDL_Win->SwapBuffers();
  31.806 -    }
  31.807 -#endif
  31.808 -
  31.809 -/* Is the system palette settable? */
  31.810 -    int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
  31.811 -    {
  31.812 -        int i;
  31.813 -        SDL_Palette *palette;
  31.814 -        const color_map *cmap = BScreen().ColorMap();
  31.815 -
  31.816 -        /* Get the screen colormap */
  31.817 -        palette = _this->screen->format->palette;
  31.818 -        for (i = 0; i < 256; ++i) {
  31.819 -            palette->colors[i].r = cmap->color_list[i].red;
  31.820 -            palette->colors[i].g = cmap->color_list[i].green;
  31.821 -            palette->colors[i].b = cmap->color_list[i].blue;
  31.822 -        }
  31.823 -        return (0);
  31.824 -    }
  31.825 -
  31.826 -    void BE_VideoQuit(_THIS)
  31.827 -    {
  31.828 -        int i, j;
  31.829 -
  31.830 -        SDL_Win->Quit();
  31.831 -        SDL_Win = NULL;
  31.832 -
  31.833 -        if (SDL_BlankCursor != NULL) {
  31.834 -            BE_FreeWMCursor(_this, SDL_BlankCursor);
  31.835 -            SDL_BlankCursor = NULL;
  31.836 -        }
  31.837 -        for (i = 0; i < NUM_MODELISTS; ++i) {
  31.838 -            if (SDL_modelist[i]) {
  31.839 -                for (j = 0; SDL_modelist[i][j]; ++j) {
  31.840 -                    SDL_free(SDL_modelist[i][j]);
  31.841 -                }
  31.842 -                SDL_free(SDL_modelist[i]);
  31.843 -                SDL_modelist[i] = NULL;
  31.844 -            }
  31.845 -        }
  31.846 -        /* Restore the original video mode */
  31.847 -        if (_this->screen) {
  31.848 -            if ((_this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  31.849 -                BScreen bscreen;
  31.850 -                bscreen.SetMode(&saved_mode);
  31.851 -            }
  31.852 -            _this->screen->pixels = NULL;
  31.853 -        }
  31.854 -#if SDL_VIDEO_OPENGL
  31.855 -        if (_this->gl_config.dll_handle != NULL)
  31.856 -            unload_add_on((image_id) _this->gl_config.dll_handle);
  31.857 -#endif
  31.858 -
  31.859 -        SDL_QuitBeApp();
  31.860 -    }
  31.861 -
  31.862 -};                              /* Extern C */
  31.863 -
  31.864 -/* vi: set ts=4 sw=4 expandtab: */
    32.1 --- a/src/video/bwindow/SDL_syswm.cc	Thu Sep 15 08:21:54 2011 -0700
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,54 +0,0 @@
    32.4 -/*
    32.5 -  Simple DirectMedia Layer
    32.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    32.7 -
    32.8 -  This software is provided 'as-is', without any express or implied
    32.9 -  warranty.  In no event will the authors be held liable for any damages
   32.10 -  arising from the use of this software.
   32.11 -
   32.12 -  Permission is granted to anyone to use this software for any purpose,
   32.13 -  including commercial applications, and to alter it and redistribute it
   32.14 -  freely, subject to the following restrictions:
   32.15 -
   32.16 -  1. The origin of this software must not be misrepresented; you must not
   32.17 -     claim that you wrote the original software. If you use this software
   32.18 -     in a product, an acknowledgment in the product documentation would be
   32.19 -     appreciated but is not required.
   32.20 -  2. Altered source versions must be plainly marked as such, and must not be
   32.21 -     misrepresented as being the original software.
   32.22 -  3. This notice may not be removed or altered from any source distribution.
   32.23 -*/
   32.24 -#include "SDL_config.h"
   32.25 -
   32.26 -#include "SDL_BWin.h"
   32.27 -
   32.28 -extern "C"
   32.29 -{
   32.30 -
   32.31 -#include "SDL_syswm_c.h"
   32.32 -#include "SDL_error.h"
   32.33 -
   32.34 -    void BE_SetWMCaption(_THIS, const char *title, const char *icon)
   32.35 -    {
   32.36 -        SDL_Win->SetTitle(title);
   32.37 -    }
   32.38 -
   32.39 -    int BE_IconifyWindow(_THIS)
   32.40 -    {
   32.41 -        SDL_Win->Minimize(true);
   32.42 -    }
   32.43 -
   32.44 -    int BE_GetWMInfo(_THIS, SDL_SysWMinfo * info)
   32.45 -    {
   32.46 -        if (info->version.major <= SDL_MAJOR_VERSION) {
   32.47 -            return 1;
   32.48 -        } else {
   32.49 -            SDL_SetError("Application not compiled with SDL %d.%d\n",
   32.50 -                         SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   32.51 -            return -1;
   32.52 -        }
   32.53 -    }
   32.54 -
   32.55 -};                              /* Extern C */
   32.56 -
   32.57 -/* vi: set ts=4 sw=4 expandtab: */
    33.1 --- a/src/video/bwindow/SDL_syswm_c.h	Thu Sep 15 08:21:54 2011 -0700
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,31 +0,0 @@
    33.4 -/*
    33.5 -  Simple DirectMedia Layer
    33.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    33.7 -
    33.8 -  This software is provided 'as-is', without any express or implied
    33.9 -  warranty.  In no event will the authors be held liable for any damages
   33.10 -  arising from the use of this software.
   33.11 -
   33.12 -  Permission is granted to anyone to use this software for any purpose,
   33.13 -  including commercial applications, and to alter it and redistribute it
   33.14 -  freely, subject to the following restrictions:
   33.15 -
   33.16 -  1. The origin of this software must not be misrepresented; you must not
   33.17 -     claim that you wrote the original software. If you use this software
   33.18 -     in a product, an acknowledgment in the product documentation would be
   33.19 -     appreciated but is not required.
   33.20 -  2. Altered source versions must be plainly marked as such, and must not be
   33.21 -     misrepresented as being the original software.
   33.22 -  3. This notice may not be removed or altered from any source distribution.
   33.23 -*/
   33.24 -#include "SDL_config.h"
   33.25 -
   33.26 -#include "SDL_syswm.h"
   33.27 -#include "SDL_lowvideo.h"
   33.28 -
   33.29 -
   33.30 -/* Functions to be exported */
   33.31 -extern void BE_SetWMCaption(_THIS, const char *title, const char *icon);
   33.32 -extern int BE_IconifyWindow(_THIS);
   33.33 -extern int BE_GetWMInfo(_THIS, SDL_SysWMinfo * info);
   33.34 -/* vi: set ts=4 sw=4 expandtab: */
    34.1 --- a/src/video/bwindow/SDL_sysyuv.cc	Thu Sep 15 08:21:54 2011 -0700
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,321 +0,0 @@
    34.4 -/*
    34.5 -  Simple DirectMedia Layer
    34.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    34.7 -
    34.8 -  This software is provided 'as-is', without any express or implied
    34.9 -  warranty.  In no event will the authors be held liable for any damages
   34.10 -  arising from the use of this software.
   34.11 -
   34.12 -  Permission is granted to anyone to use this software for any purpose,
   34.13 -  including commercial applications, and to alter it and redistribute it
   34.14 -  freely, subject to the following restrictions:
   34.15 -
   34.16 -  1. The origin of this software must not be misrepresented; you must not
   34.17 -     claim that you wrote the original software. If you use this software
   34.18 -     in a product, an acknowledgment in the product documentation would be
   34.19 -     appreciated but is not required.
   34.20 -  2. Altered source versions must be plainly marked as such, and must not be
   34.21 -     misrepresented as being the original software.
   34.22 -  3. This notice may not be removed or altered from any source distribution.
   34.23 -*/
   34.24 -#include "SDL_config.h"
   34.25 -
   34.26 -/* This is the BeOS version of SDL YUV video overlays */
   34.27 -
   34.28 -#include "SDL_video.h"
   34.29 -#include "SDL_sysyuv.h"
   34.30 -#include "../SDL_yuvfuncs.h"
   34.31 -
   34.32 -extern "C"
   34.33 -{
   34.34 -
   34.35 -/* The functions used to manipulate software video overlays */
   34.36 -    static struct private_yuvhwfuncs be_yuvfuncs = {
   34.37 -        BE_LockYUVOverlay,
   34.38 -        BE_UnlockYUVOverlay,
   34.39 -        BE_DisplayYUVOverlay,
   34.40 -        BE_FreeYUVOverlay
   34.41 -    };
   34.42 -
   34.43 -    BBitmap *BE_GetOverlayBitmap(BRect bounds, color_space cs)
   34.44 -    {
   34.45 -        BBitmap *bbitmap;
   34.46 -        bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs);
   34.47 -        if (!bbitmap || bbitmap->InitCheck() != B_OK) {
   34.48 -            delete bbitmap;
   34.49 -            return 0;
   34.50 -        }
   34.51 -        overlay_restrictions r;
   34.52 -        bbitmap->GetOverlayRestrictions(&r);
   34.53 -        uint32 width = bounds.IntegerWidth() + 1;
   34.54 -        uint32 height = bounds.IntegerHeight() + 1;
   34.55 -        uint32 width_padding = 0;
   34.56 -        uint32 height_padding = 0;
   34.57 -        if ((r.source.horizontal_alignment != 0) ||
   34.58 -            (r.source.vertical_alignment != 0)) {
   34.59 -            delete bbitmap;
   34.60 -            return 0;
   34.61 -        }
   34.62 -        if (r.source.width_alignment != 0) {
   34.63 -            uint32 aligned_width = r.source.width_alignment + 1;
   34.64 -            if (width % aligned_width > 0) {
   34.65 -                width_padding = aligned_width - width % aligned_width;
   34.66 -            }
   34.67 -        }
   34.68 -        if (r.source.height_alignment != 0) {
   34.69 -            uint32 aligned_height = r.source.height_alignment + 1;
   34.70 -            if (height % aligned_height > 0) {
   34.71 -                fprintf(stderr, "GetOverlayBitmap failed height alignment\n");
   34.72 -                fprintf(stderr, "- height = %lu, aligned_height = %lu\n",
   34.73 -                        height, aligned_height);
   34.74 -                delete bbitmap;
   34.75 -                return 0;
   34.76 -            }
   34.77 -        }
   34.78 -        if ((r.source.min_width > width) ||
   34.79 -            (r.source.min_height > height) ||
   34.80 -            (r.source.max_width < width) || (r.source.max_height < height)) {
   34.81 -            fprintf(stderr, "GetOverlayBitmap failed bounds tests\n");
   34.82 -            delete bbitmap;
   34.83 -            return 0;
   34.84 -        }
   34.85 -        if ((width_padding != 0) || (height_padding != 0)) {
   34.86 -            delete bbitmap;
   34.87 -            bounds.Set(bounds.left, bounds.top,
   34.88 -                       bounds.right + width_padding,
   34.89 -                       bounds.bottom + height_padding);
   34.90 -            bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs);
   34.91 -            if (!bbitmap || bbitmap->InitCheck() != B_OK) {
   34.92 -                fprintf(stderr, "GetOverlayBitmap failed late\n");
   34.93 -                delete bbitmap;
   34.94 -                return 0;
   34.95 -            }
   34.96 -        }
   34.97 -        return bbitmap;
   34.98 -    }
   34.99 -
  34.100 -// See <GraphicsDefs.h> [btw: Cb=U, Cr=V]
  34.101 -// See also http://www.fourcc.org/indexyuv.htm
  34.102 -    enum color_space convert_color_space(Uint32 format)
  34.103 -    {
  34.104 -        switch (format) {
  34.105 -        case SDL_YV12_OVERLAY:
  34.106 -            return B_YUV9;
  34.107 -        case SDL_IYUV_OVERLAY:
  34.108 -            return B_YUV12;
  34.109 -        case SDL_YUY2_OVERLAY:
  34.110 -            return B_YCbCr422;
  34.111 -        case SDL_UYVY_OVERLAY:
  34.112 -            return B_YUV422;
  34.113 -        case SDL_YVYU_OVERLAY: // not supported on beos?
  34.114 -            return B_NO_COLOR_SPACE;
  34.115 -        default:
  34.116 -            return B_NO_COLOR_SPACE;
  34.117 -        }
  34.118 -    }
  34.119 -
  34.120 -// See SDL_video.h
  34.121 -    int count_planes(Uint32 format)
  34.122 -    {
  34.123 -        switch (format) {
  34.124 -        case SDL_YV12_OVERLAY:
  34.125 -        case SDL_IYUV_OVERLAY:
  34.126 -            return 3;
  34.127 -        case SDL_YUY2_OVERLAY:
  34.128 -        case SDL_UYVY_OVERLAY:
  34.129 -        case SDL_YVYU_OVERLAY:
  34.130 -            return 1;
  34.131 -        default:
  34.132 -            return 0;
  34.133 -        }
  34.134 -    }
  34.135 -
  34.136 -    SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height,
  34.137 -                                     Uint32 format, SDL_Surface * display)
  34.138 -    {
  34.139 -        SDL_Overlay *overlay;
  34.140 -        struct private_yuvhwdata *hwdata;
  34.141 -        BBitmap *bbitmap;
  34.142 -        int planes;
  34.143 -        BRect bounds;
  34.144 -        color_space cs;
  34.145 -
  34.146 -        /* find the appropriate BeOS colorspace descriptor */
  34.147 -        cs = convert_color_space(format);
  34.148 -        if (cs == B_NO_COLOR_SPACE) {
  34.149 -            return NULL;
  34.150 -        }
  34.151 -
  34.152 -        /* count planes */
  34.153 -        planes = count_planes(format);
  34.154 -        if (planes == 0) {
  34.155 -            return NULL;
  34.156 -        }
  34.157 -        /* TODO: figure out planar modes, if anyone cares */
  34.158 -        if (planes == 3) {
  34.159 -            return NULL;
  34.160 -        }
  34.161 -
  34.162 -        /* Create the overlay structure */
  34.163 -        overlay = (SDL_Overlay *) SDL_calloc(1, sizeof(SDL_Overlay));
  34.164 -
  34.165 -        if (overlay == NULL) {
  34.166 -            SDL_OutOfMemory();
  34.167 -            return NULL;
  34.168 -        }
  34.169 -
  34.170 -        /* Fill in the basic members */
  34.171 -        overlay->format = format;
  34.172 -        overlay->w = width;
  34.173 -        overlay->h = height;
  34.174 -        overlay->hwdata = NULL;
  34.175 -
  34.176 -        /* Set up the YUV surface function structure */
  34.177 -        overlay->hwfuncs = &be_yuvfuncs;
  34.178 -
  34.179 -        /* Create the pixel data and lookup tables */
  34.180 -        hwdata =
  34.181 -            (struct private_yuvhwdata *) SDL_calloc(1,
  34.182 -                                                    sizeof(struct
  34.183 -                                                           private_yuvhwdata));
  34.184 -
  34.185 -        if (hwdata == NULL) {
  34.186 -            SDL_OutOfMemory();
  34.187 -            SDL_FreeYUVOverlay(overlay);
  34.188 -            return NULL;
  34.189 -        }
  34.190 -
  34.191 -        overlay->hwdata = hwdata;
  34.192 -        overlay->hwdata->display = display;
  34.193 -        overlay->hwdata->bview = NULL;
  34.194 -        overlay->hwdata->bbitmap = NULL;
  34.195 -        overlay->hwdata->locked = 0;
  34.196 -
  34.197 -        /* Create the BBitmap framebuffer */
  34.198 -        bounds.top = 0;
  34.199 -        bounds.left = 0;
  34.200 -        bounds.right = width - 1;
  34.201 -        bounds.bottom = height - 1;
  34.202 -
  34.203 -        BView *bview =
  34.204 -            new BView(bounds, "overlay", B_FOLLOW_NONE, B_WILL_DRAW);
  34.205 -        if (!bview) {
  34.206 -            SDL_OutOfMemory();
  34.207 -            SDL_FreeYUVOverlay(overlay);
  34.208 -            return NULL;
  34.209 -        }
  34.210 -        overlay->hwdata->bview = bview;
  34.211 -        overlay->hwdata->first_display = true;
  34.212 -        bview->Hide();
  34.213 -
  34.214 -        bbitmap = BE_GetOverlayBitmap(bounds, cs);
  34.215 -        if (!bbitmap) {
  34.216 -            overlay->hwdata->bbitmap = NULL;
  34.217 -            SDL_FreeYUVOverlay(overlay);
  34.218 -            return NULL;
  34.219 -        }
  34.220 -        overlay->hwdata->bbitmap = bbitmap;
  34.221 -
  34.222 -        overlay->planes = planes;
  34.223 -        overlay->pitches =
  34.224 -            (Uint16 *) SDL_calloc(overlay->planes, sizeof(Uint16));
  34.225 -        overlay->pixels =
  34.226 -            (Uint8 **) SDL_calloc(overlay->planes, sizeof(Uint8 *));
  34.227 -        if (!overlay->pitches || !overlay->pixels) {
  34.228 -            SDL_OutOfMemory();
  34.229 -            SDL_FreeYUVOverlay(overlay);
  34.230 -            return (NULL);
  34.231 -        }
  34.232 -
  34.233 -        overlay->pitches[0] = bbitmap->BytesPerRow();
  34.234 -        overlay->pixels[0] = (Uint8 *) bbitmap->Bits();
  34.235 -        overlay->hw_overlay = 1;
  34.236 -
  34.237 -        if (SDL_Win->LockWithTimeout(1000000) != B_OK) {
  34.238 -            SDL_FreeYUVOverlay(overlay);
  34.239 -            return (NULL);
  34.240 -        }
  34.241 -        BView *view = SDL_Win->View();
  34.242 -        view->AddChild(bview);
  34.243 -        rgb_color key;
  34.244 -        bview->SetViewOverlay(bbitmap, bounds, bview->Bounds(), &key,
  34.245 -                              B_FOLLOW_ALL,
  34.246 -                              B_OVERLAY_FILTER_HORIZONTAL |
  34.247 -                              B_OVERLAY_FILTER_VERTICAL);
  34.248 -        bview->SetViewColor(key);
  34.249 -        bview->Flush();
  34.250 -        SDL_Win->Unlock();
  34.251 -
  34.252 -        current_overlay = overlay;
  34.253 -
  34.254 -        return overlay;
  34.255 -    }
  34.256 -
  34.257 -    int BE_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
  34.258 -    {
  34.259 -        if (overlay == NULL) {
  34.260 -            return 0;
  34.261 -        }
  34.262 -
  34.263 -        overlay->hwdata->locked = 1;
  34.264 -        return 0;
  34.265 -    }
  34.266 -
  34.267 -    void BE_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
  34.268 -    {
  34.269 -        if (overlay == NULL) {
  34.270 -            return;
  34.271 -        }
  34.272 -
  34.273 -        overlay->hwdata->locked = 0;
  34.274 -    }
  34.275 -
  34.276 -    int BE_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
  34.277 -                             SDL_Rect * dst)
  34.278 -    {
  34.279 -        if ((overlay == NULL) || (overlay->hwdata == NULL)
  34.280 -            || (overlay->hwdata->bview == NULL) || (SDL_Win->View() == NULL)) {
  34.281 -            return -1;
  34.282 -        }
  34.283 -        if (SDL_Win->LockWithTimeout(50000) != B_OK) {
  34.284 -            return 0;
  34.285 -        }
  34.286 -        BView *bview = overlay->hwdata->bview;
  34.287 -        if (SDL_Win->IsFullScreen()) {
  34.288 -            int left, top;
  34.289 -            SDL_Win->GetXYOffset(left, top);
  34.290 -            bview->MoveTo(left + dst->x, top + dst->y);
  34.291 -        } else {
  34.292 -            bview->MoveTo(dst->x, dst->y);
  34.293 -        }
  34.294 -        bview->ResizeTo(dst->w, dst->h);
  34.295 -        bview->Flush();
  34.296 -        if (overlay->hwdata->first_display) {
  34.297 -            bview->Show();
  34.298 -            overlay->hwdata->first_display = false;
  34.299 -        }
  34.300 -        SDL_Win->Unlock();
  34.301 -
  34.302 -        return 0;
  34.303 -    }
  34.304 -
  34.305 -    void BE_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
  34.306 -    {
  34.307 -        if (overlay == NULL) {
  34.308 -            return;
  34.309 -        }
  34.310 -
  34.311 -        if (overlay->hwdata == NULL) {
  34.312 -            return;
  34.313 -        }
  34.314 -
  34.315 -        current_overlay = NULL;
  34.316 -
  34.317 -        delete overlay->hwdata->bbitmap;
  34.318 -
  34.319 -        SDL_free(overlay->hwdata);
  34.320 -    }
  34.321 -
  34.322 -};                              // extern "C"
  34.323 -
  34.324 -/* vi: set ts=4 sw=4 expandtab: */
    35.1 --- a/src/video/bwindow/SDL_sysyuv.h	Thu Sep 15 08:21:54 2011 -0700
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,77 +0,0 @@
    35.4 -/*
    35.5 -  Simple DirectMedia Layer
    35.6 -  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    35.7 -
    35.8 -  This software is provided 'as-is', without any express or implied
    35.9 -  warranty.  In no event will the authors be held liable for any damages
   35.10 -  arising from the use of this software.
   35.11 -
   35.12 -  Permission is granted to anyone to use this software for any purpose,
   35.13 -  including commercial applications, and to alter it and redistribute it
   35.14 -  freely, subject to the following restrictions:
   35.15 -
   35.16 -  1. The origin of this software must not be misrepresented; you must not
   35.17 -     claim that you wrote the original software. If you use this software
   35.18 -     in a product, an acknowledgment in the product documentation would be
   35.19 -     appreciated but is not required.
   35.20 -  2. Altered source versions must be plainly marked as such, and must not be
   35.21 -     misrepresented as being the original software.
   35.22 -  3. This notice may not be removed or altered from any source distribution.
   35.23 -*/
   35.24 -#include "SDL_config.h"
   35.25 -
   35.26 -
   35.27 -#ifndef __SDL_SYS_YUV_H__
   35.28 -#define __SDL_SYS_YUV_H__
   35.29 -
   35.30 -/* This is the BeOS implementation of YUV video overlays */
   35.31 -
   35.32 -#include "SDL_video.h"
   35.33 -#include "SDL_lowvideo.h"
   35.34 -
   35.35 -extern "C"
   35.36 -{
   35.37 -
   35.38 -    struct private_yuvhwdata
   35.39 -    {
   35.40 -/*  FRAMEDATA* CurrentFrameData;
   35.41 -    FRAMEDATA* FrameData0;
   35.42 -    FRAMEDATA* FrameData1;
   35.43 -    PgScalerProps_t   props;
   35.44 -    PgScalerCaps_t    caps;
   35.45 -    PgVideoChannel_t* channel;
   35.46 -    PhArea_t CurrentViewPort;
   35.47 -    PhPoint_t CurrentWindowPos;
   35.48 -    long format;
   35.49 -    int scaler_on;
   35.50 -    int current;
   35.51 -    long YStride;
   35.52 -    long VStride;
   35.53 -    long UStride;
   35.54 -    int ischromakey;
   35.55 -    long chromakey;
   35.56 -    int forcedredraw;
   35.57 -    unsigned long State;
   35.58 -    long flags;
   35.59 -*/
   35.60 -        SDL_Surface *display;
   35.61 -        BView *bview;
   35.62 -        bool first_display;
   35.63 -        BBitmap *bbitmap;
   35.64 -        int locked;
   35.65 -    };
   35.66 -
   35.67 -    extern BBitmap *BE_GetOverlayBitmap(BRect bounds, color_space cs);
   35.68 -    extern SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height,
   35.69 -                                            Uint32 format,
   35.70 -                                            SDL_Surface * display);
   35.71 -    extern int BE_LockYUVOverlay(_THIS, SDL_Overlay * overlay);
   35.72 -    extern void BE_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay);
   35.73 -    extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay,
   35.74 -                                    SDL_Rect * src, SDL_Rect * dst);
   35.75 -    extern void BE_FreeYUVOverlay(_THIS, SDL_Overlay * overlay);
   35.76 -
   35.77 -};
   35.78 -
   35.79 -#endif /* __SDL_PH_YUV_H__ */
   35.80 -/* vi: set ts=4 sw=4 expandtab: */