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