blob: 2a58f2dc620fc866144b77a91f33a54294d7e95c [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"
Florin Malita54f65c42018-01-16 17:04:30 -050014#include "SkottieSlide.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070015#include "SKPSlide.h"
jvanverth9f372462016-04-06 06:08:59 -070016
csmartdalton61cd31a2017-02-27 17:00:53 -070017#include "GrContext.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070018#include "SkCanvas.h"
Brian Osmanfdab5762017-11-09 10:27:55 -050019#include "SkColorSpacePriv.h"
Brian Osmane0d4fba2017-03-15 10:24:55 -040020#include "SkColorSpaceXformCanvas.h"
Brian Osman2dd96932016-10-18 15:33:53 -040021#include "SkCommandLineFlags.h"
Chris Dalton040238b2017-12-18 14:22:34 -070022#include "SkCommonFlagsGpu.h"
Brian Osman53136aa2017-07-20 15:43:35 -040023#include "SkEventTracingPriv.h"
Greg Daniel285db442016-10-14 09:12:53 -040024#include "SkGraphics.h"
Brian Osmanf750fbc2017-02-08 10:47:28 -050025#include "SkImagePriv.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070026#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050027#include "SkOSPath.h"
Ben Wagnerabdcc5f2018-02-12 16:37:28 -050028#include "SkPaintFilterCanvas.h"
Brian Osman3ac99cf2017-12-01 11:23:53 -050029#include "SkPictureRecorder.h"
Yuqian Li399b3c22017-08-03 11:08:15 -040030#include "SkScan.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070031#include "SkStream.h"
liyuqian74959a12016-06-16 14:10:34 -070032#include "SkSurface.h"
csmartdalton29d87152017-02-10 17:05:14 -050033#include "SkTaskGroup.h"
Yuqian Lib2ba6642017-11-22 12:07:41 -050034#include "SkThreadedBMPDevice.h"
jvanverth9f372462016-04-06 06:08:59 -070035
Brian Osman79086b92017-02-10 13:36:16 -050036#include "imgui.h"
37
Chris Dalton1a325d22017-07-14 15:17:41 -060038#include "ccpr/GrCoverageCountingPathRenderer.h"
39
csmartdalton578f0642017-02-24 16:04:47 -070040#include <stdlib.h>
csmartdalton61cd31a2017-02-27 17:00:53 -070041#include <map>
csmartdalton578f0642017-02-24 16:04:47 -070042
jvanverth34524262016-05-04 13:49:13 -070043using namespace sk_app;
44
csmartdalton61cd31a2017-02-27 17:00:53 -070045static std::map<GpuPathRenderers, std::string> gPathRendererNames;
46
jvanverth9f372462016-04-06 06:08:59 -070047Application* Application::Create(int argc, char** argv, void* platformData) {
jvanverth34524262016-05-04 13:49:13 -070048 return new Viewer(argc, argv, platformData);
jvanverth9f372462016-04-06 06:08:59 -070049}
50
Brian Osman2dd96932016-10-18 15:33:53 -040051static DEFINE_string2(match, m, nullptr,
jvanverth2bb3b6d2016-04-08 07:24:09 -070052 "[~][^]substring[$] [...] of bench name to run.\n"
53 "Multiple matches may be separated by spaces.\n"
54 "~ causes a matching bench to always be skipped\n"
55 "^ requires the start of the bench to match\n"
56 "$ requires the end of the bench to match\n"
57 "^ and $ requires an exact match\n"
58 "If a bench does not match any list entry,\n"
59 "it is skipped unless some list entry starts with ~");
bsalomon6c471f72016-07-26 12:56:32 -070060
Chris Dalton7a0ebfc2017-10-13 12:35:50 -060061static DEFINE_string(slide, "", "Start on this sample.");
62static DEFINE_bool(list, false, "List samples?");
Jim Van Verth6f449692017-02-14 15:16:46 -050063
bsalomon6c471f72016-07-26 12:56:32 -070064#ifdef SK_VULKAN
jvanverthb8794cc2016-07-27 14:29:18 -070065# define BACKENDS_STR "\"sw\", \"gl\", and \"vk\""
bsalomon6c471f72016-07-26 12:56:32 -070066#else
67# define BACKENDS_STR "\"sw\" and \"gl\""
68#endif
69
liyuqian71491dc2016-06-09 12:02:34 -070070#ifdef SK_BUILD_FOR_ANDROID
Brian Salomon96789b32017-05-26 12:06:21 -040071static DEFINE_string(skps, "/data/local/tmp/skps", "Directory to read skps from.");
72static DEFINE_string(jpgs, "/data/local/tmp/resources", "Directory to read jpgs from.");
Florin Malita094ccde2017-12-30 12:27:00 -050073static DEFINE_string(jsons, "/data/local/tmp/jsons", "Directory to read (Bodymovin) jsons from.");
liyuqian71491dc2016-06-09 12:02:34 -070074#else
Brian Osman2dd96932016-10-18 15:33:53 -040075static DEFINE_string(skps, "skps", "Directory to read skps from.");
76static DEFINE_string(jpgs, "jpgs", "Directory to read jpgs from.");
Florin Malita094ccde2017-12-30 12:27:00 -050077static DEFINE_string(jsons, "jsons", "Directory to read (Bodymovin) jsons from.");
liyuqian71491dc2016-06-09 12:02:34 -070078#endif
jvanverth2bb3b6d2016-04-08 07:24:09 -070079
Brian Osman2dd96932016-10-18 15:33:53 -040080static DEFINE_string2(backend, b, "sw", "Backend to use. Allowed values are " BACKENDS_STR ".");
bsalomon6c471f72016-07-26 12:56:32 -070081
Brian Salomonbdecacf2018-02-02 20:32:49 -050082static DEFINE_int32(msaa, 1, "Number of subpixel samples. 0 for no HW antialiasing.");
csmartdalton008b9d82017-02-22 12:00:42 -070083
Brian Osman53136aa2017-07-20 15:43:35 -040084DECLARE_int32(threads)
Brian Salomon41eac792017-03-08 14:03:56 -050085
Brian Salomon194db172017-08-17 14:37:06 -040086const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
csmartdalton578f0642017-02-24 16:04:47 -070087 "OpenGL",
Brian Salomon194db172017-08-17 14:37:06 -040088#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
89 "ANGLE",
90#endif
jvanverth063ece72016-06-17 09:29:14 -070091#ifdef SK_VULKAN
csmartdalton578f0642017-02-24 16:04:47 -070092 "Vulkan",
jvanverth063ece72016-06-17 09:29:14 -070093#endif
csmartdalton578f0642017-02-24 16:04:47 -070094 "Raster"
jvanverthaf236b52016-05-20 06:01:06 -070095};
96
bsalomon6c471f72016-07-26 12:56:32 -070097static sk_app::Window::BackendType get_backend_type(const char* str) {
98#ifdef SK_VULKAN
99 if (0 == strcmp(str, "vk")) {
100 return sk_app::Window::kVulkan_BackendType;
101 } else
102#endif
Brian Salomon194db172017-08-17 14:37:06 -0400103#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
104 if (0 == strcmp(str, "angle")) {
105 return sk_app::Window::kANGLE_BackendType;
106 } else
107#endif
bsalomon6c471f72016-07-26 12:56:32 -0700108 if (0 == strcmp(str, "gl")) {
109 return sk_app::Window::kNativeGL_BackendType;
110 } else if (0 == strcmp(str, "sw")) {
111 return sk_app::Window::kRaster_BackendType;
112 } else {
113 SkDebugf("Unknown backend type, %s, defaulting to sw.", str);
114 return sk_app::Window::kRaster_BackendType;
115 }
116}
117
Brian Osmana109e392017-02-24 09:49:14 -0500118static SkColorSpacePrimaries gSrgbPrimaries = {
119 0.64f, 0.33f,
120 0.30f, 0.60f,
121 0.15f, 0.06f,
122 0.3127f, 0.3290f };
123
124static SkColorSpacePrimaries gAdobePrimaries = {
125 0.64f, 0.33f,
126 0.21f, 0.71f,
127 0.15f, 0.06f,
128 0.3127f, 0.3290f };
129
130static SkColorSpacePrimaries gP3Primaries = {
131 0.680f, 0.320f,
132 0.265f, 0.690f,
133 0.150f, 0.060f,
134 0.3127f, 0.3290f };
135
136static SkColorSpacePrimaries gRec2020Primaries = {
137 0.708f, 0.292f,
138 0.170f, 0.797f,
139 0.131f, 0.046f,
140 0.3127f, 0.3290f };
141
142struct NamedPrimaries {
143 const char* fName;
144 SkColorSpacePrimaries* fPrimaries;
145} gNamedPrimaries[] = {
146 { "sRGB", &gSrgbPrimaries },
147 { "AdobeRGB", &gAdobePrimaries },
148 { "P3", &gP3Primaries },
149 { "Rec. 2020", &gRec2020Primaries },
150};
151
152static bool primaries_equal(const SkColorSpacePrimaries& a, const SkColorSpacePrimaries& b) {
153 return memcmp(&a, &b, sizeof(SkColorSpacePrimaries)) == 0;
154}
155
Brian Osman70d2f432017-11-08 09:54:10 -0500156static Window::BackendType backend_type_for_window(Window::BackendType backendType) {
157 // In raster mode, we still use GL for the window.
158 // This lets us render the GUI faster (and correct).
159 return Window::kRaster_BackendType == backendType ? Window::kNativeGL_BackendType : backendType;
160}
161
liyuqiane5a6cd92016-05-27 08:52:52 -0700162const char* kName = "name";
163const char* kValue = "value";
164const char* kOptions = "options";
165const char* kSlideStateName = "Slide";
166const char* kBackendStateName = "Backend";
csmartdalton578f0642017-02-24 16:04:47 -0700167const char* kMSAAStateName = "MSAA";
csmartdalton61cd31a2017-02-27 17:00:53 -0700168const char* kPathRendererStateName = "Path renderer";
liyuqianb73c24b2016-06-03 08:47:23 -0700169const char* kSoftkeyStateName = "Softkey";
170const char* kSoftkeyHint = "Please select a softkey";
liyuqian1f508fd2016-06-07 06:57:40 -0700171const char* kFpsStateName = "FPS";
liyuqian6f163d22016-06-13 12:26:45 -0700172const char* kON = "ON";
173const char* kOFF = "OFF";
liyuqian2edb0f42016-07-06 14:11:32 -0700174const char* kRefreshStateName = "Refresh";
liyuqiane5a6cd92016-05-27 08:52:52 -0700175
jvanverth34524262016-05-04 13:49:13 -0700176Viewer::Viewer(int argc, char** argv, void* platformData)
Florin Malitaab99c342018-01-16 16:23:03 -0500177 : fCurrentSlide(-1)
178 , fRefresh(false)
Brian Osman3ac99cf2017-12-01 11:23:53 -0500179 , fSaveToSKP(false)
Brian Osman79086b92017-02-10 13:36:16 -0500180 , fShowImGuiDebugWindow(false)
Brian Osmanfce09c52017-11-14 15:32:20 -0500181 , fShowSlidePicker(false)
Brian Osman79086b92017-02-10 13:36:16 -0500182 , fShowImGuiTestWindow(false)
Brian Osmanf6877092017-02-13 09:39:57 -0500183 , fShowZoomWindow(false)
184 , fLastImage(nullptr)
jvanverth063ece72016-06-17 09:29:14 -0700185 , fBackendType(sk_app::Window::kNativeGL_BackendType)
Brian Osman92004802017-03-06 11:47:26 -0500186 , fColorMode(ColorMode::kLegacy)
Brian Osmana109e392017-02-24 09:49:14 -0500187 , fColorSpacePrimaries(gSrgbPrimaries)
Brian Osmanfdab5762017-11-09 10:27:55 -0500188 // Our UI can only tweak gamma (currently), so start out gamma-only
189 , fColorSpaceTransferFn(g2Dot2_TransferFn)
egdaniel2a0bb0a2016-04-11 08:30:40 -0700190 , fZoomLevel(0.0f)
Brian Osmanb53f48c2017-06-07 10:00:30 -0400191 , fGestureDevice(GestureDevice::kNone)
Yuqian Lib2ba6642017-11-22 12:07:41 -0500192 , fTileCnt(0)
193 , fThreadCnt(0)
jvanverthc265a922016-04-08 12:51:45 -0700194{
Greg Daniel285db442016-10-14 09:12:53 -0400195 SkGraphics::Init();
csmartdalton61cd31a2017-02-27 17:00:53 -0700196
Brian Osmanf09e35e2017-12-15 14:48:09 -0500197 gPathRendererNames[GpuPathRenderers::kAll] = "All Path Renderers";
198 gPathRendererNames[GpuPathRenderers::kDefault] =
199 "Default Ganesh Behavior (best path renderer, not including CCPR)";
200 gPathRendererNames[GpuPathRenderers::kStencilAndCover] = "NV_path_rendering";
201 gPathRendererNames[GpuPathRenderers::kMSAA] = "Sample shading";
202 gPathRendererNames[GpuPathRenderers::kSmall] = "Small paths (cached sdf or alpha masks)";
203 gPathRendererNames[GpuPathRenderers::kCoverageCounting] = "Coverage counting";
204 gPathRendererNames[GpuPathRenderers::kTessellating] = "Tessellating";
205 gPathRendererNames[GpuPathRenderers::kNone] = "Software masks";
csmartdalton61cd31a2017-02-27 17:00:53 -0700206
jvanverth2bb3b6d2016-04-08 07:24:09 -0700207 SkDebugf("Command line arguments: ");
208 for (int i = 1; i < argc; ++i) {
209 SkDebugf("%s ", argv[i]);
210 }
211 SkDebugf("\n");
212
213 SkCommandLineFlags::Parse(argc, argv);
Greg Daniel9fcc7432016-11-29 16:35:19 -0500214#ifdef SK_BUILD_FOR_ANDROID
Brian Salomon96789b32017-05-26 12:06:21 -0400215 SetResourcePath("/data/local/tmp/resources");
Greg Daniel9fcc7432016-11-29 16:35:19 -0500216#endif
jvanverth2bb3b6d2016-04-08 07:24:09 -0700217
Brian Osmanbc8150f2017-07-24 11:38:01 -0400218 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -0400219 static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads);
Greg Daniel285db442016-10-14 09:12:53 -0400220
bsalomon6c471f72016-07-26 12:56:32 -0700221 fBackendType = get_backend_type(FLAGS_backend[0]);
jvanverth9f372462016-04-06 06:08:59 -0700222 fWindow = Window::CreateNativeWindow(platformData);
jvanverth9f372462016-04-06 06:08:59 -0700223
csmartdalton578f0642017-02-24 16:04:47 -0700224 DisplayParams displayParams;
225 displayParams.fMSAASampleCount = FLAGS_msaa;
Chris Dalton040238b2017-12-18 14:22:34 -0700226 SetCtxOptionsFromCommonFlags(&displayParams.fGrContextOptions);
csmartdalton578f0642017-02-24 16:04:47 -0700227 fWindow->setRequestedDisplayParams(displayParams);
228
Brian Osman56a24812017-12-19 11:15:16 -0500229 // Configure timers
230 fStatsLayer.setActive(false);
231 fAnimateTimer = fStatsLayer.addTimer("Animate", SK_ColorMAGENTA, 0xffff66ff);
232 fPaintTimer = fStatsLayer.addTimer("Paint", SK_ColorGREEN);
233 fFlushTimer = fStatsLayer.addTimer("Flush", SK_ColorRED, 0xffff6666);
234
jvanverth9f372462016-04-06 06:08:59 -0700235 // register callbacks
brianosman622c8d52016-05-10 06:50:49 -0700236 fCommands.attach(fWindow);
Brian Osman80fc07e2017-12-08 16:45:43 -0500237 fWindow->pushLayer(this);
Brian Osman56a24812017-12-19 11:15:16 -0500238 fWindow->pushLayer(&fStatsLayer);
Brian Osmand67e5182017-12-08 16:46:09 -0500239 fWindow->pushLayer(&fImGuiLayer);
jvanverth9f372462016-04-06 06:08:59 -0700240
brianosman622c8d52016-05-10 06:50:49 -0700241 // add key-bindings
Brian Osman79086b92017-02-10 13:36:16 -0500242 fCommands.addCommand(' ', "GUI", "Toggle Debug GUI", [this]() {
243 this->fShowImGuiDebugWindow = !this->fShowImGuiDebugWindow;
244 fWindow->inval();
245 });
Brian Osmanfce09c52017-11-14 15:32:20 -0500246 // Command to jump directly to the slide picker and give it focus
247 fCommands.addCommand('/', "GUI", "Jump to slide picker", [this]() {
248 this->fShowImGuiDebugWindow = true;
249 this->fShowSlidePicker = true;
250 fWindow->inval();
251 });
252 // Alias that to Backspace, to match SampleApp
253 fCommands.addCommand(Window::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() {
254 this->fShowImGuiDebugWindow = true;
255 this->fShowSlidePicker = true;
256 fWindow->inval();
257 });
Brian Osman79086b92017-02-10 13:36:16 -0500258 fCommands.addCommand('g', "GUI", "Toggle GUI Demo", [this]() {
259 this->fShowImGuiTestWindow = !this->fShowImGuiTestWindow;
260 fWindow->inval();
261 });
Brian Osmanf6877092017-02-13 09:39:57 -0500262 fCommands.addCommand('z', "GUI", "Toggle zoom window", [this]() {
263 this->fShowZoomWindow = !this->fShowZoomWindow;
264 fWindow->inval();
265 });
brianosman622c8d52016-05-10 06:50:49 -0700266 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
Brian Osman56a24812017-12-19 11:15:16 -0500267 fStatsLayer.setActive(!fStatsLayer.getActive());
brianosman622c8d52016-05-10 06:50:49 -0700268 fWindow->inval();
269 });
Jim Van Verth90dcce52017-11-03 13:36:07 -0400270 fCommands.addCommand('0', "Overlays", "Reset stats", [this]() {
Brian Osman56a24812017-12-19 11:15:16 -0500271 fStatsLayer.resetMeasurements();
Jim Van Verth90dcce52017-11-03 13:36:07 -0400272 this->updateTitle();
273 fWindow->inval();
274 });
Brian Osmanf750fbc2017-02-08 10:47:28 -0500275 fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() {
Brian Osman92004802017-03-06 11:47:26 -0500276 switch (fColorMode) {
277 case ColorMode::kLegacy:
278 this->setColorMode(ColorMode::kColorManagedSRGB8888_NonLinearBlending);
279 break;
280 case ColorMode::kColorManagedSRGB8888_NonLinearBlending:
281 this->setColorMode(ColorMode::kColorManagedSRGB8888);
282 break;
283 case ColorMode::kColorManagedSRGB8888:
284 this->setColorMode(ColorMode::kColorManagedLinearF16);
285 break;
286 case ColorMode::kColorManagedLinearF16:
287 this->setColorMode(ColorMode::kLegacy);
288 break;
Brian Osmanf750fbc2017-02-08 10:47:28 -0500289 }
brianosman622c8d52016-05-10 06:50:49 -0700290 });
291 fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
Florin Malitaab99c342018-01-16 16:23:03 -0500292 this->setCurrentSlide(fCurrentSlide < fSlides.count() - 1 ? fCurrentSlide + 1 : 0);
brianosman622c8d52016-05-10 06:50:49 -0700293 });
294 fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
Florin Malitaab99c342018-01-16 16:23:03 -0500295 this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.count() - 1);
brianosman622c8d52016-05-10 06:50:49 -0700296 });
297 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
298 this->changeZoomLevel(1.f / 32.f);
299 fWindow->inval();
300 });
301 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
302 this->changeZoomLevel(-1.f / 32.f);
303 fWindow->inval();
304 });
jvanverthaf236b52016-05-20 06:01:06 -0700305 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
Brian Salomon194db172017-08-17 14:37:06 -0400306 sk_app::Window::BackendType newBackend = (sk_app::Window::BackendType)(
307 (fBackendType + 1) % sk_app::Window::kBackendTypeCount);
Jim Van Verthd63c1022017-01-05 13:50:49 -0500308 // Switching to and from Vulkan is problematic on Linux so disabled for now
Brian Salomon194db172017-08-17 14:37:06 -0400309#if defined(SK_BUILD_FOR_UNIX) && defined(SK_VULKAN)
310 if (newBackend == sk_app::Window::kVulkan_BackendType) {
311 newBackend = (sk_app::Window::BackendType)((newBackend + 1) %
312 sk_app::Window::kBackendTypeCount);
313 } else if (fBackendType == sk_app::Window::kVulkan_BackendType) {
314 newBackend = sk_app::Window::kVulkan_BackendType;
Jim Van Verthd63c1022017-01-05 13:50:49 -0500315 }
316#endif
Brian Osman621491e2017-02-28 15:45:01 -0500317 this->setBackend(newBackend);
jvanverthaf236b52016-05-20 06:01:06 -0700318 });
Yuqian Lib2ba6642017-11-22 12:07:41 -0500319 fCommands.addCommand('+', "Threaded Backend", "Increase tile count", [this]() {
320 fTileCnt++;
321 if (fThreadCnt == 0) {
322 this->resetExecutor();
323 }
324 this->updateTitle();
325 fWindow->inval();
326 });
327 fCommands.addCommand('-', "Threaded Backend", "Decrease tile count", [this]() {
328 fTileCnt = SkTMax(0, fTileCnt - 1);
329 if (fThreadCnt == 0) {
330 this->resetExecutor();
331 }
332 this->updateTitle();
333 fWindow->inval();
334 });
335 fCommands.addCommand('>', "Threaded Backend", "Increase thread count", [this]() {
336 if (fTileCnt == 0) {
337 return;
338 }
339 fThreadCnt = (fThreadCnt + 1) % fTileCnt;
340 this->resetExecutor();
341 this->updateTitle();
342 fWindow->inval();
343 });
344 fCommands.addCommand('<', "Threaded Backend", "Decrease thread count", [this]() {
345 if (fTileCnt == 0) {
346 return;
347 }
348 fThreadCnt = (fThreadCnt + fTileCnt - 1) % fTileCnt;
349 this->resetExecutor();
350 this->updateTitle();
351 fWindow->inval();
352 });
Brian Osman3ac99cf2017-12-01 11:23:53 -0500353 fCommands.addCommand('K', "IO", "Save slide to SKP", [this]() {
354 fSaveToSKP = true;
355 fWindow->inval();
356 });
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500357 fCommands.addCommand('H', "Paint", "Hinting mode", [this]() {
358 if (!fPaintOverrides.fHinting) {
359 fPaintOverrides.fHinting = true;
360 fPaint.setHinting(SkPaint::kNo_Hinting);
361 } else {
362 switch (fPaint.getHinting()) {
363 case SkPaint::kNo_Hinting:
364 fPaint.setHinting(SkPaint::kSlight_Hinting);
365 break;
366 case SkPaint::kSlight_Hinting:
367 fPaint.setHinting(SkPaint::kNormal_Hinting);
368 break;
369 case SkPaint::kNormal_Hinting:
370 fPaint.setHinting(SkPaint::kFull_Hinting);
371 break;
372 case SkPaint::kFull_Hinting:
373 fPaint.setHinting(SkPaint::kNo_Hinting);
374 fPaintOverrides.fHinting = false;
375 break;
376 }
377 }
378 this->updateTitle();
379 fWindow->inval();
380 });
381 fCommands.addCommand('A', "Paint", "Antialias Mode", [this]() {
382 if (!(fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag)) {
383 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias;
384 fPaintOverrides.fFlags |= SkPaint::kAntiAlias_Flag;
385 fPaint.setAntiAlias(false);
386 fPaintOverrides.fOriginalSkUseAnalyticAA = gSkUseAnalyticAA;
387 fPaintOverrides.fOriginalSkForceAnalyticAA = gSkForceAnalyticAA;
388 fPaintOverrides.fOriginalSkUseDeltaAA = gSkUseDeltaAA;
389 fPaintOverrides.fOriginalSkForceDeltaAA = gSkForceDeltaAA;
390 gSkUseAnalyticAA = gSkForceAnalyticAA = false;
391 gSkUseDeltaAA = gSkForceDeltaAA = false;
392 } else {
393 fPaint.setAntiAlias(true);
394 switch (fPaintOverrides.fAntiAlias) {
395 case SkPaintFields::AntiAliasState::Alias:
396 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Normal;
397 break;
398 case SkPaintFields::AntiAliasState::Normal:
399 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAEnabled;
400 gSkUseDeltaAA = gSkForceDeltaAA = false;
401 gSkUseAnalyticAA = true;
402 break;
403 case SkPaintFields::AntiAliasState::AnalyticAAEnabled:
404 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAForced;
405 gSkForceAnalyticAA = true;
406 break;
407 case SkPaintFields::AntiAliasState::AnalyticAAForced:
408 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAEnabled;
409 gSkUseAnalyticAA = gSkForceAnalyticAA = false;
410 gSkUseDeltaAA = true;
411 break;
412 case SkPaintFields::AntiAliasState::DeltaAAEnabled:
413 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAForced;
414 gSkForceDeltaAA = true;
415 break;
416 case SkPaintFields::AntiAliasState::DeltaAAForced:
417 fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias;
418 fPaintOverrides.fFlags &= ~SkPaint::kAntiAlias_Flag;
419 gSkUseAnalyticAA = fPaintOverrides.fOriginalSkUseAnalyticAA;
420 gSkForceAnalyticAA = fPaintOverrides.fOriginalSkForceAnalyticAA;
421 gSkUseDeltaAA = fPaintOverrides.fOriginalSkUseDeltaAA;
422 gSkForceDeltaAA = fPaintOverrides.fOriginalSkForceDeltaAA;
423 break;
424 }
425 }
426 this->updateTitle();
427 fWindow->inval();
428 });
429 fCommands.addCommand('L', "Paint", "Subpixel Antialias Mode", [this]() {
430 if (!(fPaintOverrides.fFlags & SkPaint::kLCDRenderText_Flag)) {
431 fPaintOverrides.fFlags |= SkPaint::kLCDRenderText_Flag;
432 fPaint.setLCDRenderText(false);
433 } else {
434 if (!fPaint.isLCDRenderText()) {
435 fPaint.setLCDRenderText(true);
436 } else {
437 fPaintOverrides.fFlags &= ~SkPaint::kLCDRenderText_Flag;
438 }
439 }
440 this->updateTitle();
441 fWindow->inval();
442 });
443 fCommands.addCommand('S', "Paint", "Subpixel Position Mode", [this]() {
444 if (!(fPaintOverrides.fFlags & SkPaint::kSubpixelText_Flag)) {
445 fPaintOverrides.fFlags |= SkPaint::kSubpixelText_Flag;
446 fPaint.setSubpixelText(false);
447 } else {
448 if (!fPaint.isSubpixelText()) {
449 fPaint.setSubpixelText(true);
450 } else {
451 fPaintOverrides.fFlags &= ~SkPaint::kSubpixelText_Flag;
452 }
453 }
454 this->updateTitle();
455 fWindow->inval();
456 });
Yuqian Lib2ba6642017-11-22 12:07:41 -0500457
jvanverth2bb3b6d2016-04-08 07:24:09 -0700458 // set up slides
459 this->initSlides();
Jim Van Verth6f449692017-02-14 15:16:46 -0500460 if (FLAGS_list) {
461 this->listNames();
462 }
jvanverth2bb3b6d2016-04-08 07:24:09 -0700463
djsollen12d62a72016-04-21 07:59:44 -0700464 fAnimTimer.run();
465
Hal Canaryc465d132017-12-08 10:21:31 -0500466 auto gamutImage = GetResourceAsImage("images/gamut.png");
Brian Osmana109e392017-02-24 09:49:14 -0500467 if (gamutImage) {
Mike Reed0acd7952017-04-28 11:12:19 -0400468 fImGuiGamutPaint.setShader(gamutImage->makeShader());
Brian Osmana109e392017-02-24 09:49:14 -0500469 }
470 fImGuiGamutPaint.setColor(SK_ColorWHITE);
471 fImGuiGamutPaint.setFilterQuality(kLow_SkFilterQuality);
472
Brian Osman70d2f432017-11-08 09:54:10 -0500473 fWindow->attach(backend_type_for_window(fBackendType));
Jim Van Verth0848fb02018-01-22 13:39:30 -0500474 this->setCurrentSlide(this->startupSlide());
jvanverth9f372462016-04-06 06:08:59 -0700475}
476
jvanverth34524262016-05-04 13:49:13 -0700477void Viewer::initSlides() {
liyuqian1f508fd2016-06-07 06:57:40 -0700478 fAllSlideNames = Json::Value(Json::arrayValue);
479
jvanverth2bb3b6d2016-04-08 07:24:09 -0700480 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
481 while (gms) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400482 std::unique_ptr<skiagm::GM> gm(gms->factory()(nullptr));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700483
484 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
485 sk_sp<Slide> slide(new GMSlide(gm.release()));
486 fSlides.push_back(slide);
487 }
488
489 gms = gms->next();
490 }
491
492 // reverse array
493 for (int i = 0; i < fSlides.count()/2; ++i) {
494 sk_sp<Slide> temp = fSlides[i];
495 fSlides[i] = fSlides[fSlides.count() - i - 1];
496 fSlides[fSlides.count() - i - 1] = temp;
497 }
498
jvanverthc7027ab2016-06-16 09:52:35 -0700499 // samples
500 const SkViewRegister* reg = SkViewRegister::Head();
501 while (reg) {
502 sk_sp<Slide> slide(new SampleSlide(reg->factory()));
brianosmane1d20072016-07-12 09:07:33 -0700503 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, slide->getName().c_str())) {
504 fSlides.push_back(slide);
505 }
jvanverthc7027ab2016-06-16 09:52:35 -0700506 reg = reg->next();
507 }
508
jvanverth2bb3b6d2016-04-08 07:24:09 -0700509 // SKPs
510 for (int i = 0; i < FLAGS_skps.count(); i++) {
511 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
jvanverthc265a922016-04-08 12:51:45 -0700512 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
513 continue;
514 }
515
jvanverth2bb3b6d2016-04-08 07:24:09 -0700516 SkString path(FLAGS_skps[i]);
jvanverthc265a922016-04-08 12:51:45 -0700517 sk_sp<SKPSlide> slide(new SKPSlide(SkOSPath::Basename(path.c_str()), path));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700518 if (slide) {
519 fSlides.push_back(slide);
520 }
521 } else {
522 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
jvanverthc265a922016-04-08 12:51:45 -0700523 SkString skpName;
524 while (it.next(&skpName)) {
525 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, skpName.c_str())) {
526 continue;
527 }
528
529 SkString path = SkOSPath::Join(FLAGS_skps[i], skpName.c_str());
530 sk_sp<SKPSlide> slide(new SKPSlide(skpName, path));
jvanverth2bb3b6d2016-04-08 07:24:09 -0700531 if (slide) {
532 fSlides.push_back(slide);
533 }
534 }
535 }
536 }
liyuqian6f163d22016-06-13 12:26:45 -0700537
538 // JPGs
539 for (int i = 0; i < FLAGS_jpgs.count(); i++) {
540 SkOSFile::Iter it(FLAGS_jpgs[i], ".jpg");
541 SkString jpgName;
542 while (it.next(&jpgName)) {
brianosmane1d20072016-07-12 09:07:33 -0700543 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jpgName.c_str())) {
544 continue;
545 }
546
liyuqian6f163d22016-06-13 12:26:45 -0700547 SkString path = SkOSPath::Join(FLAGS_jpgs[i], jpgName.c_str());
548 sk_sp<ImageSlide> slide(new ImageSlide(jpgName, path));
549 if (slide) {
550 fSlides.push_back(slide);
551 }
552 }
553 }
Florin Malita094ccde2017-12-30 12:27:00 -0500554
555 // JSONs
556 for (const auto& json : FLAGS_jsons) {
Florin Malita54f65c42018-01-16 17:04:30 -0500557 fSlides.push_back(sk_make_sp<SkottieSlide2>(json));
Mike Reed29859872018-01-08 08:25:27 -0500558
Florin Malita094ccde2017-12-30 12:27:00 -0500559 SkOSFile::Iter it(json.c_str(), ".json");
560 SkString jsonName;
561 while (it.next(&jsonName)) {
562 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jsonName.c_str())) {
563 continue;
564 }
Florin Malita54f65c42018-01-16 17:04:30 -0500565 fSlides.push_back(sk_make_sp<SkottieSlide>(jsonName, SkOSPath::Join(json.c_str(),
566 jsonName.c_str())));
Florin Malita094ccde2017-12-30 12:27:00 -0500567 }
568 }
jvanverth2bb3b6d2016-04-08 07:24:09 -0700569}
570
571
jvanverth34524262016-05-04 13:49:13 -0700572Viewer::~Viewer() {
jvanverth9f372462016-04-06 06:08:59 -0700573 fWindow->detach();
574 delete fWindow;
575}
576
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500577struct SkPaintTitleUpdater {
578 SkPaintTitleUpdater(SkString* title) : fTitle(title), fCount(0) {}
579 void append(const char* s) {
580 if (fCount == 0) {
581 fTitle->append(" {");
582 } else {
583 fTitle->append(", ");
584 }
585 fTitle->append(s);
586 ++fCount;
587 }
588 void done() {
589 if (fCount > 0) {
590 fTitle->append("}");
591 }
592 }
593 SkString* fTitle;
594 int fCount;
595};
596
brianosman05de2162016-05-06 13:28:57 -0700597void Viewer::updateTitle() {
csmartdalton578f0642017-02-24 16:04:47 -0700598 if (!fWindow) {
599 return;
600 }
Brian Salomonbdecacf2018-02-02 20:32:49 -0500601 if (fWindow->sampleCount() < 1) {
csmartdalton578f0642017-02-24 16:04:47 -0700602 return; // Surface hasn't been created yet.
603 }
604
jvanverth34524262016-05-04 13:49:13 -0700605 SkString title("Viewer: ");
jvanverthc265a922016-04-08 12:51:45 -0700606 title.append(fSlides[fCurrentSlide]->getName());
brianosmanb109b8c2016-06-16 13:03:24 -0700607
Yuqian Li399b3c22017-08-03 11:08:15 -0400608 if (gSkUseDeltaAA) {
609 if (gSkForceDeltaAA) {
610 title.append(" <FDAA>");
611 } else {
612 title.append(" <DAA>");
613 }
614 } else if (gSkUseAnalyticAA) {
615 if (gSkForceAnalyticAA) {
616 title.append(" <FAAA>");
617 } else {
618 title.append(" <AAA>");
619 }
620 }
621
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500622 SkPaintTitleUpdater paintTitle(&title);
623 if (fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag) {
624 if (fPaint.isAntiAlias()) {
625 paintTitle.append("Antialias");
626 } else {
627 paintTitle.append("Alias");
628 }
629 }
630 if (fPaintOverrides.fFlags & SkPaint::kLCDRenderText_Flag) {
631 if (fPaint.isLCDRenderText()) {
632 paintTitle.append("LCD");
633 } else {
634 paintTitle.append("lcd");
635 }
636 }
637 if (fPaintOverrides.fFlags & SkPaint::kSubpixelText_Flag) {
638 if (fPaint.isSubpixelText()) {
639 paintTitle.append("Subpixel Glyphs");
640 } else {
641 paintTitle.append("Pixel Glyphs");
642 }
643 }
644 if (fPaintOverrides.fHinting) {
645 switch (fPaint.getHinting()) {
646 case SkPaint::kNo_Hinting:
647 paintTitle.append("No Hinting");
648 break;
649 case SkPaint::kSlight_Hinting:
650 paintTitle.append("Slight Hinting");
651 break;
652 case SkPaint::kNormal_Hinting:
653 paintTitle.append("Normal Hinting");
654 break;
655 case SkPaint::kFull_Hinting:
656 paintTitle.append("Full Hinting");
657 break;
658 }
659 }
660 paintTitle.done();
661
Yuqian Lib2ba6642017-11-22 12:07:41 -0500662 if (fTileCnt > 0) {
663 title.appendf(" T%d", fTileCnt);
664 if (fThreadCnt > 0) {
665 title.appendf("/%d", fThreadCnt);
666 }
667 }
668
Brian Osman92004802017-03-06 11:47:26 -0500669 switch (fColorMode) {
670 case ColorMode::kLegacy:
671 title.append(" Legacy 8888");
672 break;
673 case ColorMode::kColorManagedSRGB8888_NonLinearBlending:
674 title.append(" ColorManaged 8888 (Nonlinear blending)");
675 break;
676 case ColorMode::kColorManagedSRGB8888:
677 title.append(" ColorManaged 8888");
678 break;
679 case ColorMode::kColorManagedLinearF16:
680 title.append(" ColorManaged F16");
681 break;
682 }
Brian Osmanf750fbc2017-02-08 10:47:28 -0500683
Brian Osman92004802017-03-06 11:47:26 -0500684 if (ColorMode::kLegacy != fColorMode) {
Brian Osmana109e392017-02-24 09:49:14 -0500685 int curPrimaries = -1;
686 for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
687 if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
688 curPrimaries = i;
689 break;
690 }
691 }
692 title.appendf(" %s", curPrimaries >= 0 ? gNamedPrimaries[curPrimaries].fName : "Custom");
Brian Osmanfdab5762017-11-09 10:27:55 -0500693
694 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
695 title.appendf(" Gamma %f", fColorSpaceTransferFn.fG);
696 }
brianosman05de2162016-05-06 13:28:57 -0700697 }
Brian Osmanf750fbc2017-02-08 10:47:28 -0500698
csmartdalton578f0642017-02-24 16:04:47 -0700699 title.append(" [");
jvanverthaf236b52016-05-20 06:01:06 -0700700 title.append(kBackendTypeStrings[fBackendType]);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500701 int msaa = fWindow->sampleCount();
702 if (msaa > 1) {
csmartdalton578f0642017-02-24 16:04:47 -0700703 title.appendf(" MSAA: %i", msaa);
704 }
705 title.append("]");
csmartdalton61cd31a2017-02-27 17:00:53 -0700706
707 GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers;
Brian Osman8b0f2652017-08-29 15:18:34 -0400708 if (GpuPathRenderers::kDefault != pr) {
csmartdalton61cd31a2017-02-27 17:00:53 -0700709 title.appendf(" [Path renderer: %s]", gPathRendererNames[pr].c_str());
710 }
711
brianosman05de2162016-05-06 13:28:57 -0700712 fWindow->setTitle(title.c_str());
713}
714
Florin Malitaab99c342018-01-16 16:23:03 -0500715int Viewer::startupSlide() const {
Jim Van Verth6f449692017-02-14 15:16:46 -0500716
717 if (!FLAGS_slide.isEmpty()) {
718 int count = fSlides.count();
719 for (int i = 0; i < count; i++) {
720 if (fSlides[i]->getName().equals(FLAGS_slide[0])) {
Florin Malitaab99c342018-01-16 16:23:03 -0500721 return i;
Jim Van Verth6f449692017-02-14 15:16:46 -0500722 }
723 }
724
725 fprintf(stderr, "Unknown slide \"%s\"\n", FLAGS_slide[0]);
726 this->listNames();
727 }
728
Florin Malitaab99c342018-01-16 16:23:03 -0500729 return 0;
Jim Van Verth6f449692017-02-14 15:16:46 -0500730}
731
Florin Malitaab99c342018-01-16 16:23:03 -0500732void Viewer::listNames() const {
Jim Van Verth6f449692017-02-14 15:16:46 -0500733 SkDebugf("All Slides:\n");
Florin Malitaab99c342018-01-16 16:23:03 -0500734 for (const auto& slide : fSlides) {
735 SkDebugf(" %s\n", slide->getName().c_str());
Jim Van Verth6f449692017-02-14 15:16:46 -0500736 }
737}
738
Florin Malitaab99c342018-01-16 16:23:03 -0500739void Viewer::setCurrentSlide(int slide) {
740 SkASSERT(slide >= 0 && slide < fSlides.count());
liyuqian6f163d22016-06-13 12:26:45 -0700741
Florin Malitaab99c342018-01-16 16:23:03 -0500742 if (slide == fCurrentSlide) {
743 return;
744 }
745
746 if (fCurrentSlide >= 0) {
747 fSlides[fCurrentSlide]->unload();
748 }
749
750 fSlides[slide]->load(SkIntToScalar(fWindow->width()),
751 SkIntToScalar(fWindow->height()));
752 fCurrentSlide = slide;
753 this->setupCurrentSlide();
754}
755
756void Viewer::setupCurrentSlide() {
Jim Van Verth0848fb02018-01-22 13:39:30 -0500757 if (fCurrentSlide >= 0) {
758 // prepare dimensions for image slides
759 fGesture.resetTouchState();
760 fDefaultMatrix.reset();
liyuqiane46e4f02016-05-20 07:32:19 -0700761
Jim Van Verth0848fb02018-01-22 13:39:30 -0500762 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
763 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
764 const SkRect windowRect = SkRect::MakeIWH(fWindow->width(), fWindow->height());
Brian Osman42bb6ac2017-06-05 08:46:04 -0400765
Jim Van Verth0848fb02018-01-22 13:39:30 -0500766 // Start with a matrix that scales the slide to the available screen space
767 if (fWindow->scaleContentToFit()) {
768 if (windowRect.width() > 0 && windowRect.height() > 0) {
769 fDefaultMatrix.setRectToRect(slideBounds, windowRect, SkMatrix::kStart_ScaleToFit);
770 }
liyuqiane46e4f02016-05-20 07:32:19 -0700771 }
Jim Van Verth0848fb02018-01-22 13:39:30 -0500772
773 // Prevent the user from dragging content so far outside the window they can't find it again
774 fGesture.setTransLimit(slideBounds, windowRect, fDefaultMatrix);
775
776 this->updateTitle();
777 this->updateUIState();
778
779 fStatsLayer.resetMeasurements();
780
781 fWindow->inval();
liyuqiane46e4f02016-05-20 07:32:19 -0700782 }
jvanverthc265a922016-04-08 12:51:45 -0700783}
784
785#define MAX_ZOOM_LEVEL 8
786#define MIN_ZOOM_LEVEL -8
787
jvanverth34524262016-05-04 13:49:13 -0700788void Viewer::changeZoomLevel(float delta) {
jvanverthc265a922016-04-08 12:51:45 -0700789 fZoomLevel += delta;
Brian Osman42bb6ac2017-06-05 08:46:04 -0400790 fZoomLevel = SkScalarPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
jvanverthc265a922016-04-08 12:51:45 -0700791}
792
liyuqiand3cdbca2016-05-17 12:44:20 -0700793SkMatrix Viewer::computeMatrix() {
jvanverthc265a922016-04-08 12:51:45 -0700794 SkMatrix m;
jvanverthc265a922016-04-08 12:51:45 -0700795
Brian Osman42bb6ac2017-06-05 08:46:04 -0400796 SkScalar zoomScale = (fZoomLevel < 0) ? SK_Scalar1 / (SK_Scalar1 - fZoomLevel)
797 : SK_Scalar1 + fZoomLevel;
798 m = fGesture.localM();
liyuqiand3cdbca2016-05-17 12:44:20 -0700799 m.preConcat(fGesture.globalM());
Brian Osman42bb6ac2017-06-05 08:46:04 -0400800 m.preConcat(fDefaultMatrix);
801 m.preScale(zoomScale, zoomScale);
jvanverthc265a922016-04-08 12:51:45 -0700802
liyuqiand3cdbca2016-05-17 12:44:20 -0700803 return m;
jvanverthc265a922016-04-08 12:51:45 -0700804}
805
Brian Osman621491e2017-02-28 15:45:01 -0500806void Viewer::setBackend(sk_app::Window::BackendType backendType) {
807 fBackendType = backendType;
808
809 fWindow->detach();
810
Brian Osman70d2f432017-11-08 09:54:10 -0500811#if defined(SK_BUILD_FOR_WIN)
Brian Salomon194db172017-08-17 14:37:06 -0400812 // Switching between OpenGL, Vulkan, and ANGLE in the same window is problematic at this point
813 // on Windows, so we just delete the window and recreate it.
Brian Osman70d2f432017-11-08 09:54:10 -0500814 DisplayParams params = fWindow->getRequestedDisplayParams();
815 delete fWindow;
816 fWindow = Window::CreateNativeWindow(nullptr);
Brian Osman621491e2017-02-28 15:45:01 -0500817
Brian Osman70d2f432017-11-08 09:54:10 -0500818 // re-register callbacks
819 fCommands.attach(fWindow);
Brian Osman80fc07e2017-12-08 16:45:43 -0500820 fWindow->pushLayer(this);
Brian Osman56a24812017-12-19 11:15:16 -0500821 fWindow->pushLayer(&fStatsLayer);
Brian Osmand67e5182017-12-08 16:46:09 -0500822 fWindow->pushLayer(&fImGuiLayer);
823
Brian Osman70d2f432017-11-08 09:54:10 -0500824 // Don't allow the window to re-attach. If we're in MSAA mode, the params we grabbed above
825 // will still include our correct sample count. But the re-created fWindow will lose that
826 // information. On Windows, we need to re-create the window when changing sample count,
827 // so we'll incorrectly detect that situation, then re-initialize the window in GL mode,
828 // rendering this tear-down step pointless (and causing the Vulkan window context to fail
829 // as if we had never changed windows at all).
830 fWindow->setRequestedDisplayParams(params, false);
Brian Osman621491e2017-02-28 15:45:01 -0500831#endif
832
Brian Osman70d2f432017-11-08 09:54:10 -0500833 fWindow->attach(backend_type_for_window(fBackendType));
Brian Osman621491e2017-02-28 15:45:01 -0500834}
835
Brian Osman92004802017-03-06 11:47:26 -0500836void Viewer::setColorMode(ColorMode colorMode) {
837 fColorMode = colorMode;
liyuqian6f163d22016-06-13 12:26:45 -0700838
Brian Osmanf750fbc2017-02-08 10:47:28 -0500839 // 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 -0400840 // or out of legacy/nonlinear mode, we need to update our window configuration.
csmartdalton578f0642017-02-24 16:04:47 -0700841 DisplayParams params = fWindow->getRequestedDisplayParams();
Brian Osman92004802017-03-06 11:47:26 -0500842 bool wasInLegacy = !SkToBool(params.fColorSpace);
Brian Osmane0d4fba2017-03-15 10:24:55 -0400843 bool wantLegacy = (ColorMode::kLegacy == fColorMode) ||
844 (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode);
Brian Osman92004802017-03-06 11:47:26 -0500845 if (wasInLegacy != wantLegacy) {
846 params.fColorSpace = wantLegacy ? nullptr : SkColorSpace::MakeSRGB();
csmartdalton578f0642017-02-24 16:04:47 -0700847 fWindow->setRequestedDisplayParams(params);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500848 }
849
850 this->updateTitle();
851 fWindow->inval();
852}
853
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500854class OveridePaintFilterCanvas : public SkPaintFilterCanvas {
855public:
856 OveridePaintFilterCanvas(SkCanvas* canvas, SkPaint* paint, Viewer::SkPaintFields* fields)
857 : SkPaintFilterCanvas(canvas), fPaint(paint), fPaintOverrides(fields)
858 { }
859 bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override {
860 if (fPaintOverrides->fHinting) {
861 paint->writable()->setHinting(fPaint->getHinting());
862 }
863 if (fPaintOverrides->fFlags & SkPaint::kAntiAlias_Flag) {
864 paint->writable()->setAntiAlias(fPaint->isAntiAlias());
865 }
866 if (fPaintOverrides->fFlags & SkPaint::kLCDRenderText_Flag) {
867 paint->writable()->setLCDRenderText(fPaint->isLCDRenderText());
868 }
869 if (fPaintOverrides->fFlags & SkPaint::kSubpixelText_Flag) {
870 paint->writable()->setSubpixelText(fPaint->isSubpixelText());
871 }
872 return true;
873 }
874 SkPaint* fPaint;
875 Viewer::SkPaintFields* fPaintOverrides;
876};
877
Brian Osmanf750fbc2017-02-08 10:47:28 -0500878void Viewer::drawSlide(SkCanvas* canvas) {
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500879 SkAutoCanvasRestore autorestore(canvas, false);
880
Brian Osmanf750fbc2017-02-08 10:47:28 -0500881 // By default, we render directly into the window's surface/canvas
882 SkCanvas* slideCanvas = canvas;
Brian Osmanf6877092017-02-13 09:39:57 -0500883 fLastImage.reset();
jvanverth3d6ed3a2016-04-07 11:09:51 -0700884
Brian Osmane0d4fba2017-03-15 10:24:55 -0400885 // If we're in any of the color managed modes, construct the color space we're going to use
886 sk_sp<SkColorSpace> cs = nullptr;
887 if (ColorMode::kLegacy != fColorMode) {
888 auto transferFn = (ColorMode::kColorManagedLinearF16 == fColorMode)
889 ? SkColorSpace::kLinear_RenderTargetGamma : SkColorSpace::kSRGB_RenderTargetGamma;
Mike Kleinc722f792017-07-31 11:57:21 -0400890 SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
Brian Osmane0d4fba2017-03-15 10:24:55 -0400891 SkAssertResult(fColorSpacePrimaries.toXYZD50(&toXYZ));
Brian Osmanfdab5762017-11-09 10:27:55 -0500892 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
893 cs = SkColorSpace::MakeRGB(fColorSpaceTransferFn, toXYZ);
894 } else {
895 cs = SkColorSpace::MakeRGB(transferFn, toXYZ);
896 }
Brian Osmane0d4fba2017-03-15 10:24:55 -0400897 }
898
Brian Osman3ac99cf2017-12-01 11:23:53 -0500899 if (fSaveToSKP) {
900 SkPictureRecorder recorder;
901 SkCanvas* recorderCanvas = recorder.beginRecording(
902 SkRect::Make(fSlides[fCurrentSlide]->getDimensions()));
903 // In xform-canvas mode, record the transformed output
904 std::unique_ptr<SkCanvas> xformCanvas = nullptr;
905 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
906 xformCanvas = SkCreateColorSpaceXformCanvas(recorderCanvas, cs);
907 recorderCanvas = xformCanvas.get();
908 }
909 fSlides[fCurrentSlide]->draw(recorderCanvas);
910 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
911 SkFILEWStream stream("sample_app.skp");
912 picture->serialize(&stream);
913 fSaveToSKP = false;
914 }
915
Brian Osmane0d4fba2017-03-15 10:24:55 -0400916 // 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 -0500917 // we need to render offscreen. We also need to render offscreen if we're in any raster mode,
918 // because the window surface is actually GL.
Brian Osmanf750fbc2017-02-08 10:47:28 -0500919 sk_sp<SkSurface> offscreenSurface = nullptr;
Yuqian Lib2ba6642017-11-22 12:07:41 -0500920 std::unique_ptr<SkThreadedBMPDevice> threadedDevice;
921 std::unique_ptr<SkCanvas> threadedCanvas;
Brian Osman70d2f432017-11-08 09:54:10 -0500922 if (Window::kRaster_BackendType == fBackendType ||
923 ColorMode::kColorManagedLinearF16 == fColorMode ||
Brian Osman92004802017-03-06 11:47:26 -0500924 fShowZoomWindow ||
Brian Osmane0d4fba2017-03-15 10:24:55 -0400925 (ColorMode::kColorManagedSRGB8888 == fColorMode &&
926 !primaries_equal(fColorSpacePrimaries, gSrgbPrimaries))) {
927
Brian Osman92004802017-03-06 11:47:26 -0500928 SkColorType colorType = (ColorMode::kColorManagedLinearF16 == fColorMode)
929 ? kRGBA_F16_SkColorType : kN32_SkColorType;
Brian Osmane0d4fba2017-03-15 10:24:55 -0400930 // In nonlinear blending mode, we actually use a legacy off-screen canvas, and wrap it
931 // with a special canvas (below) that has the color space attached
932 sk_sp<SkColorSpace> offscreenColorSpace =
933 (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) ? nullptr : cs;
Brian Osman92004802017-03-06 11:47:26 -0500934 SkImageInfo info = SkImageInfo::Make(fWindow->width(), fWindow->height(), colorType,
Brian Osmane0d4fba2017-03-15 10:24:55 -0400935 kPremul_SkAlphaType, std::move(offscreenColorSpace));
Brian Osman70d2f432017-11-08 09:54:10 -0500936 offscreenSurface = Window::kRaster_BackendType == fBackendType ? SkSurface::MakeRaster(info)
937 : canvas->makeSurface(info);
Yuqian Lib2ba6642017-11-22 12:07:41 -0500938 SkPixmap offscreenPixmap;
939 if (fTileCnt > 0 && offscreenSurface->peekPixels(&offscreenPixmap)) {
940 SkBitmap offscreenBitmap;
941 offscreenBitmap.installPixels(offscreenPixmap);
942 threadedDevice.reset(new SkThreadedBMPDevice(offscreenBitmap, fTileCnt,
943 fThreadCnt, fExecutor.get()));
944 threadedCanvas.reset(new SkCanvas(threadedDevice.get()));
945 slideCanvas = threadedCanvas.get();
946 } else {
947 slideCanvas = offscreenSurface->getCanvas();
948 }
Brian Osmanf750fbc2017-02-08 10:47:28 -0500949 }
950
Brian Osmane0d4fba2017-03-15 10:24:55 -0400951 std::unique_ptr<SkCanvas> xformCanvas = nullptr;
952 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
953 xformCanvas = SkCreateColorSpaceXformCanvas(slideCanvas, cs);
954 slideCanvas = xformCanvas.get();
955 }
956
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500957 int count = slideCanvas->save();
Brian Osmanf750fbc2017-02-08 10:47:28 -0500958 slideCanvas->clear(SK_ColorWHITE);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500959 slideCanvas->concat(computeMatrix());
Brian Osman1df161a2017-02-09 12:10:20 -0500960 // Time the painting logic of the slide
Brian Osman56a24812017-12-19 11:15:16 -0500961 fStatsLayer.beginTiming(fPaintTimer);
Ben Wagnerabdcc5f2018-02-12 16:37:28 -0500962 OveridePaintFilterCanvas filterCanvas(slideCanvas, &fPaint, &fPaintOverrides);
963 fSlides[fCurrentSlide]->draw(&filterCanvas);
Brian Osman56a24812017-12-19 11:15:16 -0500964 fStatsLayer.endTiming(fPaintTimer);
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500965 slideCanvas->restoreToCount(count);
Brian Osman1df161a2017-02-09 12:10:20 -0500966
967 // Force a flush so we can time that, too
Brian Osman56a24812017-12-19 11:15:16 -0500968 fStatsLayer.beginTiming(fFlushTimer);
Brian Osman1df161a2017-02-09 12:10:20 -0500969 slideCanvas->flush();
Brian Osman56a24812017-12-19 11:15:16 -0500970 fStatsLayer.endTiming(fFlushTimer);
Brian Osmanf750fbc2017-02-08 10:47:28 -0500971
972 // If we rendered offscreen, snap an image and push the results to the window's canvas
973 if (offscreenSurface) {
Brian Osmanf6877092017-02-13 09:39:57 -0500974 fLastImage = offscreenSurface->makeImageSnapshot();
Brian Osmanf750fbc2017-02-08 10:47:28 -0500975
976 // Tag the image with the sRGB gamut, so no further color space conversion happens
Brian Osmane0d4fba2017-03-15 10:24:55 -0400977 sk_sp<SkColorSpace> srgb = (ColorMode::kColorManagedLinearF16 == fColorMode)
Brian Osmanf750fbc2017-02-08 10:47:28 -0500978 ? SkColorSpace::MakeSRGBLinear() : SkColorSpace::MakeSRGB();
Brian Osmane0d4fba2017-03-15 10:24:55 -0400979 auto retaggedImage = SkImageMakeRasterCopyAndAssignColorSpace(fLastImage.get(), srgb.get());
Brian Salomonbf52e3d2017-02-22 15:21:11 -0500980 SkPaint paint;
981 paint.setBlendMode(SkBlendMode::kSrc);
982 canvas->drawImage(retaggedImage, 0, 0, &paint);
liyuqian74959a12016-06-16 14:10:34 -0700983 }
liyuqian6f163d22016-06-13 12:26:45 -0700984}
985
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700986void Viewer::onBackendCreated() {
Florin Malitaab99c342018-01-16 16:23:03 -0500987 this->setupCurrentSlide();
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700988 fWindow->show();
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700989}
Jim Van Verth6f449692017-02-14 15:16:46 -0500990
Christopher Dalton443ec1b2017-02-24 13:22:53 -0700991void Viewer::onPaint(SkCanvas* canvas) {
Jim Van Verth90dcce52017-11-03 13:36:07 -0400992 this->drawSlide(canvas);
jvanverthc265a922016-04-08 12:51:45 -0700993
brianosman622c8d52016-05-10 06:50:49 -0700994 fCommands.drawHelp(canvas);
liyuqian2edb0f42016-07-06 14:11:32 -0700995
Brian Osmand67e5182017-12-08 16:46:09 -0500996 this->drawImGui();
Brian Osman79086b92017-02-10 13:36:16 -0500997
Brian Osman1df161a2017-02-09 12:10:20 -0500998 // Update the FPS
Jim Van Verth90dcce52017-11-03 13:36:07 -0400999 this->updateUIState();
jvanverth3d6ed3a2016-04-07 11:09:51 -07001000}
1001
jvanverth814e38d2016-06-06 08:48:47 -07001002bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) {
Brian Osmanb53f48c2017-06-07 10:00:30 -04001003 if (GestureDevice::kMouse == fGestureDevice) {
1004 return false;
1005 }
liyuqiand3cdbca2016-05-17 12:44:20 -07001006 void* castedOwner = reinterpret_cast<void*>(owner);
1007 switch (state) {
1008 case Window::kUp_InputState: {
1009 fGesture.touchEnd(castedOwner);
1010 break;
1011 }
1012 case Window::kDown_InputState: {
Brian Osman42bb6ac2017-06-05 08:46:04 -04001013 fGesture.touchBegin(castedOwner, x, y);
liyuqiand3cdbca2016-05-17 12:44:20 -07001014 break;
1015 }
1016 case Window::kMove_InputState: {
Brian Osman42bb6ac2017-06-05 08:46:04 -04001017 fGesture.touchMoved(castedOwner, x, y);
liyuqiand3cdbca2016-05-17 12:44:20 -07001018 break;
1019 }
1020 }
Brian Osmanb53f48c2017-06-07 10:00:30 -04001021 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone;
liyuqiand3cdbca2016-05-17 12:44:20 -07001022 fWindow->inval();
1023 return true;
1024}
1025
Brian Osman80fc07e2017-12-08 16:45:43 -05001026bool Viewer::onMouse(int x, int y, Window::InputState state, uint32_t modifiers) {
Brian Osman16c81a12017-12-20 11:58:34 -05001027 if (GestureDevice::kTouch == fGestureDevice) {
1028 return false;
Brian Osman80fc07e2017-12-08 16:45:43 -05001029 }
Brian Osman16c81a12017-12-20 11:58:34 -05001030
Florin Malita8deb2952018-02-01 14:16:54 -05001031 const auto slideMatrix = this->computeMatrix();
1032 SkMatrix slideInvMatrix;
1033 if (slideMatrix.invert(&slideInvMatrix)) {
1034 SkPoint slideMouse = SkPoint::Make(x, y);
1035 slideInvMatrix.mapPoints(&slideMouse, 1);
1036 if (fSlides[fCurrentSlide]->onMouse(slideMouse.x(), slideMouse.y(), state, modifiers)) {
1037 fWindow->inval();
1038 return true;
1039 }
Brian Osman16c81a12017-12-20 11:58:34 -05001040 }
1041
1042 switch (state) {
1043 case Window::kUp_InputState: {
1044 fGesture.touchEnd(nullptr);
1045 break;
1046 }
1047 case Window::kDown_InputState: {
1048 fGesture.touchBegin(nullptr, x, y);
1049 break;
1050 }
1051 case Window::kMove_InputState: {
1052 fGesture.touchMoved(nullptr, x, y);
1053 break;
1054 }
1055 }
1056 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
1057
1058 if (state != Window::kMove_InputState || fGesture.isBeingTouched()) {
1059 fWindow->inval();
1060 }
Jim Van Verthe7705782017-05-04 14:00:59 -04001061 return true;
1062}
1063
Brian Osmana109e392017-02-24 09:49:14 -05001064static ImVec2 ImGui_DragPrimary(const char* label, float* x, float* y,
1065 const ImVec2& pos, const ImVec2& size) {
1066 // Transform primaries ([0, 0] - [0.8, 0.9]) to screen coords (including Y-flip)
1067 ImVec2 center(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y);
1068
1069 // Invisible 10x10 button
1070 ImGui::SetCursorScreenPos(ImVec2(center.x - 5, center.y - 5));
1071 ImGui::InvisibleButton(label, ImVec2(10, 10));
1072
1073 if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) {
1074 ImGuiIO& io = ImGui::GetIO();
1075 // Normalized mouse position, relative to our gamut box
1076 ImVec2 mousePosXY((io.MousePos.x - pos.x) / size.x, (io.MousePos.y - pos.y) / size.y);
1077 // Clamp to edge of box, convert back to primary scale
1078 *x = SkTPin(mousePosXY.x, 0.0f, 1.0f) * 0.8f;
1079 *y = SkTPin(1 - mousePosXY.y, 0.0f, 1.0f) * 0.9f;
1080 }
1081
1082 if (ImGui::IsItemHovered()) {
1083 ImGui::SetTooltip("x: %.3f\ny: %.3f", *x, *y);
1084 }
1085
1086 // Return screen coordinates for the caller. We could just return center here, but we'd have
1087 // one frame of lag during drag.
1088 return ImVec2(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y);
1089}
1090
1091static void ImGui_Primaries(SkColorSpacePrimaries* primaries, SkPaint* gamutPaint) {
1092 ImDrawList* drawList = ImGui::GetWindowDrawList();
1093
1094 // The gamut image covers a (0.8 x 0.9) shaped region, so fit our image/canvas to the available
1095 // width, and scale the height to maintain aspect ratio.
1096 float canvasWidth = SkTMax(ImGui::GetContentRegionAvailWidth(), 50.0f);
1097 ImVec2 size = ImVec2(canvasWidth, canvasWidth * (0.9f / 0.8f));
1098 ImVec2 pos = ImGui::GetCursorScreenPos();
1099
1100 // Background image. Only draw a subset of the image, to avoid the regions less than zero.
1101 // Simplifes re-mapping math, clipping behavior, and increases resolution in the useful area.
1102 // Magic numbers are pixel locations of the origin and upper-right corner.
1103 drawList->AddImage(gamutPaint, pos, ImVec2(pos.x + size.x, pos.y + size.y),
1104 ImVec2(242, 61), ImVec2(1897, 1922));
1105 ImVec2 endPos = ImGui::GetCursorPos();
1106
1107 // Primary markers
1108 ImVec2 r = ImGui_DragPrimary("R", &primaries->fRX, &primaries->fRY, pos, size);
1109 ImVec2 g = ImGui_DragPrimary("G", &primaries->fGX, &primaries->fGY, pos, size);
1110 ImVec2 b = ImGui_DragPrimary("B", &primaries->fBX, &primaries->fBY, pos, size);
1111 ImVec2 w = ImGui_DragPrimary("W", &primaries->fWX, &primaries->fWY, pos, size);
1112
1113 // Gamut triangle
1114 drawList->AddCircle(r, 5.0f, 0xFF000040);
1115 drawList->AddCircle(g, 5.0f, 0xFF004000);
1116 drawList->AddCircle(b, 5.0f, 0xFF400000);
1117 drawList->AddCircle(w, 5.0f, 0xFFFFFFFF);
1118 drawList->AddTriangle(r, g, b, 0xFFFFFFFF);
1119
1120 // Re-position cursor immediate after the diagram for subsequent controls
1121 ImGui::SetCursorPos(endPos);
1122}
1123
Brian Osmand67e5182017-12-08 16:46:09 -05001124void Viewer::drawImGui() {
Brian Osman79086b92017-02-10 13:36:16 -05001125 // Support drawing the ImGui demo window. Superfluous, but gives a good idea of what's possible
1126 if (fShowImGuiTestWindow) {
1127 ImGui::ShowTestWindow(&fShowImGuiTestWindow);
1128 }
1129
1130 if (fShowImGuiDebugWindow) {
Brian Osmana109e392017-02-24 09:49:14 -05001131 // We have some dynamic content that sizes to fill available size. If the scroll bar isn't
1132 // always visible, we can end up in a layout feedback loop.
1133 ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiSetCond_FirstUseEver);
Brian Salomon99a33902017-03-07 15:16:34 -05001134 DisplayParams params = fWindow->getRequestedDisplayParams();
1135 bool paramsChanged = false;
Brian Osmana109e392017-02-24 09:49:14 -05001136 if (ImGui::Begin("Tools", &fShowImGuiDebugWindow,
1137 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
Brian Osman621491e2017-02-28 15:45:01 -05001138 if (ImGui::CollapsingHeader("Backend")) {
1139 int newBackend = static_cast<int>(fBackendType);
1140 ImGui::RadioButton("Raster", &newBackend, sk_app::Window::kRaster_BackendType);
1141 ImGui::SameLine();
1142 ImGui::RadioButton("OpenGL", &newBackend, sk_app::Window::kNativeGL_BackendType);
Brian Salomon194db172017-08-17 14:37:06 -04001143#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
1144 ImGui::SameLine();
1145 ImGui::RadioButton("ANGLE", &newBackend, sk_app::Window::kANGLE_BackendType);
1146#endif
Brian Osman621491e2017-02-28 15:45:01 -05001147#if defined(SK_VULKAN)
1148 ImGui::SameLine();
1149 ImGui::RadioButton("Vulkan", &newBackend, sk_app::Window::kVulkan_BackendType);
1150#endif
1151 if (newBackend != fBackendType) {
1152 fDeferredActions.push_back([=]() {
1153 this->setBackend(static_cast<sk_app::Window::BackendType>(newBackend));
1154 });
1155 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001156
Brian Salomon99a33902017-03-07 15:16:34 -05001157 const GrContext* ctx = fWindow->getGrContext();
Jim Van Verthfbdc0802017-05-02 16:15:53 -04001158 bool* wire = &params.fGrContextOptions.fWireframeMode;
1159 if (ctx && ImGui::Checkbox("Wireframe Mode", wire)) {
1160 paramsChanged = true;
1161 }
Brian Salomon99a33902017-03-07 15:16:34 -05001162
Brian Osman28b12522017-03-08 17:10:24 -05001163 if (ctx) {
1164 int sampleCount = fWindow->sampleCount();
1165 ImGui::Text("MSAA: "); ImGui::SameLine();
Brian Salomonbdecacf2018-02-02 20:32:49 -05001166 ImGui::RadioButton("1", &sampleCount, 1); ImGui::SameLine();
Brian Osman28b12522017-03-08 17:10:24 -05001167 ImGui::RadioButton("4", &sampleCount, 4); ImGui::SameLine();
1168 ImGui::RadioButton("8", &sampleCount, 8); ImGui::SameLine();
1169 ImGui::RadioButton("16", &sampleCount, 16);
1170
1171 if (sampleCount != params.fMSAASampleCount) {
1172 params.fMSAASampleCount = sampleCount;
1173 paramsChanged = true;
1174 }
1175 }
1176
Brian Osman8a9de3d2017-03-01 14:59:05 -05001177 if (ImGui::TreeNode("Path Renderers")) {
Brian Osman8a9de3d2017-03-01 14:59:05 -05001178 GpuPathRenderers prevPr = params.fGrContextOptions.fGpuPathRenderers;
Brian Osman8a9de3d2017-03-01 14:59:05 -05001179 auto prButton = [&](GpuPathRenderers x) {
1180 if (ImGui::RadioButton(gPathRendererNames[x].c_str(), prevPr == x)) {
Brian Salomon99a33902017-03-07 15:16:34 -05001181 if (x != params.fGrContextOptions.fGpuPathRenderers) {
1182 params.fGrContextOptions.fGpuPathRenderers = x;
1183 paramsChanged = true;
1184 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001185 }
1186 };
1187
1188 if (!ctx) {
1189 ImGui::RadioButton("Software", true);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001190 } else if (fWindow->sampleCount() > 1) {
Brian Osman8b0f2652017-08-29 15:18:34 -04001191 prButton(GpuPathRenderers::kDefault);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001192 prButton(GpuPathRenderers::kAll);
1193 if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {
1194 prButton(GpuPathRenderers::kStencilAndCover);
1195 }
1196 if (ctx->caps()->sampleShadingSupport()) {
1197 prButton(GpuPathRenderers::kMSAA);
1198 }
1199 prButton(GpuPathRenderers::kTessellating);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001200 prButton(GpuPathRenderers::kNone);
1201 } else {
Brian Osman8b0f2652017-08-29 15:18:34 -04001202 prButton(GpuPathRenderers::kDefault);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001203 prButton(GpuPathRenderers::kAll);
Chris Dalton1a325d22017-07-14 15:17:41 -06001204 if (GrCoverageCountingPathRenderer::IsSupported(*ctx->caps())) {
1205 prButton(GpuPathRenderers::kCoverageCounting);
1206 }
Jim Van Verth83010462017-03-16 08:45:39 -04001207 prButton(GpuPathRenderers::kSmall);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001208 prButton(GpuPathRenderers::kTessellating);
1209 prButton(GpuPathRenderers::kNone);
1210 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001211 ImGui::TreePop();
1212 }
Brian Osman621491e2017-02-28 15:45:01 -05001213 }
1214
Brian Osmanfce09c52017-11-14 15:32:20 -05001215 if (fShowSlidePicker) {
1216 ImGui::SetNextTreeNodeOpen(true);
1217 }
1218
Brian Osman79086b92017-02-10 13:36:16 -05001219 if (ImGui::CollapsingHeader("Slide")) {
1220 static ImGuiTextFilter filter;
Brian Osmanf479e422017-11-08 13:11:36 -05001221 static ImVector<const char*> filteredSlideNames;
1222 static ImVector<int> filteredSlideIndices;
1223
Brian Osmanfce09c52017-11-14 15:32:20 -05001224 if (fShowSlidePicker) {
1225 ImGui::SetKeyboardFocusHere();
1226 fShowSlidePicker = false;
1227 }
1228
Brian Osman79086b92017-02-10 13:36:16 -05001229 filter.Draw();
Brian Osmanf479e422017-11-08 13:11:36 -05001230 filteredSlideNames.clear();
1231 filteredSlideIndices.clear();
1232 int filteredIndex = 0;
1233 for (int i = 0; i < fSlides.count(); ++i) {
1234 const char* slideName = fSlides[i]->getName().c_str();
1235 if (filter.PassFilter(slideName) || i == fCurrentSlide) {
1236 if (i == fCurrentSlide) {
1237 filteredIndex = filteredSlideIndices.size();
Brian Osman79086b92017-02-10 13:36:16 -05001238 }
Brian Osmanf479e422017-11-08 13:11:36 -05001239 filteredSlideNames.push_back(slideName);
1240 filteredSlideIndices.push_back(i);
Brian Osman79086b92017-02-10 13:36:16 -05001241 }
Brian Osman79086b92017-02-10 13:36:16 -05001242 }
Brian Osmanf479e422017-11-08 13:11:36 -05001243
Brian Osmanf479e422017-11-08 13:11:36 -05001244 if (ImGui::ListBox("", &filteredIndex, filteredSlideNames.begin(),
1245 filteredSlideNames.size(), 20)) {
Florin Malitaab99c342018-01-16 16:23:03 -05001246 this->setCurrentSlide(filteredSlideIndices[filteredIndex]);
Brian Osman79086b92017-02-10 13:36:16 -05001247 }
1248 }
Brian Osmana109e392017-02-24 09:49:14 -05001249
1250 if (ImGui::CollapsingHeader("Color Mode")) {
Brian Osman92004802017-03-06 11:47:26 -05001251 ColorMode newMode = fColorMode;
1252 auto cmButton = [&](ColorMode mode, const char* label) {
1253 if (ImGui::RadioButton(label, mode == fColorMode)) {
1254 newMode = mode;
1255 }
1256 };
1257
1258 cmButton(ColorMode::kLegacy, "Legacy 8888");
1259 cmButton(ColorMode::kColorManagedSRGB8888_NonLinearBlending,
1260 "Color Managed 8888 (Nonlinear blending)");
1261 cmButton(ColorMode::kColorManagedSRGB8888, "Color Managed 8888");
1262 cmButton(ColorMode::kColorManagedLinearF16, "Color Managed F16");
1263
1264 if (newMode != fColorMode) {
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001265 // It isn't safe to switch color mode now (in the middle of painting). We might
1266 // tear down the back-end, etc... Defer this change until the next onIdle.
1267 fDeferredActions.push_back([=]() {
Brian Osman92004802017-03-06 11:47:26 -05001268 this->setColorMode(newMode);
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001269 });
Brian Osmana109e392017-02-24 09:49:14 -05001270 }
1271
1272 // Pick from common gamuts:
1273 int primariesIdx = 4; // Default: Custom
1274 for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
1275 if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
1276 primariesIdx = i;
1277 break;
1278 }
1279 }
1280
Brian Osmanfdab5762017-11-09 10:27:55 -05001281 // When we're in xform canvas mode, we can alter the transfer function, too
1282 if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
1283 ImGui::SliderFloat("Gamma", &fColorSpaceTransferFn.fG, 0.5f, 3.5f);
1284 }
1285
Brian Osmana109e392017-02-24 09:49:14 -05001286 if (ImGui::Combo("Primaries", &primariesIdx,
1287 "sRGB\0AdobeRGB\0P3\0Rec. 2020\0Custom\0\0")) {
1288 if (primariesIdx >= 0 && primariesIdx <= 3) {
1289 fColorSpacePrimaries = *gNamedPrimaries[primariesIdx].fPrimaries;
1290 }
1291 }
1292
1293 // Allow direct editing of gamut
1294 ImGui_Primaries(&fColorSpacePrimaries, &fImGuiGamutPaint);
1295 }
Brian Osman79086b92017-02-10 13:36:16 -05001296 }
Brian Salomon99a33902017-03-07 15:16:34 -05001297 if (paramsChanged) {
1298 fDeferredActions.push_back([=]() {
1299 fWindow->setRequestedDisplayParams(params);
1300 fWindow->inval();
1301 this->updateTitle();
1302 });
1303 }
Brian Osman79086b92017-02-10 13:36:16 -05001304 ImGui::End();
1305 }
1306
Brian Osmanf6877092017-02-13 09:39:57 -05001307 if (fShowZoomWindow && fLastImage) {
1308 if (ImGui::Begin("Zoom", &fShowZoomWindow, ImVec2(200, 200))) {
Brian Osmanead517d2017-11-13 15:36:36 -05001309 static int zoomFactor = 8;
1310 if (ImGui::Button("<<")) {
1311 zoomFactor = SkTMax(zoomFactor / 2, 4);
1312 }
1313 ImGui::SameLine(); ImGui::Text("%2d", zoomFactor); ImGui::SameLine();
1314 if (ImGui::Button(">>")) {
1315 zoomFactor = SkTMin(zoomFactor * 2, 32);
1316 }
Brian Osmanf6877092017-02-13 09:39:57 -05001317
Brian Osmanf6877092017-02-13 09:39:57 -05001318 ImVec2 mousePos = ImGui::GetMousePos();
1319 ImVec2 avail = ImGui::GetContentRegionAvail();
1320
Brian Osmanead517d2017-11-13 15:36:36 -05001321 uint32_t pixel = 0;
1322 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
1323 if (fLastImage->readPixels(info, &pixel, info.minRowBytes(), mousePos.x, mousePos.y)) {
1324 ImGui::SameLine();
Brian Osman07b56b22017-11-21 14:59:31 -05001325 ImGui::Text("(X, Y): %d, %d RGBA: %x %x %x %x",
1326 sk_float_round2int(mousePos.x), sk_float_round2int(mousePos.y),
1327 SkGetPackedR32(pixel), SkGetPackedG32(pixel),
Brian Osmanead517d2017-11-13 15:36:36 -05001328 SkGetPackedB32(pixel), SkGetPackedA32(pixel));
1329 }
1330
Brian Osmand67e5182017-12-08 16:46:09 -05001331 fImGuiLayer.skiaWidget(avail, [=](SkCanvas* c) {
Brian Osmanead517d2017-11-13 15:36:36 -05001332 // Translate so the region of the image that's under the mouse cursor is centered
1333 // in the zoom canvas:
1334 c->scale(zoomFactor, zoomFactor);
1335 c->translate(avail.x * 0.5f / zoomFactor - mousePos.x - 0.5f,
1336 avail.y * 0.5f / zoomFactor - mousePos.y - 0.5f);
1337 c->drawImage(this->fLastImage, 0, 0);
1338
1339 SkPaint outline;
1340 outline.setStyle(SkPaint::kStroke_Style);
1341 c->drawRect(SkRect::MakeXYWH(mousePos.x, mousePos.y, 1, 1), outline);
1342 });
Brian Osmanf6877092017-02-13 09:39:57 -05001343 }
1344
1345 ImGui::End();
1346 }
Brian Osman79086b92017-02-10 13:36:16 -05001347}
1348
liyuqian2edb0f42016-07-06 14:11:32 -07001349void Viewer::onIdle() {
Brian Osmanfd8f4d52017-02-24 11:57:23 -05001350 for (int i = 0; i < fDeferredActions.count(); ++i) {
1351 fDeferredActions[i]();
1352 }
1353 fDeferredActions.reset();
1354
Brian Osman56a24812017-12-19 11:15:16 -05001355 fStatsLayer.beginTiming(fAnimateTimer);
jvanverthc265a922016-04-08 12:51:45 -07001356 fAnimTimer.updateTime();
Brian Osman1df161a2017-02-09 12:10:20 -05001357 bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer);
Brian Osman56a24812017-12-19 11:15:16 -05001358 fStatsLayer.endTiming(fAnimateTimer);
Brian Osman1df161a2017-02-09 12:10:20 -05001359
Brian Osman79086b92017-02-10 13:36:16 -05001360 ImGuiIO& io = ImGui::GetIO();
Brian Osman56a24812017-12-19 11:15:16 -05001361 if (animateWantsInval || fStatsLayer.getActive() || fRefresh || io.MetricsActiveWindows) {
jvanverthc265a922016-04-08 12:51:45 -07001362 fWindow->inval();
1363 }
jvanverth9f372462016-04-06 06:08:59 -07001364}
liyuqiane5a6cd92016-05-27 08:52:52 -07001365
1366void Viewer::updateUIState() {
csmartdalton578f0642017-02-24 16:04:47 -07001367 if (!fWindow) {
1368 return;
1369 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001370 if (fWindow->sampleCount() < 1) {
csmartdalton578f0642017-02-24 16:04:47 -07001371 return; // Surface hasn't been created yet.
1372 }
1373
liyuqianb73c24b2016-06-03 08:47:23 -07001374 // Slide state
liyuqiane5a6cd92016-05-27 08:52:52 -07001375 Json::Value slideState(Json::objectValue);
1376 slideState[kName] = kSlideStateName;
1377 slideState[kValue] = fSlides[fCurrentSlide]->getName().c_str();
liyuqian1f508fd2016-06-07 06:57:40 -07001378 if (fAllSlideNames.size() == 0) {
1379 for(auto slide : fSlides) {
1380 fAllSlideNames.append(Json::Value(slide->getName().c_str()));
1381 }
liyuqiane5a6cd92016-05-27 08:52:52 -07001382 }
liyuqian1f508fd2016-06-07 06:57:40 -07001383 slideState[kOptions] = fAllSlideNames;
liyuqiane5a6cd92016-05-27 08:52:52 -07001384
liyuqianb73c24b2016-06-03 08:47:23 -07001385 // Backend state
liyuqiane5a6cd92016-05-27 08:52:52 -07001386 Json::Value backendState(Json::objectValue);
1387 backendState[kName] = kBackendStateName;
liyuqian6cb70252016-06-02 12:16:25 -07001388 backendState[kValue] = kBackendTypeStrings[fBackendType];
liyuqiane5a6cd92016-05-27 08:52:52 -07001389 backendState[kOptions] = Json::Value(Json::arrayValue);
liyuqianb73c24b2016-06-03 08:47:23 -07001390 for (auto str : kBackendTypeStrings) {
liyuqian6cb70252016-06-02 12:16:25 -07001391 backendState[kOptions].append(Json::Value(str));
1392 }
liyuqiane5a6cd92016-05-27 08:52:52 -07001393
csmartdalton578f0642017-02-24 16:04:47 -07001394 // MSAA state
1395 Json::Value msaaState(Json::objectValue);
1396 msaaState[kName] = kMSAAStateName;
1397 msaaState[kValue] = fWindow->sampleCount();
1398 msaaState[kOptions] = Json::Value(Json::arrayValue);
1399 if (sk_app::Window::kRaster_BackendType == fBackendType) {
1400 msaaState[kOptions].append(Json::Value(0));
1401 } else {
1402 for (int msaa : {0, 4, 8, 16}) {
1403 msaaState[kOptions].append(Json::Value(msaa));
1404 }
1405 }
1406
csmartdalton61cd31a2017-02-27 17:00:53 -07001407 // Path renderer state
1408 GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers;
1409 Json::Value prState(Json::objectValue);
1410 prState[kName] = kPathRendererStateName;
1411 prState[kValue] = gPathRendererNames[pr];
1412 prState[kOptions] = Json::Value(Json::arrayValue);
1413 const GrContext* ctx = fWindow->getGrContext();
1414 if (!ctx) {
1415 prState[kOptions].append("Software");
Brian Salomonbdecacf2018-02-02 20:32:49 -05001416 } else if (fWindow->sampleCount() > 1) {
Brian Osman8b0f2652017-08-29 15:18:34 -04001417 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kDefault]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001418 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kAll]);
1419 if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {
1420 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kStencilAndCover]);
1421 }
1422 if (ctx->caps()->sampleShadingSupport()) {
1423 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kMSAA]);
1424 }
Brian Osman8a9de3d2017-03-01 14:59:05 -05001425 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kTessellating]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001426 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kNone]);
1427 } else {
Brian Osman8b0f2652017-08-29 15:18:34 -04001428 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kDefault]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001429 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kAll]);
Chris Dalton1a325d22017-07-14 15:17:41 -06001430 if (GrCoverageCountingPathRenderer::IsSupported(*ctx->caps())) {
1431 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kCoverageCounting]);
1432 }
Jim Van Verth83010462017-03-16 08:45:39 -04001433 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kSmall]);
Brian Osman8a9de3d2017-03-01 14:59:05 -05001434 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kTessellating]);
csmartdalton61cd31a2017-02-27 17:00:53 -07001435 prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kNone]);
1436 }
1437
liyuqianb73c24b2016-06-03 08:47:23 -07001438 // Softkey state
1439 Json::Value softkeyState(Json::objectValue);
1440 softkeyState[kName] = kSoftkeyStateName;
1441 softkeyState[kValue] = kSoftkeyHint;
1442 softkeyState[kOptions] = Json::Value(Json::arrayValue);
1443 softkeyState[kOptions].append(kSoftkeyHint);
1444 for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) {
1445 softkeyState[kOptions].append(Json::Value(softkey.c_str()));
1446 }
1447
liyuqian1f508fd2016-06-07 06:57:40 -07001448 // FPS state
1449 Json::Value fpsState(Json::objectValue);
1450 fpsState[kName] = kFpsStateName;
Brian Osman56a24812017-12-19 11:15:16 -05001451 double animTime = fStatsLayer.getLastTime(fAnimateTimer);
1452 double paintTime = fStatsLayer.getLastTime(fPaintTimer);
1453 double flushTime = fStatsLayer.getLastTime(fFlushTimer);
Brian Osman1df161a2017-02-09 12:10:20 -05001454 fpsState[kValue] = SkStringPrintf("%8.3lf ms\n\nA %8.3lf\nP %8.3lf\nF%8.3lf",
Brian Osman56a24812017-12-19 11:15:16 -05001455 animTime + paintTime + flushTime,
1456 animTime, paintTime, flushTime).c_str();
liyuqian1f508fd2016-06-07 06:57:40 -07001457 fpsState[kOptions] = Json::Value(Json::arrayValue);
1458
liyuqiane5a6cd92016-05-27 08:52:52 -07001459 Json::Value state(Json::arrayValue);
1460 state.append(slideState);
1461 state.append(backendState);
csmartdalton578f0642017-02-24 16:04:47 -07001462 state.append(msaaState);
csmartdalton61cd31a2017-02-27 17:00:53 -07001463 state.append(prState);
liyuqianb73c24b2016-06-03 08:47:23 -07001464 state.append(softkeyState);
liyuqian1f508fd2016-06-07 06:57:40 -07001465 state.append(fpsState);
liyuqiane5a6cd92016-05-27 08:52:52 -07001466
Brian Osmaneff04b52017-11-21 13:18:02 -05001467 fWindow->setUIState(state.toStyledString().c_str());
liyuqiane5a6cd92016-05-27 08:52:52 -07001468}
1469
1470void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) {
liyuqian6cb70252016-06-02 12:16:25 -07001471 // For those who will add more features to handle the state change in this function:
1472 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
1473 // For example, after slide change, updateUIState is called inside setupCurrentSlide;
1474 // after backend change, updateUIState is called in this function.
liyuqiane5a6cd92016-05-27 08:52:52 -07001475 if (stateName.equals(kSlideStateName)) {
Florin Malitaab99c342018-01-16 16:23:03 -05001476 for (int i = 0; i < fSlides.count(); ++i) {
1477 if (fSlides[i]->getName().equals(stateValue)) {
1478 this->setCurrentSlide(i);
1479 return;
liyuqiane5a6cd92016-05-27 08:52:52 -07001480 }
liyuqiane5a6cd92016-05-27 08:52:52 -07001481 }
Florin Malitaab99c342018-01-16 16:23:03 -05001482
1483 SkDebugf("Slide not found: %s", stateValue.c_str());
liyuqian6cb70252016-06-02 12:16:25 -07001484 } else if (stateName.equals(kBackendStateName)) {
1485 for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) {
1486 if (stateValue.equals(kBackendTypeStrings[i])) {
1487 if (fBackendType != i) {
1488 fBackendType = (sk_app::Window::BackendType)i;
1489 fWindow->detach();
Brian Osman70d2f432017-11-08 09:54:10 -05001490 fWindow->attach(backend_type_for_window(fBackendType));
liyuqian6cb70252016-06-02 12:16:25 -07001491 }
1492 break;
1493 }
1494 }
csmartdalton578f0642017-02-24 16:04:47 -07001495 } else if (stateName.equals(kMSAAStateName)) {
1496 DisplayParams params = fWindow->getRequestedDisplayParams();
1497 int sampleCount = atoi(stateValue.c_str());
1498 if (sampleCount != params.fMSAASampleCount) {
1499 params.fMSAASampleCount = sampleCount;
1500 fWindow->setRequestedDisplayParams(params);
1501 fWindow->inval();
Brian Salomon99a33902017-03-07 15:16:34 -05001502 this->updateTitle();
1503 this->updateUIState();
csmartdalton61cd31a2017-02-27 17:00:53 -07001504 }
1505 } else if (stateName.equals(kPathRendererStateName)) {
1506 DisplayParams params = fWindow->getRequestedDisplayParams();
1507 for (const auto& pair : gPathRendererNames) {
1508 if (pair.second == stateValue.c_str()) {
1509 if (params.fGrContextOptions.fGpuPathRenderers != pair.first) {
1510 params.fGrContextOptions.fGpuPathRenderers = pair.first;
1511 fWindow->setRequestedDisplayParams(params);
1512 fWindow->inval();
Brian Salomon99a33902017-03-07 15:16:34 -05001513 this->updateTitle();
1514 this->updateUIState();
csmartdalton61cd31a2017-02-27 17:00:53 -07001515 }
1516 break;
1517 }
csmartdalton578f0642017-02-24 16:04:47 -07001518 }
liyuqianb73c24b2016-06-03 08:47:23 -07001519 } else if (stateName.equals(kSoftkeyStateName)) {
1520 if (!stateValue.equals(kSoftkeyHint)) {
1521 fCommands.onSoftkey(stateValue);
Brian Salomon99a33902017-03-07 15:16:34 -05001522 this->updateUIState(); // This is still needed to reset the value to kSoftkeyHint
liyuqianb73c24b2016-06-03 08:47:23 -07001523 }
liyuqian2edb0f42016-07-06 14:11:32 -07001524 } else if (stateName.equals(kRefreshStateName)) {
1525 // This state is actually NOT in the UI state.
1526 // We use this to allow Android to quickly set bool fRefresh.
1527 fRefresh = stateValue.equals(kON);
liyuqiane5a6cd92016-05-27 08:52:52 -07001528 } else {
1529 SkDebugf("Unknown stateName: %s", stateName.c_str());
1530 }
1531}
Brian Osman79086b92017-02-10 13:36:16 -05001532
1533bool Viewer::onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) {
Brian Osmand67e5182017-12-08 16:46:09 -05001534 return fCommands.onKey(key, state, modifiers);
Brian Osman79086b92017-02-10 13:36:16 -05001535}
1536
1537bool Viewer::onChar(SkUnichar c, uint32_t modifiers) {
Brian Osmand67e5182017-12-08 16:46:09 -05001538 if (fSlides[fCurrentSlide]->onChar(c)) {
Jim Van Verth6f449692017-02-14 15:16:46 -05001539 fWindow->inval();
1540 return true;
Brian Osman80fc07e2017-12-08 16:45:43 -05001541 } else {
1542 return fCommands.onChar(c, modifiers);
Jim Van Verth6f449692017-02-14 15:16:46 -05001543 }
Brian Osman79086b92017-02-10 13:36:16 -05001544}