Skia Introduction and the steps to compile under Windows

Source: Internet
Author: User
Tags cairo drawtext xml parser skia

Skia is a C + + open source 2D vector graphics processing library (Cairo is a vector library), including fonts, coordinate transformations, bitmaps, and so on, equivalent to lightweight Cairo, currently used primarily for Google's Android and Chrome platforms, Skia with opengl/ ES with specific hardware features to enhance the display effect. In addition, Skia is one of the many graphics platforms supported by WebKit and is implemented in the graphicscontext.h/.c of WebKit.

Both Android and Chrome have a copy of the Skia in the source code repository, and some changes have been made because of different requirements.

The underlying libraries required by Skia are: Freetype2,expat,tinyxml.

You can use SVN to download source code from Google: Svncheckout http://skia.googlecode.com/svn.

Skia's header files and library function interfaces are implemented in C + +.

Code structure, SRC directory:

(1), animator directory: used to achieve Skia animation effect, Android does not support;

(2), Core directory: Skia, Basic is a number of graphic drawing functions;

(3), effects directory: To achieve a number of graphic image effects, including masks, reliefs, blur, filters, gradient, discrete, transparent, etc., and to achieve the path of various effects;

(4) GL Catalogue: Implement the Skia graphics library, Skia call OpenGL or OpenGL ES to achieve some simple 3D effect;

(5), images directory: Used to handle images, support the decoding of common images, encoding and animation of some images. The types of images Skia can handle include: BMP, Jpeg/pvjpeg, PNG, ICO, skmovie processing GIF animation;

(6), Ports directory: is the implementation of some of the Skia interface on different systems, platform-related code, such as fonts, threads, time and so on. These interfaces with Skia need to be implemented for different operating systems;

(7), SVG directory: To achieve the Skia vector SVG support, Android does not support;

(8), Utils directory: some auxiliary tools class;

(9), views directory: Skia built a set of interface UI Library;

(10), XML directory: Processing XML data, Skia here is just a layer of XML parser wrapper, the implementation of the specific XML parser needs to be implemented according to different operating systems and host programs;

(11), opts directory: Performance optimization of the Code;

(12), PDF catalogue: Processing PDF documents, using a FPDFEMB library;

Skia is primarily used by third-party libraries: Zlib, Jpeglib, Pnglib, Giflib, FPDFEMB (processing PDF documents).

Skia engine in Android source code location: (1), header file: Android/external/skia/include, which also contains several subdirectories: Animotor,core,effects,images,views,...;( 2), the source file is located in: Android/external/skia/src directory, subdirectory structure and header file directory is the same, (3), packaging layer: Android to the Skia engine is encapsulated, in order to make Java code convenient call, The code for Skia encapsulation exists under the ANDROID/FRAMEWORK/BASE/CORE/JNI and Android/framework/base/core/jni/android/graphics directories. In Android, Skia exists in the form of an extended library, and the directory is External/skia.

The Skia itself is a opensource project, integrated into the Android system. So Skia is not part of the Android framework and does not need to implement the framework's API to support Skia. However, Skia can also hook up other 3rd party encoding and decoding libraries or hardware codec libraries.

The Android version is different, the Skia version is not the same, the interface is slightly different.

The Skia consists of three libraries: (1), libcorecg.so: Part of the/skia/src/core, for example, where Region,rect is used to calculate the visible area in Surfaceflinger; (2), Libsgl.so: Contains part of the/skia/src/core|effects|images|ports|utils and all the content, this realizes the Skia most of the graphic effect, as well as the graphics format codec, (3), libskiagl.so: Contains The content inside the/SKIA/SRC/GL is used primarily to invoke OpenGL for partial effects.

Skia to the upper interface: Skia source files and some of the header files are in the EXTERNAL/SKIA/SRC directory, the exported header file in the External/skia/include directory. The main thing is that the Skcanvas class, almost the entire Androidgui system of the underlying drawing is done by this class. The Skcanvas class has three drawing functions: (1), basic drawing (e.g. Drawargb,drawline function), (2), image file drawing (e.g. Drawbitmap function), (3), text drawing (DrawText function).

Skia Image Codec part: (1),/include/image/skimagedecoder.h: Decoding the image file or stream to Skia internal memory Skbitmap; (2),/include/image/ SKImageEncoder.h: Encodes the Skia internal memory skbitmap into a file or stream form. These interfaces require a specific class implementation, with the main code in the Src/image file.

Skia engine Important class: (1), a core class of the Skcanvas:skia engine, which encapsulates all the paint operations on the device.

Hardware acceleration techniques used in Skia: (1), Opengl/opengles, (2), Simd:sse2/ssse3,neon.

Skia compilation under Windows:

1, download Python-2.7.8.amd64.msi and install from https://www.python.org/download/releases/2.7.8/, install to D:\ProgramFiles\Python27 directory, and add D:\ProgramFiles\Python27 to the environment variable path, restart the computer;

2, download setup-x86_64.exe and install from https://cygwin.com/install.html;

3, use SVN, download gyp:http://gyp.googlecode.com/svn/trunk, the entire Gyp folder into the/trunk_no_commit/third_party/externals folder;

4, in other branches of Jsoncpp, Jsoncpp-chromium, Libjpeg, libwebp four folder contents all copied to the/trunk_no_commit/third_party/externals folder;

5, open Cygwin, switch it to Skia trunk_no_commit directory, execute Python gyp_skia, will generate an out folder, there are generated Skia.sln project;

6, if in the execution of the Python gyp_skia command process, prompt/third_party/externals/libwebp/src/dec/frame.c and other files lost, then download the latest code from the relevant website to replace it.

7, (1), if the errorc2220:warning treated as Error-no ' object ' file generated, then the c/c++->general:treat warning as Er in the corresponding project Rors, from the original Level3 (/W3) to No (/wx-), such as effects, GM Engineering; (2), select Gm/verttext.cpp file->file->advancedsave options-> Encoding: Changed from original Unicode (UTF-8 without signature)-codepage 65001 to Chinesesimplified (GB2312)-codepage 936, (3), if Third_ Third-party library files in Party/extternal do not match with other source code, you can modify the corresponding. gyp files under the Gyp folder.

download all the corresponding skia source, including branches and trunk , the download found no trunk only trunk_no_commit

9,     open cygwin trunk_no_commit python Gyp_skia command, if warning:missing input Files related information, the lack of relevant files, the prompt to find the cause, or in the post-compilation error;

10. execute correctly after Pythongyp_skia command, you will Trunk_no_commit generated under directory out folder, open the inside of the Skia.sln , compiling SampleApp works, it generates SampleApp.exe and other corresponding static libraries.

11, modeled tests project to create a new Testskia project, project settings and code as follows:

(1), Debug and release, Character set:use Unicode Character Set;

(2), C + +->additional Include Directories:

E:\skia\code\google\trunk_no_commit\includee:\skia\code\google\trunk_no_commit\include\animatore:\skia\code\ Google\trunk_no_commit\include\confige:\skia\code\google\trunk_no_commit\include\coree:\skia\code\google\trunk _no_commit\include\device\xpse:\skia\code\google\trunk_no_commit\include\effectse:\skia\code\google\trunk_no_ Commit\include\gpue:\skia\code\google\trunk_no_commit\include\gpu\gle:\skia\code\google\trunk_no_commit\ Include\imagese:\skia\code\google\trunk_no_commit\include\pathopse:\skia\code\google\trunk_no_commit\include\ Pdfe:\skia\code\google\trunk_no_commit\include\pipee:\skia\code\google\trunk_no_commit\include\portse:\skia\ Code\google\trunk_no_commit\include\recorde:\skia\code\google\trunk_no_commit\include\svge:\skia\code\google\ Trunk_no_commit\include\texte:\skia\code\google\trunk_no_commit\include\utilse:\skia\code\google\trunk_no_ Commit\include\utils\wine:\skia\code\google\trunk_no_commit\include\viewse:\skia\code\google\trunk_no_commit\ Include\views\animatede:\skiA\code\google\trunk_no_commit\include\xmle:\skia\code\google\trunk_no_commit\tools 
(3), Preprocessor:

Debug:

