xref: /aosp_15_r20/external/skia/site/docs/user/tips.md (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1---
2title: 'Tips & FAQ'
3linkTitle: 'Tips & FAQ'
4---
5
6## Capture a `.skp` file on a web page in Chromium
7
8Use the script `experimental/tools/web_to_skp` , _or_ do the following:
9
101.  Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
112.  Open the JS console (Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (MacOS))
123.  Execute: `chrome.gpuBenchmarking.printToSkPicture('/tmp')` This returns
13    "undefined" on success.
14
15Open the resulting file in the [Skia Debugger](/docs/dev/tools/debugger),
16rasterize it with `dm`, or use Skia's `viewer` to view it:
17
18<!--?prettify lang=sh?-->
19
20    out/Release/dm --src skp --skps /tmp/layer_0.skp -w /tmp \
21        --config 8888 gpu pdf --verbose
22    ls -l /tmp/*/skp/layer_0.skp.*
23
24    out/Release/viewer --skps /tmp --slide layer_0.skp
25
26---
27
28## Capture a `.mskp` file on a web page in Chromium
29
30Multipage Skia Picture files capture the commands sent to produce PDFs and
31printed documents.
32
33Use the script `experimental/tools/web_to_mskp` , _or_ do the following:
34
351.  Launch Chrome or Chromium with `--no-sandbox --enable-gpu-benchmarking`
362.  Open the JS console (Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (MacOS))
373.  Execute:
38    `chrome.gpuBenchmarking.printPagesToSkPictures('/tmp/filename.mskp')` This
39    returns "undefined" on success.
40
41Open the resulting file in the [Skia Debugger](/docs/dev/tools/debugger) or
42process it with `dm`.
43
44<!--?prettify lang=sh?-->
45
46    experimental/tools/mskp_parser.py /tmp/filename.mskp /tmp/filename.mskp.skp
47    ls -l /tmp/filename.mskp.skp
48    # open filename.mskp.skp in the debugger.
49
50    out/Release/dm --src mskp --mskps /tmp/filename.mskp -w /tmp \
51        --config pdf --verbose
52    ls -l /tmp/pdf/mskp/filename.mskp.pdf
53
54---
55
56## How to add hardware acceleration in Skia
57
58There are two ways Skia takes advantage of specific hardware.
59
601.  Custom bottleneck routines
61
62    There are sets of bottleneck routines inside the blits of Skia that can be
63    replace on a platform in order to take advantage of specific CPU features.
64    One such example is the NEON SIMD instructions on ARM v7 devices. See
65    [src/opts/](https://skia.googlesource.com/skia/+/main/src/opts/)
66
67---
68
69## Does Skia support Font hinting?
70
71Skia has a built-in font cache, but it does not know how to actually render font
72files like TrueType into its cache. For that it relies on the platform to supply
73an instance of `SkScalerContext`. This is Skia's abstract interface for
74communicating with a font scaler engine. In src/ports you can see support files
75for FreeType, macOS, and Windows GDI font engines. Other font engines can easily
76be supported in a like manner.
77
78---
79
80## Does Skia shape text (kerning)?
81
82Shaping is the process that translates a span of Unicode text into a span of
83positioned glyphs with the appropriate typefaces.
84
85Skia does not shape text. Skia provides interfaces to draw glyphs, but does not
86implement a text shaper. Skia's client's often use
87[HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz/) to generate the
88glyphs and their positions, including kerning.
89
90[Here is an example of how to use Skia and HarfBuzz together](https://github.com/aam/skiaex).
91In the example, a `SkTypeface` and a `hb_face_t` are created using the same
92`mmap()`ed `.ttf` font file. The HarfBuzz face is used to shape unicode text
93into a sequence of glyphs and positions, and the `SkTypeface` can then be used
94to draw those glyphs.
95
96---
97
98## How do I add drop shadow on text?
99
100<fiddle-embed-sk name='1ff4da09e515087f7011c7caec2e98ae'></fiddle-embed-sk>
101