Skip to main content

Android UI Internal : EGL

EGL is a hard topic to tackle. I didn't find any good tutorial 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 an 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

Understand Container - Index Page

This is an index page to a series of 8 articles on container implementation. OCI Specification Linux Namespaces Linux Cgroup Linux Capability Mount and Jail User and Root Network and Hook Network and CNI
This page has a very good page view after being created. Then I was thinking if anyone would be interested in a more polished, extended, and easier to read version.
So I started a book called "understand container". Let me know if you will be interested in the work by subscribing here and I'll send the first draft version which will include all the 8 articles here. The free subscription will end at 31th, Oct, 2018.

* Remember to click "Share email with author (optional)", so that I can send the book to your email directly. 


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.

Understand Container: OCI Specification

OCI is the industry collaborated effort to define an open containers specifications regarding container format and runtime - that is the official tone and is true. The history of how it comes to where it stands today from the initial disagreement is a very interesting story or case study regarding open source business model and competition.

But past is past, nowadays, OCI is non-argumentable THE container standard, IMO, as we'll see later in the article it is adopted by most of the mainstream container implementation, including docker, and container orchestration system, such as kubernetes, Plus, it is particularly helpful to anyone trying to understand how the containers works internally. Open source code are awesome but it is double awesome with high quality documentation!