Win32_debug_consolesk_internalsk_gamma_srgbsk_gamma_apply_to_a8sk_scalar_to_float_excludedsk_allow_static_ Global_initializers=1sk_support_gpu=1sk_support_opencl=0sk_force_distancefield_fonts=0sk_scalar_is_floatsk_can _use_floatsk_build_for_win32_crt_secure_no_warningsgr_gl_function_type=__stdcallsk_build_json_writersk_support _pdfsk_debugsk_developer=1

Release:

Win32ndebug_consolesk_internalsk_gamma_srgbsk_gamma_apply_to_a8sk_scalar_to_float_excludedsk_allow_static_ Global_initializers=1sk_support_gpu=1sk_support_opencl=0sk_force_distancefield_fonts=0sk_scalar_is_floatsk_can _use_floatsk_build_for_win32_crt_secure_no_warningsgr_gl_function_type=__stdcallsk_build_json_writersk_support _pdfsk_release

(4), Linker, Input-Additional Dependencies:

OpenGL32.libusp10.libDelayImp.libwindowscodecs.lib

(5), skcommandlineflags two files in the trunk_no_commit->tools->flags are copied to this test project and added to the project;

(6), stdafx.h:

#pragma once#include "targetver.h" #include <stdio.h> #include "SkCanvas.h" #include "SkData.h" #include " SkDocument.h "#include" SkForceLinking.h "#include" SkGraphics.h "#include" SkSurface.h "#include" SkImage.h "#include" SkStream.h "#include" SkString.h "#include" SkCommandLineFlags.h "

(7), Stdafx.cpp:

#include "stdafx.h"//todo:reference any additional headers the need in stdafx. h//and not in this file#ifdef _debug#pragma comment (lib, "e:/skia/code/google/trunk_no_commit/out/debug/lib/ Experimental.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/lib/libetc1.lib ") #pragma Comment (lib, "E:/skia/code/google/trunk_no_commit/out/debug/lib/libjpeg.lib") #pragma comment (lib, "e:/skia/code/ Google/trunk_no_commit/out/debug/lib/libwebp_dec.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/ Out/debug/lib/libwebp_dsp.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/lib/libwebp_ Enc.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/lib/libwebp_utils.lib ") #pragma Comment (lib, "E:/skia/code/google/trunk_no_commit/out/debug/lib/lua.lib") #pragma comment (lib, "e:/skia/code/ Google/trunk_no_commit/out/debug/lib/skflate.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/out/ Debug/lib/views_animated.lib ") #pragma Comment (lib, "E:/skia/code/google/trunk_no_commit/out/debug/skia_animator.lib") #pragma comment (lib, "E:/skia/code /google/trunk_no_commit/out/debug/skia_core.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/out/ Debug/skia_effects.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/skia_images.lib ") # pragma comment (lib, "E:/skia/code/google/trunk_no_commit/out/debug/skia_opts.lib") #pragma comment (lib, "e:/skia/ Code/google/trunk_no_commit/out/debug/skia_opts_ssse3.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_ Commit/out/debug/skia_pdf.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/skia_ Ports.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/skia_sfnt.lib ") #pragma comment (lib , "E:/skia/code/google/trunk_no_commit/out/debug/skia_skgpu.lib") #pragma comment (lib, "E:/skia/code/google/trunk_ No_commit/out/debug/skia_skgputest.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/skia _Utils.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/debug/skia_views.lib ") #pragma comment ( LIB, "E:/skia/code/google/trunk_no_commit/out/debug/skia_xml.lib") #else #pragma comment (lib, "e:/skia/code/google/ Trunk_no_commit/out/release/lib/experimental.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/out/ Release/lib/libetc1.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/lib/libjpeg.lib ") #pragma comment (lib, "E:/skia/code/google/trunk_no_commit/out/release/lib/libwebp_dec.lib") #pragma comment (lib, "E :/skia/code/google/trunk_no_commit/out/release/lib/libwebp_dsp.lib ") #pragma comment (lib," e:/skia/code/google/ Trunk_no_commit/out/release/lib/libwebp_enc.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/out/ Release/lib/libwebp_utils.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/lib/lua.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/lib/skflate.lib ") #pragma comment (LIB, "E:/skia/code/google/trunk_no_commit/out/release/lib/views_animated.lib") #pragma comment (lib, "e:/skia/code/ Google/trunk_no_commit/out/release/skia_animator.lib ") #pragma comment (lib," e:/skia/code/google/trunk_no_commit/ Out/release/skia_core.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_ Effects.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_images.lib ") #pragma Comment (lib, "E:/skia/code/google/trunk_no_commit/out/release/skia_opts.lib") #pragma comment (lib, "e:/skia/code/ Google/trunk_no_commit/out/release/skia_opts_ssse3.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_ Commit/out/release/skia_pdf.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_ Ports.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_sfnt.lib ") #pragma comment ( LIB, "E:/skia/code/google/trunk_no_commit/out/release/skia_skgpu.lib") #pragma comment (lib, "e:/skia/code/google/ Trunk_no_commiT/out/release/skia_skgputest.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_ Utils.lib ") #pragma comment (lib," E:/skia/code/google/trunk_no_commit/out/release/skia_views.lib ") #pragma comment ( LIB, "E:/skia/code/google/trunk_no_commit/out/release/skia_xml.lib") #endif

