We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2247

Summary: Landscape mode in Android XperiaE
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: *don't know*Assignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: Daniel-Knobe, gabomdq
Version: HG 2.1   
Hardware: ARM   
OS: Android (All)   
Attachments: Starting the app
Starting the app, pressing home (running in background) and get into again by starting the app
Starting the app, pressing power twice (running in background), slide to unlock to go into app again
logcat good 1
logcat bad 1
logcat good 2
logcat bad 2
logcat good 3
logcat bad 3

Description Sylvain 2013-11-17 21:53:40 UTC
I open the ticket to trace the issue as reported by Daniel K. with its XperiaE.

SDL application are not working in Landscape :  only black screen appear, while the game is working underneath.
(If we turn the screen off/on, we start to see the App, but not rotated correctly).
It appears after this commit : https://hg.libsdl.org/SDL/rev/ac4ce59c40e7


I put debugging information and see no blattant error : it was the same output as a working device.
No SDL_Error Log.
I put also additionnal information.

The only difference I see is the presence of "onWindowFocusChanged()" and "handleResume()"  which occur earlier.
but it does not trigger the nativeResume.

see the log:

-----------------------------------------------------------
V/SDL     (24024): onResume()
V/SDL     (24024): nativeResume() mIsPaused=false  mIsSurfaceReady=false  mHasFocus=true
V/SDL     (24024): surfaceCreated()
V/SDL     (24024): surfaceChanged()
V/SDL     (24024): pixel format RGB_565
I/SDL/APP (24024): MyDebug Android_SetScreenResolution sent RESIZED 480 320 15151002 0x0
V/SDL     (24024): Window size:480x320
I/SDL/APP (24024): MyDebug Java_org_libsdl_app_SDLActivity_nativeInit nativeInit
I/SDL/APP (24024): MyDebug SDL_Android_Init _________
I/SDL/APP (24024): MyDebug SDL_Android_Init nativeInit : finished
I/SDL/APP (24024): MyDebug Android_VideoInit Done Video Init
V/SDL     (24024): onWindowFocusChanged(): true          ***************  earlier
V/SDL     (24024): handleResume() mIsPaused=false  mIsSurfaceReady=true  mHasFocus=true          ***************  earlier
I/SDL/APP (24024): MyDebug Android_CreateWindow start 
I/SDL/APP (24024): MyDebug Android_CreateWindow -- 0 0 480 320 
I/SDL/APP (24024): MyDebug Android_JNI_GetNativeWindow get native windows : 0x535e80a0
I/SDL/APP (24024): MyDebug Android_CreateWindow end
I/SDL/APP (24024): MyDebug GLES2_CreateRenderer
I/SDL/APP (24024): MyDebug : GLES2_CreateRenderer max_texture_width/h = 4096/4096
I/SDL/APP (24024): MyDebug : GLES2_ResetState 
I/SDL/APP (24024): MyDebug : GLES2_UpdateViewport   SDL_CurrentContext=0x5057ffd8 data->context=0x5057ffd8 current_program=0x0
I/SDL/APP (24024): MyDebug GLES2_CreateRenderer end
I/SDL/APP (24024): MyDebug : GLES2_UpdateViewport   SDL_CurrentContext=0x5057ffd8 data->context=0x5057ffd8 current_program=0x0
V/SDL     (24024): SDL audio: opening device
V/SDL     (24024): SDL audio: wanted stereo 16-bit 22.05kHz, 256 frames buffer
V/SDL     (24024): SDL audio: got stereo 16-bit 22.05kHz, 1200 frames buffer

**** expected onWindowFocusChanged(): true
**** expected handleResume() mIsPaused=false  mIsSurfaceReady=true  mHasFocus=true

I/SDL/APP (24024): MyDebug : GLES2_SetOrthographicProjection view port 480 x 320  renderer->target=0x0
I/SDL/APP (24024): MyDebug : GLES2_SetOrthographicProjection set projection matrix
I/SDL/APP (24024): MyDebug : GLES2_SetOrthographicProjection view port 480 x 320  renderer->target=0x0
I/SDL/APP (24024): MyDebug : GLES2_SetOrthographicProjection set projection matrix
------------------------------------------------------------------

Also, afer the VideoInit, there is :

I/SDL/APP (24024): MyDebug Android_VideoInit Done Video Init
D/dalvikvm(24024): GC_CONCURRENT freed 353K, 7% free 8110K/8647K, paused 20ms+27ms, total 142ms
I/Adreno200-EGL(24024): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_RB1.04.01.01.06.043_msm7627a_JB_REL_RB1.2_Merge_release_AU (Merge)
I/Adreno200-EGL(24024): Build Date: 02/07/13 Thu
I/Adreno200-EGL(24024): Local Branch: 
I/Adreno200-EGL(24024): Remote Branch: m/jb_rel_rb1.2
I/Adreno200-EGL(24024): Local Patches: NONE
I/Adreno200-EGL(24024): Reconstruct Branch: NOTHING
Comment 1 Gabriel Jacobo 2013-11-18 00:37:09 UTC
Sorry if I already asked you this, but...does testgles or testrendercopyex work as expected on this device?
Comment 2 Daniel Knobe 2013-11-18 00:50:30 UTC
No, both tests have the exactily the same behavior as the apps Sylvain and I developed.

