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


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:
  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:
  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)
  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 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,  Android Skia和2D圖形系統, ailyanlu, Mar. 16, 2012,  Android圖片編碼解碼實現方案(skia), Arrow, Jan 25, 2013,  Android 3.0 Hardware Acceleration, Romain Guy, Mar. 2011,  Android 4.0 Graphics and Animations, Romain Guy, Nov. 2011,  iOS vs. Android ICS : Hardware Accelerated Graphics Pipelines, Nathan De Vries, Nov. 2011,  Learning about Android Graphics Subsystem, MIPS Developer Team, Apr. 2012,  Hardware Accelerated 2D Rendering for Android, Jim Huang, Feb 19, 2013,  Skia & FreeType Android 2D Graphics Essentials, Kyungmin Lee, 2012,  Hardware Acceleration,  Android Skia圖形渲染,  Android SKia 渲染概述,
  27. 27. Q & A