2. G(PU)-force by Royi Benyossef (+royiby)
Android developer since 2009.
GDG Herzliya co-founder.
Android speaker and lecturer.
Android Mentor for Google Launchpad.
Android GDE 2013, 2014, 2015.
Android group leader at Vidmind.
Royi Benyossef
11. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
Definition
12. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
Definition Graphics rendered by the GPU
13. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
- Definition
In Android
Graphics rendered by the GPU
14. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
- Definition
In Android
Graphics rendered by the GPU
Canvas drawn by the GPU
15. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
- Definition
In Android
Graphics rendered by the GPU
Canvas drawn by the GPU
(= HW drawing model)
16. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
- Definition
In Android
Graphics rendered by the GPU
Canvas drawn by the GPU
(= HW drawing model)
NOT Canvas drawn by the CPU
17. With a little help from my libs by Royi Benyossef (+royiby)
Prolog
- Definition
In Android
Graphics rendered by the GPU
Canvas drawn by the GPU
(= HW drawing model)
NOT Canvas drawn by the CPU
(!= SW drawing model)
19. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
(Let me dig deeper… please)
20. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
SW model
21. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
SW model Invalidate hierarchy
22. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
SW model Invalidate hierarchy
Draw hierarchy
23. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
- SW model
HW model
Invalidate hierarchy
Draw hierarchy
24. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
- SW model
HW model
Invalidate hierarchy
Draw hierarchy
Invalidate hierarchy
25. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
- SW model
HW model
Invalidate hierarchy
Draw hierarchy
Invalidate hierarchy
Record & update display lists
26. With a little help from my libs by Royi Benyossef (+royiby)
Android drawing models
- SW model
HW model
Invalidate hierarchy
Draw hierarchy
Invalidate hierarchy
Record & update display lists
Draw hierarchy
28. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
(How it differs between the SW and HW models)
(P.S. also point #1)
29. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
SW model
30. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
SW model Calling item is redrawn
31. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
SW model Calling item is redrawn
All affiliated items are
redrawn
32. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
SW model Calling item is redrawn
All affiliated items are
redrawn
* Executed immediately
33. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
- SW model
HW model
34. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
- SW model
HW model
Calling item is saved to the
display list
35. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
- SW model
HW model
Calling item is saved to the
display list
Display list is updated
36. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
- SW model
HW model
Calling item is saved to the
display list
Display list is updated
Diff is drawn
37. With a little help from my libs by Royi Benyossef (+royiby)
OnInvalidate()
- SW model
HW model
Calling item is saved to the
display list
Display list is updated
Diff is drawn
* Executed on V-sync
38. With a little help from my libs by Royi Benyossef (+royiby)
Resources
(Expertise & availability)
(P.S. also points #2 & #3)
39. With a little help from my libs by Royi Benyossef (+royiby)
Resources
Expertise
40. With a little help from my libs by Royi Benyossef (+royiby)
Resources
Expertise Specifically designed HW&SW
41. With a little help from my libs by Royi Benyossef (+royiby)
Resources
- Expertise
Availability
42. With a little help from my libs by Royi Benyossef (+royiby)
Resources
- Expertise
Availability
Separate resource repo
44. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
OnInvalidate()
45. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
OnInvalidate() Refresh ONLY what was asked
46. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
OnInvalidate() Refresh ONLY what was asked
* Not always good
47. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
OnInvalidate() Refresh ONLY what was asked
* Not always good
Timing is better
48. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
Res. expertise
Refresh ONLY what was asked
* Not always good
Timing is better
49. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
Res. expertise
Refresh ONLY what was asked
* Not always good
Timing is better
Faster
50. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
Res. expertise
Refresh ONLY what was asked
* Not always good
Timing is better
Faster
Better quality
51. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
- Res. expertise
Res. avail.
Refresh ONLY what was asked
* Not always good
Timing is better
Faster
Better quality
52. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
Res. expertise
Res. avail.
Refresh ONLY what was asked
* Not always good
Timing is better
Faster
Better quality
No waiting
53. With a little help from my libs by Royi Benyossef (+royiby)
Benefits
- OnInvalidate()
Res. expertise
Res. avail.
Refresh ONLY what was asked
* Not always good
Timing is better
Faster
Better quality
No waiting (OK, less waiting)
58. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
API avail.
59. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
API avail. API < 11 N/A
60. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
API avail. API < 11 N/A
API >= 11 (3.x) Available, off
61. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
API avail. API < 11 N/A
API >= 11 (3.x) Available, off
API >= 14(4.x) Available, on
64. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
Impediments
Increased RAM usage
65. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
Impediments
Increased RAM usage
Not all op.s are supported
66. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
Impediments
Increased RAM usage
Not all op.s are supported
67. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
Impediments
Increased RAM usage
Not all op.s are supported
Possible sick strange things!
68. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
- Impediments
Examples
Possible sick strange things:
69. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
- Impediments
Examples
Invisible UI elements
70. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
- Impediments
Examples
Badly rendered pixels
71. With a little help from my libs by Royi Benyossef (+royiby)
Impediments
- API avail.
- Impediments
Examples
Possible sick strange things:
> Invisible UI elements
> Badly rendered pixels
> Exceptions
81. With a little help from my libs by Royi Benyossef (+royiby)
Check, test & verify
(Oh my!)
82. With a little help from my libs by Royi Benyossef (+royiby)
Check, test & verify
Check
83. With a little help from my libs by Royi Benyossef (+royiby)
Check DAC/guide/topics/graphics/hardware-accel.
html#drawing-support
Check, test & verify
84. With a little help from my libs by Royi Benyossef (+royiby)
Check, test & verify
- Check
Test
85. With a little help from my libs by Royi Benyossef (+royiby)
Check, test & verify
- Check
Test All the
devices!!!
86. With a little help from my libs by Royi Benyossef (+royiby)
- Check
Test
All the devices
Systrace
Check, test & verify
87. With a little help from my libs by Royi Benyossef (+royiby)
- Check
Test
All the devices
Systrace
Dumpsys gfxinfo
Check, test & verify
88. With a little help from my libs by Royi Benyossef (+royiby)
- Check
Test
All the devices
Systrace
Dumpsys gfxinfo
*Tracer
Check, test & verify
89. With a little help from my libs by Royi Benyossef (+royiby)
- Check
Test
** Ran Nachmany’s great session
https://www.youtube.com/watch?
v=aEFxqdPgHJk
Check, test & verify
93. With a little help from my libs by Royi Benyossef (+royiby)
Reduce, reuse, recycle
(Things you need less of)
94. With a little help from my libs by Royi Benyossef (+royiby)
Reduce, reuse, recycle
No. of views
95. With a little help from my libs by Royi Benyossef (+royiby)
No. of views
Reduce, reuse, recycle
Less views
96. With a little help from my libs by Royi Benyossef (+royiby)
No. of views
Reduce, reuse, recycle
Less views
Smaller display lists
97. With a little help from my libs by Royi Benyossef (+royiby)
No. of views
Reduce, reuse, recycle
Less views
Smaller display lists
Less to draw
98. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
99. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
100. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Test:
101. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Test:
> Developer options
102. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Test:
Developer options
> Down. hierarchyViewer
103. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Test:
Developer options
Down. hierarchyViewer
(Screen layers)
104. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Fix:
105. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Fix:
> Merge/remove layers
106. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Never draw more than x2 the
no. of pixels
Fix:
Merge/remove layers
> Crop unseen pixels
107. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Tip:
108. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
Overdraw
Reduce, reuse, recycle
Tip:
Transparent pixels in
bitmaps count!
109. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
110. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
111. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
Cause GC (very expensive)
112. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
Cause GC (very expensive)
113. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
Cause GC (very expensive)
Examples:
114. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
Cause GC (very expensive)
Examples:
> Paint
115. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
New
Reduce, reuse, recycle
Objects in rendering func.
Cause GC (very expensive)
Examples:
Paint
>Path
116. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
- New
Modifications
Reduce, reuse, recycle
117. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
- New
Modifications
Reduce, reuse, recycle
Shape/Circle/Path create a
new text. when altered
118. With a little help from my libs by Royi Benyossef (+royiby)
- No. of views
- Overdraw
- New
Modifications
Reduce, reuse, recycle
Shape/Circle/Path create a
new text. when altered
Bitmaps are reloaded when
altered (to the GPU)
119. With a little help from my libs by Royi Benyossef (+royiby)
Use. Differently.
(Pro-tips for better usage)
120. With a little help from my libs by Royi Benyossef (+royiby)
Alpha anim.
Use. Differently.
121. With a little help from my libs by Royi Benyossef (+royiby)
Alpha anim.
Use. Differently.
Created in an off-screen
buffer
122. With a little help from my libs by Royi Benyossef (+royiby)
Alpha anim.
Use. Differently.
Created in an off-screen
buffer
Should be dealt in a hardware
layer type
123. With a little help from my libs by Royi Benyossef (+royiby)
- Alpha animation
Custom view
Use. Differently.
124. With a little help from my libs by Royi Benyossef (+royiby)
- Alpha animation
Custom view
Use. Differently.
private class PieView extends View {
public PieView(Context context) {
super(context);
if (!isInEditMode()) {
setLayerType(
View.
LAYER_TYPE_HARDWARE,
null);}}}
125. With a little help from my libs by Royi Benyossef (+royiby)
Set the scope
(One size does not fit all)
126. With a little help from my libs by Royi Benyossef (+royiby)
Application
Set the scope
<application android:hardwareAccelerated="true"
…
>
127. With a little help from my libs by Royi Benyossef (+royiby)
- Application
Activity
<application android:hardwareAccelerated="true">
<activity
android:hardwareAccelerated="false"
/>
</application>
Set the scope
128. With a little help from my libs by Royi Benyossef (+royiby)
- Application
- Activity
Window
Set the scope
getWindow().setFlags(
WindowManager.LayoutParams
.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams
.FLAG_HARDWARE_ACCELERATED
);
129. With a little help from my libs by Royi Benyossef (+royiby)
- Application
- Activity
Window
Set the scope
getWindow().setFlags(
WindowManager.LayoutParams
.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams
.FLAG_HARDWARE_ACCELERATED
);
Note: You currently cannot disable
hardware acceleration at the window level.
130. With a little help from my libs by Royi Benyossef (+royiby)
- Application
- Activity
- Window
View&layer
Set the scope
myView.setLayerType(
View.LAYER_TYPE_SOFTWARE, null
);
131. With a little help from my libs by Royi Benyossef (+royiby)
- Application
- Activity
- Window
View&layer
Set the scope
myView.setLayerType(
View.LAYER_TYPE_SOFTWARE, null
);
Note:You currently cannot enable hardware
acceleration at the view level. View layers
have other functions besides disabling
hardware acceleration. See View layers for
more information about their uses.
132. With a little help from my libs by Royi Benyossef (+royiby)
Layer up
(All layers are NOT created equal)
133. With a little help from my libs by Royi Benyossef (+royiby)
None
Layer up
LAYER_TYPE_NONE
134. With a little help from my libs by Royi Benyossef (+royiby)
None
Layer up
LAYER_TYPE_NONE
not backed by any off screen buffer,
rendered in the SW model.
135. With a little help from my libs by Royi Benyossef (+royiby)
- None
Hardware
Layer up
LAYER_TYPE_HARDWARE
136. With a little help from my libs by Royi Benyossef (+royiby)
- None
Hardware
Layer up
LAYER_TYPE_HARDWARE
if HW accel. is on, layer is backed by HW
texture buffer and rendered in the HW
model, else it is the same as in the case of
LAYER_TYPE_SOFTWARE.
137. With a little help from my libs by Royi Benyossef (+royiby)
- None
Hardware
Layer up
Best for performance
138. With a little help from my libs by Royi Benyossef (+royiby)
- None
Hardware
Layer up
Best for performance:
> V-sync
139. With a little help from my libs by Royi Benyossef (+royiby)
- None
Hardware
Layer up
Best for performance:
V-sync
> Anim. added to the hardware
texture w/o redrawing.
140. With a little help from my libs by Royi Benyossef (+royiby)
- None
-Hardware
Software
Layer up
LAYER_TYPE_SOFTWARE - backed by a
Bitmap as if it was a buffer, rendered in the
SW model.
141. With a little help from my libs by Royi Benyossef (+royiby)
- None
-Hardware
Software
Layer up
Best for compatibility
142. With a little help from my libs by Royi Benyossef (+royiby)
- None
-Hardware
Software
Layer up
Best for compatibility:
> Min API < 11
143. With a little help from my libs by Royi Benyossef (+royiby)
- None
-Hardware
Software
Layer up
Best for compatibility:
Min API < 11
> Fixes different behaviour on
different devices (GPUs)
144. With a little help from my libs by Royi Benyossef (+royiby)
Be informed
(Which getter can’t be trusted)
145. With a little help from my libs by Royi Benyossef (+royiby)
View.isHardwareAccelerated()
Be informed
146. With a little help from my libs by Royi Benyossef (+royiby)
- View.isHardwareAccelerated()
Canvas.isHardwareAccelerated()
Be informed
147. With a little help from my libs by Royi Benyossef (+royiby)
- View.isHardwareAccelerated()
- Canvas.isHardwareAccelerated()
Be informed
148. With a little help from my libs by Royi Benyossef (+royiby)
- View.isHardwareAccelerated()
- Canvas.isHardwareAccelerated()
Be informed
149. With a little help from my libs by Royi Benyossef (+royiby)
- View.isHardwareAccelerated()
- Canvas.isHardwareAccelerated()
A view attached to a hardware accel. window can still be
drawn in the SW model
Be informed
150. With a little help from my libs by Royi Benyossef (+royiby)
- View.isHardwareAccelerated()
- Canvas.isHardwareAccelerated()
A view attached to a hardware accel. window can still be
drawn in the SW model (like when it’s drawn to a bitmap
for caching).
Be informed
151. With a little help from my libs by Royi Benyossef (+royiby)
Summary
(What did we have here?)
152. With a little help from my libs by Royi Benyossef (+royiby)
Generally
Summery
153. With a little help from my libs by Royi Benyossef (+royiby)
Generally
Summery
HW accel is good but it has
issues
154. With a little help from my libs by Royi Benyossef (+royiby)
- Generally
GPUs
Summery
Are not created equally
155. With a little help from my libs by Royi Benyossef (+royiby)
- Generally
- GPUs
Less is more
Summery
Take only what you need
156. With a little help from my libs by Royi Benyossef (+royiby)
- Generally
- GPUs
Less is more
Summery
Take only what you need
Reduce, reuse, recycle
157. With a little help from my libs by Royi Benyossef (+royiby)
- Generally
- GPUs
- Less is more
Analyze&adapt
Summery
Wait for it...
158. With a little help from my libs by Royi Benyossef (+royiby)
- Generally
- GPUs
- Less is more
Analyze&adapt
Summery
ALWAYS!
159. “We should be building great
things. Things that Don’t yet
exist”
160. I Hope You Liked It
Thank you for listening
By Royi Benyossef (+royiby)