Introduction to Skia by Ryan Chou @20141008

27
Copyright © 2014 Realtek Semiconductor Corp. Skia Date : 2014/10/8 Author : Ryan Chou

description

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.

Transcript of Introduction to Skia by Ryan Chou @20141008

Page 1: Introduction to Skia by Ryan Chou @20141008

Copyright © 2014 Realtek Semiconductor Corp.

Skia

Date : 2014/10/8

Author : Ryan Chou

Page 2: Introduction to Skia by Ryan Chou @20141008

Outline

What is Skia Skia in Android Reference Q & A

Page 3: Introduction to Skia by Ryan Chou @20141008

Outline

What is Skia Skia in Android Reference Q & A

Page 4: Introduction to Skia by Ryan Chou @20141008

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

Page 5: Introduction to Skia by Ryan Chou @20141008

Outline

What is Skia Skia in Android Reference Q & A

Page 6: Introduction to Skia by Ryan Chou @20141008

Skia in Android

The source is located in external/skia, which major serves as Image decoder and encoder 2D graphic render

Page 7: Introduction to Skia by Ryan Chou @20141008

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

Page 8: Introduction to Skia by Ryan Chou @20141008

Architecture of Image DecoderAPP (MediaBrowser/RealtekGallery2)

Framework (BitmapFactory)

Skia

jpeg png gif webp bmp

libjpeg libpng libgif

DecodReg

JNI

Page 9: Introduction to Skia by Ryan Chou @20141008

Architecture of Image Encoder

JNI

APP

Framework (Bitmap::Compress)

Skia

jpeg png gif webp bmp

libjpeg libpng libgif

EncodeReg

Page 10: Introduction to Skia by Ryan Chou @20141008

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

Page 11: Introduction to Skia by Ryan Chou @20141008

Example: Skia API

Page 12: Introduction to Skia by Ryan Chou @20141008

Skia Rendering Pipeline

Source: http://www.xenomachina.com/2011/05/androids-2d-canvas-rendering-pipeline.html

Page 13: Introduction to Skia by Ryan Chou @20141008

Skia back-end

Render in software1) 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 acceleration1) Create a GLES2 window or framebufffer

2) Create the appropriate GrContext, SkGpuDevice and SkGpuCanvas

Page 14: Introduction to Skia by Ryan Chou @20141008

How Views are Drawn in Android pre 3.0

Source: http://developer.android.com/guide/topics/ui/how-android-draws.html

Page 15: Introduction to Skia by Ryan Chou @20141008

Why New Drawing Model in Android post-3.0?

Page 16: Introduction to Skia by Ryan Chou @20141008

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

Page 17: Introduction to Skia by Ryan Chou @20141008

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_HARDWARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)

CANNOT disable hardware acceleration at the window level View

setLayerType(View.LAYER_TYPE_SOFTWARE, null) CANNOT disable hardware acceleration at the view level

Page 18: Introduction to Skia by Ryan Chou @20141008

How Views are Drawn (Since 3.0)

Page 19: Introduction to Skia by Ryan Chou @20141008

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

Page 20: Introduction to Skia by Ryan Chou @20141008

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.

Page 21: Introduction to Skia by Ryan Chou @20141008

How Views are Drawn (Since 3.0)

Page 22: Introduction to Skia by Ryan Chou @20141008

Display List Properties (Since 4.1)

Page 23: Introduction to Skia by Ryan Chou @20141008

Android 2D Graphics Architecture

Page 24: Introduction to Skia by Ryan Chou @20141008

Android 2D Graphics Libraries

Page 25: Introduction to Skia by Ryan Chou @20141008

Outline

What is Skia Skia in Android Reference Q & A

Page 26: Introduction to Skia by Ryan Chou @20141008

Reference Bezier Curve, http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B.C3.A9zier_curves Android Skia 和 2D圖形系統 , ailyanlu, Mar. 16, 2012,

http://wenku.baidu.com/view/3a915fe94afe04a1b071dee6.html Android圖片編碼解碼實現方案 (skia), Arrow, Jan 25, 2013,

http://blog.csdn.net/myarrow/article/details/8540990 Android 3.0 Hardware Acceleration, Romain Guy, Mar. 2011,

http://android-developers.blogspot.kr/2011/03/android-30-hardware-acceleration.html Android 4.0 Graphics and Animations, Romain Guy, Nov. 2011,

http://android-developers.blogspot.kr/2011/11/android-40-graphics-and-animations.html iOS vs. Android ICS : Hardware Accelerated Graphics Pipelines, Nathan De Vries, Nov. 2011,

http://atnan.com/blog/2011/11/10/ios-vs-android-ics-hardware-accelerated-graphics-pipelines Learning about Android Graphics Subsystem, MIPS Developer Team, Apr. 2012,

http://blog.imgtec.com/news/learning-about-the-android-graphics-subsystem Hardware Accelerated 2D Rendering for Android, Jim Huang, Feb 19, 2013,

http://www.slideshare.net/jserv/accel2drendering?related=1 Skia & FreeType Android 2D Graphics Essentials, Kyungmin Lee, 2012,

http://www.slideshare.net/snailee/skia-freetype-android-2d-graphics-essentials?related=2 Hardware Acceleration, http://developer.android.com/guide/topics/graphics/hardware-accel.html Android Skia圖形渲染 , http://www.3g-edu.org/news/art045.htm Android SKia 渲染概述 , http://www.3g-edu.org/news/art044.htm

Page 27: Introduction to Skia by Ryan Chou @20141008

Q & A