Android UI Internal : GLSurfaceView

GLSurfaceView is the primary building block for 3D applications as View is for 2D applications. It is widely used not only in 3D games but also multimedia applications such as a camera to create special preview effect.

GLSurfaceView extends SurfaceView and additionally owns a render thread and a render object set by the client. The render thread keeps running , continuously or on-demand, and delegates to the render object to draw frame using OpenGL API. For both SurfaceView and GLSurfaceView, rendering is performing in a separate thread other than main thread. The difference is with SurfaceView the rendering thread is created by client while with GLSurfaceView it is created by the system. What's more, GLSurfaceView will internally handle the synchronization between main thread and rendering thread.

setRender() is the only API you must call to initialize GLSurfaceView properly. Optionally, you can call setRenderMode to indicate you want to render continousely or on-demand -  that is to render when requestRender is called. Or, you can call getHolder.setFormat, which is inherited from SurfaceView, to set the underling surface format. To synchronize the main thread and the render thread, you can call onPause/onResume and queueEvent.

Until now, things are easy to understand. However, when it comes to seven setEGLxxx APIs,  most people are confused. What is EGL? How is that related to the GLSurfaceView? Is it same thing with GL? 

We will end this article with following digram which covers the main component in GLSurfaceView and answer above questions regarding EGL in  next article.

GLSurfaceView UML

Check out other articles in Android UI Internal series