简体   繁体   中英

C + Linux: How to takeover the framebuffer

I have an OpenGL application that renders directly to the framebuffer.

If I start the application from the terminal, at times I will see a glimpse of the cursor flashing behind my application. Likewise, if I start it from inside a terminal emulator in X, I get glimpses of the mouse moving behind if I move the mouse around.

My application currently renders at 45fps so low frame rate shouldn't be the issue.

I notice when X starts it seems to clear the shell before starting to render but then when you close X server later on, the diagnostic stuff that was being sent to stdout comes back so I doubt it's issuing a clear command.

How is what I want to do accomplished? Can you simply render to fb1 and tell the video output to display from fb1 and not fight over fb0? Then when your application dies you can return the display to fb0?

EDIT:

For clarification, the app is being developed for an embedded system on an ARM SoC (Freescale i.MX6) with the Vivante GPU and running on ArchLinux ARM.

I have an OpenGL application that renders directly to the framebuffer.

Just for clarification: You're doing this using KMS + DRI/DRM + GBM right?

If I start the application from the shell, at times I will see a glimpse of the cursor flashing behind my application.

You're mixing up a few terms here. A shell is the program that provides you with a command like, job control, stdio redirection, scripting support and so on. What you probably are referring to is the Linux kernel virtual terminal console (Linux VT).

When starting a program that directly uses a framebuffer device, you have to put the virtual terminal your process uses into graphics mode (KDSETMODE).

Likewise, if I start it from inside a terminal emulator in X, I get glimpses of the mouse moving behind if I move the mouse around.

When in a started from a X11 environment the X11 server is the exclusive owner of the VT and graphics mode. All graphics operations must go through the X11 server. As far as systems design is concerned, any program trying to touch a fbdev it doesn't own should be shot in the face (immediately be sent a SIGSEGV). Don't do it. Period, no discussion. The X11 server owns the VT and while the VT is active the fbdev.

What you can do instead is allocate a own VT for your program, and let it use that. However you will then get graphical output only if the X11 server is not running and the console switched to the VT of your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM