0% found this document useful (0 votes)
362 views

High Performance Graphics in Android-Public

The document discusses high performance graphics techniques in Android, including how to initialize graphics using the SurfaceFlinger and Gralloc frameworks, animating graphics using the animation framework and Canvas/OpenGL ES, improving performance by using SurfaceView to render off the UI thread, and future graphics technologies like RenderScript. It also provides code snippets as examples of implementing these graphics techniques.

Uploaded by

Joseph Ku
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views

High Performance Graphics in Android-Public

The document discusses high performance graphics techniques in Android, including how to initialize graphics using the SurfaceFlinger and Gralloc frameworks, animating graphics using the animation framework and Canvas/OpenGL ES, improving performance by using SurfaceView to render off the UI thread, and future graphics technologies like RenderScript. It also provides code snippets as examples of implementing these graphics techniques.

Uploaded by

Joseph Ku
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

High Performance

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

void DisplayHardware::init(uint32_t dpy)


{
mNativeWindow = new FramebufferNativeWindow();
framebuffer_device_t const * fbDev = mNativeWindow->getDevice();
......

/*
* Create our main surface
*/

surface = eglCreateWindowSurface(display, config,


mNativeWindow.get(), NULL);
......

}
Start From Here

• hardware/libhardware/modules/gralloc/framebuffer.cpp
int mapFrameBufferLocked(struct private_module_t* module)
{
// already initialized...
if (module->framebuffer) {
return 0;
}

char const * const device_template[] = {


"/dev/graphics/fb%u",
"/dev/fb%u",
0 };

int fd = -1;
int i=0;
char name[64];

while ((fd==-1) && device_template[i]) {


snprintf(name, 64, device_template[i], 0);
fd = open(name, O_RDWR, 0);
i++;
}
......
}
Move It!

• 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

Animation anim = new TranslateAnimation(


Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 10.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f
);
anim.setDuration(3000);
findViewById(R.id.ImageView01_turtle).startAnimation(anim);
findViewById(R.id.ImageView02_rabbit).startAnimation(anim);
What is the key of the
“Lazy” animations?
Interpolator
Android Animation Framework

• 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

• Code snippets – Part I


public class testSurfaceView extends SurfaceView implements
SurfaceHolder.Callback, Runnable
{
private SurfaceHolder holder;
......
public testSurfaceView(Context context) {
super(context);
init(context);
}

private init(Context, context) {


holder = getHolder();
holder.addCallback(this);
holder.setFixedSize(getWidth(), getHeight());
......
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
......
}
SurfaceView

• Code snippets – Part II

......

@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

• DirectFB is a thin library that provides hardware


graphics acceleration, input device handling and
abstraction, integrated windowing system with
support for translucent windows and multiple display
layers, not only on top of the Linux Framebuffer
Device.
• Latest stable version: 1.4.3 (update to 2009/12/12)
• License: LGPL
df_andi is back !!!
Results on Google Ion

Drawing methods 10 Tuxes 200 Tuxes


Canvas (SurfaceView) 42.52fps 13.35fps
OpenGL ES - Basic Vertex Quads 53.18fps 10.97fps
OpenGL ES - VBO Extension 57.80fps 21.23fps
OpenGL ES - Draw Texture Extension 57.81fps 42.93fps
The Future

• 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

int main(int launchID) {


int z;
int x = Sprite->x;
int y = Sprite->y;
struct path_s * p = (struct path_s *)path;

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

You might also like