1*c8dee2aaSAndroid Build Coastguard Worker 2*c8dee2aaSAndroid Build Coastguard Worker--- 3*c8dee2aaSAndroid Build Coastguard Workertitle: "Skia Viewer" 4*c8dee2aaSAndroid Build Coastguard WorkerlinkTitle: "Skia Viewer" 5*c8dee2aaSAndroid Build Coastguard Worker 6*c8dee2aaSAndroid Build Coastguard Worker--- 7*c8dee2aaSAndroid Build Coastguard Worker 8*c8dee2aaSAndroid Build Coastguard WorkerThe Skia Viewer displays a series of slides that exhibit specific features of Skia, including the Skia GMs and programmed samples that allow interaction. In addition, the Viewer is used to debug and understand different parts of the Skia system: 9*c8dee2aaSAndroid Build Coastguard Worker 10*c8dee2aaSAndroid Build Coastguard Worker* Observe rendering performance - placing the Viewer in stats mode displays average frame times. 11*c8dee2aaSAndroid Build Coastguard Worker* Try different rendering methods - it's possible to cycle among the three rendering methods: raster, OpenGL and Vulkan (on supported platforms). You can use this with stats mode to see the effect that the different rendering methods have on drawing performance. 12*c8dee2aaSAndroid Build Coastguard Worker* Display and manipulate your own pictures. 13*c8dee2aaSAndroid Build Coastguard Worker 14*c8dee2aaSAndroid Build Coastguard WorkerSome slides require resources stored outside the program. These resources are stored in the `<skia-path>/resources` directory. 15*c8dee2aaSAndroid Build Coastguard Worker 16*c8dee2aaSAndroid Build Coastguard WorkerLinux, Macintosh and Windows 17*c8dee2aaSAndroid Build Coastguard Worker---------------------------- 18*c8dee2aaSAndroid Build Coastguard Worker 19*c8dee2aaSAndroid Build Coastguard WorkerThe Viewer can be built using the regular GN build process, e.g. 20*c8dee2aaSAndroid Build Coastguard Worker 21*c8dee2aaSAndroid Build Coastguard Worker bin/gn gen out/Release --args='is_debug=false' 22*c8dee2aaSAndroid Build Coastguard Worker ninja -C out/Release viewer 23*c8dee2aaSAndroid Build Coastguard Worker 24*c8dee2aaSAndroid Build Coastguard WorkerTo load resources in the desktop Viewers, use the `--resourcePath` option: 25*c8dee2aaSAndroid Build Coastguard Worker 26*c8dee2aaSAndroid Build Coastguard Worker <skia-path>/out/Release/viewer --resourcePath <skia-path>/resources 27*c8dee2aaSAndroid Build Coastguard Worker 28*c8dee2aaSAndroid Build Coastguard WorkerSimilarly, `--skps <skp-file-path>` will load any `.skp` files in that directory 29*c8dee2aaSAndroid Build Coastguard Workerfor display within the Viewer. 30*c8dee2aaSAndroid Build Coastguard Worker 31*c8dee2aaSAndroid Build Coastguard WorkerOther useful command-line options: using `--match <pattern>` will load only SKPs or slides 32*c8dee2aaSAndroid Build Coastguard Workermatching that name; using `--slide <name>` will launch at that slide; and you can start up 33*c8dee2aaSAndroid Build Coastguard Workerwith a particular rendering method by using `--backend`, i.e., `--backend sw`, `--backend gl`, 34*c8dee2aaSAndroid Build Coastguard Worker`--backend vk`, or `--backend mtl`. 35*c8dee2aaSAndroid Build Coastguard Worker 36*c8dee2aaSAndroid Build Coastguard WorkerThe desktop Viewers are controlled using the keyboard and mouse: left (←) and right 37*c8dee2aaSAndroid Build Coastguard Worker(→) arrows to move from slide to slide; up (↑) and down (↓) arrows to 38*c8dee2aaSAndroid Build Coastguard Workerzoom in and out; clicking and dragging will translate. Other display options and a slide 39*c8dee2aaSAndroid Build Coastguard Workerpicker can be found in the Tools UI, which can be toggled by hitting the spacebar. 40*c8dee2aaSAndroid Build Coastguard Worker 41*c8dee2aaSAndroid Build Coastguard WorkerKey | Action 42*c8dee2aaSAndroid Build Coastguard Worker-------|------------- 43*c8dee2aaSAndroid Build Coastguard Worker← → | Move between the slides 44*c8dee2aaSAndroid Build Coastguard Worker↑ ↓ | Zoom in / out 45*c8dee2aaSAndroid Build Coastguard Workerd | Change render methods among raster, OpenGL and Vulkan 46*c8dee2aaSAndroid Build Coastguard Workers | Display rendering times and graph 47*c8dee2aaSAndroid Build Coastguard WorkerSpace | Toggle display of Tools UI 48*c8dee2aaSAndroid Build Coastguard Worker 49*c8dee2aaSAndroid Build Coastguard WorkerAndroid 50*c8dee2aaSAndroid Build Coastguard Worker------- 51*c8dee2aaSAndroid Build Coastguard Worker 52*c8dee2aaSAndroid Build Coastguard WorkerTo build Viewer as an Android App, first follow the 53*c8dee2aaSAndroid Build Coastguard Worker[Android build instructions](/docs/user/build#android) to set up the 54*c8dee2aaSAndroid Build Coastguard WorkerAndroid NDK and a ninja out directory. In addition, you will need the 55*c8dee2aaSAndroid Build Coastguard Worker[Android SDK](https://developer.android.com/studio/#command-tools) installed and your 56*c8dee2aaSAndroid Build Coastguard Worker`ANDROID_HOME` environment variable set. 57*c8dee2aaSAndroid Build Coastguard Worker 58*c8dee2aaSAndroid Build Coastguard Worker mkdir ~/android-sdk 59*c8dee2aaSAndroid Build Coastguard Worker ( cd ~/android-sdk; unzip ~/Downloads/sdk-tools-*.zip ) 60*c8dee2aaSAndroid Build Coastguard Worker yes | ~/android-sdk/tools/bin/sdkmanager --licenses 61*c8dee2aaSAndroid Build Coastguard Worker export ANDROID_HOME=~/android-sdk # Or wherever you installed the Android SDK. 62*c8dee2aaSAndroid Build Coastguard Worker 63*c8dee2aaSAndroid Build Coastguard WorkerIf you are not using the NDK included with the Android SDK (at ~/android-sdk/ndk-bundle 64*c8dee2aaSAndroid Build Coastguard Workerin this example) you'll need to set the environmental variable `ANDROID_NDK_HOME`, e.g., 65*c8dee2aaSAndroid Build Coastguard Worker 66*c8dee2aaSAndroid Build Coastguard Worker export ANDROID_NDK_HOME=/tmp/ndk 67*c8dee2aaSAndroid Build Coastguard Worker 68*c8dee2aaSAndroid Build Coastguard WorkerThe Viewer APK must be built by gradle which can be invoked on the command line 69*c8dee2aaSAndroid Build Coastguard Workerwith the following script: 70*c8dee2aaSAndroid Build Coastguard Worker 71*c8dee2aaSAndroid Build Coastguard Worker platform_tools/android/bin/android_build_app -C <out_dir> viewer 72*c8dee2aaSAndroid Build Coastguard Worker 73*c8dee2aaSAndroid Build Coastguard Workerwhere `<out_dir>` is the ninja out directory (e.g., `out/arm64`) 74*c8dee2aaSAndroid Build Coastguard Workerthat you created. Upon completion of the script the APK 75*c8dee2aaSAndroid Build Coastguard Workercan be found at `<out_dir>/viewer.apk`. Install it with `adb install`. 76*c8dee2aaSAndroid Build Coastguard Worker 77*c8dee2aaSAndroid Build Coastguard WorkerIt is possible to pass additional command line flags like 78*c8dee2aaSAndroid Build Coastguard Worker 79*c8dee2aaSAndroid Build Coastguard Worker adb shell am start -a android.intent.action.MAIN -n org.skia.viewer/org.skia.viewer.ViewerActivity --es args '"--androidndkfonts"' 80*c8dee2aaSAndroid Build Coastguard Worker 81*c8dee2aaSAndroid Build Coastguard Worker### How to Use the App 82*c8dee2aaSAndroid Build Coastguard Worker 83*c8dee2aaSAndroid Build Coastguard WorkerMost app functions (except touch gestures and arrow buttons) are placed in the **left drawer**. 84*c8dee2aaSAndroid Build Coastguard WorkerClick on the upper-left hamburger button to open that drawer. 85*c8dee2aaSAndroid Build Coastguard Worker 86*c8dee2aaSAndroid Build Coastguard Worker#### Switch Slides 87*c8dee2aaSAndroid Build Coastguard Worker 88*c8dee2aaSAndroid Build Coastguard WorkerIn the upper-right corner, there are two arrows: next slide, previous slide. 89*c8dee2aaSAndroid Build Coastguard Worker 90*c8dee2aaSAndroid Build Coastguard WorkerIn the left drawer, you can directly select a slide from a list (spinner). Above that spinner, 91*c8dee2aaSAndroid Build Coastguard Workerthere’s a text filter that applies to the slide list. There are hundreds of slides so if you 92*c8dee2aaSAndroid Build Coastguard Workerknow the slide name, use that filter to quickly locate and show it. 93*c8dee2aaSAndroid Build Coastguard Worker 94*c8dee2aaSAndroid Build Coastguard Worker#### Zoom / Translate 95*c8dee2aaSAndroid Build Coastguard Worker 96*c8dee2aaSAndroid Build Coastguard WorkerWe support touch gestures on the slide so you can drag and pinch to zoom. 97*c8dee2aaSAndroid Build Coastguard Worker 98*c8dee2aaSAndroid Build Coastguard Worker#### Change Backend 99*c8dee2aaSAndroid Build Coastguard Worker 100*c8dee2aaSAndroid Build Coastguard WorkerIn the left drawer, you can select the backend from a list of OpenGL, Vulkan, and Raster. 101*c8dee2aaSAndroid Build Coastguard Worker 102*c8dee2aaSAndroid Build Coastguard Worker#### Softkey / Stats 103*c8dee2aaSAndroid Build Coastguard Worker 104*c8dee2aaSAndroid Build Coastguard WorkerIn the left drawer, there’s a list of softkeys. They correspond to the keyboard commands 105*c8dee2aaSAndroid Build Coastguard Workerof a desktop Viewer app. For example, you can toggle color mode or stats window. These can 106*c8dee2aaSAndroid Build Coastguard Workerbe filtered like the slides. 107*c8dee2aaSAndroid Build Coastguard Worker 108*c8dee2aaSAndroid Build Coastguard WorkerFor animation slides, we also show FPS (actually, it’s Seconds Per Frame) --- frame 109*c8dee2aaSAndroid Build Coastguard Workerrefresh rate in milliseconds. 110*c8dee2aaSAndroid Build Coastguard Worker 111*c8dee2aaSAndroid Build Coastguard Worker#### Loading resources / skps 112*c8dee2aaSAndroid Build Coastguard Worker 113*c8dee2aaSAndroid Build Coastguard WorkerTODO (https://issues.skia.org/295805469): This used to be possible with the instructions 114*c8dee2aaSAndroid Build Coastguard Workerbelow, but they no longer work on recent versions of Android. 115*c8dee2aaSAndroid Build Coastguard Worker 116*c8dee2aaSAndroid Build Coastguard WorkerTo load resources in the Android Viewer place them in 117*c8dee2aaSAndroid Build Coastguard Worker`/data/local/tmp/resources`; to load SKPs place them in `/data/local/tmp/skps`. 118*c8dee2aaSAndroid Build Coastguard Worker 119*c8dee2aaSAndroid Build Coastguard WorkeriOS 120*c8dee2aaSAndroid Build Coastguard Worker--- 121*c8dee2aaSAndroid Build Coastguard Worker 122*c8dee2aaSAndroid Build Coastguard WorkerViewer on iOS is built using the regular GN process, e.g. 123*c8dee2aaSAndroid Build Coastguard Worker 124*c8dee2aaSAndroid Build Coastguard Worker bin/gn gen out/Release --args='target_os="ios" is_debug=false' 125*c8dee2aaSAndroid Build Coastguard Worker ninja -C out/Release viewer 126*c8dee2aaSAndroid Build Coastguard Worker 127*c8dee2aaSAndroid Build Coastguard WorkerLike other iOS apps it can be deployed either by using something like 128*c8dee2aaSAndroid Build Coastguard Worker[ios-deploy](https://github.com/ios-control/ios-deploy) 129*c8dee2aaSAndroid Build Coastguard Workeror by building within Xcode and launching via the IDE. See the 130*c8dee2aaSAndroid Build Coastguard Worker[iOS build instructions](https://skia.org/docs/user/build#ios) for more information 131*c8dee2aaSAndroid Build Coastguard Workeron managing provisioning profiles for signing and deployment. 132*c8dee2aaSAndroid Build Coastguard Worker 133*c8dee2aaSAndroid Build Coastguard WorkerViewer will 134*c8dee2aaSAndroid Build Coastguard Workerautomatically bundle the `resources` directory in the top-level Skia directory, 135*c8dee2aaSAndroid Build Coastguard Workerand will bundle an `skps` directory if also placed in the Skia directory. 136*c8dee2aaSAndroid Build Coastguard Worker 137*c8dee2aaSAndroid Build Coastguard WorkerOn iOS the Viewer provides basic touch functionality: you can view slides, 138*c8dee2aaSAndroid Build Coastguard Workerswipe between them, pinch-zoom to scale, and translate via panning. There is not 139*c8dee2aaSAndroid Build Coastguard Workeryet support for display options or selecting from a list of slides. 140*c8dee2aaSAndroid Build Coastguard Worker 141