blob: 220a48280539b1b5f9ce85b97d023ee9e94105ce [file] [log] [blame]
jvanverth9f372462016-04-06 06:08:59 -07001/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
jvanverth34524262016-05-04 13:49:13 -07008#include "Viewer.h"
jvanverth9f372462016-04-06 06:08:59 -07009
jvanverth2bb3b6d2016-04-08 07:24:09 -070010#include "GMSlide.h"
liyuqian6f163d22016-06-13 12:26:45 -070011#include "ImageSlide.h"
Greg Daniel9fcc7432016-11-29 16:35:19 -050012#include "Resources.h"
jvanverthc7027ab2016-06-16 09:52:35 -070013#include "SampleSlide.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070014#include "SKPSlide.h"
jvanverth9f372462016-04-06 06:08:59 -070015
csmartdalton61cd31a2017-02-27 17:00:53 -070016#include "GrContext.h"
Greg Daniel285db442016-10-14 09:12:53 -040017#include "SkATrace.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070018#include "SkCanvas.h"
Brian Osmana109e392017-02-24 09:49:14 -050019#include "SkColorSpace_Base.h"
Brian Osmane0d4fba2017-03-15 10:24:55 -040020#include "SkColorSpaceXformCanvas.h"
Brian Osman2dd96932016-10-18 15:33:53 -040021#include "SkCommandLineFlags.h"
Brian Osmanf9810662017-08-30 10:02:10 -040022#include "SkCommonFlagsGpuThreads.h"
csmartdalton008b9d82017-02-22 12:00:42 -070023#include "SkCommonFlagsPathRenderer.h"
liyuqian74959a12016-06-16 14:10:34 -070024#include "SkDashPathEffect.h"
Brian Osman53136aa2017-07-20 15:43:35 -040025#include "SkEventTracingPriv.h"
Greg Daniel285db442016-10-14 09:12:53 -040026#include "SkGraphics.h"
Brian Osmanf750fbc2017-02-08 10:47:28 -050027#include "SkImagePriv.h"
liyuqian6f163d22016-06-13 12:26:45 -070028#include "SkMetaData.h"
csmartdalton61cd31a2017-02-27 17:00:53 -070029#include "SkOnce.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070030#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050031#include "SkOSPath.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070032#include "SkRandom.h"
Yuqian Li399b3c22017-08-03 11:08:15 -040033#include "SkScan.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070034#include "SkStream.h"
liyuqian74959a12016-06-16 14:10:34 -070035#include "SkSurface.h"
Brian Osman79086b92017-02-10 13:36:16 -050036#include "SkSwizzle.h"
csmartdalton29d87152017-02-10 17:05:14 -050037#include "SkTaskGroup.h"
liyuqian2edb0f42016-07-06 14:11:32 -070038#include "SkTime.h"
Mike Reed887cdf12017-04-03 11:11:09 -040039#include "SkVertices.h"
jvanverth9f372462016-04-06 06:08:59 -070040
Brian Osman79086b92017-02-10 13:36:16 -050041#include "imgui.h"
42
Chris Dalton1a325d22017-07-14 15:17:41 -060043#include "ccpr/GrCoverageCountingPathRenderer.h"
44
csmartdalton578f0642017-02-24 16:04:47 -070045#include <stdlib.h>
csmartdalton61cd31a2017-02-27 17:00:53 -070046#include <map>
csmartdalton578f0642017-02-24 16:04:47 -070047
jvanverth34524262016-05-04 13:49:13 -070048using namespace sk_app;
49
csmartdalton61cd31a2017-02-27 17:00:53 -070050static std::map<GpuPathRenderers, std::string> gPathRendererNames;
51
jvanverth9f372462016-04-06 06:08:59 -070052Application* Application::Create(int argc, char** argv, void* platformData) {
jvanverth34524262016-05-04 13:49:13 -070053 return new Viewer(argc, argv, platformData);
jvanverth9f372462016-04-06 06:08:59 -070054}
55
Christopher Dalton443ec1b2017-02-24 13:22:53 -070056static void on_backend_created_func(void* userData) {
57 Viewer* vv = reinterpret_cast<Viewer*>(userData);
58
59 return vv->onBackendCreated();
60}
61
jvanverth9f372462016-04-06 06:08:59 -070062static void on_paint_handler(SkCanvas* canvas, void* userData) {
jvanverth34524262016-05-04 13:49:13 -070063 Viewer* vv = reinterpret_cast<Viewer*>(userData);
jvanverth9f372462016-04-06 06:08:59 -070064
65 return vv->onPaint(canvas);
66}
67
jvanverth814e38d2016-06-06 08:48:47 -070068static bool on_touch_handler(intptr_t owner, Window::InputState state, float x, float y, void* userData)
liyuqiand3cdbca2016-05-17 12:44:20 -070069{
70 Viewer* viewer = reinterpret_cast<Viewer*>(userData);
71
72 return viewer->onTouch(owner, state, x, y);
73}
74
liyuqiane5a6cd92016-05-27 08:52:52 -070075static void on_ui_state_changed_handler(const SkString& stateName, const SkString& stateValue, void* userData) {
76 Viewer* viewer = reinterpret_cast<Viewer*>(userData);
77
78 return viewer->onUIStateChanged(stateName, stateValue);
79}
80
Brian Osman79086b92017-02-10 13:36:16 -050081static bool on_mouse_handler(int x, int y, Window::InputState state, uint32_t modifiers,
82 void* userData) {
83 ImGuiIO& io = ImGui::GetIO();
84 io.MousePos.x = static_cast<float>(x);
85 io.MousePos.y = static_cast<float>(y);
86 if (Window::kDown_InputState == state) {
87 io.MouseDown[0] = true;
88 } else if (Window::kUp_InputState == state) {
89 io.MouseDown[0] = false;
90 }
Jim Van Verthe7705782017-05-04 14:00:59 -040091 if (io.WantCaptureMouse) {
92 return true;
93 } else {
94 Viewer* viewer = reinterpret_cast<Viewer*>(userData);
95 return viewer->onMouse(x, y, state, modifiers);
96 }
Brian Osman79086b92017-02-10 13:36:16 -050097}
98
99static bool on_mouse_wheel_handler(float delta, uint32_t modifiers, void* userData) {
100 ImGuiIO& io = ImGui::GetIO();
101 io.MouseWheel += delta;
102 return true;
103}
104
105static bool on_key_handler(Window::Key key, Window::InputState state, uint32_t modifiers,
106 void* userData) {
107 ImGuiIO& io = ImGui::GetIO();
108 io.KeysDown[static_cast<int>(key)] = (Window::kDown_InputState == state);
109
110 if (io.WantCaptureKeyboard) {
111 return true;
112 } else {
113 Viewer* viewer = reinterpret_cast<Viewer*>(userData);
114 return viewer->onKey(key, state, modifiers);
115 }
116}
117
118static bool on_char_handler(SkUnichar c, uint32_t modifiers, void* userData) {
119 ImGuiIO& io = ImGui::GetIO();
120 if (io.WantTextInput) {
121 if (c > 0 && c < 0x10000) {
122 io.AddInputCharacter(c);
123 }
124 return true;
125 } else {
126 Viewer* viewer = reinterpret_cast<Viewer*>(userData);
127 return viewer->onChar(c, modifiers);
128 }
129}
130
Brian Osman2dd96932016-10-18 15:33:53 -0400131static DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
Brian Osman16adfa32016-10-18 14:42:44 -0400132
Brian Osman2dd96932016-10-18 15:33:53 -0400133static DEFINE_string2(match, m, nullptr,
jvanverth2bb3b6d2016-04-08 07:24:09 -0700134 "[~][^]substring[$] [...] of bench name to run.\n"
135 "Multiple matches may be separated by spaces.\n"
136 "~ causes a matching bench to always be skipped\n"
137 "^ requires the start of the bench to match\n"
138 "$ requires the end of the bench to match\n"
139 "^ and $ requires an exact match\n"
140 "If a bench does not match any list entry,\n"
141 "it is skipped unless some list entry starts with ~");
bsalomon6c471f72016-07-26 12:56:32 -0700142
Chris Dalton7a0ebfc2017-10-13 12:35:50 -0600143static DEFINE_string(slide, "", "Start on this sample.");
144static DEFINE_bool(list, false, "List samples?");
Jim Van Verth6f449692017-02-14 15:16:46 -0500145
bsalomon6c471f72016-07-26 12:56:32 -0700146#ifdef SK_VULKAN
jvanverthb8794cc2016-07-27 14:29:18 -0700147# define BACKENDS_STR "\"sw\", \"gl\", and \"vk\""
bsalomon6c471f72016-07-26 12:56:32 -0700148#else
149# define BACKENDS_STR "\"sw\" and \"gl\""
150#endif
151
liyuqian71491dc2016-06-09 12:02:34 -0700152#ifdef SK_BUILD_FOR_ANDROID
Brian Salomon96789b32017-05-26 12:06:21 -0400153static DEFINE_string(skps, "/data/local/tmp/skps", "Directory to read skps from.");
154static DEFINE_string(jpgs, "/data/local/tmp/resources", "Directory to read jpgs from.");
liyuqian71491dc2016-06-09 12:02:34 -0700155#else
Brian Osman2dd96932016-10-18 15:33:53 -0400156static DEFINE_string(skps, "skps", "Directory to read skps from.");
157static DEFINE_string(jpgs, "jpgs", "Directory to read jpgs from.");
liyuqian71491dc2016-06-09 12:02:34 -0700158#endif
jvanverth2bb3b6d2016-04-08 07:24:09 -0700159
Brian Osman2dd96932016-10-18 15:33:53 -0400160static DEFINE_string2(backend, b, "sw", "Backend to use. Allowed values are " BACKENDS_STR ".");
bsalomon6c471f72016-07-26 12:56:32 -0700161
Chris Dalton7a0ebfc2017-10-13 12:35:50 -0600162static DEFINE_int32(msaa, 0, "Number of subpixel samples. 0 for no HW antialiasing.");
163static DEFINE_bool(cachePathMasks, true, "Allows path mask textures to be cached in GPU configs.");
csmartdalton008b9d82017-02-22 12:00:42 -0700164DEFINE_pathrenderer_flag;
165
Chris Dalton7a0ebfc2017-10-13 12:35:50 -0600166static DEFINE_bool(instancedRendering, false, "Enable instanced rendering on GPU backends.");
Brian Osman53136aa2017-07-20 15:43:35 -0400167DECLARE_int32(threads)
Brian Salomon41eac792017-03-08 14:03:56 -0500168
Brian Salomon194db172017-08-17 14:37:06 -0400169const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
csmartdalton578f0642017-02-24 16:04:47 -0700170 "OpenGL",
Brian Salomon194db172017-08-17 14:37:06 -0400171#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
172 "ANGLE",
173#endif
jvanverth063ece72016-06-17 09:29:14 -0700174#ifdef SK_VULKAN
csmartdalton578f0642017-02-24 16:04:47 -0700175 "Vulkan",
jvanverth063ece72016-06-17 09:29:14 -0700176#endif
csmartdalton578f0642017-02-24 16:04:47 -0700177 "Raster"
jvanverthaf236b52016-05-20 06:01:06 -0700178};
179
bsalomon6c471f72016-07-26 12:56:32 -0700180static sk_app::Window::BackendType get_backend_type(const char* str) {
181#ifdef SK_VULKAN
182 if (0 == strcmp(str, "vk")) {
183 return sk_app::Window::kVulkan_BackendType;
184 } else
185#endif
Brian Salomon194db172017-08-17 14:37:06 -0400186#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
187 if (0 == strcmp(str, "angle")) {
188 return sk_app::Window::kANGLE_BackendType;
189 } else
190#endif
bsalomon6c471f72016-07-26 12:56:32 -0700191 if (0 == strcmp(str, "gl")) {
192 return sk_app::Window::kNativeGL_BackendType;
193 } else if (0 == strcmp(str, "sw")) {
194 return sk_app::Window::kRaster_BackendType;
195 } else {
196 SkDebugf("Unknown backend type, %s, defaulting to sw.", str);
197 return sk_app::Window::kRaster_BackendType;
198 }
199}
200
Brian Osmana109e392017-02-24 09:49:14 -0500201static SkColorSpacePrimaries gSrgbPrimaries = {
202 0.64f, 0.33f,
203 0.30f, 0.60f,
204 0.15f, 0.06f,
205 0.3127f, 0.3290f };
206
207static SkColorSpacePrimaries gAdobePrimaries = {
208 0.64f, 0.33f,
209 0.21f, 0.71f,
210 0.15f, 0.06f,
211 0.3127f, 0.3290f };
212
213static SkColorSpacePrimaries gP3Primaries = {
214 0.680f, 0.320f,
215 0.265f, 0.690f,
216 0.150f, 0.060f,
217 0.3127f, 0.3290f };
218
219static SkColorSpacePrimaries gRec2020Primaries = {
220 0.708f, 0.292f,
221 0.170f, 0.797f,
222 0.131f, 0.046f,
223 0.3127f, 0.3290f };
224
225struct NamedPrimaries {
226 const char* fName;
227 SkColorSpacePrimaries* fPrimaries;
228} gNamedPrimaries[] = {
229 { "sRGB", &gSrgbPrimaries },
230 { "AdobeRGB", &gAdobePrimaries },
231 { "P3", &gP3Primaries },
232 { "Rec. 2020", &gRec2020Primaries },
233};
234
235static bool primaries_equal(const SkColorSpacePrimaries& a, const SkColorSpacePrimaries& b) {
236 return memcmp(&a, &b, sizeof(SkColorSpacePrimaries)) == 0;
237}
238
Brian Osman70d2f432017-11-08 09:54:10 -0500239static Window::BackendType backend_type_for_window(Window::BackendType backendType) {
240 // In raster mode, we still use GL for the window.
241 // This lets us render the GUI faster (and correct).
242 return Window::kRaster_BackendType == backendType ? Window::kNativeGL_BackendType : backendType;
243}
244
liyuqiane5a6cd92016-05-27 08:52:52 -0700245const char* kName = "name";
246const char* kValue = "value";
247const char* kOptions = "options";
248const char* kSlideStateName = "Slide";
249const char* kBackendStateName = "Backend";
csmartdalton578f0642017-02-24 16:04:47 -0700250const char* kMSAAStateName = "MSAA";
csmartdalton61cd31a2017-02-27 17:00:53 -0700251const char* kPathRendererStateName = "Path renderer";
Brian Salomon99a33902017-03-07 15:16:34 -0500252const char* kInstancedRenderingStateName = "Instanced rendering";
liyuqianb73c24b2016-06-03 08:47:23 -0700253const char* kSoftkeyStateName = "Softkey";
254const char* kSoftkeyHint = "Please select a softkey";
liyuqian1f508fd2016-06-07 06:57:40 -0700255const char* kFpsStateName = "FPS";
liyuqian6f163d22016-06-13 12:26:45 -0700256const char* kON = "ON";
257const char* kOFF = "OFF";
liyuqian2edb0f42016-07-06 14:11:32 -0700258const char* kRefreshStateName = "Refresh";
liyuqiane5a6cd92016-05-27 08:52:52 -0700259
jvanverth34524262016-05-04 13:49:13 -0700260Viewer::Viewer(int argc, char** argv, void* platformData)
jvanverthc265a922016-04-08 12:51:45 -0700261 : fCurrentMeasurement(0)
Jim Van Verth90dcce52017-11-03 13:36:07 -0400262 , fCumulativeMeasurementTime(0)
263 , fCumulativeMeasurementCount(0)
jvanverthc265a922016-04-08 12:51:45 -0700264 , fDisplayStats(false)
liyuqian2edb0f42016-07-06 14:11:32 -0700265 , fRefresh(false)
Brian Osman79086b92017-02-10 13:36:16 -0500266 , fShowImGuiDebugWindow(false)
267 , fShowImGuiTestWindow(false)
Brian Osmanf6877092017-02-13 09:39:57 -0500268 , fShowZoomWindow(false)
269 , fLastImage(nullptr)
jvanverth063ece72016-06-17 09:29:14 -0700270 , fBackendType(sk_app::Window::kNativeGL_BackendType)
Brian Osman92004802017-03-06 11:47:26 -0500271 , fColorMode(ColorMode::kLegacy)
Brian Osmana109e392017-02-24 09:49:14 -0500272 , fColorSpacePrimaries(gSrgbPrimaries)
egdaniel2a0bb0a2016-04-11 08:30:40 -0700273 , fZoomLevel(0.0f)
Brian Osmanb53f48c2017-06-07 10:00:30 -0400274 , fGestureDevice(GestureDevice::kNone)
jvanverthc265a922016-04-08 12:51:45 -0700275{
Greg Daniel285db442016-10-14 09:12:53 -0400276 SkGraphics::Init();
csmartdalton61cd31a2017-02-27 17:00:53 -0700277
278 static SkOnce initPathRendererNames;
279 initPathRendererNames([]() {
Brian Osman8b0f2652017-08-29 15:18:34 -0400280 gPathRendererNames[GpuPathRenderers::kAll] = "All Path Renderers";
281 gPathRendererNames[GpuPathRenderers::kDefault] =
282 "Default Ganesh Behavior (best path renderer, not including CCPR)";
csmartdalton61cd31a2017-02-27 17:00:53 -0700283 gPathRendererNames[GpuPathRenderers::kStencilAndCover] = "NV_path_rendering";
284 gPathRendererNames[GpuPathRenderers::kMSAA] = "Sample shading";
Jim Van Verth83010462017-03-16 08:45:39 -0400285 gPathRendererNames[GpuPathRenderers::kSmall] = "Small paths (cached sdf or alpha masks)";
Chris Dalton1a325d22017-07-14 15:17:41 -0600286 gPathRendererNames[GpuPathRenderers::kCoverageCounting] = "Coverage counting";
Brian Osman8a9de3d2017-03-01 14:59:05 -0500287 gPathRendererNames[GpuPathRenderers::kTessellating] = "Tessellating";
csmartdalton61cd31a2017-02-27 17:00:53 -0700288 gPathRendererNames[GpuPathRenderers::kNone] = "Software masks";
289 });
290
Brian Osman1df161a2017-02-09 12:10:20 -0500291 memset(fPaintTimes, 0, sizeof(fPaintTimes));
292 memset(fFlushTimes, 0, sizeof(fFlushTimes));
293 memset(fAnimateTimes, 0, sizeof(fAnimateTimes));
jvanverth9f372462016-04-06 06:08:59 -0700294
jvanverth2bb3b6d2016-04-08 07:24:09 -0700295 SkDebugf("Command line arguments: ");
296 for (int i = 1; i < argc; ++i) {
297 SkDebugf("%s ", argv[i]);
298 }
299 SkDebugf("\n");
300
301 SkCommandLineFlags::Parse(argc, argv);
Greg Daniel9fcc7432016-11-29 16:35:19 -0500302#ifdef SK_BUILD_FOR_ANDROID
Brian Salomon96789b32017-05-26 12:06:21 -0400303 SetResourcePath("/data/local/tmp/resources");
Greg Daniel9fcc7432016-11-29 16:35:19 -0500304#endif
jvanverth2bb3b6d2016-04-08 07:24:09 -0700305
Brian Osmanbc8150f2017-07-24 11:38:01 -0400306 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -0400307 static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads);
Greg Daniel285db442016-10-14 09:12:53 -0400308
bsalomon6c471f72016-07-26 12:56:32 -0700309 fBackendType = get_backend_type(FLAGS_backend[0]);
jvanverth9f372462016-04-06 06:08:59 -0700310 fWindow = Window::CreateNativeWindow(platformData);
jvanverth9f372462016-04-06 06:08:59 -0700311
csmartdalton578f0642017-02-24 16:04:47 -0700312 DisplayParams displayParams;
313 displayParams.fMSAASampleCount = FLAGS_msaa;
Brian Salomon41eac792017-03-08 14:03:56 -0500314 displayParams.fGrContextOptions.fEnableInstancedRendering = FLAGS_instancedRendering;
csmartdalton61cd31a2017-02-27 17:00:53 -0700315 displayParams.fGrContextOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
Chris Dalton7a0ebfc2017-10-13 12:35:50 -0600316 displayParams.fGrContextOptions.fAllowPathMaskCaching = FLAGS_cachePathMasks;
Brian Osmanf9810662017-08-30 10:02:10 -0400317 displayParams.fGrContextOptions.fExecutor = GpuExecutorForTools();
csmartdalton578f0642017-02-24 16:04:47 -0700318 fWindow->setRequestedDisplayParams(displayParams);
319
jvanverth9f372462016-04-06 06:08:59 -0700320 // register callbacks
brianosman622c8d52016-05-10 06:50:49 -0700321 fCommands.attach(fWindow);
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700322 fWindow->registerBackendCreatedFunc(on_backend_created_func, this);
jvanverth9f372462016-04-06 06:08:59 -0700323 fWindow->registerPaintFunc(on_paint_handler, this);
liyuqiand3cdbca2016-05-17 12:44:20 -0700324 fWindow->registerTouchFunc(on_touch_handler, this);
liyuqiane5a6cd92016-05-27 08:52:52 -0700325 fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this);
Brian Osman79086b92017-02-10 13:36:16 -0500326 fWindow->registerMouseFunc(on_mouse_handler, this);
327 fWindow->registerMouseWheelFunc(on_mouse_wheel_handler, this);
328 fWindow->registerKeyFunc(on_key_handler, this);
329 fWindow->registerCharFunc(on_char_handler, this);
jvanverth9f372462016-04-06 06:08:59 -0700330
brianosman622c8d52016-05-10 06:50:49 -0700331 // add key-bindings
Brian Osman79086b92017-02-10 13:36:16 -0500332 fCommands.addCommand(' ', "GUI", "Toggle Debug GUI", [this]() {
333 this->fShowImGuiDebugWindow = !this->fShowImGuiDebugWindow;
334 fWindow->inval();
335 });
336 fCommands.addCommand('g', "GUI", "Toggle GUI Demo", [this]() {
337 this->fShowImGuiTestWindow = !this->fShowImGuiTestWindow;
338 fWindow->inval();
339 });
Brian Osmanf6877092017-02-13 09:39:57 -0500340 fCommands.addCommand('z', "GUI", "Toggle zoom window", [this]() {
341 this->fShowZoomWindow = !this->fShowZoomWindow;
342 fWindow->inval();
343 });
brianosman622c8d52016-05-10 06:50:49 -0700344 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
345 this->fDisplayStats = !this->fDisplayStats;
346 fWindow->inval();
347 });
Jim Van Verth90dcce52017-11-03 13:36:07 -0400348 fCommands.addCommand('0', "Overlays", "Reset stats", [this]() {
349 this->resetMeasurements();
350 this->updateTitle();
351 fWindow->inval();
352 });
Brian Osmanf750fbc2017-02-08 10:47:28 -0500353 fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() {
Brian Osman92004802017-03-06 11:47:26 -0500354 switch (fColorMode) {
355 case ColorMode::kLegacy:
356 this->setColorMode(ColorMode::kColorManagedSRGB8888_NonLinearBlending);
357 break;
358 case ColorMode::kColorManagedSRGB8888_NonLinearBlending:
359 this->setColorMode(ColorMode::kColorManagedSRGB8888);
360 break;
361 case ColorMode::kColorManagedSRGB8888:
362 this->setColorMode(ColorMode::kColorManagedLinearF16);
363 break;
364 case ColorMode::kColorManagedLinearF16:
365 this->setColorMode(ColorMode::kLegacy);
366 break;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500367 }
brianosman622c8d52016-05-10 06:50:49 -0700368 });
369 fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
370 int previousSlide = fCurrentSlide;
371 fCurrentSlide++;
372 if (fCurrentSlide >= fSlides.count()) {
373 fCurrentSlide = 0;
374 }
375 this->setupCurrentSlide(previousSlide);
376 });
377 fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
378 int previousSlide = fCurrentSlide;
379 fCurrentSlide--;
380 if (fCurrentSlide < 0) {
381 fCurrentSlide = fSlides.count() - 1;
382 }
383 this->setupCurrentSlide(previousSlide);
384 });
385 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
386 this->changeZoomLevel(1.f / 32.f);
387 fWindow->inval();
388 });
389 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
390 this->changeZoomLevel(-1.f / 32.f);
391 fWindow->inval();
392 });
jvanverthaf236b52016-05-20 06:01:06 -0700393 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
Brian Salomon194db172017-08-17 14:37:06 -0400394 sk_app::Window::BackendType newBackend = (sk_app::Window::BackendType)(
395 (fBackendType + 1) % sk_app::Window::kBackendTypeCount);
Jim Van Verthd63c1022017-01-05 13:50:49 -0500396 // Switching to and from Vulkan is problematic on Linux so disabled for now
Brian Salomon194db172017-08-17 14:37:06 -0400397#if defined(SK_BUILD_FOR_UNIX) && defined(SK_VULKAN)
398 if (newBackend == sk_app::Window::kVulkan_BackendType) {
399 newBackend = (sk_app::Window::BackendType)((newBackend + 1) %
400 sk_app::Window::kBackendTypeCount);
401 } else if (fBackendType == sk_app::Window::kVulkan_BackendType) {
402 newBackend = sk_app::Window::kVulkan_BackendType;
Jim Van Verthd63c1022017-01-05 13:50:49 -0500403 }
404#endif
Brian Osman621491e2017-02-28 15:45:01 -0500405 this->setBackend(newBackend);
jvanverthaf236b52016-05-20 06:01:06 -0700406 });
brianosman622c8d52016-05-10 06:50:49 -0700407
Yuqian Li399b3c22017-08-03 11:08:15 -0400408 fCommands.addCommand('A', "AAA", "Toggle analytic AA", [this]() {
409 if (!gSkUseAnalyticAA) {
410 gSkUseAnalyticAA = true;
411 } else if (!gSkForceAnalyticAA) {
412 gSkForceAnalyticAA = true;
413 } else {
414 gSkUseAnalyticAA = gSkForceAnalyticAA = false;
415 }
416 this->updateTitle();
417 fWindow->inval();
418 });
419 fCommands.addCommand('D', "DAA", "Toggle delta AA", [this]() {
420 if (!gSkUseDeltaAA) {
421 gSkUseDeltaAA = true;
422 } else if (!gSkForceDeltaAA) {
423 gSkForceDeltaAA = true;
424 } else {
425 gSkUseDeltaAA = gSkForceDeltaAA = false;
426 }
427 this->updateTitle();
428 fWindow->inval();
429 });
430
jvanverth2bb3b6d2016-04-08 07:24:09 -0700431 // set up slides
432 this->initSlides();
Jim Van Verth6f449692017-02-14 15:16:46 -0500433 this->setStartupSlide();
434 if (FLAGS_list) {
435 this->listNames();
436 }
jvanverth2bb3b6d2016-04-08 07:24:09 -0700437
djsollen12d62a72016-04-21 07:59:44 -0700438 fAnimTimer.run();
439
Brian Osman79086b92017-02-10 13:36:16 -0500440 // ImGui initialization:
441 ImGuiIO& io = ImGui::GetIO();
442 io.DisplaySize.x = static_cast<float>(fWindow->width());
443 io.DisplaySize.y = static_cast<float>(fWindow->height());
444
445 // Keymap...
446 io.KeyMap[ImGuiKey_Tab] = (int)Window::Key::kTab;
447 io.KeyMap[ImGuiKey_LeftArrow] = (int)Window::Key::kLeft;
448 io.KeyMap[ImGuiKey_RightArrow] = (int)Window::Key::kRight;
449 io.KeyMap[ImGuiKey_UpArrow] = (int)Window::Key::kUp;
450 io.KeyMap[ImGuiKey_DownArrow] = (int)Window::Key::kDown;
451 io.KeyMap[ImGuiKey_PageUp] = (int)Window::Key::kPageUp;
452 io.KeyMap[ImGuiKey_PageDown] = (int)Window::Key::kPageDown;
453 io.KeyMap[ImGuiKey_Home] = (int)Window::Key::kHome;
454 io.KeyMap[ImGuiKey_End] = (int)Window::Key::kEnd;
455 io.KeyMap[ImGuiKey_Delete] = (int)Window::Key::kDelete;
456 io.KeyMap[ImGuiKey_Backspace] = (int)Window::Key::kBack;
457 io.KeyMap[ImGuiKey_Enter] = (int)Window::Key::kOK;
458 io.KeyMap[ImGuiKey_Escape] = (int)Window::Key::kEscape;
459 io.KeyMap[ImGuiKey_A] = (int)Window::Key::kA;
460 io.KeyMap[ImGuiKey_C] = (int)Window::Key::kC;
461 io.KeyMap[ImGuiKey_V] = (int)Window::Key::kV;
462 io.KeyMap[ImGuiKey_X] = (int)Window::Key::kX;
463 io.KeyMap[ImGuiKey_Y] = (int)Window::Key::kY;
464 io.KeyMap[ImGuiKey_Z] = (int)Window::Key::kZ;
465
466 int w, h;
467 unsigned char* pixels;
468 io.Fonts->GetTexDataAsAlpha8(&pixels, &w, &h);
469 SkImageInfo info = SkImageInfo::MakeA8(w, h);
470 SkPixmap pmap(info, pixels, info.minRowBytes());
Brian Osmanf6877092017-02-13 09:39:57 -0500471 SkMatrix localMatrix = SkMatrix::MakeScale(1.0f / w, 1.0f / h);
472 auto fontImage = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
Mike Reed0acd7952017-04-28 11:12:19 -0400473 auto fontShader = fontImage->makeShader(&localMatrix);
Brian Osmanf6877092017-02-13 09:39:57 -0500474 fImGuiFontPaint.setShader(fontShader);
475 fImGuiFontPaint.setColor(SK_ColorWHITE);
476 fImGuiFontPaint.setFilterQuality(kLow_SkFilterQuality);
477 io.Fonts->TexID = &fImGuiFontPaint;
Brian Osman79086b92017-02-10 13:36:16 -0500478
Brian Osmana109e392017-02-24 09:49:14 -0500479 auto gamutImage = GetResourceAsImage("gamut.png");
480 if (gamutImage) {
Mike Reed0acd7952017-04-28 11:12:19 -0400481 fImGuiGamutPaint.setShader(gamutImage->makeShader());
Brian Osmana109e392017-02-24 09:49:14 -0500482 }
483 fImGuiGamutPaint.setColor(SK_ColorWHITE);
484 fImGuiGamutPaint.setFilterQuality(kLow_SkFilterQuality);
485
Brian Osman70d2f432017-11-08 09:54:10 -0500486 fWindow->attach(backend_type_for_window(fBackendType));
jvanverth9f372462016-04-06 06:08:59 -0700487}
488
jvanverth34524262016-05-04 13:49:13 -0700489void Viewer::initSlides() {
liyuqian1f508fd2016-06-07 06:57:40 -0700490 fAllSlideNames = Json::Value(Json::arrayValue);
491
jvanverth2bb3b6d2016-04-08 07:24:09 -0700492 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
493 while (gms) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400494 std::unique_ptr<skiagm::GM> gm(gms->factory()(nullptr));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700495
496 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
497 sk_sp<Slide> slide(new GMSlide(gm.release()));
498 fSlides.push_back(slide);
499 }
500
501 gms = gms->next();
502 }
503
504 // reverse array
505 for (int i = 0; i < fSlides.count()/2; ++i) {
506 sk_sp<Slide> temp = fSlides[i];
507 fSlides[i] = fSlides[fSlides.count() - i - 1];
508 fSlides[fSlides.count() - i - 1] = temp;
509 }
510
jvanverthc7027ab2016-06-16 09:52:35 -0700511 // samples
512 const SkViewRegister* reg = SkViewRegister::Head();
513 while (reg) {
514 sk_sp<Slide> slide(new SampleSlide(reg->factory()));
brianosmane1d20072016-07-12 09:07:33 -0700515 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, slide->getName().c_str())) {
516 fSlides.push_back(slide);
517 }
jvanverthc7027ab2016-06-16 09:52:35 -0700518 reg = reg->next();
519 }
520
jvanverth2bb3b6d2016-04-08 07:24:09 -0700521 // SKPs
522 for (int i = 0; i < FLAGS_skps.count(); i++) {
523 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
jvanverthc265a922016-04-08 12:51:45 -0700524 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
525 continue;
526 }
527
jvanverth2bb3b6d2016-04-08 07:24:09 -0700528 SkString path(FLAGS_skps[i]);
jvanverthc265a922016-04-08 12:51:45 -0700529 sk_sp<SKPSlide> slide(new SKPSlide(SkOSPath::Basename(path.c_str()), path));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700530 if (slide) {
531 fSlides.push_back(slide);
532 }
533 } else {
534 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
jvanverthc265a922016-04-08 12:51:45 -0700535 SkString skpName;
536 while (it.next(&skpName)) {
537 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, skpName.c_str())) {
538 continue;
539 }
540
541 SkString path = SkOSPath::Join(FLAGS_skps[i], skpName.c_str());
542 sk_sp<SKPSlide> slide(new SKPSlide(skpName, path));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700543 if (slide) {
544 fSlides.push_back(slide);
545 }
546 }
547 }
548 }
liyuqian6f163d22016-06-13 12:26:45 -0700549
550 // JPGs
551 for (int i = 0; i < FLAGS_jpgs.count(); i++) {
552 SkOSFile::Iter it(FLAGS_jpgs[i], ".jpg");
553 SkString jpgName;
554 while (it.next(&jpgName)) {
brianosmane1d20072016-07-12 09:07:33 -0700555 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jpgName.c_str())) {
556 continue;
557 }
558
liyuqian6f163d22016-06-13 12:26:45 -0700559 SkString path = SkOSPath::Join(FLAGS_jpgs[i], jpgName.c_str());
560 sk_sp<ImageSlide> slide(new ImageSlide(jpgName, path));
561 if (slide) {
562 fSlides.push_back(slide);
563 }
564 }
565 }
jvanverth2bb3b6d2016-04-08 07:24:09 -0700566}
567
568
jvanverth34524262016-05-04 13:49:13 -0700569Viewer::~Viewer() {
jvanverth9f372462016-04-06 06:08:59 -0700570 fWindow->detach();
571 delete fWindow;
572}
573
brianosman05de2162016-05-06 13:28:57 -0700574void Viewer::updateTitle() {
csmartdalton578f0642017-02-24 16:04:47 -0700575 if (!fWindow) {
576 return;
577 }
578 if (fWindow->sampleCount() < 0) {
579 return; // Surface hasn't been created yet.
580 }
581
jvanverth34524262016-05-04 13:49:13 -0700582 SkString title("Viewer: ");
jvanverthc265a922016-04-08 12:51:45 -0700583 title.append(fSlides[fCurrentSlide]->getName());
brianosmanb109b8c2016-06-16 13:03:24 -0700584
Yuqian Li399b3c22017-08-03 11:08:15 -0400585 if (gSkUseDeltaAA) {
586 if (gSkForceDeltaAA) {
587 title.append(" <FDAA>");
588 } else {
589 title.append(" <DAA>");
590 }
591 } else if (gSkUseAnalyticAA) {
592 if (gSkForceAnalyticAA) {
593 title.append(" <FAAA>");
594 } else {
595 title.append(" <AAA>");
596 }
597 }
598
Brian Osman92004802017-03-06 11:47:26 -0500599 switch (fColorMode) {
600 case ColorMode::kLegacy:
601 title.append(" Legacy 8888");
602 break;
603 case ColorMode::kColorManagedSRGB8888_NonLinearBlending:
604 title.append(" ColorManaged 8888 (Nonlinear blending)");
605 break;
606 case ColorMode::kColorManagedSRGB8888:
607 title.append(" ColorManaged 8888");
608 break;
609 case ColorMode::kColorManagedLinearF16:
610 title.append(" ColorManaged F16");
611 break;
612 }
Brian Osmanf750fbc2017-02-08 10:47:28 -0500613
Brian Osman92004802017-03-06 11:47:26 -0500614 if (ColorMode::kLegacy != fColorMode) {
Brian Osmana109e392017-02-24 09:49:14 -0500615 int curPrimaries = -1;
616 for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
617 if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
618 curPrimaries = i;
619 break;
620 }
621 }
622 title.appendf(" %s", curPrimaries >= 0 ? gNamedPrimaries[curPrimaries].fName : "Custom");
brianosman05de2162016-05-06 13:28:57 -0700623 }
Brian Osmanf750fbc2017-02-08 10:47:28 -0500624
Jim Van Verth90dcce52017-11-03 13:36:07 -0400625 if (fDisplayStats) {
626 double ms = 0;
627 int count = 0;
628 int i = (fCurrentMeasurement + kMeasurementCount - 1) & (kMeasurementCount - 1);
629 do {
630 double inc = fAnimateTimes[i] + fPaintTimes[i] + fFlushTimes[i];
631 if (inc <= 0) {
632 break;
633 }
634 ms += inc;
635 ++count;
636 i = (i + kMeasurementCount - 1) & (kMeasurementCount - 1);
637 } while (i != fCurrentMeasurement);
638
639 title.appendf(" %8.4f ms -> %4.4f ms", ms / SkTMax(1, count),
640 fCumulativeMeasurementTime / SkTMax(1, fCumulativeMeasurementCount));
641 }
642
csmartdalton578f0642017-02-24 16:04:47 -0700643 title.append(" [");
jvanverthaf236b52016-05-20 06:01:06 -0700644 title.append(kBackendTypeStrings[fBackendType]);
csmartdalton578f0642017-02-24 16:04:47 -0700645 if (int msaa = fWindow->sampleCount()) {
646 title.appendf(" MSAA: %i", msaa);
647 }
648 title.append("]");
csmartdalton61cd31a2017-02-27 17:00:53 -0700649
650 GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers;
Brian Osman8b0f2652017-08-29 15:18:34 -0400651 if (GpuPathRenderers::kDefault != pr) {
csmartdalton61cd31a2017-02-27 17:00:53 -0700652 title.appendf(" [Path renderer: %s]", gPathRendererNames[pr].c_str());
653 }
654
brianosman05de2162016-05-06 13:28:57 -0700655 fWindow->setTitle(title.c_str());
656}
657
Jim Van Verth6f449692017-02-14 15:16:46 -0500658void Viewer::setStartupSlide() {
659
660 if (!FLAGS_slide.isEmpty()) {
661 int count = fSlides.count();
662 for (int i = 0; i < count; i++) {
663 if (fSlides[i]->getName().equals(FLAGS_slide[0])) {
664 fCurrentSlide = i;
665 return;
666 }
667 }
668
669 fprintf(stderr, "Unknown slide \"%s\"\n", FLAGS_slide[0]);
670 this->listNames();
671 }
672
673 fCurrentSlide = 0;
674}
675
676void Viewer::listNames() {
677 int count = fSlides.count();
678 SkDebugf("All Slides:\n");
679 for (int i = 0; i < count; i++) {
680 SkDebugf(" %s\n", fSlides[i]->getName().c_str());
681 }
682}
683
Jim Van Verth90dcce52017-11-03 13:36:07 -0400684void Viewer::resetMeasurements() {
685 memset(fPaintTimes, 0, sizeof(fPaintTimes));
686 memset(fFlushTimes, 0, sizeof(fFlushTimes));
687 memset(fAnimateTimes, 0, sizeof(fAnimateTimes));
688 fCurrentMeasurement = 0;
689 fCumulativeMeasurementTime = 0;
690 fCumulativeMeasurementCount = 0;
691}
692
brianosman05de2162016-05-06 13:28:57 -0700693void Viewer::setupCurrentSlide(int previousSlide) {
liyuqiane5a6cd92016-05-27 08:52:52 -0700694 if (fCurrentSlide == previousSlide) {
695 return; // no change; do nothing
696 }
liyuqian6f163d22016-06-13 12:26:45 -0700697 // prepare dimensions for image slides
jvanverthc7027ab2016-06-16 09:52:35 -0700698 fSlides[fCurrentSlide]->load(SkIntToScalar(fWindow->width()), SkIntToScalar(fWindow->height()));
liyuqian6f163d22016-06-13 12:26:45 -0700699
liyuqiane46e4f02016-05-20 07:32:19 -0700700 fGesture.reset();
701 fDefaultMatrix.reset();
liyuqiane46e4f02016-05-20 07:32:19 -0700702
Brian Osman42bb6ac2017-06-05 08:46:04 -0400703 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
704 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
705 const SkRect windowRect = SkRect::MakeIWH(fWindow->width(), fWindow->height());
706
707 // Start with a matrix that scales the slide to the available screen space
708 if (fWindow->scaleContentToFit()) {
709 if (windowRect.width() > 0 && windowRect.height() > 0) {
710 fDefaultMatrix.setRectToRect(slideBounds, windowRect, SkMatrix::kStart_ScaleToFit);
liyuqiane46e4f02016-05-20 07:32:19 -0700711 }
712 }
713
Brian Osman42bb6ac2017-06-05 08:46:04 -0400714 // Prevent the user from dragging content so far outside the window they can't find it again
715 fGesture.setTransLimit(slideBounds, windowRect, fDefaultMatrix);
liyuqiane46e4f02016-05-20 07:32:19 -0700716
brianosman05de2162016-05-06 13:28:57 -0700717 this->updateTitle();
liyuqiane5a6cd92016-05-27 08:52:52 -0700718 this->updateUIState();
jvanverthc265a922016-04-08 12:51:45 -0700719 if (previousSlide >= 0) {
720 fSlides[previousSlide]->unload();
721 }
Jim Van Verth90dcce52017-11-03 13:36:07 -0400722
723 this->resetMeasurements();
724
jvanverthc265a922016-04-08 12:51:45 -0700725 fWindow->inval();
726}
727
728#define MAX_ZOOM_LEVEL 8
729#define MIN_ZOOM_LEVEL -8
730
jvanverth34524262016-05-04 13:49:13 -0700731void Viewer::changeZoomLevel(float delta) {
jvanverthc265a922016-04-08 12:51:45 -0700732 fZoomLevel += delta;
Brian Osman42bb6ac2017-06-05 08:46:04 -0400733 fZoomLevel = SkScalarPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
jvanverthc265a922016-04-08 12:51:45 -0700734}
735
liyuqiand3cdbca2016-05-17 12:44:20 -0700736SkMatrix Viewer::computeMatrix() {
jvanverthc265a922016-04-08 12:51:45 -0700737 SkMatrix m;
jvanverthc265a922016-04-08 12:51:45 -0700738
Brian Osman42bb6ac2017-06-05 08:46:04 -0400739 SkScalar zoomScale = (fZoomLevel < 0) ? SK_Scalar1 / (SK_Scalar1 - fZoomLevel)
740 : SK_Scalar1 + fZoomLevel;
741 m = fGesture.localM();
liyuqiand3cdbca2016-05-17 12:44:20 -0700742 m.preConcat(fGesture.globalM());
Brian Osman42bb6ac2017-06-05 08:46:04 -0400743 m.preConcat(fDefaultMatrix);
744 m.preScale(zoomScale, zoomScale);
jvanverthc265a922016-04-08 12:51:45 -0700745
liyuqiand3cdbca2016-05-17 12:44:20 -0700746 return m;
jvanverthc265a922016-04-08 12:51:45 -0700747}
748
Brian Osman621491e2017-02-28 15:45:01 -0500749void Viewer::setBackend(sk_app::Window::BackendType backendType) {
750 fBackendType = backendType;
751
752 fWindow->detach();
753
Brian Osman70d2f432017-11-08 09:54:10 -0500754#if defined(SK_BUILD_FOR_WIN)
Brian Salomon194db172017-08-17 14:37:06 -0400755 // Switching between OpenGL, Vulkan, and ANGLE in the same window is problematic at this point
756 // on Windows, so we just delete the window and recreate it.
Brian Osman70d2f432017-11-08 09:54:10 -0500757 DisplayParams params = fWindow->getRequestedDisplayParams();
758 delete fWindow;
759 fWindow = Window::CreateNativeWindow(nullptr);
Brian Osman621491e2017-02-28 15:45:01 -0500760
Brian Osman70d2f432017-11-08 09:54:10 -0500761 // re-register callbacks
762 fCommands.attach(fWindow);
763 fWindow->registerBackendCreatedFunc(on_backend_created_func, this);
764 fWindow->registerPaintFunc(on_paint_handler, this);
765 fWindow->registerTouchFunc(on_touch_handler, this);
766 fWindow->registerUIStateChangedFunc(on_ui_state_changed_handler, this);
767 fWindow->registerMouseFunc(on_mouse_handler, this);
768 fWindow->registerMouseWheelFunc(on_mouse_wheel_handler, this);
769 fWindow->registerKeyFunc(on_key_handler, this);
770 fWindow->registerCharFunc(on_char_handler, this);
771 // Don't allow the window to re-attach. If we're in MSAA mode, the params we grabbed above
772 // will still include our correct sample count. But the re-created fWindow will lose that
773 // information. On Windows, we need to re-create the window when changing sample count,
774 // so we'll incorrectly detect that situation, then re-initialize the window in GL mode,
775 // rendering this tear-down step pointless (and causing the Vulkan window context to fail
776 // as if we had never changed windows at all).
777 fWindow->setRequestedDisplayParams(params, false);
Brian Osman621491e2017-02-28 15:45:01 -0500778#endif
779
Brian Osman70d2f432017-11-08 09:54:10 -0500780 fWindow->attach(backend_type_for_window(fBackendType));
Brian Osman621491e2017-02-28 15:45:01 -0500781}
782
Brian Osman92004802017-03-06 11:47:26 -0500783void Viewer::setColorMode(ColorMode colorMode) {
784 fColorMode = colorMode;
liyuqian6f163d22016-06-13 12:26:45 -0700785
Brian Osmanf750fbc2017-02-08 10:47:28 -0500786 // When we're in color managed mode, we tag our window surface as sRGB. If we've switched into
Brian Osmane0d4fba2017-03-15 10:24:55 -0400787 // or out of legacy/nonlinear mode, we need to update our window configuration.
csmartdalton578f0642017-02-24 16:04:47 -0700788 DisplayParams params = fWindow->getRequestedDisplayParams();
Brian Osman92004802017-03-06 11:47:26 -0500789 bool wasInLegacy = !SkToBool(params.fColorSpace);
Brian Osmane0d4fba2017-03-15 10:24:55 -0400790 bool wantLegacy = (ColorMode::kLegacy == fColorMode) ||
791 (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode);
Brian Osman92004802017-03-06 11:47:26 -0500792 if (wasInLegacy != wantLegacy) {
793 params.fColorSpace = wantLegacy ? nullptr : SkColorSpace::MakeSRGB();
csmartdalton578f0642017-02-24 16:04:47 -0700794 fWindow->setRequestedDisplayParams(params);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500795 }
796
797 this->updateTitle();
798 fWindow->inval();
799}
800
801void Viewer::drawSlide(SkCanvas* canvas) {
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500802 SkAutoCanvasRestore autorestore(canvas, false);
803
Brian Osmanf750fbc2017-02-08 10:47:28 -0500804 // By default, we render directly into the window's surface/canvas
805 SkCanvas* slideCanvas = canvas;
Brian Osmanf6877092017-02-13 09:39:57 -0500806 fLastImage.reset();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700807
Brian Osmane0d4fba2017-03-15 10:24:55 -0400808 // If we're in any of the color managed modes, construct the color space we're going to use
809 sk_sp<SkColorSpace> cs = nullptr;
810 if (ColorMode::kLegacy != fColorMode) {
811 auto transferFn = (ColorMode::kColorManagedLinearF16 == fColorMode)
812 ? SkColorSpace::kLinear_RenderTargetGamma : SkColorSpace::kSRGB_RenderTargetGamma;
Mike Kleinc722f792017-07-31 11:57:21 -0400813 SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
Brian Osmane0d4fba2017-03-15 10:24:55 -0400814 SkAssertResult(fColorSpacePrimaries.toXYZD50(&toXYZ));
815 cs = SkColorSpace::MakeRGB(transferFn, toXYZ);
816 }
817
818 // If we're in F16, or we're zooming, or we're in color correct 8888 and the gamut isn't sRGB,
Brian Osman70d2f432017-11-08 09:54:10 -0500819 // we need to render offscreen. We also need to render offscreen if we're in any raster mode,
820 // because the window surface is actually GL.
Brian Osmanf750fbc2017-02-08 10:47:28 -0500821 sk_sp<SkSurface> offscreenSurface = nullptr;
Brian Osman70d2f432017-11-08 09:54:10 -0500822 if (Window::kRaster_BackendType == fBackendType ||
823 ColorMode::kColorManagedLinearF16 == fColorMode ||
Brian Osman92004802017-03-06 11:47:26 -0500824 fShowZoomWindow ||
Brian Osmane0d4fba2017-03-15 10:24:55 -0400825 (ColorMode::kColorManagedSRGB8888 == fColorMode &&
826 !primaries_equal(fColorSpacePrimaries, gSrgbPrimaries))) {
827
Brian Osman92004802017-03-06 11:47:26 -0500828 SkColorType colorType = (ColorMode::kColorManagedLinearF16 == fColorMode)
829 ? kRGBA_F16_SkColorType : kN32_SkColorType;
Brian Osmane0d4fba2017-03-15 10:24:55 -0400830 // In nonlinear blending mode, we actually use a legacy off-screen canvas, and wrap it
831 // with a special canvas (below) that has the color space attached
832 sk_sp<SkColorSpace> offscreenColorSpace =
833 (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) ? nullptr : cs;
Brian Osman92004802017-03-06 11:47:26 -0500834 SkImageInfo info = SkImageInfo::Make(fWindow->width(), fWindow->height(), colorType,
Brian Osmane0d4fba2017-03-15 10:24:55 -0400835 kPremul_SkAlphaType, std::move(offscreenColorSpace));
Brian Osman70d2f432017-11-08 09:54:10 -0500836 offscreenSurface = Window::kRaster_BackendType == fBackendType ? SkSurface::MakeRaster(info)
837 : canvas->makeSurface(info);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500838 slideCanvas = offscreenSurface->getCanvas();
839 }
840
Brian Osmane0d4fba2017-03-15 10:24:55 -0400841 std::unique_ptr<SkCanvas> xformCanvas = nullptr;
842 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
843 xformCanvas = SkCreateColorSpaceXformCanvas(slideCanvas, cs);
844 slideCanvas = xformCanvas.get();
845 }
846
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500847 int count = slideCanvas->save();
Brian Osmanf750fbc2017-02-08 10:47:28 -0500848 slideCanvas->clear(SK_ColorWHITE);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500849 slideCanvas->concat(computeMatrix());
Brian Osman1df161a2017-02-09 12:10:20 -0500850 // Time the painting logic of the slide
851 double startTime = SkTime::GetMSecs();
Brian Osmanf750fbc2017-02-08 10:47:28 -0500852 fSlides[fCurrentSlide]->draw(slideCanvas);
Brian Osman1df161a2017-02-09 12:10:20 -0500853 fPaintTimes[fCurrentMeasurement] = SkTime::GetMSecs() - startTime;
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500854 slideCanvas->restoreToCount(count);
Brian Osman1df161a2017-02-09 12:10:20 -0500855
856 // Force a flush so we can time that, too
857 startTime = SkTime::GetMSecs();
858 slideCanvas->flush();
859 fFlushTimes[fCurrentMeasurement] = SkTime::GetMSecs() - startTime;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500860
861 // If we rendered offscreen, snap an image and push the results to the window's canvas
862 if (offscreenSurface) {
Brian Osmanf6877092017-02-13 09:39:57 -0500863 fLastImage = offscreenSurface->makeImageSnapshot();
Brian Osmanf750fbc2017-02-08 10:47:28 -0500864
865 // Tag the image with the sRGB gamut, so no further color space conversion happens
Brian Osmane0d4fba2017-03-15 10:24:55 -0400866 sk_sp<SkColorSpace> srgb = (ColorMode::kColorManagedLinearF16 == fColorMode)
Brian Osmanf750fbc2017-02-08 10:47:28 -0500867 ? SkColorSpace::MakeSRGBLinear() : SkColorSpace::MakeSRGB();
Brian Osmane0d4fba2017-03-15 10:24:55 -0400868 auto retaggedImage = SkImageMakeRasterCopyAndAssignColorSpace(fLastImage.get(), srgb.get());
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500869 SkPaint paint;
870 paint.setBlendMode(SkBlendMode::kSrc);
871 canvas->drawImage(retaggedImage, 0, 0, &paint);
liyuqian74959a12016-06-16 14:10:34 -0700872 }
liyuqian6f163d22016-06-13 12:26:45 -0700873}
874
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700875void Viewer::onBackendCreated() {
876 this->updateTitle();
877 this->updateUIState();
878 this->setupCurrentSlide(-1);
Jim Van Verth90dcce52017-11-03 13:36:07 -0400879 this->resetMeasurements();
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700880 fWindow->show();
881 fWindow->inval();
882}
Jim Van Verth6f449692017-02-14 15:16:46 -0500883
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700884void Viewer::onPaint(SkCanvas* canvas) {
Brian Osman79086b92017-02-10 13:36:16 -0500885 // Update ImGui input
886 ImGuiIO& io = ImGui::GetIO();
887 io.DeltaTime = 1.0f / 60.0f;
888 io.DisplaySize.x = static_cast<float>(fWindow->width());
889 io.DisplaySize.y = static_cast<float>(fWindow->height());
890
891 io.KeyAlt = io.KeysDown[static_cast<int>(Window::Key::kOption)];
892 io.KeyCtrl = io.KeysDown[static_cast<int>(Window::Key::kCtrl)];
893 io.KeyShift = io.KeysDown[static_cast<int>(Window::Key::kShift)];
894
895 ImGui::NewFrame();
896
Jim Van Verth90dcce52017-11-03 13:36:07 -0400897 this->drawSlide(canvas);
jvanverthc265a922016-04-08 12:51:45 -0700898
Brian Osman1df161a2017-02-09 12:10:20 -0500899 // Advance our timing bookkeeping
Jim Van Verth90dcce52017-11-03 13:36:07 -0400900 fCumulativeMeasurementTime += fAnimateTimes[fCurrentMeasurement] +
901 fPaintTimes[fCurrentMeasurement] +
902 fFlushTimes[fCurrentMeasurement];
903 fCumulativeMeasurementCount++;
Brian Osman1df161a2017-02-09 12:10:20 -0500904 fCurrentMeasurement = (fCurrentMeasurement + 1) & (kMeasurementCount - 1);
905 SkASSERT(fCurrentMeasurement < kMeasurementCount);
906
907 // Draw any overlays or UI that we don't want timed
jvanverthc265a922016-04-08 12:51:45 -0700908 if (fDisplayStats) {
909 drawStats(canvas);
Jim Van Verth90dcce52017-11-03 13:36:07 -0400910 this->updateTitle();
jvanverthc265a922016-04-08 12:51:45 -0700911 }
brianosman622c8d52016-05-10 06:50:49 -0700912 fCommands.drawHelp(canvas);
liyuqian2edb0f42016-07-06 14:11:32 -0700913
Jim Van Verth90dcce52017-11-03 13:36:07 -0400914 this->drawImGui(canvas);
Brian Osman79086b92017-02-10 13:36:16 -0500915
Brian Osman1df161a2017-02-09 12:10:20 -0500916 // Update the FPS
Jim Van Verth90dcce52017-11-03 13:36:07 -0400917 this->updateUIState();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700918}
919
jvanverth814e38d2016-06-06 08:48:47 -0700920bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) {
Brian Osmanb53f48c2017-06-07 10:00:30 -0400921 if (GestureDevice::kMouse == fGestureDevice) {
922 return false;
923 }
liyuqiand3cdbca2016-05-17 12:44:20 -0700924 void* castedOwner = reinterpret_cast<void*>(owner);
925 switch (state) {
926 case Window::kUp_InputState: {
927 fGesture.touchEnd(castedOwner);
928 break;
929 }
930 case Window::kDown_InputState: {
Brian Osman42bb6ac2017-06-05 08:46:04 -0400931 fGesture.touchBegin(castedOwner, x, y);
liyuqiand3cdbca2016-05-17 12:44:20 -0700932 break;
933 }
934 case Window::kMove_InputState: {
Brian Osman42bb6ac2017-06-05 08:46:04 -0400935 fGesture.touchMoved(castedOwner, x, y);
liyuqiand3cdbca2016-05-17 12:44:20 -0700936 break;
937 }
938 }
Brian Osmanb53f48c2017-06-07 10:00:30 -0400939 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone;
liyuqiand3cdbca2016-05-17 12:44:20 -0700940 fWindow->inval();
941 return true;
942}
943
Jim Van Verthe7705782017-05-04 14:00:59 -0400944bool Viewer::onMouse(float x, float y, Window::InputState state, uint32_t modifiers) {
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -0400945 if (!fSlides[fCurrentSlide]->onMouse(x, y, state, modifiers)) {
946 if (GestureDevice::kTouch == fGestureDevice) {
947 return false;
948 }
949 switch (state) {
950 case Window::kUp_InputState: {
951 fGesture.touchEnd(nullptr);
952 break;
953 }
954 case Window::kDown_InputState: {
955 fGesture.touchBegin(nullptr, x, y);
956 break;
957 }
958 case Window::kMove_InputState: {
959 fGesture.touchMoved(nullptr, x, y);
960 break;
961 }
962 }
963 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
Brian Osmanb53f48c2017-06-07 10:00:30 -0400964 }
Jim Van Verthe7705782017-05-04 14:00:59 -0400965 fWindow->inval();
966 return true;
967}
968
jvanverth34524262016-05-04 13:49:13 -0700969void Viewer::drawStats(SkCanvas* canvas) {
jvanverth3d6ed3a2016-04-07 11:09:51 -0700970 static const float kPixelPerMS = 2.0f;
971 static const int kDisplayWidth = 130;
972 static const int kDisplayHeight = 100;
973 static const int kDisplayPadding = 10;
974 static const int kGraphPadding = 3;
975 static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps
976
Mike Reed3661bc92017-02-22 13:21:42 -0500977 SkISize canvasSize = canvas->getBaseLayerSize();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700978 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth-kDisplayPadding),
979 SkIntToScalar(kDisplayPadding),
980 SkIntToScalar(kDisplayWidth), SkIntToScalar(kDisplayHeight));
981 SkPaint paint;
982 canvas->save();
983
984 canvas->clipRect(rect);
985 paint.setColor(SK_ColorBLACK);
986 canvas->drawRect(rect, paint);
987 // draw the 16ms line
988 paint.setColor(SK_ColorLTGRAY);
989 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS,
990 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint);
991 paint.setColor(SK_ColorRED);
992 paint.setStyle(SkPaint::kStroke_Style);
993 canvas->drawRect(rect, paint);
994
995 int x = SkScalarTruncToInt(rect.fLeft) + kGraphPadding;
996 const int xStep = 2;
jvanverth3d6ed3a2016-04-07 11:09:51 -0700997 int i = fCurrentMeasurement;
998 do {
Brian Osman1df161a2017-02-09 12:10:20 -0500999 // Round to nearest values
1000 int animateHeight = (int)(fAnimateTimes[i] * kPixelPerMS + 0.5);
1001 int paintHeight = (int)(fPaintTimes[i] * kPixelPerMS + 0.5);
1002 int flushHeight = (int)(fFlushTimes[i] * kPixelPerMS + 0.5);
1003 int startY = SkScalarTruncToInt(rect.fBottom);
1004 int endY = startY - flushHeight;
1005 paint.setColor(SK_ColorRED);
1006 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY),
1007 SkIntToScalar(x), SkIntToScalar(endY), paint);
1008 startY = endY;
1009 endY = startY - paintHeight;
1010 paint.setColor(SK_ColorGREEN);
1011 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY),
1012 SkIntToScalar(x), SkIntToScalar(endY), paint);
1013 startY = endY;
1014 endY = startY - animateHeight;
1015 paint.setColor(SK_ColorMAGENTA);
jvanverth3d6ed3a2016-04-07 11:09:51 -07001016 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY),
1017 SkIntToScalar(x), SkIntToScalar(endY), paint);
1018 i++;
1019 i &= (kMeasurementCount - 1); // fast mod
1020 x += xStep;
1021 } while (i != fCurrentMeasurement);
jvanverth9f372462016-04-06 06:08:59 -07001022
1023 canvas->restore();
1024}
1025
Brian Osmana109e392017-02-24 09:49:14 -05001026static ImVec2 ImGui_DragPrimary(const char* label, float* x, float* y,
1027 const ImVec2& pos, const ImVec2& size) {
1028 // Transform primaries ([0, 0] - [0.8, 0.9]) to screen coords (including Y-flip)
1029 ImVec2 center(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y);
1030
1031 // Invisible 10x10 button
1032 ImGui::SetCursorScreenPos(ImVec2(center.x - 5, center.y - 5));
1033 ImGui::InvisibleButton(label, ImVec2(10, 10));
1034
1035 if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) {
1036 ImGuiIO& io = ImGui::GetIO();
1037 // Normalized mouse position, relative to our gamut box
1038 ImVec2 mousePosXY((io.MousePos.x - pos.x) / size.x, (io.MousePos.y - pos.y) / size.y);
1039 // Clamp to edge of box, convert back to primary scale
1040 *x = SkTPin(mousePosXY.x, 0.0f, 1.0f) * 0.8f;
1041 *y = SkTPin(1 - mousePosXY.y, 0.0f, 1.0f) * 0.9f;
1042 }
1043
1044 if (ImGui::IsItemHovered()) {
1045 ImGui::SetTooltip("x: %.3f\ny: %.3f", *x, *y);
1046 }
1047
1048 // Return screen coordinates for the caller. We could just return center here, but we'd have
1049 // one frame of lag during drag.
1050 return ImVec2(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y);
1051}
1052
1053static void ImGui_Primaries(SkColorSpacePrimaries* primaries, SkPaint* gamutPaint) {
1054 ImDrawList* drawList = ImGui::GetWindowDrawList();
1055
1056 // The gamut image covers a (0.8 x 0.9) shaped region, so fit our image/canvas to the available
1057 // width, and scale the height to maintain aspect ratio.
1058 float canvasWidth = SkTMax(ImGui::GetContentRegionAvailWidth(), 50.0f);
1059 ImVec2 size = ImVec2(canvasWidth, canvasWidth * (0.9f / 0.8f));
1060 ImVec2 pos = ImGui::GetCursorScreenPos();
1061
1062 // Background image. Only draw a subset of the image, to avoid the regions less than zero.
1063 // Simplifes re-mapping math, clipping behavior, and increases resolution in the useful area.
1064 // Magic numbers are pixel locations of the origin and upper-right corner.
1065 drawList->AddImage(gamutPaint, pos, ImVec2(pos.x + size.x, pos.y + size.y),
1066 ImVec2(242, 61), ImVec2(1897, 1922));
1067 ImVec2 endPos = ImGui::GetCursorPos();
1068
1069 // Primary markers
1070 ImVec2 r = ImGui_DragPrimary("R", &primaries->fRX, &primaries->fRY, pos, size);
1071 ImVec2 g = ImGui_DragPrimary("G", &primaries->fGX, &primaries->fGY, pos, size);
1072 ImVec2 b = ImGui_DragPrimary("B", &primaries->fBX, &primaries->fBY, pos, size);
1073 ImVec2 w = ImGui_DragPrimary("W", &primaries->fWX, &primaries->fWY, pos, size);
1074
1075 // Gamut triangle
1076 drawList->AddCircle(r, 5.0f, 0xFF000040);
1077 drawList->AddCircle(g, 5.0f, 0xFF004000);
1078 drawList->AddCircle(b, 5.0f, 0xFF400000);
1079 drawList->AddCircle(w, 5.0f, 0xFFFFFFFF);
1080 drawList->AddTriangle(r, g, b, 0xFFFFFFFF);
1081
1082 // Re-position cursor immediate after the diagram for subsequent controls
1083 ImGui::SetCursorPos(endPos);
1084}
1085
Brian Osman79086b92017-02-10 13:36:16 -05001086void Viewer::drawImGui(SkCanvas* canvas) {
1087 // Support drawing the ImGui demo window. Superfluous, but gives a good idea of what's possible
1088 if (fShowImGuiTestWindow) {
1089 ImGui::ShowTestWindow(&fShowImGuiTestWindow);
1090 }
1091
1092 if (fShowImGuiDebugWindow) {
Brian Osmana109e392017-02-24 09:49:14 -05001093 // We have some dynamic content that sizes to fill available size. If the scroll bar isn't
1094 // always visible, we can end up in a layout feedback loop.
1095 ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiSetCond_FirstUseEver);
Brian Salomon99a33902017-03-07 15:16:34 -05001096 DisplayParams params = fWindow->getRequestedDisplayParams();
1097 bool paramsChanged = false;
Brian Osmana109e392017-02-24 09:49:14 -05001098 if (ImGui::Begin("Tools", &fShowImGuiDebugWindow,
1099 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
Brian Osman621491e2017-02-28 15:45:01 -05001100 if (ImGui::CollapsingHeader("Backend")) {
1101 int newBackend = static_cast<int>(fBackendType);
1102 ImGui::RadioButton("Raster", &newBackend, sk_app::Window::kRaster_BackendType);
1103 ImGui::SameLine();
1104 ImGui::RadioButton("OpenGL", &newBackend, sk_app::Window::kNativeGL_BackendType);
Brian Salomon194db172017-08-17 14:37:06 -04001105#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
1106 ImGui::SameLine();
1107 ImGui::RadioButton("ANGLE", &newBackend, sk_app::Window::kANGLE_BackendType);
1108#endif
Brian Osman621491e2017-02-28 15:45:01 -05001109#if defined(SK_VULKAN)
1110 ImGui::SameLine();
1111 ImGui::RadioButton("Vulkan", &newBackend, sk_app::Window::kVulkan_BackendType);
1112#endif
1113 if (newBackend != fBackendType) {
1114 fDeferredActions.push_back([=]() {
1115 this->setBackend(static_cast<sk_app::Window::BackendType>(newBackend));
1116 });
1117 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001118
Brian Salomon99a33902017-03-07 15:16:34 -05001119 const GrContext* ctx = fWindow->getGrContext();
1120 bool* inst = &params.fGrContextOptions.fEnableInstancedRendering;
1121 if (ctx && ImGui::Checkbox("Instanced Rendering", inst)) {
1122 paramsChanged = true;
1123 }
Jim Van Verthfbdc0802017-05-02 16:15:53 -04001124 bool* wire = &params.fGrContextOptions.fWireframeMode;
1125 if (ctx && ImGui::Checkbox("Wireframe Mode", wire)) {
1126 paramsChanged = true;
1127 }
Brian Salomon99a33902017-03-07 15:16:34 -05001128
Brian Osman28b12522017-03-08 17:10:24 -05001129 if (ctx) {
1130 int sampleCount = fWindow->sampleCount();
1131 ImGui::Text("MSAA: "); ImGui::SameLine();
1132 ImGui::RadioButton("0", &sampleCount, 0); ImGui::SameLine();
1133 ImGui::RadioButton("4", &sampleCount, 4); ImGui::SameLine();
1134 ImGui::RadioButton("8", &sampleCount, 8); ImGui::SameLine();
1135 ImGui::RadioButton("16", &sampleCount, 16);
1136
1137 if (sampleCount != params.fMSAASampleCount) {
1138 params.fMSAASampleCount = sampleCount;
1139 paramsChanged = true;
1140 }
1141 }
1142
Brian Osman8a9de3d2017-03-01 14:59:05 -05001143 if (ImGui::TreeNode("Path Renderers")) {
Brian Osman8a9de3d2017-03-01 14:59:05 -05001144 GpuPathRenderers prevPr = params.fGrContextOptions.fGpuPathRenderers;
Brian Osman8a9de3d2017-03-01 14:59:05 -05001145 auto prButton = [&](GpuPathRenderers x) {
1146 if (ImGui::RadioButton(gPathRendererNames[x].c_str(), prevPr == x)) {
Brian Salomon99a33902017-03-07 15:16:34 -05001147 if (x != params.fGrContextOptions.fGpuPathRenderers) {
1148 params.fGrContextOptions.fGpuPathRenderers = x;
1149 paramsChanged = true;
1150 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001151 }
1152 };
1153
1154 if (!ctx) {
1155 ImGui::RadioButton("Software", true);
1156 } else if (fWindow->sampleCount()) {
Brian Osman8b0f2652017-08-29 15:18:34 -04001157 prButton(GpuPathRenderers::kDefault);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001158 prButton(GpuPathRenderers::kAll);
1159 if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {
1160 prButton(GpuPathRenderers::kStencilAndCover);
1161 }
1162 if (ctx->caps()->sampleShadingSupport()) {
1163 prButton(GpuPathRenderers::kMSAA);
1164 }
1165 prButton(GpuPathRenderers::kTessellating);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001166 prButton(GpuPathRenderers::kNone);
1167 } else {
Brian Osman8b0f2652017-08-29 15:18:34 -04001168 prButton(GpuPathRenderers::kDefault);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001169 prButton(GpuPathRenderers::kAll);
Chris Dalton1a325d22017-07-14 15:17:41 -06001170 if (GrCoverageCountingPathRenderer::IsSupported(*ctx->caps())) {
1171 prButton(GpuPathRenderers::kCoverageCounting);
1172 }
Jim Van Verth83010462017-03-16 08:45:39 -04001173 prButton(GpuPathRenderers::kSmall);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001174 prButton(GpuPathRenderers::kTessellating);
1175 prButton(GpuPathRenderers::kNone);
1176 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001177 ImGui::TreePop();
1178 }
Brian Osman621491e2017-02-28 15:45:01 -05001179 }
1180
Brian Osman79086b92017-02-10 13:36:16 -05001181 if (ImGui::CollapsingHeader("Slide")) {
1182 static ImGuiTextFilter filter;
Brian Osmanf479e422017-11-08 13:11:36 -05001183 static ImVector<const char*> filteredSlideNames;
1184 static ImVector<int> filteredSlideIndices;
1185
Brian Osman79086b92017-02-10 13:36:16 -05001186 filter.Draw();
Brian Osmanf479e422017-11-08 13:11:36 -05001187 filteredSlideNames.clear();
1188 filteredSlideIndices.clear();
1189 int filteredIndex = 0;
1190 for (int i = 0; i < fSlides.count(); ++i) {
1191 const char* slideName = fSlides[i]->getName().c_str();
1192 if (filter.PassFilter(slideName) || i == fCurrentSlide) {
1193 if (i == fCurrentSlide) {
1194 filteredIndex = filteredSlideIndices.size();
Brian Osman79086b92017-02-10 13:36:16 -05001195 }
Brian Osmanf479e422017-11-08 13:11:36 -05001196 filteredSlideNames.push_back(slideName);
1197 filteredSlideIndices.push_back(i);
Brian Osman79086b92017-02-10 13:36:16 -05001198 }
Brian Osman79086b92017-02-10 13:36:16 -05001199 }
Brian Osmanf479e422017-11-08 13:11:36 -05001200
1201 int previousSlide = fCurrentSlide;
1202 if (ImGui::ListBox("", &filteredIndex, filteredSlideNames.begin(),
1203 filteredSlideNames.size(), 20)) {
1204 fCurrentSlide = filteredSlideIndices[filteredIndex];
1205 setupCurrentSlide(previousSlide);
Brian Osman79086b92017-02-10 13:36:16 -05001206 }
1207 }
Brian Osmana109e392017-02-24 09:49:14 -05001208
1209 if (ImGui::CollapsingHeader("Color Mode")) {
Brian Osman92004802017-03-06 11:47:26 -05001210 ColorMode newMode = fColorMode;
1211 auto cmButton = [&](ColorMode mode, const char* label) {
1212 if (ImGui::RadioButton(label, mode == fColorMode)) {
1213 newMode = mode;
1214 }
1215 };
1216
1217 cmButton(ColorMode::kLegacy, "Legacy 8888");
1218 cmButton(ColorMode::kColorManagedSRGB8888_NonLinearBlending,
1219 "Color Managed 8888 (Nonlinear blending)");
1220 cmButton(ColorMode::kColorManagedSRGB8888, "Color Managed 8888");
1221 cmButton(ColorMode::kColorManagedLinearF16, "Color Managed F16");
1222
1223 if (newMode != fColorMode) {
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001224 // It isn't safe to switch color mode now (in the middle of painting). We might
1225 // tear down the back-end, etc... Defer this change until the next onIdle.
1226 fDeferredActions.push_back([=]() {
Brian Osman92004802017-03-06 11:47:26 -05001227 this->setColorMode(newMode);
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001228 });
Brian Osmana109e392017-02-24 09:49:14 -05001229 }
1230
1231 // Pick from common gamuts:
1232 int primariesIdx = 4; // Default: Custom
1233 for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
1234 if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
1235 primariesIdx = i;
1236 break;
1237 }
1238 }
1239
1240 if (ImGui::Combo("Primaries", &primariesIdx,
1241 "sRGB\0AdobeRGB\0P3\0Rec. 2020\0Custom\0\0")) {
1242 if (primariesIdx >= 0 && primariesIdx <= 3) {
1243 fColorSpacePrimaries = *gNamedPrimaries[primariesIdx].fPrimaries;
1244 }
1245 }
1246
1247 // Allow direct editing of gamut
1248 ImGui_Primaries(&fColorSpacePrimaries, &fImGuiGamutPaint);
1249 }
Brian Osman79086b92017-02-10 13:36:16 -05001250 }
Brian Salomon99a33902017-03-07 15:16:34 -05001251 if (paramsChanged) {
1252 fDeferredActions.push_back([=]() {
1253 fWindow->setRequestedDisplayParams(params);
1254 fWindow->inval();
1255 this->updateTitle();
1256 });
1257 }
Brian Osman79086b92017-02-10 13:36:16 -05001258 ImGui::End();
1259 }
1260
Brian Osmanf6877092017-02-13 09:39:57 -05001261 SkPaint zoomImagePaint;
1262 if (fShowZoomWindow && fLastImage) {
1263 if (ImGui::Begin("Zoom", &fShowZoomWindow, ImVec2(200, 200))) {
1264 static int zoomFactor = 4;
1265 ImGui::SliderInt("Scale", &zoomFactor, 1, 16);
1266
Mike Reed0acd7952017-04-28 11:12:19 -04001267 zoomImagePaint.setShader(fLastImage->makeShader());
Brian Osmanf6877092017-02-13 09:39:57 -05001268 zoomImagePaint.setColor(SK_ColorWHITE);
1269
1270 // Zoom by shrinking the corner UVs towards the mouse cursor
1271 ImVec2 mousePos = ImGui::GetMousePos();
1272 ImVec2 avail = ImGui::GetContentRegionAvail();
1273
1274 ImVec2 zoomHalfExtents = ImVec2((avail.x * 0.5f) / zoomFactor,
1275 (avail.y * 0.5f) / zoomFactor);
1276 ImGui::Image(&zoomImagePaint, avail,
1277 ImVec2(mousePos.x - zoomHalfExtents.x, mousePos.y - zoomHalfExtents.y),
1278 ImVec2(mousePos.x + zoomHalfExtents.x, mousePos.y + zoomHalfExtents.y));
1279 }
1280
1281 ImGui::End();
1282 }
1283
Brian Osman79086b92017-02-10 13:36:16 -05001284 // This causes ImGui to rebuild vertex/index data based on all immediate-mode commands
1285 // (widgets, etc...) that have been issued
1286 ImGui::Render();
1287
1288 // Then we fetch the most recent data, and convert it so we can render with Skia
1289 const ImDrawData* drawData = ImGui::GetDrawData();
1290 SkTDArray<SkPoint> pos;
1291 SkTDArray<SkPoint> uv;
1292 SkTDArray<SkColor> color;
Brian Osman79086b92017-02-10 13:36:16 -05001293
1294 for (int i = 0; i < drawData->CmdListsCount; ++i) {
1295 const ImDrawList* drawList = drawData->CmdLists[i];
1296
1297 // De-interleave all vertex data (sigh), convert to Skia types
1298 pos.rewind(); uv.rewind(); color.rewind();
1299 for (int i = 0; i < drawList->VtxBuffer.size(); ++i) {
1300 const ImDrawVert& vert = drawList->VtxBuffer[i];
1301 pos.push(SkPoint::Make(vert.pos.x, vert.pos.y));
1302 uv.push(SkPoint::Make(vert.uv.x, vert.uv.y));
1303 color.push(vert.col);
1304 }
1305 // ImGui colors are RGBA
1306 SkSwapRB(color.begin(), color.begin(), color.count());
1307
1308 int indexOffset = 0;
1309
1310 // Draw everything with canvas.drawVertices...
1311 for (int j = 0; j < drawList->CmdBuffer.size(); ++j) {
1312 const ImDrawCmd* drawCmd = &drawList->CmdBuffer[j];
1313
1314 // TODO: Find min/max index for each draw, so we know how many vertices (sigh)
1315 if (drawCmd->UserCallback) {
1316 drawCmd->UserCallback(drawList, drawCmd);
1317 } else {
Brian Osmanf6877092017-02-13 09:39:57 -05001318 SkPaint* paint = static_cast<SkPaint*>(drawCmd->TextureId);
1319 SkASSERT(paint);
1320
Brian Osman79086b92017-02-10 13:36:16 -05001321 canvas->save();
1322 canvas->clipRect(SkRect::MakeLTRB(drawCmd->ClipRect.x, drawCmd->ClipRect.y,
1323 drawCmd->ClipRect.z, drawCmd->ClipRect.w));
Mike Reed887cdf12017-04-03 11:11:09 -04001324 canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode,
1325 drawList->VtxBuffer.size(), pos.begin(),
1326 uv.begin(), color.begin(),
1327 drawCmd->ElemCount,
1328 drawList->IdxBuffer.begin() + indexOffset),
1329 SkBlendMode::kModulate, *paint);
Brian Osman79086b92017-02-10 13:36:16 -05001330 indexOffset += drawCmd->ElemCount;
1331 canvas->restore();
1332 }
1333 }
1334 }
1335}
1336
liyuqian2edb0f42016-07-06 14:11:32 -07001337void Viewer::onIdle() {
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001338 for (int i = 0; i < fDeferredActions.count(); ++i) {
1339 fDeferredActions[i]();
1340 }
1341 fDeferredActions.reset();
1342
Brian Osman1df161a2017-02-09 12:10:20 -05001343 double startTime = SkTime::GetMSecs();
jvanverthc265a922016-04-08 12:51:45 -07001344 fAnimTimer.updateTime();
Brian Osman1df161a2017-02-09 12:10:20 -05001345 bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer);
1346 fAnimateTimes[fCurrentMeasurement] = SkTime::GetMSecs() - startTime;
1347
Brian Osman79086b92017-02-10 13:36:16 -05001348 ImGuiIO& io = ImGui::GetIO();
1349 if (animateWantsInval || fDisplayStats || fRefresh || io.MetricsActiveWindows) {
jvanverthc265a922016-04-08 12:51:45 -07001350 fWindow->inval();
1351 }
jvanverth9f372462016-04-06 06:08:59 -07001352}
liyuqiane5a6cd92016-05-27 08:52:52 -07001353
1354void Viewer::updateUIState() {
csmartdalton578f0642017-02-24 16:04:47 -07001355 if (!fWindow) {
1356 return;
1357 }
1358 if (fWindow->sampleCount() < 0) {
1359 return; // Surface hasn't been created yet.
1360 }
1361
liyuqianb73c24b2016-06-03 08:47:23 -07001362 // Slide state
liyuqiane5a6cd92016-05-27 08:52:52 -07001363 Json::Value slideState(Json::objectValue);
1364 slideState[kName] = kSlideStateName;
1365 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
liyuqian1f508fd2016-06-07 06:57:40 -07001366 if (fAllSlideNames.size() == 0) {
1367 for(auto slide : fSlides) {
1368 fAllSlideNames.append(Json::Value(slide->getName().c_str()));
1369 }
liyuqiane5a6cd92016-05-27 08:52:52 -07001370 }
liyuqian1f508fd2016-06-07 06:57:40 -07001371 slideState[kOptions] = fAllSlideNames;
liyuqiane5a6cd92016-05-27 08:52:52 -07001372
liyuqianb73c24b2016-06-03 08:47:23 -07001373 // Backend state
liyuqiane5a6cd92016-05-27 08:52:52 -07001374 Json::Value backendState(Json::objectValue);
1375 backendState[kName] = kBackendStateName;
liyuqian6cb70252016-06-02 12:16:25 -07001376 backendState[kValue] = kBackendTypeStrings[fBackendType];
liyuqiane5a6cd92016-05-27 08:52:52 -07001377 backendState[kOptions] = Json::Value(Json::arrayValue);
liyuqianb73c24b2016-06-03 08:47:23 -07001378 for (auto str : kBackendTypeStrings) {
liyuqian6cb70252016-06-02 12:16:25 -07001379 backendState[kOptions].append(Json::Value(str));
1380 }
liyuqiane5a6cd92016-05-27 08:52:52 -07001381
csmartdalton578f0642017-02-24 16:04:47 -07001382 // MSAA state
1383 Json::Value msaaState(Json::objectValue);
1384 msaaState[kName] = kMSAAStateName;
1385 msaaState[kValue] = fWindow->sampleCount();
1386 msaaState[kOptions] = Json::Value(Json::arrayValue);
1387 if (sk_app::Window::kRaster_BackendType == fBackendType) {
1388 msaaState[kOptions].append(Json::Value(0));
1389 } else {
1390 for (int msaa : {0, 4, 8, 16}) {
1391 msaaState[kOptions].append(Json::Value(msaa));
1392 }
1393 }
1394
csmartdalton61cd31a2017-02-27 17:00:53 -07001395 // Path renderer state
1396 GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers;
1397 Json::Value prState(Json::objectValue);
1398 prState[kName] = kPathRendererStateName;
1399 prState[kValue] = gPathRendererNames[pr];
1400 prState[kOptions] = Json::Value(Json::arrayValue);
1401 const GrContext* ctx = fWindow->getGrContext();
1402 if (!ctx) {
1403 prState[kOptions].append("Software");
1404 } else if (fWindow->sampleCount()) {
Brian Osman8b0f2652017-08-29 15:18:34 -04001405 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kDefault]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001406 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kAll]);
1407 if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {
1408 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kStencilAndCover]);
1409 }
1410 if (ctx->caps()->sampleShadingSupport()) {
1411 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kMSAA]);
1412 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001413 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kTessellating]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001414 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kNone]);
1415 } else {
Brian Osman8b0f2652017-08-29 15:18:34 -04001416 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kDefault]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001417 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kAll]);
Chris Dalton1a325d22017-07-14 15:17:41 -06001418 if (GrCoverageCountingPathRenderer::IsSupported(*ctx->caps())) {
1419 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kCoverageCounting]);
1420 }
Jim Van Verth83010462017-03-16 08:45:39 -04001421 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kSmall]);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001422 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kTessellating]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001423 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kNone]);
1424 }
1425
Brian Salomon99a33902017-03-07 15:16:34 -05001426 // Instanced rendering state
1427 Json::Value instState(Json::objectValue);
1428 instState[kName] = kInstancedRenderingStateName;
Yuqian Lid9020422017-07-25 15:01:53 -04001429 instState[kValue] = kOFF;
1430 instState[kOptions] = Json::Value(Json::arrayValue);
Brian Salomon99a33902017-03-07 15:16:34 -05001431 if (ctx) {
1432 if (fWindow->getRequestedDisplayParams().fGrContextOptions.fEnableInstancedRendering) {
1433 instState[kValue] = kON;
Brian Salomon99a33902017-03-07 15:16:34 -05001434 }
Brian Salomon99a33902017-03-07 15:16:34 -05001435 instState[kOptions].append(kOFF);
1436 instState[kOptions].append(kON);
1437 }
1438
liyuqianb73c24b2016-06-03 08:47:23 -07001439 // Softkey state
1440 Json::Value softkeyState(Json::objectValue);
1441 softkeyState[kName] = kSoftkeyStateName;
1442 softkeyState[kValue] = kSoftkeyHint;
1443 softkeyState[kOptions] = Json::Value(Json::arrayValue);
1444 softkeyState[kOptions].append(kSoftkeyHint);
1445 for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) {
1446 softkeyState[kOptions].append(Json::Value(softkey.c_str()));
1447 }
1448
liyuqian1f508fd2016-06-07 06:57:40 -07001449 // FPS state
1450 Json::Value fpsState(Json::objectValue);
1451 fpsState[kName] = kFpsStateName;
Brian Osman1df161a2017-02-09 12:10:20 -05001452 int idx = (fCurrentMeasurement + (kMeasurementCount - 1)) & (kMeasurementCount - 1);
1453 fpsState[kValue] = SkStringPrintf("%8.3lf ms\n\nA %8.3lf\nP %8.3lf\nF%8.3lf",
1454 fAnimateTimes[idx] + fPaintTimes[idx] + fFlushTimes[idx],
1455 fAnimateTimes[idx],
1456 fPaintTimes[idx],
1457 fFlushTimes[idx]).c_str();
liyuqian1f508fd2016-06-07 06:57:40 -07001458 fpsState[kOptions] = Json::Value(Json::arrayValue);
1459
liyuqiane5a6cd92016-05-27 08:52:52 -07001460 Json::Value state(Json::arrayValue);
1461 state.append(slideState);
1462 state.append(backendState);
csmartdalton578f0642017-02-24 16:04:47 -07001463 state.append(msaaState);
csmartdalton61cd31a2017-02-27 17:00:53 -07001464 state.append(prState);
Brian Salomon99a33902017-03-07 15:16:34 -05001465 state.append(instState);
liyuqianb73c24b2016-06-03 08:47:23 -07001466 state.append(softkeyState);
liyuqian1f508fd2016-06-07 06:57:40 -07001467 state.append(fpsState);
liyuqiane5a6cd92016-05-27 08:52:52 -07001468
1469 fWindow->setUIState(state);
1470}
1471
1472void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) {
liyuqian6cb70252016-06-02 12:16:25 -07001473 // For those who will add more features to handle the state change in this function:
1474 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
1475 // For example, after slide change, updateUIState is called inside setupCurrentSlide;
1476 // after backend change, updateUIState is called in this function.
liyuqiane5a6cd92016-05-27 08:52:52 -07001477 if (stateName.equals(kSlideStateName)) {
1478 int previousSlide = fCurrentSlide;
1479 fCurrentSlide = 0;
1480 for(auto slide : fSlides) {
1481 if (slide->getName().equals(stateValue)) {
Brian Salomon99a33902017-03-07 15:16:34 -05001482 this->setupCurrentSlide(previousSlide);
liyuqiane5a6cd92016-05-27 08:52:52 -07001483 break;
1484 }
1485 fCurrentSlide++;
1486 }
1487 if (fCurrentSlide >= fSlides.count()) {
1488 fCurrentSlide = previousSlide;
1489 SkDebugf("Slide not found: %s", stateValue.c_str());
1490 }
liyuqian6cb70252016-06-02 12:16:25 -07001491 } else if (stateName.equals(kBackendStateName)) {
1492 for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) {
1493 if (stateValue.equals(kBackendTypeStrings[i])) {
1494 if (fBackendType != i) {
1495 fBackendType = (sk_app::Window::BackendType)i;
1496 fWindow->detach();
Brian Osman70d2f432017-11-08 09:54:10 -05001497 fWindow->attach(backend_type_for_window(fBackendType));
liyuqian6cb70252016-06-02 12:16:25 -07001498 }
1499 break;
1500 }
1501 }
csmartdalton578f0642017-02-24 16:04:47 -07001502 } else if (stateName.equals(kMSAAStateName)) {
1503 DisplayParams params = fWindow->getRequestedDisplayParams();
1504 int sampleCount = atoi(stateValue.c_str());
1505 if (sampleCount != params.fMSAASampleCount) {
1506 params.fMSAASampleCount = sampleCount;
1507 fWindow->setRequestedDisplayParams(params);
1508 fWindow->inval();
Brian Salomon99a33902017-03-07 15:16:34 -05001509 this->updateTitle();
1510 this->updateUIState();
csmartdalton61cd31a2017-02-27 17:00:53 -07001511 }
1512 } else if (stateName.equals(kPathRendererStateName)) {
1513 DisplayParams params = fWindow->getRequestedDisplayParams();
1514 for (const auto& pair : gPathRendererNames) {
1515 if (pair.second == stateValue.c_str()) {
1516 if (params.fGrContextOptions.fGpuPathRenderers != pair.first) {
1517 params.fGrContextOptions.fGpuPathRenderers = pair.first;
1518 fWindow->setRequestedDisplayParams(params);
1519 fWindow->inval();
Brian Salomon99a33902017-03-07 15:16:34 -05001520 this->updateTitle();
1521 this->updateUIState();
csmartdalton61cd31a2017-02-27 17:00:53 -07001522 }
1523 break;
1524 }
csmartdalton578f0642017-02-24 16:04:47 -07001525 }
Brian Salomon99a33902017-03-07 15:16:34 -05001526 } else if (stateName.equals(kInstancedRenderingStateName)) {
1527 DisplayParams params = fWindow->getRequestedDisplayParams();
1528 bool value = !strcmp(stateValue.c_str(), kON);
1529 if (params.fGrContextOptions.fEnableInstancedRendering != value) {
1530 params.fGrContextOptions.fEnableInstancedRendering = value;
1531 fWindow->setRequestedDisplayParams(params);
1532 fWindow->inval();
1533 this->updateTitle();
1534 this->updateUIState();
1535 }
liyuqianb73c24b2016-06-03 08:47:23 -07001536 } else if (stateName.equals(kSoftkeyStateName)) {
1537 if (!stateValue.equals(kSoftkeyHint)) {
1538 fCommands.onSoftkey(stateValue);
Brian Salomon99a33902017-03-07 15:16:34 -05001539 this->updateUIState(); // This is still needed to reset the value to kSoftkeyHint
liyuqianb73c24b2016-06-03 08:47:23 -07001540 }
liyuqian2edb0f42016-07-06 14:11:32 -07001541 } else if (stateName.equals(kRefreshStateName)) {
1542 // This state is actually NOT in the UI state.
1543 // We use this to allow Android to quickly set bool fRefresh.
1544 fRefresh = stateValue.equals(kON);
liyuqiane5a6cd92016-05-27 08:52:52 -07001545 } else {
1546 SkDebugf("Unknown stateName: %s", stateName.c_str());
1547 }
1548}
Brian Osman79086b92017-02-10 13:36:16 -05001549
1550bool Viewer::onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) {
1551 return fCommands.onKey(key, state, modifiers);
1552}
1553
1554bool Viewer::onChar(SkUnichar c, uint32_t modifiers) {
Jim Van Verth6f449692017-02-14 15:16:46 -05001555 if (fSlides[fCurrentSlide]->onChar(c)) {
1556 fWindow->inval();
1557 return true;
1558 }
1559
Brian Osman79086b92017-02-10 13:36:16 -05001560 return fCommands.onChar(c, modifiers);
1561}