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`, |
| 23 | `CFLAGS`, or `CPPFLAGS` to control how Skia is compiled. For |
| 24 | example: |
| 25 | |
| 26 | <!--?prettify lang=sh?--> |
| 27 | |
| 28 | CC='clang' CXX='clang++' python bin/sync-and-gyp |
| 29 | ninja -C out/Debug |
| 30 | |
| 31 | The `GYP_GENERATORS` environment variable can be used to set the |
| 32 | build systems that you want to use (as a comma-separated list). |
| 33 | The default is `'ninja,msvs-ninja'` on Windows, `'ninja,xcode'` on |
| 34 | Mac OS X, and just `'ninja'` on Linux. For example, to generate |
| 35 | only Ninja files on Mac: |
| 36 | |
| 37 | <!--?prettify lang=sh?--> |
| 38 | |
| 39 | GYP_GENERATORS='ninja' python bin/sync-and-gyp |
| 40 | ninja -C out/Debug |
| 41 | |
| 42 | Finally, the `SKIA_OUT` environment variable can be used to set |
| 43 | the path for the build directory. The default is `out` inside the |
| 44 | top-level Skia source directory. For example to test Skia with |
| 45 | two different compilers: |
| 46 | |
| 47 | <!--?prettify lang=sh?--> |
| 48 | |
| 49 | CC='clang' CXX='clang++' SKIA_OUT=~/build/skia_clang python bin/sync-and-gyp |
| 50 | CC='gcc' CXX='g++' SKIA_OUT=~/build/skia_gcc python bin/sync-and-gyp |
| 51 | ninja -C ~/build/skia_clang/Debug |
| 52 | ninja -C ~/build/skia_gcc/Debug |
| 53 | |
| 54 | * * * |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 55 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 56 | <span id="bitmap-subsetting"></span> |
| 57 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 58 | Bitmap Subsetting |
| 59 | ----------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 60 | |
| 61 | Taking a subset of a bitmap is effectively free - no pixels are copied or |
| 62 | memory is allocated. This allows Skia to offer an API that typically operates |
| 63 | on entire bitmaps; clients who want to operate on a subset of a bitmap can use |
| 64 | the following pattern, here being used to magnify a portion of an image with |
| 65 | drawBitmapNine(): |
| 66 | |
| 67 | SkBitmap subset; |
| 68 | bitmap.extractSubset(&subset, rect); |
| 69 | canvas->drawBitmapNine(subset, ...); |
| 70 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 71 | * * * |
| 72 | |
| 73 | <span id="skp-capture"></span> |
| 74 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 75 | Capture a `.skp` file on a web page in Chromium |
| 76 | ----------------------------------------------- |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 77 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 78 | 1. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking` |
| 79 | 2. Open the JS console (ctrl-shift-J) |
| 80 | 3. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')` |
| 81 | This returns "undefined" on success. |
| 82 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 83 | Open the resulting file in the Skia Debugger, rasterize it with `dm`, |
| 84 | or use Skia's `SampleApp` to view it: |
| 85 | |
| 86 | <!--?prettify lang=sh?--> |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 87 | |
| 88 | bin/sync-and-gyp |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 89 | ninja -C out/Release debugger dm SampleApp |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 90 | out/Release/debugger /tmp/layer_0.skp & |
| 91 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 92 | out/Release/dm --src skp --skps /tmp/layer_0.skp -w /tmp \ |
| 93 | --config 8888 gpu pdf --verbose |
| 94 | ls -l /tmp/*/skp/layer_0.skp.* |
| 95 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 96 | out/Release/SampleApp --picture /tmp/layer_0.skp |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 97 | |
| 98 | * * * |
| 99 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 100 | <span id="hw-acceleration"></span> |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 101 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 102 | How to add hardware acceleration in Skia |
| 103 | ---------------------------------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 104 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 105 | There are two ways Skia takes advantage of specific hardware. |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 106 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 107 | 1. Subclass SkCanvas |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 108 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 109 | Since all drawing calls go through SkCanvas, those calls can be |
| 110 | redirected to a different graphics API. SkGLCanvas has been |
| 111 | written to direct its drawing calls to OpenGL. See src/gl/ |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 112 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 113 | 2. Custom bottleneck routines |
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 sets of bottleneck routines inside the blits of Skia |
| 116 | that can be replace on a platform in order to take advantage of |
| 117 | specific CPU features. One such example is the NEON SIMD |
| 118 | instructions on ARM v7 devices. See src/opts/ |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 119 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame] | 120 | * * * |
| 121 | |
| 122 | <span id="font-hinting"></span> |
| 123 | |
halcanary | b500239 | 2015-11-16 07:37:23 -0800 | [diff] [blame] | 124 | Does Skia support Font hinting? |
| 125 | ------------------------------- |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 126 | |
| 127 | Skia has a built-in font cache, but it does not know how to actual render font |
| 128 | files like TrueType? into its cache. For that it relies on the platform to |
| 129 | supply an instance of SkScalerContext?. This is Skia's abstract interface for |
| 130 | communicating with a font scaler engine. In src/ports you can see support |
| 131 | files for FreeType?, Mac OS X, and Windows GDI font engines. Other font |
| 132 | engines can easily be supported in a like manner. |
| 133 | |
| 134 | |