The blackscreen occurs when I switch in landscape mode by adding a line to the manifest file / adding a line in the java file. In portrait everything works as expected.
Comment 3 Sylvain 2013-11-18 07:37:28 UTC
I also opened this one :)
https://bugzilla.libsdl.org/show_bug.cgi?id=2248

It happens sometimes in IOS !

Daniel, does it look the same as what you see in XperiaE when it came back after off/on ? (see description of cards collumns, bottom card, background).
Comment 4 Daniel Knobe 2013-11-18 09:05:37 UTC
Created attachment 1451 [details]
Starting the app
Comment 5 Daniel Knobe 2013-11-18 09:07:21 UTC
Created attachment 1452 [details]
Starting the app, pressing home (running in background) and get into again by starting the app
Comment 6 Daniel Knobe 2013-11-18 09:08:25 UTC
Created attachment 1453 [details]
Starting the app, pressing power twice (running in background), slide to unlock to go into app again
Comment 7 Daniel Knobe 2013-11-18 09:10:17 UTC
It's a little bit different. Like we thought it's not a determinate problem.
On the Xperia E I get allways a blackscreen on start (see screenshot: "Starting the app").

I added screenshots, so that it's possible to make a comparison to the apple pics.
Comment 8 Sylvain 2013-11-18 09:16:36 UTC
Yes I agree this looks different.


what I see : 
- pressing home (Background-Foreground) solves the issue !


Pressing the off/on seems to only make the rendering appears:
- I believe the renderer is created with wrong size.
- but the pipeline is correctly doing the 90deg rotation !
Comment 9 Sylvain 2013-11-18 09:18:35 UTC
hum I am wrong with my last comment, please ignore it.
Comment 10 Sylvain 2013-11-18 09:21:01 UTC
Ok. could you do the same screenshot with the Spider game ?

this seems stupid but the background is blit in a different way that it reflects the internals of SDL.
Comment 11 Daniel Knobe 2013-11-18 09:26:58 UTC
Absolutly the same behavior in spider.
My games has this behavior, too.
I don't add the screens here (because they contain no new informations).
Comment 12 Sylvain 2013-11-18 09:50:43 UTC
So:

what I see : 
- pressing home (Background-Foreground) solves the issue !


Pressing the off/on seems to only make the rendering appears:
- I believe the renderer is created with correct size.
I draw to size with w=480 h=320. and it fits into the renderer window.
and the backgroung (on spider) fits also. (I use rect dst == NULL).
it take the full size inside the rendered.

- the pipeline is correctly doing the 90deg rotation !
but it is also scaling the image which is wrong!
Comment 13 Gabriel Jacobo 2013-11-18 11:56:13 UTC
If the problem exists in testgles, it's fairly safe to assume the problem does not lie in the Renderer code. Can you try a bulk approach to debugging by creating a debug version with SDL_Log statements across the SDL_egl.c and all the JAVA side functions? Maybe that will shed some light as to what's going on without access to the device.

Another question, are you changing the min or target SDK level? Do you see other apps having the same problem?

Could this be related? https://bugzilla.libsdl.org/show_bug.cgi?id=1849
Comment 14 Sylvain 2013-11-18 20:47:40 UTC
here's two logcats

logcat_good_1.txt 
logcat_bad_1.txt

for the behavier on a working phone, and the one of Daniel.

* I screw-up the log of renderer.viewport{x/y/w/h}  h is always y for both log
* Maybe I miss some java function ?
* I put logs wherever I could ...
* trace the sendWindowEvent stuff

So far, the diff says :
- difference in depth_size and in ES_BIT
- onWindowFocusChanged is sent earlier

In my app.. for historical raison, dont know if it have any effect.
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);

I will remove that in the next log I guess.

And the manifest xml:
 <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
 <uses-feature android:glEsVersion="0x00020000" />
Comment 15 Sylvain 2013-11-18 20:48:42 UTC
Created attachment 1454 [details]
logcat good 1
Comment 16 Sylvain 2013-11-18 20:48:58 UTC
Created attachment 1455 [details]
logcat bad 1
Comment 17 Sylvain 2013-11-19 08:27:17 UTC
 I mess-up the logcat. wait again for new logcat please.
