Android graphics engine skia

Source: Internet
Author: User
Tags cairo skia
Introduction 1

Google Android uses skia as its core graphics engine. Skia is also Google Chrome's graphics engine.

The skia Graphics Rendering Engine was initially developed by skia, which was acquired by Google in 2005.

Skia is very similar to openwave's (now called purple labs) V7 vector graphics engine. They all come from Mike Reed's company.

If you are working on vector graphics or image rendering on mobile devices, you should carefully study the source code of checkout skia.

Skia is quite elegant in its simplicity and power, a great combination.

"By adding skia engine to chrome, Google can ensure good graphics performance on devices that don't have a graphics processing unit." 5

Features4

Skia has around 80,000 lines of code and is developed based on C ++. Its main features include:

  • Optimised software-based rasteriser (module SGL /);
  • Optional Gl-based acceleration of certain graphics operations including shader support and textures (module Gl /);
  • Animation capabilities (module animator /);
  • Some built-in SVG support (module (SVG /)
  • Built-in image decoders: PNG, JPEG, GIF, BMP, wbmp, ico (modules images /);
  • Text capabilities (no built-in support for complex scripts );
  • Some awareness of higher-level UI toolkit constructs (platform windows, platform events): Mac, Unix (sic. X11, incomplete), Windows, wxWidgets
  • Performace features
    1. Copy-on-write for images and certain other data types;
    2. Extensive use of the stack, both internally and for API consumers to avoid needless allocations and memory fragmentation;
    3. Thread-safety to enable parallelisation.

The library is portable and has (optional) platform-specific backends:

  • Fonts: Android/ascender, FreeType, Windows (GDI );
  • Threading: pthread, windows;
  • XML: expat, tinyxml;
  • Android shared memory (ashmem) for inter-process image data references;
Why does Google Chrome select skia 6

Why not use OpenGL or DirectX to accelerate rendering?

  • Data is read from the video card and then copied back to the video card in another process. In this case, it is not worthwhile to use hardware for accelerated rendering;
  • Relatively speaking, drawing takes only a small amount of time. Most of the time is the calculation of the location, style, and output text of page elements. That is, 3D acceleration is not significantly improved;

Why not use other graphics libraries?

  • Windows GDI: The underlying graphics API of Microsoft Windows, which is relatively only capable of drawing the base. For example, <canvas> and SVG must be implemented independently.
  • GDI +: more advanced APIs on Windows. GDI + uses a device-independent metrics, this makes text and letter spacing in chrome different from other Windows applications (which measure and draw text tailored to the screen device ). At that time, Microsoft also recommended developers to use the new graphic API. The technical support and maintenance of GDI + may be limited.
  • Cairo: an open source 2D graphics library that has been used in Firefox 3.

The final choice of skia is as follows:

  • Skia is cross-platform;
  • There was already a high-quality WebKit port using it created for Android's browser;
  • We had in-house expertise.

Http://blog.chromium.org/2008/10/graphics-in-google-chrome.html

Source code download

Http://src.chromium.org/viewvc/chrome/trunk/src/skia/

Hello world4

In this simple example we draw a few rectangles to a memory-based image buffer. this also demonstrates how one might integrate with the Platform graphics system to get something on screen, though in this case we're using Cairo to save the resulting image to disk:

#include "SkBitmap.h"#include "SkDevice.h"#include "SkPaint.h"#include "SkRect.h"#include <cairo.h>int main(){  SkBitmap bitmap;  bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);  bitmap.allocPixels();  SkDevice device(bitmap);  SkCanvas canvas(&device);  SkPaint paint;  SkRect r;  paint.setARGB(255, 255, 255, 255);  r.set(10, 10, 20, 20);  canvas.drawRect(r, paint);  paint.setARGB(255, 255, 0, 0);  r.offset(5, 5);  canvas.drawRect(r, paint);  paint.setARGB(255, 0, 0, 255);  r.offset(5, 5);  canvas.drawRect(r, paint);  {    SkAutoLockPixels image_lock(bitmap);    cairo_surface_t* surface = cairo_image_surface_create_for_data(        (unsigned char*)bitmap.getPixels(), CAIRO_FORMAT_ARGB32,        bitmap.width(), bitmap.height(), bitmap.rowBytes());    cairo_surface_write_to_png(surface, "snapshot.png");    cairo_surface_destroy(surface);  }  return 0;}

You can build this example for yourself linking statically to the libskia. A object file generated during the chrome Build Process on Linux.

Standalone skia2

Someone tried skia of stand-alone on the Internet. For details, refer:

Http://vuhung16.blogspot.com/2008/10/standalone-skia.html

Open skia3

Google Code found an openskia project. From the author's perspective, standalone skia is a person.

Http://code.google.com/p/openskia/

Openskia is a graphics engine based skia graphics engine that was developed by skia inc., a company Google acquired in 2005.

This vector graphics engine software makes highend visual effects possible on feature phone. it is tiny in size and is capable of delivering very high quality. skia's engine is the graphics core of both Google Android and Google Chrome.

Reference
  1. Skia Source Code released
  2. Standalone skia
  3. Openskia
  4. Skia graphics library in chrome: First Impressions
  5. Chrome's secret: The skia Engine
  6. Graphics in Google Chrome
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.