Skip to main content

Android UI Internal : EGL

EGL is a hard topic to tackle. I didn't find any good toturial that explained it well. After reading its wiki page, I ended up having more questions such as what is windowing system, what is surface binding and more.
EGL is an interface rendering APIs (such as OpenGL, OpenGL ES or OpenVG) and the underlying native platform windowing system. EGL handles graphics context management, surface/buffer binding, rendering synchronization
Nevertheless, I don't think I can do any better in explaining what EGL is a less than 100 pages as the EGL spec does. Instead, I would like to pick a easier task and only talk about following items.
  • Why we need EGL? Isn't OpenGL enough? 
In short, it is for separation of concerns. 
OpenGL is responsible for drawing while EGL is responsible for the others - context management, surface binding and rendering synchronization. Read EGL spec for details. But for now just remember we always need to use EGL with OpenGL. The next item explains how they cooperate.
  •  How EGL is typically used with OpenGL?
To draw a frame, below is the typical calling sequence, which can be simplified as setupWithEGL, drawWithOpenGL, tearDownWithEGL.


To echo the EGL responsilibity described in item 1 or in quoted Wiki page , here is the mapping from API to its functionality. 

eglGetConfig/eglChooseConfig                       - configuration management 
eglCreateWIndowSurface/eglDestorySurface  - surface binding
eglCreateContext/eglMakeCurrent                   - context management 
eglSwapBuffer                                                 -  buffer managment 

For detail explanation of each API, please refer to EGL spec or  this ref card 
  •  EGL and GLSurfaceView 
"But I did not use EGL in my 3D application with GLSurfaceView." You questioned. That is because GLSurfaceView did it for you, with EglHelper.

In article GLSurfaceView, I raised the question of what are the APIs SetEGLxxx for.  Now, I think you have the answer. 

GLSurfaceView and EGL
Besides GLSurfaceView, SurfaceFlinger and HWUI module also use EGL. One for UI composition and one for View drawing.
  •  EGL and native window system
EGL also aims to hide the native window system of the operation system. In Android, the native window is of type  - ANativeWindow - which does not tell too much by it name.  We will talk about it later since it is a very important concept for framework developer and NDK developer.

Check out other articles in Android UI Internal series 

Popular posts from this blog

Android Camera2 API Explained

Compared with the old camera API, the Camera2 API introduced in the L is a lot more complex: more than ten classes are involved, calls (almost always) are asynchronized, plus lots of capture controls and meta data that you feel confused about.

No worries. Let me help you out. Whenever facing a complex system need a little bit effort to understand, I usually turns to the UML class diagram to capture the big picture.

So, here is the class diagram for Camera2 API.

You are encouraged to read this Android document first and then come back to this article, with your questions. I'll expand what is said there, and list the typical steps of using camera2 API. 

1. Start from CameraManager. We use it to iterate all the cameras that are available in the system, each with a designated cameraId. Using the cameraId, we can get the properties of the specified camera device. Those properties are represented by class CameraCharacteristics. Things like "is it front or back camera", "outpu…

Java Collections Framework Cheat Sheet

Java Collections Framework (JCF) implements the Abstract Data Type  for Java platform. Every serious Java programmer should familiar himself on this topic and be able to choose the right class for specific need.  A thorough introduction to JCF is not the target of this small article and to achieve that goal you can start with this excellent tutorial . 

Instead, I'd like to
1) Provide an overview of JCF's classes ,   2) Provide a cheat sheet you can post in your cubicel for daily reference, 3) Underline the relationship between JCF's implementation and the data structure and algorithm you learned in your undergraduate course

With these goals in mind, I came up following diagram - Java Collection Cheat Sheet. You can click it to zoom in. There is no necessity for more explanation once your familiar with UML class diagram and have a basic understanding of common data structures.

Android Security: An Overview Of Application Sandbox

The Problem: Define a policy to control how various clients can access different resources. A solution: Each resource has an owner and belongs to a group.Each client has an owner but can belongs to multiple groups.Each resource has a mode stating the access permissions allowed for its owner, group members and others, respectively. In the context of operating system, or Linux specifically, the resources can be files, sockets, etc; the clients are actually processes; and we have three access permissions:read, write and execute.