(8), TestSkia.cpp:

#include "stdafx.h" #include <iostream>using namespace Std;__sk_force_image_decoder_linking;define_string2 ( OutFile, O, "Skhello", "the filename to write the image.");D Efine_string2 (text, T, "Hello", "the string to write."); static void Dodraw (skcanvas* canvas, const skpaint& paint, const char text[]) {Skrect bounds;canvas->getclipbounds (&bounds); Canvas->drawcolor (sk_colorwhite); Canvas->drawtext (text, strlen (text), Bounds.centerx (), Bounds.centery (), paint);} static bool Do_surface (int w, int h, const char path[], const char text[], const skpaint& paint) {Skautotunref<sksu Rface> Surface (Sksurface::newrasterpmcolor (W, h));d Odraw (Surface->getcanvas (), paint, text); Skautotunref<skimage> image (Surface->newimagesnapshot ()); Skautodataunref data (Image->encode ()); if (NULL = = Data.get ()) {return false;} Skfilewstream Stream (path), Return Stream.Write (Data->data (), data->size ()); static bool Do_document (int w, int h, const char path[], const char TExt[], const skpaint& paint) {skautotunref<skdocument> doc (skdocument::createpdf (path)), if (Doc.get ()) { Skscalar width = skinttoscalar (w); Skscalar height = skinttoscalar (h);d Odraw (doc->beginpage (width, height, NULL), paint, text), return true; return false;} int tool_main (int argc, char** argv) {skcommandlineflags::setusage (""); Skcommandlineflags::P arse (argc, argv); Skautographics AG; Skstring path ("Skhello"); Skstring text ("Hello"); Flags_outfile.isempty ()) {Path.set (flags_outfile[0]);} if (! Flags_text.isempty ()) {Text.set (flags_text[0]);} Skpaint Paint;paint.setantialias (True);p aint.settextsize (Skinttoscalar ());p aint.settextalign (SkPaint::kCenter _align); Skscalar width = paint.measuretext (Text.c_str (), text.size ()); Skscalar spacing = paint.getfontspacing (), int w = skscalarroundtoint (width) + 30;int h = skscalarroundtoint (spacing) + 30; static const struct {bool (*FPROC) (int w, int h, const char path[], const char text[],const skpaint&); Const char* Fsuf Fix;} Grec[] = {{Do_surface, ". png"},{do_document, ". pdf"},};for (size_t i = 0; i < Sk_array_count (GREC); ++i) {skstring file;file.pr intf ("%s%s", Path.c_str (), Grec[i].fsuffix), if (!grec[i].fproc (W, H, File.c_str (), Text.c_str (), paint)) {return-1;}} return 0;}  int main (int argc, char* argv[]) {int flag = Tool_main (argc, (char**) argv); if (flag = = 0) cout<< "OK" <<endl;else cout<< "error" <<endl;return 0;}

Run this project, will generate Skhello.pdf and skhello.png two files in this project directory, the file content is Hello


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.