From afa5bfc8d0653adc185e436eb44f4f3c1124f6ac Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 21 Jun 2011 13:49:14 +0000 Subject: [PATCH 01/27] SDL 1.3 patch 00 for GSoC: Haiku - Implemented pthread spinlock in src/atomic/spinlock.c (in both trylock and unlock). Added appropriate checks in configure.in and include/SDL_configure.h.in. --- configure.in | 19 +++++++++++++++++++ include/SDL_config.h.in | 1 + src/atomic/SDL_spinlock.c | 11 +++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index b291df45a..1b2a07f26 100644 --- a/configure.in +++ b/configure.in @@ -280,6 +280,25 @@ if test x$enable_gcc_atomics = xyes; then fi fi +# Check for pthread implementation +AC_MSG_CHECKING(for pthread spinlock) +have_pthread_spinlock=no + +AC_TRY_LINK([ +#include +],[ +pthread_spinlock_t a; +pthread_spin_trylock(&a); +pthread_spin_unlock(&a); +],[ +have_pthread_spinlock=yes +]) +AC_MSG_RESULT($have_pthread_spinlock) +if test x$have_pthread_spinlock = xyes; then + AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [ ]) +fi + + # Standard C sources SOURCES="$SOURCES $srcdir/src/*.c" SOURCES="$SOURCES $srcdir/src/atomic/*.c" diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index b5bb3e1bd..f4ea2f84a 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -45,6 +45,7 @@ #undef SIZEOF_VOIDP #undef HAVE_GCC_ATOMICS #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET +#undef HAVE_PTHREAD_SPINLOCK /* Comment this if you want to build without any C library requirements */ #undef HAVE_LIBC diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index f74de81c7..093554774 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -77,9 +77,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); return (result == 0); -#else +#elif HAVE_PTHREAD_SPINLOCK + /* pthread instructions */ + return (pthread_spin_trylock(lock) == 0); +#else /* Need CPU instructions for spinlock here! */ __need_spinlock_implementation__ + #endif } @@ -101,7 +105,10 @@ SDL_AtomicUnlock(SDL_SpinLock *lock) #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET __sync_lock_release(lock); - + +#elif HAVE_PTHREAD_SPINLOCK + pthread_spin_unlock(lock); + #else *lock = 0; #endif From 4f1212a24b502c05c722f663202f2591c2d07c07 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Fri, 24 Jun 2011 12:48:43 +0000 Subject: [PATCH 02/27] Replaced private event functionality with event sending. --- src/video/bwindow/SDL_BWin.h | 79 +++++++++++++++++++------------ src/video/bwindow/SDL_lowvideo.h | 2 +- src/video/bwindow/SDL_sysvideo.cc | 9 ++-- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 1606853d4..4688cc017 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -33,6 +33,9 @@ #endif #include +//FIXME: Temporary fix until I can understand what the values used from here do +#include "SDL_compat.h" + #include "../../main/beos/SDL_BeApp.h" #include "SDL_events.h" #include "SDL_BView.h" @@ -219,7 +222,8 @@ class SDL_BWin:public BDirectWindow if (inhibit_resize) inhibit_resize = false; else - SDL_PrivateResize((int) width, (int) height); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, + (int) width, (int) height); } virtual int CreateView(Uint32 flags, Uint32 gl_flags) { @@ -227,7 +231,7 @@ class SDL_BWin:public BDirectWindow retval = 0; Lock(); - if (flags & SDL_INTERNALOPENGL) { + if (flags & SDL_OPENGL/*SDL_INTERNALOPENGL*/) { #if SDL_VIDEO_OPENGL if (SDL_GLView == NULL) { SDL_GLView = new BGLView(Bounds(), "SDL GLView", @@ -321,17 +325,24 @@ class SDL_BWin:public BDirectWindow virtual void Minimize(bool minimize) { /* This is only called when mimimized, not when restored */ - //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); BWindow::Minimize(minimize); } virtual void WindowActivated(bool active) { - SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); +// SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); + if( active ) { + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + } else { + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); + } } virtual bool QuitRequested(void) { if (SDL_BeAppActive > 0) { - SDL_PrivateQuit(); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 0); /* We don't ever actually close the window here because the application should respond to the quit request, or ignore it as desired. @@ -401,19 +412,23 @@ class SDL_BWin:public BDirectWindow && msg->FindInt32("be:transit", &transit) == B_OK) { if (transit == B_EXITED_VIEW) { if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { - SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); +// SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); be_app->SetCursor(B_HAND_CURSOR); } } else { int x, y; if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { - SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); +// SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); SDL_SetCursor(NULL); } GetXYOffset(x, y); x = (int) where.x - x; y = (int) where.y - y; - SDL_PrivateMouseMotion(0, 0, x, y); + SDL_SendMouseMotion(window, 0, x, y); } } break; @@ -424,19 +439,21 @@ class SDL_BWin:public BDirectWindow /* it looks like mouse down is send only for first clicked button, each next is not send while last one is holded */ int32 buttons; - int sdl_buttons = 0; +// int sdl_buttons = 0; if (msg->FindInt32("buttons", &buttons) == B_OK) { /* Add any mouse button events */ if (buttons & B_PRIMARY_MOUSE_BUTTON) { - sdl_buttons |= SDL_BUTTON_LEFT; +// sdl_buttons |= SDL_BUTTON_LMASK; + SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_LEFT); } if (buttons & B_SECONDARY_MOUSE_BUTTON) { - sdl_buttons |= SDL_BUTTON_RIGHT; +// sdl_buttons |= SDL_BUTTON_RMASK; + SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_RIGHT); } if (buttons & B_TERTIARY_MOUSE_BUTTON) { - sdl_buttons |= SDL_BUTTON_MIDDLE; +// sdl_buttons |= SDL_BUTTON_MMASK; + SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_MIDDLE); } - SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0); last_buttons = buttons; } @@ -455,19 +472,21 @@ class SDL_BWin:public BDirectWindow without releasing previous one first) - but that's probably because of how drivers are written?, not BeOS itself. */ int32 buttons; - int sdl_buttons = 0; +// int sdl_buttons = 0; if (msg->FindInt32("buttons", &buttons) == B_OK) { /* Add any mouse button events */ if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) { - sdl_buttons |= SDL_BUTTON_LEFT; +// sdl_buttons |= SDL_BUTTON_LMASK; + SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_LEFT); } if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) { - sdl_buttons |= SDL_BUTTON_RIGHT; +// sdl_buttons |= SDL_BUTTON_RMASK; + SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_RIGHT); } if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) { - sdl_buttons |= SDL_BUTTON_MIDDLE; +// sdl_buttons |= SDL_BUTTON_MMASK; + SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_MIDDLE); } - SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0); last_buttons = buttons; } @@ -481,15 +500,9 @@ class SDL_BWin:public BDirectWindow if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) { if (x < 0 || y < 0) { - SDL_PrivateMouseButton(SDL_PRESSED, - SDL_BUTTON_WHEELDOWN, 0, 0); - SDL_PrivateMouseButton(SDL_RELEASED, - SDL_BUTTON_WHEELDOWN, 0, 0); + SDL_SendMouseWheel(window, (int)x, (int)y); } else if (x > 0 || y > 0) { - SDL_PrivateMouseButton(SDL_PRESSED, - SDL_BUTTON_WHEELUP, 0, 0); - SDL_PrivateMouseButton(SDL_RELEASED, - SDL_BUTTON_WHEELUP, 0, 0); + SDL_SendMouseWheel(window, (int)x, (int)y); } } break; @@ -509,7 +522,7 @@ class SDL_BWin:public BDirectWindow if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) { SDL_Keysym keysym; - keysym.scancode = key; + keysym.scancode = (SDL_Scancode)key; if ((key > 0) && (key < 128)) { keysym.sym = keymap[key]; } else { @@ -520,6 +533,7 @@ class SDL_BWin:public BDirectWindow anyway, and doesn't care about what we setup here */ keysym.mod = KMOD_NONE; keysym.unicode = 0; +#if 0 /* FIXME: As far as I can make out, this isn't really used anymore? */ if (SDL_TranslateUNICODE) { const char *bytes; if (msg->FindString("bytes", &bytes) == B_OK) { @@ -530,7 +544,8 @@ class SDL_BWin:public BDirectWindow keysym.unicode = Translate2Unicode(bytes); } } - SDL_PrivateKeyboard(SDL_PRESSED, &keysym); +#endif + SDL_SendKeyboardKey(SDL_PRESSED, keysym.scancode); } break; } @@ -543,7 +558,7 @@ class SDL_BWin:public BDirectWindow if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) { SDL_Keysym keysym; - keysym.scancode = key; + keysym.scancode = (SDL_Scancode)key; if ((key > 0) && (key < 128)) { keysym.sym = keymap[key]; } else { @@ -551,13 +566,15 @@ class SDL_BWin:public BDirectWindow } keysym.mod = KMOD_NONE; /* FIX THIS? */ keysym.unicode = 0; +#if 0 /* FIXME: As far as I can make out, this isn't really used anymore? */ if (SDL_TranslateUNICODE) { const char *bytes; if (msg->FindString("bytes", &bytes) == B_OK) { keysym.unicode = Translate2Unicode(bytes); } } - SDL_PrivateKeyboard(SDL_RELEASED, &keysym); +#endif + SDL_SendKeyboardKey(SDL_RELEASED, keysym.scancode); } break; } @@ -586,6 +603,8 @@ class SDL_BWin:public BDirectWindow int32 last_buttons; SDL_Keycode keymap[128]; + + SDL_Window *window; }; #endif /* _SDL_BWin_h */ diff --git a/src/video/bwindow/SDL_lowvideo.h b/src/video/bwindow/SDL_lowvideo.h index 94555fdb1..87ca33dfb 100644 --- a/src/video/bwindow/SDL_lowvideo.h +++ b/src/video/bwindow/SDL_lowvideo.h @@ -43,7 +43,7 @@ struct SDL_PrivateVideoData SDL_Rect **SDL_modelist[NUM_MODELISTS]; /* A completely clear cursor */ - WMcursor *BlankCursor; + struct WMcursor *BlankCursor; SDL_Overlay *overlay; }; diff --git a/src/video/bwindow/SDL_sysvideo.cc b/src/video/bwindow/SDL_sysvideo.cc index a083893be..9610f43ec 100644 --- a/src/video/bwindow/SDL_sysvideo.cc +++ b/src/video/bwindow/SDL_sysvideo.cc @@ -549,7 +549,10 @@ extern "C" current->flags |= SDL_NOFRAME; SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); } else { - if ((flags & SDL_RESIZABLE) && !(flags & SDL_INTERNALOPENGL)) { + /* FIXME: What was SDL_INTERNALOPENGL? This used it before, but it + isn't defined anywhere. */ + if ((flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL + /*SDL_INTERNALOPENGL*/)) { current->flags |= SDL_RESIZABLE; /* We don't want opaque resizing (TM). :-) */ SDL_Win->SetFlags(B_OUTLINE_RESIZE); @@ -558,8 +561,8 @@ extern "C" } } - if (flags & SDL_INTERNALOPENGL) { - current->flags |= SDL_INTERNALOPENGL; + if (flags & SDL_OPENGL /*SDL_INTERNALOPENGL*/) { + current->flags |= SDL_OPENGL /*SDL_INTERNALOPENGL*/; current->pitch = 0; current->pixels = NULL; _this->UpdateRects = NULL; From 70ba5c8150fce7004bdf252a13fb9f94f61a4e15 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 12 Jul 2011 15:06:12 +0000 Subject: [PATCH 03/27] Rewrote most of Haiku video support to conform with 1.3 functionality. --- src/main/beos/SDL_BApp.h | 312 +++++++++++ src/main/beos/SDL_BeApp.cc | 16 +- src/video/bwindow/SDL_BView.h | 10 +- src/video/bwindow/SDL_BWin.h | 822 ++++++++++++++--------------- src/video/bwindow/SDL_bclipboard.c | 109 ++++ src/video/bwindow/SDL_bclipboard.h | 31 ++ src/video/bwindow/SDL_bmodes.c | 78 +++ src/video/bwindow/SDL_bmodes.h | 27 + src/video/bwindow/SDL_bopengl.c | 195 +++++++ src/video/bwindow/SDL_bopengl.h | 27 + src/video/bwindow/SDL_bvideo.c | 202 +++++++ src/video/bwindow/SDL_bvideo.h | 44 ++ src/video/bwindow/SDL_bwindow.c | 203 +++++++ src/video/bwindow/SDL_bwindow.h | 56 ++ 14 files changed, 1701 insertions(+), 431 deletions(-) create mode 100644 src/main/beos/SDL_BApp.h create mode 100644 src/video/bwindow/SDL_bclipboard.c create mode 100644 src/video/bwindow/SDL_bclipboard.h create mode 100644 src/video/bwindow/SDL_bmodes.c create mode 100644 src/video/bwindow/SDL_bmodes.h create mode 100644 src/video/bwindow/SDL_bopengl.c create mode 100644 src/video/bwindow/SDL_bopengl.h create mode 100644 src/video/bwindow/SDL_bvideo.c create mode 100644 src/video/bwindow/SDL_bvideo.h create mode 100644 src/video/bwindow/SDL_bwindow.c create mode 100644 src/video/bwindow/SDL_bwindow.h diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h new file mode 100644 index 000000000..d42960117 --- /dev/null +++ b/src/main/beos/SDL_BApp.h @@ -0,0 +1,312 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef SDL_BAPP_H +#define SDL_BAPP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "SDL_config.h" +#include "SDL_video.h" + +/* Local includes */ +#include "../../events/SDL_events_c.h" + +#ifdef __cplusplus +} +#endif + + +#include + + +/* Forward declarations */ +class SDL_BWin; + +/* Message constants */ +enum ToSDL { + /* Intercepted by BWindow on its way to BView */ + BAPP_MOUSE_MOVED, + BAPP_MOUSE_BUTTON, + BAPP_MOUSE_WHEEL, + BAPP_KEY, + BAPP_REPAINT, /* from _UPDATE_ */ + /* From BWindow */ + BAPP_MAXIMIZE, /* from B_ZOOM */ + BAPP_MINIMIZE, + BAPP_RESTORE, /* TODO: IMPLEMENT! */ + BAPP_SHOW, + BAPP_HIDE, + BAPP_MOUSE_FOCUS, /* caused by MOUSE_MOVE */ + BAPP_KEYBOARD_FOCUS, /* from WINDOW_ACTIVATED */ + BAPP_WINDOW_CLOSE_REQUESTED, + BAPP_WINDOW_MOVED, + BAPP_WINDOW_RESIZED, + BAPP_SCREEN_CHANGED +}; + + + +/* Create a descendant of BApplication */ +class SDL_BApp : public BApplication { +public: + SDL_BApp(const char* signature) : + BApplication(signature) { + } + /* Event-handling functions */ + virtual void MessageReceived(BMessage* message) { + /* Sort out SDL-related messages */ + switch ( message->what ) { + case BAPP_MOUSE_MOVED: + _HandleMouseMove(message); + break; + + case BAPP_MOUSE_BUTTON: + _HandleMouseButton(message); + break; + + case BAPP_MOUSE_WHEEL: + _HandleMouseWheel(message); + break; + + case BAPP_KEY: + _HandleKey(message); + break; + + case BAPP_REPAINT: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_EXPOSED); + break; + + case BAPP_MAXIMIZE: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MAXIMIZED); + break; + + case BAPP_MINIMIZE: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MINIMIZED); + break; + + case BAPP_SHOW: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_SHOWN); + break; + + case BAPP_HIDE: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_HIDDEN); + break; + + case BAPP_MOUSE_FOCUS: + _HandleMouseFocus(message); + break; + + case BAPP_KEYBOARD_FOCUS: + _HandleKeyboardFocus(message); + break; + + case BAPP_WINDOW_CLOSE_REQUESTED: + _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_CLOSE); + break; + + case BAPP_WINDOW_MOVED: + _HandleWindowMoved(message); + break; + + case BAPP_WINDOW_RESIZED: + _HandleWindowResized(message); + break; + + case BAPP_SCREEN_CHANGED: + /* TODO: Handle screen resize or workspace change */ + break; + + default: + BApplication::MessageReceived(message); + break; + } + } + + /* Window creation/destruction methods */ + int32 GetID(SDL_Window *win) { + int32 i; + for(i = 0; i < window_map.size(); ++i) { + if( window_map[i] == NULL ) { + window_map[i] = win; + return i; + } + } + + /* Expand the vector if all slots are full */ + if( i == window_map.size() ) { + window_map.push_back(win); + return i; + } + } + + void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ + +private: + /* Event management */ + void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) { + SDL_Window *win; + int32 winID; + if( + !_GetWinID(msg, &winID) + ) { + return; + } + win = window_map[winID]; + SDL_SendWindowEvent(win, sdlEventType, 0, 0); + } + + void _HandleMouseMove(BMessage *msg) { + SDL_Window *win; + int32 winID; + int32 dx, dy; + if( + !_GetWinID(msg, &winID) || + msg->FindInt32("dx", &dx) != B_OK || /* x movement */ + msg->FindInt32("dy", &dy) != B_OK /* y movement */ + ) { + return; + } + win = window_map[winID]; + SDL_SendMouseMotion(win, 0, dx, dy); + } + + void _HandleMouseButton(BMessage *msg) { + SDL_Window *win; + int32 winID; + int32 button, state; /* left/middle/right, pressed/released */ + if( + !_GetWinID(msg, &winID) || + msg->FindInt32("button-id", &button) != B_OK || + msg->FindInt32("button-state", &state) != B_OK + ) { + return; + } + win = window_map[winID]; + SDL_SendMouseButton(win, state, button); + } + + void _HandleMouseWheel(BMessage *msg) { + SDL_Window *win; + int32 winID; + int32 xTicks, yTicks; + if( + !_GetWinID(msg, &winID) || + msg->FindInt32("xticks", &xTicks) != B_OK || + msg->FindInt32("yticks", &yTicks) != B_OK + ) { + return; + } + win = window_map[winID]; + SDL_SendMouseWheel(win, xTicks, yTicks); + } + + void _HandleKey(BMessage *msg) { + int32 scancode, state; /* scancode, pressed/released */ + if( + msg->FindInt32("key-state", &state) != B_OK || + msg->FindInt32("key-scancode", &scancode) != B_OK + ) { + return; + } + SDL_SendKeyboardKey(state, (SDL_Scancode)scancode); + } + + void _HandleMouseFocus(BMessage *msg) { + SDL_Window *win; + int32 winID; + bool bSetFocus; /* If false, lose focus */ + if( + !_GetWinID(msg, &winID) || + msg->FindBool("focusGained", &bSetFocus) != B_OK + ) { + return; + } + win = window_map[winID]; + if(bSetFocus) { + SDL_SetMouseFocus(win); + } else if(SDL_GetMouseFocus() == win) { + /* Only lose all focus if this window was the current focus */ + SDL_SetMouseFocus(NULL); + } + } + + void _HandleKeyboardFocus(BMessage *msg) { + SDL_Window *win; + int32 winID; + bool bSetFocus; /* If false, lose focus */ + if( + !_GetWinID(msg, &winID) || + msg->FindBool("focusGained", &bSetFocus) != B_OK + ) { + return; + } + win = window_map[winID]; + if(bSetFocus) { + SDL_SetKeyboardFocus(win); + } else if(SDL_GetKeyboardFocus() == win) { + /* Only lose all focus if this window was the current focus */ + SDL_SetKeyboardFocus(NULL); + } + } + + void _HandleWindowMoved(BMessage *msg) { + SDL_Window *win; + int32 winID; + int32 xPos, yPos; + /* Get the window id and new x/y position of the window */ + if( + !_GetWinID(msg, &winID) || + msg->FindInt32("window-x", &xPos) != B_OK || + msg->FindInt32("window-y", &yPos) != B_OK + ) { + return; + } + win = window_map[winID]; + SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos); + } + + void _HandleWindowResized(BMessage *msg) { + SDL_Window *win; + int32 winID; + int32 w, h; + /* Get the window id ]and new x/y position of the window */ + if( + !_GetWinID(msg, &winID) || + msg->FindInt32("window-w", &w) != B_OK || + msg->FindInt32("window-h", &h) != B_OK + ) { + return; + } + win = window_map[winID]; + SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); + } + + bool _GetWinID(BMessage *msg, int32 *winID) { + return msg->FindInt32("window-id", winID) == B_OK; + } + + /* Members */ + vector window_map; /* Keeps track of SDL_Windows by index-id */ +}; + +#endif diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 2f68881e1..a31465e5e 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -27,11 +27,14 @@ #include #include +#include "SDL_BApp.h" /* SDL_BApp class definition */ #include "SDL_BeApp.h" #include "SDL_thread.h" #include "SDL_timer.h" #include "SDL_error.h" +#include "../../video/bwindow/SDL_BWin.h" + /* Flag to tell whether or not the Be application is active or not */ int SDL_BeAppActive = 0; static SDL_Thread *SDL_AppThread = NULL; @@ -41,7 +44,7 @@ StartBeApp(void *unused) { BApplication *App; - App = new BApplication("application/x-SDL-executable"); + App = new SDL_BApp("application/x-SDL-executable"); App->Run(); delete App; @@ -110,4 +113,15 @@ SDL_QuitBeApp(void) } } +/* SDL_BApp functions */ +void SDL_BApp::ClearID(SDL_BWin *bwin) { + window_map[bwin->GetID()] = NULL; + int32 i = window_map.size() - 1; + while(i >= 0 && window_map[i] == NULL) { + window_map.pop_back(); + --i; + } +} + /* vi: set ts=4 sw=4 expandtab: */ + diff --git a/src/video/bwindow/SDL_BView.h b/src/video/bwindow/SDL_BView.h index e5d29ef68..f522fe95e 100644 --- a/src/video/bwindow/SDL_BView.h +++ b/src/video/bwindow/SDL_BView.h @@ -24,11 +24,15 @@ #define _SDL_BView_h /* This is the event handling and graphics update portion of SDL_BWin */ +#ifdef __cplusplus +extern "C" { +#endif -extern "C" -{ #include "../../events/SDL_events_c.h" -}; + +#ifdef __cplusplus +} +#endif class SDL_BView:public BView { diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 4688cc017..94042966b 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -22,7 +22,17 @@ #ifndef _SDL_BWin_h #define _SDL_BWin_h +#ifdef __cplusplus +extern "C" { +#endif + #include "SDL_config.h" +#include "SDL.h" +#include "SDL_syswm.h" + +#ifdef __cplusplus +} +#endif #include #include @@ -31,27 +41,30 @@ #if SDL_VIDEO_OPENGL #include #endif -#include - -//FIXME: Temporary fix until I can understand what the values used from here do -#include "SDL_compat.h" - -#include "../../main/beos/SDL_BeApp.h" #include "SDL_events.h" #include "SDL_BView.h" +#include "../../main/beos/SDL_BApp.h" -extern "C" -{ -#include "../../events/SDL_events_c.h" +enum WinCommands { + BWIN_MOVE_WINDOW, + BWIN_RESIZE_WINDOW, + BWIN_SHOW_WINDOW, + BWIN_HIDE_WINDOW, + BWIN_MAXIMIZE_WINDOW, + BWIN_MINIMIZE_WINDOW, + BWIN_RESTORE_WINDOW, /* TODO: IMPLEMENT THIS! */ + BWIN_SET_TITLE, + BWIN_FULLSCREEN }; + class SDL_BWin:public BDirectWindow { public: + /* Constructor/Destructor */ SDL_BWin(BRect bounds):BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { - InitKeyboard(); last_buttons = 0; the_view = NULL; @@ -60,8 +73,10 @@ class SDL_BWin:public BDirectWindow #endif SDL_View = NULL; Unlock(); - shown = false; + _shown = false; inhibit_resize = false; + mouse_focused = false; + prev_frame = NULL; } virtual ~ SDL_BWin() @@ -86,145 +101,9 @@ class SDL_BWin:public BDirectWindow delete SDL_View; } } - - virtual void InitKeyboard(void) - { - for (uint i = 0; i < SDL_TABLESIZE(keymap); ++i) - keymap[i] = SDLK_UNKNOWN; - - keymap[0x01] = SDLK_ESCAPE; - keymap[B_F1_KEY] = SDLK_F1; - keymap[B_F2_KEY] = SDLK_F2; - keymap[B_F3_KEY] = SDLK_F3; - keymap[B_F4_KEY] = SDLK_F4; - keymap[B_F5_KEY] = SDLK_F5; - keymap[B_F6_KEY] = SDLK_F6; - keymap[B_F7_KEY] = SDLK_F7; - keymap[B_F8_KEY] = SDLK_F8; - keymap[B_F9_KEY] = SDLK_F9; - keymap[B_F10_KEY] = SDLK_F10; - keymap[B_F11_KEY] = SDLK_F11; - keymap[B_F12_KEY] = SDLK_F12; - keymap[B_PRINT_KEY] = SDLK_PRINTSCREEN; - keymap[B_SCROLL_KEY] = SDLK_SCROLLLOCK; - keymap[B_PAUSE_KEY] = SDLK_PAUSE; - keymap[0x11] = SDLK_BACKQUOTE; - keymap[0x12] = SDLK_1; - keymap[0x13] = SDLK_2; - keymap[0x14] = SDLK_3; - keymap[0x15] = SDLK_4; - keymap[0x16] = SDLK_5; - keymap[0x17] = SDLK_6; - keymap[0x18] = SDLK_7; - keymap[0x19] = SDLK_8; - keymap[0x1a] = SDLK_9; - keymap[0x1b] = SDLK_0; - keymap[0x1c] = SDLK_MINUS; - keymap[0x1d] = SDLK_EQUALS; - keymap[0x1e] = SDLK_BACKSPACE; - keymap[0x1f] = SDLK_INSERT; - keymap[0x20] = SDLK_HOME; - keymap[0x21] = SDLK_PAGEUP; - keymap[0x22] = SDLK_NUMLOCKCLEAR; - keymap[0x23] = SDLK_KP_DIVIDE; - keymap[0x24] = SDLK_KP_MULTIPLY; - keymap[0x25] = SDLK_KP_MINUS; - keymap[0x26] = SDLK_TAB; - keymap[0x27] = SDLK_q; - keymap[0x28] = SDLK_w; - keymap[0x29] = SDLK_e; - keymap[0x2a] = SDLK_r; - keymap[0x2b] = SDLK_t; - keymap[0x2c] = SDLK_y; - keymap[0x2d] = SDLK_u; - keymap[0x2e] = SDLK_i; - keymap[0x2f] = SDLK_o; - keymap[0x30] = SDLK_p; - keymap[0x31] = SDLK_LEFTBRACKET; - keymap[0x32] = SDLK_RIGHTBRACKET; - keymap[0x33] = SDLK_BACKSLASH; - keymap[0x34] = SDLK_DELETE; - keymap[0x35] = SDLK_END; - keymap[0x36] = SDLK_PAGEDOWN; - keymap[0x37] = SDLK_KP_7; - keymap[0x38] = SDLK_KP_8; - keymap[0x39] = SDLK_KP_9; - keymap[0x3a] = SDLK_KP_PLUS; - keymap[0x3b] = SDLK_CAPSLOCK; - keymap[0x3c] = SDLK_a; - keymap[0x3d] = SDLK_s; - keymap[0x3e] = SDLK_d; - keymap[0x3f] = SDLK_f; - keymap[0x40] = SDLK_g; - keymap[0x41] = SDLK_h; - keymap[0x42] = SDLK_j; - keymap[0x43] = SDLK_k; - keymap[0x44] = SDLK_l; - keymap[0x45] = SDLK_SEMICOLON; - keymap[0x46] = SDLK_QUOTE; - keymap[0x47] = SDLK_RETURN; - keymap[0x48] = SDLK_KP_4; - keymap[0x49] = SDLK_KP_5; - keymap[0x4a] = SDLK_KP_6; - keymap[0x4b] = SDLK_LSHIFT; - keymap[0x4c] = SDLK_z; - keymap[0x4d] = SDLK_x; - keymap[0x4e] = SDLK_c; - keymap[0x4f] = SDLK_v; - keymap[0x50] = SDLK_b; - keymap[0x51] = SDLK_n; - keymap[0x52] = SDLK_m; - keymap[0x53] = SDLK_COMMA; - keymap[0x54] = SDLK_PERIOD; - keymap[0x55] = SDLK_SLASH; - keymap[0x56] = SDLK_RSHIFT; - keymap[0x57] = SDLK_UP; - keymap[0x58] = SDLK_KP_1; - keymap[0x59] = SDLK_KP_2; - keymap[0x5a] = SDLK_KP_3; - keymap[0x5b] = SDLK_KP_ENTER; - keymap[0x5c] = SDLK_LCTRL; - keymap[0x5d] = SDLK_LALT; - keymap[0x5e] = SDLK_SPACE; - keymap[0x5f] = SDLK_RALT; - keymap[0x60] = SDLK_RCTRL; - keymap[0x61] = SDLK_LEFT; - keymap[0x62] = SDLK_DOWN; - keymap[0x63] = SDLK_RIGHT; - keymap[0x64] = SDLK_KP_0; - keymap[0x65] = SDLK_KP_PERIOD; - keymap[0x66] = SDLK_LGUI; - keymap[0x67] = SDLK_RGUI; - keymap[0x68] = SDLK_MENU; - keymap[0x69] = SDLK_2; //SDLK_EURO; - keymap[0x6a] = SDLK_KP_EQUALS; - keymap[0x6b] = SDLK_POWER; - } - - /* Override the Show() method so we can tell when we've been shown */ - virtual void Show(void) - { - BWindow::Show(); - shown = true; - } - virtual bool Shown(void) - { - return (shown); - } - /* If called, the next resize event will not be forwarded to SDL. */ - virtual void InhibitResize(void) - { - inhibit_resize = true; - } - /* Handle resizing of the window */ - virtual void FrameResized(float width, float height) - { - if (inhibit_resize) - inhibit_resize = false; - else - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, - (int) width, (int) height); - } + + + /* Other construction */ virtual int CreateView(Uint32 flags, Uint32 gl_flags) { int retval; @@ -271,10 +150,218 @@ class SDL_BWin:public BDirectWindow Unlock(); return (retval); } - virtual void SetBitmap(BBitmap * bitmap) - { - SDL_View->SetBitmap(bitmap); + + /* * * * * Event sending * * * * */ + /* Hook functions */ + virtual void FrameMoved(BPoint origin) { + /* Post a message to the BApp so that it can handle the window event */ + BMessage msg(BAPP_WINDOW_MOVED); + msg.AddInt32("window-x", (int)origin.x); + msg.AddInt32("window-y", (int)origin.y); + _PostWindowEvent(msg); + + /* Perform normal hook operations */ + BDirectWindow::FrameMoved(origin); } + + virtual void FrameResized(float width, float height) { + /* Post a message to the BApp so that it can handle the window event */ + BMessage msg(BAPP_WINDOW_RESIZED); + msg.AddInt32("window-w", (int)width) + 1; /* TODO: Check that +1 is needed */ + msg.AddInt32("window-h", (int)height) + 1; + _PostWindowEvent(msg); + + /* Perform normal hook operations */ + BDirectWindow::FrameResized(width, height); + } + + virtual bool QuitRequested() { + BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED); + _PostWindowEvent(msg); + + /* We won't allow a quit unless asked by DestroyWindow() */ + return false; + } + + virtual void WindowActivated(bool active) { + BMessage msg(BAPP_KEYBOARD_FOCUS); /* Mouse focus sold separately */ + _PostWindowEvent(msg); + } + + virtual void Zoom(BPoint origin, + float width, + float height) { + BMessage msg(BAPP_MAXIMIZE); /* Closest thing to maximization Haiku has */ + _PostWindowEvent(msg); + + /* Before the window zooms, record its size */ + if( !prev_frame ) + prev_frame = new BRect(Frame()); + + /* Perform normal hook operations */ + BDirectWindow::Zoom(origin, width, height); + } + + /* Member functions */ + virtual void Show() { + BDirectWindow::Show(); + _shown = true; + + BMessage msg(BAPP_SHOW); + _PostWindowEvent(msg); + } + + virtual void Hide() { + /* FIXME: Multiple hides require multiple shows to undo. Should + this be altered to prevent this from happening? */ + BDirectWindow::Hide(); + _shown = false; + + BMessage msg(BAPP_HIDE); + _PostWindowEvent(msg); + } + + virtual void Minimize(bool minimize) { + BDirectWindow::Minimize(minimize); + int32 minState = (minimize ? BAPP_MINIMIZE : BAPP_RESTORE); + + BMessage msg(minState); + _PostWindowEvent(msg); + } + + + /* BView message interruption */ + virtual void DispatchMessage(BMessage * msg, BHandler * target) + { + + BPoint where; /* Used by mouse moved */ + int32 buttons; /* Used for mouse button events */ + int32 key; /* Used for key events */ + + switch (msg->what) { + case B_MOUSE_MOVED: + where; + int32 transit; + if (msg->FindPoint("where", &where) == B_OK + && msg->FindInt32("be:transit", &transit) == B_OK) { + _MouseMotionEvent(where, transit); + } + + /* FIXME: Apparently a button press/release event might be dropped + if made before before a different button is released. Does + B_MOUSE_MOVED have the data needed to check if a mouse button + state has changed? */ + if (msg->FindInt32("buttons", &buttons) == B_OK) { + _MouseButtonEvent(buttons); + } + break; + + case B_MOUSE_DOWN: + case B_MOUSE_UP: + /* _MouseButtonEvent() detects any and all buttons that may have + changed state, as well as that button's new state */ + if (msg->FindInt32("buttons", &buttons) == B_OK) { + _MouseButtonEvent(buttons); + } + break; + + case B_MOUSE_WHEEL_CHANGED: + float x, y; + if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK + && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) { + _MouseWheelEvent((int)x, (int)y); + } + break; + + case B_KEY_DOWN: + case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */ + if (msg->FindInt32("key", &key) == B_OK) { + _KeyEvent((SDL_Scancode)key, SDL_PRESSED); + } + break; + + case B_KEY_UP: + case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */ + if (msg->FindInt32("key", &key) == B_OK) { + _KeyEvent(key, SDL_RELEASED); + } + break; + + case _UPDATE_: + case _UPDATE_IF_NEEDED_: /* Hopefully one doesn't call the other */ + _RepaintEvent(); + break; + + default: + /* move it after switch{} so it's always handled + that way we keep BeOS feautures like: + - CTRL+Q to close window (and other shortcuts) + - PrintScreen to make screenshot into /boot/home + - etc.. */ + //BDirectWindow::DispatchMessage(msg, target); + break; + } + BDirectWindow::DispatchMessage(msg, target); + } + + /* Handle command messages */ + virtual void MessageReceived(BMessage* message) { + switch (message->what) { + /* Handle commands from SDL */ + case BWIN_SET_TITLE: + _SetTitle(message); + break; + case BWIN_MOVE_WINDOW: + _MoveTo(message); + break; + case BWIN_RESIZE_WINDOW: + _ResizeTo(message); + break; + case BWIN_SHOW_WINDOW: + Show(); + break; + case BWIN_HIDE_WINDOW: + Hide(); + break; + case BWIN_MAXIMIZE_WINDOW: + BWindow::Zoom(); + break; + case BWIN_MINIMIZE_WINDOW: + Minimize(true); + break; + case BWIN_RESTORE_WINDOW: + _Restore(); + break; + case BWIN_FULLSCREEN: + _SetFullScreen(message); + break; + default: + /* Perform normal message handling */ + BDirectWindow::MessageReceived(message); + break; + } + + } + + + + /* Accessor methods */ + bool IsShown() { return _shown; } + int32 GetID() { return _id; } + + /* Setter methods */ + void SetID(int32 id) { _id = id; } + + + + + + + + + + /* FIXME: Methods copied directly; do we need them? */ +#if 0 /* Disabled until its purpose is determined */ virtual void SetXYOffset(int x, int y) { #if SDL_VIDEO_OPENGL @@ -295,6 +382,7 @@ class SDL_BWin:public BDirectWindow #endif SDL_View->GetXYOffset(x, y); } +#endif virtual bool BeginDraw(void) { return (Lock()); @@ -321,291 +409,171 @@ class SDL_BWin:public BDirectWindow return (the_view); } - /* Hook functions -- overridden */ - virtual void Minimize(bool minimize) - { - /* This is only called when mimimized, not when restored */ - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); - BWindow::Minimize(minimize); + + + + + + +private: + /* Event redirection */ + void _MouseMotionEvent(BPoint &where, int32 transit) { + if(transit == B_EXITED_VIEW) { + /* Change mouse focus */ + if(mouse_focused) { + _MouseFocusEvent(false); + } + } else { + static int x = 0, y = 0; + /* Change mouse focus */ + if (!mouse_focused) { + _MouseFocusEvent(true); + } +// GetXYOffset(x, y); //FIXME: What is this doing? (from SDL 1.2) + BMessage msg(BAPP_MOUSE_MOVED); + msg.AddInt32("dx", where.x - x); + msg.AddInt32("dy", where.y - y); + x = (int) where.x; + y = (int) where.y; + _PostWindowEvent(msg); + } } - virtual void WindowActivated(bool active) - { -// SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); - if( active ) { - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); - } else { - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); - } + + void _MouseFocusEvent(bool focusGained) { + mouse_focused = focusGained; + BMessage msg(BAPP_MOUSE_FOCUS); + msg.AddBool("focusGained", focusGained); + _PostWindowEvent(msg); + +//FIXME: Why were these here? +// if false: be_app->SetCursor(B_HAND_CURSOR); +// if true: SDL_SetCursor(NULL); } - virtual bool QuitRequested(void) - { - if (SDL_BeAppActive > 0) { - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 0); - /* We don't ever actually close the window here because - the application should respond to the quit request, - or ignore it as desired. - */ - return (false); - } - return (true); /* Close the app window */ + + void _MouseButtonEvent(int32 buttons) { + int32 buttonStateChange = buttons ^ last_buttons; + + /* Make sure at least one button has changed state */ + if( !(buttonStateChange) ) { + return; + } + + /* Add any mouse button events */ + if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) { + _SendMouseButton(SDL_BUTTON_LEFT, buttons & B_PRIMARY_MOUSE_BUTTON); + } + if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) { + _SendMouseButton(SDL_BUTTON_RIGHT, buttons & B_PRIMARY_MOUSE_BUTTON); + } + if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) { + _SendMouseButton(SDL_BUTTON_MIDDLE, buttons & B_PRIMARY_MOUSE_BUTTON); + } + + last_buttons = buttons; } - virtual void Quit() - { - if (!IsLocked()) - Lock(); - BDirectWindow::Quit(); + + void _SendMouseButton(int32 button, int32 state) { + BMessage msg(BAPP_MOUSE_BUTTON); + msg.AddInt32("button-id", button); + msg.AddInt32("button-state", state); + _PostWindowEvent(msg); + } + + void _MouseWheelEvent(int32 x, int32 y) { + /* Create a message to pass along to the BeApp thread */ + BMessage msg(BAPP_MOUSE_WHEEL); + msg.AddInt32("xticks", x); + msg.AddInt32("yticks", y); + _PostWindowEvent(msg); + } + + void _KeyEvent(int32 keyCode, int32 keyState) { + /* Create a message to pass along to the BeApp thread */ + BMessage msg(BAPP_KEY); + msg.AddInt32("key-state", keyState); + msg.AddInt32("key-scancode", keyCode); + be_app->PostMessage(&msg); + /* Apparently SDL only uses the scancode */ + } + + void _RepaintEvent() { + /* Force a repaint: Call the SDL exposed event */ + BMessage msg(BAPP_REPAINT); + _PostWindowEvent(msg); + } + void _PostWindowEvent(BMessage &msg) { + msg.AddInt32("window-id", _id); + be_app->PostMessage(&msg); + } + + /* Command methods (functions called upon by SDL) */ + void _SetTitle(BMessage *msg) { + const char *title; + if( + msg->FindString("window-title", &title) != B_OK + ) { + return; + } + SetTitle(title); + } + + void _MoveTo(BMessage *msg) { + int32 x, y; + if( + msg->FindInt32("window-x", &x) != B_OK || + msg->FindInt32("window-y", &y) != B_OK + ) { + return; + } + MoveTo(x, y); + } + + void _ResizeTo(BMessage *msg) { + int32 w, h; + if( + msg->FindInt32("window-w", &w) != B_OK || + msg->FindInt32("window-h", &h) != B_OK + ) { + return; + } + ResizeTo(w, h); + } + + void _Restore() { + if(IsMinimized()) { + Minimize(false); + } else if(IsHidden()) { + Show(); + } else if(prev_frame != NULL) { /* Zoomed */ + MoveTo(prev_frame->left, prev_frame->top); + ResizeTo(prev_frame->Width(), prev_frame->Height()); + } } - virtual int16 Translate2Unicode(const char *buf) - { - int32 state, srclen, dstlen; - unsigned char destbuf[2]; - Uint16 unicode = 0; - - if ((uchar) buf[0] > 127) { - state = 0; - srclen = SDL_strlen(buf); - dstlen = sizeof(destbuf); - convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, - (char *) destbuf, &dstlen, &state); - unicode = destbuf[0]; - unicode <<= 8; - unicode |= destbuf[1]; - } else - unicode = buf[0]; - - /* For some reason function keys map to control characters */ -# define CTRL(X) ((X)-'@') - switch (unicode) { - case CTRL('A'): - case CTRL('B'): - case CTRL('C'): - case CTRL('D'): - case CTRL('E'): - case CTRL('K'): - case CTRL('L'): - case CTRL('P'): - if (!(SDL_GetModState() & KMOD_CTRL)) - unicode = 0; - break; - /* Keyboard input maps newline to carriage return */ - case '\n': - unicode = '\r'; - break; - default: - break; - } - - return unicode; + void _SetFullScreen(BMessage *msg) { + bool fullscreen; + if( + msg->FindBool("fullscreen", &fullscreen) != B_OK + ) { + return; + } + SetFullScreen(fullscreen); } - - virtual void DispatchMessage(BMessage * msg, BHandler * target) - { - switch (msg->what) { - case B_MOUSE_MOVED: - { - BPoint where; - int32 transit; - if (msg->FindPoint("where", &where) == B_OK - && msg->FindInt32("be:transit", &transit) == B_OK) { - if (transit == B_EXITED_VIEW) { - if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { -// SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); - be_app->SetCursor(B_HAND_CURSOR); - } - } else { - int x, y; - if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { -// SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); - SDL_SetCursor(NULL); - } - GetXYOffset(x, y); - x = (int) where.x - x; - y = (int) where.y - y; - SDL_SendMouseMotion(window, 0, x, y); - } - } - break; - } - - case B_MOUSE_DOWN: - { - /* it looks like mouse down is send only for first clicked - button, each next is not send while last one is holded */ - int32 buttons; -// int sdl_buttons = 0; - if (msg->FindInt32("buttons", &buttons) == B_OK) { - /* Add any mouse button events */ - if (buttons & B_PRIMARY_MOUSE_BUTTON) { -// sdl_buttons |= SDL_BUTTON_LMASK; - SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_LEFT); - } - if (buttons & B_SECONDARY_MOUSE_BUTTON) { -// sdl_buttons |= SDL_BUTTON_RMASK; - SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_RIGHT); - } - if (buttons & B_TERTIARY_MOUSE_BUTTON) { -// sdl_buttons |= SDL_BUTTON_MMASK; - SDL_SendMouseButton(window, SDL_PRESSED, SDL_BUTTON_MIDDLE); - } - - last_buttons = buttons; - } - break; - } - - case B_MOUSE_UP: - { - /* mouse up doesn't give which button was released, - only state of buttons (after release, so it's always = 0), - which is not what we need ;] - So we need to store button in mouse down, and restore - in mouse up :( - mouse up is (similarly to mouse down) send only for - first button down (ie. it's no send if we click another button - without releasing previous one first) - but that's probably - because of how drivers are written?, not BeOS itself. */ - int32 buttons; -// int sdl_buttons = 0; - if (msg->FindInt32("buttons", &buttons) == B_OK) { - /* Add any mouse button events */ - if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) { -// sdl_buttons |= SDL_BUTTON_LMASK; - SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_LEFT); - } - if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) { -// sdl_buttons |= SDL_BUTTON_RMASK; - SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_RIGHT); - } - if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) { -// sdl_buttons |= SDL_BUTTON_MMASK; - SDL_SendMouseButton(window, SDL_RELEASED, SDL_BUTTON_MIDDLE); - } - - last_buttons = buttons; - } - break; - } - - case B_MOUSE_WHEEL_CHANGED: - { - float x, y; - x = y = 0; - if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK - && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) { - if (x < 0 || y < 0) { - SDL_SendMouseWheel(window, (int)x, (int)y); - } else if (x > 0 || y > 0) { - SDL_SendMouseWheel(window, (int)x, (int)y); - } - } - break; - } - - case B_KEY_DOWN: - case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */ - { - int32 key; - int32 modifiers; - int32 key_repeat; - /* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */ - if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK - && key_repeat > 0) - break; - - if (msg->FindInt32("key", &key) == B_OK - && msg->FindInt32("modifiers", &modifiers) == B_OK) { - SDL_Keysym keysym; - keysym.scancode = (SDL_Scancode)key; - if ((key > 0) && (key < 128)) { - keysym.sym = keymap[key]; - } else { - keysym.sym = SDLK_UNKNOWN; - } - /* FIX THIS? - it seems SDL_PrivateKeyboard() changes mod value - anyway, and doesn't care about what we setup here */ - keysym.mod = KMOD_NONE; - keysym.unicode = 0; -#if 0 /* FIXME: As far as I can make out, this isn't really used anymore? */ - if (SDL_TranslateUNICODE) { - const char *bytes; - if (msg->FindString("bytes", &bytes) == B_OK) { - /* FIX THIS? - this cares only about first "letter", - so if someone maps some key to print - "BeOS rulez!" only "B" will be used. */ - keysym.unicode = Translate2Unicode(bytes); - } - } -#endif - SDL_SendKeyboardKey(SDL_PRESSED, keysym.scancode); - } - break; - } - - case B_KEY_UP: - case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */ - { - int32 key; - int32 modifiers; - if (msg->FindInt32("key", &key) == B_OK - && msg->FindInt32("modifiers", &modifiers) == B_OK) { - SDL_Keysym keysym; - keysym.scancode = (SDL_Scancode)key; - if ((key > 0) && (key < 128)) { - keysym.sym = keymap[key]; - } else { - keysym.sym = SDLK_UNKNOWN; - } - keysym.mod = KMOD_NONE; /* FIX THIS? */ - keysym.unicode = 0; -#if 0 /* FIXME: As far as I can make out, this isn't really used anymore? */ - if (SDL_TranslateUNICODE) { - const char *bytes; - if (msg->FindString("bytes", &bytes) == B_OK) { - keysym.unicode = Translate2Unicode(bytes); - } - } -#endif - SDL_SendKeyboardKey(SDL_RELEASED, keysym.scancode); - } - break; - } - - default: - /* move it after switch{} so it's always handled - that way we keep BeOS feautures like: - - CTRL+Q to close window (and other shortcuts) - - PrintScreen to make screenshot into /boot/home - - etc.. */ - //BDirectWindow::DispatchMessage(msg, target); - break; - } - BDirectWindow::DispatchMessage(msg, target); - } - - private: + + /* Members */ #if SDL_VIDEO_OPENGL BGLView * SDL_GLView; #endif SDL_BView *SDL_View; BView *the_view; - - bool shown; - bool inhibit_resize; - - int32 last_buttons; - SDL_Keycode keymap[128]; - SDL_Window *window; + int32 last_buttons; + int32 _id; /* Window id used by SDL_BApp */ + bool mouse_focused; /* Does this window have mouse focus? */ + bool _shown; + bool inhibit_resize; + + BRect *prev_frame; /* Previous position and size of the window */ }; -#endif /* _SDL_BWin_h */ -/* vi: set ts=4 sw=4 expandtab: */ +#endif diff --git a/src/video/bwindow/SDL_bclipboard.c b/src/video/bwindow/SDL_bclipboard.c new file mode 100644 index 000000000..4cc965899 --- /dev/null +++ b/src/video/bwindow/SDL_bclipboard.c @@ -0,0 +1,109 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/* BWindow based framebuffer implementation */ +#include "SDL_config.h" + +#include +#include + +#include "SDL_BWin.h" +#include "SDL_timer.h" +#include "../SDL_sysvideo.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int BE_SetClipboardText(_THIS, const char *text) { +#if 0 + BMessage *clip = NULL; + if(be_clipboard->Lock()) { + be_clipboard->Clear(); + if((clip = be_clipboard->Data())) { + /* Presumably the string of characters is ascii-format */ + ssize_t asciiLength = 0; + for(; text[asciiLength] != 0; ++asciiLength) {} + clip->AddData("text/plain", B_MIME_TYPE, &text, asciiLength); + be_clipboard->Commit(); + } + be_clipboard->Unlock(); + } +#else +return -1; +#endif +} + +char *BE_GetClipboardText(_THIS) { +#if 0 + BMessage *clip = NULL; + const char *text; + ssize_t length; + if(be_clipboard->Lock()) { + if((clip = be_clipboard->Data())) { + /* Presumably the string of characters is ascii-format */ + clip->FindData("text/plain", B_MIME_TYPE, (void**)&text, &length); + } else { + be_clipboard->Unlock(); + return NULL; + } + be_clipboard->Unlock(); + } else { + return NULL; + } + + /* Copy the data and pass on to SDL */ + char *result = (char*)SDL_calloc(1, sizeof(char*)*length); + SDL_strlcpy(result, text, length); + + return result; +#else +return NULL; +#endif; +} + +SDL_bool BE_HasClipboardText(_THIS) { +#if 0 + BMessage *clip = NULL; + const char *text; + ssize_t length; + SDL_bool retval = SDL_FALSE; + + if(be_clipboard->Lock()) { + if((clip = be_clipboard->Data())) { + /* Presumably the string of characters is ascii-format */ + clip->FindData("text/plain", B_MIME_TYPE, (void**)&text, &length); + if( text ) retval = SDL_TRUE; + } + be_clipboard->Unlock(); + } + return retval; +#else +return SDL_FALSE; +#endif + +} + +#ifdef __cplusplus +} /* Extern C */ +#endif + diff --git a/src/video/bwindow/SDL_bclipboard.h b/src/video/bwindow/SDL_bclipboard.h new file mode 100644 index 000000000..bfb806cd0 --- /dev/null +++ b/src/video/bwindow/SDL_bclipboard.h @@ -0,0 +1,31 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_config.h" + +#ifndef SDL_BCLIPBOARD_H +#define SDL_BCLIPBOARD_H + +extern int BE_SetClipboardText(_THIS, const char *text); +extern char *BE_GetClipboardText(_THIS); +extern SDL_bool BE_HasClipboardText(_THIS); + +#endif diff --git a/src/video/bwindow/SDL_bmodes.c b/src/video/bwindow/SDL_bmodes.c new file mode 100644 index 000000000..2818718f5 --- /dev/null +++ b/src/video/bwindow/SDL_bmodes.c @@ -0,0 +1,78 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../SDL_sysvideo.h" + +int BE_InitModes(_THIS) { +#if 0 + display_mode *modes; + uint32 i, nmodes; + int bpp; + + /* It is important that this be created after SDL_InitBeApp() */ + BScreen bscreen; + + /* Save the current display mode */ + bscreen.GetMode(&saved_mode); + _this->info.current_w = saved_mode.virtual_width; + _this->info.current_h = saved_mode.virtual_height; + + /* Get the video modes we can switch to in fullscreen mode */ + bscreen.GetModeList(&modes, &nmodes); + SDL_qsort(modes, nmodes, sizeof *modes, CompareModes); + for (i = 0; i < nmodes; ++i) { + bpp = ColorSpaceToBitsPerPixel(modes[i].space); + //if ( bpp != 0 ) { // There are bugs in changing colorspace + if (modes[i].space == saved_mode.space) { + BE_AddMode(_this, ((bpp + 7) / 8) - 1, + modes[i].virtual_width, modes[i].virtual_height); + } + } +#else +return -1; +#endif +} + +int BE_QuitModes(_THIS) { +#if 0 + int i, j; + for (i = 0; i < NUM_MODELISTS; ++i) { + if (SDL_modelist[i]) { + for (j = 0; SDL_modelist[i][j]; ++j) { + SDL_free(SDL_modelist[i][j]); + } + SDL_free(SDL_modelist[i]); + SDL_modelist[i] = NULL; + } + } + + /* Restore the original video mode */ + if (_this->screen) { + if ((_this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { + BScreen bscreen; + bscreen.SetMode(&saved_mode); + } + _this->screen->pixels = NULL; + } +#else +return -1; +#endif +} diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h new file mode 100644 index 000000000..e8208cf68 --- /dev/null +++ b/src/video/bwindow/SDL_bmodes.h @@ -0,0 +1,27 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_BMODES_H +#define SDL_BMODES_H + +extern int BE_InitModes(_THIS); +extern int BE_QuitModes(_THIS); +#endif diff --git a/src/video/bwindow/SDL_bopengl.c b/src/video/bwindow/SDL_bopengl.c new file mode 100644 index 000000000..4e8ae5225 --- /dev/null +++ b/src/video/bwindow/SDL_bopengl.c @@ -0,0 +1,195 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_bopengl.h" +#include "../SDL_sysvideo.h" + + +/* Passing a NULL path means load pointers from the application */ +int BE_GL_LoadLibrary(_THIS, const char *path) +{ +#if 0 + if (path == NULL) { + if (_this->gl_config.dll_handle == NULL) { + image_info info; + int32 cookie = 0; + while (get_next_image_info(0, &cookie, &info) == B_OK) { + void *location = NULL; + if (get_image_symbol + ((image_id) cookie, "glBegin", + B_SYMBOL_TYPE_ANY, &location) == B_OK) { + _this->gl_config.dll_handle = (void *) cookie; + _this->gl_config.driver_loaded = 1; + SDL_strlcpy(_this->gl_config.driver_path, + "libGL.so", + SDL_arraysize(_this-> + gl_config.driver_path)); + } + } + } + } else { + /* + FIXME None of BeOS libGL.so implementations have exported functions + to load BGLView, which should be reloaded from new lib. + So for now just "load" linked libGL.so :( + */ + if (_this->gl_config.dll_handle == NULL) { + return BE_GL_LoadLibrary(_this, NULL); + } + + /* Unload old first */ + /*if (_this->gl_config.dll_handle != NULL) { */ + /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */ + /* image_info info; + if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) { + if (info.type != B_APP_IMAGE) { + unload_add_on((image_id)_this->gl_config.dll_handle); + } + } + + } + + if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) { + _this->gl_config.driver_loaded = 1; + SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); + } */ + } + + if (_this->gl_config.dll_handle != NULL) { + return 0; + } else { + _this->gl_config.dll_handle = NULL; + _this->gl_config.driver_loaded = 0; + *_this->gl_config.driver_path = '\0'; + return -1; + } +#endif +} + +void *BE_GL_GetProcAddress(_THIS, const char *proc) +{ +#if 0 + if (_this->gl_config.dll_handle != NULL) { + void *location = NULL; + status_t err; + if ((err = + get_image_symbol((image_id) _this->gl_config.dll_handle, + proc, B_SYMBOL_TYPE_ANY, + &location)) == B_OK) { + return location; + } else { + SDL_SetError("Couldn't find OpenGL symbol"); + return NULL; + } + } else { + SDL_SetError("OpenGL library not loaded"); + return NULL; + } +#endif +} + + + + +int BE_GL_MakeCurrent(_THIS) +{ + /* FIXME: should we glview->unlock and then glview->lock()? */ + return 0; +} + + + + + + + + + + + + +#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */ + + int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) + { + /* + FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values + */ + switch (attrib) { + case SDL_GL_RED_SIZE: + glGetIntegerv(GL_RED_BITS, (GLint *) value); + break; + case SDL_GL_GREEN_SIZE: + glGetIntegerv(GL_GREEN_BITS, (GLint *) value); + break; + case SDL_GL_BLUE_SIZE: + glGetIntegerv(GL_BLUE_BITS, (GLint *) value); + break; + case SDL_GL_ALPHA_SIZE: + glGetIntegerv(GL_ALPHA_BITS, (GLint *) value); + break; + case SDL_GL_DOUBLEBUFFER: + glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value); + break; + case SDL_GL_BUFFER_SIZE: + int v; + glGetIntegerv(GL_RED_BITS, (GLint *) & v); + *value = v; + glGetIntegerv(GL_GREEN_BITS, (GLint *) & v); + *value += v; + glGetIntegerv(GL_BLUE_BITS, (GLint *) & v); + *value += v; + glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v); + *value += v; + break; + case SDL_GL_DEPTH_SIZE: + glGetIntegerv(GL_DEPTH_BITS, (GLint *) value); /* Mesa creates 16 only? r5 always 32 */ + break; + case SDL_GL_STENCIL_SIZE: + glGetIntegerv(GL_STENCIL_BITS, (GLint *) value); + break; + case SDL_GL_ACCUM_RED_SIZE: + glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value); + break; + case SDL_GL_ACCUM_GREEN_SIZE: + glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value); + break; + case SDL_GL_ACCUM_BLUE_SIZE: + glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value); + break; + case SDL_GL_ACCUM_ALPHA_SIZE: + glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value); + break; + case SDL_GL_STEREO: + case SDL_GL_MULTISAMPLEBUFFERS: + case SDL_GL_MULTISAMPLESAMPLES: + default: + *value = 0; + return (-1); + } + return 0; + } + + void BE_GL_SwapBuffers(_THIS) + { + SDL_Win->SwapBuffers(); + } +#endif diff --git a/src/video/bwindow/SDL_bopengl.h b/src/video/bwindow/SDL_bopengl.h new file mode 100644 index 000000000..de32975b7 --- /dev/null +++ b/src/video/bwindow/SDL_bopengl.h @@ -0,0 +1,27 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_BOPENGL_H +#define SDL_BOPENGL_H +extern int BE_GL_LoadLibrary(_THIS, const char *path); +extern void *BE_GL_GetProcAddress(_THIS, const char *proc); +extern int BE_GL_MakeCurrent(_THIS); +#endif diff --git a/src/video/bwindow/SDL_bvideo.c b/src/video/bwindow/SDL_bvideo.c new file mode 100644 index 000000000..3b4fea7f8 --- /dev/null +++ b/src/video/bwindow/SDL_bvideo.c @@ -0,0 +1,202 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +#include "SDL_bwindow.h" +#include "SDL_bclipboard.h" +#include "SDL_bvideo.h" +#include "SDL_bopengl.h" +#include "SDL_bmodes.h" + +#ifdef __cplusplus +extern "C" { +#endif +/* FIXME: Undefined functions */ +// #define BE_VideoInit NULL +// #define BE_VideoQuit NULL + #define BE_GetDisplayBounds NULL + #define BE_GetDisplayModes NULL + #define BE_SetDisplayMode NULL + #define BE_PumpEvents NULL + +#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ +// #define BE_GL_LoadLibrary NULL +// #define BE_GL_GetProcAddress NULL + #define BE_GL_UnloadLibrary NULL + #define BE_GL_CreateContext NULL +// #define BE_GL_MakeCurrent NULL + #define BE_GL_SetSwapInterval NULL + #define BE_GL_GetSwapInterval NULL + #define BE_GL_SwapWindow NULL + #define BE_GL_DeleteContext NULL +#endif + #define BE_StartTextInput NULL + #define BE_StopTextInput NULL + #define BE_SetTextInputRect NULL + +// #define BE_DeleteDevice NULL + +/* End undefined functions */ + +static SDL_VideoDevice * +BE_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + SDL_VideoData *data; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (device) { + data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + } else { + data = NULL; + } + if (!data) { + SDL_OutOfMemory(); + if (device) { + SDL_free(device); + } + return NULL; + } + device->driverdata = data; + +/* TODO: Figure out what sort of initialization needs to go here */ + + /* Set the function pointers */ + device->VideoInit = BE_VideoInit; + device->VideoQuit = BE_VideoQuit; + device->GetDisplayBounds = BE_GetDisplayBounds; + device->GetDisplayModes = BE_GetDisplayModes; + device->SetDisplayMode = BE_SetDisplayMode; + device->PumpEvents = BE_PumpEvents; + + device->CreateWindow = BE_CreateWindow; + device->CreateWindowFrom = BE_CreateWindowFrom; + device->SetWindowTitle = BE_SetWindowTitle; + device->SetWindowIcon = BE_SetWindowIcon; + device->SetWindowPosition = BE_SetWindowPosition; + device->SetWindowSize = BE_SetWindowSize; + device->ShowWindow = BE_ShowWindow; + device->HideWindow = BE_HideWindow; + device->RaiseWindow = BE_RaiseWindow; + device->MaximizeWindow = BE_MaximizeWindow; + device->MinimizeWindow = BE_MinimizeWindow; + device->RestoreWindow = BE_RestoreWindow; + device->SetWindowFullscreen = BE_SetWindowFullscreen; + device->SetWindowGammaRamp = BE_SetWindowGammaRamp; + device->GetWindowGammaRamp = BE_GetWindowGammaRamp; + device->SetWindowGrab = BE_SetWindowGrab; + device->DestroyWindow = BE_DestroyWindow; + device->GetWindowWMInfo = BE_GetWindowWMInfo; + device->CreateWindowFramebuffer = BE_CreateWindowFramebuffer; + device->UpdateWindowFramebuffer = BE_UpdateWindowFramebuffer; + device->DestroyWindowFramebuffer = BE_DestroyWindowFramebuffer; + + device->shape_driver.CreateShaper = NULL; + device->shape_driver.SetWindowShape = NULL; + device->shape_driver.ResizeWindowShape = NULL; + +#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ + device->GL_LoadLibrary = BE_GL_LoadLibrary; + device->GL_GetProcAddress = BE_GL_GetProcAddress; + device->GL_UnloadLibrary = BE_GL_UnloadLibrary; + device->GL_CreateContext = BE_GL_CreateContext; + device->GL_MakeCurrent = BE_GL_MakeCurrent; + device->GL_SetSwapInterval = BE_GL_SetSwapInterval; + device->GL_GetSwapInterval = BE_GL_GetSwapInterval; + device->GL_SwapWindow = BE_GL_SwapWindow; + device->GL_DeleteContext = BE_GL_DeleteContext; +#endif + device->StartTextInput = BE_StartTextInput; + device->StopTextInput = BE_StopTextInput; + device->SetTextInputRect = BE_SetTextInputRect; + + device->SetClipboardText = BE_SetClipboardText; + device->GetClipboardText = BE_GetClipboardText; + device->HasClipboardText = BE_HasClipboardText; + + device->free = BE_DeleteDevice; + + return device; +} + +static void BE_DeleteDevice(SDL_VideoDevice * device) +{ + SDL_free(device->driverdata); + SDL_free(device); +} + +/* FIXME: This is the 1.2 function at the moment. Read through it and + o understand what it does. */ +int BE_VideoInit(_THIS) +{ + /* Initialize the Be Application for appserver interaction */ + if (SDL_InitBeApp() < 0) { + return -1; + } + + BE_InitModes(_this); + +#if SDL_VIDEO_OPENGL + /* testgl application doesn't load library, just tries to load symbols */ + /* is it correct? if so we have to load library here */ + BE_GL_LoadLibrary(_this, NULL); +#endif + + /* Fill in some window manager capabilities */ +// _this->info.wm_available = 1; + + /* We're done! */ + return (0); +} + +static int BE_Available(void) +{ + return (1); +} + +void BE_VideoQuit(_THIS) +{ + +#if 0 + SDL_Win->Quit(); + SDL_Win = NULL; +#endif +#if 0 + if (SDL_BlankCursor != NULL) { + BE_FreeWMCursor(_this, SDL_BlankCursor); + SDL_BlankCursor = NULL; + } +#endif + + BE_QuitModes(_this); + +#if SDL_VIDEO_OPENGL +// if (_this->gl_config.dll_handle != NULL) +// unload_add_on((image_id) _this->gl_config.dll_handle); +#endif + + SDL_QuitBeApp(); +} + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bvideo.h b/src/video/bwindow/SDL_bvideo.h new file mode 100644 index 000000000..c1c32a6bb --- /dev/null +++ b/src/video/bwindow/SDL_bvideo.h @@ -0,0 +1,44 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef BVIDEO_H +#define BVIDEO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../main/beos/SDL_BeApp.h" +#include "../SDL_sysvideo.h" + +typedef struct SDL_VideoData { + +} SDL_VideoData; + +extern void BE_VideoQuit(_THIS); +extern int BE_VideoInit(_THIS); +extern void BE_DeleteDevice(_THIS); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/video/bwindow/SDL_bwindow.c b/src/video/bwindow/SDL_bwindow.c new file mode 100644 index 000000000..1341093e6 --- /dev/null +++ b/src/video/bwindow/SDL_bwindow.c @@ -0,0 +1,203 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_config.h" +#include "../SDL_sysvideo.h" + +#include "SDL_BWin.h" +#include + +/* Define a path to window's BWIN data */ +#ifdef __cplusplus +extern "C" { +#endif + +static inline SDL_BWin *_ToBeWin(SDL_Window *window) { + return ((SDL_BWin*)(window->driverdata)); +} + +static inline SDL_BApp *_GetBeApp() { + return ((SDL_BApp*)be_app); +} + +int _InitWindow(_THIS, SDL_Window *window) { + BRect bounds( + window->x, + window->y, + window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing + window->y + window->h - 1 + ); + + SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds); + if(bwin == NULL) + return ENOMEM; + + window->driverdata = bwin; + int32 winID = _GetBeApp()->GetID(window); + bwin->SetID(winID); + return 0; +} + +int BE_CreateWindow(_THIS, SDL_Window *window) { + if(_InitWindow(_this, window) == ENOMEM) + return ENOMEM; + + /* Start window loop */ + _ToBeWin(window)->Show(); + return 0; +} + +int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { + + SDL_BWin *otherBWin = (SDL_BWin*)data; + if(!otherBWin->LockLooper()) + return -1; + + /* Create the new window and initialize its members */ + window->x = (int)otherBWin->Frame().left; + window->y = (int)otherBWin->Frame().top; + window->w = (int)otherBWin->Frame().Width(); + window->h = (int)otherBWin->Frame().Height(); + + /* If we are out of memory, return the error code */ + if(_InitWindow(_this, window) == ENOMEM) + return ENOMEM; + + /* TODO: Add any other SDL-supported window attributes here */ + _ToBeWin(window)->SetTitle(otherBWin->Title()); + + /* Start window loop and unlock the other window */ + _ToBeWin(window)->Show(); + + otherBWin->UnlockLooper(); + return 0; +} + +void BE_SetWindowTitle(_THIS, SDL_Window * window) { + BMessage msg(BWIN_SET_TITLE); + msg.AddString("window-title", window->title); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) { + /* FIXME: Icons not supported by BeOs/Haiku */ +} + +void BE_SetWindowPosition(_THIS, SDL_Window * window) { + BMessage msg(BWIN_MOVE_WINDOW); + msg.AddInt32("window-x", window->x); + msg.AddInt32("window-y", window->y); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_SetWindowSize(_THIS, SDL_Window * window) { + BMessage msg(BWIN_RESIZE_WINDOW); + msg.AddInt32("window-w", window->w - 1); + msg.AddInt32("window-h", window->h - 1); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_ShowWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_SHOW_WINDOW); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_HideWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_HIDE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_RaiseWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */ + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_MaximizeWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_MAXIMIZE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_MinimizeWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_MINIMIZE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_RestoreWindow(_THIS, SDL_Window * window) { + BMessage msg(BWIN_RESTORE_WINDOW); + _ToBeWin(window)->PostMessage(&msg); +} + +void BE_SetWindowFullscreen(_THIS, SDL_Window * window, + SDL_VideoDisplay * display, SDL_bool fullscreen) { + /* Haiku tracks all video display information */ + BMessage msg(BWIN_FULLSCREEN); + msg.AddBool("fullscreen", fullscreen); + _ToBeWin(window)->PostMessage(&msg); + +} + +int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) { + /* FIXME: Not BeOs/Haiku supported */ +} + +int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) { + /* FIXME: Not BeOs/Haiku supported */ +} + + +void BE_SetWindowGrab(_THIS, SDL_Window * window) { + /* TODO: Implement this! */ +} + +void BE_DestroyWindow(_THIS, SDL_Window * window) { + _ToBeWin(window)->LockLooper(); /* This MUST be locked */ + _GetBeApp()->ClearID(_ToBeWin(window)); + _ToBeWin(window)->Quit(); + window->driverdata = NULL; +} + +SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, + struct SDL_SysWMinfo *info) { + /* FIXME: What is the point of this? What information should be included? */ +} + + +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch) { + /* FIXME: Not BeOs/Haiku supported */ + return -1; +} + +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects) { + /* FIXME: Not BeOs/Haiku supported */ + return -1; +} + +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { + /* FIXME: Not BeOs/Haiku supported */ +} + + +#ifdef __cplusplus +} +#endif + diff --git a/src/video/bwindow/SDL_bwindow.h b/src/video/bwindow/SDL_bwindow.h new file mode 100644 index 000000000..26f800b7f --- /dev/null +++ b/src/video/bwindow/SDL_bwindow.h @@ -0,0 +1,56 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_BWINDOW_H +#define SDL_BWINDOW_H + + +#include "../SDL_sysvideo.h" + +extern int BE_CreateWindow(_THIS, SDL_Window *window); +extern int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); +extern void BE_SetWindowTitle(_THIS, SDL_Window * window); +extern void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon); +extern void BE_SetWindowPosition(_THIS, SDL_Window * window); +extern void BE_SetWindowSize(_THIS, SDL_Window * window); +extern void BE_ShowWindow(_THIS, SDL_Window * window); +extern void BE_HideWindow(_THIS, SDL_Window * window); +extern void BE_RaiseWindow(_THIS, SDL_Window * window); +extern void BE_MaximizeWindow(_THIS, SDL_Window * window); +extern void BE_MinimizeWindow(_THIS, SDL_Window * window); +extern void BE_RestoreWindow(_THIS, SDL_Window * window); +extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen); +extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp); +extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp); +extern void BE_SetWindowGrab(_THIS, SDL_Window * window); +extern void BE_DestroyWindow(_THIS, SDL_Window * window); +extern SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, + struct SDL_SysWMinfo *info); + +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch); +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects); +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); + +#endif + From 461d178134374d028e21b10d412e836b742da91b Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 12 Jul 2011 15:09:44 +0000 Subject: [PATCH 04/27] Removed 1.2 files. --- src/video/bwindow/SDL_lowvideo.h | 59 -- src/video/bwindow/SDL_sysevents.cc | 48 -- src/video/bwindow/SDL_sysevents_c.h | 31 - src/video/bwindow/SDL_sysmouse.cc | 144 ----- src/video/bwindow/SDL_sysmouse_c.h | 32 -- src/video/bwindow/SDL_sysvideo.cc | 864 ---------------------------- src/video/bwindow/SDL_syswm.cc | 54 -- src/video/bwindow/SDL_syswm_c.h | 31 - src/video/bwindow/SDL_sysyuv.cc | 321 ----------- src/video/bwindow/SDL_sysyuv.h | 77 --- 10 files changed, 1661 deletions(-) delete mode 100644 src/video/bwindow/SDL_lowvideo.h delete mode 100644 src/video/bwindow/SDL_sysevents.cc delete mode 100644 src/video/bwindow/SDL_sysevents_c.h delete mode 100644 src/video/bwindow/SDL_sysmouse.cc delete mode 100644 src/video/bwindow/SDL_sysmouse_c.h delete mode 100644 src/video/bwindow/SDL_sysvideo.cc delete mode 100644 src/video/bwindow/SDL_syswm.cc delete mode 100644 src/video/bwindow/SDL_syswm_c.h delete mode 100644 src/video/bwindow/SDL_sysyuv.cc delete mode 100644 src/video/bwindow/SDL_sysyuv.h diff --git a/src/video/bwindow/SDL_lowvideo.h b/src/video/bwindow/SDL_lowvideo.h deleted file mode 100644 index 87ca33dfb..000000000 --- a/src/video/bwindow/SDL_lowvideo.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifndef _SDL_lowvideo_h -#define _SDL_lowvideo_h - -#include "SDL_BWin.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" - -/* Hidden "this" pointer for the video functions */ -#define _THIS SDL_VideoDevice *_this - -/* Private display data */ -struct SDL_PrivateVideoData -{ - /* The main window */ - SDL_BWin *SDL_Win; - - /* The fullscreen mode list */ - display_mode saved_mode; -#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ - int SDL_nummodes[NUM_MODELISTS]; - SDL_Rect **SDL_modelist[NUM_MODELISTS]; - - /* A completely clear cursor */ - struct WMcursor *BlankCursor; - - SDL_Overlay *overlay; -}; -/* Old variable names */ -#define SDL_Win (_this->hidden->SDL_Win) -#define saved_mode (_this->hidden->saved_mode) -#define SDL_nummodes (_this->hidden->SDL_nummodes) -#define SDL_modelist (_this->hidden->SDL_modelist) -#define SDL_BlankCursor (_this->hidden->BlankCursor) -#define current_overlay (_this->hidden->overlay) - -#endif /* _SDL_lowvideo_h */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysevents.cc b/src/video/bwindow/SDL_sysevents.cc deleted file mode 100644 index 7d14e5286..000000000 --- a/src/video/bwindow/SDL_sysevents.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include -#include -#include -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_BWin.h" -#include "SDL_lowvideo.h" - -extern "C" -{ - -#include "../../events/SDL_sysevents.h" -#include "../../events/SDL_events_c.h" -#include "SDL_sysevents_c.h" - - void BE_PumpEvents(_THIS) - { - } - - void BE_InitOSKeymap(_THIS) - { - } - -}; /* Extern C */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysevents_c.h b/src/video/bwindow/SDL_sysevents_c.h deleted file mode 100644 index 401e4a63d..000000000 --- a/src/video/bwindow/SDL_sysevents_c.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include "SDL_lowvideo.h" - -/* Variables and functions exported by SDL_sysevents.c to other parts - of the native video subsystem (SDL_sysvideo.c) -*/ - -extern void BE_InitOSKeymap(_THIS); -extern void BE_PumpEvents(_THIS); -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysmouse.cc b/src/video/bwindow/SDL_sysmouse.cc deleted file mode 100644 index 0f5fd1153..000000000 --- a/src/video/bwindow/SDL_sysmouse.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include -#include - -#include "SDL_BWin.h" - -extern "C" -{ - -#include "SDL_sysmouse_c.h" - -/* Convert bits to padded bytes */ -#define PADDED_BITS(bits) ((bits+7)/8) - -/* The implementation dependent data for the window manager cursor */ - struct WMcursor - { - char *bits; - }; - -/* Can this be done in the BeOS? */ - WMcursor *BE_CreateWMCursor(_THIS, - Uint8 * data, Uint8 * mask, int w, int h, - int hot_x, int hot_y) - { - WMcursor *cursor; - int allowed_x; - int allowed_y; - int run, pad, i; - char *cptr; - - allowed_x = 16; /* BeOS limitation */ - allowed_y = 16; /* BeOS limitation */ - if ((w > allowed_x) || (h > allowed_y)) - { - SDL_SetError("Only cursors of dimension (%dx%d) are allowed", - allowed_x, allowed_y); - return (NULL); - } - - /* Allocate the cursor */ - cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor)); - if (cursor == NULL) { - SDL_OutOfMemory(); - return (NULL); - } - cursor->bits = - (char *) SDL_malloc(4 + 2 * ((allowed_x / 8) * allowed_y)); - if (cursor->bits == NULL) { - SDL_free(cursor); - SDL_OutOfMemory(); - return (NULL); - } - cursor->bits[0] = allowed_y; /* Size of the cursor */ - cursor->bits[1] = 1; /* Bit depth of cursor */ - cursor->bits[2] = hot_y; - cursor->bits[3] = hot_x; - cptr = &cursor->bits[4]; - - /* Pad out to the normal cursor size */ - run = PADDED_BITS(w); - pad = PADDED_BITS(allowed_x) - run; - for (i = 0; i < h; ++i) { - SDL_memcpy(cptr, data, run); - SDL_memset(cptr + run, 0, pad); - data += run; - cptr += (run + pad); - } - for (; i < allowed_y; ++i) { - SDL_memset(cptr, 0, run + pad); - cptr += (run + pad); - } - for (i = 0; i < h; ++i) { - /* FIXME: The mask should be OR'd with the data to turn - inverted color pixels black, since inverted color pixels - aren't supported under BeOS. - */ - SDL_memcpy(cptr, mask, run); - SDL_memset(cptr + run, 0, pad); - mask += run; - cptr += (run + pad); - } - for (; i < allowed_y; ++i) { - SDL_memset(cptr, 0, run + pad); - cptr += (run + pad); - } - return (cursor); - } - - int BE_ShowWMCursor(_THIS, WMcursor * cursor) - { - if (be_app->Lock()) { - if (cursor == NULL) { - if (SDL_BlankCursor != NULL) { - be_app->SetCursor(SDL_BlankCursor->bits); - } - } else { - be_app->SetCursor(cursor->bits); - } - be_app->Unlock(); - } - return (1); - } - - void BE_FreeWMCursor(_THIS, WMcursor * cursor) - { - SDL_free(cursor->bits); - SDL_free(cursor); - } - -/* Implementation by Christian Bauer */ - void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y) - { - BPoint pt(x, y); - SDL_Win->Lock(); - SDL_Win->ConvertToScreen(&pt); - SDL_Win->Unlock(); - set_mouse_position((int32) pt.x, (int32) pt.y); - } - -}; /* Extern C */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysmouse_c.h b/src/video/bwindow/SDL_sysmouse_c.h deleted file mode 100644 index 46182096f..000000000 --- a/src/video/bwindow/SDL_sysmouse_c.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include "SDL_lowvideo.h" - -/* Functions to be exported */ -extern void BE_FreeWMCursor(_THIS, WMcursor * cursor); -extern WMcursor *BE_CreateWMCursor(_THIS, - Uint8 * data, Uint8 * mask, int w, int h, - int hot_x, int hot_y); -extern int BE_ShowWMCursor(_THIS, WMcursor * cursor); -extern void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y); -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysvideo.cc b/src/video/bwindow/SDL_sysvideo.cc deleted file mode 100644 index 9610f43ec..000000000 --- a/src/video/bwindow/SDL_sysvideo.cc +++ /dev/null @@ -1,864 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -/* BWindow based framebuffer implementation */ - -#include - -#include "SDL_BWin.h" -#include "SDL_timer.h" - -extern "C" -{ - -#include "../SDL_sysvideo.h" -#include "../../events/SDL_events_c.h" -#include "SDL_sysevents_c.h" -#include "SDL_sysmouse_c.h" -#include "SDL_syswm_c.h" -#include "SDL_lowvideo.h" -#include "../SDL_yuvfuncs.h" -#include "SDL_sysyuv.h" -#include "../blank_cursor.h" - -#define BEOS_HIDDEN_SIZE 32 /* starting hidden window size */ - -/* Initialization/Query functions */ - static int BE_VideoInit(_THIS, SDL_PixelFormat * vformat); - static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format, - Uint32 flags); - static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, - Uint32 flags); - static void BE_UpdateMouse(_THIS); - static int BE_SetColors(_THIS, int firstcolor, int ncolors, - SDL_Color * colors); - static void BE_VideoQuit(_THIS); - -/* Hardware surface functions */ - static int BE_AllocHWSurface(_THIS, SDL_Surface * surface); - static int BE_LockHWSurface(_THIS, SDL_Surface * surface); - static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface); - static void BE_FreeHWSurface(_THIS, SDL_Surface * surface); - - static int BE_ToggleFullScreen(_THIS, int fullscreen); - static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, - Uint32 format, - SDL_Surface * display); - -/* OpenGL functions */ -#if SDL_VIDEO_OPENGL - static int BE_GL_LoadLibrary(_THIS, const char *path); - static void *BE_GL_GetProcAddress(_THIS, const char *proc); - static int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value); - static int BE_GL_MakeCurrent(_THIS); - static void BE_GL_SwapBuffers(_THIS); -#endif - -/* FB driver bootstrap functions */ - - static int BE_Available(void) - { - return (1); - } - - static void BE_DeleteDevice(SDL_VideoDevice * device) - { - SDL_free(device->hidden); - SDL_free(device); - } - - static SDL_VideoDevice *BE_CreateDevice(int devindex) - { - SDL_VideoDevice *device; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); - if (device) { - SDL_memset(device, 0, (sizeof *device)); - device->hidden = (struct SDL_PrivateVideoData *) - SDL_malloc((sizeof *device->hidden)); - } - if ((device == NULL) || (device->hidden == NULL)) { - SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return (0); - } - SDL_memset(device->hidden, 0, (sizeof *device->hidden)); - - /* Set the function pointers */ - /* Initialization/Query functions */ - device->VideoInit = BE_VideoInit; - device->ListModes = BE_ListModes; - device->SetVideoMode = BE_SetVideoMode; - device->ToggleFullScreen = BE_ToggleFullScreen; - device->UpdateMouse = BE_UpdateMouse; - device->CreateYUVOverlay = BE_CreateYUVOverlay; - device->SetColors = BE_SetColors; - device->UpdateRects = NULL; - device->VideoQuit = BE_VideoQuit; - /* Hardware acceleration functions */ - device->AllocHWSurface = BE_AllocHWSurface; - device->CheckHWBlit = NULL; - device->FillHWRect = NULL; - device->SetHWColorKey = NULL; - device->SetHWAlpha = NULL; - device->LockHWSurface = BE_LockHWSurface; - device->UnlockHWSurface = BE_UnlockHWSurface; - device->FlipHWSurface = NULL; - device->FreeHWSurface = BE_FreeHWSurface; -#if SDL_VIDEO_OPENGL - /* OpenGL support */ - device->GL_LoadLibrary = BE_GL_LoadLibrary; - device->GL_GetProcAddress = BE_GL_GetProcAddress; - device->GL_GetAttribute = BE_GL_GetAttribute; - device->GL_MakeCurrent = BE_GL_MakeCurrent; - device->GL_SwapBuffers = BE_GL_SwapBuffers; -#endif - /* Window manager functions */ - device->SetCaption = BE_SetWMCaption; - device->SetIcon = NULL; - device->IconifyWindow = BE_IconifyWindow; - device->GrabInput = NULL; - device->GetWMInfo = BE_GetWMInfo; - /* Cursor manager functions */ - device->FreeWMCursor = BE_FreeWMCursor; - device->CreateWMCursor = BE_CreateWMCursor; - device->ShowWMCursor = BE_ShowWMCursor; - device->WarpWMCursor = BE_WarpWMCursor; - device->MoveWMCursor = NULL; - device->CheckMouseMode = NULL; - /* Event manager functions */ - device->InitOSKeymap = BE_InitOSKeymap; - device->PumpEvents = BE_PumpEvents; - - device->free = BE_DeleteDevice; - - /* Set the driver flags */ - device->handles_any_size = 1; - - return device; - } - - VideoBootStrap BWINDOW_bootstrap = { - "bwindow", "BDirectWindow graphics", - BE_Available, BE_CreateDevice - }; - - static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) - { - int bitsperpixel; - - bitsperpixel = 0; - switch (colorspace) { - case B_CMAP8: - bitsperpixel = 8; - break; - case B_RGB15: - case B_RGBA15: - case B_RGB15_BIG: - case B_RGBA15_BIG: - bitsperpixel = 15; - break; - case B_RGB16: - case B_RGB16_BIG: - bitsperpixel = 16; - break; - case B_RGB32: - case B_RGBA32: - case B_RGB32_BIG: - case B_RGBA32_BIG: - bitsperpixel = 32; - break; - default: - break; - } - return (bitsperpixel); - } - -/* Function to sort the display_list in bscreen */ - static int CompareModes(const void *A, const void *B) - { - const display_mode *a = (display_mode *) A; - const display_mode *b = (display_mode *) B; - - if (a->space == b->space) { - return ((b->virtual_width * b->virtual_height) - - (a->virtual_width * a->virtual_height)); - } else { - return (ColorSpaceToBitsPerPixel(b->space) - - ColorSpaceToBitsPerPixel(a->space)); - } - } - -/* Yes, this isn't the fastest it could be, but it works nicely */ - static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h) - { - SDL_Rect *mode; - int i; - int next_mode; - - /* Check to see if we already have this mode */ - if (SDL_nummodes[index] > 0) { - for (i = SDL_nummodes[index] - 1; i >= 0; --i) { - mode = SDL_modelist[index][i]; - if ((mode->w == w) && (mode->h == h)) { -#ifdef BWINDOW_DEBUG - fprintf(stderr, - "We already have mode %dx%d at %d bytes per pixel\n", - w, h, index + 1); -#endif - return (0); - } - } - } - - /* Set up the new video mode rectangle */ - mode = (SDL_Rect *) SDL_malloc(sizeof *mode); - if (mode == NULL) { - SDL_OutOfMemory(); - return (-1); - } - mode->x = 0; - mode->y = 0; - mode->w = w; - mode->h = h; -#ifdef BWINDOW_DEBUG - fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, - index + 1); -#endif - - /* Allocate the new list of modes, and fill in the new mode */ - next_mode = SDL_nummodes[index]; - SDL_modelist[index] = (SDL_Rect **) - SDL_realloc(SDL_modelist[index], - (1 + next_mode + 1) * sizeof(SDL_Rect *)); - if (SDL_modelist[index] == NULL) { - SDL_OutOfMemory(); - SDL_nummodes[index] = 0; - SDL_free(mode); - return (-1); - } - SDL_modelist[index][next_mode] = mode; - SDL_modelist[index][next_mode + 1] = NULL; - SDL_nummodes[index]++; - - return (0); - } - - int BE_VideoInit(_THIS, SDL_PixelFormat * vformat) - { - display_mode *modes; - uint32 i, nmodes; - int bpp; - BRect bounds; - - /* Initialize the Be Application for appserver interaction */ - if (SDL_InitBeApp() < 0) { - return (-1); - } - - /* It is important that this be created after SDL_InitBeApp() */ - BScreen bscreen; - - /* Save the current display mode */ - bscreen.GetMode(&saved_mode); - _this->info.current_w = saved_mode.virtual_width; - _this->info.current_h = saved_mode.virtual_height; - - /* Determine the screen depth */ - vformat->BitsPerPixel = - ColorSpaceToBitsPerPixel(bscreen.ColorSpace()); - if (vformat->BitsPerPixel == 0) { - SDL_SetError("Unknown BScreen colorspace: 0x%x", - bscreen.ColorSpace()); - return (-1); - } - - /* Get the video modes we can switch to in fullscreen mode */ - bscreen.GetModeList(&modes, &nmodes); - SDL_qsort(modes, nmodes, sizeof *modes, CompareModes); - for (i = 0; i < nmodes; ++i) { - bpp = ColorSpaceToBitsPerPixel(modes[i].space); - //if ( bpp != 0 ) { // There are bugs in changing colorspace - if (modes[i].space == saved_mode.space) { - BE_AddMode(_this, ((bpp + 7) / 8) - 1, - modes[i].virtual_width, modes[i].virtual_height); - } - } - - /* Create the window and view */ - bounds.top = 0; - bounds.left = 0; - bounds.right = BEOS_HIDDEN_SIZE; - bounds.bottom = BEOS_HIDDEN_SIZE; - SDL_Win = new SDL_BWin(bounds); - -#if SDL_VIDEO_OPENGL - /* testgl application doesn't load library, just tries to load symbols */ - /* is it correct? if so we have to load library here */ - BE_GL_LoadLibrary(_this, NULL); -#endif - - /* Create the clear cursor */ - SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask, - BLANK_CWIDTH, BLANK_CHEIGHT, - BLANK_CHOTX, BLANK_CHOTY); - - /* Fill in some window manager capabilities */ - _this->info.wm_available = 1; - - /* We're done! */ - return (0); - } - -/* We support any dimension at our bit-depth */ - SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) - { - SDL_Rect **modes; - - modes = ((SDL_Rect **) 0); - if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { - modes = SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]; - } else { - if (format->BitsPerPixel == _this->screen->format->BitsPerPixel) { - modes = ((SDL_Rect **) - 1); - } - } - return (modes); - } - -/* Various screen update functions available */ - static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects); - - -/* Find the closest display mode for fullscreen */ - static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp, - display_mode * mode) - { - BScreen bscreen; - uint32 i, nmodes; - SDL_Rect **modes; - display_mode *dmodes; - display_mode current; - float current_refresh; - bscreen.GetMode(¤t); - current_refresh = (1000 * current.timing.pixel_clock) / - (current.timing.h_total * current.timing.v_total); - - modes = SDL_modelist[((bpp + 7) / 8) - 1]; - - bool exactmatch = false; - for (uint32 x = 0; modes[x]; x++) { - if (modes[x]->w == width && modes[x]->h == height) { - exactmatch = true; - i = x; - break; - } - } - if (!exactmatch) { - for (i = 0; modes[i] && (modes[i]->w > width) && - (modes[i]->h > height); ++i) { - /* still looking */ - } - if (!modes[i] || (modes[i]->w < width) || (modes[i]->h < height)) { - /* We went too far */ - --i; - } - } - width = modes[i]->w; - height = modes[i]->h; - bscreen.GetModeList(&dmodes, &nmodes); - for (i = 0; i < nmodes; ++i) { - if ((bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) && - (width == dmodes[i].virtual_width) && - (height == dmodes[i].virtual_height)) { - break; - } - } - if (i != nmodes) { - *mode = dmodes[i]; - if ((mode->virtual_width <= current.virtual_width) && - (mode->virtual_height <= current.virtual_height)) { - float new_refresh = (1000 * mode->timing.pixel_clock) / - (mode->timing.h_total * mode->timing.v_total); - if (new_refresh < current_refresh) { - mode->timing.pixel_clock = - (uint32) ((mode->timing.h_total * - mode->timing.v_total) * - current_refresh / 1000); - } - } - return true; - } else { - return false; - } - } - - static int BE_SetFullScreen(_THIS, SDL_Surface * screen, int fullscreen) - { - int was_fullscreen; - bool needs_unlock; - BScreen bscreen; - BRect bounds; - display_mode mode; - int width, height, bpp; - - /* Set the fullscreen mode */ - was_fullscreen = SDL_Win->IsFullScreen(); - SDL_Win->SetFullScreen(fullscreen); - fullscreen = SDL_Win->IsFullScreen(); - - width = screen->w; - height = screen->h; - - /* Set the appropriate video mode */ - if (fullscreen) { - bpp = screen->format->BitsPerPixel; - bscreen.GetMode(&mode); - if ((bpp != ColorSpaceToBitsPerPixel(mode.space)) || - (width != mode.virtual_width) || - (height != mode.virtual_height)) { - if (BE_FindClosestFSMode(_this, width, height, bpp, &mode)) { - bscreen.SetMode(&mode); - /* This simply stops the next resize event from being - * sent to the SDL handler. - */ - SDL_Win->InhibitResize(); - } else { - fullscreen = 0; - SDL_Win->SetFullScreen(fullscreen); - } - } - } - if (was_fullscreen && !fullscreen) { - bscreen.SetMode(&saved_mode); - } - - if (SDL_Win->Lock()) { - int xoff, yoff; - if (SDL_Win->Shown()) { - needs_unlock = 1; - SDL_Win->Hide(); - } else { - needs_unlock = 0; - } - /* This resizes the window and view area, but inhibits resizing - * of the BBitmap due to the InhibitResize call above. Thus the - * bitmap (pixel data) never changes. - */ - SDL_Win->ResizeTo(width, height); - bounds = bscreen.Frame(); - /* Calculate offsets - used either to center window - * (windowed mode) or to set drawing offsets (fullscreen mode) - */ - xoff = (bounds.IntegerWidth() - width) / 2; - yoff = (bounds.IntegerHeight() - height) / 2; - if (fullscreen) { - /* Set offset for drawing */ - SDL_Win->SetXYOffset(xoff, yoff); - } else { - /* Center window and reset the drawing offset */ - SDL_Win->SetXYOffset(0, 0); - } - if (!needs_unlock || was_fullscreen) { - /* Center the window the first time */ - SDL_Win->MoveTo(xoff > 0 ? (float) xoff : 0.0f, - yoff > 0 ? (float) yoff : 0.0f); - } - SDL_Win->Show(); - - /* Unlock the window manually after the first Show() */ - if (needs_unlock) { - SDL_Win->Unlock(); - } - } - - /* Set the fullscreen flag in the screen surface */ - if (fullscreen) { - screen->flags |= SDL_FULLSCREEN; - } else { - screen->flags &= ~SDL_FULLSCREEN; - } - return (1); - } - - static int BE_ToggleFullScreen(_THIS, int fullscreen) - { - return BE_SetFullScreen(_this, _this->screen, fullscreen); - } - -/* FIXME: check return values and cleanup here */ - SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current, - int width, int height, int bpp, Uint32 flags) - { - BScreen bscreen; - BBitmap *bbitmap; - BRect bounds; - Uint32 gl_flags = 0; - - /* Only RGB works on r5 currently */ - gl_flags = BGL_RGB; - if (_this->gl_config.double_buffer) - gl_flags |= BGL_DOUBLE; - else - gl_flags |= BGL_SINGLE; - if (_this->gl_config.alpha_size > 0 || bpp == 32) - gl_flags |= BGL_ALPHA; - if (_this->gl_config.depth_size > 0) - gl_flags |= BGL_DEPTH; - if (_this->gl_config.stencil_size > 0) - gl_flags |= BGL_STENCIL; - if (_this->gl_config.accum_red_size > 0 - || _this->gl_config.accum_green_size > 0 - || _this->gl_config.accum_blue_size > 0 - || _this->gl_config.accum_alpha_size > 0) - gl_flags |= BGL_ACCUM; - - /* Create the view for this window, using found flags */ - if (SDL_Win->CreateView(flags, gl_flags) < 0) { - return (NULL); - } - - current->flags = 0; /* Clear flags */ - current->w = width; - current->h = height; - SDL_Win->SetType(B_TITLED_WINDOW); - if (flags & SDL_NOFRAME) { - current->flags |= SDL_NOFRAME; - SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); - } else { - /* FIXME: What was SDL_INTERNALOPENGL? This used it before, but it - isn't defined anywhere. */ - if ((flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL - /*SDL_INTERNALOPENGL*/)) { - current->flags |= SDL_RESIZABLE; - /* We don't want opaque resizing (TM). :-) */ - SDL_Win->SetFlags(B_OUTLINE_RESIZE); - } else { - SDL_Win->SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); - } - } - - if (flags & SDL_OPENGL /*SDL_INTERNALOPENGL*/) { - current->flags |= SDL_OPENGL /*SDL_INTERNALOPENGL*/; - current->pitch = 0; - current->pixels = NULL; - _this->UpdateRects = NULL; - } else { - /* Create the BBitmap framebuffer */ - bounds.top = 0; - bounds.left = 0; - bounds.right = width - 1; - bounds.bottom = height - 1; - bbitmap = new BBitmap(bounds, bscreen.ColorSpace()); - if (!bbitmap->IsValid()) { - SDL_SetError("Couldn't create screen bitmap"); - delete bbitmap; - return (NULL); - } - current->pitch = bbitmap->BytesPerRow(); - current->pixels = (void *) bbitmap->Bits(); - SDL_Win->SetBitmap(bbitmap); - _this->UpdateRects = BE_NormalUpdate; - } - - /* Set the correct fullscreen mode */ - BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0); - - /* We're done */ - return (current); - } - -/* Update the current mouse state and position */ - void BE_UpdateMouse(_THIS) - { - BPoint point; - uint32 buttons; - - if (SDL_Win->Lock()) { - /* Get new input state, if still active */ - if (SDL_Win->IsActive()) { - (SDL_Win->View())->GetMouse(&point, &buttons, true); - } else { - point.x = -1; - point.y = -1; - } - SDL_Win->Unlock(); - - if ((point.x >= 0) && (point.x < SDL_VideoSurface->w) && - (point.y >= 0) && (point.y < SDL_VideoSurface->h)) { - SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); - SDL_PrivateMouseMotion(0, 0, - (Sint16) point.x, (Sint16) point.y); - } else { - SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); - } - } - } - -/* We don't actually allow hardware surfaces other than the main one */ - static int BE_AllocHWSurface(_THIS, SDL_Surface * surface) - { - return (-1); - } - static void BE_FreeHWSurface(_THIS, SDL_Surface * surface) - { - return; - } - static int BE_LockHWSurface(_THIS, SDL_Surface * surface) - { - return (0); - } - static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface) - { - return; - } - - static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects) - { - if (SDL_Win->BeginDraw()) { - int i; - - for (i = 0; i < numrects; ++i) { - BRect rect; - - rect.top = rects[i].y; - rect.left = rects[i].x; - rect.bottom = rect.top + rects[i].h - 1; - rect.right = rect.left + rects[i].w - 1; - SDL_Win->DrawAsync(rect); - } - SDL_Win->EndDraw(); - } - } - -#if SDL_VIDEO_OPENGL -/* Passing a NULL path means load pointers from the application */ - int BE_GL_LoadLibrary(_THIS, const char *path) - { - if (path == NULL) { - if (_this->gl_config.dll_handle == NULL) { - image_info info; - int32 cookie = 0; - while (get_next_image_info(0, &cookie, &info) == B_OK) { - void *location = NULL; - if (get_image_symbol - ((image_id) cookie, "glBegin", - B_SYMBOL_TYPE_ANY, &location) == B_OK) { - _this->gl_config.dll_handle = (void *) cookie; - _this->gl_config.driver_loaded = 1; - SDL_strlcpy(_this->gl_config.driver_path, - "libGL.so", - SDL_arraysize(_this-> - gl_config.driver_path)); - } - } - } - } else { - /* - FIXME None of BeOS libGL.so implementations have exported functions - to load BGLView, which should be reloaded from new lib. - So for now just "load" linked libGL.so :( - */ - if (_this->gl_config.dll_handle == NULL) { - return BE_GL_LoadLibrary(_this, NULL); - } - - /* Unload old first */ - /*if (_this->gl_config.dll_handle != NULL) { */ - /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */ - /* image_info info; - if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) { - if (info.type != B_APP_IMAGE) { - unload_add_on((image_id)_this->gl_config.dll_handle); - } - } - - } - - if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) { - _this->gl_config.driver_loaded = 1; - SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); - } */ - } - - if (_this->gl_config.dll_handle != NULL) { - return 0; - } else { - _this->gl_config.dll_handle = NULL; - _this->gl_config.driver_loaded = 0; - *_this->gl_config.driver_path = '\0'; - return -1; - } - } - - void *BE_GL_GetProcAddress(_THIS, const char *proc) - { - if (_this->gl_config.dll_handle != NULL) { - void *location = NULL; - status_t err; - if ((err = - get_image_symbol((image_id) _this->gl_config.dll_handle, - proc, B_SYMBOL_TYPE_ANY, - &location)) == B_OK) { - return location; - } else { - SDL_SetError("Couldn't find OpenGL symbol"); - return NULL; - } - } else { - SDL_SetError("OpenGL library not loaded"); - return NULL; - } - } - - int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) - { - /* - FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values - */ - switch (attrib) { - case SDL_GL_RED_SIZE: - glGetIntegerv(GL_RED_BITS, (GLint *) value); - break; - case SDL_GL_GREEN_SIZE: - glGetIntegerv(GL_GREEN_BITS, (GLint *) value); - break; - case SDL_GL_BLUE_SIZE: - glGetIntegerv(GL_BLUE_BITS, (GLint *) value); - break; - case SDL_GL_ALPHA_SIZE: - glGetIntegerv(GL_ALPHA_BITS, (GLint *) value); - break; - case SDL_GL_DOUBLEBUFFER: - glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value); - break; - case SDL_GL_BUFFER_SIZE: - int v; - glGetIntegerv(GL_RED_BITS, (GLint *) & v); - *value = v; - glGetIntegerv(GL_GREEN_BITS, (GLint *) & v); - *value += v; - glGetIntegerv(GL_BLUE_BITS, (GLint *) & v); - *value += v; - glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v); - *value += v; - break; - case SDL_GL_DEPTH_SIZE: - glGetIntegerv(GL_DEPTH_BITS, (GLint *) value); /* Mesa creates 16 only? r5 always 32 */ - break; - case SDL_GL_STENCIL_SIZE: - glGetIntegerv(GL_STENCIL_BITS, (GLint *) value); - break; - case SDL_GL_ACCUM_RED_SIZE: - glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value); - break; - case SDL_GL_ACCUM_GREEN_SIZE: - glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value); - break; - case SDL_GL_ACCUM_BLUE_SIZE: - glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value); - break; - case SDL_GL_ACCUM_ALPHA_SIZE: - glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value); - break; - case SDL_GL_STEREO: - case SDL_GL_MULTISAMPLEBUFFERS: - case SDL_GL_MULTISAMPLESAMPLES: - default: - *value = 0; - return (-1); - } - return 0; - } - - int BE_GL_MakeCurrent(_THIS) - { - /* FIXME: should we glview->unlock and then glview->lock()? */ - return 0; - } - - void BE_GL_SwapBuffers(_THIS) - { - SDL_Win->SwapBuffers(); - } -#endif - -/* Is the system palette settable? */ - int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) - { - int i; - SDL_Palette *palette; - const color_map *cmap = BScreen().ColorMap(); - - /* Get the screen colormap */ - palette = _this->screen->format->palette; - for (i = 0; i < 256; ++i) { - palette->colors[i].r = cmap->color_list[i].red; - palette->colors[i].g = cmap->color_list[i].green; - palette->colors[i].b = cmap->color_list[i].blue; - } - return (0); - } - - void BE_VideoQuit(_THIS) - { - int i, j; - - SDL_Win->Quit(); - SDL_Win = NULL; - - if (SDL_BlankCursor != NULL) { - BE_FreeWMCursor(_this, SDL_BlankCursor); - SDL_BlankCursor = NULL; - } - for (i = 0; i < NUM_MODELISTS; ++i) { - if (SDL_modelist[i]) { - for (j = 0; SDL_modelist[i][j]; ++j) { - SDL_free(SDL_modelist[i][j]); - } - SDL_free(SDL_modelist[i]); - SDL_modelist[i] = NULL; - } - } - /* Restore the original video mode */ - if (_this->screen) { - if ((_this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { - BScreen bscreen; - bscreen.SetMode(&saved_mode); - } - _this->screen->pixels = NULL; - } -#if SDL_VIDEO_OPENGL - if (_this->gl_config.dll_handle != NULL) - unload_add_on((image_id) _this->gl_config.dll_handle); -#endif - - SDL_QuitBeApp(); - } - -}; /* Extern C */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_syswm.cc b/src/video/bwindow/SDL_syswm.cc deleted file mode 100644 index 8c0a52ed1..000000000 --- a/src/video/bwindow/SDL_syswm.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include "SDL_BWin.h" - -extern "C" -{ - -#include "SDL_syswm_c.h" -#include "SDL_error.h" - - void BE_SetWMCaption(_THIS, const char *title, const char *icon) - { - SDL_Win->SetTitle(title); - } - - int BE_IconifyWindow(_THIS) - { - SDL_Win->Minimize(true); - } - - int BE_GetWMInfo(_THIS, SDL_SysWMinfo * info) - { - if (info->version.major <= SDL_MAJOR_VERSION) { - return 1; - } else { - SDL_SetError("Application not compiled with SDL %d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION); - return -1; - } - } - -}; /* Extern C */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_syswm_c.h b/src/video/bwindow/SDL_syswm_c.h deleted file mode 100644 index b38b86a58..000000000 --- a/src/video/bwindow/SDL_syswm_c.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include "SDL_syswm.h" -#include "SDL_lowvideo.h" - - -/* Functions to be exported */ -extern void BE_SetWMCaption(_THIS, const char *title, const char *icon); -extern int BE_IconifyWindow(_THIS); -extern int BE_GetWMInfo(_THIS, SDL_SysWMinfo * info); -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysyuv.cc b/src/video/bwindow/SDL_sysyuv.cc deleted file mode 100644 index 50a0266f1..000000000 --- a/src/video/bwindow/SDL_sysyuv.cc +++ /dev/null @@ -1,321 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -/* This is the BeOS version of SDL YUV video overlays */ - -#include "SDL_video.h" -#include "SDL_sysyuv.h" -#include "../SDL_yuvfuncs.h" - -extern "C" -{ - -/* The functions used to manipulate software video overlays */ - static struct private_yuvhwfuncs be_yuvfuncs = { - BE_LockYUVOverlay, - BE_UnlockYUVOverlay, - BE_DisplayYUVOverlay, - BE_FreeYUVOverlay - }; - - BBitmap *BE_GetOverlayBitmap(BRect bounds, color_space cs) - { - BBitmap *bbitmap; - bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs); - if (!bbitmap || bbitmap->InitCheck() != B_OK) { - delete bbitmap; - return 0; - } - overlay_restrictions r; - bbitmap->GetOverlayRestrictions(&r); - uint32 width = bounds.IntegerWidth() + 1; - uint32 height = bounds.IntegerHeight() + 1; - uint32 width_padding = 0; - uint32 height_padding = 0; - if ((r.source.horizontal_alignment != 0) || - (r.source.vertical_alignment != 0)) { - delete bbitmap; - return 0; - } - if (r.source.width_alignment != 0) { - uint32 aligned_width = r.source.width_alignment + 1; - if (width % aligned_width > 0) { - width_padding = aligned_width - width % aligned_width; - } - } - if (r.source.height_alignment != 0) { - uint32 aligned_height = r.source.height_alignment + 1; - if (height % aligned_height > 0) { - fprintf(stderr, "GetOverlayBitmap failed height alignment\n"); - fprintf(stderr, "- height = %lu, aligned_height = %lu\n", - height, aligned_height); - delete bbitmap; - return 0; - } - } - if ((r.source.min_width > width) || - (r.source.min_height > height) || - (r.source.max_width < width) || (r.source.max_height < height)) { - fprintf(stderr, "GetOverlayBitmap failed bounds tests\n"); - delete bbitmap; - return 0; - } - if ((width_padding != 0) || (height_padding != 0)) { - delete bbitmap; - bounds.Set(bounds.left, bounds.top, - bounds.right + width_padding, - bounds.bottom + height_padding); - bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs); - if (!bbitmap || bbitmap->InitCheck() != B_OK) { - fprintf(stderr, "GetOverlayBitmap failed late\n"); - delete bbitmap; - return 0; - } - } - return bbitmap; - } - -// See [btw: Cb=U, Cr=V] -// See also http://www.fourcc.org/indexyuv.htm - enum color_space convert_color_space(Uint32 format) - { - switch (format) { - case SDL_YV12_OVERLAY: - return B_YUV9; - case SDL_IYUV_OVERLAY: - return B_YUV12; - case SDL_YUY2_OVERLAY: - return B_YCbCr422; - case SDL_UYVY_OVERLAY: - return B_YUV422; - case SDL_YVYU_OVERLAY: // not supported on beos? - return B_NO_COLOR_SPACE; - default: - return B_NO_COLOR_SPACE; - } - } - -// See SDL_video.h - int count_planes(Uint32 format) - { - switch (format) { - case SDL_YV12_OVERLAY: - case SDL_IYUV_OVERLAY: - return 3; - case SDL_YUY2_OVERLAY: - case SDL_UYVY_OVERLAY: - case SDL_YVYU_OVERLAY: - return 1; - default: - return 0; - } - } - - SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, - Uint32 format, SDL_Surface * display) - { - SDL_Overlay *overlay; - struct private_yuvhwdata *hwdata; - BBitmap *bbitmap; - int planes; - BRect bounds; - color_space cs; - - /* find the appropriate BeOS colorspace descriptor */ - cs = convert_color_space(format); - if (cs == B_NO_COLOR_SPACE) { - return NULL; - } - - /* count planes */ - planes = count_planes(format); - if (planes == 0) { - return NULL; - } - /* TODO: figure out planar modes, if anyone cares */ - if (planes == 3) { - return NULL; - } - - /* Create the overlay structure */ - overlay = (SDL_Overlay *) SDL_calloc(1, sizeof(SDL_Overlay)); - - if (overlay == NULL) { - SDL_OutOfMemory(); - return NULL; - } - - /* Fill in the basic members */ - overlay->format = format; - overlay->w = width; - overlay->h = height; - overlay->hwdata = NULL; - - /* Set up the YUV surface function structure */ - overlay->hwfuncs = &be_yuvfuncs; - - /* Create the pixel data and lookup tables */ - hwdata = - (struct private_yuvhwdata *) SDL_calloc(1, - sizeof(struct - private_yuvhwdata)); - - if (hwdata == NULL) { - SDL_OutOfMemory(); - SDL_FreeYUVOverlay(overlay); - return NULL; - } - - overlay->hwdata = hwdata; - overlay->hwdata->display = display; - overlay->hwdata->bview = NULL; - overlay->hwdata->bbitmap = NULL; - overlay->hwdata->locked = 0; - - /* Create the BBitmap framebuffer */ - bounds.top = 0; - bounds.left = 0; - bounds.right = width - 1; - bounds.bottom = height - 1; - - BView *bview = - new BView(bounds, "overlay", B_FOLLOW_NONE, B_WILL_DRAW); - if (!bview) { - SDL_OutOfMemory(); - SDL_FreeYUVOverlay(overlay); - return NULL; - } - overlay->hwdata->bview = bview; - overlay->hwdata->first_display = true; - bview->Hide(); - - bbitmap = BE_GetOverlayBitmap(bounds, cs); - if (!bbitmap) { - overlay->hwdata->bbitmap = NULL; - SDL_FreeYUVOverlay(overlay); - return NULL; - } - overlay->hwdata->bbitmap = bbitmap; - - overlay->planes = planes; - overlay->pitches = - (Uint16 *) SDL_calloc(overlay->planes, sizeof(Uint16)); - overlay->pixels = - (Uint8 **) SDL_calloc(overlay->planes, sizeof(Uint8 *)); - if (!overlay->pitches || !overlay->pixels) { - SDL_OutOfMemory(); - SDL_FreeYUVOverlay(overlay); - return (NULL); - } - - overlay->pitches[0] = bbitmap->BytesPerRow(); - overlay->pixels[0] = (Uint8 *) bbitmap->Bits(); - overlay->hw_overlay = 1; - - if (SDL_Win->LockWithTimeout(1000000) != B_OK) { - SDL_FreeYUVOverlay(overlay); - return (NULL); - } - BView *view = SDL_Win->View(); - view->AddChild(bview); - rgb_color key; - bview->SetViewOverlay(bbitmap, bounds, bview->Bounds(), &key, - B_FOLLOW_ALL, - B_OVERLAY_FILTER_HORIZONTAL | - B_OVERLAY_FILTER_VERTICAL); - bview->SetViewColor(key); - bview->Flush(); - SDL_Win->Unlock(); - - current_overlay = overlay; - - return overlay; - } - - int BE_LockYUVOverlay(_THIS, SDL_Overlay * overlay) - { - if (overlay == NULL) { - return 0; - } - - overlay->hwdata->locked = 1; - return 0; - } - - void BE_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay) - { - if (overlay == NULL) { - return; - } - - overlay->hwdata->locked = 0; - } - - int BE_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src, - SDL_Rect * dst) - { - if ((overlay == NULL) || (overlay->hwdata == NULL) - || (overlay->hwdata->bview == NULL) || (SDL_Win->View() == NULL)) { - return -1; - } - if (SDL_Win->LockWithTimeout(50000) != B_OK) { - return 0; - } - BView *bview = overlay->hwdata->bview; - if (SDL_Win->IsFullScreen()) { - int left, top; - SDL_Win->GetXYOffset(left, top); - bview->MoveTo(left + dst->x, top + dst->y); - } else { - bview->MoveTo(dst->x, dst->y); - } - bview->ResizeTo(dst->w, dst->h); - bview->Flush(); - if (overlay->hwdata->first_display) { - bview->Show(); - overlay->hwdata->first_display = false; - } - SDL_Win->Unlock(); - - return 0; - } - - void BE_FreeYUVOverlay(_THIS, SDL_Overlay * overlay) - { - if (overlay == NULL) { - return; - } - - if (overlay->hwdata == NULL) { - return; - } - - current_overlay = NULL; - - delete overlay->hwdata->bbitmap; - - SDL_free(overlay->hwdata); - } - -}; // extern "C" - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_sysyuv.h b/src/video/bwindow/SDL_sysyuv.h deleted file mode 100644 index 69d40a1ba..000000000 --- a/src/video/bwindow/SDL_sysyuv.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - - -#ifndef __SDL_SYS_YUV_H__ -#define __SDL_SYS_YUV_H__ - -/* This is the BeOS implementation of YUV video overlays */ - -#include "SDL_video.h" -#include "SDL_lowvideo.h" - -extern "C" -{ - - struct private_yuvhwdata - { -/* FRAMEDATA* CurrentFrameData; - FRAMEDATA* FrameData0; - FRAMEDATA* FrameData1; - PgScalerProps_t props; - PgScalerCaps_t caps; - PgVideoChannel_t* channel; - PhArea_t CurrentViewPort; - PhPoint_t CurrentWindowPos; - long format; - int scaler_on; - int current; - long YStride; - long VStride; - long UStride; - int ischromakey; - long chromakey; - int forcedredraw; - unsigned long State; - long flags; -*/ - SDL_Surface *display; - BView *bview; - bool first_display; - BBitmap *bbitmap; - int locked; - }; - - extern BBitmap *BE_GetOverlayBitmap(BRect bounds, color_space cs); - extern SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, - Uint32 format, - SDL_Surface * display); - extern int BE_LockYUVOverlay(_THIS, SDL_Overlay * overlay); - extern void BE_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay); - extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, - SDL_Rect * src, SDL_Rect * dst); - extern void BE_FreeYUVOverlay(_THIS, SDL_Overlay * overlay); - -}; - -#endif /* __SDL_PH_YUV_H__ */ -/* vi: set ts=4 sw=4 expandtab: */ From 9a7e7f87f9e49c2f85b1fa65898073a8d1f729ba Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 13 Jul 2011 09:29:43 +0000 Subject: [PATCH 05/27] Renamed all .c files in src/video/bwindow to .cc files. --- src/video/bwindow/{SDL_bclipboard.c => SDL_bclipboard.cc} | 0 src/video/bwindow/{SDL_bmodes.c => SDL_bmodes.cc} | 0 src/video/bwindow/{SDL_bopengl.c => SDL_bopengl.cc} | 0 src/video/bwindow/{SDL_bvideo.c => SDL_bvideo.cc} | 0 src/video/bwindow/{SDL_bwindow.c => SDL_bwindow.cc} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/video/bwindow/{SDL_bclipboard.c => SDL_bclipboard.cc} (100%) rename src/video/bwindow/{SDL_bmodes.c => SDL_bmodes.cc} (100%) rename src/video/bwindow/{SDL_bopengl.c => SDL_bopengl.cc} (100%) rename src/video/bwindow/{SDL_bvideo.c => SDL_bvideo.cc} (100%) rename src/video/bwindow/{SDL_bwindow.c => SDL_bwindow.cc} (100%) diff --git a/src/video/bwindow/SDL_bclipboard.c b/src/video/bwindow/SDL_bclipboard.cc similarity index 100% rename from src/video/bwindow/SDL_bclipboard.c rename to src/video/bwindow/SDL_bclipboard.cc diff --git a/src/video/bwindow/SDL_bmodes.c b/src/video/bwindow/SDL_bmodes.cc similarity index 100% rename from src/video/bwindow/SDL_bmodes.c rename to src/video/bwindow/SDL_bmodes.cc diff --git a/src/video/bwindow/SDL_bopengl.c b/src/video/bwindow/SDL_bopengl.cc similarity index 100% rename from src/video/bwindow/SDL_bopengl.c rename to src/video/bwindow/SDL_bopengl.cc diff --git a/src/video/bwindow/SDL_bvideo.c b/src/video/bwindow/SDL_bvideo.cc similarity index 100% rename from src/video/bwindow/SDL_bvideo.c rename to src/video/bwindow/SDL_bvideo.cc diff --git a/src/video/bwindow/SDL_bwindow.c b/src/video/bwindow/SDL_bwindow.cc similarity index 100% rename from src/video/bwindow/SDL_bwindow.c rename to src/video/bwindow/SDL_bwindow.cc From 63c52052ea52e926a0e23a58dab946fe43f9a0f9 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 13 Jul 2011 09:37:00 +0000 Subject: [PATCH 06/27] Fixed video compile(?) --- configure.in | 1 + src/main/beos/SDL_BApp.h | 108 +++++++++++++++++++++++++++---- src/main/beos/SDL_BeApp.cc | 8 +-- src/video/bwindow/SDL_bopengl.cc | 8 ++- src/video/bwindow/SDL_bopengl.h | 14 ++++ 5 files changed, 120 insertions(+), 19 deletions(-) diff --git a/configure.in b/configure.in index 1b2a07f26..9daef39b5 100644 --- a/configure.in +++ b/configure.in @@ -1238,6 +1238,7 @@ CheckBWINDOW() { if test x$enable_video = xyes; then AC_DEFINE(SDL_VIDEO_DRIVER_BWINDOW, 1, [ ]) + # SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc" .cc sources have been removed SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc" have_video=yes fi diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index d42960117..5932b9af3 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -33,10 +33,13 @@ extern "C" { #ifdef __cplusplus } + +#include /* Vector should only be included if we use a C++ + compiler */ + #endif -#include /* Forward declarations */ @@ -71,6 +74,17 @@ class SDL_BApp : public BApplication { public: SDL_BApp(const char* signature) : BApplication(signature) { +#ifndef __cplusplus + /* Set vector imitation variables */ + _ResizeArray(); + _size = 0; + _length = 0; +#endif + } + virtual ~SDL_BApp() { +#ifndef __cplusplus + SDL_free(window_map); +#endif } /* Event-handling functions */ virtual void MessageReceived(BMessage* message) { @@ -145,20 +159,22 @@ public: /* Window creation/destruction methods */ int32 GetID(SDL_Window *win) { int32 i; - for(i = 0; i < window_map.size(); ++i) { - if( window_map[i] == NULL ) { - window_map[i] = win; + for(i = 0; i < _GetNumWindowSlots(); ++i) { + if( _GetSDLWindow(i) == NULL ) { + _SetSDLWindow(win, i); return i; } } /* Expand the vector if all slots are full */ - if( i == window_map.size() ) { - window_map.push_back(win); + if( i == _GetNumWindowSlots() ) { + _PushBackWindow(win); return i; } } + /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is + there another way to do this? */ void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ private: @@ -171,7 +187,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendWindowEvent(win, sdlEventType, 0, 0); } @@ -186,7 +202,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendMouseMotion(win, 0, dx, dy); } @@ -201,7 +217,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendMouseButton(win, state, button); } @@ -216,7 +232,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendMouseWheel(win, xTicks, yTicks); } @@ -241,7 +257,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); if(bSetFocus) { SDL_SetMouseFocus(win); } else if(SDL_GetMouseFocus() == win) { @@ -260,7 +276,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); if(bSetFocus) { SDL_SetKeyboardFocus(win); } else if(SDL_GetKeyboardFocus() == win) { @@ -281,7 +297,7 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos); } @@ -297,16 +313,80 @@ private: ) { return; } - win = window_map[winID]; + win = _GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); } bool _GetWinID(BMessage *msg, int32 *winID) { return msg->FindInt32("window-id", winID) == B_OK; } + + + + /* Vector imitators */ + SDL_Window *_GetSDLWindow(int32 winID) { + return window_map[winID]; + } + void _SetSDLWindow(SDL_Window *win, int32 winID) { + window_map[winID] = win; + } + + int32 _GetNumWindowSlots() { +#ifdef __cplusplus + return window_map.size(); +#else + return _size; +#endif + } + + + void _PopBackWindow() { +#ifdef __cplusplus + window_map.pop_back(); +#else + --_size; +#endif + } + + void _PushBackWindow(SDL_Window *win) { +#ifdef __cplusplus + window_map.push_back(win); +#else + /* Resize array */ + if(_length == _size) { + _ResizeArray(); + } + + window_map[_size] = win; + ++_size; +#endif + } + +#ifndef __cplusplus + _ResizeArray() { + _length += 4; /* Increase capacity by some arbitrary number */ + SDL_Window *temp = (SDL_Window*)SDL_calloc(_length, + sizeof(SDL_Window*)); + + /* Move windows from old list to new list */ + int32 i; + for(i = 0; i < _size; ++i) { + temp[i] = window_map[i]; + } + SDL_free(window_map); + window_map = temp; + } +#endif + /* Members */ +#ifdef __cplusplus vector window_map; /* Keeps track of SDL_Windows by index-id */ +#else + int32 _size; + int32 _length; + SDL_Window *window_map; +#endif }; #endif diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index a31465e5e..3a7905da4 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -115,10 +115,10 @@ SDL_QuitBeApp(void) /* SDL_BApp functions */ void SDL_BApp::ClearID(SDL_BWin *bwin) { - window_map[bwin->GetID()] = NULL; - int32 i = window_map.size() - 1; - while(i >= 0 && window_map[i] == NULL) { - window_map.pop_back(); + _SetSDLWindow(NULL, bwin->GetID()); + int32 i = _GetNumWindowSlots() - 1; + while(i >= 0 && _GetSDLWindow(i) == NULL) { + _PopBackWindow(); --i; } } diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index 4e8ae5225..a81820b08 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -20,8 +20,10 @@ */ #include "SDL_bopengl.h" -#include "../SDL_sysvideo.h" +#ifdef __cplusplus +extern "C" { +#endif /* Passing a NULL path means load pointers from the application */ int BE_GL_LoadLibrary(_THIS, const char *path) @@ -193,3 +195,7 @@ int BE_GL_MakeCurrent(_THIS) SDL_Win->SwapBuffers(); } #endif + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bopengl.h b/src/video/bwindow/SDL_bopengl.h index de32975b7..062b635d0 100644 --- a/src/video/bwindow/SDL_bopengl.h +++ b/src/video/bwindow/SDL_bopengl.h @@ -21,7 +21,21 @@ #ifndef SDL_BOPENGL_H #define SDL_BOPENGL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../SDL_sysvideo.h" + + + extern int BE_GL_LoadLibrary(_THIS, const char *path); extern void *BE_GL_GetProcAddress(_THIS, const char *proc); extern int BE_GL_MakeCurrent(_THIS); + +#ifdef __cplusplus +} +#endif + #endif From 569fcd280ca1b27e74c7f7e002b22a687edff6b7 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Thu, 14 Jul 2011 17:58:47 +0000 Subject: [PATCH 07/27] Should compile now (fixed typos(?)) --- src/power/beos/SDL_syspower.c | 7 +++++-- src/thread/beos/SDL_systhread.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/power/beos/SDL_syspower.c b/src/power/beos/SDL_syspower.c index 547ec47fc..136a01dfb 100644 --- a/src/power/beos/SDL_syspower.c +++ b/src/power/beos/SDL_syspower.c @@ -50,7 +50,8 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent) uint8 battery_flags; uint8 battery_life; uint32 battery_time; - + int rc; /* FIXME: This was undefined before; not sure what type it is */ + if (fd == -1) { return SDL_FALSE; /* maybe some other method will work? */ } @@ -77,7 +78,9 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent) if (battery_status == 0xFF) { battery_flags = 0xFF; } else { - battery_flags = (1 << status.battery_status); + battery_flags = (1 << battery_status); /* FIXME: Used to be + status.battery_status, + not sure why */ } } diff --git a/src/thread/beos/SDL_systhread.c b/src/thread/beos/SDL_systhread.c index 799513153..5f49d8734 100644 --- a/src/thread/beos/SDL_systhread.c +++ b/src/thread/beos/SDL_systhread.c @@ -90,7 +90,7 @@ SDL_ThreadID(void) } int -SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority) +SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int32 value; From a6ec7506e1b8e094006cd865666cc697d89f2160 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 20 Jul 2011 19:25:38 +0000 Subject: [PATCH 08/27] Framebuffer support in progress. --- src/video/bwindow/SDL_BWin.h | 20 ++- src/video/bwindow/SDL_bevents.cc | 33 +++++ src/video/bwindow/SDL_bevents.h | 37 +++++ src/video/bwindow/SDL_bmodes.cc | 226 ++++++++++++++++++++++++------- src/video/bwindow/SDL_bmodes.h | 16 +++ src/video/bwindow/SDL_bvideo.cc | 22 +-- src/video/bwindow/SDL_bvideo.h | 1 + src/video/bwindow/SDL_bwindow.cc | 26 ++-- 8 files changed, 306 insertions(+), 75 deletions(-) create mode 100644 src/video/bwindow/SDL_bevents.cc create mode 100644 src/video/bwindow/SDL_bevents.h diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 94042966b..f9139652e 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -66,17 +66,16 @@ class SDL_BWin:public BDirectWindow B_TITLED_WINDOW, 0) { last_buttons = 0; - +printf("SDL_BWin.h: 69\n"); the_view = NULL; #if SDL_VIDEO_OPENGL SDL_GLView = NULL; #endif SDL_View = NULL; - Unlock(); _shown = false; inhibit_resize = false; mouse_focused = false; - prev_frame = NULL; + prev_frame = NULL; printf("SDL_BWin.h: 79\n"); } virtual ~ SDL_BWin() @@ -151,6 +150,12 @@ class SDL_BWin:public BDirectWindow return (retval); } + + /* * * * * Framebuffering* * * * */ + virtual void DirectConnected(direct_buffer_info *info) { + } + + /* * * * * Event sending * * * * */ /* Hook functions */ virtual void FrameMoved(BPoint origin) { @@ -460,13 +465,16 @@ private: /* Add any mouse button events */ if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) { - _SendMouseButton(SDL_BUTTON_LEFT, buttons & B_PRIMARY_MOUSE_BUTTON); + _SendMouseButton(SDL_BUTTON_LEFT, buttons & + B_PRIMARY_MOUSE_BUTTON); } if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) { - _SendMouseButton(SDL_BUTTON_RIGHT, buttons & B_PRIMARY_MOUSE_BUTTON); + _SendMouseButton(SDL_BUTTON_RIGHT, buttons & + B_PRIMARY_MOUSE_BUTTON); } if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) { - _SendMouseButton(SDL_BUTTON_MIDDLE, buttons & B_PRIMARY_MOUSE_BUTTON); + _SendMouseButton(SDL_BUTTON_MIDDLE, buttons & + B_PRIMARY_MOUSE_BUTTON); } last_buttons = buttons; diff --git a/src/video/bwindow/SDL_bevents.cc b/src/video/bwindow/SDL_bevents.cc new file mode 100644 index 000000000..484d73a26 --- /dev/null +++ b/src/video/bwindow/SDL_bevents.cc @@ -0,0 +1,33 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_bevents.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void BE_PumpEvents(_THIS) { +} + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bevents.h b/src/video/bwindow/SDL_bevents.h new file mode 100644 index 000000000..a930324c8 --- /dev/null +++ b/src/video/bwindow/SDL_bevents.h @@ -0,0 +1,37 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_BEVENTS_H +#define SDL_BEVENTS_H + +#include "../SDL_sysvideo.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void BE_PumpEvents(_THIS); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 2818718f5..e1c6015d2 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -19,60 +19,186 @@ 3. This notice may not be removed or altered from any source distribution. */ -#include "../SDL_sysvideo.h" + + +#include +#include +#include "SDL_bmodes.h" + +#include "../../main/beos/SDL_BApp.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +static inline SDL_BApp *_GetBeApp() { + return ((SDL_BApp*)be_app); +} + + +/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */ +static float get_refresh_rate(display_mode &mode) { + return rint(10 * float(mode.timing.pixel_clock * 1000) + / float(mode.timing.h_total * mode.timing.v_total)) / 10.0; +} + +static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) +{ + int bitsperpixel; + + bitsperpixel = 0; + switch (colorspace) { + case B_CMAP8: + bitsperpixel = 8; + break; + case B_RGB15: + case B_RGBA15: + case B_RGB15_BIG: + case B_RGBA15_BIG: + bitsperpixel = 15; + break; + case B_RGB16: + case B_RGB16_BIG: + bitsperpixel = 16; + break; + case B_RGB32: + case B_RGBA32: + case B_RGB32_BIG: + case B_RGBA32_BIG: + bitsperpixel = 32; + break; + default: + break; + } + return(bitsperpixel); +} + +static inline int32 BppToSDLPxFormat(int32 bpp) { + /* Translation taken from SDL_windowsmodes.c */ + switch (bpp) { + case 32: + return SDL_PIXELFORMAT_RGB888; + break; + case 24: /* May not be supported by Haiku */ + return SDL_PIXELFORMAT_RGB24; + break; + case 16: + return SDL_PIXELFORMAT_RGB565; + break; + case 15: + return SDL_PIXELFORMAT_RGB555; + break; + case 8: + return SDL_PIXELFORMAT_INDEX8; + break; + case 4: /* May not be supported by Haiku */ + return SDL_PIXELFORMAT_INDEX4LSB; + break; + } +} + +static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, + SDL_DisplayMode *mode) { + mode->w = bmode->virtual_width; + mode->h = bmode->virtual_height; + mode->refresh_rate = (int)get_refresh_rate(*bmode); + mode->driverdata = bmode; /* This makes setting display + modes easier */ + + /* Set the format */ + int32 bpp = ColorSpaceToBitsPerPixel(bmode->space); + mode->format = BppToSDLPxFormat(bpp); +} + +/* Later, there may be more than one monitor available */ +void BE_AddDisplay(BScreen *screen) { + SDL_VideoDisplay display; + SDL_DisplayMode mode; + display_mode bmode; + screen->GetMode(&bmode); + + BE_BDisplayModeToSdlDisplayMode(&bmode, &mode); + + SDL_zero(display); + display.desktop_mode = mode; + display.current_mode = mode; + SDL_AddVideoDisplay(&display); +} int BE_InitModes(_THIS) { -#if 0 - display_mode *modes; - uint32 i, nmodes; - int bpp; - - /* It is important that this be created after SDL_InitBeApp() */ - BScreen bscreen; - + printf("Init Modes\n"); + BScreen screen; + /* Save the current display mode */ - bscreen.GetMode(&saved_mode); - _this->info.current_w = saved_mode.virtual_width; - _this->info.current_h = saved_mode.virtual_height; - - /* Get the video modes we can switch to in fullscreen mode */ - bscreen.GetModeList(&modes, &nmodes); - SDL_qsort(modes, nmodes, sizeof *modes, CompareModes); - for (i = 0; i < nmodes; ++i) { - bpp = ColorSpaceToBitsPerPixel(modes[i].space); - //if ( bpp != 0 ) { // There are bugs in changing colorspace - if (modes[i].space == saved_mode.space) { - BE_AddMode(_this, ((bpp + 7) / 8) - 1, - modes[i].virtual_width, modes[i].virtual_height); - } - } -#else -return -1; -#endif + display_mode *prevMode; + screen.GetMode(prevMode); + _GetBeApp()->SetPrevMode(prevMode); + + /* Only one possible video display right now */ + BE_AddDisplay(&screen); } int BE_QuitModes(_THIS) { -#if 0 - int i, j; - for (i = 0; i < NUM_MODELISTS; ++i) { - if (SDL_modelist[i]) { - for (j = 0; SDL_modelist[i][j]; ++j) { - SDL_free(SDL_modelist[i][j]); - } - SDL_free(SDL_modelist[i]); - SDL_modelist[i] = NULL; - } - } - - /* Restore the original video mode */ - if (_this->screen) { - if ((_this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { - BScreen bscreen; - bscreen.SetMode(&saved_mode); - } - _this->screen->pixels = NULL; - } -#else -return -1; -#endif + /* Restore the previous video mode */ + printf("Quit Modes\n"); + + BScreen screen; + display_mode *savedMode = _GetBeApp()->GetPrevMode(); + screen.SetMode(savedMode); + return 0; } + + +int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { + BScreen bscreen; + BRect rc = bscreen.Frame(); + rect->x = (int)rc.left; + rect->y = (int)rc.top; + rect->w = (int)rc.Width() + 1; + rect->h = (int)rc.Height() + 1; + return 0; +} + +void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { + printf("Get Display Modes\n"); + /* Get the current screen */ + BScreen bscreen; + + /* Iterate through all of the modes */ + SDL_DisplayMode mode; + display_mode this_bmode; + display_mode *bmodes; + uint32 count, i; + + /* Get graphics-hardware supported modes */ + bscreen.GetModeList(&bmodes, &count); + bscreen.GetMode(&this_bmode); + + for(i = 0; i < count; ++i) { + //FIXME: Apparently there are errors with colorspace changes + if (bmodes[i].space == this_bmode.space) { + BE_BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); + SDL_AddDisplayMode(display, &mode); + } + } + free(bmodes); +} + +int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ + printf("Set Display Modes\n"); + /* Get the current screen */ + BScreen bscreen; + + /* Set the mode using the driver data */ + display_mode *bmode = (display_mode*)mode->driverdata; + if(bscreen.SetMode(bmode) == B_OK) { + return 0; /* No error */ + } + + return -1; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h index e8208cf68..aeecfe1cb 100644 --- a/src/video/bwindow/SDL_bmodes.h +++ b/src/video/bwindow/SDL_bmodes.h @@ -22,6 +22,22 @@ #ifndef SDL_BMODES_H #define SDL_BMODES_H +#ifdef __cplusplus +extern "C" { +#endif + +#include "../SDL_sysvideo.h" + extern int BE_InitModes(_THIS); extern int BE_QuitModes(_THIS); +extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, + SDL_Rect *rect); +extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display); +extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, + SDL_DisplayMode *mode); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index 3b4fea7f8..94725efa8 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -20,22 +20,21 @@ */ + + +#ifdef __cplusplus +extern "C" { +#endif + #include "SDL_bwindow.h" #include "SDL_bclipboard.h" #include "SDL_bvideo.h" #include "SDL_bopengl.h" #include "SDL_bmodes.h" +#include "SDL_bevents.h" -#ifdef __cplusplus -extern "C" { -#endif /* FIXME: Undefined functions */ -// #define BE_VideoInit NULL -// #define BE_VideoQuit NULL - #define BE_GetDisplayBounds NULL - #define BE_GetDisplayModes NULL - #define BE_SetDisplayMode NULL - #define BE_PumpEvents NULL +// #define BE_PumpEvents NULL #if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ // #define BE_GL_LoadLibrary NULL @@ -138,6 +137,11 @@ BE_CreateDevice(int devindex) return device; } +VideoBootStrap BWINDOW_bootstrap = { + "bwindow", "BDirectWindow graphics", + BE_Available, BE_CreateDevice +}; + static void BE_DeleteDevice(SDL_VideoDevice * device) { SDL_free(device->driverdata); diff --git a/src/video/bwindow/SDL_bvideo.h b/src/video/bwindow/SDL_bvideo.h index c1c32a6bb..a50221501 100644 --- a/src/video/bwindow/SDL_bvideo.h +++ b/src/video/bwindow/SDL_bvideo.h @@ -36,6 +36,7 @@ typedef struct SDL_VideoData { extern void BE_VideoQuit(_THIS); extern int BE_VideoInit(_THIS); extern void BE_DeleteDevice(_THIS); +extern int BE_Available(void); #ifdef __cplusplus } diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index 1341093e6..8181a18b1 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -37,25 +37,25 @@ static inline SDL_BApp *_GetBeApp() { return ((SDL_BApp*)be_app); } -int _InitWindow(_THIS, SDL_Window *window) { +int _InitWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 40\n"); BRect bounds( window->x, window->y, window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing window->y + window->h - 1 ); - +printf("SDL_bwindow.cc: 30\n"); SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds); if(bwin == NULL) return ENOMEM; - +printf("SDL_bwindow.cc: 51\n"); window->driverdata = bwin; int32 winID = _GetBeApp()->GetID(window); bwin->SetID(winID); return 0; } -int BE_CreateWindow(_THIS, SDL_Window *window) { +int BE_CreateWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 58\n"); if(_InitWindow(_this, window) == ENOMEM) return ENOMEM; @@ -179,21 +179,27 @@ SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, } -extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + +int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) { - /* FIXME: Not BeOs/Haiku supported */ + /* pitch = width of screen, in bytes */ + BScreen bscreen; + *pitch = (bscreen->Frame().right - bscreen->Frame().left + 1) * /*screen w*/ + SDL_BYTESPERPIXEL(*format); + + /* FIXME: FINISH! */ return -1; } -extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, +int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) { - /* FIXME: Not BeOs/Haiku supported */ + return -1; } -extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { - /* FIXME: Not BeOs/Haiku supported */ +void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { + /* FIXME: FINISH! */ } From 8932a116a033a9c0ee2185a7687f9d15d08faa38 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Fri, 22 Jul 2011 12:39:53 +0000 Subject: [PATCH 09/27] Drawing code works, but it flashes --- src/main/beos/SDL_BApp.h | 10 ++++ src/main/beos/SDL_BeApp.cc | 12 +++-- src/main/beos/SDL_BeApp.h | 8 +++ src/video/bwindow/SDL_BWin.h | 68 +++++++++++++++++++++++ src/video/bwindow/SDL_bmodes.cc | 93 ++++++++++++++++++++++++++++++++ src/video/bwindow/SDL_bmodes.h | 8 +++ src/video/bwindow/SDL_bwindow.cc | 21 -------- src/video/bwindow/SDL_bwindow.h | 7 +-- 8 files changed, 197 insertions(+), 30 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 5932b9af3..94591e0e5 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -21,11 +21,14 @@ #ifndef SDL_BAPP_H #define SDL_BAPP_H +#include + #ifdef __cplusplus extern "C" { #endif #include "SDL_config.h" + #include "SDL_video.h" /* Local includes */ @@ -173,6 +176,11 @@ public: } } + /* Modes methods */ + void SetPrevMode(display_mode *prevMode) { saved_mode = prevMode; } + + display_mode* GetPrevMode() { return saved_mode; } + /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is there another way to do this? */ void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ @@ -387,6 +395,8 @@ private: int32 _length; SDL_Window *window_map; #endif + + display_mode *saved_mode; }; #endif diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 3a7905da4..708109c01 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -35,6 +35,9 @@ #include "../../video/bwindow/SDL_BWin.h" +#ifdef __cplusplus +extern "C" { +#endif /* Flag to tell whether or not the Be application is active or not */ int SDL_BeAppActive = 0; static SDL_Thread *SDL_AppThread = NULL; @@ -113,6 +116,12 @@ SDL_QuitBeApp(void) } } + +/* vi: set ts=4 sw=4 expandtab: */ +#ifdef __cplusplus +} +#endif + /* SDL_BApp functions */ void SDL_BApp::ClearID(SDL_BWin *bwin) { _SetSDLWindow(NULL, bwin->GetID()); @@ -122,6 +131,3 @@ void SDL_BApp::ClearID(SDL_BWin *bwin) { --i; } } - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/src/main/beos/SDL_BeApp.h b/src/main/beos/SDL_BeApp.h index f734a90e3..7d95e32be 100644 --- a/src/main/beos/SDL_BeApp.h +++ b/src/main/beos/SDL_BeApp.h @@ -20,6 +20,10 @@ */ #include "SDL_config.h" + +#ifdef __cplusplus +extern "C" { +#endif /* Handle the BeApp specific portions of the application */ /* Initialize the Be Application, if it's not already started */ @@ -31,3 +35,7 @@ extern void SDL_QuitBeApp(void); /* Flag to tell whether the app is active or not */ extern int SDL_BeAppActive; /* vi: set ts=4 sw=4 expandtab: */ + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index f9139652e..083ea8f70 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -76,11 +76,18 @@ printf("SDL_BWin.h: 69\n"); inhibit_resize = false; mouse_focused = false; prev_frame = NULL; printf("SDL_BWin.h: 79\n"); + + /* Handle framebuffer stuff */ + _connected = connection_disabled = false; + buffer_locker = new BLocker(); +// LockBuffer(); /* Unlocked by buffer initialization */ } virtual ~ SDL_BWin() { Lock(); + connection_disabled = false; + if (the_view) { #if SDL_VIDEO_OPENGL if (the_view == SDL_GLView) { @@ -99,6 +106,11 @@ printf("SDL_BWin.h: 69\n"); if (SDL_View) { delete SDL_View; } + + /* Clean up framebuffer stuff */ + buffer_locker->Lock(); + buffer_locker->Unlock(); + delete buffer_locker; } @@ -153,6 +165,41 @@ printf("SDL_BWin.h: 69\n"); /* * * * * Framebuffering* * * * */ virtual void DirectConnected(direct_buffer_info *info) { + if(!_connected && connection_disabled) { + return; + } + LockBuffer(); + + switch(info->buffer_state & B_DIRECT_MODE_MASK) { + case B_DIRECT_START: +printf("SDL_BWin.h: 175 Direct start.\n"); + _connected = true; + + case B_DIRECT_MODIFY: + + if(_clips) { + free(_clips); + _clips = NULL; + } + + num_clips = info->clip_list_count; + _clips = (clipping_rect *)malloc(num_clips*sizeof(clipping_rect)); + if(_clips) { + memcpy(_clips, info->clip_list, + num_clips*sizeof(clipping_rect)); + + _bits = (uint8*) info->bits; + row_bytes = info->bytes_per_row; + _bounds = info->window_bounds; + } + + break; + + case B_DIRECT_STOP: + _connected = false; + break; + } + UnlockBuffer(); } @@ -353,6 +400,18 @@ printf("SDL_BWin.h: 69\n"); /* Accessor methods */ bool IsShown() { return _shown; } int32 GetID() { return _id; } + void LockBuffer() { buffer_locker->Lock(); } + void UnlockBuffer() { buffer_locker->Unlock(); } + uint32 GetRowBytes() { return row_bytes; } + int32 GetFbX() { return _bounds.left; } + int32 GetFbY() { return _bounds.top; } + int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } + int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } + bool ConnectionEnabled() { return !connection_disabled; } + bool Connected() { return _connected; } + clipping_rect *GetClips() { return _clips; } + int32 GetNumClips() { return num_clips; } + uint8* GetBufferPx() { return _bits; } /* Setter methods */ void SetID(int32 id) { _id = id; } @@ -582,6 +641,15 @@ private: bool inhibit_resize; BRect *prev_frame; /* Previous position and size of the window */ + + /* Framebuffer members */ + bool _connected, connection_disabled; + uint8 *_bits; + uint32 row_bytes; + clipping_rect _bounds; + BLocker *buffer_locker; + clipping_rect *_clips; + int32 num_clips; }; #endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index e1c6015d2..8814f70d0 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -24,6 +24,7 @@ #include #include #include "SDL_bmodes.h" +#include "SDL_BWin.h" #include "../../main/beos/SDL_BApp.h" @@ -31,6 +32,9 @@ extern "C" { #endif +static inline SDL_BWin *_ToBeWin(SDL_Window *window) { + return ((SDL_BWin*)(window->driverdata)); +} static inline SDL_BApp *_GetBeApp() { return ((SDL_BApp*)be_app); @@ -199,6 +203,95 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ return -1; } + + +int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch) { + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + while(!bwin->Connected()) { snooze(1600); } + + /* Make sure we have exclusive access to frame buffer data */ + bwin->LockBuffer(); + + /* format */ + display_mode bmode; + bscreen.GetMode(&bmode); + int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); + *format = BppToSDLPxFormat(bpp); + + /* pitch = width of screen, in bytes */ + *pitch = bpp * bwin->GetFbWidth() / 8; + + /* Create a copy of the pixel buffer */ + printf("SDL_bmodes.cc: 230; fbh: %i, pitch: %i; (x,y) = (%i, %i)\n", bwin->GetFbHeight(), (*pitch), bwin->GetFbX(), bwin->GetFbY()); + *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * bpp / 8, sizeof(uint8)); + + bwin->UnlockBuffer(); + return 0; +} + + + +int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects) { + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + if(bwin->ConnectionEnabled() && bwin->Connected()) { + bwin->LockBuffer(); + int32 windowPitch = window->surface->pitch; + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; + + int32 bpp = window->surface->format->BitsPerPixel; + uint8 *windowBaseAddress = (uint8*)window->surface->pixels; + int32 windowSub = bwin->GetFbX() * bpp / 8 + + bwin->GetFbY() * windowPitch; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; + + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * bpp / 8; + windowpx = windowBaseAddress + + clips[i].top * windowPitch + clips[i].left * bpp / 8 + - windowSub; + + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + memcpy(bufferpx, windowpx, width * bpp / 8); + bufferpx += bufferPitch; + windowpx += windowPitch; + } + } + bwin->UnlockBuffer(); + } + return 0; +} + +void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { + /* FIXME: FINISH! */ + printf("ERROR: Attempted to destroy the window frame buffer\n"); +} + #ifdef __cplusplus } #endif diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h index aeecfe1cb..af080c524 100644 --- a/src/video/bwindow/SDL_bmodes.h +++ b/src/video/bwindow/SDL_bmodes.h @@ -36,6 +36,14 @@ extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display); extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch); +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects); +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); + + #ifdef __cplusplus } #endif diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index 8181a18b1..4cb92ece1 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -180,27 +180,6 @@ SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, -int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, - Uint32 * format, - void ** pixels, int *pitch) { - /* pitch = width of screen, in bytes */ - BScreen bscreen; - *pitch = (bscreen->Frame().right - bscreen->Frame().left + 1) * /*screen w*/ - SDL_BYTESPERPIXEL(*format); - - /* FIXME: FINISH! */ - return -1; -} - -int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) { - - return -1; -} - -void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { - /* FIXME: FINISH! */ -} #ifdef __cplusplus diff --git a/src/video/bwindow/SDL_bwindow.h b/src/video/bwindow/SDL_bwindow.h index 26f800b7f..8e6959851 100644 --- a/src/video/bwindow/SDL_bwindow.h +++ b/src/video/bwindow/SDL_bwindow.h @@ -45,12 +45,7 @@ extern void BE_DestroyWindow(_THIS, SDL_Window * window); extern SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info); -extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, - Uint32 * format, - void ** pixels, int *pitch); -extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); -extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); + #endif From ee8ee9d166b3e4bac0ecc058e8640701b098734c Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Fri, 22 Jul 2011 16:54:23 +0000 Subject: [PATCH 10/27] Corrected memory leak with rendering. --- src/video/bwindow/SDL_BView.h | 124 -------------------------------- src/video/bwindow/SDL_BWin.h | 112 +++++++++-------------------- src/video/bwindow/SDL_bmodes.cc | 49 ++++++++----- 3 files changed, 62 insertions(+), 223 deletions(-) delete mode 100644 src/video/bwindow/SDL_BView.h diff --git a/src/video/bwindow/SDL_BView.h b/src/video/bwindow/SDL_BView.h deleted file mode 100644 index f522fe95e..000000000 --- a/src/video/bwindow/SDL_BView.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifndef _SDL_BView_h -#define _SDL_BView_h - -/* This is the event handling and graphics update portion of SDL_BWin */ -#ifdef __cplusplus -extern "C" { -#endif - -#include "../../events/SDL_events_c.h" - -#ifdef __cplusplus -} -#endif - -class SDL_BView:public BView -{ - public: - SDL_BView(BRect frame):BView(frame, "SDL View", B_FOLLOW_ALL_SIDES, - (B_WILL_DRAW | B_FRAME_EVENTS)) - { - image = NULL; - xoff = yoff = 0; - SetViewColor(0, 0, 0, 0); - SetHighColor(0, 0, 0, 0); - } - virtual ~ SDL_BView() - { - SetBitmap(NULL); - } - /* Set drawing offsets for fullscreen mode */ - virtual void SetXYOffset(int x, int y) - { - xoff = x; - yoff = y; - } - virtual void GetXYOffset(int &x, int &y) - { - x = xoff; - y = yoff; - } - /* The view changed size. If it means we're in fullscreen, we - * draw a nice black box in the entire view to get black borders. - */ - virtual void FrameResized(float width, float height) - { - BRect bounds; - bounds.top = bounds.left = 0; - bounds.right = width; - bounds.bottom = height; - /* Fill the entire view with black */ - FillRect(bounds, B_SOLID_HIGH); - /* And if there's an image, redraw it. */ - if (image) { - bounds = image->Bounds(); - Draw(bounds); - } - } - - /* Drawing portion of this complete breakfast. :) */ - virtual void SetBitmap(BBitmap * bitmap) - { - if (image) { - delete image; - } - image = bitmap; - } - virtual void Draw(BRect updateRect) - { - if (image) { - if (xoff || yoff) { - BRect dest; - dest.top = updateRect.top + yoff; - dest.left = updateRect.left + xoff; - dest.bottom = updateRect.bottom + yoff; - dest.right = updateRect.right + xoff; - DrawBitmap(image, updateRect, dest); - } else { - DrawBitmap(image, updateRect, updateRect); - } - } - } - virtual void DrawAsync(BRect updateRect) - { - if (xoff || yoff) { - BRect dest; - dest.top = updateRect.top + yoff; - dest.left = updateRect.left + xoff; - dest.bottom = updateRect.bottom + yoff; - dest.right = updateRect.right + xoff;; - DrawBitmapAsync(image, updateRect, dest); - } else { - DrawBitmapAsync(image, updateRect, updateRect); - } - } - - private: - BBitmap * image; - int xoff, yoff; -}; - -#endif /* _SDL_BView_h */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 083ea8f70..b96857c91 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -42,7 +42,6 @@ extern "C" { #include #endif #include "SDL_events.h" -#include "SDL_BView.h" #include "../../main/beos/SDL_BApp.h" enum WinCommands { @@ -67,11 +66,10 @@ class SDL_BWin:public BDirectWindow { last_buttons = 0; printf("SDL_BWin.h: 69\n"); - the_view = NULL; + #if SDL_VIDEO_OPENGL SDL_GLView = NULL; #endif - SDL_View = NULL; _shown = false; inhibit_resize = false; mouse_focused = false; @@ -79,42 +77,39 @@ printf("SDL_BWin.h: 69\n"); /* Handle framebuffer stuff */ _connected = connection_disabled = false; + trash_window_buffer = false; buffer_locker = new BLocker(); + window_buffer = NULL; // LockBuffer(); /* Unlocked by buffer initialization */ } virtual ~ SDL_BWin() { Lock(); - connection_disabled = false; + connection_disabled = true; - if (the_view) { #if SDL_VIDEO_OPENGL - if (the_view == SDL_GLView) { - SDL_GLView->UnlockGL(); - } -#endif - RemoveChild(the_view); - the_view = NULL; + if (SDL_GLView) { + SDL_GLView->UnlockGL(); } + RemoveChild(SDL_GLView); +#endif Unlock(); #if SDL_VIDEO_OPENGL if (SDL_GLView) { delete SDL_GLView; } #endif - if (SDL_View) { - delete SDL_View; - } /* Clean up framebuffer stuff */ buffer_locker->Lock(); - buffer_locker->Unlock(); + free(_clips); delete buffer_locker; } - + /* Other construction */ +#if SDL_VIDEO_OPENGL virtual int CreateView(Uint32 flags, Uint32 gl_flags) { int retval; @@ -122,7 +117,6 @@ printf("SDL_BWin.h: 69\n"); retval = 0; Lock(); if (flags & SDL_OPENGL/*SDL_INTERNALOPENGL*/) { -#if SDL_VIDEO_OPENGL if (SDL_GLView == NULL) { SDL_GLView = new BGLView(Bounds(), "SDL GLView", B_FOLLOW_ALL_SIDES, @@ -137,31 +131,16 @@ printf("SDL_BWin.h: 69\n"); SDL_GLView->LockGL(); the_view = SDL_GLView; } -#else - SDL_SetError("OpenGL support not enabled"); - retval = -1; -#endif } else { - if (SDL_View == NULL) { - SDL_View = new SDL_BView(Bounds()); - } - if (the_view != SDL_View) { - if (the_view) { -#if SDL_VIDEO_OPENGL - if (the_view == SDL_GLView) { - SDL_GLView->UnlockGL(); - } -#endif - RemoveChild(the_view); - } - AddChild(SDL_View); - the_view = SDL_View; + if (the_view) { + SDL_GLView->UnlockGL(); + RemoveChild(the_view); } } Unlock(); return (retval); } - +#endif /* * * * * Framebuffering* * * * */ virtual void DirectConnected(direct_buffer_info *info) { @@ -172,7 +151,7 @@ printf("SDL_BWin.h: 69\n"); switch(info->buffer_state & B_DIRECT_MODE_MASK) { case B_DIRECT_START: -printf("SDL_BWin.h: 175 Direct start.\n"); +printf(__FILE__": %d; Direct start.\n", __LINE__); _connected = true; case B_DIRECT_MODIFY: @@ -182,6 +161,12 @@ printf("SDL_BWin.h: 175 Direct start.\n"); _clips = NULL; } + /* Can we reuse the window's pixel buffer after this? */ + trash_window_buffer = ((info->buffer_state & B_BUFFER_RESIZED) + || (info->buffer_state & B_BUFFER_RESET) + || ((info->buffer_state & B_DIRECT_MODE_MASK) + == B_DIRECT_START)); + num_clips = info->clip_list_count; _clips = (clipping_rect *)malloc(num_clips*sizeof(clipping_rect)); if(_clips) { @@ -191,6 +176,7 @@ printf("SDL_BWin.h: 175 Direct start.\n"); _bits = (uint8*) info->bits; row_bytes = info->bytes_per_row; _bounds = info->window_bounds; + bytes_per_px = info->bits_per_pixel / 8; } break; @@ -203,6 +189,8 @@ printf("SDL_BWin.h: 175 Direct start.\n"); } + + /* * * * * Event sending * * * * */ /* Hook functions */ virtual void FrameMoved(BPoint origin) { @@ -412,54 +400,16 @@ printf("SDL_BWin.h: 175 Direct start.\n"); clipping_rect *GetClips() { return _clips; } int32 GetNumClips() { return num_clips; } uint8* GetBufferPx() { return _bits; } + int32 GetBytesPerPx() { return bytes_per_px; } + void SetWindowFramebuffer(uint8* fb) { window_buffer = fb; } + uint8* GetWindowFramebuffer() { return window_buffer; } + bool CanTrashWindowBuffer() { return trash_window_buffer; } /* Setter methods */ void SetID(int32 id) { _id = id; } - - - - - - - /* FIXME: Methods copied directly; do we need them? */ -#if 0 /* Disabled until its purpose is determined */ - virtual void SetXYOffset(int x, int y) - { -#if SDL_VIDEO_OPENGL - if (the_view == SDL_GLView) { - return; - } -#endif - SDL_View->SetXYOffset(x, y); - } - virtual void GetXYOffset(int &x, int &y) - { -#if SDL_VIDEO_OPENGL - if (the_view == SDL_GLView) { - x = 0; - y = 0; - return; - } -#endif - SDL_View->GetXYOffset(x, y); - } -#endif - virtual bool BeginDraw(void) - { - return (Lock()); - } - virtual void DrawAsync(BRect updateRect) - { - SDL_View->DrawAsync(updateRect); - } - virtual void EndDraw(void) - { - SDL_View->Sync(); - Unlock(); - } #if SDL_VIDEO_OPENGL virtual void SwapBuffers(void) { @@ -631,7 +581,6 @@ private: #if SDL_VIDEO_OPENGL BGLView * SDL_GLView; #endif - SDL_BView *SDL_View; BView *the_view; int32 last_buttons; @@ -650,6 +599,9 @@ private: BLocker *buffer_locker; clipping_rect *_clips; int32 num_clips; + int32 bytes_per_px; + uint8 *window_buffer; /* A copy of the window buffer */ + bool trash_window_buffer; }; #endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 8814f70d0..6c05353c9 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -43,8 +43,8 @@ static inline SDL_BApp *_GetBeApp() { /* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */ static float get_refresh_rate(display_mode &mode) { - return rint(10 * float(mode.timing.pixel_clock * 1000) - / float(mode.timing.h_total * mode.timing.v_total)) / 10.0; + return float(mode.timing.pixel_clock * 1000) + / float(mode.timing.h_total * mode.timing.v_total); } static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) @@ -78,7 +78,7 @@ static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) return(bitsperpixel); } -static inline int32 BppToSDLPxFormat(int32 bpp) { +static inline int32 BPPToSDLPxFormat(int32 bpp) { /* Translation taken from SDL_windowsmodes.c */ switch (bpp) { case 32: @@ -112,7 +112,7 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, /* Set the format */ int32 bpp = ColorSpaceToBitsPerPixel(bmode->space); - mode->format = BppToSDLPxFormat(bpp); + mode->format = BPPToSDLPxFormat(bpp); } /* Later, there may be more than one monitor available */ @@ -145,8 +145,6 @@ int BE_InitModes(_THIS) { int BE_QuitModes(_THIS) { /* Restore the previous video mode */ - printf("Quit Modes\n"); - BScreen screen; display_mode *savedMode = _GetBeApp()->GetPrevMode(); screen.SetMode(savedMode); @@ -223,14 +221,21 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, display_mode bmode; bscreen.GetMode(&bmode); int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); - *format = BppToSDLPxFormat(bpp); + *format = BPPToSDLPxFormat(bpp); /* pitch = width of screen, in bytes */ - *pitch = bpp * bwin->GetFbWidth() / 8; + *pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx(); - /* Create a copy of the pixel buffer */ - printf("SDL_bmodes.cc: 230; fbh: %i, pitch: %i; (x,y) = (%i, %i)\n", bwin->GetFbHeight(), (*pitch), bwin->GetFbX(), bwin->GetFbY()); - *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * bpp / 8, sizeof(uint8)); + /* Create a copy of the pixel buffer if it doesn't recycle */ + *pixels = bwin->GetWindowFramebuffer(); + if( bwin->CanTrashWindowBuffer() ) { + if( (*pixels) != NULL ) { + SDL_free(*pixels); + } + *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * + bwin->GetBytesPerPx(), sizeof(uint8)); + bwin->SetWindowFramebuffer((uint8*)(*pixels)); + } bwin->UnlockBuffer(); return 0; @@ -253,9 +258,9 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, uint8 *windowpx; uint8 *bufferpx; - int32 bpp = window->surface->format->BitsPerPixel; + int32 BPP = bwin->GetBytesPerPx(); uint8 *windowBaseAddress = (uint8*)window->surface->pixels; - int32 windowSub = bwin->GetFbX() * bpp / 8 + + int32 windowSub = bwin->GetFbX() * BPP + bwin->GetFbY() * windowPitch; clipping_rect *clips = bwin->GetClips(); int32 numClips = bwin->GetNumClips(); @@ -268,16 +273,15 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int32 width = clips[i].right - clips[i].left + 1; int32 height = clips[i].bottom - clips[i].top + 1; bufferpx = bwin->GetBufferPx() + - clips[i].top * bufferPitch + clips[i].left * bpp / 8; + clips[i].top * bufferPitch + clips[i].left * BPP; windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * bpp / 8 - - windowSub; + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; /* Copy each row of pixels from the window buffer into the frame buffer */ for(y = 0; y < height; ++y) { - memcpy(bufferpx, windowpx, width * bpp / 8); + memcpy(bufferpx, windowpx, width * BPP); bufferpx += bufferPitch; windowpx += windowPitch; } @@ -288,8 +292,15 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, } void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { - /* FIXME: FINISH! */ - printf("ERROR: Attempted to destroy the window frame buffer\n"); + SDL_BWin *bwin = _ToBeWin(window); + + bwin->LockBuffer(); + + /* Free and clear the window buffer */ + uint8* winBuffer = bwin->GetWindowFramebuffer(); + SDL_free(winBuffer); + bwin->SetWindowFramebuffer(NULL); + bwin->UnlockBuffer(); } #ifdef __cplusplus From 96dd15dd3dcb56a85c2eed2fb5dfe72adc9e09a9 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Mon, 25 Jul 2011 13:47:19 +0000 Subject: [PATCH 11/27] Corrected framebuffer creation problem --- src/video/bwindow/SDL_bmodes.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 6c05353c9..62e94ee6b 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -228,13 +228,19 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Create a copy of the pixel buffer if it doesn't recycle */ *pixels = bwin->GetWindowFramebuffer(); - if( bwin->CanTrashWindowBuffer() ) { + printf(__FILE__": %d; window frame buffer make\n", __LINE__); + if( bwin->CanTrashWindowBuffer() || (*pixels) == NULL) { if( (*pixels) != NULL ) { SDL_free(*pixels); } *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * bwin->GetBytesPerPx(), sizeof(uint8)); bwin->SetWindowFramebuffer((uint8*)(*pixels)); + if(*pixels) { + printf(__FILE__": %d; Success!\n", __LINE__); + } else { + printf(__FILE__": %d; FAIL!\n", __LINE__); + } } bwin->UnlockBuffer(); @@ -269,6 +275,7 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, /* Blit each clipping rectangle */ bscreen.WaitForRetrace(); for(i = 0; i < numClips; ++i) { + clipping_rect rc = clips[i]; /* Get addresses of the start of each clipping rectangle */ int32 width = clips[i].right - clips[i].left + 1; int32 height = clips[i].bottom - clips[i].top + 1; @@ -276,7 +283,7 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, clips[i].top * bufferPitch + clips[i].left * BPP; windowpx = windowBaseAddress + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; - +printf(__FILE__": %d\n\twindowpx = 0x%x\n\tbufferpx = 0x%x\n\twindowPitch = %i\n\tbufferPitch = %i\n", __LINE__, windowpx, bufferpx, windowPitch, bufferPitch); /* Copy each row of pixels from the window buffer into the frame buffer */ for(y = 0; y < height; ++y) From 20af8e0677b03fb0419ebd2e6b20f304d5446085 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Mon, 25 Jul 2011 16:46:55 +0000 Subject: [PATCH 12/27] Variable name/debugging output changes --- src/video/bwindow/SDL_BWin.h | 181 +++++++++++++++---------------- src/video/bwindow/SDL_bmodes.cc | 24 ++-- src/video/bwindow/SDL_bwindow.cc | 8 +- 3 files changed, 99 insertions(+), 114 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index b96857c91..b460753af 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -64,47 +64,46 @@ class SDL_BWin:public BDirectWindow SDL_BWin(BRect bounds):BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { - last_buttons = 0; -printf("SDL_BWin.h: 69\n"); + _last_buttons = 0; #if SDL_VIDEO_OPENGL - SDL_GLView = NULL; + _SDL_GLView = NULL; #endif _shown = false; - inhibit_resize = false; - mouse_focused = false; - prev_frame = NULL; printf("SDL_BWin.h: 79\n"); - + _inhibit_resize = false; + _mouse_focused = false; + _prev_frame = NULL; + /* Handle framebuffer stuff */ - _connected = connection_disabled = false; - trash_window_buffer = false; - buffer_locker = new BLocker(); - window_buffer = NULL; + _connected = _connection_disabled = false; + _trash__window_buffer = false; + _buffer_locker = new BLocker(); + _window_buffer = NULL; // LockBuffer(); /* Unlocked by buffer initialization */ } virtual ~ SDL_BWin() { Lock(); - connection_disabled = true; + _connection_disabled = true; #if SDL_VIDEO_OPENGL - if (SDL_GLView) { - SDL_GLView->UnlockGL(); + if (_SDL_GLView) { + _SDL_GLView->UnlockGL(); } - RemoveChild(SDL_GLView); + RemoveChild(_SDL_GLView); #endif Unlock(); #if SDL_VIDEO_OPENGL - if (SDL_GLView) { - delete SDL_GLView; + if (_SDL_GLView) { + delete _SDL_GLView; } #endif /* Clean up framebuffer stuff */ - buffer_locker->Lock(); + _buffer_locker->Lock(); free(_clips); - delete buffer_locker; + delete _buffer_locker; } @@ -117,24 +116,24 @@ printf("SDL_BWin.h: 69\n"); retval = 0; Lock(); if (flags & SDL_OPENGL/*SDL_INTERNALOPENGL*/) { - if (SDL_GLView == NULL) { - SDL_GLView = new BGLView(Bounds(), "SDL GLView", + if (_SDL_GLView == NULL) { + _SDL_GLView = new BGLView(Bounds(), "SDL GLView", B_FOLLOW_ALL_SIDES, (B_WILL_DRAW | B_FRAME_EVENTS), gl_flags); } - if (the_view != SDL_GLView) { - if (the_view) { - RemoveChild(the_view); + if (_the_view != _SDL_GLView) { + if (_the_view) { + RemoveChild(_the_view); } - AddChild(SDL_GLView); - SDL_GLView->LockGL(); - the_view = SDL_GLView; + AddChild(_SDL_GLView); + _SDL_GLView->LockGL(); + _the_view = _SDL_GLView; } } else { - if (the_view) { - SDL_GLView->UnlockGL(); - RemoveChild(the_view); + if (_the_view) { + _SDL_GLView->UnlockGL(); + RemoveChild(_the_view); } } Unlock(); @@ -144,41 +143,41 @@ printf("SDL_BWin.h: 69\n"); /* * * * * Framebuffering* * * * */ virtual void DirectConnected(direct_buffer_info *info) { - if(!_connected && connection_disabled) { + if(!_connected && _connection_disabled) { return; } LockBuffer(); switch(info->buffer_state & B_DIRECT_MODE_MASK) { case B_DIRECT_START: -printf(__FILE__": %d; Direct start.\n", __LINE__); _connected = true; case B_DIRECT_MODIFY: - if(_clips) { free(_clips); _clips = NULL; } /* Can we reuse the window's pixel buffer after this? */ - trash_window_buffer = ((info->buffer_state & B_BUFFER_RESIZED) + _trash__window_buffer = ((info->buffer_state & B_BUFFER_RESIZED) || (info->buffer_state & B_BUFFER_RESET) || ((info->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START)); - - num_clips = info->clip_list_count; - _clips = (clipping_rect *)malloc(num_clips*sizeof(clipping_rect)); + + _num_clips = info->clip_list_count; + _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect)); if(_clips) { memcpy(_clips, info->clip_list, - num_clips*sizeof(clipping_rect)); + _num_clips*sizeof(clipping_rect)); _bits = (uint8*) info->bits; - row_bytes = info->bytes_per_row; + _row_bytes = info->bytes_per_row; _bounds = info->window_bounds; - bytes_per_px = info->bits_per_pixel / 8; + _bytes_per_px = info->bits_per_pixel / 8; } - + + /* Whatever the case, I think this merits a repaint event */ +// _RepaintEvent(); break; case B_DIRECT_STOP: @@ -218,7 +217,7 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); virtual bool QuitRequested() { BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED); _PostWindowEvent(msg); - + /* We won't allow a quit unless asked by DestroyWindow() */ return false; } @@ -235,8 +234,8 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); _PostWindowEvent(msg); /* Before the window zooms, record its size */ - if( !prev_frame ) - prev_frame = new BRect(Frame()); + if( !_prev_frame ) + _prev_frame = new BRect(Frame()); /* Perform normal hook operations */ BDirectWindow::Zoom(origin, width, height); @@ -244,19 +243,19 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); /* Member functions */ virtual void Show() { - BDirectWindow::Show(); + while(IsHidden()) { + BDirectWindow::Show(); + } _shown = true; - + BMessage msg(BAPP_SHOW); _PostWindowEvent(msg); } virtual void Hide() { - /* FIXME: Multiple hides require multiple shows to undo. Should - this be altered to prevent this from happening? */ BDirectWindow::Hide(); _shown = false; - + BMessage msg(BAPP_HIDE); _PostWindowEvent(msg); } @@ -273,7 +272,6 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); /* BView message interruption */ virtual void DispatchMessage(BMessage * msg, BHandler * target) { - BPoint where; /* Used by mouse moved */ int32 buttons; /* Used for mouse button events */ int32 key; /* Used for key events */ @@ -326,11 +324,6 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); _KeyEvent(key, SDL_RELEASED); } break; - - case _UPDATE_: - case _UPDATE_IF_NEEDED_: /* Hopefully one doesn't call the other */ - _RepaintEvent(); - break; default: /* move it after switch{} so it's always handled @@ -341,6 +334,7 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); //BDirectWindow::DispatchMessage(msg, target); break; } + BDirectWindow::DispatchMessage(msg, target); } @@ -388,22 +382,22 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); /* Accessor methods */ bool IsShown() { return _shown; } int32 GetID() { return _id; } - void LockBuffer() { buffer_locker->Lock(); } - void UnlockBuffer() { buffer_locker->Unlock(); } - uint32 GetRowBytes() { return row_bytes; } + void LockBuffer() { _buffer_locker->Lock(); } + void UnlockBuffer() { _buffer_locker->Unlock(); } + uint32 GetRowBytes() { return _row_bytes; } int32 GetFbX() { return _bounds.left; } int32 GetFbY() { return _bounds.top; } int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } - bool ConnectionEnabled() { return !connection_disabled; } + bool ConnectionEnabled() { return !_connection_disabled; } bool Connected() { return _connected; } clipping_rect *GetClips() { return _clips; } - int32 GetNumClips() { return num_clips; } + int32 GetNumClips() { return _num_clips; } uint8* GetBufferPx() { return _bits; } - int32 GetBytesPerPx() { return bytes_per_px; } - void SetWindowFramebuffer(uint8* fb) { window_buffer = fb; } - uint8* GetWindowFramebuffer() { return window_buffer; } - bool CanTrashWindowBuffer() { return trash_window_buffer; } + int32 GetBytesPerPx() { return _bytes_per_px; } + void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } + uint8* GetWindowFramebuffer() { return _window_buffer; } + bool CanTrashWindowBuffer() { return _trash__window_buffer; } /* Setter methods */ void SetID(int32 id) { _id = id; } @@ -413,14 +407,14 @@ printf(__FILE__": %d; Direct start.\n", __LINE__); #if SDL_VIDEO_OPENGL virtual void SwapBuffers(void) { - SDL_GLView->UnlockGL(); - SDL_GLView->LockGL(); - SDL_GLView->SwapBuffers(); + _SDL_GLView->UnlockGL(); + _SDL_GLView->LockGL(); + _SDL_GLView->SwapBuffers(); } #endif virtual BView *View(void) { - return (the_view); + return (_the_view); } @@ -434,27 +428,26 @@ private: void _MouseMotionEvent(BPoint &where, int32 transit) { if(transit == B_EXITED_VIEW) { /* Change mouse focus */ - if(mouse_focused) { + if(_mouse_focused) { _MouseFocusEvent(false); } } else { static int x = 0, y = 0; /* Change mouse focus */ - if (!mouse_focused) { + if (!_mouse_focused) { _MouseFocusEvent(true); } -// GetXYOffset(x, y); //FIXME: What is this doing? (from SDL 1.2) BMessage msg(BAPP_MOUSE_MOVED); msg.AddInt32("dx", where.x - x); msg.AddInt32("dy", where.y - y); x = (int) where.x; - y = (int) where.y; + y = (int) where.y; _PostWindowEvent(msg); } } void _MouseFocusEvent(bool focusGained) { - mouse_focused = focusGained; + _mouse_focused = focusGained; BMessage msg(BAPP_MOUSE_FOCUS); msg.AddBool("focusGained", focusGained); _PostWindowEvent(msg); @@ -465,7 +458,7 @@ private: } void _MouseButtonEvent(int32 buttons) { - int32 buttonStateChange = buttons ^ last_buttons; + int32 buttonStateChange = buttons ^ _last_buttons; /* Make sure at least one button has changed state */ if( !(buttonStateChange) ) { @@ -486,7 +479,7 @@ private: B_PRIMARY_MOUSE_BUTTON); } - last_buttons = buttons; + _last_buttons = buttons; } void _SendMouseButton(int32 button, int32 state) { @@ -561,9 +554,9 @@ private: Minimize(false); } else if(IsHidden()) { Show(); - } else if(prev_frame != NULL) { /* Zoomed */ - MoveTo(prev_frame->left, prev_frame->top); - ResizeTo(prev_frame->Width(), prev_frame->Height()); + } else if(_prev_frame != NULL) { /* Zoomed */ + MoveTo(_prev_frame->left, _prev_frame->top); + ResizeTo(_prev_frame->Width(), _prev_frame->Height()); } } @@ -579,29 +572,29 @@ private: /* Members */ #if SDL_VIDEO_OPENGL - BGLView * SDL_GLView; + BGLView * _SDL_GLView; #endif - BView *the_view; + BView *_the_view; - int32 last_buttons; + int32 _last_buttons; int32 _id; /* Window id used by SDL_BApp */ - bool mouse_focused; /* Does this window have mouse focus? */ - bool _shown; - bool inhibit_resize; + bool _mouse_focused; /* Does this window have mouse focus? */ + bool _shown; + bool _inhibit_resize; - BRect *prev_frame; /* Previous position and size of the window */ + BRect *_prev_frame; /* Previous position and size of the window */ /* Framebuffer members */ - bool _connected, connection_disabled; - uint8 *_bits; - uint32 row_bytes; + bool _connected, _connection_disabled; + uint8 *_bits; + uint32 _row_bytes; clipping_rect _bounds; - BLocker *buffer_locker; - clipping_rect *_clips; - int32 num_clips; - int32 bytes_per_px; - uint8 *window_buffer; /* A copy of the window buffer */ - bool trash_window_buffer; + BLocker *_buffer_locker; + clipping_rect *_clips; + int32 _num_clips; + int32 _bytes_per_px; + uint8 *_window_buffer; /* A copy of the window buffer */ + bool _trash__window_buffer; }; #endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 62e94ee6b..d5bc4bb22 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -118,20 +118,19 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, /* Later, there may be more than one monitor available */ void BE_AddDisplay(BScreen *screen) { SDL_VideoDisplay display; - SDL_DisplayMode mode; + SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, sizeof(SDL_DisplayMode)); display_mode bmode; screen->GetMode(&bmode); - BE_BDisplayModeToSdlDisplayMode(&bmode, &mode); + BE_BDisplayModeToSdlDisplayMode(&bmode, mode); SDL_zero(display); - display.desktop_mode = mode; - display.current_mode = mode; + display.desktop_mode = *mode; + display.current_mode = *mode; SDL_AddVideoDisplay(&display); } int BE_InitModes(_THIS) { - printf("Init Modes\n"); BScreen screen; /* Save the current display mode */ @@ -144,6 +143,7 @@ int BE_InitModes(_THIS) { } int BE_QuitModes(_THIS) { + printf(__FILE__": %d; Begin quit\n", __LINE__); /* Restore the previous video mode */ BScreen screen; display_mode *savedMode = _GetBeApp()->GetPrevMode(); @@ -163,10 +163,9 @@ int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { } void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { - printf("Get Display Modes\n"); /* Get the current screen */ BScreen bscreen; - + /* Iterate through all of the modes */ SDL_DisplayMode mode; display_mode this_bmode; @@ -188,7 +187,6 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { } int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ - printf("Set Display Modes\n"); /* Get the current screen */ BScreen bscreen; @@ -212,7 +210,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, return -1; } - while(!bwin->Connected()) { snooze(1600); } + while(!bwin->Connected()) { snooze(10); } /* Make sure we have exclusive access to frame buffer data */ bwin->LockBuffer(); @@ -228,7 +226,6 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Create a copy of the pixel buffer if it doesn't recycle */ *pixels = bwin->GetWindowFramebuffer(); - printf(__FILE__": %d; window frame buffer make\n", __LINE__); if( bwin->CanTrashWindowBuffer() || (*pixels) == NULL) { if( (*pixels) != NULL ) { SDL_free(*pixels); @@ -236,11 +233,6 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * bwin->GetBytesPerPx(), sizeof(uint8)); bwin->SetWindowFramebuffer((uint8*)(*pixels)); - if(*pixels) { - printf(__FILE__": %d; Success!\n", __LINE__); - } else { - printf(__FILE__": %d; FAIL!\n", __LINE__); - } } bwin->UnlockBuffer(); @@ -283,7 +275,7 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, clips[i].top * bufferPitch + clips[i].left * BPP; windowpx = windowBaseAddress + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; -printf(__FILE__": %d\n\twindowpx = 0x%x\n\tbufferpx = 0x%x\n\twindowPitch = %i\n\tbufferPitch = %i\n", __LINE__, windowpx, bufferpx, windowPitch, bufferPitch); + /* Copy each row of pixels from the window buffer into the frame buffer */ for(y = 0; y < height; ++y) diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index 4cb92ece1..e1912261a 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -37,25 +37,25 @@ static inline SDL_BApp *_GetBeApp() { return ((SDL_BApp*)be_app); } -int _InitWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 40\n"); +int _InitWindow(_THIS, SDL_Window *window) { BRect bounds( window->x, window->y, window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing window->y + window->h - 1 ); -printf("SDL_bwindow.cc: 30\n"); + SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds); if(bwin == NULL) return ENOMEM; -printf("SDL_bwindow.cc: 51\n"); + window->driverdata = bwin; int32 winID = _GetBeApp()->GetID(window); bwin->SetID(winID); return 0; } -int BE_CreateWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 58\n"); +int BE_CreateWindow(_THIS, SDL_Window *window) { if(_InitWindow(_this, window) == ENOMEM) return ENOMEM; From 7121f4e5ba705f94ca3f66569802df6642a01ea9 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 26 Jul 2011 10:13:34 +0000 Subject: [PATCH 13/27] Fixed seg fault on video quit --- src/video/bwindow/SDL_bmodes.cc | 14 +++++++++++--- src/video/bwindow/SDL_bvideo.cc | 6 ++++-- src/video/bwindow/SDL_bvideo.h | 3 --- src/video/bwindow/SDL_bwindow.h | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index d5bc4bb22..11c336cf9 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -32,6 +32,13 @@ extern "C" { #endif +/* This wrapper is here so that the driverdata can be freed */ +typedef struct SDL_DisplayModeData { + display_mode *bmode; +}; + + + static inline SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } @@ -107,8 +114,9 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; mode->refresh_rate = (int)get_refresh_rate(*bmode); - mode->driverdata = bmode; /* This makes setting display - modes easier */ + SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData)); + data->bmode = bmode; + mode->driverdata = data; /* Set the format */ int32 bpp = ColorSpaceToBitsPerPixel(bmode->space); @@ -191,7 +199,7 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ BScreen bscreen; /* Set the mode using the driver data */ - display_mode *bmode = (display_mode*)mode->driverdata; + display_mode *bmode = ((SDL_DisplayModeData*)mode->driverdata)->bmode; if(bscreen.SetMode(bmode) == B_OK) { return 0; /* No error */ } diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index 94725efa8..8fa88bd52 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -59,10 +59,11 @@ static SDL_VideoDevice * BE_CreateDevice(int devindex) { SDL_VideoDevice *device; - SDL_VideoData *data; + /*SDL_VideoData *data;*/ /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); +#if 0 if (device) { data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); } else { @@ -75,7 +76,8 @@ BE_CreateDevice(int devindex) } return NULL; } - device->driverdata = data; +#endif + device->driverdata = NULL; /*data;*/ /* TODO: Figure out what sort of initialization needs to go here */ diff --git a/src/video/bwindow/SDL_bvideo.h b/src/video/bwindow/SDL_bvideo.h index a50221501..50fe62c21 100644 --- a/src/video/bwindow/SDL_bvideo.h +++ b/src/video/bwindow/SDL_bvideo.h @@ -29,9 +29,6 @@ extern "C" { #include "../../main/beos/SDL_BeApp.h" #include "../SDL_sysvideo.h" -typedef struct SDL_VideoData { - -} SDL_VideoData; extern void BE_VideoQuit(_THIS); extern int BE_VideoInit(_THIS); diff --git a/src/video/bwindow/SDL_bwindow.h b/src/video/bwindow/SDL_bwindow.h index 8e6959851..a274fc753 100644 --- a/src/video/bwindow/SDL_bwindow.h +++ b/src/video/bwindow/SDL_bwindow.h @@ -25,6 +25,7 @@ #include "../SDL_sysvideo.h" + extern int BE_CreateWindow(_THIS, SDL_Window *window); extern int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); extern void BE_SetWindowTitle(_THIS, SDL_Window * window); From 8771f4019a85df38f51f5372b07cbba64c3bdb0d Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 26 Jul 2011 11:38:20 +0000 Subject: [PATCH 14/27] Fixed mouse move problem --- src/main/beos/SDL_BApp.h | 8 ++++---- src/video/bwindow/SDL_BWin.h | 7 +++---- src/video/bwindow/SDL_bmodes.cc | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 94591e0e5..2ab8c0111 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -202,16 +202,16 @@ private: void _HandleMouseMove(BMessage *msg) { SDL_Window *win; int32 winID; - int32 dx, dy; + int32 x = 0, y = 0; if( !_GetWinID(msg, &winID) || - msg->FindInt32("dx", &dx) != B_OK || /* x movement */ - msg->FindInt32("dy", &dy) != B_OK /* y movement */ + msg->FindInt32("x", &x) != B_OK || /* x movement */ + msg->FindInt32("y", &y) != B_OK /* y movement */ ) { return; } win = _GetSDLWindow(winID); - SDL_SendMouseMotion(win, 0, dx, dy); + SDL_SendMouseMotion(win, 0, x, y); } void _HandleMouseButton(BMessage *msg) { diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index b460753af..561174737 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -438,10 +438,9 @@ private: _MouseFocusEvent(true); } BMessage msg(BAPP_MOUSE_MOVED); - msg.AddInt32("dx", where.x - x); - msg.AddInt32("dy", where.y - y); - x = (int) where.x; - y = (int) where.y; + msg.AddInt32("x", (int)where.x); + msg.AddInt32("y", (int)where.y); + _PostWindowEvent(msg); } } diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 11c336cf9..29b22c054 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -151,7 +151,7 @@ int BE_InitModes(_THIS) { } int BE_QuitModes(_THIS) { - printf(__FILE__": %d; Begin quit\n", __LINE__); +/* printf(__FILE__": %d; Begin quit\n", __LINE__);*/ /* Restore the previous video mode */ BScreen screen; display_mode *savedMode = _GetBeApp()->GetPrevMode(); From 350e15ee9f4afa6db06f4ea579e38d83569215c2 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 26 Jul 2011 17:48:40 +0000 Subject: [PATCH 15/27] Corrected keyboard input support --- src/main/beos/SDL_BApp.h | 12 +- src/video/bwindow/SDL_bkeyboard.cc | 184 +++++++++++++++++++++++++++++ src/video/bwindow/SDL_bkeyboard.h | 43 +++++++ src/video/bwindow/SDL_bvideo.cc | 6 + 4 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 src/video/bwindow/SDL_bkeyboard.cc create mode 100644 src/video/bwindow/SDL_bkeyboard.h diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 2ab8c0111..2360a1d31 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -23,6 +23,9 @@ #include +#include "../../video/bwindow/SDL_bkeyboard.h" + + #ifdef __cplusplus extern "C" { #endif @@ -33,6 +36,7 @@ extern "C" { /* Local includes */ #include "../../events/SDL_events_c.h" +#include "../../video/bwindow/SDL_bkeyboard.h" #ifdef __cplusplus } @@ -252,7 +256,13 @@ private: ) { return; } - SDL_SendKeyboardKey(state, (SDL_Scancode)scancode); + + /* Make sure this isn't a repeated event (key pressed and held) */ + if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) { + return; + } + BE_SetKeyState(scancode, state); + SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode)); } void _HandleMouseFocus(BMessage *msg) { diff --git a/src/video/bwindow/SDL_bkeyboard.cc b/src/video/bwindow/SDL_bkeyboard.cc new file mode 100644 index 000000000..c2c455bed --- /dev/null +++ b/src/video/bwindow/SDL_bkeyboard.cc @@ -0,0 +1,184 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2009 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "SDL_events.h" +#include "SDL_keycode.h" + +#include "SDL_bkeyboard.h" + + +#define KEYMAP_SIZE 128 + + +static SDL_Scancode keymap[KEYMAP_SIZE]; +static int8 keystate[KEYMAP_SIZE]; + +void BE_InitOSKeymap() { + for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) { + keymap[i] = SDL_SCANCODE_UNKNOWN; + } + + for( uint i = 0; i < KEYMAP_SIZE; ++i ) { + keystate[i] = SDL_RELEASED; + } + + keymap[0x01] = SDL_GetScancodeFromKey(SDLK_ESCAPE); + keymap[B_F1_KEY] = SDL_GetScancodeFromKey(SDLK_F1); + keymap[B_F2_KEY] = SDL_GetScancodeFromKey(SDLK_F2); + keymap[B_F3_KEY] = SDL_GetScancodeFromKey(SDLK_F3); + keymap[B_F4_KEY] = SDL_GetScancodeFromKey(SDLK_F4); + keymap[B_F5_KEY] = SDL_GetScancodeFromKey(SDLK_F5); + keymap[B_F6_KEY] = SDL_GetScancodeFromKey(SDLK_F6); + keymap[B_F7_KEY] = SDL_GetScancodeFromKey(SDLK_F7); + keymap[B_F8_KEY] = SDL_GetScancodeFromKey(SDLK_F8); + keymap[B_F9_KEY] = SDL_GetScancodeFromKey(SDLK_F9); + keymap[B_F10_KEY] = SDL_GetScancodeFromKey(SDLK_F10); + keymap[B_F11_KEY] = SDL_GetScancodeFromKey(SDLK_F11); + keymap[B_F12_KEY] = SDL_GetScancodeFromKey(SDLK_F12); + keymap[B_PRINT_KEY] = SDL_GetScancodeFromKey(SDLK_PRINTSCREEN); + keymap[B_SCROLL_KEY] = SDL_GetScancodeFromKey(SDLK_SCROLLLOCK); + keymap[B_PAUSE_KEY] = SDL_GetScancodeFromKey(SDLK_PAUSE); + keymap[0x11] = SDL_GetScancodeFromKey(SDLK_BACKQUOTE); + keymap[0x12] = SDL_GetScancodeFromKey(SDLK_1); + keymap[0x13] = SDL_GetScancodeFromKey(SDLK_2); + keymap[0x14] = SDL_GetScancodeFromKey(SDLK_3); + keymap[0x15] = SDL_GetScancodeFromKey(SDLK_4); + keymap[0x16] = SDL_GetScancodeFromKey(SDLK_5); + keymap[0x17] = SDL_GetScancodeFromKey(SDLK_6); + keymap[0x18] = SDL_GetScancodeFromKey(SDLK_7); + keymap[0x19] = SDL_GetScancodeFromKey(SDLK_8); + keymap[0x1a] = SDL_GetScancodeFromKey(SDLK_9); + keymap[0x1b] = SDL_GetScancodeFromKey(SDLK_0); + keymap[0x1c] = SDL_GetScancodeFromKey(SDLK_MINUS); + keymap[0x1d] = SDL_GetScancodeFromKey(SDLK_EQUALS); + keymap[0x1e] = SDL_GetScancodeFromKey(SDLK_BACKSPACE); + keymap[0x1f] = SDL_GetScancodeFromKey(SDLK_INSERT); + keymap[0x20] = SDL_GetScancodeFromKey(SDLK_HOME); + keymap[0x21] = SDL_GetScancodeFromKey(SDLK_PAGEUP); + keymap[0x22] = SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR); + keymap[0x23] = SDL_GetScancodeFromKey(SDLK_KP_DIVIDE); + keymap[0x24] = SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY); + keymap[0x25] = SDL_GetScancodeFromKey(SDLK_KP_MINUS); + keymap[0x26] = SDL_GetScancodeFromKey(SDLK_TAB); + keymap[0x27] = SDL_GetScancodeFromKey(SDLK_q); + keymap[0x28] = SDL_GetScancodeFromKey(SDLK_w); + keymap[0x29] = SDL_GetScancodeFromKey(SDLK_e); + keymap[0x2a] = SDL_GetScancodeFromKey(SDLK_r); + keymap[0x2b] = SDL_GetScancodeFromKey(SDLK_t); + keymap[0x2c] = SDL_GetScancodeFromKey(SDLK_y); + keymap[0x2d] = SDL_GetScancodeFromKey(SDLK_u); + keymap[0x2e] = SDL_GetScancodeFromKey(SDLK_i); + keymap[0x2f] = SDL_GetScancodeFromKey(SDLK_o); + keymap[0x30] = SDL_GetScancodeFromKey(SDLK_p); + keymap[0x31] = SDL_GetScancodeFromKey(SDLK_LEFTBRACKET); + keymap[0x32] = SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET); + keymap[0x33] = SDL_GetScancodeFromKey(SDLK_BACKSLASH); + keymap[0x34] = SDL_GetScancodeFromKey(SDLK_DELETE); + keymap[0x35] = SDL_GetScancodeFromKey(SDLK_END); + keymap[0x36] = SDL_GetScancodeFromKey(SDLK_PAGEDOWN); + keymap[0x37] = SDL_GetScancodeFromKey(SDLK_KP_7); + keymap[0x38] = SDL_GetScancodeFromKey(SDLK_KP_8); + keymap[0x39] = SDL_GetScancodeFromKey(SDLK_KP_9); + keymap[0x3a] = SDL_GetScancodeFromKey(SDLK_KP_PLUS); + keymap[0x3b] = SDL_GetScancodeFromKey(SDLK_CAPSLOCK); + keymap[0x3c] = SDL_GetScancodeFromKey(SDLK_a); + keymap[0x3d] = SDL_GetScancodeFromKey(SDLK_s); + keymap[0x3e] = SDL_GetScancodeFromKey(SDLK_d); + keymap[0x3f] = SDL_GetScancodeFromKey(SDLK_f); + keymap[0x40] = SDL_GetScancodeFromKey(SDLK_g); + keymap[0x41] = SDL_GetScancodeFromKey(SDLK_h); + keymap[0x42] = SDL_GetScancodeFromKey(SDLK_j); + keymap[0x43] = SDL_GetScancodeFromKey(SDLK_k); + keymap[0x44] = SDL_GetScancodeFromKey(SDLK_l); + keymap[0x45] = SDL_GetScancodeFromKey(SDLK_SEMICOLON); + keymap[0x46] = SDL_GetScancodeFromKey(SDLK_QUOTE); + keymap[0x47] = SDL_GetScancodeFromKey(SDLK_RETURN); + keymap[0x48] = SDL_GetScancodeFromKey(SDLK_KP_4); + keymap[0x49] = SDL_GetScancodeFromKey(SDLK_KP_5); + keymap[0x4a] = SDL_GetScancodeFromKey(SDLK_KP_6); + keymap[0x4b] = SDL_GetScancodeFromKey(SDLK_LSHIFT); + keymap[0x4c] = SDL_GetScancodeFromKey(SDLK_z); + keymap[0x4d] = SDL_GetScancodeFromKey(SDLK_x); + keymap[0x4e] = SDL_GetScancodeFromKey(SDLK_c); + keymap[0x4f] = SDL_GetScancodeFromKey(SDLK_v); + keymap[0x50] = SDL_GetScancodeFromKey(SDLK_b); + keymap[0x51] = SDL_GetScancodeFromKey(SDLK_n); + keymap[0x52] = SDL_GetScancodeFromKey(SDLK_m); + keymap[0x53] = SDL_GetScancodeFromKey(SDLK_COMMA); + keymap[0x54] = SDL_GetScancodeFromKey(SDLK_PERIOD); + keymap[0x55] = SDL_GetScancodeFromKey(SDLK_SLASH); + keymap[0x56] = SDL_GetScancodeFromKey(SDLK_RSHIFT); + keymap[0x57] = SDL_GetScancodeFromKey(SDLK_UP); + keymap[0x58] = SDL_GetScancodeFromKey(SDLK_KP_1); + keymap[0x59] = SDL_GetScancodeFromKey(SDLK_KP_2); + keymap[0x5a] = SDL_GetScancodeFromKey(SDLK_KP_3); + keymap[0x5b] = SDL_GetScancodeFromKey(SDLK_KP_ENTER); + keymap[0x5c] = SDL_GetScancodeFromKey(SDLK_LCTRL); + keymap[0x5d] = SDL_GetScancodeFromKey(SDLK_LALT); + keymap[0x5e] = SDL_GetScancodeFromKey(SDLK_SPACE); + keymap[0x5f] = SDL_GetScancodeFromKey(SDLK_RALT); + keymap[0x60] = SDL_GetScancodeFromKey(SDLK_RCTRL); + keymap[0x61] = SDL_GetScancodeFromKey(SDLK_LEFT); + keymap[0x62] = SDL_GetScancodeFromKey(SDLK_DOWN); + keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT); + keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0); + keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD); + keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); /* FIXME: Is this the right translation? */ + keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); /* FIXME: Is this the right translation? */ + keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU); + keymap[0x69] = SDL_GetScancodeFromKey(SDLK_UNKNOWN); /* FIXME: I couldn't find a translation */ + keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS); + keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER); +} + +SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) { + if(bkey > 0 && bkey < SDL_TABLESIZE(keymap)) { + return keymap[bkey]; + } else { + return SDL_SCANCODE_UNKNOWN; + } +} + +int8 BE_GetKeyState(int32 bkey) { + if(bkey > 0 && bkey < KEYMAP_SIZE) { + return keystate[bkey]; + } else { + return SDL_RELEASED; + } +} + +void BE_SetKeyState(int32 bkey, int8 state) { + if(bkey > 0 && bkey < KEYMAP_SIZE) { + keystate[bkey] = state; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bkeyboard.h b/src/video/bwindow/SDL_bkeyboard.h new file mode 100644 index 000000000..bad9eeaad --- /dev/null +++ b/src/video/bwindow/SDL_bkeyboard.h @@ -0,0 +1,43 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2009 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef SDL_BKEYBOARD_H +#define SDL_BKEYBOARD_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../../include/SDL_keyboard.h" + +extern void BE_InitOSKeymap(); +extern SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey); +extern int8 BE_GetKeyState(int32 bkey); +extern void BE_SetKeyState(int32 bkey, int8 state); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index 8fa88bd52..cdf10bb4b 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -26,6 +26,7 @@ extern "C" { #endif +#include "SDL_bkeyboard.h" #include "SDL_bwindow.h" #include "SDL_bclipboard.h" #include "SDL_bvideo.h" @@ -159,8 +160,13 @@ int BE_VideoInit(_THIS) return -1; } + /* Initialize video modes */ BE_InitModes(_this); + /* Init the keymap */ + BE_InitOSKeymap(); + + #if SDL_VIDEO_OPENGL /* testgl application doesn't load library, just tries to load symbols */ /* is it correct? if so we have to load library here */ From bf4cf189050ccc87607937bd57d56f7618d7d879 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 27 Jul 2011 11:06:38 +0000 Subject: [PATCH 16/27] Moved draw code to a separate thread --- src/main/beos/SDL_BApp.h | 37 +++++++++----- src/main/beos/SDL_BeApp.cc | 2 +- src/video/bwindow/SDL_BWin.h | 27 +++++++--- src/video/bwindow/SDL_bmodes.cc | 89 +++++++++++++++++++++------------ src/video/bwindow/SDL_bmodes.h | 1 + 5 files changed, 101 insertions(+), 55 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 2360a1d31..2af37abf8 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -37,6 +37,7 @@ extern "C" { /* Local includes */ #include "../../events/SDL_events_c.h" #include "../../video/bwindow/SDL_bkeyboard.h" +#include "../../video/bwindow/SDL_bmodes.h" #ifdef __cplusplus } @@ -167,7 +168,7 @@ public: int32 GetID(SDL_Window *win) { int32 i; for(i = 0; i < _GetNumWindowSlots(); ++i) { - if( _GetSDLWindow(i) == NULL ) { + if( GetSDLWindow(i) == NULL ) { _SetSDLWindow(win, i); return i; } @@ -189,6 +190,11 @@ public: there another way to do this? */ void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ + + SDL_Window *GetSDLWindow(int32 winID) { + return window_map[winID]; + } + private: /* Event management */ void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) { @@ -199,7 +205,7 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendWindowEvent(win, sdlEventType, 0, 0); } @@ -214,8 +220,11 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendMouseMotion(win, 0, x, y); + + /* FIXME: Attempt at fixing rendering problems */ + BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); } void _HandleMouseButton(BMessage *msg) { @@ -229,7 +238,7 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendMouseButton(win, state, button); } @@ -244,7 +253,7 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendMouseWheel(win, xTicks, yTicks); } @@ -275,7 +284,7 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); if(bSetFocus) { SDL_SetMouseFocus(win); } else if(SDL_GetMouseFocus() == win) { @@ -294,7 +303,7 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); if(bSetFocus) { SDL_SetKeyboardFocus(win); } else if(SDL_GetKeyboardFocus() == win) { @@ -315,8 +324,11 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos); + + /* FIXME: Attempt at fixing rendering problems */ + BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); } void _HandleWindowResized(BMessage *msg) { @@ -331,8 +343,11 @@ private: ) { return; } - win = _GetSDLWindow(winID); + win = GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); + + /* FIXME: Attempt at fixing rendering problems */ + BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); } bool _GetWinID(BMessage *msg, int32 *winID) { @@ -342,10 +357,6 @@ private: /* Vector imitators */ - SDL_Window *_GetSDLWindow(int32 winID) { - return window_map[winID]; - } - void _SetSDLWindow(SDL_Window *win, int32 winID) { window_map[winID] = win; } diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 708109c01..f54d55cd2 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -126,7 +126,7 @@ SDL_QuitBeApp(void) void SDL_BApp::ClearID(SDL_BWin *bwin) { _SetSDLWindow(NULL, bwin->GetID()); int32 i = _GetNumWindowSlots() - 1; - while(i >= 0 && _GetSDLWindow(i) == NULL) { + while(i >= 0 && GetSDLWindow(i) == NULL) { _PopBackWindow(); --i; } diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 561174737..645d6bfdc 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -76,9 +76,14 @@ class SDL_BWin:public BDirectWindow /* Handle framebuffer stuff */ _connected = _connection_disabled = false; + _buffer_created = _buffer_dirty = false; _trash__window_buffer = false; _buffer_locker = new BLocker(); _window_buffer = NULL; + + _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", + B_NORMAL_PRIORITY, (void*) this); + resume_thread(_draw_thread_id); // LockBuffer(); /* Unlocked by buffer initialization */ } @@ -86,6 +91,7 @@ class SDL_BWin:public BDirectWindow { Lock(); _connection_disabled = true; + int32 result; #if SDL_VIDEO_OPENGL if (_SDL_GLView) { @@ -102,6 +108,7 @@ class SDL_BWin:public BDirectWindow /* Clean up framebuffer stuff */ _buffer_locker->Lock(); + wait_for_thread(_draw_thread_id, &result); free(_clips); delete _buffer_locker; } @@ -382,8 +389,6 @@ class SDL_BWin:public BDirectWindow /* Accessor methods */ bool IsShown() { return _shown; } int32 GetID() { return _id; } - void LockBuffer() { _buffer_locker->Lock(); } - void UnlockBuffer() { _buffer_locker->Unlock(); } uint32 GetRowBytes() { return _row_bytes; } int32 GetFbX() { return _bounds.left; } int32 GetFbY() { return _bounds.top; } @@ -395,12 +400,18 @@ class SDL_BWin:public BDirectWindow int32 GetNumClips() { return _num_clips; } uint8* GetBufferPx() { return _bits; } int32 GetBytesPerPx() { return _bytes_per_px; } - void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } uint8* GetWindowFramebuffer() { return _window_buffer; } bool CanTrashWindowBuffer() { return _trash__window_buffer; } + bool BufferExists() { return _buffer_created; } + bool BufferIsDirty() { return _buffer_dirty; } /* Setter methods */ void SetID(int32 id) { _id = id; } + bool SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; } + void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } + void LockBuffer() { _buffer_locker->Lock(); } + void UnlockBuffer() { _buffer_locker->Unlock(); } + void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } @@ -416,10 +427,6 @@ class SDL_BWin:public BDirectWindow { return (_the_view); } - - - - @@ -584,7 +591,10 @@ private: BRect *_prev_frame; /* Previous position and size of the window */ /* Framebuffer members */ - bool _connected, _connection_disabled; + bool _connected, + _connection_disabled, + _buffer_created, + _buffer_dirty; uint8 *_bits; uint32 _row_bytes; clipping_rect _bounds; @@ -594,6 +604,7 @@ private: int32 _bytes_per_px; uint8 *_window_buffer; /* A copy of the window buffer */ bool _trash__window_buffer; + thread_id _draw_thread_id; }; #endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 29b22c054..40d13d326 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -218,7 +218,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, return -1; } - while(!bwin->Connected()) { snooze(10); } + while(!bwin->Connected()) { snooze(100); } /* Make sure we have exclusive access to frame buffer data */ bwin->LockBuffer(); @@ -243,6 +243,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, bwin->SetWindowFramebuffer((uint8*)(*pixels)); } + bwin->SetBufferExists(true); bwin->UnlockBuffer(); return 0; } @@ -251,51 +252,72 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) { + if(!window) + return 0; + SDL_BWin *bwin = _ToBeWin(window); + + bwin->LockBuffer(); + bwin->SetBufferDirty(true); + bwin->UnlockBuffer(); + + return 0; +} + +int32 BE_DrawThread(void *data) { + SDL_BWin *bwin = (SDL_BWin*)data; + SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID()); + BScreen bscreen; if(!bscreen.IsValid()) { return -1; } - if(bwin->ConnectionEnabled() && bwin->Connected()) { - bwin->LockBuffer(); - int32 windowPitch = window->surface->pitch; - int32 bufferPitch = bwin->GetRowBytes(); - uint8 *windowpx; - uint8 *bufferpx; + while(bwin->ConnectionEnabled()) { + if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { + bwin->LockBuffer(); + int32 windowPitch = window->surface->pitch; + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; - int32 BPP = bwin->GetBytesPerPx(); - uint8 *windowBaseAddress = (uint8*)window->surface->pixels; - int32 windowSub = bwin->GetFbX() * BPP + + int32 BPP = bwin->GetBytesPerPx(); + uint8 *windowBaseAddress = (uint8*)window->surface->pixels; + int32 windowSub = bwin->GetFbX() * BPP + bwin->GetFbY() * windowPitch; - clipping_rect *clips = bwin->GetClips(); - int32 numClips = bwin->GetNumClips(); - int i, y; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; - /* Blit each clipping rectangle */ - bscreen.WaitForRetrace(); - for(i = 0; i < numClips; ++i) { - clipping_rect rc = clips[i]; - /* Get addresses of the start of each clipping rectangle */ - int32 width = clips[i].right - clips[i].left + 1; - int32 height = clips[i].bottom - clips[i].top + 1; - bufferpx = bwin->GetBufferPx() + - clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + clipping_rect rc = clips[i]; + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * BPP; + windowpx = windowBaseAddress + + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; - /* Copy each row of pixels from the window buffer into the frame - buffer */ - for(y = 0; y < height; ++y) - { - memcpy(bufferpx, windowpx, width * BPP); - bufferpx += bufferPitch; - windowpx += windowPitch; + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + memcpy(bufferpx, windowpx, width * BPP); + bufferpx += bufferPitch; + windowpx += windowPitch; + } } + bwin->SetBufferDirty(false); + bwin->UnlockBuffer(); + } else { + snooze(1000); } - bwin->UnlockBuffer(); } - return 0; + + return B_OK; } void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { @@ -307,6 +329,7 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { uint8* winBuffer = bwin->GetWindowFramebuffer(); SDL_free(winBuffer); bwin->SetWindowFramebuffer(NULL); + bwin->SetBufferExists(false); bwin->UnlockBuffer(); } diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h index af080c524..044441af4 100644 --- a/src/video/bwindow/SDL_bmodes.h +++ b/src/video/bwindow/SDL_bmodes.h @@ -42,6 +42,7 @@ extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); +extern int32 BE_DrawThread(void *data); #ifdef __cplusplus From 41cbb17de72c20dda779f884ad1cc6eb106b62d2 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Thu, 28 Jul 2011 18:21:38 +0000 Subject: [PATCH 17/27] Render thread partially corrected --- src/main/beos/SDL_BApp.h | 44 ++---------------------------- src/video/bwindow/SDL_BWin.h | 31 +++++++++++---------- src/video/bwindow/SDL_bkeyboard.cc | 6 ++-- src/video/bwindow/SDL_bmodes.cc | 25 +++++++++-------- 4 files changed, 36 insertions(+), 70 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 2af37abf8..58aea50af 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -345,7 +345,7 @@ private: } win = GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); - + /* FIXME: Attempt at fixing rendering problems */ BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); } @@ -356,66 +356,28 @@ private: - /* Vector imitators */ + /* Vector functions: Wraps vector stuff in case we need to change + implementation */ void _SetSDLWindow(SDL_Window *win, int32 winID) { window_map[winID] = win; } int32 _GetNumWindowSlots() { -#ifdef __cplusplus return window_map.size(); -#else - return _size; -#endif } void _PopBackWindow() { -#ifdef __cplusplus window_map.pop_back(); -#else - --_size; -#endif } void _PushBackWindow(SDL_Window *win) { -#ifdef __cplusplus window_map.push_back(win); -#else - /* Resize array */ - if(_length == _size) { - _ResizeArray(); - } - - window_map[_size] = win; - ++_size; -#endif } -#ifndef __cplusplus - _ResizeArray() { - _length += 4; /* Increase capacity by some arbitrary number */ - SDL_Window *temp = (SDL_Window*)SDL_calloc(_length, - sizeof(SDL_Window*)); - - /* Move windows from old list to new list */ - int32 i; - for(i = 0; i < _size; ++i) { - temp[i] = window_map[i]; - } - SDL_free(window_map); - window_map = temp; - } -#endif /* Members */ -#ifdef __cplusplus vector window_map; /* Keeps track of SDL_Windows by index-id */ -#else - int32 _size; - int32 _length; - SDL_Window *window_map; -#endif display_mode *saved_mode; }; diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 645d6bfdc..3e7bcfdf8 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -77,14 +77,13 @@ class SDL_BWin:public BDirectWindow /* Handle framebuffer stuff */ _connected = _connection_disabled = false; _buffer_created = _buffer_dirty = false; - _trash__window_buffer = false; + _trash_window_buffer = false; _buffer_locker = new BLocker(); _window_buffer = NULL; _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", B_NORMAL_PRIORITY, (void*) this); resume_thread(_draw_thread_id); -// LockBuffer(); /* Unlocked by buffer initialization */ } virtual ~ SDL_BWin() @@ -153,8 +152,13 @@ class SDL_BWin:public BDirectWindow if(!_connected && _connection_disabled) { return; } + + /* Determine if the pixel buffer is usable after this update */ + _trash_window_buffer = _trash_window_buffer + || ((info->buffer_state & B_BUFFER_RESIZED) + || (info->buffer_state & B_BUFFER_RESET)); LockBuffer(); - + switch(info->buffer_state & B_DIRECT_MODE_MASK) { case B_DIRECT_START: _connected = true; @@ -165,12 +169,6 @@ class SDL_BWin:public BDirectWindow _clips = NULL; } - /* Can we reuse the window's pixel buffer after this? */ - _trash__window_buffer = ((info->buffer_state & B_BUFFER_RESIZED) - || (info->buffer_state & B_BUFFER_RESET) - || ((info->buffer_state & B_DIRECT_MODE_MASK) - == B_DIRECT_START)); - _num_clips = info->clip_list_count; _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect)); if(_clips) { @@ -181,16 +179,18 @@ class SDL_BWin:public BDirectWindow _row_bytes = info->bytes_per_row; _bounds = info->window_bounds; _bytes_per_px = info->bits_per_pixel / 8; + _buffer_dirty = true; + + /* Now we check for a good buffer */ +// SetBufferExists(!_trash_window_buffer); } - - /* Whatever the case, I think this merits a repaint event */ -// _RepaintEvent(); break; case B_DIRECT_STOP: _connected = false; break; } + UnlockBuffer(); } @@ -401,17 +401,18 @@ class SDL_BWin:public BDirectWindow uint8* GetBufferPx() { return _bits; } int32 GetBytesPerPx() { return _bytes_per_px; } uint8* GetWindowFramebuffer() { return _window_buffer; } - bool CanTrashWindowBuffer() { return _trash__window_buffer; } + bool CanTrashWindowBuffer() { return _trash_window_buffer; } bool BufferExists() { return _buffer_created; } bool BufferIsDirty() { return _buffer_dirty; } /* Setter methods */ void SetID(int32 id) { _id = id; } - bool SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; } + void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; } void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } void LockBuffer() { _buffer_locker->Lock(); } void UnlockBuffer() { _buffer_locker->Unlock(); } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } + void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; } @@ -603,7 +604,7 @@ private: int32 _num_clips; int32 _bytes_per_px; uint8 *_window_buffer; /* A copy of the window buffer */ - bool _trash__window_buffer; + bool _trash_window_buffer; thread_id _draw_thread_id; }; diff --git a/src/video/bwindow/SDL_bkeyboard.cc b/src/video/bwindow/SDL_bkeyboard.cc index c2c455bed..c153539ca 100644 --- a/src/video/bwindow/SDL_bkeyboard.cc +++ b/src/video/bwindow/SDL_bkeyboard.cc @@ -149,10 +149,10 @@ void BE_InitOSKeymap() { keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT); keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0); keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD); - keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); /* FIXME: Is this the right translation? */ - keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); /* FIXME: Is this the right translation? */ + keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); + keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU); - keymap[0x69] = SDL_GetScancodeFromKey(SDLK_UNKNOWN); /* FIXME: I couldn't find a translation */ + keymap[0x69] = SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */ keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS); keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER); } diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 40d13d326..79058e8b6 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -217,12 +217,12 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, if(!bscreen.IsValid()) { return -1; } - - while(!bwin->Connected()) { snooze(100); } + while(!bwin->Connected()) { snooze(100); } + /* Make sure we have exclusive access to frame buffer data */ bwin->LockBuffer(); - + /* format */ display_mode bmode; bscreen.GetMode(&bmode); @@ -234,16 +234,15 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Create a copy of the pixel buffer if it doesn't recycle */ *pixels = bwin->GetWindowFramebuffer(); - if( bwin->CanTrashWindowBuffer() || (*pixels) == NULL) { - if( (*pixels) != NULL ) { - SDL_free(*pixels); - } - *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * - bwin->GetBytesPerPx(), sizeof(uint8)); - bwin->SetWindowFramebuffer((uint8*)(*pixels)); + if( (*pixels) != NULL ) { + SDL_free(*pixels); } + *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * + bwin->GetBytesPerPx(), sizeof(uint8)); + bwin->SetWindowFramebuffer((uint8*)(*pixels)); bwin->SetBufferExists(true); + bwin->SetTrashBuffer(false); bwin->UnlockBuffer(); return 0; } @@ -305,15 +304,19 @@ int32 BE_DrawThread(void *data) { buffer */ for(y = 0; y < height; ++y) { + if(bwin->CanTrashWindowBuffer()) { + goto escape; /* Break out before the buffer is killed */ + } memcpy(bufferpx, windowpx, width * BPP); bufferpx += bufferPitch; windowpx += windowPitch; } } bwin->SetBufferDirty(false); +escape: bwin->UnlockBuffer(); } else { - snooze(1000); + snooze(16000); } } From 2f9415199b6b97e00729e76ca99f94062299d96a Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Sat, 30 Jul 2011 18:26:13 +0000 Subject: [PATCH 18/27] Framebuffer code moved to SDL_bframebuffer.*, OpenGL support began --- src/main/beos/SDL_BApp.h | 49 ++++---- src/video/bwindow/SDL_BWin.h | 83 +++++-------- src/video/bwindow/SDL_bframebuffer.cc | 172 ++++++++++++++++++++++++++ src/video/bwindow/SDL_bframebuffer.h | 43 +++++++ src/video/bwindow/SDL_bmodes.cc | 131 +------------------- src/video/bwindow/SDL_bmodes.h | 12 +- src/video/bwindow/SDL_bopengl.cc | 73 +++++++---- src/video/bwindow/SDL_bopengl.h | 15 ++- src/video/bwindow/SDL_bvideo.cc | 19 +-- 9 files changed, 341 insertions(+), 256 deletions(-) create mode 100644 src/video/bwindow/SDL_bframebuffer.cc create mode 100644 src/video/bwindow/SDL_bframebuffer.h diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 58aea50af..053db8b46 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -22,6 +22,7 @@ #define SDL_BAPP_H #include +#include #include "../../video/bwindow/SDL_bkeyboard.h" @@ -37,16 +38,14 @@ extern "C" { /* Local includes */ #include "../../events/SDL_events_c.h" #include "../../video/bwindow/SDL_bkeyboard.h" -#include "../../video/bwindow/SDL_bmodes.h" +#include "../../video/bwindow/SDL_bframebuffer.h" #ifdef __cplusplus } - -#include /* Vector should only be included if we use a C++ - compiler */ - #endif +#include + @@ -82,18 +81,15 @@ class SDL_BApp : public BApplication { public: SDL_BApp(const char* signature) : BApplication(signature) { -#ifndef __cplusplus - /* Set vector imitation variables */ - _ResizeArray(); - _size = 0; - _length = 0; -#endif + _current_context = NULL; } + + virtual ~SDL_BApp() { -#ifndef __cplusplus - SDL_free(window_map); -#endif } + + + /* Event-handling functions */ virtual void MessageReceived(BMessage* message) { /* Sort out SDL-related messages */ @@ -182,9 +178,9 @@ public: } /* Modes methods */ - void SetPrevMode(display_mode *prevMode) { saved_mode = prevMode; } + void SetPrevMode(display_mode *prevMode) { _saved_mode = prevMode; } - display_mode* GetPrevMode() { return saved_mode; } + display_mode* GetPrevMode() { return _saved_mode; } /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is there another way to do this? */ @@ -192,9 +188,15 @@ public: SDL_Window *GetSDLWindow(int32 winID) { - return window_map[winID]; + return _window_map[winID]; } + void SetCurrentContext(BGLView *newContext) { + if(_current_context) + _current_context->UnlockGL(); + _current_context = newContext; + _current_context->LockGL(); + } private: /* Event management */ void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) { @@ -359,27 +361,28 @@ private: /* Vector functions: Wraps vector stuff in case we need to change implementation */ void _SetSDLWindow(SDL_Window *win, int32 winID) { - window_map[winID] = win; + _window_map[winID] = win; } int32 _GetNumWindowSlots() { - return window_map.size(); + return _window_map.size(); } void _PopBackWindow() { - window_map.pop_back(); + _window_map.pop_back(); } void _PushBackWindow(SDL_Window *win) { - window_map.push_back(win); + _window_map.push_back(win); } /* Members */ - vector window_map; /* Keeps track of SDL_Windows by index-id */ + vector _window_map; /* Keeps track of SDL_Windows by index-id */ - display_mode *saved_mode; + display_mode *_saved_mode; + BGLView *_current_context; }; #endif diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 3e7bcfdf8..f52180e82 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -29,6 +29,7 @@ extern "C" { #include "SDL_config.h" #include "SDL.h" #include "SDL_syswm.h" +#include "SDL_bframebuffer.h" #ifdef __cplusplus } @@ -44,6 +45,7 @@ extern "C" { #include "SDL_events.h" #include "../../main/beos/SDL_BApp.h" + enum WinCommands { BWIN_MOVE_WINDOW, BWIN_RESIZE_WINDOW, @@ -113,38 +115,36 @@ class SDL_BWin:public BDirectWindow } - /* Other construction */ + /* * * * * OpenGL functionality * * * * */ #if SDL_VIDEO_OPENGL - virtual int CreateView(Uint32 flags, Uint32 gl_flags) - { - int retval; - - retval = 0; + virtual BGLView *CreateGLView(Uint32 gl_flags) { Lock(); - if (flags & SDL_OPENGL/*SDL_INTERNALOPENGL*/) { - if (_SDL_GLView == NULL) { - _SDL_GLView = new BGLView(Bounds(), "SDL GLView", - B_FOLLOW_ALL_SIDES, - (B_WILL_DRAW | B_FRAME_EVENTS), - gl_flags); - } - if (_the_view != _SDL_GLView) { - if (_the_view) { - RemoveChild(_the_view); - } - AddChild(_SDL_GLView); - _SDL_GLView->LockGL(); - _the_view = _SDL_GLView; - } - } else { - if (_the_view) { - _SDL_GLView->UnlockGL(); - RemoveChild(_the_view); - } + if (_SDL_GLView == NULL) { + _SDL_GLView = new BGLView(Bounds(), "SDL GLView", + B_FOLLOW_ALL_SIDES, + (B_WILL_DRAW | B_FRAME_EVENTS), + gl_flags); } + AddChild(_SDL_GLView); + _SDL_GLView->LockGL(); /* "New" GLViews are created */ Unlock(); - return (retval); + return (_SDL_GLView); } + + virtual void RemoveGLView() { + Lock(); + if(_SDL_GLView) { + _SDL_GLView->UnlockGL(); + RemoveChild(_SDL_GLView); + } + Unlock(); + } + + virtual void SwapBuffers(void) { + _SDL_GLView->UnlockGL(); + _SDL_GLView->LockGL(); + _SDL_GLView->SwapBuffers(); + } #endif /* * * * * Framebuffering* * * * */ @@ -180,9 +180,6 @@ class SDL_BWin:public BDirectWindow _bounds = info->window_bounds; _bytes_per_px = info->bits_per_pixel / 8; _buffer_dirty = true; - - /* Now we check for a good buffer */ -// SetBufferExists(!_trash_window_buffer); } break; @@ -190,6 +187,11 @@ class SDL_BWin:public BDirectWindow _connected = false; break; } +#if SDL_VIDEO_OPENGL + if(_SDL_GLView) { + _SDL_GLView->DirectConnected(info); + } +#endif UnlockBuffer(); } @@ -213,8 +215,8 @@ class SDL_BWin:public BDirectWindow virtual void FrameResized(float width, float height) { /* Post a message to the BApp so that it can handle the window event */ BMessage msg(BAPP_WINDOW_RESIZED); - msg.AddInt32("window-w", (int)width) + 1; /* TODO: Check that +1 is needed */ - msg.AddInt32("window-h", (int)height) + 1; + msg.AddInt32("window-w", (int)width + 1); /* TODO: Check that +1 is needed */ + msg.AddInt32("window-h", (int)height + 1); _PostWindowEvent(msg); /* Perform normal hook operations */ @@ -413,22 +415,6 @@ class SDL_BWin:public BDirectWindow void UnlockBuffer() { _buffer_locker->Unlock(); } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; } - - - -#if SDL_VIDEO_OPENGL - virtual void SwapBuffers(void) - { - _SDL_GLView->UnlockGL(); - _SDL_GLView->LockGL(); - _SDL_GLView->SwapBuffers(); - } -#endif - virtual BView *View(void) - { - return (_the_view); - } - private: @@ -581,7 +567,6 @@ private: #if SDL_VIDEO_OPENGL BGLView * _SDL_GLView; #endif - BView *_the_view; int32 _last_buttons; int32 _id; /* Window id used by SDL_BApp */ diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc new file mode 100644 index 000000000..98634a49e --- /dev/null +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -0,0 +1,172 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_bframebuffer.h" + +#include +#include +#include "SDL_bmodes.h" +#include "SDL_BWin.h" + +#include "../../main/beos/SDL_BApp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static inline SDL_BWin *_ToBeWin(SDL_Window *window) { + return ((SDL_BWin*)(window->driverdata)); +} + +static inline SDL_BApp *_GetBeApp() { + return ((SDL_BApp*)be_app); +} + +int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch) { + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + while(!bwin->Connected()) { snooze(100); } + + /* Make sure we have exclusive access to frame buffer data */ + bwin->LockBuffer(); + + /* format */ + display_mode bmode; + bscreen.GetMode(&bmode); + int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); + *format = BPPToSDLPxFormat(bpp); + + /* pitch = width of screen, in bytes */ + *pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx(); + + /* Create a copy of the pixel buffer if it doesn't recycle */ + *pixels = bwin->GetWindowFramebuffer(); + if( (*pixels) != NULL ) { + SDL_free(*pixels); + } + *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * + bwin->GetBytesPerPx(), sizeof(uint8)); + bwin->SetWindowFramebuffer((uint8*)(*pixels)); + + bwin->SetBufferExists(true); + bwin->SetTrashBuffer(false); + bwin->UnlockBuffer(); + return 0; +} + + + +int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects) { + if(!window) + return 0; + + SDL_BWin *bwin = _ToBeWin(window); + + bwin->LockBuffer(); + bwin->SetBufferDirty(true); + bwin->UnlockBuffer(); + + return 0; +} + +int32 BE_DrawThread(void *data) { + SDL_BWin *bwin = (SDL_BWin*)data; + SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID()); + + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + while(bwin->ConnectionEnabled()) { + if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { + bwin->LockBuffer(); + int32 windowPitch = window->surface->pitch; + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; + + int32 BPP = bwin->GetBytesPerPx(); + uint8 *windowBaseAddress = (uint8*)window->surface->pixels; + int32 windowSub = bwin->GetFbX() * BPP + + bwin->GetFbY() * windowPitch; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; + + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + clipping_rect rc = clips[i]; + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * BPP; + windowpx = windowBaseAddress + + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + if(bwin->CanTrashWindowBuffer()) { + goto escape; /* Break out before the buffer is killed */ + } + memcpy(bufferpx, windowpx, width * BPP); + bufferpx += bufferPitch; + windowpx += windowPitch; + } + } + bwin->SetBufferDirty(false); +escape: + bwin->UnlockBuffer(); + } else { + snooze(16000); + } + } + + return B_OK; +} + +void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { + SDL_BWin *bwin = _ToBeWin(window); + + bwin->LockBuffer(); + + /* Free and clear the window buffer */ + uint8* winBuffer = bwin->GetWindowFramebuffer(); + SDL_free(winBuffer); + bwin->SetWindowFramebuffer(NULL); + bwin->SetBufferExists(false); + bwin->UnlockBuffer(); +} + +#ifdef __cplusplus +} +#endif diff --git a/src/video/bwindow/SDL_bframebuffer.h b/src/video/bwindow/SDL_bframebuffer.h new file mode 100644 index 000000000..d34b530c0 --- /dev/null +++ b/src/video/bwindow/SDL_bframebuffer.h @@ -0,0 +1,43 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_BFRAMEBUFFER_H +#define SDL_BFRAMEBUFFER_H +#include +#ifdef __cplusplus +extern "C" { +#endif + +#include "../SDL_sysvideo.h" + +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, + Uint32 * format, + void ** pixels, int *pitch); +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, + SDL_Rect * rects, int numrects); +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); +extern int32 BE_DrawThread(void *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 79058e8b6..a75801433 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -54,7 +54,7 @@ static float get_refresh_rate(display_mode &mode) { / float(mode.timing.h_total * mode.timing.v_total); } -static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) +static inline int32 ColorSpaceToBitsPerPixel(uint32 colorspace) { int bitsperpixel; @@ -207,135 +207,6 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ return -1; } - - -int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, - Uint32 * format, - void ** pixels, int *pitch) { - SDL_BWin *bwin = _ToBeWin(window); - BScreen bscreen; - if(!bscreen.IsValid()) { - return -1; - } - - while(!bwin->Connected()) { snooze(100); } - - /* Make sure we have exclusive access to frame buffer data */ - bwin->LockBuffer(); - - /* format */ - display_mode bmode; - bscreen.GetMode(&bmode); - int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); - *format = BPPToSDLPxFormat(bpp); - - /* pitch = width of screen, in bytes */ - *pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx(); - - /* Create a copy of the pixel buffer if it doesn't recycle */ - *pixels = bwin->GetWindowFramebuffer(); - if( (*pixels) != NULL ) { - SDL_free(*pixels); - } - *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * - bwin->GetBytesPerPx(), sizeof(uint8)); - bwin->SetWindowFramebuffer((uint8*)(*pixels)); - - bwin->SetBufferExists(true); - bwin->SetTrashBuffer(false); - bwin->UnlockBuffer(); - return 0; -} - - - -int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) { - if(!window) - return 0; - - SDL_BWin *bwin = _ToBeWin(window); - - bwin->LockBuffer(); - bwin->SetBufferDirty(true); - bwin->UnlockBuffer(); - - return 0; -} - -int32 BE_DrawThread(void *data) { - SDL_BWin *bwin = (SDL_BWin*)data; - SDL_Window *window = _GetBeApp()->GetSDLWindow(bwin->GetID()); - - BScreen bscreen; - if(!bscreen.IsValid()) { - return -1; - } - - while(bwin->ConnectionEnabled()) { - if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { - bwin->LockBuffer(); - int32 windowPitch = window->surface->pitch; - int32 bufferPitch = bwin->GetRowBytes(); - uint8 *windowpx; - uint8 *bufferpx; - - int32 BPP = bwin->GetBytesPerPx(); - uint8 *windowBaseAddress = (uint8*)window->surface->pixels; - int32 windowSub = bwin->GetFbX() * BPP + - bwin->GetFbY() * windowPitch; - clipping_rect *clips = bwin->GetClips(); - int32 numClips = bwin->GetNumClips(); - int i, y; - - /* Blit each clipping rectangle */ - bscreen.WaitForRetrace(); - for(i = 0; i < numClips; ++i) { - clipping_rect rc = clips[i]; - /* Get addresses of the start of each clipping rectangle */ - int32 width = clips[i].right - clips[i].left + 1; - int32 height = clips[i].bottom - clips[i].top + 1; - bufferpx = bwin->GetBufferPx() + - clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * BPP - windowSub; - - /* Copy each row of pixels from the window buffer into the frame - buffer */ - for(y = 0; y < height; ++y) - { - if(bwin->CanTrashWindowBuffer()) { - goto escape; /* Break out before the buffer is killed */ - } - memcpy(bufferpx, windowpx, width * BPP); - bufferpx += bufferPitch; - windowpx += windowPitch; - } - } - bwin->SetBufferDirty(false); -escape: - bwin->UnlockBuffer(); - } else { - snooze(16000); - } - } - - return B_OK; -} - -void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { - SDL_BWin *bwin = _ToBeWin(window); - - bwin->LockBuffer(); - - /* Free and clear the window buffer */ - uint8* winBuffer = bwin->GetWindowFramebuffer(); - SDL_free(winBuffer); - bwin->SetWindowFramebuffer(NULL); - bwin->SetBufferExists(false); - bwin->UnlockBuffer(); -} - #ifdef __cplusplus } #endif diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h index 044441af4..04055a128 100644 --- a/src/video/bwindow/SDL_bmodes.h +++ b/src/video/bwindow/SDL_bmodes.h @@ -28,6 +28,9 @@ extern "C" { #include "../SDL_sysvideo.h" +extern int32 ColorSpaceToBitsPerPixel(uint32 colorspace); +extern int32 BPPToSDLPxFormat(int32 bpp); + extern int BE_InitModes(_THIS); extern int BE_QuitModes(_THIS); extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, @@ -36,15 +39,6 @@ extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display); extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, - Uint32 * format, - void ** pixels, int *pitch); -extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); -extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); -extern int32 BE_DrawThread(void *data); - - #ifdef __cplusplus } #endif diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index a81820b08..6fbc2682d 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -21,14 +21,27 @@ #include "SDL_bopengl.h" +#include +#include +#include +#include "SDL_BWin.h" +#include "../../main/beos/SDL_BApp.h" + #ifdef __cplusplus extern "C" { #endif +static inline SDL_BWin *_ToBeWin(SDL_Window *window) { + return ((SDL_BWin*)(window->driverdata)); +} + +static inline SDL_BApp *_GetBeApp() { + return ((SDL_BApp*)be_app); +} + /* Passing a NULL path means load pointers from the application */ int BE_GL_LoadLibrary(_THIS, const char *path) { -#if 0 if (path == NULL) { if (_this->gl_config.dll_handle == NULL) { image_info info; @@ -83,12 +96,10 @@ int BE_GL_LoadLibrary(_THIS, const char *path) *_this->gl_config.driver_path = '\0'; return -1; } -#endif } void *BE_GL_GetProcAddress(_THIS, const char *proc) { -#if 0 if (_this->gl_config.dll_handle != NULL) { void *location = NULL; status_t err; @@ -105,29 +116,9 @@ void *BE_GL_GetProcAddress(_THIS, const char *proc) SDL_SetError("OpenGL library not loaded"); return NULL; } -#endif } - - -int BE_GL_MakeCurrent(_THIS) -{ - /* FIXME: should we glview->unlock and then glview->lock()? */ - return 0; -} - - - - - - - - - - - - #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */ int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) @@ -190,11 +181,39 @@ int BE_GL_MakeCurrent(_THIS) return 0; } - void BE_GL_SwapBuffers(_THIS) - { - SDL_Win->SwapBuffers(); - } #endif + void BE_GL_SwapWindow(_THIS, SDL_Window * window) { + _ToBeWin(window)->SwapBuffers(); + } + +int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { + _GetBeApp()->SetCurrentContext((BGLView*)context); + return 0; +} + + +SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) { + /* FIXME: Not sure what flags should be included here; may want to have + most of them */ + return (SDL_GLContext)(_ToBeWin(window)->CreateGLView( + BGL_RGB | BGL_DOUBLE)); +} + +void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { + /* Currently, automatically unlocks the view */ +// _ToBeWin(window)->RemoveGLView(); FIXME: Need to get the bwindow somehow +} + + +int BE_GL_SetSwapInterval(_THIS, int interval) { +} + +int BE_GL_GetSwapInterval(_THIS) { +} + + +void BE_GL_UnloadLibrary(_THIS) { +} #ifdef __cplusplus } diff --git a/src/video/bwindow/SDL_bopengl.h b/src/video/bwindow/SDL_bopengl.h index 062b635d0..86692f546 100644 --- a/src/video/bwindow/SDL_bopengl.h +++ b/src/video/bwindow/SDL_bopengl.h @@ -29,10 +29,19 @@ extern "C" { #include "../SDL_sysvideo.h" +extern int BE_GL_LoadLibrary(_THIS, const char *path); //FIXME +extern void *BE_GL_GetProcAddress(_THIS, const char *proc); //FIXME +extern void BE_GL_UnloadLibrary(_THIS); //TODO +//extern int BE_GL_SetupWindow(_THIS, SDL_Window * window); //TODO +extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window, + SDL_GLContext context); +extern int BE_GL_SetSwapInterval(_THIS, int interval); //TODO +extern int BE_GL_GetSwapInterval(_THIS); //TODO +extern void BE_GL_SwapWindow(_THIS, SDL_Window * window); +extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window); +extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context); + -extern int BE_GL_LoadLibrary(_THIS, const char *path); -extern void *BE_GL_GetProcAddress(_THIS, const char *proc); -extern int BE_GL_MakeCurrent(_THIS); #ifdef __cplusplus } diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index cdf10bb4b..721bfb490 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -32,22 +32,11 @@ extern "C" { #include "SDL_bvideo.h" #include "SDL_bopengl.h" #include "SDL_bmodes.h" +#include "SDL_bframebuffer.h" #include "SDL_bevents.h" /* FIXME: Undefined functions */ // #define BE_PumpEvents NULL - -#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ -// #define BE_GL_LoadLibrary NULL -// #define BE_GL_GetProcAddress NULL - #define BE_GL_UnloadLibrary NULL - #define BE_GL_CreateContext NULL -// #define BE_GL_MakeCurrent NULL - #define BE_GL_SetSwapInterval NULL - #define BE_GL_GetSwapInterval NULL - #define BE_GL_SwapWindow NULL - #define BE_GL_DeleteContext NULL -#endif #define BE_StartTextInput NULL #define BE_StopTextInput NULL #define BE_SetTextInputRect NULL @@ -115,8 +104,8 @@ BE_CreateDevice(int devindex) device->shape_driver.CreateShaper = NULL; device->shape_driver.SetWindowShape = NULL; device->shape_driver.ResizeWindowShape = NULL; - -#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ + +//#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ device->GL_LoadLibrary = BE_GL_LoadLibrary; device->GL_GetProcAddress = BE_GL_GetProcAddress; device->GL_UnloadLibrary = BE_GL_UnloadLibrary; @@ -126,7 +115,7 @@ BE_CreateDevice(int devindex) device->GL_GetSwapInterval = BE_GL_GetSwapInterval; device->GL_SwapWindow = BE_GL_SwapWindow; device->GL_DeleteContext = BE_GL_DeleteContext; -#endif +//#endif device->StartTextInput = BE_StartTextInput; device->StopTextInput = BE_StopTextInput; device->SetTextInputRect = BE_SetTextInputRect; From 2dda40712044b986030ef4a19b0f6a1f60739630 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 3 Aug 2011 05:09:36 +0000 Subject: [PATCH 19/27] Fixed minor rendering issues. --- src/video/bwindow/SDL_BWin.h | 4 ++-- src/video/bwindow/SDL_bframebuffer.cc | 2 +- src/video/bwindow/SDL_bwindow.cc | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index f52180e82..0e423a1a9 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -63,8 +63,8 @@ class SDL_BWin:public BDirectWindow { public: /* Constructor/Destructor */ - SDL_BWin(BRect bounds):BDirectWindow(bounds, "Untitled", - B_TITLED_WINDOW, 0) + SDL_BWin(BRect bounds, uint32 flags):BDirectWindow(bounds, "Untitled", + B_TITLED_WINDOW, flags) { _last_buttons = 0; diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 98634a49e..7b93f800f 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -53,7 +53,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Make sure we have exclusive access to frame buffer data */ bwin->LockBuffer(); - + /* format */ display_mode bmode; bscreen.GetMode(&bmode); diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index e1912261a..2297fc800 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -38,20 +38,32 @@ static inline SDL_BApp *_GetBeApp() { } int _InitWindow(_THIS, SDL_Window *window) { + uint32 flags = 0; BRect bounds( window->x, window->y, window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing window->y + window->h - 1 ); + + if(window->flags & SDL_WINDOW_FULLSCREEN) { + } + if(window->flags & SDL_WINDOW_OPENGL) { + } + if(!(window->flags & SDL_WINDOW_RESIZABLE)) { + flags |= B_NOT_RESIZABLE; + } + if(window->flags & SDL_WINDOW_BORDERLESS) { + } - SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds); + SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, flags); if(bwin == NULL) return ENOMEM; window->driverdata = bwin; int32 winID = _GetBeApp()->GetID(window); bwin->SetID(winID); + return 0; } @@ -59,6 +71,7 @@ int BE_CreateWindow(_THIS, SDL_Window *window) { if(_InitWindow(_this, window) == ENOMEM) return ENOMEM; + printf("Flags = 0x%x\n", window->flags); /* Start window loop */ _ToBeWin(window)->Show(); return 0; @@ -76,6 +89,11 @@ int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { window->w = (int)otherBWin->Frame().Width(); window->h = (int)otherBWin->Frame().Height(); + /* Set SDL flags */ + if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) { + window->flags |= SDL_WINDOW_RESIZABLE; + } + /* If we are out of memory, return the error code */ if(_InitWindow(_this, window) == ENOMEM) return ENOMEM; From 3c7c721663b7e5c72694fcf4ce169d60dfb18c83 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 3 Aug 2011 06:22:33 +0000 Subject: [PATCH 20/27] Replaced window backbuffer with BBitmap --- src/video/bwindow/SDL_BWin.h | 16 ++++++----- src/video/bwindow/SDL_bframebuffer.cc | 39 +++++++++++++++------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 0e423a1a9..a1afc86c9 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -81,7 +81,7 @@ class SDL_BWin:public BDirectWindow _buffer_created = _buffer_dirty = false; _trash_window_buffer = false; _buffer_locker = new BLocker(); - _window_buffer = NULL; + _bitmap = NULL; _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", B_NORMAL_PRIORITY, (void*) this); @@ -394,27 +394,29 @@ class SDL_BWin:public BDirectWindow uint32 GetRowBytes() { return _row_bytes; } int32 GetFbX() { return _bounds.left; } int32 GetFbY() { return _bounds.top; } - int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } - int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } +// int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } +// int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } bool ConnectionEnabled() { return !_connection_disabled; } bool Connected() { return _connected; } clipping_rect *GetClips() { return _clips; } int32 GetNumClips() { return _num_clips; } uint8* GetBufferPx() { return _bits; } int32 GetBytesPerPx() { return _bytes_per_px; } - uint8* GetWindowFramebuffer() { return _window_buffer; } +// uint8* GetWindowFramebuffer() { return _window_buffer; } bool CanTrashWindowBuffer() { return _trash_window_buffer; } bool BufferExists() { return _buffer_created; } bool BufferIsDirty() { return _buffer_dirty; } + BBitmap *GetBitmap() { return _bitmap; } /* Setter methods */ void SetID(int32 id) { _id = id; } void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; } - void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } +// void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } void LockBuffer() { _buffer_locker->Lock(); } void UnlockBuffer() { _buffer_locker->Unlock(); } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; } + void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; } private: @@ -588,9 +590,11 @@ private: clipping_rect *_clips; int32 _num_clips; int32 _bytes_per_px; - uint8 *_window_buffer; /* A copy of the window buffer */ +// uint8 *_window_buffer; /* A copy of the window buffer */ bool _trash_window_buffer; thread_id _draw_thread_id; + + BBitmap *_bitmap; }; #endif diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 7b93f800f..0ebeb7cbb 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -60,17 +60,21 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); *format = BPPToSDLPxFormat(bpp); - /* pitch = width of screen, in bytes */ - *pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx(); - - /* Create a copy of the pixel buffer if it doesn't recycle */ - *pixels = bwin->GetWindowFramebuffer(); - if( (*pixels) != NULL ) { - SDL_free(*pixels); + /* Create the new bitmap object */ + BBitmap *bitmap = bwin->GetBitmap(); + if(bitmap) { + delete bitmap; } - *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * - bwin->GetBytesPerPx(), sizeof(uint8)); - bwin->SetWindowFramebuffer((uint8*)(*pixels)); + bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, + false, /* Views not accepted */ + true); /* Contiguous memory required */ + bwin->SetBitmap(bitmap); + + /* Set the pixel pointer */ + *pixels = bitmap->Bits(); + + /* pitch = width of window, in bytes */ + *pitch = bitmap->BytesPerRow(); bwin->SetBufferExists(true); bwin->SetTrashBuffer(false); @@ -106,13 +110,13 @@ int32 BE_DrawThread(void *data) { while(bwin->ConnectionEnabled()) { if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { bwin->LockBuffer(); - int32 windowPitch = window->surface->pitch; + BBitmap *bitmap = bwin->GetBitmap(); + int32 windowPitch = bitmap->BytesPerRow(); int32 bufferPitch = bwin->GetRowBytes(); uint8 *windowpx; uint8 *bufferpx; int32 BPP = bwin->GetBytesPerPx(); - uint8 *windowBaseAddress = (uint8*)window->surface->pixels; int32 windowSub = bwin->GetFbX() * BPP + bwin->GetFbY() * windowPitch; clipping_rect *clips = bwin->GetClips(); @@ -128,8 +132,9 @@ int32 BE_DrawThread(void *data) { int32 height = clips[i].bottom - clips[i].top + 1; bufferpx = bwin->GetBufferPx() + clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + windowpx = (uint8*)bitmap->Bits(); + + clips[i].top * windowPitch + clips[i].left * BPP - + windowSub; /* Copy each row of pixels from the window buffer into the frame buffer */ @@ -160,9 +165,9 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { bwin->LockBuffer(); /* Free and clear the window buffer */ - uint8* winBuffer = bwin->GetWindowFramebuffer(); - SDL_free(winBuffer); - bwin->SetWindowFramebuffer(NULL); + BBitmap *bitmap = bwin->GetBitmap(); + delete bitmap; + bwin->SetBitmap(NULL); bwin->SetBufferExists(false); bwin->UnlockBuffer(); } From 06dfd29b2309cf275032fa1ed294c599c57a173f Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Mon, 8 Aug 2011 17:00:38 +0000 Subject: [PATCH 21/27] Some video fixes --- src/video/bwindow/SDL_BWin.h | 11 +++- src/video/bwindow/SDL_bframebuffer.cc | 13 ++++- src/video/bwindow/SDL_bopengl.cc | 73 +++++++++++++++++---------- 3 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index a1afc86c9..3715033e5 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -156,7 +156,8 @@ class SDL_BWin:public BDirectWindow /* Determine if the pixel buffer is usable after this update */ _trash_window_buffer = _trash_window_buffer || ((info->buffer_state & B_BUFFER_RESIZED) - || (info->buffer_state & B_BUFFER_RESET)); + || (info->buffer_state & B_BUFFER_RESET) + || (info->driver_state == B_MODE_CHANGED)); LockBuffer(); switch(info->buffer_state & B_DIRECT_MODE_MASK) { @@ -193,7 +194,12 @@ class SDL_BWin:public BDirectWindow } #endif + + /* Call the base object directconnected */ + BDirectWindow::DirectConnected(info); + UnlockBuffer(); + } @@ -407,6 +413,9 @@ class SDL_BWin:public BDirectWindow bool BufferExists() { return _buffer_created; } bool BufferIsDirty() { return _buffer_dirty; } BBitmap *GetBitmap() { return _bitmap; } +#if SDL_VIDEO_OPENGL + BGLView *GetGLView() { return _SDL_GLView; } +#endif /* Setter methods */ void SetID(int32 id) { _id = id; } diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 0ebeb7cbb..51a2772c7 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -62,12 +62,20 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Create the new bitmap object */ BBitmap *bitmap = bwin->GetBitmap(); + if(bitmap) { delete bitmap; } bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, false, /* Views not accepted */ true); /* Contiguous memory required */ + + if(bitmap->InitCheck() != B_OK) { + SDL_SetError("Could not initialize back buffer!\n"); + return -1; + } + + bwin->SetBitmap(bitmap); /* Set the pixel pointer */ @@ -132,7 +140,7 @@ int32 BE_DrawThread(void *data) { int32 height = clips[i].bottom - clips[i].top + 1; bufferpx = bwin->GetBufferPx() + clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = (uint8*)bitmap->Bits(); + + windowpx = (uint8*)bitmap->Bits() + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; @@ -143,11 +151,14 @@ int32 BE_DrawThread(void *data) { if(bwin->CanTrashWindowBuffer()) { goto escape; /* Break out before the buffer is killed */ } +// printf("memcpy(0x%x, 0x%x, %i) ", bufferpx, windowpx, width * BPP); memcpy(bufferpx, windowpx, width * BPP); bufferpx += bufferPitch; windowpx += windowPitch; } +// printf("\t-\t"); } +// printf("\n"); bwin->SetBufferDirty(false); escape: bwin->UnlockBuffer(); diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index 6fbc2682d..906e9542d 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -119,6 +119,52 @@ void *BE_GL_GetProcAddress(_THIS, const char *proc) } + + +void BE_GL_SwapWindow(_THIS, SDL_Window * window) { + _ToBeWin(window)->SwapBuffers(); +} + +int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { + _GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView()); + return 0; +} + + +SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) { + /* FIXME: Not sure what flags should be included here; may want to have + most of them */ + SDL_BWin *bwin = _ToBeWin(window); + bwin->CreateGLView(BGL_RGB | BGL_DOUBLE); + return (SDL_GLContext)(bwin); +} + +void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { + /* Currently, automatically unlocks the view */ + ((SDL_BWin*)context)->RemoveGLView(); +} + + +int BE_GL_SetSwapInterval(_THIS, int interval) { + printf(__FILE__": %d- swap interval set\n", __LINE__); + return 0; +} + +int BE_GL_GetSwapInterval(_THIS) { + printf(__FILE__": %d- swap interval requested\n", __LINE__); + return 0; +} + + +void BE_GL_UnloadLibrary(_THIS) { + printf(__FILE__": %d- Library unloaded\n", __LINE__); +} + + + + + + #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */ int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) @@ -182,38 +228,13 @@ void *BE_GL_GetProcAddress(_THIS, const char *proc) } #endif - void BE_GL_SwapWindow(_THIS, SDL_Window * window) { - _ToBeWin(window)->SwapBuffers(); - } - -int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { - _GetBeApp()->SetCurrentContext((BGLView*)context); - return 0; -} -SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) { - /* FIXME: Not sure what flags should be included here; may want to have - most of them */ - return (SDL_GLContext)(_ToBeWin(window)->CreateGLView( - BGL_RGB | BGL_DOUBLE)); -} - -void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { - /* Currently, automatically unlocks the view */ -// _ToBeWin(window)->RemoveGLView(); FIXME: Need to get the bwindow somehow -} -int BE_GL_SetSwapInterval(_THIS, int interval) { -} - -int BE_GL_GetSwapInterval(_THIS) { -} -void BE_GL_UnloadLibrary(_THIS) { -} + #ifdef __cplusplus } From eb58f97bd3a2f149887d1a58c020f3d3447b127a Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Tue, 9 Aug 2011 16:34:25 +0000 Subject: [PATCH 22/27] Fixed OpenGL library loading functions --- configure.in | 1 - src/video/bwindow/SDL_bopengl.cc | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 9daef39b5..1b2a07f26 100644 --- a/configure.in +++ b/configure.in @@ -1238,7 +1238,6 @@ CheckBWINDOW() { if test x$enable_video = xyes; then AC_DEFINE(SDL_VIDEO_DRIVER_BWINDOW, 1, [ ]) - # SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc" .cc sources have been removed SOURCES="$SOURCES $srcdir/src/video/bwindow/*.cc" have_video=yes fi diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index 906e9542d..9de4eedf9 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -42,11 +42,28 @@ static inline SDL_BApp *_GetBeApp() { /* Passing a NULL path means load pointers from the application */ int BE_GL_LoadLibrary(_THIS, const char *path) { + image_info info; + int32 cookie = 0; + while (get_next_image_info(0, &cookie, &info) == B_OK) { + void *location = NULL; + if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY, + &location) == B_OK) { + + printf("HERE2\n"); + _this->gl_config.dll_handle = (void *) info.id; + _this->gl_config.driver_loaded = 1; + SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", + SDL_arraysize(_this->gl_config.driver_path)); + } + } +#if 0 +printf("\n\nLibrary loading: %s\n\n", path); if (path == NULL) { if (_this->gl_config.dll_handle == NULL) { image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { + printf(__FILE__": %d - Inside while\n",__LINE__); void *location = NULL; if (get_image_symbol ((image_id) cookie, "glBegin", @@ -69,7 +86,6 @@ int BE_GL_LoadLibrary(_THIS, const char *path) if (_this->gl_config.dll_handle == NULL) { return BE_GL_LoadLibrary(_this, NULL); } - /* Unload old first */ /*if (_this->gl_config.dll_handle != NULL) { */ /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */ @@ -91,11 +107,13 @@ int BE_GL_LoadLibrary(_THIS, const char *path) if (_this->gl_config.dll_handle != NULL) { return 0; } else { +printf(__FILE__": %d- gl_config.driver_loaded = 0\n", __LINE__); _this->gl_config.dll_handle = NULL; _this->gl_config.driver_loaded = 0; *_this->gl_config.driver_path = '\0'; return -1; } +#endif } void *BE_GL_GetProcAddress(_THIS, const char *proc) From 23e3df144f1efd902eb1d07abfebd326dc69be9d Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Fri, 12 Aug 2011 16:58:54 +0000 Subject: [PATCH 23/27] Reduced SEGFAULT occurence on resize? --- src/main/beos/SDL_BApp.h | 4 +- src/video/bwindow/SDL_BWin.h | 5 ++- src/video/bwindow/SDL_bframebuffer.cc | 60 ++++++++++++++++++++++++++- src/video/bwindow/SDL_bframebuffer.h | 2 + src/video/bwindow/SDL_bopengl.cc | 3 +- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 053db8b46..a2e504113 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -330,7 +330,7 @@ private: SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos); /* FIXME: Attempt at fixing rendering problems */ - BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); +// BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); Handled by DirectConnected } void _HandleWindowResized(BMessage *msg) { @@ -349,7 +349,7 @@ private: SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); /* FIXME: Attempt at fixing rendering problems */ - BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); +// BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); Handled by DirectConnected } bool _GetWinID(BMessage *msg, int32 *winID) { diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 3715033e5..192bfc59e 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -82,10 +82,11 @@ class SDL_BWin:public BDirectWindow _trash_window_buffer = false; _buffer_locker = new BLocker(); _bitmap = NULL; - +#ifdef DRAWTHREAD _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", B_NORMAL_PRIORITY, (void*) this); resume_thread(_draw_thread_id); +#endif } virtual ~ SDL_BWin() @@ -109,7 +110,9 @@ class SDL_BWin:public BDirectWindow /* Clean up framebuffer stuff */ _buffer_locker->Lock(); +#ifdef DRAWTHREAD wait_for_thread(_draw_thread_id, &result); +#endif free(_clips); delete _buffer_locker; } diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 51a2772c7..afe8df68b 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -32,6 +32,8 @@ extern "C" { #endif +int32 BE_UpdateOnce(SDL_Window *window); + static inline SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } @@ -98,10 +100,15 @@ int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, return 0; SDL_BWin *bwin = _ToBeWin(window); - + +#ifdef DRAWTHREAD bwin->LockBuffer(); bwin->SetBufferDirty(true); bwin->UnlockBuffer(); +#else + bwin->SetBufferDirty(true); + BE_UpdateOnce(window); +#endif return 0; } @@ -148,9 +155,11 @@ int32 BE_DrawThread(void *data) { buffer */ for(y = 0; y < height; ++y) { + if(bwin->CanTrashWindowBuffer()) { goto escape; /* Break out before the buffer is killed */ } + // printf("memcpy(0x%x, 0x%x, %i) ", bufferpx, windowpx, width * BPP); memcpy(bufferpx, windowpx, width * BPP); bufferpx += bufferPitch; @@ -183,6 +192,55 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { bwin->UnlockBuffer(); } + +int32 BE_UpdateOnce(SDL_Window *window) { + SDL_BWin *bwin = _ToBeWin(window); + BScreen bscreen; + if(!bscreen.IsValid()) { + return -1; + } + + if(bwin->ConnectionEnabled() && bwin->Connected()) { + bwin->LockBuffer(); + int32 windowPitch = window->surface->pitch; + int32 bufferPitch = bwin->GetRowBytes(); + uint8 *windowpx; + uint8 *bufferpx; + + int32 BPP = bwin->GetBytesPerPx(); + uint8 *windowBaseAddress = (uint8*)window->surface->pixels; + int32 windowSub = bwin->GetFbX() * BPP + + bwin->GetFbY() * windowPitch; + clipping_rect *clips = bwin->GetClips(); + int32 numClips = bwin->GetNumClips(); + int i, y; + + /* Blit each clipping rectangle */ + bscreen.WaitForRetrace(); + for(i = 0; i < numClips; ++i) { + clipping_rect rc = clips[i]; + /* Get addresses of the start of each clipping rectangle */ + int32 width = clips[i].right - clips[i].left + 1; + int32 height = clips[i].bottom - clips[i].top + 1; + bufferpx = bwin->GetBufferPx() + + clips[i].top * bufferPitch + clips[i].left * BPP; + windowpx = windowBaseAddress + + clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + + /* Copy each row of pixels from the window buffer into the frame + buffer */ + for(y = 0; y < height; ++y) + { + memcpy(bufferpx, windowpx, width * BPP); + bufferpx += bufferPitch; + windowpx += windowPitch; + } + } + bwin->UnlockBuffer(); + } + return 0; +} + #ifdef __cplusplus } #endif diff --git a/src/video/bwindow/SDL_bframebuffer.h b/src/video/bwindow/SDL_bframebuffer.h index d34b530c0..05efa5b9a 100644 --- a/src/video/bwindow/SDL_bframebuffer.h +++ b/src/video/bwindow/SDL_bframebuffer.h @@ -26,6 +26,8 @@ extern "C" { #endif +#define DRAWTHREAD + #include "../SDL_sysvideo.h" extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index 9de4eedf9..ed2d1d083 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -48,8 +48,7 @@ int BE_GL_LoadLibrary(_THIS, const char *path) void *location = NULL; if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY, &location) == B_OK) { - - printf("HERE2\n"); + _this->gl_config.dll_handle = (void *) info.id; _this->gl_config.driver_loaded = 1; SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", From d7bd0b0425ba0ff662c3660780df1f4ba59340c0 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Wed, 17 Aug 2011 13:31:18 +0000 Subject: [PATCH 24/27] Fixed some problems with switching to/from fullscreen --- src/SDL_compat.c | 2 +- src/video/bwindow/SDL_BWin.h | 5 ++- src/video/bwindow/SDL_bmodes.cc | 66 ++++++++++++++++++++++++-------- src/video/bwindow/SDL_bwindow.cc | 2 +- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 013dd22b1..dd3fc7371 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -848,7 +848,7 @@ SDL_WM_ToggleFullScreen(SDL_Surface * surface) /* Copy the old bits out */ length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel; pixels = SDL_malloc(SDL_PublicSurface->h * length); - if (pixels) { + if (pixels && SDL_PublicSurface->pixels) { src = (Uint8*)SDL_PublicSurface->pixels; dst = (Uint8*)pixels; for (row = 0; row < SDL_PublicSurface->h; ++row) { diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 192bfc59e..2bb982eb3 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -98,8 +98,10 @@ class SDL_BWin:public BDirectWindow #if SDL_VIDEO_OPENGL if (_SDL_GLView) { _SDL_GLView->UnlockGL(); + RemoveChild(_SDL_GLView); /* Why was this outside the if + statement before? */ } - RemoveChild(_SDL_GLView); + #endif Unlock(); #if SDL_VIDEO_OPENGL @@ -129,6 +131,7 @@ class SDL_BWin:public BDirectWindow gl_flags); } AddChild(_SDL_GLView); + _SDL_GLView->EnableDirectMode(true); _SDL_GLView->LockGL(); /* "New" GLViews are created */ Unlock(); return (_SDL_GLView); diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index a75801433..245e84d4f 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -32,12 +32,12 @@ extern "C" { #endif +#if 1 /* This wrapper is here so that the driverdata can be freed */ typedef struct SDL_DisplayModeData { display_mode *bmode; }; - - +#endif static inline SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); @@ -47,6 +47,13 @@ static inline SDL_BApp *_GetBeApp() { return ((SDL_BApp*)be_app); } +static inline display_mode * _ExtractBMode(SDL_DisplayMode *mode) { +#if 0 + return (display_mode*)(mode->driverdata); +#else + return ((SDL_DisplayModeData*)mode->driverdata)->bmode; +#endif +} /* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */ static float get_refresh_rate(display_mode &mode) { @@ -114,9 +121,14 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; mode->refresh_rate = (int)get_refresh_rate(*bmode); +#if 1 SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData)); data->bmode = bmode; + mode->driverdata = data; +#else + mode->driverdata = bmode; +#endif /* Set the format */ int32 bpp = ColorSpaceToBitsPerPixel(bmode->space); @@ -127,14 +139,15 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, void BE_AddDisplay(BScreen *screen) { SDL_VideoDisplay display; SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, sizeof(SDL_DisplayMode)); - display_mode bmode; - screen->GetMode(&bmode); + display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode)); + screen->GetMode(bmode); - BE_BDisplayModeToSdlDisplayMode(&bmode, mode); + BE_BDisplayModeToSdlDisplayMode(bmode, mode); SDL_zero(display); display.desktop_mode = *mode; display.current_mode = *mode; + SDL_AddVideoDisplay(&display); } @@ -142,20 +155,19 @@ int BE_InitModes(_THIS) { BScreen screen; /* Save the current display mode */ - display_mode *prevMode; - screen.GetMode(prevMode); - _GetBeApp()->SetPrevMode(prevMode); +// display_mode *prevMode; +// screen.GetMode(prevMode); +// _GetBeApp()->SetPrevMode(prevMode); /* Only one possible video display right now */ BE_AddDisplay(&screen); } int BE_QuitModes(_THIS) { -/* printf(__FILE__": %d; Begin quit\n", __LINE__);*/ /* Restore the previous video mode */ BScreen screen; - display_mode *savedMode = _GetBeApp()->GetPrevMode(); - screen.SetMode(savedMode); +// display_mode *savedMode = _GetBeApp()->GetPrevMode(); +// screen.SetMode(savedMode); return 0; } @@ -197,13 +209,37 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ /* Get the current screen */ BScreen bscreen; - + if(!bscreen.IsValid()) { + printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); + } + /* Set the mode using the driver data */ - display_mode *bmode = ((SDL_DisplayModeData*)mode->driverdata)->bmode; - if(bscreen.SetMode(bmode) == B_OK) { + display_mode *bmode = _ExtractBMode(mode); + + status_t s; + if((s = bscreen.SetMode(bmode)) == B_OK) { return 0; /* No error */ } - +printf(__FILE__": %d - ERROR: FAILED TO CHANGE VIDEO MODE; s = %i, status = B_BAD_VALUE? %i\n", __LINE__, s, s == B_BAD_VALUE); + display_mode *bmode_list; + uint32 count; + bscreen.GetModeList(&bmode_list, &count); + s = bscreen.ProposeMode(bmode, &bmode_list[count - 1], &bmode_list[0]); + switch(s) { + case B_OK: + printf(__FILE__": %d - B_OK\n", __LINE__); + break; + case B_BAD_VALUE: + printf(__FILE__": %d - B_BAD_VALUE\n", __LINE__); + break; + case B_ERROR: + printf(__FILE__": %d - B_ERROR\n", __LINE__); + break; + default: + printf(__FILE__": %d - (unknown error code)\n", __LINE__); + break; + } + free(bmode_list); return -1; } diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index 2297fc800..de2b3ca69 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -51,7 +51,7 @@ int _InitWindow(_THIS, SDL_Window *window) { if(window->flags & SDL_WINDOW_OPENGL) { } if(!(window->flags & SDL_WINDOW_RESIZABLE)) { - flags |= B_NOT_RESIZABLE; + flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; } if(window->flags & SDL_WINDOW_BORDERLESS) { } From 491df9d7302f3ac5b599a6756407f392383623d9 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Sat, 20 Aug 2011 15:16:13 +0000 Subject: [PATCH 25/27] Temporary mode-setting hack works --- src/video/bwindow/SDL_BWin.h | 18 +++ src/video/bwindow/SDL_bframebuffer.cc | 11 +- src/video/bwindow/SDL_bmodes.cc | 216 +++++++++++++++++++++++--- src/video/bwindow/SDL_bopengl.cc | 20 ++- src/video/bwindow/SDL_bopengl.h | 3 +- src/video/bwindow/SDL_bwindow.cc | 1 - 6 files changed, 238 insertions(+), 31 deletions(-) diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 2bb982eb3..b9d142a49 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -185,6 +185,9 @@ class SDL_BWin:public BDirectWindow _bits = (uint8*) info->bits; _row_bytes = info->bytes_per_row; _bounds = info->window_bounds; +printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left, + _bounds.top, _bounds.right, _bounds.bottom, Frame().left, Frame().top, + Frame().right, Frame().bottom); _bytes_per_px = info->bits_per_pixel / 8; _buffer_dirty = true; } @@ -572,12 +575,27 @@ private: void _SetFullScreen(BMessage *msg) { bool fullscreen; + + BRect rc1 = Bounds(), + rc2 = Frame(); +printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom, +rc2.left, rc2.top, rc2.right, rc2.bottom); if( msg->FindBool("fullscreen", &fullscreen) != B_OK ) { return; } + +if(fullscreen) { + printf("Setting fullscreen...\n"); +} else { + printf("Unsetting fullscreen...\n"); +} +#if 1 SetFullScreen(fullscreen); +#endif +printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom, +rc2.left, rc2.top, rc2.right, rc2.bottom); } /* Members */ diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index afe8df68b..4d0a2bb97 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -125,7 +125,10 @@ int32 BE_DrawThread(void *data) { while(bwin->ConnectionEnabled()) { if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { bwin->LockBuffer(); - BBitmap *bitmap = bwin->GetBitmap(); + BBitmap *bitmap = NULL; +// while(!bitmap) { + bitmap = bwin->GetBitmap(); +// } int32 windowPitch = bitmap->BytesPerRow(); int32 bufferPitch = bwin->GetRowBytes(); uint8 *windowpx; @@ -193,6 +196,12 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { } +/* + * TODO: + * This was written to test if certain errors were caused by threading issues. + * The specific issues have since become rare enough that they may have been + * solved, but I doubt it- they were pretty sporadic before now. + */ int32 BE_UpdateOnce(SDL_Window *window) { SDL_BWin *bwin = _ToBeWin(window); BScreen bscreen; diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 245e84d4f..0e3e5b78b 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -26,13 +26,20 @@ #include "SDL_bmodes.h" #include "SDL_BWin.h" +#if SDL_VIDEO_OPENGL +#include "SDL_bopengl.h" +#endif + #include "../../main/beos/SDL_BApp.h" #ifdef __cplusplus extern "C" { #endif -#if 1 + +#define WRAP_BMODE 1 + +#if WRAP_BMODE /* This wrapper is here so that the driverdata can be freed */ typedef struct SDL_DisplayModeData { display_mode *bmode; @@ -121,7 +128,7 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; mode->refresh_rate = (int)get_refresh_rate(*bmode); -#if 1 +#if WRAP_BMODE SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData)); data->bmode = bmode; @@ -206,8 +213,159 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { free(bmodes); } + + + + + + + + + + + + + +static int get_combine_mode(display_mode &mode) { + if ((mode.flags & B_SCROLL) == 0) + return 0; + + if (mode.virtual_width == mode.timing.h_display * 2) + return 1; + + if (mode.virtual_height == mode.timing.v_display * 2) + return 2; + + return 0; +} +#if 0 +bool _GetDisplayMode(const screen_mode& mode, display_mode& displayMode) +{ + uint16 virtualWidth, virtualHeight; + int32 bestIndex = -1; + float bestDiff = 999; + + virtualWidth = mode.combine == kCombineHorizontally + ? mode.width * 2 : mode.width; + virtualHeight = mode.combine == kCombineVertically + ? mode.height * 2 : mode.height; + + // try to find mode in list provided by driver + for (uint32 i = 0; i < fModeCount; i++) { + if (fModeList[i].virtual_width != virtualWidth + || fModeList[i].virtual_height != virtualHeight + || (color_space)fModeList[i].space != mode.space) + continue; + + // Accept the mode if the computed refresh rate of the mode is within + // 0.6 percent of the refresh rate specified by the caller. Note that + // refresh rates computed from mode parameters is not exact; especially + // some of the older modes such as 640x480, 800x600, and 1024x768. + // The tolerance of 0.6% was obtained by examining the various possible + // modes. + + float refreshDiff = fabs(get_refresh_rate(fModeList[i]) - mode.refresh); + if (refreshDiff < 0.006 * mode.refresh) { + // Accept this mode. + displayMode = fModeList[i]; + displayMode.h_display_start = 0; + displayMode.v_display_start = 0; + + // Since the computed refresh rate of the selected mode might differ + // from selected refresh rate by a few tenths (e.g. 60.2 instead of + // 60.0), tweak the pixel clock so the the refresh rate of the mode + // matches the selected refresh rate. + + displayMode.timing.pixel_clock = uint32(((displayMode.timing.h_total + * displayMode.timing.v_total * mode.refresh) / 1000.0) + 0.5); + return true; + } + + // Mode not acceptable. + + if (refreshDiff < bestDiff) { + bestDiff = refreshDiff; + bestIndex = i; + } + } + + // we didn't find the exact mode, but something very similar? + if (bestIndex == -1) + return false; + + displayMode = fModeList[bestIndex]; + displayMode.h_display_start = 0; + displayMode.v_display_start = 0; + + // For the mode selected by the width, height, and refresh rate, compute + // the video timing parameters for the mode by using the VESA Generalized + // Timing Formula (GTF). + + ComputeGTFVideoTiming(displayMode.timing.h_display, + displayMode.timing.v_display, mode.refresh, displayMode.timing); + + return true; +} +#endif + +void _SpoutModeData(display_mode *bmode) { + printf("BMode:\n"); + printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); + printf("\th,v = (%i,%i)\n", bmode->h_display_start, + bmode->v_display_start); + printf("\tcombine mode = %i\n", get_combine_mode(*bmode)); + if(bmode->flags) { + printf("\tFlags:\n"); + if(bmode->flags & B_SCROLL) { + printf("\t\tB_SCROLL\n"); + } + if(bmode->flags & B_8_BIT_DAC) { + printf("\t\tB_8_BIT_DAC\n"); + } + if(bmode->flags & B_HARDWARE_CURSOR) { + printf("\t\tB_HARDWARE_CURSOR\n"); + } + if(bmode->flags & B_PARALLEL_ACCESS) { + printf("\t\tB_PARALLEL_ACCESS\n"); + } + if(bmode->flags & B_DPMS) { + printf("\t\tB_DPMS\n"); + } + if(bmode->flags & B_IO_FB_NA) { + printf("\t\tB_IO_FB_NA\n"); + } + } + printf("\tTiming:\n"); + printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); + printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.h_display, bmode->timing.h_sync_start, + bmode->timing.h_sync_end, bmode->timing.h_total); + printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.v_display, bmode->timing.v_sync_start, + bmode->timing.v_sync_end, bmode->timing.v_total); + if(bmode->timing.flags) { + printf("\t\tFlags:\n"); + if(bmode->timing.flags & B_BLANK_PEDESTAL) { + printf("\t\t\tB_BLANK_PEDESTAL\n"); + } + if(bmode->timing.flags & B_TIMING_INTERLACED) { + printf("\t\t\tB_TIMING_INTERLACED\n"); + } + if(bmode->timing.flags & B_POSITIVE_HSYNC) { + printf("\t\t\tB_POSITIVE_HSYNC\n"); + } + if(bmode->timing.flags & B_POSITIVE_VSYNC) { + printf("\t\t\tB_POSITIVE_VSYNC\n"); + } + if(bmode->timing.flags & B_SYNC_ON_GREEN) { + printf("\t\t\tB_SYNC_ON_GREEN\n"); + } + } +} + int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ /* Get the current screen */ +printf(__FILE__": %d\n", __LINE__); BScreen bscreen; if(!bscreen.IsValid()) { printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); @@ -216,31 +374,39 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ /* Set the mode using the driver data */ display_mode *bmode = _ExtractBMode(mode); - status_t s; - if((s = bscreen.SetMode(bmode)) == B_OK) { - return 0; /* No error */ + +_SpoutModeData(bmode); +printf("\n"); +uint32 c = 0, i, x = 0; +#define RES 0 +display_mode *bmode_list; +bscreen.GetModeList(&bmode_list, &c); +for(i = 0; i < c; ++i) { + if( bmode_list[i].space == bmode->space && + bmode_list[i].virtual_width == bmode->virtual_width && + bmode_list[i].virtual_height == bmode->virtual_height ) { + if(x == RES) + bmode = &bmode_list[i]; + + ++x; + _SpoutModeData(&bmode_list[i]); +// break; } -printf(__FILE__": %d - ERROR: FAILED TO CHANGE VIDEO MODE; s = %i, status = B_BAD_VALUE? %i\n", __LINE__, s, s == B_BAD_VALUE); - display_mode *bmode_list; - uint32 count; - bscreen.GetModeList(&bmode_list, &count); - s = bscreen.ProposeMode(bmode, &bmode_list[count - 1], &bmode_list[0]); - switch(s) { - case B_OK: - printf(__FILE__": %d - B_OK\n", __LINE__); - break; - case B_BAD_VALUE: - printf(__FILE__": %d - B_BAD_VALUE\n", __LINE__); - break; - case B_ERROR: - printf(__FILE__": %d - B_ERROR\n", __LINE__); - break; - default: - printf(__FILE__": %d - (unknown error code)\n", __LINE__); - break; +} + + if(bscreen.SetMode(bmode) != B_OK) { + SDL_SetError("Bad video mode\n"); + return -1; } - free(bmode_list); - return -1; +free(bmode_list); + +#if SDL_VIDEO_OPENGL + /* The OpenGL context may need to be rebooted */ +// BE_GL_RebootContexts(_this); +#endif + +printf(__FILE__": %d\n", __LINE__); + return 0; } #ifdef __cplusplus diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index ed2d1d083..f202cce17 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -31,6 +31,9 @@ extern "C" { #endif + +#define BGL_FLAGS BGL_RGB | BGL_DOUBLE + static inline SDL_BWin *_ToBeWin(SDL_Window *window) { return ((SDL_BWin*)(window->driverdata)); } @@ -152,12 +155,13 @@ SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) { /* FIXME: Not sure what flags should be included here; may want to have most of them */ SDL_BWin *bwin = _ToBeWin(window); - bwin->CreateGLView(BGL_RGB | BGL_DOUBLE); + bwin->CreateGLView(BGL_FLAGS); return (SDL_GLContext)(bwin); } void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { /* Currently, automatically unlocks the view */ +printf(__FILE__": %d\n", __LINE__); ((SDL_BWin*)context)->RemoveGLView(); } @@ -179,7 +183,19 @@ void BE_GL_UnloadLibrary(_THIS) { - +void BE_GL_RebootContexts(_THIS) { + SDL_Window *window = _this->windows; + while(window) { + SDL_BWin *bwin = _ToBeWin(window); + if(bwin->GetGLView()) { + bwin->LockLooper(); + bwin->RemoveGLView(); + bwin->CreateGLView(BGL_FLAGS); + bwin->UnlockLooper(); + } + window = window->next; + } +} #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */ diff --git a/src/video/bwindow/SDL_bopengl.h b/src/video/bwindow/SDL_bopengl.h index 86692f546..1f718e92c 100644 --- a/src/video/bwindow/SDL_bopengl.h +++ b/src/video/bwindow/SDL_bopengl.h @@ -32,7 +32,6 @@ extern "C" { extern int BE_GL_LoadLibrary(_THIS, const char *path); //FIXME extern void *BE_GL_GetProcAddress(_THIS, const char *proc); //FIXME extern void BE_GL_UnloadLibrary(_THIS); //TODO -//extern int BE_GL_SetupWindow(_THIS, SDL_Window * window); //TODO extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); extern int BE_GL_SetSwapInterval(_THIS, int interval); //TODO @@ -41,7 +40,7 @@ extern void BE_GL_SwapWindow(_THIS, SDL_Window * window); extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window); extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context); - +extern void BE_GL_RebootContexts(_THIS); #ifdef __cplusplus } diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index de2b3ca69..b17d96a4e 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -71,7 +71,6 @@ int BE_CreateWindow(_THIS, SDL_Window *window) { if(_InitWindow(_this, window) == ENOMEM) return ENOMEM; - printf("Flags = 0x%x\n", window->flags); /* Start window loop */ _ToBeWin(window)->Show(); return 0; From 4799ac2b6ee064c7e8fef11efbcc094ae941e7c7 Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Mon, 22 Aug 2011 11:02:05 +0000 Subject: [PATCH 26/27] Partially cleaned out code --- src/main/beos/SDL_BApp.h | 15 +- src/video/bwindow/SDL_BWin.h | 47 ++--- src/video/bwindow/SDL_bclipboard.cc | 18 +- src/video/bwindow/SDL_bevents.cc | 1 + src/video/bwindow/SDL_bframebuffer.cc | 8 +- src/video/bwindow/SDL_bmodes.cc | 289 +++++++++----------------- src/video/bwindow/SDL_bopengl.cc | 70 +------ src/video/bwindow/SDL_bvideo.cc | 45 +--- src/video/bwindow/SDL_bwindow.cc | 7 + 9 files changed, 148 insertions(+), 352 deletions(-) diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index a2e504113..3dd3718cc 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -177,11 +177,6 @@ public: } } - /* Modes methods */ - void SetPrevMode(display_mode *prevMode) { _saved_mode = prevMode; } - - display_mode* GetPrevMode() { return _saved_mode; } - /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is there another way to do this? */ void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */ @@ -225,7 +220,7 @@ private: win = GetSDLWindow(winID); SDL_SendMouseMotion(win, 0, x, y); - /* FIXME: Attempt at fixing rendering problems */ + /* Tell the application that the mouse passed over, redraw needed */ BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); } @@ -328,9 +323,6 @@ private: } win = GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos); - - /* FIXME: Attempt at fixing rendering problems */ -// BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); Handled by DirectConnected } void _HandleWindowResized(BMessage *msg) { @@ -347,9 +339,6 @@ private: } win = GetSDLWindow(winID); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); - - /* FIXME: Attempt at fixing rendering problems */ -// BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); Handled by DirectConnected } bool _GetWinID(BMessage *msg, int32 *winID) { @@ -379,7 +368,7 @@ private: /* Members */ - vector _window_map; /* Keeps track of SDL_Windows by index-id */ + vector _window_map; /* Keeps track of SDL_Windows by index-id*/ display_mode *_saved_mode; BGLView *_current_context; diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index b9d142a49..ee770d5cd 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -53,7 +53,7 @@ enum WinCommands { BWIN_HIDE_WINDOW, BWIN_MAXIMIZE_WINDOW, BWIN_MINIMIZE_WINDOW, - BWIN_RESTORE_WINDOW, /* TODO: IMPLEMENT THIS! */ + BWIN_RESTORE_WINDOW, BWIN_SET_TITLE, BWIN_FULLSCREEN }; @@ -185,9 +185,6 @@ class SDL_BWin:public BDirectWindow _bits = (uint8*) info->bits; _row_bytes = info->bytes_per_row; _bounds = info->window_bounds; -printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left, - _bounds.top, _bounds.right, _bounds.bottom, Frame().left, Frame().top, - Frame().right, Frame().bottom); _bytes_per_px = info->bits_per_pixel / 8; _buffer_dirty = true; } @@ -230,7 +227,8 @@ printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left, virtual void FrameResized(float width, float height) { /* Post a message to the BApp so that it can handle the window event */ BMessage msg(BAPP_WINDOW_RESIZED); - msg.AddInt32("window-w", (int)width + 1); /* TODO: Check that +1 is needed */ + + msg.AddInt32("window-w", (int)width + 1); msg.AddInt32("window-h", (int)height + 1); _PostWindowEvent(msg); @@ -409,15 +407,12 @@ printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left, uint32 GetRowBytes() { return _row_bytes; } int32 GetFbX() { return _bounds.left; } int32 GetFbY() { return _bounds.top; } -// int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } -// int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } bool ConnectionEnabled() { return !_connection_disabled; } bool Connected() { return _connected; } clipping_rect *GetClips() { return _clips; } int32 GetNumClips() { return _num_clips; } uint8* GetBufferPx() { return _bits; } int32 GetBytesPerPx() { return _bytes_per_px; } -// uint8* GetWindowFramebuffer() { return _window_buffer; } bool CanTrashWindowBuffer() { return _trash_window_buffer; } bool BufferExists() { return _buffer_created; } bool BufferIsDirty() { return _buffer_dirty; } @@ -429,7 +424,6 @@ printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left, /* Setter methods */ void SetID(int32 id) { _id = id; } void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; } -// void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; } void LockBuffer() { _buffer_locker->Lock(); } void UnlockBuffer() { _buffer_locker->Unlock(); } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } @@ -575,27 +569,12 @@ private: void _SetFullScreen(BMessage *msg) { bool fullscreen; - - BRect rc1 = Bounds(), - rc2 = Frame(); -printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom, -rc2.left, rc2.top, rc2.right, rc2.bottom); if( msg->FindBool("fullscreen", &fullscreen) != B_OK ) { return; } - -if(fullscreen) { - printf("Setting fullscreen...\n"); -} else { - printf("Unsetting fullscreen...\n"); -} -#if 1 SetFullScreen(fullscreen); -#endif -printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom, -rc2.left, rc2.top, rc2.right, rc2.bottom); } /* Members */ @@ -615,7 +594,8 @@ rc2.left, rc2.top, rc2.right, rc2.bottom); bool _connected, _connection_disabled, _buffer_created, - _buffer_dirty; + _buffer_dirty, + _trash_window_buffer; uint8 *_bits; uint32 _row_bytes; clipping_rect _bounds; @@ -623,11 +603,24 @@ rc2.left, rc2.top, rc2.right, rc2.bottom); clipping_rect *_clips; int32 _num_clips; int32 _bytes_per_px; -// uint8 *_window_buffer; /* A copy of the window buffer */ - bool _trash_window_buffer; thread_id _draw_thread_id; BBitmap *_bitmap; }; + +/* FIXME: + * An explanation of framebuffer flags. + * + * _connected - Original variable used to let the drawing thread know + * when changes are being made to the other framebuffer + * members. + * _connection_disabled - Used to signal to the drawing thread that the window + * is closing, and the thread should exit. + * _buffer_created - True if the current buffer is valid + * _buffer_dirty - True if the window should be redrawn. + * _trash_window_buffer - True if the window buffer needs to be trashed partway + * through a draw cycle. Occurs when the previous + * buffer provided by DirectConnected() is invalidated. + */ #endif diff --git a/src/video/bwindow/SDL_bclipboard.cc b/src/video/bwindow/SDL_bclipboard.cc index 4cc965899..90914a1fd 100644 --- a/src/video/bwindow/SDL_bclipboard.cc +++ b/src/video/bwindow/SDL_bclipboard.cc @@ -35,7 +35,6 @@ extern "C" { #endif int BE_SetClipboardText(_THIS, const char *text) { -#if 0 BMessage *clip = NULL; if(be_clipboard->Lock()) { be_clipboard->Clear(); @@ -48,20 +47,17 @@ int BE_SetClipboardText(_THIS, const char *text) { } be_clipboard->Unlock(); } -#else -return -1; -#endif } char *BE_GetClipboardText(_THIS) { -#if 0 BMessage *clip = NULL; const char *text; ssize_t length; if(be_clipboard->Lock()) { if((clip = be_clipboard->Data())) { /* Presumably the string of characters is ascii-format */ - clip->FindData("text/plain", B_MIME_TYPE, (void**)&text, &length); + clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, + &length); } else { be_clipboard->Unlock(); return NULL; @@ -76,13 +72,9 @@ char *BE_GetClipboardText(_THIS) { SDL_strlcpy(result, text, length); return result; -#else -return NULL; -#endif; } SDL_bool BE_HasClipboardText(_THIS) { -#if 0 BMessage *clip = NULL; const char *text; ssize_t length; @@ -91,15 +83,13 @@ SDL_bool BE_HasClipboardText(_THIS) { if(be_clipboard->Lock()) { if((clip = be_clipboard->Data())) { /* Presumably the string of characters is ascii-format */ - clip->FindData("text/plain", B_MIME_TYPE, (void**)&text, &length); + clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, + &length); if( text ) retval = SDL_TRUE; } be_clipboard->Unlock(); } return retval; -#else -return SDL_FALSE; -#endif } diff --git a/src/video/bwindow/SDL_bevents.cc b/src/video/bwindow/SDL_bevents.cc index 484d73a26..e5ad003ec 100644 --- a/src/video/bwindow/SDL_bevents.cc +++ b/src/video/bwindow/SDL_bevents.cc @@ -26,6 +26,7 @@ extern "C" { #endif void BE_PumpEvents(_THIS) { + /* Since the event thread is its own thread, this isn't really necessary */ } #ifdef __cplusplus diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 4d0a2bb97..cd76a24e3 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -126,9 +126,7 @@ int32 BE_DrawThread(void *data) { if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { bwin->LockBuffer(); BBitmap *bitmap = NULL; -// while(!bitmap) { - bitmap = bwin->GetBitmap(); -// } + bitmap = bwin->GetBitmap(); int32 windowPitch = bitmap->BytesPerRow(); int32 bufferPitch = bwin->GetRowBytes(); uint8 *windowpx; @@ -163,14 +161,12 @@ int32 BE_DrawThread(void *data) { goto escape; /* Break out before the buffer is killed */ } -// printf("memcpy(0x%x, 0x%x, %i) ", bufferpx, windowpx, width * BPP); memcpy(bufferpx, windowpx, width * BPP); bufferpx += bufferPitch; windowpx += windowPitch; } -// printf("\t-\t"); } -// printf("\n"); + bwin->SetBufferDirty(false); escape: bwin->UnlockBuffer(); diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 0e3e5b78b..9b4f3b270 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -37,10 +37,11 @@ extern "C" { #endif -#define WRAP_BMODE 1 +#define WRAP_BMODE 1 /* FIXME: Some debate as to whether this is necessary */ #if WRAP_BMODE -/* This wrapper is here so that the driverdata can be freed */ +/* This wrapper is here so that the driverdata can be freed without freeing + the display_mode structure */ typedef struct SDL_DisplayModeData { display_mode *bmode; }; @@ -55,10 +56,10 @@ static inline SDL_BApp *_GetBeApp() { } static inline display_mode * _ExtractBMode(SDL_DisplayMode *mode) { -#if 0 - return (display_mode*)(mode->driverdata); -#else +#if WRAP_BMODE return ((SDL_DisplayModeData*)mode->driverdata)->bmode; +#else + return (display_mode*)(mode->driverdata); #endif } @@ -68,6 +69,68 @@ static float get_refresh_rate(display_mode &mode) { / float(mode.timing.h_total * mode.timing.v_total); } + +#if 0 +/* TODO: + * This is a useful debugging tool. Uncomment and insert into code as needed. + */ +void _SpoutModeData(display_mode *bmode) { + printf("BMode:\n"); + printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); + printf("\th,v = (%i,%i)\n", bmode->h_display_start, + bmode->v_display_start); + if(bmode->flags) { + printf("\tFlags:\n"); + if(bmode->flags & B_SCROLL) { + printf("\t\tB_SCROLL\n"); + } + if(bmode->flags & B_8_BIT_DAC) { + printf("\t\tB_8_BIT_DAC\n"); + } + if(bmode->flags & B_HARDWARE_CURSOR) { + printf("\t\tB_HARDWARE_CURSOR\n"); + } + if(bmode->flags & B_PARALLEL_ACCESS) { + printf("\t\tB_PARALLEL_ACCESS\n"); + } + if(bmode->flags & B_DPMS) { + printf("\t\tB_DPMS\n"); + } + if(bmode->flags & B_IO_FB_NA) { + printf("\t\tB_IO_FB_NA\n"); + } + } + printf("\tTiming:\n"); + printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); + printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.h_display, bmode->timing.h_sync_start, + bmode->timing.h_sync_end, bmode->timing.h_total); + printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", + bmode->timing.v_display, bmode->timing.v_sync_start, + bmode->timing.v_sync_end, bmode->timing.v_total); + if(bmode->timing.flags) { + printf("\t\tFlags:\n"); + if(bmode->timing.flags & B_BLANK_PEDESTAL) { + printf("\t\t\tB_BLANK_PEDESTAL\n"); + } + if(bmode->timing.flags & B_TIMING_INTERLACED) { + printf("\t\t\tB_TIMING_INTERLACED\n"); + } + if(bmode->timing.flags & B_POSITIVE_HSYNC) { + printf("\t\t\tB_POSITIVE_HSYNC\n"); + } + if(bmode->timing.flags & B_POSITIVE_VSYNC) { + printf("\t\t\tB_POSITIVE_VSYNC\n"); + } + if(bmode->timing.flags & B_SYNC_ON_GREEN) { + printf("\t\t\tB_SYNC_ON_GREEN\n"); + } + } +} +#endif + + + static inline int32 ColorSpaceToBitsPerPixel(uint32 colorspace) { int bitsperpixel; @@ -123,17 +186,21 @@ static inline int32 BPPToSDLPxFormat(int32 bpp) { } } -static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, +static inline void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) { mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; mode->refresh_rate = (int)get_refresh_rate(*bmode); + #if WRAP_BMODE - SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData)); + SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, + sizeof(SDL_DisplayModeData)); data->bmode = bmode; mode->driverdata = data; + #else + mode->driverdata = bmode; #endif @@ -143,13 +210,14 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode, } /* Later, there may be more than one monitor available */ -void BE_AddDisplay(BScreen *screen) { +void _AddDisplay(BScreen *screen) { SDL_VideoDisplay display; - SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, sizeof(SDL_DisplayMode)); + SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, + sizeof(SDL_DisplayMode)); display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode)); screen->GetMode(bmode); - BE_BDisplayModeToSdlDisplayMode(bmode, mode); + _BDisplayModeToSdlDisplayMode(bmode, mode); SDL_zero(display); display.desktop_mode = *mode; @@ -158,23 +226,20 @@ void BE_AddDisplay(BScreen *screen) { SDL_AddVideoDisplay(&display); } +/* + * Functions called by SDL + */ + int BE_InitModes(_THIS) { BScreen screen; - - /* Save the current display mode */ -// display_mode *prevMode; -// screen.GetMode(prevMode); -// _GetBeApp()->SetPrevMode(prevMode); - /* Only one possible video display right now */ - BE_AddDisplay(&screen); + /* TODO: When Haiku supports multiple display screens, call + _AddDisplayScreen() for each of them. */ + _AddDisplay(&screen); } int BE_QuitModes(_THIS) { - /* Restore the previous video mode */ - BScreen screen; -// display_mode *savedMode = _GetBeApp()->GetPrevMode(); -// screen.SetMode(savedMode); + /* FIXME: Nothing really needs to be done here at the moment? */ return 0; } @@ -206,7 +271,7 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { for(i = 0; i < count; ++i) { //FIXME: Apparently there are errors with colorspace changes if (bmodes[i].space == this_bmode.space) { - BE_BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); + _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); SDL_AddDisplayMode(display, &mode); } } @@ -214,158 +279,8 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { } - - - - - - - - - - - - -static int get_combine_mode(display_mode &mode) { - if ((mode.flags & B_SCROLL) == 0) - return 0; - - if (mode.virtual_width == mode.timing.h_display * 2) - return 1; - - if (mode.virtual_height == mode.timing.v_display * 2) - return 2; - - return 0; -} -#if 0 -bool _GetDisplayMode(const screen_mode& mode, display_mode& displayMode) -{ - uint16 virtualWidth, virtualHeight; - int32 bestIndex = -1; - float bestDiff = 999; - - virtualWidth = mode.combine == kCombineHorizontally - ? mode.width * 2 : mode.width; - virtualHeight = mode.combine == kCombineVertically - ? mode.height * 2 : mode.height; - - // try to find mode in list provided by driver - for (uint32 i = 0; i < fModeCount; i++) { - if (fModeList[i].virtual_width != virtualWidth - || fModeList[i].virtual_height != virtualHeight - || (color_space)fModeList[i].space != mode.space) - continue; - - // Accept the mode if the computed refresh rate of the mode is within - // 0.6 percent of the refresh rate specified by the caller. Note that - // refresh rates computed from mode parameters is not exact; especially - // some of the older modes such as 640x480, 800x600, and 1024x768. - // The tolerance of 0.6% was obtained by examining the various possible - // modes. - - float refreshDiff = fabs(get_refresh_rate(fModeList[i]) - mode.refresh); - if (refreshDiff < 0.006 * mode.refresh) { - // Accept this mode. - displayMode = fModeList[i]; - displayMode.h_display_start = 0; - displayMode.v_display_start = 0; - - // Since the computed refresh rate of the selected mode might differ - // from selected refresh rate by a few tenths (e.g. 60.2 instead of - // 60.0), tweak the pixel clock so the the refresh rate of the mode - // matches the selected refresh rate. - - displayMode.timing.pixel_clock = uint32(((displayMode.timing.h_total - * displayMode.timing.v_total * mode.refresh) / 1000.0) + 0.5); - return true; - } - - // Mode not acceptable. - - if (refreshDiff < bestDiff) { - bestDiff = refreshDiff; - bestIndex = i; - } - } - - // we didn't find the exact mode, but something very similar? - if (bestIndex == -1) - return false; - - displayMode = fModeList[bestIndex]; - displayMode.h_display_start = 0; - displayMode.v_display_start = 0; - - // For the mode selected by the width, height, and refresh rate, compute - // the video timing parameters for the mode by using the VESA Generalized - // Timing Formula (GTF). - - ComputeGTFVideoTiming(displayMode.timing.h_display, - displayMode.timing.v_display, mode.refresh, displayMode.timing); - - return true; -} -#endif - -void _SpoutModeData(display_mode *bmode) { - printf("BMode:\n"); - printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); - printf("\th,v = (%i,%i)\n", bmode->h_display_start, - bmode->v_display_start); - printf("\tcombine mode = %i\n", get_combine_mode(*bmode)); - if(bmode->flags) { - printf("\tFlags:\n"); - if(bmode->flags & B_SCROLL) { - printf("\t\tB_SCROLL\n"); - } - if(bmode->flags & B_8_BIT_DAC) { - printf("\t\tB_8_BIT_DAC\n"); - } - if(bmode->flags & B_HARDWARE_CURSOR) { - printf("\t\tB_HARDWARE_CURSOR\n"); - } - if(bmode->flags & B_PARALLEL_ACCESS) { - printf("\t\tB_PARALLEL_ACCESS\n"); - } - if(bmode->flags & B_DPMS) { - printf("\t\tB_DPMS\n"); - } - if(bmode->flags & B_IO_FB_NA) { - printf("\t\tB_IO_FB_NA\n"); - } - } - printf("\tTiming:\n"); - printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); - printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", - bmode->timing.h_display, bmode->timing.h_sync_start, - bmode->timing.h_sync_end, bmode->timing.h_total); - printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", - bmode->timing.v_display, bmode->timing.v_sync_start, - bmode->timing.v_sync_end, bmode->timing.v_total); - if(bmode->timing.flags) { - printf("\t\tFlags:\n"); - if(bmode->timing.flags & B_BLANK_PEDESTAL) { - printf("\t\t\tB_BLANK_PEDESTAL\n"); - } - if(bmode->timing.flags & B_TIMING_INTERLACED) { - printf("\t\t\tB_TIMING_INTERLACED\n"); - } - if(bmode->timing.flags & B_POSITIVE_HSYNC) { - printf("\t\t\tB_POSITIVE_HSYNC\n"); - } - if(bmode->timing.flags & B_POSITIVE_VSYNC) { - printf("\t\t\tB_POSITIVE_VSYNC\n"); - } - if(bmode->timing.flags & B_SYNC_ON_GREEN) { - printf("\t\t\tB_SYNC_ON_GREEN\n"); - } - } -} - int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ /* Get the current screen */ -printf(__FILE__": %d\n", __LINE__); BScreen bscreen; if(!bscreen.IsValid()) { printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); @@ -375,24 +290,18 @@ printf(__FILE__": %d\n", __LINE__); display_mode *bmode = _ExtractBMode(mode); -_SpoutModeData(bmode); -printf("\n"); -uint32 c = 0, i, x = 0; -#define RES 0 -display_mode *bmode_list; -bscreen.GetModeList(&bmode_list, &c); -for(i = 0; i < c; ++i) { - if( bmode_list[i].space == bmode->space && - bmode_list[i].virtual_width == bmode->virtual_width && - bmode_list[i].virtual_height == bmode->virtual_height ) { - if(x == RES) + /* FIXME: Is the first option always going to be the right one? */ + uint32 c = 0, i; + display_mode *bmode_list; + bscreen.GetModeList(&bmode_list, &c); + for(i = 0; i < c; ++i) { + if( bmode_list[i].space == bmode->space && + bmode_list[i].virtual_width == bmode->virtual_width && + bmode_list[i].virtual_height == bmode->virtual_height ) { bmode = &bmode_list[i]; - - ++x; - _SpoutModeData(&bmode_list[i]); -// break; + break; + } } -} if(bscreen.SetMode(bmode) != B_OK) { SDL_SetError("Bad video mode\n"); @@ -401,11 +310,11 @@ for(i = 0; i < c; ++i) { free(bmode_list); #if SDL_VIDEO_OPENGL - /* The OpenGL context may need to be rebooted */ + /* FIXME: Is there some way to reboot the OpenGL context? This doesn't + help */ // BE_GL_RebootContexts(_this); #endif -printf(__FILE__": %d\n", __LINE__); return 0; } diff --git a/src/video/bwindow/SDL_bopengl.cc b/src/video/bwindow/SDL_bopengl.cc index f202cce17..4d372569b 100644 --- a/src/video/bwindow/SDL_bopengl.cc +++ b/src/video/bwindow/SDL_bopengl.cc @@ -45,6 +45,7 @@ static inline SDL_BApp *_GetBeApp() { /* Passing a NULL path means load pointers from the application */ int BE_GL_LoadLibrary(_THIS, const char *path) { +/* FIXME: Is this working correctly? */ image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { @@ -58,64 +59,6 @@ int BE_GL_LoadLibrary(_THIS, const char *path) SDL_arraysize(_this->gl_config.driver_path)); } } -#if 0 -printf("\n\nLibrary loading: %s\n\n", path); - if (path == NULL) { - if (_this->gl_config.dll_handle == NULL) { - image_info info; - int32 cookie = 0; - while (get_next_image_info(0, &cookie, &info) == B_OK) { - printf(__FILE__": %d - Inside while\n",__LINE__); - void *location = NULL; - if (get_image_symbol - ((image_id) cookie, "glBegin", - B_SYMBOL_TYPE_ANY, &location) == B_OK) { - _this->gl_config.dll_handle = (void *) cookie; - _this->gl_config.driver_loaded = 1; - SDL_strlcpy(_this->gl_config.driver_path, - "libGL.so", - SDL_arraysize(_this-> - gl_config.driver_path)); - } - } - } - } else { - /* - FIXME None of BeOS libGL.so implementations have exported functions - to load BGLView, which should be reloaded from new lib. - So for now just "load" linked libGL.so :( - */ - if (_this->gl_config.dll_handle == NULL) { - return BE_GL_LoadLibrary(_this, NULL); - } - /* Unload old first */ - /*if (_this->gl_config.dll_handle != NULL) { */ - /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */ - /* image_info info; - if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) { - if (info.type != B_APP_IMAGE) { - unload_add_on((image_id)_this->gl_config.dll_handle); - } - } - - } - - if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) { - _this->gl_config.driver_loaded = 1; - SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); - } */ - } - - if (_this->gl_config.dll_handle != NULL) { - return 0; - } else { -printf(__FILE__": %d- gl_config.driver_loaded = 0\n", __LINE__); - _this->gl_config.dll_handle = NULL; - _this->gl_config.driver_loaded = 0; - *_this->gl_config.driver_path = '\0'; - return -1; - } -#endif } void *BE_GL_GetProcAddress(_THIS, const char *proc) @@ -161,28 +104,29 @@ SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) { void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { /* Currently, automatically unlocks the view */ -printf(__FILE__": %d\n", __LINE__); ((SDL_BWin*)context)->RemoveGLView(); } int BE_GL_SetSwapInterval(_THIS, int interval) { - printf(__FILE__": %d- swap interval set\n", __LINE__); + /* TODO: Implement this, if necessary? */ return 0; } int BE_GL_GetSwapInterval(_THIS) { - printf(__FILE__": %d- swap interval requested\n", __LINE__); + /* TODO: Implement this, if necessary? */ return 0; } void BE_GL_UnloadLibrary(_THIS) { - printf(__FILE__": %d- Library unloaded\n", __LINE__); + /* TODO: Implement this, if necessary? */ } - +/* FIXME: This function is meant to clear the OpenGL context when the video + mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not + currently in use. */ void BE_GL_RebootContexts(_THIS) { SDL_Window *window = _this->windows; while(window) { diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index 721bfb490..1e4b48e40 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -53,23 +53,11 @@ BE_CreateDevice(int devindex) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); -#if 0 - if (device) { - data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - } else { - data = NULL; - } - if (!data) { - SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return NULL; - } -#endif - device->driverdata = NULL; /*data;*/ -/* TODO: Figure out what sort of initialization needs to go here */ + device->driverdata = NULL; /* FIXME: Is this the cause of some of the + SDL_Quit() errors? */ + +/* TODO: Figure out if any initialization needs to go here */ /* Set the function pointers */ device->VideoInit = BE_VideoInit; @@ -105,7 +93,7 @@ BE_CreateDevice(int devindex) device->shape_driver.SetWindowShape = NULL; device->shape_driver.ResizeWindowShape = NULL; -//#if SDL_VIDEO_OPENGL_WGL /* FIXME: Replace with BeOs's SDL OPENGL stuff */ + device->GL_LoadLibrary = BE_GL_LoadLibrary; device->GL_GetProcAddress = BE_GL_GetProcAddress; device->GL_UnloadLibrary = BE_GL_UnloadLibrary; @@ -115,7 +103,7 @@ BE_CreateDevice(int devindex) device->GL_GetSwapInterval = BE_GL_GetSwapInterval; device->GL_SwapWindow = BE_GL_SwapWindow; device->GL_DeleteContext = BE_GL_DeleteContext; -//#endif + device->StartTextInput = BE_StartTextInput; device->StopTextInput = BE_StopTextInput; device->SetTextInputRect = BE_SetTextInputRect; @@ -140,8 +128,6 @@ static void BE_DeleteDevice(SDL_VideoDevice * device) SDL_free(device); } -/* FIXME: This is the 1.2 function at the moment. Read through it and - o understand what it does. */ int BE_VideoInit(_THIS) { /* Initialize the Be Application for appserver interaction */ @@ -162,9 +148,6 @@ int BE_VideoInit(_THIS) BE_GL_LoadLibrary(_this, NULL); #endif - /* Fill in some window manager capabilities */ -// _this->info.wm_available = 1; - /* We're done! */ return (0); } @@ -177,24 +160,8 @@ static int BE_Available(void) void BE_VideoQuit(_THIS) { -#if 0 - SDL_Win->Quit(); - SDL_Win = NULL; -#endif -#if 0 - if (SDL_BlankCursor != NULL) { - BE_FreeWMCursor(_this, SDL_BlankCursor); - SDL_BlankCursor = NULL; - } -#endif - BE_QuitModes(_this); -#if SDL_VIDEO_OPENGL -// if (_this->gl_config.dll_handle != NULL) -// unload_add_on((image_id) _this->gl_config.dll_handle); -#endif - SDL_QuitBeApp(); } diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index b17d96a4e..c88d534aa 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -47,13 +47,17 @@ int _InitWindow(_THIS, SDL_Window *window) { ); if(window->flags & SDL_WINDOW_FULLSCREEN) { + /* TODO: Add support for this flag */ + printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__); } if(window->flags & SDL_WINDOW_OPENGL) { + /* TODO: Add support for this flag */ } if(!(window->flags & SDL_WINDOW_RESIZABLE)) { flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; } if(window->flags & SDL_WINDOW_BORDERLESS) { + /* TODO: Add support for this flag */ } SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, flags); @@ -172,10 +176,12 @@ void BE_SetWindowFullscreen(_THIS, SDL_Window * window, int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) { /* FIXME: Not BeOs/Haiku supported */ + return -1; } int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) { /* FIXME: Not BeOs/Haiku supported */ + return -1; } @@ -193,6 +199,7 @@ void BE_DestroyWindow(_THIS, SDL_Window * window) { SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) { /* FIXME: What is the point of this? What information should be included? */ + return SDL_FALSE; } From b6c26ffe7190cea99fbff14f6e368fd55c83372c Mon Sep 17 00:00:00 2001 From: Nathan Heisey Date: Mon, 22 Aug 2011 21:07:16 +0000 Subject: [PATCH 27/27] Fixed static misnomers --- src/video/bwindow/SDL_bframebuffer.cc | 4 ++-- src/video/bwindow/SDL_bmodes.cc | 15 ++++++++------- src/video/bwindow/SDL_bmodes.h | 4 ++-- src/video/bwindow/SDL_bvideo.cc | 4 ++-- src/video/bwindow/SDL_bwindow.cc | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index cd76a24e3..f3fb8ef5b 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -59,8 +59,8 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* format */ display_mode bmode; bscreen.GetMode(&bmode); - int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); - *format = BPPToSDLPxFormat(bpp); + int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode.space); + *format = BE_BPPToSDLPxFormat(bpp); /* Create the new bitmap object */ BBitmap *bitmap = bwin->GetBitmap(); diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 9b4f3b270..06b412b64 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -131,7 +131,7 @@ void _SpoutModeData(display_mode *bmode) { -static inline int32 ColorSpaceToBitsPerPixel(uint32 colorspace) +int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace) { int bitsperpixel; @@ -162,7 +162,7 @@ static inline int32 ColorSpaceToBitsPerPixel(uint32 colorspace) return(bitsperpixel); } -static inline int32 BPPToSDLPxFormat(int32 bpp) { +int32 BE_BPPToSDLPxFormat(int32 bpp) { /* Translation taken from SDL_windowsmodes.c */ switch (bpp) { case 32: @@ -186,7 +186,7 @@ static inline int32 BPPToSDLPxFormat(int32 bpp) { } } -static inline void _BDisplayModeToSdlDisplayMode(display_mode *bmode, +static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) { mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; @@ -205,12 +205,12 @@ static inline void _BDisplayModeToSdlDisplayMode(display_mode *bmode, #endif /* Set the format */ - int32 bpp = ColorSpaceToBitsPerPixel(bmode->space); - mode->format = BPPToSDLPxFormat(bpp); + int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode->space); + mode->format = BE_BPPToSDLPxFormat(bpp); } /* Later, there may be more than one monitor available */ -void _AddDisplay(BScreen *screen) { +static void _AddDisplay(BScreen *screen) { SDL_VideoDisplay display; SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, sizeof(SDL_DisplayMode)); @@ -307,7 +307,8 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ SDL_SetError("Bad video mode\n"); return -1; } -free(bmode_list); + + free(bmode_list); #if SDL_VIDEO_OPENGL /* FIXME: Is there some way to reboot the OpenGL context? This doesn't diff --git a/src/video/bwindow/SDL_bmodes.h b/src/video/bwindow/SDL_bmodes.h index 04055a128..f958f6632 100644 --- a/src/video/bwindow/SDL_bmodes.h +++ b/src/video/bwindow/SDL_bmodes.h @@ -28,8 +28,8 @@ extern "C" { #include "../SDL_sysvideo.h" -extern int32 ColorSpaceToBitsPerPixel(uint32 colorspace); -extern int32 BPPToSDLPxFormat(int32 bpp); +extern int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace); +extern int32 BE_BPPToSDLPxFormat(int32 bpp); extern int BE_InitModes(_THIS); extern int BE_QuitModes(_THIS); diff --git a/src/video/bwindow/SDL_bvideo.cc b/src/video/bwindow/SDL_bvideo.cc index 1e4b48e40..0037c04d5 100644 --- a/src/video/bwindow/SDL_bvideo.cc +++ b/src/video/bwindow/SDL_bvideo.cc @@ -122,7 +122,7 @@ VideoBootStrap BWINDOW_bootstrap = { BE_Available, BE_CreateDevice }; -static void BE_DeleteDevice(SDL_VideoDevice * device) +void BE_DeleteDevice(SDL_VideoDevice * device) { SDL_free(device->driverdata); SDL_free(device); @@ -152,7 +152,7 @@ int BE_VideoInit(_THIS) return (0); } -static int BE_Available(void) +int BE_Available(void) { return (1); } diff --git a/src/video/bwindow/SDL_bwindow.cc b/src/video/bwindow/SDL_bwindow.cc index c88d534aa..2c550d593 100644 --- a/src/video/bwindow/SDL_bwindow.cc +++ b/src/video/bwindow/SDL_bwindow.cc @@ -37,7 +37,7 @@ static inline SDL_BApp *_GetBeApp() { return ((SDL_BApp*)be_app); } -int _InitWindow(_THIS, SDL_Window *window) { +static int _InitWindow(_THIS, SDL_Window *window) { uint32 flags = 0; BRect bounds( window->x,