Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw using framebuffer on Android?

I would like to write an application for Android which displays stuff on screen using the framebuffer. This will run only on a specific rooted device, so permissions etc is not a problem. Same application (simple test version anyway) is already running okay on PC/Linux.

The questions:

  1. How to avoid the Android OS from accessing the framebuffer? I would like, while my application is running, to have the OS never touch the framebuffer, no writes and no ioctls. What do I need to do to get exclusive use of the framebuffer, and then (when my application quits) give it back to the OS?

  2. Are there any differences between Android framebuffer and Linux framebuffer to watch out for?

P.S. I would like to start my application as a regular Android application (with some native code), it just has no visible UI except for framebuffer draws which take over the whole screen. It would be nice to still be able to get events from the OS.

See also: http://www.kandroid.org/online-pdk/guide/display_drivers.html

like image 790
Alex I Avatar asked Jan 25 '14 09:01

Alex I


1 Answers

Hi Alex Not sure why / how to stop android OS from writing to framebuffer. As long as your android application is visible and on top you have the control as what you want to display.

Your application should have an activity with a SurfaceView ( you may want your application to hide notification bar call this function in oncreate of your activity) requestWindowFeature(Window.FEATURE_NO_TITLE); )

your activity should have SurfaceHolder.Callback implementation to handle callbacks as when the surface is ready to filled with framebuffer. Get the surface holder object as SurfaceView.getHolder() incase you want set pixel formats of the view etc.

Once "surfaceCreated" callback is called you can safely pass your surfaceview object(passing width and height maybe a good idea too) to the native so that you can fill it framebuffer using "ANativeWindow" class.

Check NDK sample code to see how to use the class NDK documentation

SurfaceHolder.Callback documentation

SurfaceHolder documentation

essentially you need to these (ON JB /Kitkat)

  1. get the native window (ANativeWindow) associated with the surfaceview by ANativeWindow_fromSurface.

  2. Acquire a lock on the ANativeWindow by ANativeWindow_acquire .

  3. Set geometry parameters(window,width,height,pf) for the nativewindow by ANativeWindow_setBuffersGeometry

  4. Load the nativewindow with the frambuffer stored (apply dirty rectangle if any here) by ANativeWindow_lock

  5. Final step to unlock and post the changes for rendering by ANativeWindow_unlockAndPost

Go through the ndk sample examples in case you need sample code.NDK documentation

like image 195
amIT Avatar answered Nov 02 '22 08:11

amIT