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

Commit

Permalink
Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
Browse files Browse the repository at this point in the history
From: couriersud arcor.de
To: slouken@libsdl.org
Subject: Directfb driver for SDL1.3

Hi,

the attachment contains a patch for a SDL1.3 directfb driver. It supports:

- Renderer "directfb":

Hardware acceleration as supported by the underlying directfb driver. With a
radeon X850, testsprite2 runs at 50% to 70% of OpenGL (X11, dri) performance.

Also supports hardware accelerated yuv overlays. This must be enabled by sett
ing:

export SDL_DIRECTFB_YUV_DIRECT=1

- Renderer "opengl"

Supports software opengl using mesa opengl (make linux-directfb).

Some more information may be found in README.DirectFB

There will certainly still be some bugs, and there is some debug code around.
 When I find some time, I will compile against directfb-0.9.25 as distributed
 with ubuntu 7.04.

The diff also contains a fix for SDL_LockYUVOverlay fixing a bug in  *pixels
and pitches initialization.

Kind regards,

couriersud
  • Loading branch information
slouken committed Aug 11, 2007
1 parent 1fc29dd commit dbc7937
Show file tree
Hide file tree
Showing 12 changed files with 2,198 additions and 1,407 deletions.
45 changes: 45 additions & 0 deletions README.DirectFB
@@ -0,0 +1,45 @@
SDL on DirectFB

Supports:

- Hardware YUV overlays
- OpenGL - software only
- 2D/3D accelerations (depends on directfb driver)

What you need:

DirectFB 1.0.0 - required
Kernel-Framebuffer support: required: vesafb, radeonfb ....
Mesa 7.0.x - optional for OpenGL

As of this writing 20070810 you need to pull Mesa from git and do the following:

------------------------
cd mesa
make linux-directfb
make

echo Installing - pleaser enter sudo pw.

sudo make install INSTALL_DIR=/usr/local/dfb_GL
cd src/mesa/drivers/directfb
make
sudo make install INSTALL_DIR=/usr/local/dfb_GL
------------------------

To run the SDL - testprograms:

export SDL_VIDEODRIVER=directfb
export LD_LIBRARY_PATH=/usr/local/dfb_GL/lib
export LD_PRELOAD=/usr/local/dfb_GL/libGL.so.7

./testgl

To use hardware accelerated YUV-overlays for YUV-textures, use:

export SDL_DIRECTFB_YUV_DIRECT=1

This is disabled by default. It will only support one concurrent
overlay and may behave strange if not used with SDL_CreateYUvOverlay
from SDLcompat.c.

8 changes: 5 additions & 3 deletions src/SDL_compat.c
Expand Up @@ -1440,19 +1440,21 @@ SDL_LockYUVOverlay(SDL_Overlay * overlay)
< 0) {
return -1;
}
overlay->pixels[0] = (Uint8 *) pixels;
overlay->pitches[0] = pitch;
switch (overlay->format) {
case SDL_YV12_OVERLAY:
case SDL_IYUV_OVERLAY:
overlay->pixels[0] = (Uint8 *) pixels;
overlay->pitches[1] = pitch / 2;
overlay->pitches[2] = pitch / 2;
overlay->pixels[1] =
overlay->pixels[0] + overlay->pitches[0] * overlay->h;
overlay->pixels[2] =
overlay->pixels[1] + overlay->pitches[1] * overlay->h;
overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2;
break;
case SDL_YUY2_OVERLAY:
case SDL_UYVY_OVERLAY:
case SDL_YVYU_OVERLAY:
overlay->pixels[0] = (Uint8 *) pixels;
break;
}
return 0;
Expand Down
258 changes: 201 additions & 57 deletions src/video/directfb/SDL_DirectFB_events.c
Expand Up @@ -23,70 +23,97 @@

/* Handle the event stream, converting DirectFB input events into SDL events */

#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

#include <directfb.h>

#include "SDL.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_events.h"

/* The translation tables from a DirectFB keycode to a SDL keysym */
static SDLKey keymap[256];
static SDL_keysym *DirectFB_TranslateKey(DFBInputEvent * ev,
SDL_keysym * keysym);
static int DirectFB_TranslateButton(DFBInputEvent * ev);

static int posted = 0;
static SDL_keysym *DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
DFBInputDeviceKeySymbol key_symbol,
DFBInputDeviceModifierMask key_mod,
SDL_keysym * keysym);