Comment 19 Daniel Knobe 2013-11-19 12:29:21 UTC
Thanks for this idea, but this doesn't help. 
Changing the glViewport on HTC does change the output like it should. On the Xperia E the blackscreen stays black.
Comment 20 Gabriel Jacobo 2013-11-19 14:05:41 UTC
I brought back a handy feature of the Java code here: https://hg.libsdl.org/SDL/rev/ba26f042e36d

It's unlikely that it is related to what you are seeing, but we are just poking in the dark anyway, so you may as well give it a try.
Comment 21 Sylvain 2013-11-19 19:55:37 UTC
Created attachment 1457 [details]
logcat good 2
Comment 22 Sylvain 2013-11-19 19:56:36 UTC
Created attachment 1458 [details]
logcat bad 2
Comment 23 Sylvain 2013-11-19 20:07:10 UTC
Good catch about the eglChoose mecanism ! but it doesnt solve the issue !

Also, remember going to background and then foreground is solving the problem, 
so the configuration remains the same ?

Here the logcat of a full scenario. 

we just do : 
start
- wait (the eglSwapBuffers)
- go to Background
- go to Foreground
- wait (the eglSwapBuffers)


"Logcat good 2 and background foregound" is with my device
and "bad" is with the XperiaE of Daniel.

There almost no difference

But we can notice during the resuming, the behavior is a little bit different :
"android_egl_context_restore" appears between "there1" and "there2". 

so the function with the logging :

 324 /* Resume */
 325 void Java_org_libsdl_app_SDLActivity_nativeResume(
 326                                     JNIEnv* env, jclass cls)
 327 {
 328     __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
 329     SDL_Log("MyDebug : %s Android_Window=%p", __func__, Android_Window);
 330 
 331     SDL_Log("MyDebug : %s WILL ENTER FOREGROUND", __func__);
 332     SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
 333     SDL_Log("MyDebug : %s WILL DID FOREGROUND", __func__);
 334     SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
 335 
 336 
 337     if (Android_Window) {
 338         /* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
 339          * We can't restore the GL Context here because it needs to be done on the SDL main thread
 340          * and this function will be called from the Java thread instead.
 341          */
 342         SDL_Log("MyDebug : %s there1", __func__);
 343         if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
 344         SDL_Log("MyDebug : %s there2", __func__);
 345         SDL_Log("MyDebug : %s FOCUS_GAINED", __func__);
 346         SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
 347         SDL_Log("MyDebug : %s RESTORED", __func__);
 348         SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
 349     }
 350 }


hope this helps
Comment 24 Gabriel Jacobo 2013-11-19 20:12:31 UTC
Given there's two threads at work here, it may be more helpful to run:

   adb logcat -v threadtime 

So it's easier to identify which lines come from which thread (and will probably help identify if there's some hidden timing problem)
Comment 25 Sylvain 2013-11-19 20:56:56 UTC
Created attachment 1459 [details]
logcat good 3
Comment 26 Sylvain 2013-11-19 20:57:23 UTC
Created attachment 1460 [details]
logcat bad 3
Comment 27 Sylvain 2013-11-19 20:58:11 UTC
here it is. with the -v theadtime setting
Comment 28 Daniel Knobe 2013-11-20 08:24:06 UTC
I have additional informations. May be this helps to get this bug fixed.
I played arround with some options and found that if I enable in the developer options: Force GPU-Rendering (Use 2D-Hardwareaccelation in Apps) everthing works nice!

All use cases (see pics) works without a problem with this option on!
Comment 29 Sylvain 2013-11-20 09:44:58 UTC
maybe this could help : http://developer.android.com/guide/topics/graphics/hardware-accel.html
Comment 30 Daniel Knobe 2013-11-20 11:55:53 UTC
Yes this fixes the problem :), so Gabriel should we add the line in the manifest of the android-project example of SDL?
Comment 31 Gabriel Jacobo 2013-11-20 12:07:10 UTC
Not a bad workaround at all...I do wonder if this has any side effects, specially on API level 10 devices.
Comment 32 Daniel Knobe 2013-11-20 12:12:04 UTC
I have no Android 2.x device here, so I can't test it :-/.
Comment 33 Sylvain 2013-11-20 13:00:09 UTC
Just wondering, it seems there are severals workaround possible, from the url:

Application level
Activity level
Window level
View level

Which one should be used ?

Also. How comes this bug did not appear with the common egl ? Maybe HW acceleration was already activated when creating : khronos.egl objets ?  
If so, would it be possible that khronos were using implicitly the "windows/view" level solution. ?
Comment 34 Daniel Knobe 2013-11-21 16:06:28 UTC
It works on all levels, this are the options:
<application android:hardwareAccelerated="true" ...>
or
<activity android:hardwareAccelerated="true" />
or
getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
in the onCreate() method.
Comment 35 Gabriel Jacobo 2013-11-22 13:27:16 UTC
Ok, fixed here: https://hg.libsdl.org/SDL/rev/1e390ba95c43

Thanks!