jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 1 | Tips & FAQ |
| 2 | ========== |
| 3 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 4 | <span id="gypdefines"></span> |
| 5 | |
| 6 | Gyp Options |
| 7 | ----------- |
| 8 | |
| 9 | When running `sync-and-gyp`, the `GYP_DEFINES` environment variable can |
| 10 | be used to change Skia’s compile-time settings, using a |
| 11 | space-separated list of key=value pairs. For example, to disable both |
| 12 | the 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 | |
| 19 | Note: Setting enviroment variables in the Windows CMD.EXE shell [uses a |
| 20 | different syntax](/user/quick/windows#env). |
| 21 | |
| 22 | You can also set environment variables such as `CC`, `CXX`, |
kjlubick | 222b30d | 2015-12-03 09:20:55 -0800 | [diff] [blame^] | 23 | `CFLAGS`, `CXXFLAGS`, or `CPPFLAGS` to control how Skia is compiled. |
| 24 | To build with clang, for example: |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 25 | |
| 26 | <!--?prettify lang=sh?--> |
| 27 | |
| 28 | CC='clang' CXX='clang++' python bin/sync-and-gyp |
| 29 | ninja -C out/Debug |
| 30 | |
kjlubick | 222b30d | 2015-12-03 09:20:55 -0800 | [diff] [blame^] | 31 | To 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 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 41 | The `GYP_GENERATORS` environment variable can be used to set the |
| 42 | build systems that you want to use (as a comma-separated list). |
| 43 | The default is `'ninja,msvs-ninja'` on Windows, `'ninja,xcode'` on |
| 44 | Mac OS X, and just `'ninja'` on Linux. For example, to generate |
| 45 | only 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 | |
| 52 | Finally, the `SKIA_OUT` environment variable can be used to set |
| 53 | the path for the build directory. The default is `out` inside the |
| 54 | top-level Skia source directory. For example to test Skia with |
| 55 | two 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 | * * * |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 65 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 66 | <span id="bitmap-subsetting"></span> |
| 67 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 68 | Bitmap Subsetting |
| 69 | ----------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 70 | |
| 71 | Taking a subset of a bitmap is effectively free - no pixels are copied or |
| 72 | memory is allocated. This allows Skia to offer an API that typically operates |
| 73 | on entire bitmaps; clients who want to operate on a subset of a bitmap can use |
| 74 | the following pattern, here being used to magnify a portion of an image with |
| 75 | drawBitmapNine(): |
| 76 | |
| 77 | SkBitmap subset; |
| 78 | bitmap.extractSubset(&subset, rect); |
| 79 | canvas->drawBitmapNine(subset, ...); |
| 80 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 81 | * * * |
| 82 | |
| 83 | <span id="skp-capture"></span> |
| 84 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 85 | Capture a `.skp` file on a web page in Chromium |
| 86 | ----------------------------------------------- |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 87 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 88 | 1. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking` |
| 89 | 2. Open the JS console (ctrl-shift-J) |
| 90 | 3. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')` |
| 91 | This returns "undefined" on success. |
| 92 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 93 | Open the resulting file in the Skia Debugger, rasterize it with `dm`, |
| 94 | or use Skia's `SampleApp` to view it: |
| 95 | |
| 96 | <!--?prettify lang=sh?--> |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 97 | |
| 98 | bin/sync-and-gyp |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 99 | ninja -C out/Release debugger dm SampleApp |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 100 | out/Release/debugger /tmp/layer_0.skp & |
| 101 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 102 | 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 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 106 | out/Release/SampleApp --picture /tmp/layer_0.skp |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 107 | |
| 108 | * * * |
| 109 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 110 | <span id="hw-acceleration"></span> |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 111 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 112 | How to add hardware acceleration in Skia |
| 113 | ---------------------------------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 114 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 115 | There are two ways Skia takes advantage of specific hardware. |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 116 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 117 | 1. Subclass SkCanvas |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 118 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 119 | 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/ |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 122 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 123 | 2. Custom bottleneck routines |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 124 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 125 | 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/ |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 129 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 130 | * * * |
| 131 | |
| 132 | <span id="font-hinting"></span> |
| 133 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 134 | Does Skia support Font hinting? |
| 135 | ------------------------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 136 | |
| 137 | Skia has a built-in font cache, but it does not know how to actual render font |
| 138 | files like TrueType? into its cache. For that it relies on the platform to |
| 139 | supply an instance of SkScalerContext?. This is Skia's abstract interface for |
| 140 | communicating with a font scaler engine. In src/ports you can see support |
| 141 | files for FreeType?, Mac OS X, and Windows GDI font engines. Other font |
| 142 | engines can easily be supported in a like manner. |
| 143 | |
| 144 | |