How Android finds OpenGL libraries, and the death of egl.cfg

Everybody who works on Android platform development knows that the vendor OpenGL libraries are located using information in egl.cfg. As of Android Kit Kat 4.4, they are out of date. Read on to find out why.

The OpenGL libraries

Android uses OpenGL ES to process 3D graphical functions and EGL to map them to a physical display. OpenGL ES is implemented in

/system/lib/libGLESv1_CM.so
/system/lib/libGLESv2.so
/system/lib/libGLESv3.so

The last one is optional, since Jelly Bean 4.3, and is for devices that support OpenGL ES 3.0. If it exists, it is a symlink to /system/lib/libGLESv2.so

EGL is implemented in

/system/lib/libEGL.so

These are just shim libraries. They call down to vendor supplied libraries that use the platform GPU do the real work. The library loader code is in frameworks/native/opengl/libs/EGL/Loader.cpp

Hardware accelerated graphics is a requirement for Android devices (since ICS 4.0).

Locating the vendor OpenGL libraries - past

Begin by looking at /system/lib/egl/egl.cfg, which contains something like this (from a Nexus 5 running KK 4.4)

0 0 android
0 1 adreno

The first number is the display ID, which is always 0: Android only supports OpenGL on the primary display. The second number is the implementation number. The OpenGL library loader tries the one with the highest number first and falls back to lower ones until it either succeeds or fails altogether. The text part is called the tag and is used to construct the name of the library. So in the case that the tag is “adreno” the libraries are

libEGL_adreno.so
libGLESv1_CM_adreno.so
libGLESv2_adreno.so

All three can be combined into a single library named libGLES_adreno.so. They are located in either /vendor/lib/egl or /system/lib/egl.

The idea of the line with the tag “android” is if the adreno libraries are not present the default OpenGL library, libGLES_android.so, will be loaded. This is a software OpenGL renderer also known as “Pixel Flinger”

At least, all the above is the theory: in fact neither the display ID nor the implementation numbers have been checked since JB 4.1: any old thing would do. And the tag “android” is assumed so the fallback to android is automatic. So the egl.cfg could (and should) have been written as

0 0 adreno

Locating the vendor OpenGL libraries – present

Now, in Kit Kat 4.4, the OpenGL loader code has been cleaned up a bit. It no longer reads egl.cfg. I repeat, egl.cfg is redundant and should no longer be placed in /system/lib/egl. So, that file you find on a Nexus 5 running Kit Kat 4.4: just delete it.

The new rules for loading the libraries are

1. Try to load files named
libGLES.so, or:
libEGL.so, libGLESv1_CM.so, libGLESv2.so
from /vendor/lib/egl or /system/lib/egl

2. For compatibility with the old naming scheme, also try to load files named
libGLES_*.so, or:
libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
from /vendor/lib/egl or /system/lib/egl

The android “Pixel Flinger” fallback is gone altogether unless running in the emulator (system property ro.kernel.qemu = 1), in which case android is assumed.

Conclusion

This makes life simpler, and means that people working at the platform level can find the libraries a little more easily. It also means that a lot of readmes and howtos are out of date...

Want to know more about Android?

I have two training courses that will help you:
Android porting: http://www.2net.co.uk/training/android-porting
Android Internals: http://2net.co.uk/training/android-internals

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

a simple "egl.cfg" theory hack..

So, some people are trying to hack this conf file -- egl.cfg -- to not use CPU and force the graphics instead..
I have a Sony E1 (2015) using KIT KAT 4.4.2. What can I do to force my adreno graphics and if I should it??

the source page: http://forum.xda-developers.com/showthread.php?t=1877183&page=39 -- There's no solution just theory instead and sorry 39 pages!

Thanks anyway!

Since you are using KitKat,

Since you are using KitKat, the egl.cfg is not used, as described above. So making changes to it will not make any difference. Even with pre KitKit, that whole XDA thread is based on the misunderstanding the line that reads "0 0 Android" in old egl.cfg files was forcing the device use a software implementation of OpenGL (one called PixelFlinger) rather than the GPU, and so making the graphics sluggish and using more battery power. That never happened. The only reason "0 0 Android" was there is as a fallback in case the GPU drivers could not load. Conclusion: you can totally ignore that thread on XDA, it will not help you :-)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Youtube and Vimeo video links are automatically converted into embedded videos.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.