Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should we use LAYER_TYPE_HARDWARE

After reading on http://developer.android.com/guide/topics/graphics/hardware-accel.html , my understanding on 3 different type of layering techniques are (Assume the device has GPU)

  • LAYER_TYPE_SOFTWARE - Draw is performed by software on software's off-screen bitmap memory. Software's off-screen bitmap will then transferred to GPU. GPU render the bitmap on screen.
  • LAYER_TYPE_NONE - GPU will draw directly on screen.
  • LAYER_TYPE_HARDWARE - Draw is performed by GPU on GPU's off-screen bitmap memory. GPU's off-screen bitmap will then render to screen by GPU.

When to use LAYER_TYPE_SOFTWARE

My understanding certain draw operation isn't supported by GPU like setShadowLayer. Hence, we need to switch to LAYER_TYPE_SOFTWARE, so that draw will be performed by software.

However, since there's software's off-screen bitmap memory transferred to GPU operation, things may appear slower.

When to use LAYER_TYPE_NONE

I think this is the default settings in most of the devices. So, I assume we should use this technique most of the time.

When to use LAYER_TYPE_HARDWARE

I have no idea when to use this technique. Any example will be very much appreciated, on when we should apply LAYER_TYPE_HARDWARE technique.

p/s Also, my understanding on LAYER_TYPE_... may appear wrong. Kindly correct me, if you find any mistake. Thank you.

like image 962
Cheok Yan Cheng Avatar asked Nov 26 '14 13:11

Cheok Yan Cheng


1 Answers

Basically its like a drawing cache. if your custom view is expensive to render/draw but the content doesn't change too much often then i'd use the flag. otherwise your just stressing out the device to cache for no reason.

like image 67
j2emanue Avatar answered Oct 23 '22 13:10

j2emanue