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