Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SurfaceView and GLSurfaceView in Android

Can anyone tell me what the basic difference is between SurfaceView and GLSurfaceView? When should I use SurfaceView, and when should I use GLSurfaceView?

I read some already answered questions on Stack Overflow, but they did not satisfy my queries.

Any help would be appreciated.

like image 518
AndroDev Avatar asked Jun 14 '12 08:06

AndroDev


People also ask

What is SurfaceView in Android?

Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

What is GLSurface?

A GLSurfaceView provides the following features: Manages a surface, which is a special piece of memory that can be composited into the Android view system. Manages an EGL display, which enables OpenGL to render into a surface. Accepts a user-provided Renderer object that does the actual rendering.

How do you pause a surface view?

If you want to 'pause' the thread, you have to use wait() and notifyAll().


2 Answers

A GLSurfaceView is a SurfaceView that you can render into with OpenGL. Choosing between them is simple:

  • If you're familiar with OpenGL and need what it provides, use a GLSurfaceView.
  • Otherwise, use a SurfaceView.

OpenGL is low-level. If you're not already familiar with it, it's an undertaking to learn. If you only need 2D drawing, SurfaceView uses the high-level, reasonably high-performance Canvas. It's very easy to work with.

Unless you have a strong reason to use a GLSurfaceView, you should use a regular SurfaceView. I would suggest that if you don't already know that you need GL, then you probably don't.

like image 70
Darshan Rivka Whittle Avatar answered Oct 18 '22 15:10

Darshan Rivka Whittle


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 camera to create special preview affect.

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.

For more, check out this and this

like image 41
pierrotlefou Avatar answered Oct 18 '22 17:10

pierrotlefou