You are on page 1of 25

AndroidVG

The Power of OpenVG on Android

Shuo-Hung Chen <shuohong@gmail.com>


Hsiao-Mei Lin <berrymei@gmail.com>

AndroidVG

AndroidVG brings OpenVG library on Android platforms


Focused on 2D vector graphics
It was motivated to accelerate Adobe Flash player on
Android

slow!

Project history

June 2010: Kick off

October 2010: First release

Website:

http://code.google.com/p/androidvg/

Vector Graphics

Vector graphics are created from mathematical


formulas used to define lines, shapes and curves.
Shapes are edited by moving points called nodes
(drawing points)
Vector graphics can be scaled or resized to any
resolution.

Resized
3
Image

What is OpenVG?

OpenVG is a royalty-free,
cross-platform API by
Khronos Group

Low-level hardware
acceleration interface for
vector graphics libraries

Support SVG and Flash

OpenVG 1.0:
-

2D vector and raster graphics


OpenVG 1.1:

Full acceleration support for Adobe


Flash and Flash Lite

HW accelerated text rendering

multi-sampled anti-aliasing

Benefits of OpenVG
Low power consumption
Seamless Transition from software to hardware
Scalability
Accelerates existing formats
Games, screen-savers, mapping, user interfaces
Portable content
Royalty free

Target Applications
Portable mapping applications
E-book readers
SVG Viewers
Games
Scalable User Interfaces
Low-level graphics device interface

OpenVG API Design Philosophy


Hardware acceleration abstraction layer
Simplicity
OpenGL-style syntax
Extensibility
Focus on embedded devices

Drawing Graphics with OpenVG


VGPath path = vgCreatePath(...);
cmd[0] = VG_MOVE_TO_ABS;
cmd[1] = VG_LINE_TO_ABS;
cmd[2] = VG_CBUIC_TO_ABS;
coord[0] = ...;
vgAppendPathData(...);
vgDrawPath(path, VG_FILL_PATH);

vgRotate(...)

Developer Friendly
vgRotate(...)

vgTransform(...)

vgScale(...)

Path and Paint


VG_LINE_TO

VG_SCUBIC_TO

VG_HLINE_TO

VG_VLINE_TO

VG_SCCWARC_TO

Single Color

VG_QUAD_TO

VG_LCWARC_TO

Linear Gradient

10

VG_CUBIC_TO

VG_SCWARD_TO

Radial Gradient

VG_SQUAD_TO

VG_LCCWARC_TO

OpenVG Rendering Pipeline


1

Path, transformation, stroke and paint

Clipping and masking

Stroked path generation

Paint generation

Transformation

Image interpolation

Rasterization

Blending and antialiasing

11

Android Graphics
Application
Java
View/Widget/Canvas

Skia

2D

3D

OpenGL ES

Surface

12

Skia, Inc was acquired by


Google in 2005.

Skia is the 2D render engine


in Android and Chrome.

It is a software render
engine.

Accelerated by OpenGL ES

Available OpenVG Hardware


PowerVR SGX 5-series

ADRENO 205 or later

Tegra 2

Google Nexus S

HTC Desire HD

Motorola Xoom

13

Goal of AndroidVG

Current

Our Goal

Application

Application
Java
View/Widget/Canvas

Java
View/Widget/Canvas

OpenGL ES

Skia

Skia

OpenGL ES

AndroidVG

Hardware

Hardware

With hardware

Without hardware

Acceleration interface

2D render engine

libhvg.so

libvg.so
14

Current AndroidVG

Built on OpenGL ES 1.1

Hardware acceleration with 3D GPU

Adaptive path generation using ShivaVG

Application
AndroidVG
AndroidVG

OpenGL ES
3D GPU
15

3D GPU Acceleration
T1
T5
T8
Path Generation

T7

T4

Triangulation by
CPU

T3

Screen
Display on
Screen !!

T2

T6

Send to
GPU
Draw by
GPU

T1

T5

T4
T7

16

T3

T2

T6
T8

AndroidVG Rendering Pipeline


Works on CPU

Path Generation
Works on CPU

OpenGL ES on GPU
17

Software Path Generation


Path: Mathematical Equations

Adaptive Path Generation

18

...
Almost straight line
Push & Return!

...

Triangulation Methods
Complexity

Hardware
Accelerated

Released Date

Ear-Clipping

O(n2)

No

Oct 2010

Monotone Polygon

O(n log(n))

No

Nov 2010

Stencil Buffer

O(n)

Yes

May 2011

19

Software Triangulation
Ear Clipping

Ear: Triangle with 2 side on polygon


and 3rd on inside it.

Monotone Polygon

If nodes are not at the same side of a


swipe line, split it!

Easy but Slow

Complex but Faster


20

Hardware Stencil Buffer

A stencil buffer is a per-pixel


integer to control which pixel is
to be rendered.

Current version only success on


Samsung devices: Nexus S,
Galaxy Tab.

Some Android GPU doesnt have


stencil buffer: HTC Desire HD.

glEnable(GL_STENCIL_TEST);
glStencilOp(GL_INVERT, ...);

Initial

123

134

145

156

167

Final

GPU accelerated & Fast!!


21

Developing with AndroidVG

22

Java Wrapper for AndroidVG


Java
public native void vgScale((float) sx, (float) sy);
!

JNI

JNIEXPORT jint JNICALL

Java_com_example_androidvg_VG11_vgScale(
!
JNIEnv* env, jobject obj,
!
jfloat sx, jfloat sy){
! ! ! vgScale(
! ! ! (VGfloat) sx,
! ! ! (VGfloat) sy
! ! ! );
! }

void vgScale(VGfloat sx, VGfloat sy);

23

How to Use AndroidVG Library


Developers

Android API

Native C

24

25

You might also like