SlideShare a Scribd company logo
1 of 96
Download to read offline
&Graphics Performance
&Chet Haase Romain Guy
Architecture
Reordering & merging
Save Cancel
Maximize compatibility
Include metadata
Include metadata Maximize compatibility CancelSave
Order of drawing commands
Include metadata Maximize compatibility CancelSave
1. Re-ordering
Include metadata
Maximize compatibility
Cancel
Save
2. Merging
Multi-threading
Drawing
Drawing
Shadows
Shadows
Shadows
Shadows
Drawing
Paths
Paths
Shadows
Shadows
Shadows
Shadows
Non-rectangular clipping
@Override
protected void onDraw(Canvas canvas) {
// Clip with a shape
Path clip = getPath();
canvas.clipPath(clip);
// Draw the content
for (int i = 0; i < mLines,length; i++) {
TextLine line = mLines[i];
canvas.drawText(line.text,
line.x, line.y, mPaint);
}
}
Developer Tools
2
Overdraw
Overdraw
Overdraw
Overdraw
Blue
Green
Red
Deep Red
1x
2x
3x
4x
0
3
6
9
12
15
Timeinms
Frames
Update display lists Process display lists Swap buffers
performTraversals
draw
getDL drawDisplayList
systrace
flush drawing commands
android:sdk $ cd platform-tools/
android:platform-tools $
./systrace.py gfx view freq sched
import android.os.Trace;
@Override
public View getView(int pos, View view, ViewGroup parent) {
Trace.beginSection("getView");
if (view == null) {
view = createView();
}
// Trace time spent binding data
Trace.beginSection("bind");
bindView(pos, view);
Trace.endSection();
Trace.endSection();
return view;
}
android:sdk $ cd platform-tools/
android:platform-tools $
./systrace.py -a com.example.myapp
Tips & Tricks
3
Overdraw demo
Trilinear filtering
Off On
private void loadData() {
// Load bitmap
Bitmap b = getBitmap();
// Enable trilinear filtering
b.setHasMipMap(true);
}
<bitmap
android:mipMap="true"
android:src="@drawable/my_drawable" />
Canvas layers
@Override
protected void onDraw(Canvas canvas) {
// Create a clipped layer
canvas.save();
canvas.saveLayer(x, y, width, height,
Canvas.CLIP_TO_LAYER_SAVE_FLAG);
// Draw stuff
canvas.drawBitmap(bugDroid, 0.0f, 0.0f, null);
canvas.restore();
}
saveLayer()
@Override
protected void onDraw(Canvas canvas) {
// Create an unclipped layer
canvas.save();
canvas.saveLayer(x, y, width, height, 0);
// Draw stuff
canvas.drawBitmap(bugDroid, 0.0f, 0.0f, null);
canvas.restore();
}
saveLayer()
Using alpha with care
view.setAlpha(0.5f);
View.ALPHA.set(view, 0.5f);
ObjectAnimation.ofFloat(view, "alpha", 0.5f)
view.animate().alpha(0.5f);
view.setAnimation(new AlphaAnimation(1.0f, 0.5f));
view.setAlpha(0.5f);
View.ALPHA.set(view, 0.5f);
ObjectAnimation.ofFloat(view, "alpha", 0.5f)
view.animate().alpha(0.5f);
view.setAnimation(new AlphaAnimation(1.0f, 0.5f));
Canvas.saveLayerAlpha(l, t, r, b, 127,
Canvas.CLIP_TO_LAYER_SAVE_FLAG);
==
lternatives
// Not this
textView.setAlpha(alpha);
// But this
int newTextColor = (int) (0xFF * alpha) << 24 |
baseTextColor & 0xFFFFFF;
textView.setTextColor(newTextColor);
// Not this
imageView.setAlpha(alpha);
// But this
imageView.setImageAlpha((int) (alpha * 255));
// Not this
customView.setAlpha(alpha);
// But this
int alpha = (int)
(255 * slider.getProgress() / 100.0f);
paint.setAlpha(alpha);
canvas.draw*(..., paint);
// Or use a layer
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
// Transient layer
view.animate().alpha(0).withLayer();
// API level 16+
@Override
public boolean hasOverlappingRendering() {
// Don't lie to us!
return false;
}
640 dp
400dp
Canvas
@Override
protected void onDraw(Canvas canvas) {
// Get the dimensions of the Canvas
int w = canvas.getWidth();
int h = canvas.getHeight();
canvas.drawRect(0, 0, w, h, mPaint);
}
1280 px
800px
View
300px
600 px
With hardware rendering
600x300 px (size of the View)
With hardware rendering
With software rendering
600x300 px
1280x800 px
(size of the View)
(size of the window)
✂
Clipping
@Override
protected void onDraw(Canvas canvas) {
// Keep the jellybeans
canvas.clipRect(l, t, r, b);
// Rotate the jar
canvas.rotate(-30.0f, pX, pY);
// Draw the jar
canvas.drawBitmap(mJellyBeans, x, y, null);
}
1. Clip
2. Rotate
3. Draw
@Override
protected void onDraw(Canvas canvas) {
// Rotate the jar
canvas.rotate(-30.0f, pX, pY);
// Keep the jellybeans
canvas.clipRect(l, t, r, b);
// Draw the jar
canvas.drawBitmap(mJellyBeans, x, y, null);
}
1. Rotate
2. Clip
3. Draw
Stencilbuffer
Stencilbuffer
640 px
400px
View
Invalidate
640 px
400px (170,125)
(470,275)
@Override
protected void onDraw(Canvas canvas) {
// Query the current clip
Rect clip = canvas.getClipBounds();
// ???
Log.d("I/O", "clip = " + clip);
}
With hardware rendering
0, 0, 640, 400
(bounds of the View)
With hardware rendering
With software rendering
0, 0, 640, 400
170,125, 470, 275
(bounds of the View)
(bounds of the dirty rect)
Reordering barriers
Non-rectangular clips
saveLayer()
More info
Parleys.com
For Butter or Worse
Google I/O 2012
Various Android GUI & performance talks
Accelerated Android Rendering
Google I/O 2011
More info
Romain’s Tips & Tricks
www.curious-creature.org
Chet’s Tips & Tricks
goo.gl/y9JZr
Android Performance Case Study
graphics-geek.blogspot.com
Q&A
google.com/+ChetHaase
google.com/+RomainGuy
@chethaase
@romainguy
Developers

More Related Content

Similar to Google I/O 2013 - Android Graphics Performance

How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
PL dream
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
Framgia Vietnam
 

Similar to Google I/O 2013 - Android Graphics Performance (20)

Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Mapping the world with Twitter
Mapping the world with TwitterMapping the world with Twitter
Mapping the world with Twitter
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With Chartkick
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Deep dive into deeplearn.js
Deep dive into deeplearn.jsDeep dive into deeplearn.js
Deep dive into deeplearn.js
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
 

Recently uploaded

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Google I/O 2013 - Android Graphics Performance