static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);

void
DirectFB_PumpEvents(_THIS)
DirectFB_PumpEventsWindow(_THIS)
{
DFBInputEvent evt;
SDL_DFB_DEVICEDATA(_this);
DFB_WindowData *p;
DFBWindowEvent evt;

while (HIDDEN->eventbuffer->GetEvent(HIDDEN->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
SDL_keysym keysym;
for (p = devdata->firstwin; p != NULL; p = p->next) {
while (p->eventbuffer->GetEvent(p->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
SDL_keysym keysym;

switch (evt.type) {
case DIET_BUTTONPRESS:
posted += SDL_PrivateMouseButton(SDL_PRESSED,
DirectFB_TranslateButton
(&evt), 0, 0);
break;
case DIET_BUTTONRELEASE:
posted += SDL_PrivateMouseButton(SDL_RELEASED,
DirectFB_TranslateButton
(&evt), 0, 0);
break;
case DIET_KEYPRESS:
posted +=
SDL_PrivateKeyboard(SDL_PRESSED,
DirectFB_TranslateKey(&evt, &keysym));
break;
case DIET_KEYRELEASE:
posted +=
SDL_PrivateKeyboard(SDL_RELEASED,
DirectFB_TranslateKey(&evt, &keysym));
break;
case DIET_AXISMOTION:
if (evt.flags & DIEF_AXISREL) {
if (evt.axis == DIAI_X)
posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
else if (evt.axis == DIAI_Y)
posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
if (evt.clazz = DFEC_WINDOW) {
switch (evt.type) {
case DWET_BUTTONDOWN:
SDL_SendMouseButton(devdata->mouse, SDL_PRESSED,
DirectFB_TranslateButton(evt.button));
break;
case DWET_BUTTONUP:
SDL_SendMouseButton(devdata->mouse, SDL_RELEASED,
DirectFB_TranslateButton(evt.button));
break;
case DWET_MOTION:
SDL_SendMouseMotion(devdata->mouse, 0, evt.x, evt.y);
break;
case DWET_KEYDOWN:
DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
evt.modifiers, &keysym);
SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
keysym.scancode, keysym.sym);
break;
case DWET_KEYUP:
DirectFB_TranslateKey(evt.key_id, evt.key_symbol,
evt.modifiers, &keysym);
SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
keysym.scancode, keysym.sym);
break;
case DWET_POSITION_SIZE:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
evt.cy);
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
evt.h);
break;
case DWET_POSITION:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.cx,
evt.cy);
break;
case DWET_SIZE:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w,
evt.h);
break;
case DWET_CLOSE:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
case DWET_GOTFOCUS:
//TODO: Implement for yuv-overlay DirectFB_SwitchOverlayContext(this, evt.window_id);
SDL_SetKeyboardFocus(devdata->keyboard, p->id);
break;
case DWET_LOSTFOCUS:
SDL_SetKeyboardFocus(devdata->keyboard, 0);
break;
case DWET_ENTER:
//SDL_DirectFB_ReshowCursor(_this, 0);
SDL_SetMouseFocus(devdata->mouse, p->id);
break;
case DWET_LEAVE:
SDL_SetMouseFocus(devdata->mouse, 0);
//SDL_DirectFB_ReshowCursor(_this, 1);
break;
default:
;
}
}
break;
default:
;
}
}
}
Expand Down Expand Up @@ -177,35 +204,80 @@ DirectFB_InitOSKeymap(_THIS)
keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;

keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDLK_KP_EQUALS;
keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDLK_KP_PERIOD;
keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDLK_KP0;
keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDLK_KP1;
keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDLK_KP2;
keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDLK_KP3;
keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDLK_KP4;
keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDLK_KP5;
keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDLK_KP6;
keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDLK_KP7;
keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDLK_KP8;
keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDLK_KP9;
keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
}

keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDLK_BACKQUOTE; /* TLDE */
keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDLK_MINUS; /* AE11 */
keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDLK_EQUALS; /* AE12 */
keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDLK_RIGHTBRACKET; /* AD11 */
keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDLK_LEFTBRACKET; /* AD12 */
keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDLK_BACKSLASH; /* BKSL */
keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDLK_SEMICOLON; /* AC10 */
keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDLK_QUOTE; /* AC11 */
keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDLK_COMMA; /* AB08 */
keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDLK_PERIOD; /* AB09 */
keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDLK_SLASH; /* AB10 */
keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDLK_LESS; /* 103rd */
}

