1*c8dee2aaSAndroid Build Coastguard Worker--- 2*c8dee2aaSAndroid Build Coastguard Workertitle: 'Skia Debugger' 3*c8dee2aaSAndroid Build Coastguard WorkerlinkTitle: 'Skia Debugger' 4*c8dee2aaSAndroid Build Coastguard Worker--- 5*c8dee2aaSAndroid Build Coastguard Worker 6*c8dee2aaSAndroid Build Coastguard Worker## Introduction 7*c8dee2aaSAndroid Build Coastguard Worker 8*c8dee2aaSAndroid Build Coastguard WorkerThe Skia Debugger is a graphical tool used to step through and analyze the 9*c8dee2aaSAndroid Build Coastguard Workercontents of the Skia picture format. The tool is available online at 10*c8dee2aaSAndroid Build Coastguard Worker[https://debugger.skia.org](https://debugger.skia.org/) or can be run locally. 11*c8dee2aaSAndroid Build Coastguard Worker 12*c8dee2aaSAndroid Build Coastguard WorkerFeatures: 13*c8dee2aaSAndroid Build Coastguard Worker 14*c8dee2aaSAndroid Build Coastguard Worker- Draw command and multiple frame playback 15*c8dee2aaSAndroid Build Coastguard Worker- Shows the current clip and matrix at any step 16*c8dee2aaSAndroid Build Coastguard Worker- Zoomed viewer with crosshair for selecting pixels. 17*c8dee2aaSAndroid Build Coastguard Worker- Breakpoints that stop playback when a pixel's color changes. 18*c8dee2aaSAndroid Build Coastguard Worker- GPU or CPU backed execution. 19*c8dee2aaSAndroid Build Coastguard Worker- GPU op bounds visualization 20*c8dee2aaSAndroid Build Coastguard Worker- Android offscreen layer visualization 21*c8dee2aaSAndroid Build Coastguard Worker- Shared resource viewer 22*c8dee2aaSAndroid Build Coastguard Worker 23*c8dee2aaSAndroid Build Coastguard Worker<img src="../onlinedebugger.png" style="display: inline-block;" /> 24*c8dee2aaSAndroid Build Coastguard Worker 25*c8dee2aaSAndroid Build Coastguard Worker## User Guide 26*c8dee2aaSAndroid Build Coastguard Worker 27*c8dee2aaSAndroid Build Coastguard WorkerSKP files can contain a single frame or multiple frames. Single frame files have 28*c8dee2aaSAndroid Build Coastguard Workerthe .skp extension and Multi-frame files have the .mskp extension. In the online 29*c8dee2aaSAndroid Build Coastguard Workerdebugger linked above, Open a [sample mskp file](/docs/dev/tools/calendar.mskp) 30*c8dee2aaSAndroid Build Coastguard Workeror capture one from an android device using the 31*c8dee2aaSAndroid Build Coastguard Worker[instructions here](https://sites.google.com/a/google.com/skia/android/skp-from-framework). 32*c8dee2aaSAndroid Build Coastguard Worker 33*c8dee2aaSAndroid Build Coastguard Worker### Command Playback and Filters 34*c8dee2aaSAndroid Build Coastguard Worker 35*c8dee2aaSAndroid Build Coastguard WorkerTry playing back the commands within the current frame using the lower play 36*c8dee2aaSAndroid Build Coastguard Workerbutton <img src="../playcommands.png" style="display: inline-block;" />, (the 37*c8dee2aaSAndroid Build Coastguard Workerone not in a circle) You should see the image built up one draw at a time. 38*c8dee2aaSAndroid Build Coastguard Worker 39*c8dee2aaSAndroid Build Coastguard WorkerMany commands manipulate the matrix or clip but don't make any visible change 40*c8dee2aaSAndroid Build Coastguard Workerwhen run. Try filtering these out by pasting 41*c8dee2aaSAndroid Build Coastguard Worker`!drawannotation save restore concat setmatrix cliprect` in to the filter 42*c8dee2aaSAndroid Build Coastguard Workertextbox just below the command playback controls. Press enter to apply the 43*c8dee2aaSAndroid Build Coastguard Workerfilter, and resume playback if it was paused. This will have the effect of 44*c8dee2aaSAndroid Build Coastguard Workermaking the playback appear to be much faster as there are only 29 commands in 45*c8dee2aaSAndroid Build Coastguard Workerthe first frame of the sample file that pass this filter. 46*c8dee2aaSAndroid Build Coastguard Worker 47*c8dee2aaSAndroid Build Coastguard WorkerTry pausing command playback and stepping forward and back through the commands 48*c8dee2aaSAndroid Build Coastguard Workerusing `,` (comma) and `.` (period). 49*c8dee2aaSAndroid Build Coastguard Worker 50*c8dee2aaSAndroid Build Coastguard Worker> Filters are case insensitive, and the only supported logical operator is ! 51*c8dee2aaSAndroid Build Coastguard Worker> (not) which applies to the entire filter and is only recognised when it occurs 52*c8dee2aaSAndroid Build Coastguard Worker> at the beginning. 53*c8dee2aaSAndroid Build Coastguard Worker 54*c8dee2aaSAndroid Build Coastguard WorkerAny command can be expanded using the 55*c8dee2aaSAndroid Build Coastguard Worker<img src="../expand.png" style="display: inline-block;" /> icon to see all of 56*c8dee2aaSAndroid Build Coastguard Workerthe parameters that were recorded with that command. 57*c8dee2aaSAndroid Build Coastguard Worker 58*c8dee2aaSAndroid Build Coastguard WorkerCommands can be disabled or enabled with the checkbox that becomes available 59*c8dee2aaSAndroid Build Coastguard Workerafter expanding the command's detail view. 60*c8dee2aaSAndroid Build Coastguard Worker 61*c8dee2aaSAndroid Build Coastguard WorkerJog the command playhead to the end of the list with the 62*c8dee2aaSAndroid Build Coastguard Worker<img src="../end.png" style="display: inline-block;" /> button. 63*c8dee2aaSAndroid Build Coastguard Worker 64*c8dee2aaSAndroid Build Coastguard Worker### Frame playback 65*c8dee2aaSAndroid Build Coastguard Worker 66*c8dee2aaSAndroid Build Coastguard Worker<img src="../frameplayback.png" style="display: inline-block;" /> 67*c8dee2aaSAndroid Build Coastguard Worker 68*c8dee2aaSAndroid Build Coastguard WorkerThe sample file contains multiple frames. Use the encircled play button to play 69*c8dee2aaSAndroid Build Coastguard Workerback the frames. The current frame is indicated by the slider position, and the 70*c8dee2aaSAndroid Build Coastguard Workerslider can be set manually. Frames can be stepped through with `w` (back) and 71*c8dee2aaSAndroid Build Coastguard Worker`s` forward. `p` pauses or unpauses the frame playback. 72*c8dee2aaSAndroid Build Coastguard Worker 73*c8dee2aaSAndroid Build Coastguard WorkerNot all frames in a file will have the same number of commands. When the command 74*c8dee2aaSAndroid Build Coastguard Workerplayhead is left at the end of the list the debugger will play every frame to 75*c8dee2aaSAndroid Build Coastguard Workerthe end of its list. If the command playhead is somewhere in the middle, say 76*c8dee2aaSAndroid Build Coastguard Worker155, the debugger will try to play every frame to its 155th command. 77*c8dee2aaSAndroid Build Coastguard Worker 78*c8dee2aaSAndroid Build Coastguard Worker### Resources Tab 79*c8dee2aaSAndroid Build Coastguard Worker 80*c8dee2aaSAndroid Build Coastguard Worker<img src="../resources.png" style="display: inline-block;" /> 81*c8dee2aaSAndroid Build Coastguard Worker 82*c8dee2aaSAndroid Build Coastguard WorkerAny resources that were referenced by commands in the file appear here. As of 83*c8dee2aaSAndroid Build Coastguard WorkerDec 2019, this only shows images. 84*c8dee2aaSAndroid Build Coastguard Worker 85*c8dee2aaSAndroid Build Coastguard WorkerAny resource can be selected and viewed. You may find it helpful to toggle the 86*c8dee2aaSAndroid Build Coastguard WorkerLight/Dark setting if you cannot see an image. 87*c8dee2aaSAndroid Build Coastguard Worker 88*c8dee2aaSAndroid Build Coastguard WorkerImages' names are formatted as `7 @24205864 (99, 99)` where `7` is the index of 89*c8dee2aaSAndroid Build Coastguard Workerthe image as it was saved in the file, `@24205864` is it's address in wasm 90*c8dee2aaSAndroid Build Coastguard Workermemory, for cross referencing with DrawImage\* commands in the command list 91*c8dee2aaSAndroid Build Coastguard Workerwhich also show this address, and `(99, 99)` is the size of the image. 92*c8dee2aaSAndroid Build Coastguard Worker 93*c8dee2aaSAndroid Build Coastguard WorkerThe resource viewer allows a user to determine if an image was not effectively 94*c8dee2aaSAndroid Build Coastguard Workershared between frames or draw commands. If it occurs more than once in the 95*c8dee2aaSAndroid Build Coastguard Workerresource tab, then there were multiple copies of it with different generation 96*c8dee2aaSAndroid Build Coastguard Workerids in the process that recorded the SKP. 97*c8dee2aaSAndroid Build Coastguard Worker 98*c8dee2aaSAndroid Build Coastguard Worker### Android Layers 99*c8dee2aaSAndroid Build Coastguard Worker 100*c8dee2aaSAndroid Build Coastguard Worker<img src="../layers.png" style="display: inline-block;" /> 101*c8dee2aaSAndroid Build Coastguard Worker 102*c8dee2aaSAndroid Build Coastguard WorkerWhen MSKPs are recorded in Android, Extra information about offscreen hardware 103*c8dee2aaSAndroid Build Coastguard Workerlayers is recorded. The sample google calendar mskp linked above contains this 104*c8dee2aaSAndroid Build Coastguard Workerinformation. You will find two layers on frame 3. 105*c8dee2aaSAndroid Build Coastguard Worker 106*c8dee2aaSAndroid Build Coastguard WorkerThere are two kinds of events relevant to recorded android layer use. 107*c8dee2aaSAndroid Build Coastguard Worker 108*c8dee2aaSAndroid Build Coastguard Worker1. Draw Events - points when an offscreen surface was drawn to. They may be 109*c8dee2aaSAndroid Build Coastguard Worker complete, meaning the clip equalled the surface's size, or partial, meaning 110*c8dee2aaSAndroid Build Coastguard Worker the clip was smaller. 111*c8dee2aaSAndroid Build Coastguard Worker2. Use events - points when the offscreen surface was used as an SkImage in the 112*c8dee2aaSAndroid Build Coastguard Worker main surface. 113*c8dee2aaSAndroid Build Coastguard Worker 114*c8dee2aaSAndroid Build Coastguard WorkerLayers are shown as boxes in the bottom right of the interface when viewing a 115*c8dee2aaSAndroid Build Coastguard Workerframe where a layer draw event occurred. Each Layer box has two buttons: 116*c8dee2aaSAndroid Build Coastguard Worker`Show Use` will cycle through use events for that layer in the current frame if 117*c8dee2aaSAndroid Build Coastguard Workerthere are any, and `Inspector` will open the draw event as if it were a single 118*c8dee2aaSAndroid Build Coastguard Workerframe SKP. you can play back it's commands, enable or disabled them, inspect GPU 119*c8dee2aaSAndroid Build Coastguard Workerop bounds or anything else you could do with an ordinary SKP. Exit the inspector 120*c8dee2aaSAndroid Build Coastguard Workerby clicking the `Exit` button on the layer box. 121*c8dee2aaSAndroid Build Coastguard Worker 122*c8dee2aaSAndroid Build Coastguard Worker### Crosshair and Breakpoints 123*c8dee2aaSAndroid Build Coastguard Worker 124*c8dee2aaSAndroid Build Coastguard Worker<img src="../crosshair.png" style="display: inline-block;" /> 125*c8dee2aaSAndroid Build Coastguard Worker 126*c8dee2aaSAndroid Build Coastguard WorkerClicking any point in the main view will toggle a red crosshair for selecting 127*c8dee2aaSAndroid Build Coastguard Workerpixels. the selected pixel's color is shown in several formats on the right 128*c8dee2aaSAndroid Build Coastguard Workerpane. A zoomed view centered on the selected pixel is shown below it. The 129*c8dee2aaSAndroid Build Coastguard Workerposition can be moved precisely by either clicking neighboring pixels in the 130*c8dee2aaSAndroid Build Coastguard Workerzoom view, or using `H` (left) `L` (right) `J` (down) `K` (up). 131*c8dee2aaSAndroid Build Coastguard Worker 132*c8dee2aaSAndroid Build Coastguard WorkerWhen "Break on change" is selected, command playback will pause on any command 133*c8dee2aaSAndroid Build Coastguard Workerwhich changes the color of the selected pixel. this can be used to find the 134*c8dee2aaSAndroid Build Coastguard Workercommand that draws something you see in the viewer. 135*c8dee2aaSAndroid Build Coastguard Worker 136*c8dee2aaSAndroid Build Coastguard Worker### GPU Op Bounds and Other settings 137*c8dee2aaSAndroid Build Coastguard Worker 138*c8dee2aaSAndroid Build Coastguard Worker<img src="../settings.png" style="display: inline-block;" /> 139*c8dee2aaSAndroid Build Coastguard Worker 140*c8dee2aaSAndroid Build Coastguard WorkerEach of the filtered commands from above has a colored number to its right 141*c8dee2aaSAndroid Build Coastguard Worker<img src="../gpuop.png" style="display: inline-block;" />. This is the GPU 142*c8dee2aaSAndroid Build Coastguard Workeroperation id. When multiple commands share a GPU op id, this indicates that they 143*c8dee2aaSAndroid Build Coastguard Workerwere batched together when sent to the GPU. In the WASM debugger, this goes 144*c8dee2aaSAndroid Build Coastguard Workerthough WebGL. 145*c8dee2aaSAndroid Build Coastguard Worker 146*c8dee2aaSAndroid Build Coastguard WorkerThere is a "Display GPU Op Bounds" toggle in the upper right of the interface. 147*c8dee2aaSAndroid Build Coastguard WorkerTurning this on will show a colored rectangle to represent the bounds of the GPU 148*c8dee2aaSAndroid Build Coastguard Workerop of the currently selected command. 149*c8dee2aaSAndroid Build Coastguard Worker 150*c8dee2aaSAndroid Build Coastguard WorkerGPU - Controls which backend Skia uses to draw to the screen. GPU in the online 151*c8dee2aaSAndroid Build Coastguard Workerwasm debugger means WebGL. CPU means skia draws into a surface in memory which 152*c8dee2aaSAndroid Build Coastguard Workeris copied into an HTML canvas without using the GPU. 153*c8dee2aaSAndroid Build Coastguard Worker 154*c8dee2aaSAndroid Build Coastguard WorkerLight/Dark - this toggle changes the appearance of the checkerboard behind the 155*c8dee2aaSAndroid Build Coastguard Workermain view and zoom views to assist in viewing content with transparency. 156*c8dee2aaSAndroid Build Coastguard Worker 157*c8dee2aaSAndroid Build Coastguard WorkerDisplay Overdraw Viz - This visualization shows a red overlay that is darker in 158*c8dee2aaSAndroid Build Coastguard Workerproportion to how much overdraw has occurred on a pixel. Overdraw meaning that 159*c8dee2aaSAndroid Build Coastguard Workerthe pixel was drawn to more than once. 160*c8dee2aaSAndroid Build Coastguard Worker 161*c8dee2aaSAndroid Build Coastguard Worker- As of Dec 2019, this feature may not be working correctly. 162*c8dee2aaSAndroid Build Coastguard Worker 163*c8dee2aaSAndroid Build Coastguard Worker### Image fit and download buttons. 164*c8dee2aaSAndroid Build Coastguard Worker 165*c8dee2aaSAndroid Build Coastguard Worker<img src="../settings.png" style="display: inline-block;" /> 166*c8dee2aaSAndroid Build Coastguard Worker 167*c8dee2aaSAndroid Build Coastguard WorkerThese buttons resize the main view. they are, from left to right: 168*c8dee2aaSAndroid Build Coastguard Worker 169*c8dee2aaSAndroid Build Coastguard WorkerOriginal size - the natural size of the canvas, when it was recorded. Fit to 170*c8dee2aaSAndroid Build Coastguard Workerpage - shrink enough that the whole canvas fits in the center pane. Fit to page 171*c8dee2aaSAndroid Build Coastguard Workerwidth - make the canvas fit horizontally but allow scrolling vertically Fit to 172*c8dee2aaSAndroid Build Coastguard Workerpage height - make the canvas fit vertically but allow scrolling horizontally. 173*c8dee2aaSAndroid Build Coastguard Worker 174*c8dee2aaSAndroid Build Coastguard Workernext to these is a 5th, unrelated download button which saves the current canvas 175*c8dee2aaSAndroid Build Coastguard Workeras a PNG file. 176*c8dee2aaSAndroid Build Coastguard Worker 177*c8dee2aaSAndroid Build Coastguard Worker## Building and running locally 178*c8dee2aaSAndroid Build Coastguard Worker 179*c8dee2aaSAndroid Build Coastguard WorkerBegin by following the instructions to 180*c8dee2aaSAndroid Build Coastguard Worker[download and build Skia](/docs/user/build). Next, you'll need Skia's infrastructure repository, 181*c8dee2aaSAndroid Build Coastguard Workerwhich can be downloaded with 182*c8dee2aaSAndroid Build Coastguard Worker 183*c8dee2aaSAndroid Build Coastguard Worker<!--?prettify lang=sh?--> 184*c8dee2aaSAndroid Build Coastguard Worker git clone https://skia.googlesource.com/buildbot 185*c8dee2aaSAndroid Build Coastguard Worker 186*c8dee2aaSAndroid Build Coastguard WorkerSee further instructions in buildbot/debugger-app/README.md. 187*c8dee2aaSAndroid Build Coastguard Worker 188*c8dee2aaSAndroid Build Coastguard Worker## Capturing SKPs 189*c8dee2aaSAndroid Build Coastguard Worker 190*c8dee2aaSAndroid Build Coastguard Worker### Chromium 191*c8dee2aaSAndroid Build Coastguard Worker 192*c8dee2aaSAndroid Build Coastguard WorkerSee https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/saving-skp-s-from-chromium/ 193*c8dee2aaSAndroid Build Coastguard Worker 194*c8dee2aaSAndroid Build Coastguard Worker### Android 195*c8dee2aaSAndroid Build Coastguard Worker 196*c8dee2aaSAndroid Build Coastguard WorkerSee [How to capture an SKP file from the Android framework](/docs/dev/tools/android-capture). 197