1 2--- 3title: "Skia Viewer" 4linkTitle: "Skia Viewer" 5 6--- 7 8The 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 10* Observe rendering performance - placing the Viewer in stats mode displays average frame times. 11* 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* Display and manipulate your own pictures. 13 14Some slides require resources stored outside the program. These resources are stored in the `<skia-path>/resources` directory. 15 16Linux, Macintosh and Windows 17---------------------------- 18 19The Viewer can be built using the regular GN build process, e.g. 20 21 bin/gn gen out/Release --args='is_debug=false' 22 ninja -C out/Release viewer 23 24To load resources in the desktop Viewers, use the `--resourcePath` option: 25 26 <skia-path>/out/Release/viewer --resourcePath <skia-path>/resources 27 28Similarly, `--skps <skp-file-path>` will load any `.skp` files in that directory 29for display within the Viewer. 30 31Other useful command-line options: using `--match <pattern>` will load only SKPs or slides 32matching that name; using `--slide <name>` will launch at that slide; and you can start up 33with a particular rendering method by using `--backend`, i.e., `--backend sw`, `--backend gl`, 34`--backend vk`, or `--backend mtl`. 35 36The desktop Viewers are controlled using the keyboard and mouse: left (←) and right 37(→) arrows to move from slide to slide; up (↑) and down (↓) arrows to 38zoom in and out; clicking and dragging will translate. Other display options and a slide 39picker can be found in the Tools UI, which can be toggled by hitting the spacebar. 40 41Key | Action 42-------|------------- 43← → | Move between the slides 44↑ ↓ | Zoom in / out 45d | Change render methods among raster, OpenGL and Vulkan 46s | Display rendering times and graph 47Space | Toggle display of Tools UI 48 49Android 50------- 51 52To build Viewer as an Android App, first follow the 53[Android build instructions](/docs/user/build#android) to set up the 54Android NDK and a ninja out directory. In addition, you will need the 55[Android SDK](https://developer.android.com/studio/#command-tools) installed and your 56`ANDROID_HOME` environment variable set. 57 58 mkdir ~/android-sdk 59 ( cd ~/android-sdk; unzip ~/Downloads/sdk-tools-*.zip ) 60 yes | ~/android-sdk/tools/bin/sdkmanager --licenses 61 export ANDROID_HOME=~/android-sdk # Or wherever you installed the Android SDK. 62 63If you are not using the NDK included with the Android SDK (at ~/android-sdk/ndk-bundle 64in this example) you'll need to set the environmental variable `ANDROID_NDK_HOME`, e.g., 65 66 export ANDROID_NDK_HOME=/tmp/ndk 67 68The Viewer APK must be built by gradle which can be invoked on the command line 69with the following script: 70 71 platform_tools/android/bin/android_build_app -C <out_dir> viewer 72 73where `<out_dir>` is the ninja out directory (e.g., `out/arm64`) 74that you created. Upon completion of the script the APK 75can be found at `<out_dir>/viewer.apk`. Install it with `adb install`. 76 77### How to Use the App 78 79Most app functions (except touch gestures and arrow buttons) are placed in the **left drawer**. 80Click on the upper-left hamburger button to open that drawer. 81 82#### Switch Slides 83 84In the upper-right corner, there are two arrows: next slide, previous slide. 85 86In the left drawer, you can directly select a slide from a list (spinner). Above that spinner, 87there’s a text filter that applies to the slide list. There are hundreds of slides so if you 88know the slide name, use that filter to quickly locate and show it. 89 90#### Zoom / Translate 91 92We support touch gestures on the slide so you can drag and pinch to zoom. 93 94#### Change Backend 95 96In the left drawer, you can select the backend from a list of OpenGL, Vulkan, and Raster. 97 98#### Softkey / Stats 99 100In the left drawer, there’s a list of softkeys. They correspond to the keyboard commands 101of a desktop Viewer app. For example, you can toggle color mode or stats window. These can 102be filtered like the slides. 103 104For animation slides, we also show FPS (actually, it’s Seconds Per Frame) --- frame 105refresh rate in milliseconds. 106 107#### Loading resources / skps 108 109TODO (https://issues.skia.org/295805469): This used to be possible with the instructions 110below, but they no longer work on recent versions of Android. 111 112To load resources in the Android Viewer place them in 113`/data/local/tmp/resources`; to load SKPs place them in `/data/local/tmp/skps`. 114 115iOS 116--- 117 118Viewer on iOS is built using the regular GN process, e.g. 119 120 bin/gn gen out/Release --args='target_os="ios" is_debug=false' 121 ninja -C out/Release viewer 122 123Like other iOS apps it can be deployed either by using something like 124[ios-deploy](https://github.com/ios-control/ios-deploy) 125or by building within Xcode and launching via the IDE. See the 126[iOS build instructions](https://skia.org/docs/user/build#ios) for more information 127on managing provisioning profiles for signing and deployment. 128 129Viewer will 130automatically bundle the `resources` directory in the top-level Skia directory, 131and will bundle an `skps` directory if also placed in the Skia directory. 132 133On iOS the Viewer provides basic touch functionality: you can view slides, 134swipe between them, pinch-zoom to scale, and translate via panning. There is not 135yet support for display options or selecting from a list of slides. 136 137