Download presentation
Presentation is loading. Please wait.
1
Android
2
Android Drawing on Android: Canvas vs. OpenGL Bitmap vs. Texture
NDK: Native Development Kit
3
Canvas Canvas.drawLine(), drawRect(), etc. Canvas.setMatrix(m);
Canvas.setBitmap(bmp); View.onDraw(Canvas);
4
Bitmap Bitmap.createBitmap(width, height, config);
BitmapFactory.decodeFile(file, options); With or without alpha channel (transparency).
5
View: events & invalidation
onDraw(canvas) invalidate() → onDraw() onTouchEvent() → invalidate()
6
PixelFormat RGB_565 (2 bytes / pixel) ARGB_8888 (4 bytes / pixel)
Bitmap.Config getWindow().setFormat() PixelFormat.RGBA_8888
7
Dithering
8
Canvas Not hardware accelerated (CPU) Uses Bitmap for images
Rendering in UI thread, invalidate() model Fast scrolling Slow zooming, rotation, 3d projections
9
OpenGL ES Hardware accelerated (GPU) Uses Textures for images
Rendering in separate thread (not UI thread) Fast zooming, 3d projections Fragmentation, complexity, hard to debug
10
Bitmap vs. Texture Bitmaps: use Java heap, limited to 24MB.
4bytes/pixel (ARGB) Textures: use native memory, limited only by total RAM. can use 3bytes/pixel (RGB). support pixmaps. may use fast GPU memory.
11
Native Development Kit (NDK)
12
Native Development Kit (NDK)
JNI: Java Native Interface C, C++ GCC cross compiler STL, exceptions, RTTI arm-linux-gnueabi, RISC, little endian, 32bit Thumb or ARM instructions Without hardware floating point
13
Why use NDK Performance critical code, e.g. FFT, game physics library, image/sound processing. Performance: avoid Java object creation and GC, e.g. filesystem scan. Use existing non-Java code/libraries (e.g. Python interpreter in C).
14
Java Native Interface (JNI)
class Hello { public native static int sum(int[] data); static { System.loadLibrary(“hello”); }
15
JNI C++ code JNI book
16
Stable APIs C library Math library Zlib OpenGL ES 1.x & 2.0 OpenSL ES
Android Log Bitmap interface (jnigraphics) Android native application API
17
NDK and Market Native code compiled for multiple architectures in a single APK. Market does filtering based on architectures available in APK and on platform version.
18
Thank you
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.