1*c8dee2aaSAndroid Build Coastguard Worker--- 2*c8dee2aaSAndroid Build Coastguard Workertitle: 'How to capture an SKP file from the Android Framework' 3*c8dee2aaSAndroid Build Coastguard WorkerlinkTitle: 'How to capture an SKP file from the Android Framework' 4*c8dee2aaSAndroid Build Coastguard Worker--- 5*c8dee2aaSAndroid Build Coastguard Worker 6*c8dee2aaSAndroid Build Coastguard Worker## Prerequisites 7*c8dee2aaSAndroid Build Coastguard Worker 8*c8dee2aaSAndroid Build Coastguard WorkerTo set up a newly flashed device for capturing, run the following to make it 9*c8dee2aaSAndroid Build Coastguard Workerpossible for the recording process to write its file: 10*c8dee2aaSAndroid Build Coastguard Worker 11*c8dee2aaSAndroid Build Coastguard Worker``` 12*c8dee2aaSAndroid Build Coastguard Workeradb root 13*c8dee2aaSAndroid Build Coastguard Workeradb remount 14*c8dee2aaSAndroid Build Coastguard Worker``` 15*c8dee2aaSAndroid Build Coastguard Worker 16*c8dee2aaSAndroid Build Coastguard WorkerMSKP files may capture any use of a Skia canvas, and there are two uses in 17*c8dee2aaSAndroid Build Coastguard WorkerAndroid instrumented to capture them. HWUI, which will show the contents of a 18*c8dee2aaSAndroid Build Coastguard Workersingle application, and RenderEngine which will show interleaved buffers from 19*c8dee2aaSAndroid Build Coastguard Workermultiple applications and transitions such as portrait-landscape. 20*c8dee2aaSAndroid Build Coastguard Worker 21*c8dee2aaSAndroid Build Coastguard Worker## Capturing from HWUI 22*c8dee2aaSAndroid Build Coastguard Worker 23*c8dee2aaSAndroid Build Coastguard WorkerSet the capture_skp property to enable (but not start) HWUI capture capability. 24*c8dee2aaSAndroid Build Coastguard WorkerThis will only affect applications started after setting the 25*c8dee2aaSAndroid Build Coastguard Workercapture_skp property so you may have to restart the application you wish to 26*c8dee2aaSAndroid Build Coastguard Workercapture from. 27*c8dee2aaSAndroid Build Coastguard Worker 28*c8dee2aaSAndroid Build Coastguard Worker``` 29*c8dee2aaSAndroid Build Coastguard Workeradb root 30*c8dee2aaSAndroid Build Coastguard Workeradb shell setprop debug.hwui.capture_skp_enabled true 31*c8dee2aaSAndroid Build Coastguard Worker``` 32*c8dee2aaSAndroid Build Coastguard Worker 33*c8dee2aaSAndroid Build Coastguard WorkerThen, each time you want to capture a file: 34*c8dee2aaSAndroid Build Coastguard Worker 35*c8dee2aaSAndroid Build Coastguard WorkerFirst, open the application you will be capturing from. Then, trigger capture 36*c8dee2aaSAndroid Build Coastguard Workerwith the following script from the root of your Android tree. (See 37*c8dee2aaSAndroid Build Coastguard Workerhttps://source.android.com/docs/setup/download.) 38*c8dee2aaSAndroid Build Coastguard Worker 39*c8dee2aaSAndroid Build Coastguard Worker``` 40*c8dee2aaSAndroid Build Coastguard Workerframeworks/base/libs/hwui/tests/scripts/skp-capture.sh PACKAGE_NAME FRAMES 41*c8dee2aaSAndroid Build Coastguard Worker``` 42*c8dee2aaSAndroid Build Coastguard Worker 43*c8dee2aaSAndroid Build Coastguard Worker`PACKAGE_NAME` is the name of the component or app you want to capture, for 44*c8dee2aaSAndroid Build Coastguard Workerexample: **com.google.android.apps.nexuslauncher**. 45*c8dee2aaSAndroid Build Coastguard Worker 46*c8dee2aaSAndroid Build Coastguard Worker`FRAMES` is the number of frames to capture. This is optional and defaults to 1. 47*c8dee2aaSAndroid Build Coastguard Worker 48*c8dee2aaSAndroid Build Coastguard Worker## Capturing from RenderEngine 49*c8dee2aaSAndroid Build Coastguard Worker 50*c8dee2aaSAndroid Build Coastguard WorkerOnce before capturing, run the following from the Android root. 51*c8dee2aaSAndroid Build Coastguard Worker 52*c8dee2aaSAndroid Build Coastguard Worker``` 53*c8dee2aaSAndroid Build Coastguard Workerframeworks/native/libs/renderengine/skia/debug/record.sh rootandsetup 54*c8dee2aaSAndroid Build Coastguard Worker``` 55*c8dee2aaSAndroid Build Coastguard Worker 56*c8dee2aaSAndroid Build Coastguard WorkerTo record all frames that RenderEngine handles over the span of 2 seconds. 57*c8dee2aaSAndroid Build Coastguard Worker 58*c8dee2aaSAndroid Build Coastguard Worker``` 59*c8dee2aaSAndroid Build Coastguard Workerframeworks/native/libs/renderengine/skia/debug/record.sh 2000 60*c8dee2aaSAndroid Build Coastguard Worker``` 61*c8dee2aaSAndroid Build Coastguard Worker 62*c8dee2aaSAndroid Build Coastguard WorkerThe output file is copied to your current working directory when the device is 63*c8dee2aaSAndroid Build Coastguard Workerfinished serializing it. This can take up to 30 seconds. 64*c8dee2aaSAndroid Build Coastguard Worker 65*c8dee2aaSAndroid Build Coastguard WorkerThere is a small chance that the capture script incorrectly detects that the 66*c8dee2aaSAndroid Build Coastguard Workerfile is complete too early and copies a truncated file off the device. 67*c8dee2aaSAndroid Build Coastguard WorkerIt will be unreadable in the debugger. If you suspect this has happened, it's 68*c8dee2aaSAndroid Build Coastguard Workerlikely that you can still retrieve the complete file from the device at 69*c8dee2aaSAndroid Build Coastguard Worker`/data/user/re_skiacapture_*.mskp` 70*c8dee2aaSAndroid Build Coastguard Worker 71*c8dee2aaSAndroid Build Coastguard Worker## Reading the file 72*c8dee2aaSAndroid Build Coastguard Worker 73*c8dee2aaSAndroid Build Coastguard WorkerOpen the resulting file in the [Skia Debugger]. For single frame SKPs, you could 74*c8dee2aaSAndroid Build Coastguard Workeralso use the [Skia Viewer] to view it, or rasterize it with `dm` (see [Skia 75*c8dee2aaSAndroid Build Coastguard WorkerBuild Instructions] for how to build `dm`): 76*c8dee2aaSAndroid Build Coastguard Worker 77*c8dee2aaSAndroid Build Coastguard Worker``` 78*c8dee2aaSAndroid Build Coastguard Workerout/Release/dm --src skp --skps FILENAME.skp -w /tmp --config 8888 gpu pdf --verbose 79*c8dee2aaSAndroid Build Coastguard Workerls -l /tmp/*/skp/FILENAME.skp.* 80*c8dee2aaSAndroid Build Coastguard Worker``` 81*c8dee2aaSAndroid Build Coastguard Worker 82*c8dee2aaSAndroid Build Coastguard Worker[Skia Build Instructions]: /docs/user/build 83*c8dee2aaSAndroid Build Coastguard Worker[Skia Debugger]: https://debugger.skia.org 84*c8dee2aaSAndroid Build Coastguard Worker[Skia Viewer]: /docs/user/sample/viewer/ 85