[SDL] again with doubts on Xlib

Ulrich Eckhardt doomster at knuut.de
Wed May 23 10:08:47 PDT 2007


On Wednesday 23 May 2007 09:24:02 Pavan Krishnamurthy wrote:
> My requirement is to port a library mainly used for gaming over a embedded
> linux platform, which has X11, SDL, directfb support. After going through
> many docs on X11, directfb, SDL I am again in confused state. Sorry for
> being stupid.
>
> My first doubt: Is Xserver running in user space?

Yes.

> if so can it map the video memory in it address space?

Yes, Linux drivers can support mmaping. However, much more important and 
tricky are the registers that control the video adapter. Normally, access to 
those would be exclusive to the kernel, but unfortunately it isn't in 
reality. I'd take a look at http://kerneltrap.org/node/8242 and 
http://www.kgi-project.org/, maybe that clears up some confusion. The first 
rather describes the current state while the second rather describes the way 
it should be.

> If not, how does it copy the video data to video memory?

There is still the framebuffer interface, which is an alternate way of using 
X, but I think that interface also at least partially relies on memory 
mapping.

> which driver is used by the Xserver to access the video memory?

X.org has builtin drivers for quite some video adapters. Otherwise, it can 
also use the Linux framebuffer driver.

> In normal X application, the video data is copied twice: 
>   1. From application to Xserver memory.
>   2. Xserver to video memory. Am I correct here?

I'm not sure, and it probably also depends on the way X is accessing the video 
adapter. Possibly, you would have to copy it a third time if your X server 
isn't allowed to access the video memory directly.


> DirectFB claims its a library which gives direct access to video memory
> with hardware acceleration, using the linux framebuffer driver. There is
> also a X server (XdirectFb) based on Directfb library, which avoids the X
> application's data to go through some IPCs like sockets or SHM. Instead it
> gives the application to map the video memory in its address space, and
> thus directly allow it to manipulate the screen. Thereby it claims, it
> avoids the context switch between the application and Xserver processes.
>
> Also there is a X extension called DGA ( another one DRI) which claims it
> gives direct access to video memory for the X applications. In what way is
> it different to Directfb? which driver is it using to give the direct video
> memory access. Is the video memory mapped to user space in this setup just
> like the directfb?

If and how all this works also depends on the system. If all you have is a 
framebuffer, i.e. if you don't have a GPU that can do blitting or even 
rendering for you, there is pretty little to accelerate.

> In the SHM enabled X server, the applications data doesnt go through the
> network layer, instead the data is shared between the application and the
> Xserver through shared memory. Is it possible to get direct access to video
> memory here. Can the video memory be shared to application in this setup?

Again, it depends on whether X has access. Without it, there's no way for it 
to grant access. However, generally it doesn't and shouldn't give away video 
memory to applications, because the whole idea behind that is to go through 
the X protocol in order to be a) network transparent and b) portable and 
hardware-independent. Further, I think it can be used asynchronously.

Two more points: SDL works as a layer on top of X11 or directfb. If you use 
SDL, you can decide at runtime which driver to use. If X11 doesn't work well 
enough, you can switch to a different VT and use the framebuffer driver 
there.

Then, asking questions about the internals of X (which implementation, btw, 
X.org? XFree86? Exceed?) here is rather off-topic. I'd try on the Usenet or 
maybe a dedicated X mailinglist instead.

Uli






More information about the SDL mailing list