FrameBuffer texture breaks after changing device language - android

I am happily using libgdx for an android game application.
At a specific point in the game, I use a FrameBuffer object to render the screen onto, and then use its attached color texture for rendering that to the screen (to be able to render a half-transparent screen with full-color rectangular zones).
The documentation for FrameBuffer says:
FrameBuffers are managed. In case of an OpenGL context loss, which only happens on Android when a user switches to another application or receives an incoming call, the framebuffer will be automatically recreated.
And that works perfectly, I can switch to other applications, put the device in sleep mode, go back to the application and everything including the framebuffer is working as usual.
The problem begins when I try and change the device's language when the application is running (using the android settings menu).
After I change the language to something else, the framebuffer attached texture becomes completely black (either the rendering to it fails or its rendering to the screen does).
The incredible thing is that, even if I restart the application (i.e. the application reaches its onDestroy() method and exits), the problem does NOT go away, and it does only when I kill the application process from the task manager.
I probably could solve this by adding a System.exit(0) inside the onDestroy() method, but does anyone have an idea about what exactly happens when I change the device language?
I cannot think of any possible relation between that and the framebuffer object state (the other textures are working as usual!), if anyone could enlight me it would be greatly appreciated.

Related

Activity Methods don't work when App is unfocused

I'm running into an issue and I would appreciate some guidance. I'm writing a small Android program in Android Studio that uses MediaProjection to grab a screenshot of the whole screen and then I want to pass that screenshot as a Bitmap to my System Overlay (based on the chatheads example). When the MediaProjection runs and the Imagereader creates the bitmaps, I'm passing the bitmap into a class global variable so I can pass it into my System Overlay service and display it. The problem I'm running into is if I "tab out" to a different app, my methods stop working from the MainActivity. When my app is in focus, everything works well, when a different app is focused, the system overlay contracts and expands like it should, but the screenshots are not being taken anymore. My understand is its because my app becomes "asleep" since it's not in focus. Could anyone recommend a solution? Can I momentarily awake my mainActivity so it can take a screenshot? Can I keep my activity from falling asleep on app switch? Can I bring focus to my app, take the screenshot and then switch focus to the previous app? Any other ways?
My code can be found here: https://github.com/asheron21/FacebookLikeChathead
MainActivity:https://github.com/asheron21/FacebookLikeChathead/blob/master/app/src/main/java/com/example/chatheads/MainActivity.java
Service: https://github.com/asheron21/FacebookLikeChathead/blob/master/app/src/main/java/com/example/chatheads/ChatHeadService.java
Global Variables:https://github.com/asheron21/FacebookLikeChathead/blob/master/app/src/main/java/com/example/chatheads/Globals.java
Thanks!

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:
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?
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
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)
get the native window (ANativeWindow) associated with the surfaceview by ANativeWindow_fromSurface.
Acquire a lock on the ANativeWindow by ANativeWindow_acquire .
Set geometry parameters(window,width,height,pf) for the nativewindow by ANativeWindow_setBuffersGeometry
Load the nativewindow with the frambuffer stored (apply dirty rectangle if any here)
by ANativeWindow_lock
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

Is it possible to process the video (preview) stream without displaying it on the screen in android?

I have doing a basic object detection on the camera preview screen in Android (greater than 3.2). For the devices which do not support processing on preview screen, I am buffering the preview screen, processing it and clearing the buffer. This part is working as desired.
What I now want is this app to run in the background while any other app is running in the foreground. I am using android service and am able to run a small test app in the background. However my concern is with the camera preview app.
I don't want to display the preview screen but use the preview screen information for processing. This might be too much to ask, but I wanted to know if this is even possible. I came across this link which shows some hope. Basically I want to process the video (preview) stream without displaying it on the screen. If this is doable, then I can think of putting this app in the background and some other app in the foreground.
Unfortunately I won't be able to share the code, however it is the standard logic of creating a surface view and starting the preview.
I would really appreciate any insight into this.
Check comments here.Basically he opens camera hardware, set preview callback and do startpreview without setting the previewDisplay (this might not work on every device). You can try this from your background service. All this will work if your foreground doesn't access the camera app. Please update this if it works. I am interested to know.

Blank screen onResume() after gl Context destruction, Android

For our game on Android OS we have been using the ndk mainly, to write our game and a thin Java wrapper so than we can support all devices with gles 2.0 hardware.
Our implementation is pretty standard, using the overrides of GLSurfaceView we:
* create/resume the c++ part of the game onSurfaceChanged(),
* render onDrawFrame(),
* inform the engine about lost gl Context at destroyContex() which usually occurs when the app pauses or gets destructed.
When the gl context gets recreated (when resuming - onSurfaceChanged()) we pass back the information to the game and reload all gl resources back in. During the time between onSurfaceChanged() and the first onDrawFrame though the screen is black but I have noticed quite a few 3D games that dont have this kind of a problem (i.e Gun Bros), they also dont seem to reload their resources (unless they have everything memory and quickly load them back in).
Any info on why is this happening?
Just an idea, but if you dump the screen with glReadPixels or similar on destroyContext(), and then the first thing you do on onSurfaceChanged() is to upload that and draw, you will show the user a valid image before your first onDrawFrame.

Getting an android app to keep it's OpenGL Context after hitting the home button

First a bit of context: I'm developing a video game for both the Android and iPhone platforms. The way the iPhone works, when a user hits the home button and returns to the game later, in most circumstances the game will pick up RIGHT where it left off with no hicups. I immediately jump back into my rendering and game loop. Setting this up on the iOS platform was absolutely easy for me to do. Accomplishing this on the Android has left me in a fit of rage after hours of wrestling with google results :P
I have my own OpenGL setup for both the iPhone and Android, and everything has been working great. The root of the problem, I believe, is that I need a SurfaceHolder to create an OpenGL Context. Here's the sucky part, when the screen loses focus of the game (ie the home button was hit), Android calls surfaceDestroyed in my SurfaceView class and basically KILLS my opengl context. I could recreate a new one with a new SurfaceHolder when surfaceCreated is called, but then I need to reload all of my art assets which defeats the purpose of everything I'm trying to accomplish.
Can I somehow prevent the Android OS from killing my surface holder, is there some sort of custom view I can use to get this to work? Is there some setting in the Manifest that can help me out here (I doubt it as I have thoroughly tested most of the flags)? I know this is possible because Angry Birds does this perfectly on the Android OS.

Categories

Resources