blob: 967146f5042b72d31e3f191167a69122448c02eb [file] [log] [blame] [view]
jcgregorio942262f2015-01-05 11:17:27 -08001Tips & FAQ
2==========
3
halcanaryb5002392015-11-16 07:37:23 -08004<span id="gypdefines"></span>
5
6Gyp Options
7-----------
8
9When running `sync-and-gyp`, the `GYP_DEFINES` environment variable can
10be used to change Skias compile-time settings, using a
11space-separated list of key=value pairs. For example, to disable both
12the Skia GPU backend and PDF backends, run it as follows:
13
14<!--?prettify lang=sh?-->
15
16 GYP_DEFINES='skia_gpu=0 skia_pdf=0' python bin/sync-and-gyp
17 ninja -C out/Debug
18
19Note: Setting enviroment variables in the Windows CMD.EXE shell [uses a
20different syntax](/user/quick/windows#env).
21
22You can also set environment variables such as `CC`, `CXX`,
kjlubick222b30d2015-12-03 09:20:55 -080023`CFLAGS`, `CXXFLAGS`, or `CPPFLAGS` to control how Skia is compiled.
24To build with clang, for example:
halcanaryb5002392015-11-16 07:37:23 -080025
26<!--?prettify lang=sh?-->
27
28 CC='clang' CXX='clang++' python bin/sync-and-gyp
29 ninja -C out/Debug
30
kjlubick222b30d2015-12-03 09:20:55 -080031To build with clang and enable a compiler warning for unused parameters in C++
32(but not C or assembly) code:
33
34<!--?prettify lang=sh?-->
35
36 CXXFLAGS='-Wunused-parameter'
37 CC='clang' CXX='clang++' python bin/sync-and-gyp
38 ninja -C out/Debug
39
40
halcanaryb5002392015-11-16 07:37:23 -080041The `GYP_GENERATORS` environment variable can be used to set the
42build systems that you want to use (as a comma-separated list).
43The default is `'ninja,msvs-ninja'` on Windows, `'ninja,xcode'` on
44Mac OS X, and just `'ninja'` on Linux. For example, to generate
45only Ninja files on Mac:
46
47<!--?prettify lang=sh?-->
48
49 GYP_GENERATORS='ninja' python bin/sync-and-gyp
50 ninja -C out/Debug
51
52Finally, the `SKIA_OUT` environment variable can be used to set
53the path for the build directory. The default is `out` inside the
54top-level Skia source directory. For example to test Skia with
55two different compilers:
56
57<!--?prettify lang=sh?-->
58
59 CC='clang' CXX='clang++' SKIA_OUT=~/build/skia_clang python bin/sync-and-gyp
60 CC='gcc' CXX='g++' SKIA_OUT=~/build/skia_gcc python bin/sync-and-gyp
61 ninja -C ~/build/skia_clang/Debug
62 ninja -C ~/build/skia_gcc/Debug
63
64* * *
jcgregorio942262f2015-01-05 11:17:27 -080065
halcanary8d3f7bd2015-07-09 06:58:06 -070066<span id="bitmap-subsetting"></span>
67
halcanaryb5002392015-11-16 07:37:23 -080068Bitmap Subsetting
69-----------------
jcgregorio942262f2015-01-05 11:17:27 -080070
71Taking a subset of a bitmap is effectively free - no pixels are copied or
72memory is allocated. This allows Skia to offer an API that typically operates
73on entire bitmaps; clients who want to operate on a subset of a bitmap can use
74the following pattern, here being used to magnify a portion of an image with
75drawBitmapNine():
76
77 SkBitmap subset;
78 bitmap.extractSubset(&subset, rect);
79 canvas->drawBitmapNine(subset, ...);
80
halcanary8d3f7bd2015-07-09 06:58:06 -070081* * *
82
83<span id="skp-capture"></span>
84
halcanaryb5002392015-11-16 07:37:23 -080085Capture a `.skp` file on a web page in Chromium
86-----------------------------------------------
halcanary8d3f7bd2015-07-09 06:58:06 -070087
halcanary5f0b0ad2015-07-08 10:56:01 -0700881. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
892. Open the JS console (ctrl-shift-J)
903. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')`
91 This returns "undefined" on success.
92
halcanary8d3f7bd2015-07-09 06:58:06 -070093Open the resulting file in the Skia Debugger, rasterize it with `dm`,
94or use Skia's `SampleApp` to view it:
95
96<!--?prettify lang=sh?-->
halcanary5f0b0ad2015-07-08 10:56:01 -070097
98 bin/sync-and-gyp
halcanary8d3f7bd2015-07-09 06:58:06 -070099 ninja -C out/Release debugger dm SampleApp
halcanary5f0b0ad2015-07-08 10:56:01 -0700100 out/Release/debugger /tmp/layer_0.skp &
101
halcanary5f0b0ad2015-07-08 10:56:01 -0700102 out/Release/dm --src skp --skps /tmp/layer_0.skp -w /tmp \
103 --config 8888 gpu pdf --verbose
104 ls -l /tmp/*/skp/layer_0.skp.*
105
halcanary8d3f7bd2015-07-09 06:58:06 -0700106 out/Release/SampleApp --picture /tmp/layer_0.skp
halcanary8d3f7bd2015-07-09 06:58:06 -0700107
108* * *
109
halcanary8d3f7bd2015-07-09 06:58:06 -0700110<span id="hw-acceleration"></span>
jcgregorio942262f2015-01-05 11:17:27 -0800111
halcanaryb5002392015-11-16 07:37:23 -0800112How to add hardware acceleration in Skia
113----------------------------------------
jcgregorio942262f2015-01-05 11:17:27 -0800114
halcanaryb5002392015-11-16 07:37:23 -0800115There are two ways Skia takes advantage of specific hardware.
jcgregorio942262f2015-01-05 11:17:27 -0800116
halcanaryb5002392015-11-16 07:37:23 -08001171. Subclass SkCanvas
jcgregorio942262f2015-01-05 11:17:27 -0800118
halcanaryb5002392015-11-16 07:37:23 -0800119 Since all drawing calls go through SkCanvas, those calls can be
120 redirected to a different graphics API. SkGLCanvas has been
121 written to direct its drawing calls to OpenGL. See src/gl/
jcgregorio942262f2015-01-05 11:17:27 -0800122
halcanaryb5002392015-11-16 07:37:23 -08001232. Custom bottleneck routines
jcgregorio942262f2015-01-05 11:17:27 -0800124
halcanaryb5002392015-11-16 07:37:23 -0800125 There are sets of bottleneck routines inside the blits of Skia
126 that can be replace on a platform in order to take advantage of
127 specific CPU features. One such example is the NEON SIMD
128 instructions on ARM v7 devices. See src/opts/
jcgregorio942262f2015-01-05 11:17:27 -0800129
halcanary8d3f7bd2015-07-09 06:58:06 -0700130* * *
131
132<span id="font-hinting"></span>
133
halcanaryb5002392015-11-16 07:37:23 -0800134Does Skia support Font hinting?
135-------------------------------
jcgregorio942262f2015-01-05 11:17:27 -0800136
137Skia has a built-in font cache, but it does not know how to actual render font
138files like TrueType? into its cache. For that it relies on the platform to
139supply an instance of SkScalerContext?. This is Skia's abstract interface for
140communicating with a font scaler engine. In src/ports you can see support
141files for FreeType?, Mac OS X, and Windows GDI font engines. Other font
142engines can easily be supported in a like manner.
143
144