# Problem solved: partial screen updates on Android devices

**URL:** <https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638>\
**Category:** SDL Development\
**Created:** [June 1, 2013, 9:01am UTC](https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638 "2013-06-01T09:01:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wboe](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/ed8c4c/32.png) [@wboe](https://discourse.libsdl.org/u/wboe)\
**Post date:** [June 1, 2013, 9:01am UTC](https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638/1 "2013-06-01T09:01:25Z")

</div>

Hi,

In the past I posted problems here regarding the use of SDL2 on Android tablets, in cases where the screen was not fully redrawn on each frame. In short: some tablets worked as expected, and some (e.g. the Nexus7) turned to black screen and all kinds of weird behaviour as soon as you touched it. I filed bug reports that were never solved satisfactory.

Now I created a new environment built on top of OpenGL and friends, that works for Linux and for Android. At the end it showed the same behaviour when used on Android tablets: some worked, others not. But there was one big difference: I knew what I was doing, because only OpenGL and OpenGL-ES was involved. I found that the following line of code must be inserted after a surface has been created (in my case with eglCreateWindowSurface):

Code:  
eglSurfaceAttrib(display,surface,EGL\_SWAP\_BEHAVIOR,EGL\_BUFFER\_PRESERVED);

Result: all tablets work flawlessly, also with small local screen updates!

I would be happy to file a bug report mentioning this solution, but I’m not clever enough to know where and how this should be done in the SDL2 code.

As an aside: OpenGL and friends are great, once you understand their unconventional coding model. Actually, building modern GUI components is easier then using SDL2, and probably as portable as well. Writing a complete app for Linux and for Android required only some #ifdef’s plus a small amount of glue code, and no java at all.

Regards,  
Wouter

---

<div class="post-metadata">

**Author:** ![Dimitris\_Zenios](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/f14d63/32.png) [@Dimitris\_Zenios](https://discourse.libsdl.org/u/Dimitris_Zenios)\
**Post date:** [June 1, 2013, 9:08am UTC](https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638/2 "2013-06-01T09:08:59Z")

</div>

# Somebody didn’t read SDL README.android :)================================================================================ A note regarding the use of the “dirty rectangles” rendering technique

If your app uses a variation of the “dirty rectangles” rendering technique,  
where you only update a portion of the screen on each frame, you may notice  
a  
variety of visual glitches on Android, that are not present on other  
platforms.  
This is caused by SDL’s use of EGL as the support system to handle OpenGL  
ES/ES2  
contexts, in particular the use of the eglSwapBuffers function. As stated  
in the  
documentation for the function “The contents of ancillary buffers are  
always  
undefined after calling eglSwapBuffers”.  
Setting the EGL\_SWAP\_BEHAVIOR attribute of the surface to  
EGL\_BUFFER\_PRESERVED  
is not possible for SDL as it requires EGL 1.4, available only on the API  
level  
17+, so the only workaround available on this platform is to redraw the  
entire  
screen each frame.

Reference: [http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html](http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html)

On Sat, Jun 1, 2013 at 12:01 PM, wboe \<w.boeke at upcmail.nl\> wrote:

> \*\*  
> Hi,
> 
> In the past I posted problems here regarding the use of SDL2 on Android  
> tablets, in cases where the screen was not fully redrawn on each frame. In  
> short: some tablets worked as expected, and some (e.g. the Nexus7) turned  
> to black screen and all kinds of weird behaviour as soon as you touched it.  
> I filed bug reports that were never solved satisfactory.
> 
> Now I created a new environment built on top of OpenGL and friends, that  
> works for Linux and for Android. At the end it showed the same behaviour  
> when used on Android tablets: some worked, others not. But there was one  
> big difference: I knew what I was doing, because only OpenGL and OpenGL-ES  
> was involved. I found that the following line of code must be inserted  
> after a surface has been created (in my case with eglCreateWindowSurface):
> 
> Code:
> 
> eglSurfaceAttrib(display,surface,EGL\_SWAP\_BEHAVIOR,EGL\_BUFFER\_PRESERVED);
> 
> Result: all tablets work flawlessly, also with small local screen updates!
> 
> I would be happy to file a bug report mentioning this solution, but I’m  
> not clever enough to know where and how this should be done in the SDL2  
> code.
> 
> As an aside: OpenGL and friends are great, once you understand their  
> unconventional coding model. Actually, building modern GUI components is  
> easier then using SDL2, and probably as portable as well. Writing a  
> complete app for Linux and for Android required only some #ifdef’s plus a  
> small amount of glue code, and no java at all.
> 
> Regards,  
> Wouter
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![wboe](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/ed8c4c/32.png) [@wboe](https://discourse.libsdl.org/u/wboe)\
**Post date:** [June 1, 2013, 9:35am UTC](https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638/3 "2013-06-01T09:35:03Z")

</div>

> Somebody didn’t read SDL README.android

You’re right, I confess. And indeed, I’m using api level 17.

---

<div class="post-metadata">

**Author:** ![Dimitris\_Zenios](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/f14d63/32.png) [@Dimitris\_Zenios](https://discourse.libsdl.org/u/Dimitris_Zenios)\
**Post date:** [June 1, 2013, 10:14am UTC](https://discourse.libsdl.org/t/problem-solved-partial-screen-updates-on-android-devices/19638/4 "2013-06-01T10:14:15Z")

</div>

If your final screen is hardware accelerated you might as well render the  
whole screen all the time.On Sat, Jun 1, 2013 at 12:35 PM, wboe \<w.boeke at upcmail.nl\> wrote:

> \*\*
> 
> Quote:
> 
> Somebody didn’t read SDL README.android
> 
> You’re right, I confess. And indeed, I’m using api level 17.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
