Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?
like image 208
fadden Avatar asked May 01 '14 19:05

fadden


People also ask

What is a surface in Android?

A Surface is generally created by or from a consumer of image buffers (such as a SurfaceTexture , MediaRecorder , or Allocation ), and is handed to some kind of producer (such as OpenGL , MediaPlayer , or CameraDevice ) to draw into. Note: A Surface acts like a weak reference to the consumer it is associated with.

What is canvas and surface view?

Canvas has its own Bitmap attached to it. Surface has its own Canvas attached to it. All View 's of window share the same Surface and thus share the same Canvas . SurfaceView is subclass of View , which, unlike other View 's subclasses and View itself, has its own Surface to draw in.

What is Surface holder?

android.view.SurfaceHolder. Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available through the SurfaceView class.


1 Answers

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.)

like image 137
fadden Avatar answered Oct 15 '22 00:10

fadden