static SDL_keysym *
DirectFB_TranslateKey(DFBInputEvent * ev, SDL_keysym * keysym)
DirectFB_TranslateKey(DFBInputDeviceKeyIdentifier key_id,
DFBInputDeviceKeySymbol key_symbol,
DFBInputDeviceModifierMask key_mod, SDL_keysym * keysym)
{
SDLMod mod = KMOD_NONE;

/*
* Set modifier information
*/

if (key_mod & DIMM_SHIFT)
mod = mod | KMOD_LSHIFT;
if (key_mod & DIMM_CONTROL)
mod = mod | KMOD_LCTRL;
if (key_mod & DIMM_ALT)
mod = mod | KMOD_LALT;
if (key_mod & DIMM_ALTGR)
mod = mod | KMOD_RALT;
if (key_mod & DIMM_META)
mod = mod | KMOD_LMETA;

/* Set the keysym information */
keysym->scancode = ev->key_id;
keysym->mod = KMOD_NONE; /* FIXME */
keysym->scancode = key_id;

keysym->mod = mod;
keysym->unicode =
(DFB_KEY_TYPE(ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0;
(DFB_KEY_TYPE(key_symbol) == DIKT_UNICODE) ? key_symbol : 0;

if (ev->key_symbol > 0 && ev->key_symbol < 128)
keysym->sym = ev->key_symbol;
if (key_symbol > 0 && key_symbol < 255)
keysym->sym = key_symbol;
else
keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
keysym->sym = keymap[key_id - DIKI_UNKNOWN];

return keysym;
}

static int
DirectFB_TranslateButton(DFBInputEvent * ev)
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
{
switch (ev->button) {
switch (button) {
case DIBI_LEFT:
return 1;
case DIBI_MIDDLE:
Expand All @@ -217,4 +289,76 @@ DirectFB_TranslateButton(DFBInputEvent * ev)
}
}

/* vi: set ts=4 sw=4 expandtab: */
#if 0
void
DirectFB_PumpEvents(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
DFBInputEvent evt;
static last_x = 0, last_y = 0;

while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
SDL_keysym keysym;
DFBInputDeviceModifierMask mod;

if (evt.clazz = DFEC_INPUT) {
if (evt.flags & DIEF_MODIFIERS)
mod = evt.modifiers;
else
mod = 0;

switch (evt.type) {
case DIET_BUTTONPRESS:
posted += SDL_PrivateMouseButton(SDL_PRESSED,
DirectFB_TranslateButton(evt.
button),
0, 0);
break;
case DIET_BUTTONRELEASE:
posted += SDL_PrivateMouseButton(SDL_RELEASED,
DirectFB_TranslateButton(evt.
button),
0, 0);
break;
case DIET_KEYPRESS:
posted += SDL_PrivateKeyboard(SDL_PRESSED,
DirectFB_TranslateKey(evt.
key_id,
evt.
key_symbol,
mod,
&keysym));
break;
case DIET_KEYRELEASE:
posted += SDL_PrivateKeyboard(SDL_RELEASED,
DirectFB_TranslateKey(evt.
key_id,
evt.
key_symbol,
mod,
&keysym));
break;
case DIET_AXISMOTION:
if (evt.flags & DIEF_AXISREL) {
if (evt.axis == DIAI_X)
posted +=
SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
else if (evt.axis == DIAI_Y)
posted +=
SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
} else if (evt.flags & DIEF_AXISABS) {
if (evt.axis == DIAI_X)
last_x = evt.axisabs;
else if (evt.axis == DIAI_Y)
last_y = evt.axisabs;
posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
}
break;
default:
;
}
}
}
}
#endif
3 changes: 1 addition & 2 deletions src/video/directfb/SDL_DirectFB_events.h
Expand Up @@ -25,5 +25,4 @@

/* Functions to be exported */
extern void DirectFB_InitOSKeymap(_THIS);
extern void DirectFB_PumpEvents(_THIS);
/* vi: set ts=4 sw=4 expandtab: */
extern void DirectFB_PumpEventsWindow(_THIS);

0 comments on commit dbc7937

Please sign in to comment.