# svn co https://skia.googlecode.com/svn/trunk skia-trunk乍看這「清爽」的目錄架構,很難想像過去這是商業軟體,或許 Google 有些「不能說的秘密」,除了 samplecode/ 目錄若干的程式碼之外,就幾乎沒有充分的文檔了。用 svn log 可瀏覽 Skia 開發的紀錄,"reed@android.com" 就是 Mike Reed 本人,至今仍相當活躍地改良 Skia 的實做。編譯方式很單純,先看看說明:(本文對應於 svn r130)
# cd skia-trunk # make help可得到以下說明:
Targets:
: out/libskia.a
bench: out/bench/bench
tests: out/tests/tests
clean: removes entire out/ directory
help: this text
Options: (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)
期望的編譯輸出就是靜態函式庫 out/libskia.a,而 Skia 的內部運算可選擇浮點數與定點 (fixed-point),不過筆者發現,目前尙未能透地選擇,但這不影響我們理解 Skia 的使用與體驗其威力。以筆者使用的 GNU/Linux 來說,可下達以下指令要求編譯:# make SKIA_BUILD_FOR=linux沒意外的話,系統就會乖乖的編譯:
compiling out/src/core/Sk64.o compiling out/src/core/SkAlphaRuns.o compiling out/src/core/SkBitmap.o ...至於編譯 benchmark 程式,則可透過以下指令:
# make SKIA_BUILD_FOR=linux benchbenchmark 程式算是除了 Chromium 之外,最佳的「文件」了,不過 SKia API 本來就簡潔強大,這也不妨礙。執行 benchmark 程式:
./out/bench/bench -o `pwd`陸續會有類似以下的輸出:
running bench polygon running bench lines running bench points running bench rrects3 running bench rrects1 running bench ovals3 running bench ovals1 running bench rects3 running bench rects1 running bench bitmap_index8 running bench bitmap_4444 running bench bitmap_565 running bench bitmap_8888可大概窺知 Skia 涵蓋的範疇,接著筆者就寫個小程式,使用 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; }編譯方式:
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
筆者做了簡要的註解,大概可知曉 Sk 開頭的這些 API 的功用,而上述的範例程式一開始就要求 Skia 配置畫布 (SkCanvas),接著透過一份 SkRect 物件 r,給定 ARGB 的描述,使其有著不同的顏色,再來就是調整向量物件的位移並繪製。正如前文提及,Skia 僅是繪圖引擎,並未如 Cairo 一般廣泛對應到 PDF, X11, GDI 等等底層繪圖裝置,所以為了方便觀察繪圖結果,我們透過 Skia 內建的 image codec 來輸出 PNG 圖檔,所以執行前述編譯後的執行檔 "test-skia",應該會得到以下圖檔:(本無外框與底色,但為了清楚於文章呈現,額外用繪圖軟體追加)
paint.setARGB(255, 0, 255, 0); r.offset(20, 20); canvas.drawRect(r, paint);由於 Skia 與 Cairo 的同質性相當高,也可參照 [Cairo :: documentation] 建立所需的背景知識。
不知道skia的performance能达到多少,还是和Cairo一样很慢
由 lurker0 發表於 March 22, 2009 02:51 PMSkia vs. Cairo 粗略地效能比較,可參考:
https://d.hatena.ne.jp/gyuque/20090211
我以為 jserv 會把它拿來 cmake 化一下 XD
由 Drake 發表於 March 23, 2009 01:59 PM看不懂日文实在是太痛苦了. 最要紧的部分刚好没有英文翻译.从仅有的信息来看,大的纹理拷贝是Cairo快,小的纹理拷贝是SKia快.不知道对不对?
由 lurker0 發表於 March 31, 2009 10:35 PM读了你的诸篇博文,受益匪浅。
能不能拨冗谈谈Webkit是怎么处理事件的?譬如,在一个HTML里有这么一段,
function whichButton(event)
{
if (event.button==2)
{
alert("You clicked the right mouse button!");
}
else
{
alert("You clicked the left mouse button!");
}
}
WebKit是如何捕捉并处理mousedown这个事件的?具体而言,可能有三个问题。
1. WebKit是从哪里得到mousedown这个事件的通知的?具体的源码是哪个class?
2. WebKit是如何确定与事件关联的是哪一个DOM element?
这个问题,我的理解似乎与RenderLayer::hitTest,以及RenderObject::hitTest有关。不知道正确否?
2.1. 为什么要分frontground和background?
2.2. HitTestRequest 和 HitTestResult 分别有什么用?似乎有用的部分通通在Result,那么Request是用来做什么的?
2.3. 如何从RenderObject,对应到DOM element?虽然RenderObject有m_node,但是没有见到怎么具体使用m_node的代码。
3. WebKit是如何解析HTML语句,如,尤其是,如何动态调用whichButton()这样的JS函数库?
多谢!
由 邓侃 發表於 May 6, 2009 05:55 PM移植 skia 到 Linux framebuffer :
https://blog.elleryq.idv.tw/2009/06/skia-and-framebuffer.html
[aguaiNoBook:~/Project/skia-trunk]$ g++ -I./include -I./include/core -I./include/images -Wall -o test-skia test.cc out/src/images/SkImageDecoder_libpng.o out/libskia.a -lpng -lpthread -g
在包含自 ./include/core/SkFixed.h:20 的檔案中,
從 ./include/core/Sk64.h:20,
從 ./include/core/SkBitmap.h:20,
從 test.cc:1:
./include/core/SkTypes.h:21:26: 錯誤: SkUserConfig.h:沒有此一檔案或目錄
找不到耶....
Build 不起來....大人呀最近是不是換架構了???
加上这个就可以了:-I./include/config
由 Fan 發表於 July 28, 2009 09:04 PM感謝 @Fan
由 aguai 發表於 August 27, 2009 01:36 AM/SkFontHost_FreeType.cpp:947: undefined reference to `FT_Init_FreeType'
I got this error when compiling test app. Did anyone know how to fix this?