SlideShare a Scribd company logo
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
&Graphics Performance
&Chet Haase Romain Guy
Architecture
Reordering & merging
Save Cancel
Maximize compatibility
Include metadata
Google I/O 2013 - Android Graphics Performance
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
Google I/O 2013 - Android Graphics Performance
Multi-threading
Google I/O 2013 - Android Graphics Performance
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
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
performTraversals
draw
getDL drawDisplayList
systrace
flush drawing commands
android:sdk $ cd platform-tools/
android:platform-tools $
./systrace.py gfx view freq sched
Google I/O 2013 - Android Graphics Performance
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
Google I/O 2013 - Android Graphics Performance
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()
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
@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()
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
Using alpha with care
Google I/O 2013 - Android Graphics Performance
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);
==
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
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
Google I/O 2013 - Android Graphics Performance
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);
}
Google I/O 2013 - Android Graphics Performance
1. Clip
2. Rotate
3. Draw
Google I/O 2013 - Android Graphics Performance
@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);
}
Google I/O 2013 - Android Graphics Performance
1. Rotate
2. Clip
3. Draw
Google I/O 2013 - Android Graphics Performance
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);
}
Google I/O 2013 - Android Graphics Performance
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

PDF
Javascript Styles and some tips
PDF
玉転がしゲームで学ぶUnity入門
PDF
MBrace: Cloud Computing with F#
PDF
MBrace: Large-scale cloud computation with F# (CUFP 2014)
PDF
404.ie: Solving Layout Problems with CSS Grid & Friends
PPT
Method You Use to Transfer a Drawing to a Canvas
PDF
Google I/O 2013 - Android Graphics Performance
DOCX
Android canvas-chapter20
Javascript Styles and some tips
玉転がしゲームで学ぶUnity入門
MBrace: Cloud Computing with F#
MBrace: Large-scale cloud computation with F# (CUFP 2014)
404.ie: Solving Layout Problems with CSS Grid & Friends
Method You Use to Transfer a Drawing to a Canvas
Google I/O 2013 - Android Graphics Performance
Android canvas-chapter20

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

PDF
Breathing the life into the canvas
PDF
Framing the canvas - DroidCon Paris 2014
PPTX
It's the arts! Playing around with the Android canvas
PDF
Graphicsand animations devoxx2010 (1)
PDF
S'il te plait, dessine moi une vue
DOCX
Android Studio (Java)The SimplePaint app (full code given below).docx
PDF
Project meeting: Android Graphics Architecture Overview
PDF
Enhancing UI/UX using Java animations
PDF
Make your designers love (working with) you
PDF
Android design and Custom views
PPT
Why your Android Apps Suck
PDF
Canvas API in Android
PDF
Creating custom views
PDF
Creating an Uber Clone - Part IV - Transcript.pdf
PDF
[1D6]RE-view of Android L developer PRE-view
PPTX
Canvas al ajillo
PDF
[Android] 2D Graphics
PDF
Android drawing and graphics API
PDF
Android drawing and graphics api
PPTX
Advanced #4 GPU & Animations
Breathing the life into the canvas
Framing the canvas - DroidCon Paris 2014
It's the arts! Playing around with the Android canvas
Graphicsand animations devoxx2010 (1)
S'il te plait, dessine moi une vue
Android Studio (Java)The SimplePaint app (full code given below).docx
Project meeting: Android Graphics Architecture Overview
Enhancing UI/UX using Java animations
Make your designers love (working with) you
Android design and Custom views
Why your Android Apps Suck
Canvas API in Android
Creating custom views
Creating an Uber Clone - Part IV - Transcript.pdf
[1D6]RE-view of Android L developer PRE-view
Canvas al ajillo
[Android] 2D Graphics
Android drawing and graphics API
Android drawing and graphics api
Advanced #4 GPU & Animations
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
Assigned Numbers - 2025 - Bluetooth® Document
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Ad

Google I/O 2013 - Android Graphics Performance