1cb93a386Sopenharmony_ci---
2cb93a386Sopenharmony_cititle: 'Skia Debugger'
3cb93a386Sopenharmony_cilinkTitle: 'Skia Debugger'
4cb93a386Sopenharmony_ci---
5cb93a386Sopenharmony_ci
6cb93a386Sopenharmony_ci## Introduction
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ciThe Skia Debugger is a graphical tool used to step through and analyze the
9cb93a386Sopenharmony_cicontents of the Skia picture format. The tool is available online at
10cb93a386Sopenharmony_ci[https://debugger.skia.org](https://debugger.skia.org/) or can be run locally.
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ciFeatures:
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ci- Draw command and multiple frame playback
15cb93a386Sopenharmony_ci- Shows the current clip and matrix at any step
16cb93a386Sopenharmony_ci- Zoomed viewer with crosshair for selecting pixels.
17cb93a386Sopenharmony_ci- Breakpoints that stop playback when a pixel's color changes.
18cb93a386Sopenharmony_ci- GPU or CPU backed execution.
19cb93a386Sopenharmony_ci- GPU op bounds visualization
20cb93a386Sopenharmony_ci- Android offscreen layer visualization
21cb93a386Sopenharmony_ci- Shared resource viewer
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_ci<img src="../onlinedebugger.png" style="display: inline-block;" />
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci## User Guide
26cb93a386Sopenharmony_ci
27cb93a386Sopenharmony_ciSKP files can contain a single frame or multiple frames. Single frame files have
28cb93a386Sopenharmony_cithe .skp extension and Multi-frame files have the .mskp extension. In the online
29cb93a386Sopenharmony_cidebugger linked above, Open a [sample mskp file](/docs/dev/tools/calendar.mskp)
30cb93a386Sopenharmony_cior capture one from an android device using the
31cb93a386Sopenharmony_ci[instructions here](https://sites.google.com/a/google.com/skia/android/skp-from-framework).
32cb93a386Sopenharmony_ci
33cb93a386Sopenharmony_ci### Command Playback and Filters
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ciTry playing back the commands within the current frame using the lower play
36cb93a386Sopenharmony_cibutton <img src="../playcommands.png" style="display: inline-block;" />, (the
37cb93a386Sopenharmony_cione not in a circle) You should see the image built up one draw at a time.
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ciMany commands manipulate the matrix or clip but don't make any visible change
40cb93a386Sopenharmony_ciwhen run. Try filtering these out by pasting
41cb93a386Sopenharmony_ci`!drawannotation save restore concat setmatrix cliprect` in to the filter
42cb93a386Sopenharmony_citextbox just below the command playback controls. Press enter to apply the
43cb93a386Sopenharmony_cifilter, and resume playback if it was paused. This will have the effect of
44cb93a386Sopenharmony_cimaking the playback appear to be much faster as there are only 29 commands in
45cb93a386Sopenharmony_cithe first frame of the sample file that pass this filter.
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ciTry pausing command playback and stepping forward and back through the commands
48cb93a386Sopenharmony_ciusing `,` (comma) and `.` (period).
49cb93a386Sopenharmony_ci
50cb93a386Sopenharmony_ci> Filters are case insensitive, and the only supported logical operator is !
51cb93a386Sopenharmony_ci> (not) which applies to the entire filter and is only recognised when it occurs
52cb93a386Sopenharmony_ci> at the beginning.
53cb93a386Sopenharmony_ci
54cb93a386Sopenharmony_ciAny command can be expanded using the
55cb93a386Sopenharmony_ci<img src="../expand.png" style="display: inline-block;" /> icon to see all of
56cb93a386Sopenharmony_cithe parameters that were recorded with that command.
57cb93a386Sopenharmony_ci
58cb93a386Sopenharmony_ciCommands can be disabled or enabled with the checkbox that becomes available
59cb93a386Sopenharmony_ciafter expanding the command's detail view.
60cb93a386Sopenharmony_ci
61cb93a386Sopenharmony_ciJog the command playhead to the end of the list with the
62cb93a386Sopenharmony_ci<img src="../end.png" style="display: inline-block;" /> button.
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ci### Frame playback
65cb93a386Sopenharmony_ci
66cb93a386Sopenharmony_ci<img src="../frameplayback.png" style="display: inline-block;" />
67cb93a386Sopenharmony_ci
68cb93a386Sopenharmony_ciThe sample file contains multiple frames. Use the encircled play button to play
69cb93a386Sopenharmony_ciback the frames. The current frame is indictated by the slider position, and the
70cb93a386Sopenharmony_cislider can be set manually. Frames can be stepped through with `w` (back) and
71cb93a386Sopenharmony_ci`s` forward. `p` pauses or unpauses the frame playback.
72cb93a386Sopenharmony_ci
73cb93a386Sopenharmony_ciNot all frames in a file will have the same number of commands. When the command
74cb93a386Sopenharmony_ciplayhead is left at the end of the list the debugger will play every frame to
75cb93a386Sopenharmony_cithe end of its list. If the command playhead is somewhere in the middle, say
76cb93a386Sopenharmony_ci155, the debugger will try to play every frame to its 155th command.
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_ci### Resources Tab
79cb93a386Sopenharmony_ci
80cb93a386Sopenharmony_ci<img src="../resources.png" style="display: inline-block;" />
81cb93a386Sopenharmony_ci
82cb93a386Sopenharmony_ciAny resources that were referenced by commands in the file appear here. As of
83cb93a386Sopenharmony_ciDec 2019, this only shows images.
84cb93a386Sopenharmony_ci
85cb93a386Sopenharmony_ciAny resource can be selected and viewed. You may find it helpful to toggle the
86cb93a386Sopenharmony_ciLight/Dark setting if you cannot see an image.
87cb93a386Sopenharmony_ci
88cb93a386Sopenharmony_ciImages' names are formatted as `7 @24205864 (99, 99)` where `7` is the index of
89cb93a386Sopenharmony_cithe image as it was saved in the file, `@24205864` is it's address in wasm
90cb93a386Sopenharmony_cimemory, for cross referencing with DrawImage\* commands in the command list
91cb93a386Sopenharmony_ciwhich also show this address, and `(99, 99)` is the size of the image.
92cb93a386Sopenharmony_ci
93cb93a386Sopenharmony_ciThe resource viewer allows a user to determine if an image was not effectively
94cb93a386Sopenharmony_cishared between frames or draw commands. If it occurs more than once in the
95cb93a386Sopenharmony_ciresource tab, then there were multiple copies of it with different generation
96cb93a386Sopenharmony_ciids in the process that recorded the SKP.
97cb93a386Sopenharmony_ci
98cb93a386Sopenharmony_ci### Android Layers
99cb93a386Sopenharmony_ci
100cb93a386Sopenharmony_ci<img src="../layers.png" style="display: inline-block;" />
101cb93a386Sopenharmony_ci
102cb93a386Sopenharmony_ciWhen MSKPs are recorded in Android, Extra information about offscreen hardware
103cb93a386Sopenharmony_cilayers is recorded. The sample google calendar mskp linked above contains this
104cb93a386Sopenharmony_ciinformation. You will find two layers on frame 3.
105cb93a386Sopenharmony_ci
106cb93a386Sopenharmony_ciThere are two kinds of events relevant to recorded android layer use.
107cb93a386Sopenharmony_ci
108cb93a386Sopenharmony_ci1. Draw Events - points when an offscreen surface was drawn to. They may be
109cb93a386Sopenharmony_ci   complete, meaning the clip equalled the surface's size, or partial, meaning
110cb93a386Sopenharmony_ci   the clip was smaller.
111cb93a386Sopenharmony_ci2. Use events - points when the offscreen surface was used as an SkImage in the
112cb93a386Sopenharmony_ci   main surface.
113cb93a386Sopenharmony_ci
114cb93a386Sopenharmony_ciLayers are shown as boxes in the bottom right of the interface when viewing a
115cb93a386Sopenharmony_ciframe where a layer draw event occurred. Each Layer box has two buttons:
116cb93a386Sopenharmony_ci`Show Use` will cycle through use events for that layer in the current frame if
117cb93a386Sopenharmony_cithere are any, and `Inspector` will open the draw event as if it were a single
118cb93a386Sopenharmony_ciframe SKP. you can play back it's commands, enable or disabled them, inspect GPU
119cb93a386Sopenharmony_ciop bounds or anything else you could do with an ordinary SKP. Exit the inspector
120cb93a386Sopenharmony_ciby clicking the `Exit` button on the layer box.
121cb93a386Sopenharmony_ci
122cb93a386Sopenharmony_ci### Crosshair and Breakpoints
123cb93a386Sopenharmony_ci
124cb93a386Sopenharmony_ci<img src="../crosshair.png" style="display: inline-block;" />
125cb93a386Sopenharmony_ci
126cb93a386Sopenharmony_ciClicking any point in the main view will toggle a red crosshair for selecting
127cb93a386Sopenharmony_cipixels. the selected pixel's color is shown in several formats on the right
128cb93a386Sopenharmony_cipane. A zoomed view centered on the selected pixel is shown below it. The
129cb93a386Sopenharmony_ciposition can be moved precicely by either clicking neighboring pixels in the
130cb93a386Sopenharmony_cizoom view, or using `H` (left) `L` (right) `J` (down) `K` (up).
131cb93a386Sopenharmony_ci
132cb93a386Sopenharmony_ciWhen "Break on change" is selected, command playback will pause on any command
133cb93a386Sopenharmony_ciwhich changes the color of the selected pixel. this can be used to find the
134cb93a386Sopenharmony_cicommand that draws something you see in the viewer.
135cb93a386Sopenharmony_ci
136cb93a386Sopenharmony_ci### GPU Op Bounds and Other settings
137cb93a386Sopenharmony_ci
138cb93a386Sopenharmony_ci<img src="../settings.png" style="display: inline-block;" />
139cb93a386Sopenharmony_ci
140cb93a386Sopenharmony_ciEach of the filtered commands from above has a colored number to its right
141cb93a386Sopenharmony_ci<img src="../gpuop.png" style="display: inline-block;" />. This is the GPU
142cb93a386Sopenharmony_cioperation id. When multiple commands share a GPU op id, this indicates that they
143cb93a386Sopenharmony_ciwere batched together when sent to the GPU. In the WASM debugger, this goes
144cb93a386Sopenharmony_cithough WebGL.
145cb93a386Sopenharmony_ci
146cb93a386Sopenharmony_ciThere is a "Display GPU Op Bounds" toggle in the upper right of the interface.
147cb93a386Sopenharmony_ciTurning this on will show a colored rectangle to represent the bounds of the GPU
148cb93a386Sopenharmony_ciop of the currently selected command.
149cb93a386Sopenharmony_ci
150cb93a386Sopenharmony_ciGPU - Controls which backend Skia uses to draw to the screen. GPU in the online
151cb93a386Sopenharmony_ciwasm debugger means WebGL. CPU means skia draws into a surface in memory which
152cb93a386Sopenharmony_ciis copied into an HTML canvas without using the GPU.
153cb93a386Sopenharmony_ci
154cb93a386Sopenharmony_ciLight/Dark - this toggle changes the appearance of the checkerboard behind the
155cb93a386Sopenharmony_cimain view and zoom views to assist in viewing content with transparency.
156cb93a386Sopenharmony_ci
157cb93a386Sopenharmony_ciDisplay Overdraw Viz - This vizualization shows a red overlay that is darker in
158cb93a386Sopenharmony_cipropertion to how much overdraw has occurred on a pixel. Overdraw meaning that
159cb93a386Sopenharmony_cithe pixel was drawn to more than once.
160cb93a386Sopenharmony_ci
161cb93a386Sopenharmony_ci- As of Dec 2019, this feature may not be working correctly.
162cb93a386Sopenharmony_ci
163cb93a386Sopenharmony_ci### Image fit and download buttons.
164cb93a386Sopenharmony_ci
165cb93a386Sopenharmony_ci<img src="../settings.png" style="display: inline-block;" />
166cb93a386Sopenharmony_ci
167cb93a386Sopenharmony_ciThese buttons resize the main view. they are, from left to right:
168cb93a386Sopenharmony_ci
169cb93a386Sopenharmony_ciOriginal size - the natural size of the canvas, when it was recorded. Fit to
170cb93a386Sopenharmony_cipage - shrink enough that the whole canvas fits in the center pane. Fit to page
171cb93a386Sopenharmony_ciwidth - make the canvas fit horizontally but allow scrolling vertically Fit to
172cb93a386Sopenharmony_cipage height - make the canvas fit vertically but allow scrolling horizontally.
173cb93a386Sopenharmony_ci
174cb93a386Sopenharmony_cinext to these is a 5th, unrelated download button which saves the current canvas
175cb93a386Sopenharmony_cias a PNG file.
176cb93a386Sopenharmony_ci
177cb93a386Sopenharmony_ci## Building and running locally
178cb93a386Sopenharmony_ci
179cb93a386Sopenharmony_ciBegin by following the instructions to
180cb93a386Sopenharmony_ci[download and build Skia](/docs/user/build). Next, you'll need Skia's infrastructure repository,
181cb93a386Sopenharmony_ciwhich can be downloaded with
182cb93a386Sopenharmony_ci
183cb93a386Sopenharmony_ci<!--?prettify lang=sh?-->
184cb93a386Sopenharmony_ci    git clone https://skia.googlesource.com/buildbot
185cb93a386Sopenharmony_ci
186cb93a386Sopenharmony_ciSee further instructions in buildbot/debugger-app/README.md.
187