High Performance Graphics in Android-public

36
High Performance Graphics in Android 古古古 Joseph Ku [email protected]

Transcript of High Performance Graphics in Android-public

Page 1: High Performance Graphics in Android-public

High Performance Graphics in Android

古傑芳 Joseph [email protected]

Page 2: High Performance Graphics in Android-public

Outline

• Why?

• Preparations

• Graphics in Android

• Move It!

• The Future

• Q&A

Page 3: High Performance Graphics in Android-public

Why?

Page 4: High Performance Graphics in Android-public

Once upon a time…

Page 5: High Performance Graphics in Android-public
Page 6: High Performance Graphics in Android-public

Do NOT hack anymore!

Page 7: High Performance Graphics in Android-public

Lesson One

Page 8: High Performance Graphics in Android-public

Be A Good Student !

Page 9: High Performance Graphics in Android-public

Graphics in Android

Page 10: High Performance Graphics in Android-public

Graphics in Android

Page 11: High Performance Graphics in Android-public

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); ...... }

Page 12: High Performance Graphics in Android-public

Start From Here

• hardware/libhardware/modules/gralloc/framebuffer.cppint 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++; } ......}

Page 13: High Performance Graphics in Android-public

Move It!

• Animation Framework

• Canvas

• OpenGL ES

Page 14: High Performance Graphics in Android-public

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)

Page 15: High Performance Graphics in Android-public

Wait…Wait……

Page 16: High Performance Graphics in Android-public

What is the factors ofanimation?

Page 17: High Performance Graphics in Android-public

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)

Page 18: High Performance Graphics in Android-public

Classic Game

Page 19: High Performance Graphics in Android-public

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);

Page 20: High Performance Graphics in Android-public

What is the key of the “Lazy” animations?

Page 21: High Performance Graphics in Android-public

Interpolator

Page 22: High Performance Graphics in Android-public

Android Animation Framework

• Interpolators (android.view.animation)

Classes Description

AccelerateDecelerateInterpolator

AccelerateInterpolator

AnticipateInterpolator *

AnticipateOvershootInterpolator *

BounceInterpolator *

CycleInterpolator

DecelerateInterpolator

LinearInterpolator

OvershootInterpolator *

Page 23: High Performance Graphics in Android-public

Can we improve it?

Page 24: High Performance Graphics in Android-public

Free Rendering

• Canvas

• OpenGL ES– Basic Vertex Quads

– VBO Extension

– Draw Texture Extension

Page 25: High Performance Graphics in Android-public

Not enough!!!

Page 26: High Performance Graphics in Android-public

UI Thread

Page 27: High Performance Graphics in Android-public

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) { ...... }

Page 28: High Performance Graphics in Android-public

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! }}

Page 29: High Performance Graphics in Android-public

Don’t forget…our old friend…

Page 30: High Performance Graphics in Android-public

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

Page 31: High Performance Graphics in Android-public

df_andi is back !!!

Page 32: High Performance Graphics in Android-public

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

Page 33: High Performance Graphics in Android-public

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()

Page 34: High Performance Graphics in Android-public

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;}

Page 35: High Performance Graphics in Android-public

Q & A

[email protected]

Twitterjosephku

FacebookJoseph Ku

Xbox LiveJosephku

PlayStation Networkjosephku

WiiFriend Code: 7747-0675-0711-3774

Joseph Ku

Page 36: High Performance Graphics in Android-public