This introduces the fundamental knowledge about Skia which is open-source project used in Android. In this, it contains the history of skia, and the roll of skia in Android.
2. Outline
What is Skia
Skia in Android
Reference
Q & A
3. Outline
What is Skia
Skia in Android
Reference
Q & A
4. What is Skia
A 2D graphic engine for drawing Text, Geometries, and Images
A compact open source graphics library written in C++, and licensed
under New BSD free software license
Developed by Skia Inc., which was acquired by Google in 2005
Used in Chrome browser, Chrome OS, Firefox browser, Firefox OS,
and Android
Back-ends
CPU-based software rasterization, PDF output, GPU-accelerated
OpenGL
Front-ends
SVG, PostScript, PDF, SWF and Adobe illustrator files
Its competitor is also well-known : Cairo
Open source library under GNU Lesser General Public License (LGPL)
Written in C
Skia is more compatible in mobile device
5. Outline
What is Skia
Skia in Android
Reference
Q & A
6. Skia in Android
The source is located in external/skia, which major serves as
Image decoder and encoder
2D graphic render
7. File system
src/animator: implement animation effect
src/core : implement core of Skia, which is graphic rendering
src/gl : implement graphic library. The engine is OpenGL or OpenGL
ES.
src/images : implement image related part and support decoding
and encoding of images of some common image format (bmp, gif,
png, jpg…)
src/ports : defines the porting layer, including Font, Event, File,
Thread, Time, XMLParser
src/svg : support of SVG
src/utils : assistant tools
src/views : UI (Not adopted in Android)
src/xml : implement XML DOM and Parser
10. Skia Drawing Primitive API
Overview
Drawing basic primitives include rectangles, rounded rectangles, ovals,
circles, arcs, paths, lines, text, bitmaps, and sprites. Paths allow for the
creation of more advanced shapes. Each path can be made up for multiple
contours (or continuous sections), each consisting of linear, quadratic, and
cubic segments.
A Canvas encapsulates all of the state about drawing into a device (bitmap).
A reference to the device
A stack of matrix/clip values
While the Canvas holds the state of the drawing device, the state (style) of
the object being drawn is held by the Paint, which is provided as a
parameter to each of the draw() methods. The Paint holds attributes such as
color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), etc
13. Skia back-end
Render in software
1) Create a native window and then
2) Wrap a pointer to its buffer as an SkBitmap
3) Initialize an SkCanvas with the bitmap
Render in hardware acceleration
1) Create a GLES2 window or framebufffer
2) Create the appropriate GrContext, SkGpuDevice and SkGpuCanvas
14. How Views are Drawn in
Android pre 3.0
Source: http://developer.android.com/guide/topics/ui/how-android-draws.html
16. Hardware-accelerated 2D
Rendering
Since Android 3.x, more complex than before
Major idea : transform the implementation of 2D Graphics APIs into
OpenGL ES requests
Textures, Shader, GLContext, pipeline, …
Major parts for hardware-accelerated 2D Rendering
Primitive Drawing: Shape, Text, Image
Layer/Surface Compositing
17. Control hardware accelerations
Application level
<application android:hardwareAccelerated=“true”>
Default value
False in Android 3.x; True in Android 4.x
Activity
<activity android:hardwareAccelerated=“true”>
Window
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDW
ARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDW
ARE_ACCELERATED)
CANNOT disable hardware acceleration at the window level
View
setLayerType(View.LAYER_TYPE_SOFTWARE, null)
CANNOT disable hardware acceleration at the view level
19. Display List
A display list is a series of graphics commands that define an output
image. The image is created (rendered) by executing the command.
A display list can represent both two-and three-dimensional scenes.
Systems that make use of a display list to store the scene are called
retained mode systems as opposed to immediate mode systems.
(From Wikipedia)
http://en.wikipedia.org/wiki/Display_list
http://developer.android.com/guide/topics/graphics/hardware-accel.html
20. Display List in Android (Since
3.0)
A display list records a series of graphics related operation and can replay them later.
Display lists usually built by recording operations on a android.graphics.Canvas.
Replaying the operations from a display list avoids executing views drawing code on
every frame, and is thus much more efficient.