jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 1 | Tips & FAQ |
| 2 | ========== |
| 3 | |
| 4 | Tips and Tricks |
| 5 | --------------- |
| 6 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 7 | <span id="bitmap-subsetting"></span> |
| 8 | |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 9 | ### Bitmap Subsetting |
| 10 | |
| 11 | Taking a subset of a bitmap is effectively free - no pixels are copied or |
| 12 | memory is allocated. This allows Skia to offer an API that typically operates |
| 13 | on entire bitmaps; clients who want to operate on a subset of a bitmap can use |
| 14 | the following pattern, here being used to magnify a portion of an image with |
| 15 | drawBitmapNine(): |
| 16 | |
| 17 | SkBitmap subset; |
| 18 | bitmap.extractSubset(&subset, rect); |
| 19 | canvas->drawBitmapNine(subset, ...); |
| 20 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 21 | * * * |
| 22 | |
| 23 | <span id="skp-capture"></span> |
| 24 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 25 | ### Capturing a `.skp` file on a web page in Chromium. |
| 26 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 27 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 28 | 1. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking` |
| 29 | 2. Open the JS console (ctrl-shift-J) |
| 30 | 3. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')` |
| 31 | This returns "undefined" on success. |
| 32 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 33 | Open the resulting file in the Skia Debugger, rasterize it with `dm`, |
| 34 | or use Skia's `SampleApp` to view it: |
| 35 | |
| 36 | <!--?prettify lang=sh?--> |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 37 | |
| 38 | bin/sync-and-gyp |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 39 | ninja -C out/Release debugger dm SampleApp |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 40 | out/Release/debugger /tmp/layer_0.skp & |
| 41 | |
halcanary | 5f0b0ad | 2015-07-08 10:56:01 -0700 | [diff] [blame] | 42 | out/Release/dm --src skp --skps /tmp/layer_0.skp -w /tmp \ |
| 43 | --config 8888 gpu pdf --verbose |
| 44 | ls -l /tmp/*/skp/layer_0.skp.* |
| 45 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 46 | out/Release/SampleApp --picture /tmp/layer_0.skp |
| 47 | # On MacOS, SampleApp is a bundle: |
| 48 | open out/Release/SampleApp.app --args --picture /tmp/layer_0.skp |
| 49 | |
| 50 | * * * |
| 51 | |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 52 | FAQ |
| 53 | --- |
| 54 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 55 | <span id="hw-acceleration"></span> |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 56 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 57 | ### Does Skia support HW acceleration? |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 58 | |
| 59 | There are two ways Skia can take advantage of HW. |
| 60 | |
| 61 | 1. Subclass SkCanvas |
| 62 | |
| 63 | Since all drawing calls go through SkCanvas, those calls can be redirected to |
| 64 | a different graphics API. SkGLCanvas has been written to direct its drawing |
| 65 | calls to OpenGL. See src/gl/ |
| 66 | |
| 67 | 2. Custom bottleneck routines |
| 68 | |
| 69 | There are sets of bottleneck routines inside the blits of Skia that can be |
| 70 | replace on a platform in order to take advantage of specific CPU features. One |
| 71 | such example is the NEON SIMD instructions on ARM v7 devices. See src/opts/ |
| 72 | |
halcanary | 8d3f7bd | 2015-07-09 06:58:06 -0700 | [diff] [blame^] | 73 | * * * |
| 74 | |
| 75 | <span id="font-hinting"></span> |
| 76 | |
jcgregorio | 942262f | 2015-01-05 11:17:27 -0800 | [diff] [blame] | 77 | ### Does Skia support Font hinting? |
| 78 | |
| 79 | Skia has a built-in font cache, but it does not know how to actual render font |
| 80 | files like TrueType? into its cache. For that it relies on the platform to |
| 81 | supply an instance of SkScalerContext?. This is Skia's abstract interface for |
| 82 | communicating with a font scaler engine. In src/ports you can see support |
| 83 | files for FreeType?, Mac OS X, and Windows GDI font engines. Other font |
| 84 | engines can easily be supported in a like manner. |
| 85 | |
| 86 | |