unbuntu下编译skia
一、简介 skia是谷歌的开源矢量图形引擎。早先由Skia公司开发,被谷歌收购以后,skia应用于chrome、chromium操作系统、chrome浏览器,以及Android操作系统。要研究它首要工作还是编译,以及运行测试代码。为了能尽快的编译skia,我选择了在vmware的ubuntu 10.4虚拟机上编译。二、编译过程及测试代码 1. 首先要安装skia源代码依赖的库,
一、简介
skia是谷歌的开源矢量图形引擎。早先由Skia公司开发,被谷歌收购以后,skia应用于chrome、chromium操作系统、chrome浏览器,以及Android操作系统。要研究它首要工作还是编译,以及运行测试代码。为了能尽快的编译skia,我选择了在vmware的ubuntu 10.4虚拟机上编译。
二、编译过程及测试代码
1. 首先要安装skia源代码依赖的库,libfreetype和libpng。可以使用如下命令安装:
sudo apt-get install libfreetype6-dev
sudo apt-get -f install libpng12-dev
2. 在~/下创建skia目录,进入~/skia目录,并使用如下命令下载skia源代码(当然,事先要安装svn工具),我checkout出来的版本号为624:
svn checkout http://skia.googlecode.com/svn/trunk/ skia-read-only/
3. 进入~/skia/skia-read-only目录,使用如下命令编译skia源代码。编译完成后会在~/skia/skia-read-only/out目录下生成文件libskia.so。
make SKIA_BUILD_FOR=linux
4. ~/skia/skia-read-only下,创建文件夹mytest,在其中添加文件test-skia.c,内容如下。具体使用的函数可参考其注释及skia文档。
1: /* Simple vector graphics demo utilizing Skia toolkit.
2: * Authored by Jim Huang <jserv.tw@gmail.com>
3: */
4:
5: #include "SkBitmap.h"
6: #include "SkDevice.h"
7: #include "SkPaint.h"
8: #include "SkRect.h"
9: #include "SkImageEncoder.h"
10:
11: int main()
12: {
13: // Declare a raster bitmap, which has an integer width and height,
14: // and a format (config), and a pointer to the actual pixels.
15: // Bitmaps can be drawn into a SkCanvas, but they are also used to
16: // specify the target of a SkCanvas' drawing operations.
17: SkBitmap bitmap;
18: bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200);
19: bitmap.allocPixels();
20:
21: // A Canvas encapsulates all of the state about drawing into a
22: // device (bitmap). This includes a reference to the device itself,
23: // and a stack of matrix/clip values. For any given draw call (e.g.
24: // drawRect), the geometry of the object being drawn is transformed
25: // by the concatenation of all the matrices in the stack. The
26: // transformed geometry is clipped by the intersection of all of the
27: // clips in the stack.
28: SkCanvas canvas(new SkDevice(bitmap));
29:
30: // SkPaint class holds the style and color information about how to
31: // draw geometries, text and bitmaps.
32: SkPaint paint;
33:
34: // SkIRect holds four 32 bit integer coordinates for a rectangle.
35: SkRect r;
36:
37: paint.setARGB(255, 255, 0, 0);
38: r.set(25, 25, 145, 145);
39: canvas.drawRect(r, paint); /** Draw the specified rectangle using
40: the specified paint. The rectangle
41: will be filled or stroked based on
42: the Style in the paint. */
43:
44: paint.setARGB(255, 0, 255, 0);
45: r.offset(20, 20);
46: canvas.drawRect(r, paint);
47:
48: paint.setARGB(255, 0, 0, 255);
49: r.offset(20, 20);
50: canvas.drawRect(r, paint);
51:
52: // SkImageEncoder is the base class for encoding compressed images
53: // from a specific SkBitmap.
54: SkImageEncoder::EncodeFile("snapshot.png", bitmap,
55: SkImageEncoder::kPNG_Type,
56: /* Quality ranges from 0..100 */ 100);
57: return 0;
58: }
在~/skia/skia-read-only/mytest目录下,使用如下命令编译test-skia.c文件:
g++ -I../include -I../include/core -I../include/images -I../include/config
-Wall -o test-skia test-skia.c ../out/src/images/SkImageDecoder_libpng.o
../out/libskia.a -lpng -lfreetype -lpthread -g
执行test-skia后,会在mytest目录下生成文件snapshot.png。
三、总结
原先在编译Cairo库的时候,总是希望能将其运行在windows平台下。但实际情况是,那个平台编译方便就在那个平台,因为我们的目的不是为了编译而编译,我们需要的是了解要编译的库本身。关于skia功能的简单介绍,可以参见这里。
四、参考资料
更多推荐
所有评论(0)