blob: 6357c80e3fbfa508aa3e0b4a9b865cc4dc9addef [file] [log] [blame] [view]
jcgregorio942262f2015-01-05 11:17:27 -08001Tips & FAQ
2==========
3
4Tips and Tricks
5---------------
6
halcanary8d3f7bd2015-07-09 06:58:06 -07007<span id="bitmap-subsetting"></span>
8
jcgregorio942262f2015-01-05 11:17:27 -08009### Bitmap Subsetting
10
11Taking a subset of a bitmap is effectively free - no pixels are copied or
12memory is allocated. This allows Skia to offer an API that typically operates
13on entire bitmaps; clients who want to operate on a subset of a bitmap can use
14the following pattern, here being used to magnify a portion of an image with
15drawBitmapNine():
16
17 SkBitmap subset;
18 bitmap.extractSubset(&subset, rect);
19 canvas->drawBitmapNine(subset, ...);
20
halcanary8d3f7bd2015-07-09 06:58:06 -070021* * *
22
23<span id="skp-capture"></span>
24
halcanary5f0b0ad2015-07-08 10:56:01 -070025### Capturing a `.skp` file on a web page in Chromium.
26
halcanary8d3f7bd2015-07-09 06:58:06 -070027
halcanary5f0b0ad2015-07-08 10:56:01 -0700281. Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
292. Open the JS console (ctrl-shift-J)
303. Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')`
31 This returns "undefined" on success.
32
halcanary8d3f7bd2015-07-09 06:58:06 -070033Open the resulting file in the Skia Debugger, rasterize it with `dm`,
34or use Skia's `SampleApp` to view it:
35
36<!--?prettify lang=sh?-->
halcanary5f0b0ad2015-07-08 10:56:01 -070037
38 bin/sync-and-gyp
halcanary8d3f7bd2015-07-09 06:58:06 -070039 ninja -C out/Release debugger dm SampleApp
halcanary5f0b0ad2015-07-08 10:56:01 -070040 out/Release/debugger /tmp/layer_0.skp &
41
halcanary5f0b0ad2015-07-08 10:56:01 -070042 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
halcanary8d3f7bd2015-07-09 06:58:06 -070046 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
jcgregorio942262f2015-01-05 11:17:27 -080052FAQ
53---
54
halcanary8d3f7bd2015-07-09 06:58:06 -070055<span id="hw-acceleration"></span>
jcgregorio942262f2015-01-05 11:17:27 -080056
halcanary8d3f7bd2015-07-09 06:58:06 -070057### Does Skia support HW acceleration?
jcgregorio942262f2015-01-05 11:17:27 -080058
59There are two ways Skia can take advantage of HW.
60
611. Subclass SkCanvas
62
63Since all drawing calls go through SkCanvas, those calls can be redirected to
64a different graphics API. SkGLCanvas has been written to direct its drawing
65calls to OpenGL. See src/gl/
66
672. Custom bottleneck routines
68
69There are sets of bottleneck routines inside the blits of Skia that can be
70replace on a platform in order to take advantage of specific CPU features. One
71such example is the NEON SIMD instructions on ARM v7 devices. See src/opts/
72
halcanary8d3f7bd2015-07-09 06:58:06 -070073* * *
74
75<span id="font-hinting"></span>
76
jcgregorio942262f2015-01-05 11:17:27 -080077### Does Skia support Font hinting?
78
79Skia has a built-in font cache, but it does not know how to actual render font
80files like TrueType? into its cache. For that it relies on the platform to
81supply an instance of SkScalerContext?. This is Skia's abstract interface for
82communicating with a font scaler engine. In src/ports you can see support
83files for FreeType?, Mac OS X, and Windows GDI font engines. Other font
84engines can easily be supported in a like manner.
85
86