Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Skia by Ryan Chou @20141008

1,932 views

Published on

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.

Published in: Software
  • Be the first to comment

Introduction to Skia by Ryan Chou @20141008

  1. 1. Skia Date : 2014/10/8 Author : Ryan Chou Copyright © 2014 Realtek Semiconductor Corp.
  2. 2. Outline  What is Skia  Skia in Android  Reference  Q & A
  3. 3. Outline  What is Skia  Skia in Android  Reference  Q & A
  4. 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. 5. Outline  What is Skia  Skia in Android  Reference  Q & A
  6. 6. Skia in Android  The source is located in external/skia, which major serves as  Image decoder and encoder  2D graphic render
  7. 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
  8. 8. Architecture of Image Decoder APP (MediaBrowser/RealtekGallery2) Framework (BitmapFactory) Skia DecodReg jpeg png gif webp bmp libjpeg libpng libgif JNI
  9. 9. Architecture of Image Encoder JNI APP Framework (Bitmap::Compress) Skia EncodeReg jpeg png gif webp bmp libjpeg libpng libgif
  10. 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
  11. 11. Example: Skia API
  12. 12. Skia Rendering Pipeline Source: http://www.xenomachina.com/2011/05/androids-2d-canvas-rendering-pipeline.html
  13. 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. 14. How Views are Drawn in Android pre 3.0 Source: http://developer.android.com/guide/topics/ui/how-android-draws.html
  15. 15. Why New Drawing Model in Android post-3.0?
  16. 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. 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
  18. 18. How Views are Drawn (Since 3.0)
  19. 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. 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.
  21. 21. How Views are Drawn (Since 3.0)
  22. 22. Display List Properties (Since 4.1)
  23. 23. Android 2D Graphics Architecture
  24. 24. Android 2D Graphics Libraries
  25. 25. Outline  What is Skia  Skia in Android  Reference  Q & A
  26. 26. 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
  27. 27. Q & A

×