High Performance Graphics in Android-Public
High Performance Graphics in Android-Public
Graphics in Android
古傑芳 Joseph Ku
[email protected]
Outline
• Why?
• Preparations
• Graphics in Android
• Move It!
• The Future
• Q&A
Why?
Once upon a time…
Do NOT hack
anymore!
Lesson One
Be A Good Student !
Graphics in Android
Graphics in Android
Start From Here
• frameworks/base/libs/surfaceflinger/DisplayHardware
/DisplayHardware.cpp
/*
* Create our main surface
*/
}
Start From Here
• hardware/libhardware/modules/gralloc/framebuffer.cpp
int mapFrameBufferLocked(struct private_module_t* module)
{
// already initialized...
if (module->framebuffer) {
return 0;
}
int fd = -1;
int i=0;
char name[64];
• Animation Framework
• Canvas
• OpenGL ES
Android Animation Framework
• android.view.animation
Classes Description
AlphaAnimation An animation that controls the
alpha level of an object.
RotateAnimation An animation that controls the
rotation of an object.
ScaleAnimation An animation that controls the
scale of an object.
TranslateAnimation An animation that controls the
position of an object.
AnimationDrawable An object used to create frame-
by-frame animations
(android.graphics.drawable
)
Wait…Wait……
What is the factors of
animation?
Android Animation Framework
• android.view.animation
Classes Description
AlphaAnimation An animation that controls the
alpha level of an object.
RotateAnimation An animation that controls the
rotation of an object.
ScaleAnimation An animation that controls the
scale of an object.
TranslateAnimation An animation that controls the
position of an object.
AnimationDrawable An object used to create frame-
by-frame animations
(android.graphics.drawable
)
Classic Game
The Rabbit and The Turtle
• Code snippets
• Interpolators (android.view.animation)
Classes Description
AccelerateDecelerateInterpolator
AccelerateInterpolator
AnticipateInterpolator *
AnticipateOvershootInterpolator *
BounceInterpolator *
CycleInterpolator
DecelerateInterpolator
LinearInterpolator
OvershootInterpolator *
Can we improve it?
Free Rendering
• Canvas
• OpenGL ES
– Basic Vertex Quads
– VBO Extension
– Draw Texture Extension
Not enough!!!
UI Thread
SurfaceView
@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
......
}
SurfaceView
......
@Override
public vold surfaceCreated(SurfaceHolder holder) {
thread = new Thread(this);
thread.start();
}
@Override
public vold surfaceDestroyed(SurfaceHolder holder) {
thread = null;
}
@Override
public vold run() {
// Rendering here!
}
}
Don’t forget…
our old friend…
DirectFB
• RenderScript
– Android 2.0 above
– framework/base/graphics/java/android/ renderscript
– RSSurfaceView.java
– Compiled on devices!!!
– Using acc (libacc)
– No #include
– No malloc()
– No free()
The Future
• Code snippets
z = x * 2 + y;
......
return 1;
}
Q&A
Joseph Ku
Email
[email protected]
Twitter
josephku
Facebook
Joseph Ku
Xbox Live
Josephku
PlayStation Network
josephku
Wii
Friend Code: 7747-0675-0711-3774