Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Framebuffer support in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
antifinidictor committed Jul 20, 2011
1 parent b0702d6 commit bb8889f
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 70 deletions.
20 changes: 14 additions & 6 deletions src/video/bwindow/SDL_BWin.h
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -460,13 +465,16 @@ class SDL_BWin:public BDirectWindow

/* 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;
Expand Down
33 changes: 33 additions & 0 deletions src/video/bwindow/SDL_bevents.cc
@@ -0,0 +1,33 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
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
37 changes: 37 additions & 0 deletions src/video/bwindow/SDL_bevents.h
@@ -0,0 +1,37 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
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
216 changes: 171 additions & 45 deletions src/video/bwindow/SDL_bmodes.cc
Expand Up @@ -19,60 +19,186 @@
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;
#include <AppKit.h>
#include <InterfaceKit.h>
#include "SDL_bmodes.h"

/* 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;
#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) {
printf("Init Modes\n");
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);
}

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 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);
}

/* 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;
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 */
}
#else
return -1;
#endif

return -1;
}

#ifdef __cplusplus
}
#endif
16 changes: 16 additions & 0 deletions src/video/bwindow/SDL_bmodes.h
Expand Up @@ -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

0 comments on commit bb8889f

Please sign in to comment.