Issue
I was going through the Android documentation, regarding deprecated drawing cache API's.We have extensive use of drawing cache APIs in our codebase. We are using it for snapshot of bitmaps and Views.
https://developer.android.com/reference/android/view/View#setDrawingCacheEnabled(boolean).
My doubts are mainly focused on points mentioned in the doc.
Doc says : "For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to use Canvas approach"
What does "software-rendered snapshots" mean here ?
As by default Hardware acceleration is used from Android 4.0 on-wards. So all the views when attached to window would be having isHardwareacclerated() as true. Does "software-rendered snapshots" mean, all the views to which we have disabled Hardware acceleration ?
Doc also says : However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Does this mean, we have to use PixelCopy APIs instead of canvas approach?
As per my understanding, PixelCopy APIs should be used incase of SurfaceView. Is this wrong ? Is it correct approach to use PixelCopy APIs for all the views ?
Note : Correct me If my understanding is wrong
Solution
After exploring Android docs and working with samples related to above queries, I have found answers to my queries.
- What does "software-rendered snapshots" mean here ?
Ans : Hardware acceleration is enabled by default if your Target API level is >=14. Here Views canvas use GPU for drawing. If we create canvas object in our code, It would be having isHardwareAccelerated() as false, which says draw would be performed by CPU. So "software-rendered snapshots" mean, objects which are rendered through CPU.
https://developer.android.com/guide/topics/graphics/hardware-accel
- As by default Hardware acceleration is used from Android 4.0 on-wards. So all the views when attached to window would be having isHardwareacclerated() as true. Does "software-rendered snapshots" mean, all the views to which we have disabled Hardware acceleration ?
Ans: All the drawings happend through canvas object created in code.
3.Does this mean, we have to use PixelCopy APIs instead of canvas approach? 4. As per my understanding, PixelCopy APIs should be used incase of SurfaceView. Is this wrong ? Is it correct approach to use PixelCopy APIs for all the views ?
Ans : PixelCopy APIs have to be used on SurfaceView and Window objects. We cannot use PixelCopy APIs for all the views
https://developer.android.com/reference/android/view/PixelCopy
Answered By - Shanker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.