Does SDL2 work on Beaglebone Black using DirectFB

I am using Buildroot to cross-compile to Beaglebone Black with DirectFB. DirectFB works fine but SDL2 cannot find a renderer.

The 2 commands:
SDL_Init( SDL_INIT_VIDEO )
globalwindow = SDL_CreateWindow( “Peter was here!!”, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
work fine

but
SDL_CreateRenderer( globalwindow, -1, 0) is giving me SDL error “Couldn’t find matching render driver”
and
SDL_CreateRenderer( globalwindow, 0, 0) is giving me SDL error “No hardware accelerated renderers available”

The output is as follows
Number of Video Drivers = 2
video driver 0 = directfb
video driver 1 = dummy

NumRenderDrivers = 1
driver name = software
driver flags = 9 (== 00010001 = SDL_RENDERER_SOFTWARE | SDL RENDERER_TARGETTEXTURE)
num texture formats = 8
texture max width, height = 0, 0

Buildroot downloads sdl2-2.0.8
and configures it as follows:
./configure
–target=arm-buildroot-linux-gnueabihf
–host=arm-buildroot-linux-gnueabihf
–build=i686-pc-linux-gnu
–prefix=/usr
–exec-prefix=/usr
–sysconfdir=/etc
–localstatedir=/var
–program-prefix=""
–disable-gtk-doc
–disable-gtk-doc-html
–disable-doc
–disable-docs
–disable-documentation
–with-xmlto=no
–with-fop=no
–disable-dependency-tracking
–enable-ipv6
–disable-nls
–disable-static
–enable-shared
–disable-rpath
–disable-arts
–disable-esd
–disable-dbus
–disable-pulseaudio
–disable-video-wayland
–enable-static
–disable-libudev
–enable-video-directfb
–disable-video-rpi
–disable-video-x11
–without-x

–disable-video-opengl
–disable-video-opengles
–enable-input-tslib
–disable-alsa
–enable-video-kmsdrm

You could try: CreateSoftwareRenderer to see if that helps. Might want to set https://wiki.libsdl.org/SDL_HINT_FRAMEBUFFER_ACCELERATION to 0 (disabled) with SDL_SetHint before creating the window too.

You’ll probably need some other software to enable the frame buffer access as well.
How can I customize a full-screen console background (TTY)?

I tried the suggestion but unfortunately am still having difficulty - cannot even create a surface…

	SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
	SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, 0);

	globalrenderer = SDL_CreateRenderer( globalwindow, -1, 0);
	if( globalrenderer == NULL )
	{
		printf( "Renderer could not be created! SDL Error: %s\n",
				SDL_GetError() );

		globalrenderer = SDL_CreateRenderer( globalwindow, 0, 0);
		if( globalrenderer == NULL )
			printf( "Renderer STILL not working.... %s\n",
				SDL_GetError() );

		surface = SDL_GetWindowSurface(globalwindow);
		if (!surface)
			printf("surface not created %s\n", SDL_GetError() );

		globalrenderer = SDL_CreateSoftwareRenderer(surface);
		if (!globalrenderer)
			printf( "SDL Help idea didn't work %s\n", SDL_GetError() );

…and got the output…
Number of Video Drivers = 2
video driver 0 = directfb
video driver 1 = dummy

driver name = software
driver flags = 9
num texture formats = 8
texture max width, height = 0, 0

Renderer could not be created! SDL Error: Couldn’t find matching render driver
Renderer STILL not working… No hardware accelerated renderers available
surface not created No hardware accelerated renderers available
SDL Help idea didn’t work Can’t create renderer for NULL surface

Note that this exact source program (working before) that I used for the igepv2 (Beagleboard clone) and I am migrating it to the Beaglebone black.
Before I used Buildroot 2016.08 and SDL2.0.3 with the following configuration options (AFAIK)
–disable-rpath
–disable-arts
–disable-esd
–disable-dbus
–disable-pulseaudio
–disable-video-opengl
–disable-video-opengles
–disable-video-wayland
–enable-static
–disable-libudev
–enable-video-directfb
SDL2_CONF_ENV = ac_cv_path_DIRECTFBCONFIG=$(STAGING_DIR)/usr/bin/directfb-config
–disable-video-x11 --without-x
–enable-input-tslib
–disable-alsa

Directfb works fine on it own without SDL2 so it has to be in the SDL2-Directfb connection. I am not sure what other software I need to connect Directfb to SDL2?

In summary, I figure the problem must be:
SDL2 changed (SDL2.0.3 -> SDL2.0.8) and now doesn’t work
OR
Buildroot changed (2016.08.1 -> 2018.02.3) options for compiling SDL2 and now doesn’t work
OR
there is something else I am missing.

That kind of implies that the window creation above is not working since it’s returning NULL. Could you please try using: SDL_CreateWindowAndRenderer instead to see if that fails as well?

I added the suggested code and now get a segmentation fault somewhere in SDL2. I do not have SDL2 compiled with -g so I cannot see exactly where it happened.

(gdb) run
Starting program: /root/hikingGPS/bin/oz2imageARM
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/libthread_db.so.1”.
Number of Video Drivers = 2
video driver 0 = directfb
video driver 1 = dummy
…some directfb1.7.7 output…
Current Video Driver = directfb
… some directfb output…
Thread 1 “oz2imageARM” received signal SIGSEGV, Segmentation fault.
0xb6e76e40 in ?? () from /usr/lib/libSDL2-2.0.so.0
(gdb) trace
Tracepoint 1 at 0xb6e76e40
(gdb) backtrace
#0 0xb6e76e40 in ?? () from /usr/lib/libSDL2-2.0.so.0
#1 0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

This is the source code…

/* GLOBAL VARIABLES FOR WINDOW /
SDL_Window
globalwindow; //Display window we’ll be rendering to
SDL_Renderer* globalrenderer; //The window renderer
SDL_Texture* globaltexture; //texture for display window
SDL_Surface *surface; //FIXME deleteme for debugging only

int initSDL2()
{
int success = TRUE;

/* informational debugging variables */
SDL_RendererInfo info;
int r, i;

/* print machine video driver information */
r = SDL_GetNumVideoDrivers();
printf("Number of Video Drivers = %d\n", r);
i=0;
while(i < r)
{
	printf(" video driver %d = %s\n", i, SDL_GetVideoDriver(i) ); 
	i++;
}

/* debug SDL2 with messages to stderr */
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);



