Monday, February 9, 2015

Difference Between Android SurfaceView and regular View

The main difference between SurfaceView and regular View is that SurfaceView can be updated by a background thread. 


- A surfaceView has dedicate surface buffer while all the view share one surface buffer that is allocated by ViewRoot. In another word, surfaceView cost more resources. 

- surfaceView can not be hardware accelerated as of (JB4.2) while 95% operations on normal View are HW accelerated using openGL ES. 

- More work should be done to create your customised surfaceView. You need to listen to the surfaceCreated/Destroy event, create a render thread, more importantly, synchronize the render thread and the main thread. However to customise the view, all we need to do is override onDraw method. 

- The timing to update is different. Normal view update mechanism is constraint or controlled by the framework: Application call view.invalidate in the UI thread or view.postInvalid in other thread to indicate to the framework that the view should be updated. However the view won’t be updated immediately but wait until next VSYNC event arrived. The easy approach to understand VSYNC to achieve better smoothness. Now, back to the surfaceView, you can render it anytime as we wish. However, i can hardly tell if it is an advantage, since the display is also synchronised with VSNC, as started previously. 

- SurfaceView may take more resources. 

References:

No comments:

Post a Comment