This article is very helpful for understanding the android graphics system and is recommended to you.
Http://blog.linux.org.tw /~ Jserv/archives/002095.html
In September 2008, Google announced the web browser chrome, which uses the improved WebKit as its core, and revealed many new features of chrome. For example, Google released the new [V8] JavaScript (ecmascript) the primary engine, perhaps because of its eye-catching nature, masks another original primary attack [skia], the latter is a 2D vector processing function, which contains a high-performance and complex table of fonts, base labels, and dot keys. It is not applicable to the Google Chrome browser. The new Android platform also uses skia as a processing tool to combine OpenGL/es with specific hardware features, this article describes the historical background, application plane, and programming model of Google skia.
In order to build an Open Handset Alliance (Oha) Android platform, Google has been working for a long time, and hundreds of people have developed some of them from the previous marketing case, two of them have the following meanings:
- In August 17, 2005, the business of the android company in the United States was the development of mobile phone software, which is now the predecessor of the open source Android program.
- In October November 2005, the company received the US skia, and its business was vector computing representative.
Android companies that have been acquired by Google have made achievements in the IT industry. This article is not much written, and skia is naturally not a fuel-saving product. Skia Inc. based in Chapel Hill, North Carolina-United States, written by Michael Reed (also known as Mike Reed, he is a top-notch character in the graphic technology domain, and he is working with Benoit Schillings (BEOs main developer, be Inc. the second engineering engineer, now Nokia CTO) was working with openwave, a mobile development company, that is to say, the company's product openwave phone Suite version 7.0 (below) introduced a superb vector embedding technology, in the 50-300 kb space, it provides the Alpha blended linear regression and full-function vector moment linear regression functions among others. Before joining openwave, Mike Reed served apple and represented quickdraw GX. The main component was a processing tool for processing images and fonts. Benoit schillings started openwave as trolltech cto, and Mike Reed started skia inc ., the company's first product is SGL (skia Graphics Library), a very powerful vector display engine, high quality 2D rendering on low-end devices such as phones, computers, and other handheld devices. Description of the root worker localtechwire:
"Skia's first product, SGL, is a portable graphics engine capable of rendering state-of-the-art 2D graphics on low-end devices such as mobile phones, TVs, and handhelds, "the web site said. "SGL is feature-set compatible with existing 2D standards, making it ideal to serve as a back-end for public formats such as SVG, PDF, and openvg. SGL is licensed as source or binary, and can be customized to match specific HW/framebuffer requirements."
Since skia was received by Google in 2005, it has been a mysterious and low-performing program until the beginning of 2007, the skia Gl-related program was revealed, for Google Android, the Google Chrome plugin later also uses the skia engine. With the release of the android and chrome public program, skia also opens the original program, use Apache license v2 as an example (note that this means it is incompatible with gplv2 permission granting), while Android and chrome programs both have a copy of [skia] signature, some changes have been made due to different requirements. For example, in the case of chrome, trunk, SRC, and skia, note that, skia itself does not involve the underlying environment, such as the handling of Linux framebuffer or GTK + protocol, which is also why Android (through Linux framebuffer) and chrome (the Linux version in the development uses GTK +) need to provide a copy of the modification so that the system can be connected. In this regard, may refer to the development date of Google chromium [graphics in Google Chrome]
Similar to Firefox 1.x, Firefox 2.x/ 3.x in later versions has a relatively large progress in hierarchical display, A large amount of attention is due to the introduction of the Cario vector processing program to handle the online processing, and skia is equivalent to playing the role of Cairo, but it is more practical. The quickshield WebKit was the first choice to use the cross-foot mobile engine on the desktop to solve the solution, apple and Google both have digital and comprehensive engineering investment. Thanks to the power of the Internet, there are also other vendors and developers who have already invested in development, currently, WebKit supports metrics such as Cairo, GTK +, qt4, wxWidgets, CG (non-open and original MACOs), and skia, in addition, class graphicscontext in WebKit is used to handle the aforementioned hierarchical correspondence, which allows you to define the major set and members required by different platforms based on the features of different platforms, you can test the program using WebCore/platform/graphics/graphicscontext. {H, CPP }.
Skia is implemented in C ++. The program has eight million lines. There are basically some unknown factors, and the documents that can be tested are limited, however, the svn log and program commit of chromium are the most complete files. The following are their characteristics:
- High-reliability guest rasteriser (module SGL /)
- Select images through OpenGL/es to accelerate specific operations, such as shader and textures (module Gl /)
- Dynamic processing capability (module animator /)
- Built-in SVG support (module (SVG /)
- Image codec, such as PNG, JPEG, GIF, and BMP (modules images /)
- Internal text processing, but lack of Thai and Tibetan text processing capabilities
- Performance features:
- Copy-on-write of the image and the specified data type
- Internal memory management, which is carefully exempted from fragmentation
- Thread-Safety
Skia implements the required dependency:
- Font: FreeType (it is worth noting that David Turner, creator of FreeType, is currently working on Google), Windows GDI
- Multi-threaded model: pthread, Windows threads
- XML: expat, tinyxml
We can understand the historical background to make some interesting things. First, get the original skia program token from Google Code:
# svn co http://skia.googlecode.com/svn/trunk skia-trunk
Looking at this refreshing architecture, I can imagine that this is a commercial entity, or maybe Google has some "secrets that cannot be said 」, in addition to several program examples in samplecode/project, there is almost no sufficient text. SVN log can be used to develop the development of zookeeper skia, "reed@android.com" is Mike Reed himself, so far is still very active to improve the practice of skia. The Zookeeper method is very simple. Let's take a look at the description: (this article applies to SVN r130)
# cd skia-trunk# make help
You can get the following description:
Targets: : out/libskia.a bench: out/bench/bench tests: out/tests/tests clean: removes entire out/ directory help: this textOptions: (after make, or in bash shell) SKIA_DEBUG=true for debug build SKIA_SCALAR=fixed for fixed-point build SKIA_BUILD_FOR=mac for mac build (e.g. CG for image decoding)
The expected writable output is the writable out/libskia. a. skia's internal operations can select the floating point number and fixed point (fixed-point). However, the author finds that the selection is not transparent at present, however, this does not affect our understanding of skia's usage and power. For the GNU/Linux used by the author, the following command can be used to require the following commands:
# make SKIA_BUILD_FOR=linux
If there is no accident, the system will be cool:
compiling out/src/core/Sk64.ocompiling out/src/core/SkAlphaRuns.ocompiling out/src/core/SkBitmap.o...
As for the benchmark program, the following commands can be used:
# make SKIA_BUILD_FOR=linux bench
In addition to chromium, the benchmark program is the best "file", but the skia API is already too large. This may also be useful. Compile the benchmark program:
./out/bench/bench -o `pwd`
There will be outputs similar to the following:
running bench polygonrunning bench linesrunning bench pointsrunning bench rrects3running bench rrects1running bench ovals3running bench ovals1running bench rects3running bench rects1running bench bitmap_index8running bench bitmap_4444running bench bitmap_565running bench bitmap_8888
You can probably know the knowledge of skia Han, then the author will write a small program, using skia C ++ API: [test-skia.c]
/* Simple vector graphics demo utilizing Skia toolkit. * Authored by Jim Huang <jserv.tw@gmail.com> */ #include "SkBitmap.h"#include "SkDevice.h"#include "SkPaint.h"#include "SkRect.h"#include "SkImageEncoder.h"int main(){// Declare a raster bitmap, which has an integer width and height,// and a format (config), and a pointer to the actual pixels.// Bitmaps can be drawn into a SkCanvas, but they are also used to// specify the target of a SkCanvas' drawing operations.SkBitmap bitmap;bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200);bitmap.allocPixels();// A Canvas encapsulates all of the state about drawing into a// device (bitmap). This includes a reference to the device itself,// and a stack of matrix/clip values. For any given draw call (e.g.// drawRect), the geometry of the object being drawn is transformed// by the concatenation of all the matrices in the stack. The// transformed geometry is clipped by the intersection of all of the// clips in the stack.SkCanvas canvas(new SkDevice(bitmap));// SkPaint class holds the style and color information about how to// draw geometries, text and bitmaps.SkPaint paint;// SkIRect holds four 32 bit integer coordinates for a rectangle.SkRect r;paint.setARGB(255, 255, 0, 0);r.set(25, 25, 145, 145);canvas.drawRect(r, paint); /** Draw the specified rectangle using the specified paint. The rectangle will be filled or stroked based on the Style in the paint. */paint.setARGB(255, 0, 255, 0);r.offset(20, 20);canvas.drawRect(r, paint);paint.setARGB(255, 0, 0, 255);r.offset(20, 20);canvas.drawRect(r, paint);// SkImageEncoder is the base class for encoding compressed images// from a specific SkBitmap.SkImageEncoder::EncodeFile("snapshot.png", bitmap,SkImageEncoder::kPNG_Type,/* Quality ranges from 0..100 */ 100);return 0;}
Renewal method:
g++ / -I./include / -I./include/core / -I./include/images / -Wall -o test-skia test-skia.c / out/src/images/SkImageDecoder_libpng.o out/libskia.a / -lpng -lpthread -g
The author has implemented the desired solution. We can see the functions of these Apis starting with SK, in the preceding example, skia is required to configure a skcanvas at the beginning, and then a skrect object R is used to describe the argb, so that it has different colors, and then it is the moving of the entire vector object and the moving. As mentioned above, skia benchmark is the zookeeper engine, which does not apply to PDF, X11, and GDI in general, therefore, in order to facilitate our observation of the results, we have used image codec built in skia to export PNG images, for this reason, the test-skia statement after reading the preceding example should get the following example: (this example has no external frame or background color, but it is clear that the article is displayed, external Use of external software added)
The following APIs call the combined three rectangle objects of different colors to convert them:
paint.setARGB(255, 0, 255, 0);r.offset(20, 20);canvas.drawRect(r, paint);
Because skia and Cairo are of high quality, you can refer to [Cairo: Documentation] to establish the necessary background knowledge.