//Initialize SDL2 - video only
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
	printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
	success = FALSE;
}
else
	printf("Current Video Driver = %s\n", SDL_GetCurrentVideoDriver()  ); 
	r = SDL_CreateWindowAndRenderer( 500, 500, 0,
		globalwindow, globalrenderer);
	if( r < 0 )
		printf( "failed window & renderer %s\n", SDL_GetError() );
	printf("window, renderer pointers = %x, %x\n", 
		globalwindow, globalrenderer);

Ooooops - my apologies - I forgot the & causing the seg fault.

The correct output of SDL_CreateWindowAndRenderer is
(*) FBDev/Mode: Switched to 1280x1024 (virtual 1280x1024) at 16 bit (RGB16), pitch 2560
(!) DirectFB/FBDev: Could not set gamma ramp --> Invalid argument
failed window & renderer Couldn’t find matching render driver
window, renderer pointers = 45878, 0
NumRenderDrivers = 1
driver name = software
driver flags = 9
num texture formats = 8
texture max width, height = 0, 0

so it still can create the window but not the renderer.

Hmmm, could you try using a pre-compiled binary, or building without Buildroot to see if it’s an issue with your setup?

Yes - I will try building from scratch without buildroot. Thanks for responding and helping.

1 Like

I loaded up SDL2 with gdb and have concluded that SDL2 does NOT work with directfb or with Buildroot as they currently stand. I will try to post this same note as a bug in SDL2 bugzilla.

SDL2-2.0.8 with Directfb requires hardware accelerator to work?

The example code in SDL2 wiki “SDL_GetWindowSurface”

https://wiki.libsdl.org/SDL_GetWindowSurface

doesn’t work with directfb unless there is a hardware accelerator AFAIK.

The source code (SDL2/src/video/SDL_video.c) call stack shown below shows why:

#1 SDL_GetWindowSurface
#2 SDL_CreateWindowFramebuffer
#3 _this->CreateWindowFramebuffer == SDL_CreateWindowTexture for directFB
#3 SDL_CreateWindowTexture

which executes the following code (SDL_video.c)
if (!renderer) {
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (SDL_strcmp(info.name, “software”) != 0) {
renderer = SDL_CreateRenderer(window, i, 0);
if (renderer) {
break;
}
}
}
}
if (!renderer) {
return SDL_SetError(“No hardware accelerated renderers available”);

    /* Create the data after we successfully create the renderer (bug #1116) */

SDL_CreateRenderer() which calls SW_CreateRenderer() for “software” also does not work because SDL_GetWindowSurface gets called in the process.

I am quite sure this all used to work in earlier versions of SDL2. Also Buildroot creates SDL2 with directfb used to work and no longer does (which is why I am writing this note). Hence I am assuming this is a bug. Not sure if bug #1116 commented in the source code is related or not.

Peter Thompson