Search code examples
androidsurfaceviewglsurfaceviewtextureviewsurfaceflinger

How do I use Android’s “Surface” classes?


Is there a detailed explanation of Surface, SurfaceHolder, EGLSurface, SurfaceView, GLSurfaceView, SurfaceTexture, and TextureView?  In particular:

  • What’s the difference between SurfaceView and TextureView?
  • Do I need to use GLSurfaceView to use OpenGL ES?
  • How do Surface and EGLSurface interact?
  • What does SurfaceTexture do?
  • Why does the stuff I draw on a SurfaceView have to go above or below everything else?
  • What is SurfaceFlinger?
  • How does composition of the status and navigation bars work?
  • While we’re at it, what’s the right way to structure a game loop on Android?

Solution

  • The answers to these and many other questions can now be found on the Android Open Source Project web site:

    Android System-Level Graphics

    The document begins with an explanation of the low-level infrastructure, and then explains how the higher-level features are built from them. The goal is not to provide direct answers to common questions, but rather to describe the system at a level of detail that makes the answers apparent without being overwhelming.

    The choice of material and level of detail were heavy influenced by Q&A on stackoverflow.

    (Technically this is a link-only answer, but writing 10,000 words here seemed like a bad idea.)