jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Chris Dalton | 2d18f41 | 2018-02-20 13:23:32 -0700 | [diff] [blame] | 8 | #include "BisectSlide.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 9 | #include "GMSlide.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
| 11 | #include "GrContextPriv.h" |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 12 | #include "ImageSlide.h" |
Greg Daniel | 9fcc743 | 2016-11-29 16:35:19 -0500 | [diff] [blame] | 13 | #include "Resources.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 14 | #include "SKPSlide.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 15 | #include "SampleSlide.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 16 | #include "SkCanvas.h" |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 17 | #include "SkColorSpacePriv.h" |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 18 | #include "SkColorSpaceXformCanvas.h" |
Brian Osman | 2dd9693 | 2016-10-18 15:33:53 -0400 | [diff] [blame] | 19 | #include "SkCommandLineFlags.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 20 | #include "SkCommonFlags.h" |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 21 | #include "SkCommonFlagsGpu.h" |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 22 | #include "SkEventTracingPriv.h" |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 23 | #include "SkFontMgrPriv.h" |
Greg Daniel | 285db44 | 2016-10-14 09:12:53 -0400 | [diff] [blame] | 24 | #include "SkGraphics.h" |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 25 | #include "SkImagePriv.h" |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 26 | #include "SkJSONWriter.h" |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 27 | #include "SkMakeUnique.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 28 | #include "SkOSFile.h" |
Ben Wagner | bf111d7 | 2016-11-07 18:05:29 -0500 | [diff] [blame] | 29 | #include "SkOSPath.h" |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 30 | #include "SkPaintFilterCanvas.h" |
Brian Osman | 3ac99cf | 2017-12-01 11:23:53 -0500 | [diff] [blame] | 31 | #include "SkPictureRecorder.h" |
Yuqian Li | 399b3c2 | 2017-08-03 11:08:15 -0400 | [diff] [blame] | 32 | #include "SkScan.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 33 | #include "SkStream.h" |
liyuqian | 74959a1 | 2016-06-16 14:10:34 -0700 | [diff] [blame] | 34 | #include "SkSurface.h" |
csmartdalton | 29d8715 | 2017-02-10 17:05:14 -0500 | [diff] [blame] | 35 | #include "SkTaskGroup.h" |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 36 | #include "SkTestFontMgr.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 37 | #include "SkTo.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 38 | #include "SvgSlide.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 39 | #include "Viewer.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 40 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 41 | #include "imgui.h" |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 42 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 43 | #include <stdlib.h> |
| 44 | #include <map> |
| 45 | |
Florin Malita | 3b526b0 | 2018-05-25 12:43:51 -0400 | [diff] [blame] | 46 | #if defined(SK_HAS_SKSG) |
| 47 | #include "SlideDir.h" |
| 48 | #endif |
| 49 | |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 50 | #if defined(SK_ENABLE_SKOTTIE) |
| 51 | #include "SkottieSlide.h" |
| 52 | #endif |
| 53 | |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 54 | #if !(defined(SK_BUILD_FOR_WIN) && defined(__clang__)) |
| 55 | #include "NIMASlide.h" |
| 56 | #endif |
| 57 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 58 | using namespace sk_app; |
| 59 | |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 60 | static std::map<GpuPathRenderers, std::string> gPathRendererNames; |
| 61 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 62 | Application* Application::Create(int argc, char** argv, void* platformData) { |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 63 | return new Viewer(argc, argv, platformData); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Chris Dalton | 7a0ebfc | 2017-10-13 12:35:50 -0600 | [diff] [blame] | 66 | static DEFINE_string(slide, "", "Start on this sample."); |
| 67 | static DEFINE_bool(list, false, "List samples?"); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 68 | |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 69 | #ifdef SK_VULKAN |
jvanverth | b8794cc | 2016-07-27 14:29:18 -0700 | [diff] [blame] | 70 | # define BACKENDS_STR "\"sw\", \"gl\", and \"vk\"" |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 71 | #else |
| 72 | # define BACKENDS_STR "\"sw\" and \"gl\"" |
| 73 | #endif |
| 74 | |
Brian Osman | 2dd9693 | 2016-10-18 15:33:53 -0400 | [diff] [blame] | 75 | static DEFINE_string2(backend, b, "sw", "Backend to use. Allowed values are " BACKENDS_STR "."); |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 76 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 77 | static DEFINE_int32(msaa, 1, "Number of subpixel samples. 0 for no HW antialiasing."); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 78 | |
Chris Dalton | 2d18f41 | 2018-02-20 13:23:32 -0700 | [diff] [blame] | 79 | DEFINE_string(bisect, "", "Path to a .skp or .svg file to bisect."); |
| 80 | |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 81 | DECLARE_int32(threads) |
Brian Salomon | 41eac79 | 2017-03-08 14:03:56 -0500 | [diff] [blame] | 82 | |
Florin Malita | 38792ce | 2018-05-08 10:36:18 -0400 | [diff] [blame] | 83 | DEFINE_string2(file, f, "", "Open a single file for viewing."); |
| 84 | |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 85 | const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 86 | "OpenGL", |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 87 | #if SK_ANGLE && defined(SK_BUILD_FOR_WIN) |
| 88 | "ANGLE", |
| 89 | #endif |
jvanverth | 063ece7 | 2016-06-17 09:29:14 -0700 | [diff] [blame] | 90 | #ifdef SK_VULKAN |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 91 | "Vulkan", |
jvanverth | 063ece7 | 2016-06-17 09:29:14 -0700 | [diff] [blame] | 92 | #endif |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 93 | "Raster" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 96 | static sk_app::Window::BackendType get_backend_type(const char* str) { |
| 97 | #ifdef SK_VULKAN |
| 98 | if (0 == strcmp(str, "vk")) { |
| 99 | return sk_app::Window::kVulkan_BackendType; |
| 100 | } else |
| 101 | #endif |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 102 | #if SK_ANGLE && defined(SK_BUILD_FOR_WIN) |
| 103 | if (0 == strcmp(str, "angle")) { |
| 104 | return sk_app::Window::kANGLE_BackendType; |
| 105 | } else |
| 106 | #endif |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 107 | if (0 == strcmp(str, "gl")) { |
| 108 | return sk_app::Window::kNativeGL_BackendType; |
| 109 | } else if (0 == strcmp(str, "sw")) { |
| 110 | return sk_app::Window::kRaster_BackendType; |
| 111 | } else { |
| 112 | SkDebugf("Unknown backend type, %s, defaulting to sw.", str); |
| 113 | return sk_app::Window::kRaster_BackendType; |
| 114 | } |
| 115 | } |
| 116 | |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 117 | static SkColorSpacePrimaries gSrgbPrimaries = { |
| 118 | 0.64f, 0.33f, |
| 119 | 0.30f, 0.60f, |
| 120 | 0.15f, 0.06f, |
| 121 | 0.3127f, 0.3290f }; |
| 122 | |
| 123 | static SkColorSpacePrimaries gAdobePrimaries = { |
| 124 | 0.64f, 0.33f, |
| 125 | 0.21f, 0.71f, |
| 126 | 0.15f, 0.06f, |
| 127 | 0.3127f, 0.3290f }; |
| 128 | |
| 129 | static SkColorSpacePrimaries gP3Primaries = { |
| 130 | 0.680f, 0.320f, |
| 131 | 0.265f, 0.690f, |
| 132 | 0.150f, 0.060f, |
| 133 | 0.3127f, 0.3290f }; |
| 134 | |
| 135 | static SkColorSpacePrimaries gRec2020Primaries = { |
| 136 | 0.708f, 0.292f, |
| 137 | 0.170f, 0.797f, |
| 138 | 0.131f, 0.046f, |
| 139 | 0.3127f, 0.3290f }; |
| 140 | |
| 141 | struct NamedPrimaries { |
| 142 | const char* fName; |
| 143 | SkColorSpacePrimaries* fPrimaries; |
| 144 | } gNamedPrimaries[] = { |
| 145 | { "sRGB", &gSrgbPrimaries }, |
| 146 | { "AdobeRGB", &gAdobePrimaries }, |
| 147 | { "P3", &gP3Primaries }, |
| 148 | { "Rec. 2020", &gRec2020Primaries }, |
| 149 | }; |
| 150 | |
| 151 | static bool primaries_equal(const SkColorSpacePrimaries& a, const SkColorSpacePrimaries& b) { |
| 152 | return memcmp(&a, &b, sizeof(SkColorSpacePrimaries)) == 0; |
| 153 | } |
| 154 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 155 | static Window::BackendType backend_type_for_window(Window::BackendType backendType) { |
| 156 | // In raster mode, we still use GL for the window. |
| 157 | // This lets us render the GUI faster (and correct). |
| 158 | return Window::kRaster_BackendType == backendType ? Window::kNativeGL_BackendType : backendType; |
| 159 | } |
| 160 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 161 | const char* kName = "name"; |
| 162 | const char* kValue = "value"; |
| 163 | const char* kOptions = "options"; |
| 164 | const char* kSlideStateName = "Slide"; |
| 165 | const char* kBackendStateName = "Backend"; |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 166 | const char* kMSAAStateName = "MSAA"; |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 167 | const char* kPathRendererStateName = "Path renderer"; |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 168 | const char* kSoftkeyStateName = "Softkey"; |
| 169 | const char* kSoftkeyHint = "Please select a softkey"; |
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 170 | const char* kFpsStateName = "FPS"; |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 171 | const char* kON = "ON"; |
| 172 | const char* kOFF = "OFF"; |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 173 | const char* kRefreshStateName = "Refresh"; |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 174 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 175 | Viewer::Viewer(int argc, char** argv, void* platformData) |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 176 | : fCurrentSlide(-1) |
| 177 | , fRefresh(false) |
Brian Osman | 3ac99cf | 2017-12-01 11:23:53 -0500 | [diff] [blame] | 178 | , fSaveToSKP(false) |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 179 | , fShowImGuiDebugWindow(false) |
Brian Osman | fce09c5 | 2017-11-14 15:32:20 -0500 | [diff] [blame] | 180 | , fShowSlidePicker(false) |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 181 | , fShowImGuiTestWindow(false) |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 182 | , fShowZoomWindow(false) |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 183 | , fZoomWindowFixed(false) |
| 184 | , fZoomWindowLocation{0.0f, 0.0f} |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 185 | , fLastImage(nullptr) |
Brian Osman | b63f600 | 2018-07-24 18:01:53 -0400 | [diff] [blame^] | 186 | , fZoomUI(false) |
jvanverth | 063ece7 | 2016-06-17 09:29:14 -0700 | [diff] [blame] | 187 | , fBackendType(sk_app::Window::kNativeGL_BackendType) |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 188 | , fColorMode(ColorMode::kLegacy) |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 189 | , fColorSpacePrimaries(gSrgbPrimaries) |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 190 | // Our UI can only tweak gamma (currently), so start out gamma-only |
| 191 | , fColorSpaceTransferFn(g2Dot2_TransferFn) |
egdaniel | 2a0bb0a | 2016-04-11 08:30:40 -0700 | [diff] [blame] | 192 | , fZoomLevel(0.0f) |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 193 | , fRotation(0.0f) |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 194 | , fOffset{0.0f, 0.0f} |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 195 | , fGestureDevice(GestureDevice::kNone) |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 196 | , fPerspectiveMode(kPerspective_Off) |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 197 | { |
Greg Daniel | 285db44 | 2016-10-14 09:12:53 -0400 | [diff] [blame] | 198 | SkGraphics::Init(); |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 199 | |
Brian Osman | f09e35e | 2017-12-15 14:48:09 -0500 | [diff] [blame] | 200 | gPathRendererNames[GpuPathRenderers::kAll] = "All Path Renderers"; |
Brian Osman | f09e35e | 2017-12-15 14:48:09 -0500 | [diff] [blame] | 201 | gPathRendererNames[GpuPathRenderers::kStencilAndCover] = "NV_path_rendering"; |
Brian Osman | f09e35e | 2017-12-15 14:48:09 -0500 | [diff] [blame] | 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"; |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 206 | |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 207 | 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 Daniel | 9fcc743 | 2016-11-29 16:35:19 -0500 | [diff] [blame] | 214 | #ifdef SK_BUILD_FOR_ANDROID |
Brian Salomon | 96789b3 | 2017-05-26 12:06:21 -0400 | [diff] [blame] | 215 | SetResourcePath("/data/local/tmp/resources"); |
Greg Daniel | 9fcc743 | 2016-11-29 16:35:19 -0500 | [diff] [blame] | 216 | #endif |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 217 | |
Ben Wagner | 483c772 | 2018-02-20 17:06:07 -0500 | [diff] [blame] | 218 | if (!FLAGS_nativeFonts) { |
| 219 | gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr; |
| 220 | } |
| 221 | |
Brian Osman | bc8150f | 2017-07-24 11:38:01 -0400 | [diff] [blame] | 222 | initializeEventTracingForTools(); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 223 | static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads); |
Greg Daniel | 285db44 | 2016-10-14 09:12:53 -0400 | [diff] [blame] | 224 | |
bsalomon | 6c471f7 | 2016-07-26 12:56:32 -0700 | [diff] [blame] | 225 | fBackendType = get_backend_type(FLAGS_backend[0]); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 226 | fWindow = Window::CreateNativeWindow(platformData); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 227 | |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 228 | DisplayParams displayParams; |
| 229 | displayParams.fMSAASampleCount = FLAGS_msaa; |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 230 | SetCtxOptionsFromCommonFlags(&displayParams.fGrContextOptions); |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 231 | fWindow->setRequestedDisplayParams(displayParams); |
| 232 | |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 233 | // Configure timers |
| 234 | fStatsLayer.setActive(false); |
| 235 | fAnimateTimer = fStatsLayer.addTimer("Animate", SK_ColorMAGENTA, 0xffff66ff); |
| 236 | fPaintTimer = fStatsLayer.addTimer("Paint", SK_ColorGREEN); |
| 237 | fFlushTimer = fStatsLayer.addTimer("Flush", SK_ColorRED, 0xffff6666); |
| 238 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 239 | // register callbacks |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 240 | fCommands.attach(fWindow); |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 241 | fWindow->pushLayer(this); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 242 | fWindow->pushLayer(&fStatsLayer); |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 243 | fWindow->pushLayer(&fImGuiLayer); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 244 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 245 | // add key-bindings |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 246 | fCommands.addCommand(' ', "GUI", "Toggle Debug GUI", [this]() { |
| 247 | this->fShowImGuiDebugWindow = !this->fShowImGuiDebugWindow; |
| 248 | fWindow->inval(); |
| 249 | }); |
Brian Osman | fce09c5 | 2017-11-14 15:32:20 -0500 | [diff] [blame] | 250 | // Command to jump directly to the slide picker and give it focus |
| 251 | fCommands.addCommand('/', "GUI", "Jump to slide picker", [this]() { |
| 252 | this->fShowImGuiDebugWindow = true; |
| 253 | this->fShowSlidePicker = true; |
| 254 | fWindow->inval(); |
| 255 | }); |
| 256 | // Alias that to Backspace, to match SampleApp |
| 257 | fCommands.addCommand(Window::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() { |
| 258 | this->fShowImGuiDebugWindow = true; |
| 259 | this->fShowSlidePicker = true; |
| 260 | fWindow->inval(); |
| 261 | }); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 262 | fCommands.addCommand('g', "GUI", "Toggle GUI Demo", [this]() { |
| 263 | this->fShowImGuiTestWindow = !this->fShowImGuiTestWindow; |
| 264 | fWindow->inval(); |
| 265 | }); |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 266 | fCommands.addCommand('z', "GUI", "Toggle zoom window", [this]() { |
| 267 | this->fShowZoomWindow = !this->fShowZoomWindow; |
| 268 | fWindow->inval(); |
| 269 | }); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 270 | fCommands.addCommand('Z', "GUI", "Toggle zoom window state", [this]() { |
| 271 | this->fZoomWindowFixed = !this->fZoomWindowFixed; |
| 272 | fWindow->inval(); |
| 273 | }); |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 274 | fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 275 | fStatsLayer.setActive(!fStatsLayer.getActive()); |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 276 | fWindow->inval(); |
| 277 | }); |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 278 | fCommands.addCommand('0', "Overlays", "Reset stats", [this]() { |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 279 | fStatsLayer.resetMeasurements(); |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 280 | this->updateTitle(); |
| 281 | fWindow->inval(); |
| 282 | }); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 283 | fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() { |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 284 | switch (fColorMode) { |
| 285 | case ColorMode::kLegacy: |
| 286 | this->setColorMode(ColorMode::kColorManagedSRGB8888_NonLinearBlending); |
| 287 | break; |
| 288 | case ColorMode::kColorManagedSRGB8888_NonLinearBlending: |
| 289 | this->setColorMode(ColorMode::kColorManagedSRGB8888); |
| 290 | break; |
| 291 | case ColorMode::kColorManagedSRGB8888: |
| 292 | this->setColorMode(ColorMode::kColorManagedLinearF16); |
| 293 | break; |
| 294 | case ColorMode::kColorManagedLinearF16: |
| 295 | this->setColorMode(ColorMode::kLegacy); |
| 296 | break; |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 297 | } |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 298 | }); |
| 299 | fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide", [this]() { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 300 | this->setCurrentSlide(fCurrentSlide < fSlides.count() - 1 ? fCurrentSlide + 1 : 0); |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 301 | }); |
| 302 | fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 303 | this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.count() - 1); |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 304 | }); |
| 305 | fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]() { |
| 306 | this->changeZoomLevel(1.f / 32.f); |
| 307 | fWindow->inval(); |
| 308 | }); |
| 309 | fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [this]() { |
| 310 | this->changeZoomLevel(-1.f / 32.f); |
| 311 | fWindow->inval(); |
| 312 | }); |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 313 | fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() { |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 314 | sk_app::Window::BackendType newBackend = (sk_app::Window::BackendType)( |
| 315 | (fBackendType + 1) % sk_app::Window::kBackendTypeCount); |
Jim Van Verth | d63c102 | 2017-01-05 13:50:49 -0500 | [diff] [blame] | 316 | // Switching to and from Vulkan is problematic on Linux so disabled for now |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 317 | #if defined(SK_BUILD_FOR_UNIX) && defined(SK_VULKAN) |
| 318 | if (newBackend == sk_app::Window::kVulkan_BackendType) { |
| 319 | newBackend = (sk_app::Window::BackendType)((newBackend + 1) % |
| 320 | sk_app::Window::kBackendTypeCount); |
| 321 | } else if (fBackendType == sk_app::Window::kVulkan_BackendType) { |
| 322 | newBackend = sk_app::Window::kVulkan_BackendType; |
Jim Van Verth | d63c102 | 2017-01-05 13:50:49 -0500 | [diff] [blame] | 323 | } |
| 324 | #endif |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 325 | this->setBackend(newBackend); |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 326 | }); |
Brian Osman | 3ac99cf | 2017-12-01 11:23:53 -0500 | [diff] [blame] | 327 | fCommands.addCommand('K', "IO", "Save slide to SKP", [this]() { |
| 328 | fSaveToSKP = true; |
| 329 | fWindow->inval(); |
| 330 | }); |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 331 | fCommands.addCommand('G', "Modes", "Geometry", [this]() { |
| 332 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 333 | uint32_t flags = params.fSurfaceProps.flags(); |
| 334 | if (!fPixelGeometryOverrides) { |
| 335 | fPixelGeometryOverrides = true; |
| 336 | params.fSurfaceProps = SkSurfaceProps(flags, kUnknown_SkPixelGeometry); |
| 337 | } else { |
| 338 | switch (params.fSurfaceProps.pixelGeometry()) { |
| 339 | case kUnknown_SkPixelGeometry: |
| 340 | params.fSurfaceProps = SkSurfaceProps(flags, kRGB_H_SkPixelGeometry); |
| 341 | break; |
| 342 | case kRGB_H_SkPixelGeometry: |
| 343 | params.fSurfaceProps = SkSurfaceProps(flags, kBGR_H_SkPixelGeometry); |
| 344 | break; |
| 345 | case kBGR_H_SkPixelGeometry: |
| 346 | params.fSurfaceProps = SkSurfaceProps(flags, kRGB_V_SkPixelGeometry); |
| 347 | break; |
| 348 | case kRGB_V_SkPixelGeometry: |
| 349 | params.fSurfaceProps = SkSurfaceProps(flags, kBGR_V_SkPixelGeometry); |
| 350 | break; |
| 351 | case kBGR_V_SkPixelGeometry: |
| 352 | params.fSurfaceProps = SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 353 | fPixelGeometryOverrides = false; |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | fWindow->setRequestedDisplayParams(params); |
| 358 | this->updateTitle(); |
| 359 | fWindow->inval(); |
| 360 | }); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 361 | fCommands.addCommand('H', "Paint", "Hinting mode", [this]() { |
| 362 | if (!fPaintOverrides.fHinting) { |
| 363 | fPaintOverrides.fHinting = true; |
| 364 | fPaint.setHinting(SkPaint::kNo_Hinting); |
| 365 | } else { |
| 366 | switch (fPaint.getHinting()) { |
| 367 | case SkPaint::kNo_Hinting: |
| 368 | fPaint.setHinting(SkPaint::kSlight_Hinting); |
| 369 | break; |
| 370 | case SkPaint::kSlight_Hinting: |
| 371 | fPaint.setHinting(SkPaint::kNormal_Hinting); |
| 372 | break; |
| 373 | case SkPaint::kNormal_Hinting: |
| 374 | fPaint.setHinting(SkPaint::kFull_Hinting); |
| 375 | break; |
| 376 | case SkPaint::kFull_Hinting: |
| 377 | fPaint.setHinting(SkPaint::kNo_Hinting); |
| 378 | fPaintOverrides.fHinting = false; |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | this->updateTitle(); |
| 383 | fWindow->inval(); |
| 384 | }); |
| 385 | fCommands.addCommand('A', "Paint", "Antialias Mode", [this]() { |
| 386 | if (!(fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag)) { |
| 387 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias; |
| 388 | fPaintOverrides.fFlags |= SkPaint::kAntiAlias_Flag; |
| 389 | fPaint.setAntiAlias(false); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 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; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 397 | gSkUseAnalyticAA = gSkForceAnalyticAA = false; |
| 398 | gSkUseDeltaAA = gSkForceDeltaAA = false; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 399 | break; |
| 400 | case SkPaintFields::AntiAliasState::Normal: |
| 401 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAEnabled; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 402 | gSkUseAnalyticAA = true; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 403 | gSkForceAnalyticAA = false; |
| 404 | gSkUseDeltaAA = gSkForceDeltaAA = false; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 405 | break; |
| 406 | case SkPaintFields::AntiAliasState::AnalyticAAEnabled: |
| 407 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAForced; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 408 | gSkUseAnalyticAA = gSkForceAnalyticAA = true; |
| 409 | gSkUseDeltaAA = gSkForceDeltaAA = false; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 410 | break; |
| 411 | case SkPaintFields::AntiAliasState::AnalyticAAForced: |
| 412 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAEnabled; |
| 413 | gSkUseAnalyticAA = gSkForceAnalyticAA = false; |
| 414 | gSkUseDeltaAA = true; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 415 | gSkForceDeltaAA = false; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 416 | break; |
| 417 | case SkPaintFields::AntiAliasState::DeltaAAEnabled: |
| 418 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAForced; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 419 | gSkUseAnalyticAA = gSkForceAnalyticAA = false; |
| 420 | gSkUseDeltaAA = gSkForceDeltaAA = true; |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 421 | break; |
| 422 | case SkPaintFields::AntiAliasState::DeltaAAForced: |
| 423 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias; |
| 424 | fPaintOverrides.fFlags &= ~SkPaint::kAntiAlias_Flag; |
| 425 | gSkUseAnalyticAA = fPaintOverrides.fOriginalSkUseAnalyticAA; |
| 426 | gSkForceAnalyticAA = fPaintOverrides.fOriginalSkForceAnalyticAA; |
| 427 | gSkUseDeltaAA = fPaintOverrides.fOriginalSkUseDeltaAA; |
| 428 | gSkForceDeltaAA = fPaintOverrides.fOriginalSkForceDeltaAA; |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | this->updateTitle(); |
| 433 | fWindow->inval(); |
| 434 | }); |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 435 | fCommands.addCommand('D', "Modes", "DFT", [this]() { |
| 436 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 437 | uint32_t flags = params.fSurfaceProps.flags(); |
| 438 | flags ^= SkSurfaceProps::kUseDeviceIndependentFonts_Flag; |
| 439 | params.fSurfaceProps = SkSurfaceProps(flags, params.fSurfaceProps.pixelGeometry()); |
| 440 | fWindow->setRequestedDisplayParams(params); |
| 441 | this->updateTitle(); |
| 442 | fWindow->inval(); |
| 443 | }); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 444 | fCommands.addCommand('L', "Paint", "Subpixel Antialias Mode", [this]() { |
| 445 | if (!(fPaintOverrides.fFlags & SkPaint::kLCDRenderText_Flag)) { |
| 446 | fPaintOverrides.fFlags |= SkPaint::kLCDRenderText_Flag; |
| 447 | fPaint.setLCDRenderText(false); |
| 448 | } else { |
| 449 | if (!fPaint.isLCDRenderText()) { |
| 450 | fPaint.setLCDRenderText(true); |
| 451 | } else { |
| 452 | fPaintOverrides.fFlags &= ~SkPaint::kLCDRenderText_Flag; |
| 453 | } |
| 454 | } |
| 455 | this->updateTitle(); |
| 456 | fWindow->inval(); |
| 457 | }); |
| 458 | fCommands.addCommand('S', "Paint", "Subpixel Position Mode", [this]() { |
| 459 | if (!(fPaintOverrides.fFlags & SkPaint::kSubpixelText_Flag)) { |
| 460 | fPaintOverrides.fFlags |= SkPaint::kSubpixelText_Flag; |
| 461 | fPaint.setSubpixelText(false); |
| 462 | } else { |
| 463 | if (!fPaint.isSubpixelText()) { |
| 464 | fPaint.setSubpixelText(true); |
| 465 | } else { |
| 466 | fPaintOverrides.fFlags &= ~SkPaint::kSubpixelText_Flag; |
| 467 | } |
| 468 | } |
| 469 | this->updateTitle(); |
| 470 | fWindow->inval(); |
| 471 | }); |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 472 | fCommands.addCommand('p', "Transform", "Toggle Perspective Mode", [this]() { |
| 473 | fPerspectiveMode = (kPerspective_Real == fPerspectiveMode) ? kPerspective_Fake |
| 474 | : kPerspective_Real; |
| 475 | this->updateTitle(); |
| 476 | fWindow->inval(); |
| 477 | }); |
| 478 | fCommands.addCommand('P', "Transform", "Toggle Perspective", [this]() { |
| 479 | fPerspectiveMode = (kPerspective_Off == fPerspectiveMode) ? kPerspective_Real |
| 480 | : kPerspective_Off; |
| 481 | this->updateTitle(); |
| 482 | fWindow->inval(); |
| 483 | }); |
Brian Osman | b63f600 | 2018-07-24 18:01:53 -0400 | [diff] [blame^] | 484 | fCommands.addCommand('u', "GUI", "Zoom UI", [this]() { |
| 485 | fZoomUI = !fZoomUI; |
| 486 | fStatsLayer.setDisplayScale(fZoomUI ? 2.0f : 1.0f); |
| 487 | fWindow->inval(); |
| 488 | }); |
Yuqian Li | b2ba664 | 2017-11-22 12:07:41 -0500 | [diff] [blame] | 489 | |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 490 | // set up slides |
| 491 | this->initSlides(); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 492 | if (FLAGS_list) { |
| 493 | this->listNames(); |
| 494 | } |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 495 | |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 496 | fPerspectivePoints[0].set(0, 0); |
| 497 | fPerspectivePoints[1].set(1, 0); |
| 498 | fPerspectivePoints[2].set(0, 1); |
| 499 | fPerspectivePoints[3].set(1, 1); |
djsollen | 12d62a7 | 2016-04-21 07:59:44 -0700 | [diff] [blame] | 500 | fAnimTimer.run(); |
| 501 | |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 502 | auto gamutImage = GetResourceAsImage("images/gamut.png"); |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 503 | if (gamutImage) { |
Mike Reed | 0acd795 | 2017-04-28 11:12:19 -0400 | [diff] [blame] | 504 | fImGuiGamutPaint.setShader(gamutImage->makeShader()); |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 505 | } |
| 506 | fImGuiGamutPaint.setColor(SK_ColorWHITE); |
| 507 | fImGuiGamutPaint.setFilterQuality(kLow_SkFilterQuality); |
| 508 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 509 | fWindow->attach(backend_type_for_window(fBackendType)); |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 510 | this->setCurrentSlide(this->startupSlide()); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 511 | } |
| 512 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 513 | void Viewer::initSlides() { |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 514 | using SlideFactory = sk_sp<Slide>(*)(const SkString& name, const SkString& path); |
| 515 | static const struct { |
| 516 | const char* fExtension; |
| 517 | const char* fDirName; |
| 518 | const SkCommandLineFlags::StringArray& fFlags; |
| 519 | const SlideFactory fFactory; |
| 520 | } gExternalSlidesInfo[] = { |
| 521 | { ".skp", "skp-dir", FLAGS_skps, |
| 522 | [](const SkString& name, const SkString& path) -> sk_sp<Slide> { |
| 523 | return sk_make_sp<SKPSlide>(name, path);} |
| 524 | }, |
| 525 | { ".jpg", "jpg-dir", FLAGS_jpgs, |
| 526 | [](const SkString& name, const SkString& path) -> sk_sp<Slide> { |
| 527 | return sk_make_sp<ImageSlide>(name, path);} |
| 528 | }, |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 529 | #if defined(SK_ENABLE_SKOTTIE) |
Eric Boren | 8c172ba | 2018-07-19 13:27:49 -0400 | [diff] [blame] | 530 | { ".json", "skottie-dir", FLAGS_lotties, |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 531 | [](const SkString& name, const SkString& path) -> sk_sp<Slide> { |
| 532 | return sk_make_sp<SkottieSlide>(name, path);} |
| 533 | }, |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 534 | #endif |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 535 | { ".svg", "svg-dir", FLAGS_svgs, |
| 536 | [](const SkString& name, const SkString& path) -> sk_sp<Slide> { |
| 537 | return sk_make_sp<SvgSlide>(name, path);} |
| 538 | }, |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 539 | #if !(defined(SK_BUILD_FOR_WIN) && defined(__clang__)) |
| 540 | { ".nima", "nima-dir", FLAGS_nimas, |
| 541 | [](const SkString& name, const SkString& path) -> sk_sp<Slide> { |
| 542 | return sk_make_sp<NIMASlide>(name, path);} |
| 543 | }, |
| 544 | #endif |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 545 | }; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 546 | |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 547 | SkTArray<sk_sp<Slide>, true> dirSlides; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 548 | |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 549 | const auto addSlide = [&](const SkString& name, |
| 550 | const SkString& path, |
| 551 | const SlideFactory& fact) { |
| 552 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, name.c_str())) { |
| 553 | return; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 554 | } |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 555 | |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 556 | if (auto slide = fact(name, path)) { |
Florin Malita | 76a076b | 2018-02-15 18:40:48 -0500 | [diff] [blame] | 557 | dirSlides.push_back(slide); |
| 558 | fSlides.push_back(std::move(slide)); |
| 559 | } |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 560 | }; |
Florin Malita | 76a076b | 2018-02-15 18:40:48 -0500 | [diff] [blame] | 561 | |
Florin Malita | 38792ce | 2018-05-08 10:36:18 -0400 | [diff] [blame] | 562 | if (!FLAGS_file.isEmpty()) { |
| 563 | // single file mode |
| 564 | const SkString file(FLAGS_file[0]); |
| 565 | |
| 566 | if (sk_exists(file.c_str(), kRead_SkFILE_Flag)) { |
| 567 | for (const auto& sinfo : gExternalSlidesInfo) { |
| 568 | if (file.endsWith(sinfo.fExtension)) { |
| 569 | addSlide(SkOSPath::Basename(file.c_str()), file, sinfo.fFactory); |
| 570 | return; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | fprintf(stderr, "Unsupported file type \"%s\"\n", file.c_str()); |
| 575 | } else { |
| 576 | fprintf(stderr, "Cannot read \"%s\"\n", file.c_str()); |
| 577 | } |
| 578 | |
| 579 | return; |
| 580 | } |
| 581 | |
| 582 | // Bisect slide. |
| 583 | if (!FLAGS_bisect.isEmpty()) { |
| 584 | sk_sp<BisectSlide> bisect = BisectSlide::Create(FLAGS_bisect[0]); |
| 585 | if (bisect && !SkCommandLineFlags::ShouldSkip(FLAGS_match, bisect->getName().c_str())) { |
| 586 | if (FLAGS_bisect.count() >= 2) { |
| 587 | for (const char* ch = FLAGS_bisect[1]; *ch; ++ch) { |
| 588 | bisect->onChar(*ch); |
| 589 | } |
| 590 | } |
| 591 | fSlides.push_back(std::move(bisect)); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // GMs |
| 596 | int firstGM = fSlides.count(); |
| 597 | const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); |
| 598 | while (gms) { |
| 599 | std::unique_ptr<skiagm::GM> gm(gms->factory()(nullptr)); |
| 600 | |
| 601 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { |
| 602 | sk_sp<Slide> slide(new GMSlide(gm.release())); |
| 603 | fSlides.push_back(std::move(slide)); |
| 604 | } |
| 605 | |
| 606 | gms = gms->next(); |
| 607 | } |
| 608 | // reverse gms |
| 609 | int numGMs = fSlides.count() - firstGM; |
| 610 | for (int i = 0; i < numGMs/2; ++i) { |
| 611 | std::swap(fSlides[firstGM + i], fSlides[fSlides.count() - i - 1]); |
| 612 | } |
| 613 | |
| 614 | // samples |
| 615 | const SkViewRegister* reg = SkViewRegister::Head(); |
| 616 | while (reg) { |
| 617 | sk_sp<Slide> slide(new SampleSlide(reg->factory())); |
| 618 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, slide->getName().c_str())) { |
| 619 | fSlides.push_back(slide); |
| 620 | } |
| 621 | reg = reg->next(); |
| 622 | } |
| 623 | |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 624 | for (const auto& info : gExternalSlidesInfo) { |
| 625 | for (const auto& flag : info.fFlags) { |
| 626 | if (SkStrEndsWith(flag.c_str(), info.fExtension)) { |
| 627 | // single file |
| 628 | addSlide(SkOSPath::Basename(flag.c_str()), flag, info.fFactory); |
| 629 | } else { |
| 630 | // directory |
| 631 | SkOSFile::Iter it(flag.c_str(), info.fExtension); |
| 632 | SkString name; |
| 633 | while (it.next(&name)) { |
| 634 | addSlide(name, SkOSPath::Join(flag.c_str(), name.c_str()), info.fFactory); |
| 635 | } |
Florin Malita | c659c2c | 2018-04-05 11:57:21 -0400 | [diff] [blame] | 636 | } |
Florin Malita | 3b526b0 | 2018-05-25 12:43:51 -0400 | [diff] [blame] | 637 | #if defined(SK_HAS_SKSG) |
Florin Malita | 0ffa322 | 2018-04-05 14:34:45 -0400 | [diff] [blame] | 638 | if (!dirSlides.empty()) { |
| 639 | fSlides.push_back( |
| 640 | sk_make_sp<SlideDir>(SkStringPrintf("%s[%s]", info.fDirName, flag.c_str()), |
| 641 | std::move(dirSlides))); |
| 642 | dirSlides.reset(); |
| 643 | } |
Florin Malita | 3b526b0 | 2018-05-25 12:43:51 -0400 | [diff] [blame] | 644 | #endif |
Florin Malita | c659c2c | 2018-04-05 11:57:21 -0400 | [diff] [blame] | 645 | } |
| 646 | } |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 650 | Viewer::~Viewer() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 651 | fWindow->detach(); |
| 652 | delete fWindow; |
| 653 | } |
| 654 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 655 | struct SkPaintTitleUpdater { |
| 656 | SkPaintTitleUpdater(SkString* title) : fTitle(title), fCount(0) {} |
| 657 | void append(const char* s) { |
| 658 | if (fCount == 0) { |
| 659 | fTitle->append(" {"); |
| 660 | } else { |
| 661 | fTitle->append(", "); |
| 662 | } |
| 663 | fTitle->append(s); |
| 664 | ++fCount; |
| 665 | } |
| 666 | void done() { |
| 667 | if (fCount > 0) { |
| 668 | fTitle->append("}"); |
| 669 | } |
| 670 | } |
| 671 | SkString* fTitle; |
| 672 | int fCount; |
| 673 | }; |
| 674 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 675 | void Viewer::updateTitle() { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 676 | if (!fWindow) { |
| 677 | return; |
| 678 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 679 | if (fWindow->sampleCount() < 1) { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 680 | return; // Surface hasn't been created yet. |
| 681 | } |
| 682 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 683 | SkString title("Viewer: "); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 684 | title.append(fSlides[fCurrentSlide]->getName()); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 685 | |
Yuqian Li | 399b3c2 | 2017-08-03 11:08:15 -0400 | [diff] [blame] | 686 | if (gSkUseDeltaAA) { |
| 687 | if (gSkForceDeltaAA) { |
| 688 | title.append(" <FDAA>"); |
| 689 | } else { |
| 690 | title.append(" <DAA>"); |
| 691 | } |
| 692 | } else if (gSkUseAnalyticAA) { |
| 693 | if (gSkForceAnalyticAA) { |
| 694 | title.append(" <FAAA>"); |
| 695 | } else { |
| 696 | title.append(" <AAA>"); |
| 697 | } |
| 698 | } |
| 699 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 700 | SkPaintTitleUpdater paintTitle(&title); |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 701 | auto paintFlag = [this, &paintTitle](SkPaint::Flags flag, bool (SkPaint::* isFlag)() const, |
| 702 | const char* on, const char* off) |
| 703 | { |
| 704 | if (fPaintOverrides.fFlags & flag) { |
| 705 | paintTitle.append((fPaint.*isFlag)() ? on : off); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 706 | } |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | paintFlag(SkPaint::kAntiAlias_Flag, &SkPaint::isAntiAlias, "Antialias", "Alias"); |
| 710 | paintFlag(SkPaint::kDither_Flag, &SkPaint::isDither, "DITHER", "No Dither"); |
| 711 | paintFlag(SkPaint::kFakeBoldText_Flag, &SkPaint::isFakeBoldText, "Fake Bold", "No Fake Bold"); |
| 712 | paintFlag(SkPaint::kLinearText_Flag, &SkPaint::isLinearText, "Linear Text", "Non-Linear Text"); |
| 713 | paintFlag(SkPaint::kSubpixelText_Flag, &SkPaint::isSubpixelText, "Subpixel Text", "Pixel Text"); |
| 714 | paintFlag(SkPaint::kLCDRenderText_Flag, &SkPaint::isLCDRenderText, "LCD", "lcd"); |
| 715 | paintFlag(SkPaint::kEmbeddedBitmapText_Flag, &SkPaint::isEmbeddedBitmapText, |
| 716 | "Bitmap Text", "No Bitmap Text"); |
| 717 | paintFlag(SkPaint::kAutoHinting_Flag, &SkPaint::isAutohinted, |
| 718 | "Force Autohint", "No Force Autohint"); |
| 719 | paintFlag(SkPaint::kVerticalText_Flag, &SkPaint::isVerticalText, |
| 720 | "Vertical Text", "No Vertical Text"); |
| 721 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 722 | if (fPaintOverrides.fHinting) { |
| 723 | switch (fPaint.getHinting()) { |
| 724 | case SkPaint::kNo_Hinting: |
| 725 | paintTitle.append("No Hinting"); |
| 726 | break; |
| 727 | case SkPaint::kSlight_Hinting: |
| 728 | paintTitle.append("Slight Hinting"); |
| 729 | break; |
| 730 | case SkPaint::kNormal_Hinting: |
| 731 | paintTitle.append("Normal Hinting"); |
| 732 | break; |
| 733 | case SkPaint::kFull_Hinting: |
| 734 | paintTitle.append("Full Hinting"); |
| 735 | break; |
| 736 | } |
| 737 | } |
| 738 | paintTitle.done(); |
| 739 | |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 740 | switch (fColorMode) { |
| 741 | case ColorMode::kLegacy: |
| 742 | title.append(" Legacy 8888"); |
| 743 | break; |
| 744 | case ColorMode::kColorManagedSRGB8888_NonLinearBlending: |
| 745 | title.append(" ColorManaged 8888 (Nonlinear blending)"); |
| 746 | break; |
| 747 | case ColorMode::kColorManagedSRGB8888: |
| 748 | title.append(" ColorManaged 8888"); |
| 749 | break; |
| 750 | case ColorMode::kColorManagedLinearF16: |
| 751 | title.append(" ColorManaged F16"); |
| 752 | break; |
| 753 | } |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 754 | |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 755 | if (ColorMode::kLegacy != fColorMode) { |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 756 | int curPrimaries = -1; |
| 757 | for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) { |
| 758 | if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) { |
| 759 | curPrimaries = i; |
| 760 | break; |
| 761 | } |
| 762 | } |
| 763 | title.appendf(" %s", curPrimaries >= 0 ? gNamedPrimaries[curPrimaries].fName : "Custom"); |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 764 | |
| 765 | if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) { |
| 766 | title.appendf(" Gamma %f", fColorSpaceTransferFn.fG); |
| 767 | } |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 768 | } |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 769 | |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 770 | const DisplayParams& params = fWindow->getRequestedDisplayParams(); |
| 771 | if (fPixelGeometryOverrides) { |
| 772 | switch (params.fSurfaceProps.pixelGeometry()) { |
| 773 | case kUnknown_SkPixelGeometry: |
| 774 | title.append( " Flat"); |
| 775 | break; |
| 776 | case kRGB_H_SkPixelGeometry: |
| 777 | title.append( " RGB"); |
| 778 | break; |
| 779 | case kBGR_H_SkPixelGeometry: |
| 780 | title.append( " BGR"); |
| 781 | break; |
| 782 | case kRGB_V_SkPixelGeometry: |
| 783 | title.append( " RGBV"); |
| 784 | break; |
| 785 | case kBGR_V_SkPixelGeometry: |
| 786 | title.append( " BGRV"); |
| 787 | break; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | if (params.fSurfaceProps.isUseDeviceIndependentFonts()) { |
| 792 | title.append(" DFT"); |
| 793 | } |
| 794 | |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 795 | title.append(" ["); |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 796 | title.append(kBackendTypeStrings[fBackendType]); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 797 | int msaa = fWindow->sampleCount(); |
| 798 | if (msaa > 1) { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 799 | title.appendf(" MSAA: %i", msaa); |
| 800 | } |
| 801 | title.append("]"); |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 802 | |
| 803 | GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers; |
Brian Osman | 1994f20 | 2018-07-10 11:41:22 -0400 | [diff] [blame] | 804 | if (GpuPathRenderers::kAll != pr) { |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 805 | title.appendf(" [Path renderer: %s]", gPathRendererNames[pr].c_str()); |
| 806 | } |
| 807 | |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 808 | if (kPerspective_Real == fPerspectiveMode) { |
| 809 | title.append(" Perpsective (Real)"); |
| 810 | } else if (kPerspective_Fake == fPerspectiveMode) { |
| 811 | title.append(" Perspective (Fake)"); |
| 812 | } |
| 813 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 814 | fWindow->setTitle(title.c_str()); |
| 815 | } |
| 816 | |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 817 | int Viewer::startupSlide() const { |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 818 | |
| 819 | if (!FLAGS_slide.isEmpty()) { |
| 820 | int count = fSlides.count(); |
| 821 | for (int i = 0; i < count; i++) { |
| 822 | if (fSlides[i]->getName().equals(FLAGS_slide[0])) { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 823 | return i; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | fprintf(stderr, "Unknown slide \"%s\"\n", FLAGS_slide[0]); |
| 828 | this->listNames(); |
| 829 | } |
| 830 | |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 831 | return 0; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 832 | } |
| 833 | |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 834 | void Viewer::listNames() const { |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 835 | SkDebugf("All Slides:\n"); |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 836 | for (const auto& slide : fSlides) { |
| 837 | SkDebugf(" %s\n", slide->getName().c_str()); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 841 | void Viewer::setCurrentSlide(int slide) { |
| 842 | SkASSERT(slide >= 0 && slide < fSlides.count()); |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 843 | |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 844 | if (slide == fCurrentSlide) { |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | if (fCurrentSlide >= 0) { |
| 849 | fSlides[fCurrentSlide]->unload(); |
| 850 | } |
| 851 | |
| 852 | fSlides[slide]->load(SkIntToScalar(fWindow->width()), |
| 853 | SkIntToScalar(fWindow->height())); |
| 854 | fCurrentSlide = slide; |
| 855 | this->setupCurrentSlide(); |
| 856 | } |
| 857 | |
| 858 | void Viewer::setupCurrentSlide() { |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 859 | if (fCurrentSlide >= 0) { |
| 860 | // prepare dimensions for image slides |
| 861 | fGesture.resetTouchState(); |
| 862 | fDefaultMatrix.reset(); |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 863 | |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 864 | const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 865 | const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height()); |
| 866 | const SkRect windowRect = SkRect::MakeIWH(fWindow->width(), fWindow->height()); |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 867 | |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 868 | // Start with a matrix that scales the slide to the available screen space |
| 869 | if (fWindow->scaleContentToFit()) { |
| 870 | if (windowRect.width() > 0 && windowRect.height() > 0) { |
| 871 | fDefaultMatrix.setRectToRect(slideBounds, windowRect, SkMatrix::kStart_ScaleToFit); |
| 872 | } |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 873 | } |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 874 | |
| 875 | // Prevent the user from dragging content so far outside the window they can't find it again |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 876 | fGesture.setTransLimit(slideBounds, windowRect, this->computePreTouchMatrix()); |
Jim Van Verth | 0848fb0 | 2018-01-22 13:39:30 -0500 | [diff] [blame] | 877 | |
| 878 | this->updateTitle(); |
| 879 | this->updateUIState(); |
| 880 | |
| 881 | fStatsLayer.resetMeasurements(); |
| 882 | |
| 883 | fWindow->inval(); |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 884 | } |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | #define MAX_ZOOM_LEVEL 8 |
| 888 | #define MIN_ZOOM_LEVEL -8 |
| 889 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 890 | void Viewer::changeZoomLevel(float delta) { |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 891 | fZoomLevel += delta; |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 892 | fZoomLevel = SkScalarPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL); |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 893 | this->preTouchMatrixChanged(); |
| 894 | } |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 895 | |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 896 | void Viewer::preTouchMatrixChanged() { |
| 897 | // Update the trans limit as the transform changes. |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 898 | const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 899 | const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height()); |
| 900 | const SkRect windowRect = SkRect::MakeIWH(fWindow->width(), fWindow->height()); |
| 901 | fGesture.setTransLimit(slideBounds, windowRect, this->computePreTouchMatrix()); |
| 902 | } |
| 903 | |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 904 | SkMatrix Viewer::computePerspectiveMatrix() { |
| 905 | SkScalar w = fWindow->width(), h = fWindow->height(); |
| 906 | SkPoint orthoPts[4] = { { 0, 0 }, { w, 0 }, { 0, h }, { w, h } }; |
| 907 | SkPoint perspPts[4] = { |
| 908 | { fPerspectivePoints[0].fX * w, fPerspectivePoints[0].fY * h }, |
| 909 | { fPerspectivePoints[1].fX * w, fPerspectivePoints[1].fY * h }, |
| 910 | { fPerspectivePoints[2].fX * w, fPerspectivePoints[2].fY * h }, |
| 911 | { fPerspectivePoints[3].fX * w, fPerspectivePoints[3].fY * h } |
| 912 | }; |
| 913 | SkMatrix m; |
| 914 | m.setPolyToPoly(orthoPts, perspPts, 4); |
| 915 | return m; |
| 916 | } |
| 917 | |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 918 | SkMatrix Viewer::computePreTouchMatrix() { |
| 919 | SkMatrix m = fDefaultMatrix; |
| 920 | SkScalar zoomScale = (fZoomLevel < 0) ? SK_Scalar1 / (SK_Scalar1 - fZoomLevel) |
| 921 | : SK_Scalar1 + fZoomLevel; |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 922 | m.preTranslate(fOffset.x(), fOffset.y()); |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 923 | m.preScale(zoomScale, zoomScale); |
Brian Osman | bdaf97b | 2018-04-26 16:22:42 -0400 | [diff] [blame] | 924 | |
| 925 | const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 926 | m.preRotate(fRotation, slideSize.width() * 0.5f, slideSize.height() * 0.5f); |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 927 | |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 928 | if (kPerspective_Real == fPerspectiveMode) { |
| 929 | SkMatrix persp = this->computePerspectiveMatrix(); |
Brian Osman | bdaf97b | 2018-04-26 16:22:42 -0400 | [diff] [blame] | 930 | m.postConcat(persp); |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 931 | } |
| 932 | |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 933 | return m; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 934 | } |
| 935 | |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 936 | SkMatrix Viewer::computeMatrix() { |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 937 | SkMatrix m = fGesture.localM(); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 938 | m.preConcat(fGesture.globalM()); |
Yuqian Li | 755778c | 2018-03-28 16:23:31 -0400 | [diff] [blame] | 939 | m.preConcat(this->computePreTouchMatrix()); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 940 | return m; |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 943 | void Viewer::setBackend(sk_app::Window::BackendType backendType) { |
| 944 | fBackendType = backendType; |
| 945 | |
| 946 | fWindow->detach(); |
| 947 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 948 | #if defined(SK_BUILD_FOR_WIN) |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 949 | // Switching between OpenGL, Vulkan, and ANGLE in the same window is problematic at this point |
| 950 | // on Windows, so we just delete the window and recreate it. |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 951 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 952 | delete fWindow; |
| 953 | fWindow = Window::CreateNativeWindow(nullptr); |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 954 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 955 | // re-register callbacks |
| 956 | fCommands.attach(fWindow); |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 957 | fWindow->pushLayer(this); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 958 | fWindow->pushLayer(&fStatsLayer); |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 959 | fWindow->pushLayer(&fImGuiLayer); |
| 960 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 961 | // Don't allow the window to re-attach. If we're in MSAA mode, the params we grabbed above |
| 962 | // will still include our correct sample count. But the re-created fWindow will lose that |
| 963 | // information. On Windows, we need to re-create the window when changing sample count, |
| 964 | // so we'll incorrectly detect that situation, then re-initialize the window in GL mode, |
| 965 | // rendering this tear-down step pointless (and causing the Vulkan window context to fail |
| 966 | // as if we had never changed windows at all). |
| 967 | fWindow->setRequestedDisplayParams(params, false); |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 968 | #endif |
| 969 | |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 970 | fWindow->attach(backend_type_for_window(fBackendType)); |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 971 | } |
| 972 | |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 973 | void Viewer::setColorMode(ColorMode colorMode) { |
| 974 | fColorMode = colorMode; |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 975 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 976 | // When we're in color managed mode, we tag our window surface as sRGB. If we've switched into |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 977 | // or out of legacy/nonlinear mode, we need to update our window configuration. |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 978 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 979 | bool wasInLegacy = !SkToBool(params.fColorSpace); |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 980 | bool wantLegacy = (ColorMode::kLegacy == fColorMode) || |
| 981 | (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode); |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 982 | if (wasInLegacy != wantLegacy) { |
| 983 | params.fColorSpace = wantLegacy ? nullptr : SkColorSpace::MakeSRGB(); |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 984 | fWindow->setRequestedDisplayParams(params); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | this->updateTitle(); |
| 988 | fWindow->inval(); |
| 989 | } |
| 990 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 991 | class OveridePaintFilterCanvas : public SkPaintFilterCanvas { |
| 992 | public: |
| 993 | OveridePaintFilterCanvas(SkCanvas* canvas, SkPaint* paint, Viewer::SkPaintFields* fields) |
| 994 | : SkPaintFilterCanvas(canvas), fPaint(paint), fPaintOverrides(fields) |
| 995 | { } |
| 996 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override { |
Ben Wagner | aa5da73 | 2018-03-28 13:36:02 -0400 | [diff] [blame] | 997 | if (*paint == nullptr) { |
| 998 | return true; |
| 999 | } |
Ben Wagner | d2ae4df | 2018-06-07 17:54:07 -0400 | [diff] [blame] | 1000 | if (fPaintOverrides->fTextSize) { |
| 1001 | paint->writable()->setTextSize(fPaint->getTextSize()); |
| 1002 | } |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 1003 | if (fPaintOverrides->fHinting) { |
| 1004 | paint->writable()->setHinting(fPaint->getHinting()); |
| 1005 | } |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1006 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 1007 | if (fPaintOverrides->fFlags & SkPaint::kAntiAlias_Flag) { |
| 1008 | paint->writable()->setAntiAlias(fPaint->isAntiAlias()); |
| 1009 | } |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1010 | if (fPaintOverrides->fFlags & SkPaint::kDither_Flag) { |
| 1011 | paint->writable()->setDither(fPaint->isDither()); |
| 1012 | } |
| 1013 | if (fPaintOverrides->fFlags & SkPaint::kFakeBoldText_Flag) { |
| 1014 | paint->writable()->setFakeBoldText(fPaint->isFakeBoldText()); |
| 1015 | } |
| 1016 | if (fPaintOverrides->fFlags & SkPaint::kLinearText_Flag) { |
| 1017 | paint->writable()->setLinearText(fPaint->isLinearText()); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 1018 | } |
| 1019 | if (fPaintOverrides->fFlags & SkPaint::kSubpixelText_Flag) { |
| 1020 | paint->writable()->setSubpixelText(fPaint->isSubpixelText()); |
| 1021 | } |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1022 | if (fPaintOverrides->fFlags & SkPaint::kLCDRenderText_Flag) { |
| 1023 | paint->writable()->setLCDRenderText(fPaint->isLCDRenderText()); |
| 1024 | } |
| 1025 | if (fPaintOverrides->fFlags & SkPaint::kEmbeddedBitmapText_Flag) { |
| 1026 | paint->writable()->setEmbeddedBitmapText(fPaint->isEmbeddedBitmapText()); |
| 1027 | } |
| 1028 | if (fPaintOverrides->fFlags & SkPaint::kAutoHinting_Flag) { |
| 1029 | paint->writable()->setAutohinted(fPaint->isAutohinted()); |
| 1030 | } |
| 1031 | if (fPaintOverrides->fFlags & SkPaint::kVerticalText_Flag) { |
| 1032 | paint->writable()->setVerticalText(fPaint->isVerticalText()); |
| 1033 | } |
| 1034 | |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 1035 | return true; |
| 1036 | } |
| 1037 | SkPaint* fPaint; |
| 1038 | Viewer::SkPaintFields* fPaintOverrides; |
| 1039 | }; |
| 1040 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1041 | void Viewer::drawSlide(SkCanvas* canvas) { |
Brian Salomon | bf52e3d | 2017-02-22 15:21:11 -0500 | [diff] [blame] | 1042 | SkAutoCanvasRestore autorestore(canvas, false); |
| 1043 | |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1044 | // By default, we render directly into the window's surface/canvas |
| 1045 | SkCanvas* slideCanvas = canvas; |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1046 | fLastImage.reset(); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 1047 | |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1048 | // If we're in any of the color managed modes, construct the color space we're going to use |
| 1049 | sk_sp<SkColorSpace> cs = nullptr; |
| 1050 | if (ColorMode::kLegacy != fColorMode) { |
| 1051 | auto transferFn = (ColorMode::kColorManagedLinearF16 == fColorMode) |
| 1052 | ? SkColorSpace::kLinear_RenderTargetGamma : SkColorSpace::kSRGB_RenderTargetGamma; |
Mike Klein | c722f79 | 2017-07-31 11:57:21 -0400 | [diff] [blame] | 1053 | SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor); |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1054 | SkAssertResult(fColorSpacePrimaries.toXYZD50(&toXYZ)); |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 1055 | if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) { |
| 1056 | cs = SkColorSpace::MakeRGB(fColorSpaceTransferFn, toXYZ); |
| 1057 | } else { |
| 1058 | cs = SkColorSpace::MakeRGB(transferFn, toXYZ); |
| 1059 | } |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
Brian Osman | 3ac99cf | 2017-12-01 11:23:53 -0500 | [diff] [blame] | 1062 | if (fSaveToSKP) { |
| 1063 | SkPictureRecorder recorder; |
| 1064 | SkCanvas* recorderCanvas = recorder.beginRecording( |
| 1065 | SkRect::Make(fSlides[fCurrentSlide]->getDimensions())); |
| 1066 | // In xform-canvas mode, record the transformed output |
| 1067 | std::unique_ptr<SkCanvas> xformCanvas = nullptr; |
| 1068 | if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) { |
| 1069 | xformCanvas = SkCreateColorSpaceXformCanvas(recorderCanvas, cs); |
| 1070 | recorderCanvas = xformCanvas.get(); |
| 1071 | } |
| 1072 | fSlides[fCurrentSlide]->draw(recorderCanvas); |
| 1073 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 1074 | SkFILEWStream stream("sample_app.skp"); |
| 1075 | picture->serialize(&stream); |
| 1076 | fSaveToSKP = false; |
| 1077 | } |
| 1078 | |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1079 | // If we're in F16, or we're zooming, or we're in color correct 8888 and the gamut isn't sRGB, |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 1080 | // we need to render offscreen. We also need to render offscreen if we're in any raster mode, |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 1081 | // because the window surface is actually GL, or we're doing fake perspective. |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1082 | sk_sp<SkSurface> offscreenSurface = nullptr; |
Yuqian Li | b2ba664 | 2017-11-22 12:07:41 -0500 | [diff] [blame] | 1083 | std::unique_ptr<SkCanvas> threadedCanvas; |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 1084 | if (Window::kRaster_BackendType == fBackendType || |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 1085 | kPerspective_Fake == fPerspectiveMode || |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 1086 | ColorMode::kColorManagedLinearF16 == fColorMode || |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 1087 | fShowZoomWindow || |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1088 | (ColorMode::kColorManagedSRGB8888 == fColorMode && |
| 1089 | !primaries_equal(fColorSpacePrimaries, gSrgbPrimaries))) { |
| 1090 | |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 1091 | SkColorType colorType = (ColorMode::kColorManagedLinearF16 == fColorMode) |
| 1092 | ? kRGBA_F16_SkColorType : kN32_SkColorType; |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1093 | // In nonlinear blending mode, we actually use a legacy off-screen canvas, and wrap it |
| 1094 | // with a special canvas (below) that has the color space attached |
| 1095 | sk_sp<SkColorSpace> offscreenColorSpace = |
| 1096 | (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) ? nullptr : cs; |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 1097 | SkImageInfo info = SkImageInfo::Make(fWindow->width(), fWindow->height(), colorType, |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1098 | kPremul_SkAlphaType, std::move(offscreenColorSpace)); |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 1099 | SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 1100 | canvas->getProps(&props); |
| 1101 | offscreenSurface = Window::kRaster_BackendType == fBackendType |
| 1102 | ? SkSurface::MakeRaster(info, &props) |
| 1103 | : canvas->makeSurface(info); |
Yuqian Li | b2ba664 | 2017-11-22 12:07:41 -0500 | [diff] [blame] | 1104 | SkPixmap offscreenPixmap; |
Mike Klein | 48b6490 | 2018-07-25 13:28:44 -0400 | [diff] [blame] | 1105 | slideCanvas = offscreenSurface->getCanvas(); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1106 | } |
| 1107 | |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1108 | std::unique_ptr<SkCanvas> xformCanvas = nullptr; |
| 1109 | if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) { |
| 1110 | xformCanvas = SkCreateColorSpaceXformCanvas(slideCanvas, cs); |
| 1111 | slideCanvas = xformCanvas.get(); |
| 1112 | } |
| 1113 | |
Brian Salomon | bf52e3d | 2017-02-22 15:21:11 -0500 | [diff] [blame] | 1114 | int count = slideCanvas->save(); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1115 | slideCanvas->clear(SK_ColorWHITE); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1116 | slideCanvas->concat(computeMatrix()); |
Brian Osman | e19e23f | 2018-05-22 16:56:40 -0400 | [diff] [blame] | 1117 | if (kPerspective_Real == fPerspectiveMode) { |
| 1118 | slideCanvas->clipRect(SkRect::MakeWH(fWindow->width(), fWindow->height())); |
| 1119 | } |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 1120 | // Time the painting logic of the slide |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1121 | fStatsLayer.beginTiming(fPaintTimer); |
Ben Wagner | abdcc5f | 2018-02-12 16:37:28 -0500 | [diff] [blame] | 1122 | OveridePaintFilterCanvas filterCanvas(slideCanvas, &fPaint, &fPaintOverrides); |
| 1123 | fSlides[fCurrentSlide]->draw(&filterCanvas); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1124 | fStatsLayer.endTiming(fPaintTimer); |
Brian Salomon | bf52e3d | 2017-02-22 15:21:11 -0500 | [diff] [blame] | 1125 | slideCanvas->restoreToCount(count); |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 1126 | |
| 1127 | // Force a flush so we can time that, too |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1128 | fStatsLayer.beginTiming(fFlushTimer); |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 1129 | slideCanvas->flush(); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1130 | fStatsLayer.endTiming(fFlushTimer); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1131 | |
| 1132 | // If we rendered offscreen, snap an image and push the results to the window's canvas |
| 1133 | if (offscreenSurface) { |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1134 | fLastImage = offscreenSurface->makeImageSnapshot(); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1135 | |
| 1136 | // Tag the image with the sRGB gamut, so no further color space conversion happens |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1137 | sk_sp<SkColorSpace> srgb = (ColorMode::kColorManagedLinearF16 == fColorMode) |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 1138 | ? SkColorSpace::MakeSRGBLinear() : SkColorSpace::MakeSRGB(); |
Brian Osman | e0d4fba | 2017-03-15 10:24:55 -0400 | [diff] [blame] | 1139 | auto retaggedImage = SkImageMakeRasterCopyAndAssignColorSpace(fLastImage.get(), srgb.get()); |
Brian Salomon | bf52e3d | 2017-02-22 15:21:11 -0500 | [diff] [blame] | 1140 | SkPaint paint; |
| 1141 | paint.setBlendMode(SkBlendMode::kSrc); |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 1142 | int prePerspectiveCount = canvas->save(); |
| 1143 | if (kPerspective_Fake == fPerspectiveMode) { |
| 1144 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 1145 | canvas->clear(SK_ColorWHITE); |
| 1146 | canvas->concat(this->computePerspectiveMatrix()); |
| 1147 | } |
Brian Salomon | bf52e3d | 2017-02-22 15:21:11 -0500 | [diff] [blame] | 1148 | canvas->drawImage(retaggedImage, 0, 0, &paint); |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 1149 | canvas->restoreToCount(prePerspectiveCount); |
liyuqian | 74959a1 | 2016-06-16 14:10:34 -0700 | [diff] [blame] | 1150 | } |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 1153 | void Viewer::onBackendCreated() { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 1154 | this->setupCurrentSlide(); |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 1155 | fWindow->show(); |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 1156 | } |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 1157 | |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 1158 | void Viewer::onPaint(SkCanvas* canvas) { |
Jim Van Verth | 90dcce5 | 2017-11-03 13:36:07 -0400 | [diff] [blame] | 1159 | this->drawSlide(canvas); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 1160 | |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 1161 | fCommands.drawHelp(canvas); |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 1162 | |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 1163 | this->drawImGui(); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
Florin Malita | cefc1b9 | 2018-02-19 21:43:47 -0500 | [diff] [blame] | 1166 | SkPoint Viewer::mapEvent(float x, float y) { |
| 1167 | const auto m = this->computeMatrix(); |
| 1168 | SkMatrix inv; |
| 1169 | |
| 1170 | SkAssertResult(m.invert(&inv)); |
| 1171 | |
| 1172 | return inv.mapXY(x, y); |
| 1173 | } |
| 1174 | |
jvanverth | 814e38d | 2016-06-06 08:48:47 -0700 | [diff] [blame] | 1175 | bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) { |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 1176 | if (GestureDevice::kMouse == fGestureDevice) { |
| 1177 | return false; |
| 1178 | } |
Florin Malita | cefc1b9 | 2018-02-19 21:43:47 -0500 | [diff] [blame] | 1179 | |
| 1180 | const auto slidePt = this->mapEvent(x, y); |
| 1181 | if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, 0)) { |
| 1182 | fWindow->inval(); |
| 1183 | return true; |
| 1184 | } |
| 1185 | |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 1186 | void* castedOwner = reinterpret_cast<void*>(owner); |
| 1187 | switch (state) { |
| 1188 | case Window::kUp_InputState: { |
| 1189 | fGesture.touchEnd(castedOwner); |
| 1190 | break; |
| 1191 | } |
| 1192 | case Window::kDown_InputState: { |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 1193 | fGesture.touchBegin(castedOwner, x, y); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | } |
| 1196 | case Window::kMove_InputState: { |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 1197 | fGesture.touchMoved(castedOwner, x, y); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | } |
| 1200 | } |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 1201 | fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 1202 | fWindow->inval(); |
| 1203 | return true; |
| 1204 | } |
| 1205 | |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 1206 | bool Viewer::onMouse(int x, int y, Window::InputState state, uint32_t modifiers) { |
Brian Osman | 16c81a1 | 2017-12-20 11:58:34 -0500 | [diff] [blame] | 1207 | if (GestureDevice::kTouch == fGestureDevice) { |
| 1208 | return false; |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 1209 | } |
Brian Osman | 16c81a1 | 2017-12-20 11:58:34 -0500 | [diff] [blame] | 1210 | |
Florin Malita | cefc1b9 | 2018-02-19 21:43:47 -0500 | [diff] [blame] | 1211 | const auto slidePt = this->mapEvent(x, y); |
| 1212 | if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, modifiers)) { |
| 1213 | fWindow->inval(); |
| 1214 | return true; |
Brian Osman | 16c81a1 | 2017-12-20 11:58:34 -0500 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | switch (state) { |
| 1218 | case Window::kUp_InputState: { |
| 1219 | fGesture.touchEnd(nullptr); |
| 1220 | break; |
| 1221 | } |
| 1222 | case Window::kDown_InputState: { |
| 1223 | fGesture.touchBegin(nullptr, x, y); |
| 1224 | break; |
| 1225 | } |
| 1226 | case Window::kMove_InputState: { |
| 1227 | fGesture.touchMoved(nullptr, x, y); |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone; |
| 1232 | |
| 1233 | if (state != Window::kMove_InputState || fGesture.isBeingTouched()) { |
| 1234 | fWindow->inval(); |
| 1235 | } |
Jim Van Verth | e770578 | 2017-05-04 14:00:59 -0400 | [diff] [blame] | 1236 | return true; |
| 1237 | } |
| 1238 | |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1239 | static ImVec2 ImGui_DragPrimary(const char* label, float* x, float* y, |
| 1240 | const ImVec2& pos, const ImVec2& size) { |
| 1241 | // Transform primaries ([0, 0] - [0.8, 0.9]) to screen coords (including Y-flip) |
| 1242 | ImVec2 center(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y); |
| 1243 | |
| 1244 | // Invisible 10x10 button |
| 1245 | ImGui::SetCursorScreenPos(ImVec2(center.x - 5, center.y - 5)); |
| 1246 | ImGui::InvisibleButton(label, ImVec2(10, 10)); |
| 1247 | |
| 1248 | if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { |
| 1249 | ImGuiIO& io = ImGui::GetIO(); |
| 1250 | // Normalized mouse position, relative to our gamut box |
| 1251 | ImVec2 mousePosXY((io.MousePos.x - pos.x) / size.x, (io.MousePos.y - pos.y) / size.y); |
| 1252 | // Clamp to edge of box, convert back to primary scale |
| 1253 | *x = SkTPin(mousePosXY.x, 0.0f, 1.0f) * 0.8f; |
| 1254 | *y = SkTPin(1 - mousePosXY.y, 0.0f, 1.0f) * 0.9f; |
| 1255 | } |
| 1256 | |
| 1257 | if (ImGui::IsItemHovered()) { |
| 1258 | ImGui::SetTooltip("x: %.3f\ny: %.3f", *x, *y); |
| 1259 | } |
| 1260 | |
| 1261 | // Return screen coordinates for the caller. We could just return center here, but we'd have |
| 1262 | // one frame of lag during drag. |
| 1263 | return ImVec2(pos.x + (*x / 0.8f) * size.x, pos.y + (1.0f - (*y / 0.9f)) * size.y); |
| 1264 | } |
| 1265 | |
| 1266 | static void ImGui_Primaries(SkColorSpacePrimaries* primaries, SkPaint* gamutPaint) { |
| 1267 | ImDrawList* drawList = ImGui::GetWindowDrawList(); |
| 1268 | |
| 1269 | // The gamut image covers a (0.8 x 0.9) shaped region, so fit our image/canvas to the available |
| 1270 | // width, and scale the height to maintain aspect ratio. |
| 1271 | float canvasWidth = SkTMax(ImGui::GetContentRegionAvailWidth(), 50.0f); |
| 1272 | ImVec2 size = ImVec2(canvasWidth, canvasWidth * (0.9f / 0.8f)); |
| 1273 | ImVec2 pos = ImGui::GetCursorScreenPos(); |
| 1274 | |
| 1275 | // Background image. Only draw a subset of the image, to avoid the regions less than zero. |
| 1276 | // Simplifes re-mapping math, clipping behavior, and increases resolution in the useful area. |
| 1277 | // Magic numbers are pixel locations of the origin and upper-right corner. |
| 1278 | drawList->AddImage(gamutPaint, pos, ImVec2(pos.x + size.x, pos.y + size.y), |
| 1279 | ImVec2(242, 61), ImVec2(1897, 1922)); |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1280 | |
| 1281 | // Primary markers |
| 1282 | ImVec2 r = ImGui_DragPrimary("R", &primaries->fRX, &primaries->fRY, pos, size); |
| 1283 | ImVec2 g = ImGui_DragPrimary("G", &primaries->fGX, &primaries->fGY, pos, size); |
| 1284 | ImVec2 b = ImGui_DragPrimary("B", &primaries->fBX, &primaries->fBY, pos, size); |
| 1285 | ImVec2 w = ImGui_DragPrimary("W", &primaries->fWX, &primaries->fWY, pos, size); |
| 1286 | |
| 1287 | // Gamut triangle |
| 1288 | drawList->AddCircle(r, 5.0f, 0xFF000040); |
| 1289 | drawList->AddCircle(g, 5.0f, 0xFF004000); |
| 1290 | drawList->AddCircle(b, 5.0f, 0xFF400000); |
| 1291 | drawList->AddCircle(w, 5.0f, 0xFFFFFFFF); |
| 1292 | drawList->AddTriangle(r, g, b, 0xFFFFFFFF); |
| 1293 | |
| 1294 | // Re-position cursor immediate after the diagram for subsequent controls |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1295 | ImGui::SetCursorScreenPos(ImVec2(pos.x, pos.y + size.y)); |
| 1296 | } |
| 1297 | |
| 1298 | static ImVec2 ImGui_DragPoint(const char* label, SkPoint* p, |
| 1299 | const ImVec2& pos, const ImVec2& size, bool* dragging) { |
| 1300 | // Transform points ([0, 0] - [1.0, 1.0]) to screen coords |
| 1301 | ImVec2 center(pos.x + p->fX * size.x, pos.y + p->fY * size.y); |
| 1302 | |
| 1303 | // Invisible 10x10 button |
| 1304 | ImGui::SetCursorScreenPos(ImVec2(center.x - 5, center.y - 5)); |
| 1305 | ImGui::InvisibleButton(label, ImVec2(10, 10)); |
| 1306 | |
| 1307 | if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { |
| 1308 | ImGuiIO& io = ImGui::GetIO(); |
| 1309 | // Normalized mouse position, relative to our gamut box |
| 1310 | ImVec2 mousePosXY((io.MousePos.x - pos.x) / size.x, (io.MousePos.y - pos.y) / size.y); |
| 1311 | // Clamp to edge of box |
| 1312 | p->fX = SkTPin(mousePosXY.x, 0.0f, 1.0f); |
| 1313 | p->fY = SkTPin(mousePosXY.y, 0.0f, 1.0f); |
| 1314 | *dragging = true; |
| 1315 | } |
| 1316 | |
| 1317 | // Return screen coordinates for the caller. We could just return center here, but we'd have |
| 1318 | // one frame of lag during drag. |
| 1319 | return ImVec2(pos.x + p->fX * size.x, pos.y + p->fY * size.y); |
| 1320 | } |
| 1321 | |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1322 | static bool ImGui_DragLocation(SkPoint* pt) { |
| 1323 | ImDrawList* drawList = ImGui::GetWindowDrawList(); |
| 1324 | |
| 1325 | // Fit our image/canvas to the available width, and scale the height to maintain aspect ratio. |
| 1326 | float canvasWidth = SkTMax(ImGui::GetContentRegionAvailWidth(), 50.0f); |
| 1327 | ImVec2 size = ImVec2(canvasWidth, canvasWidth); |
| 1328 | ImVec2 pos = ImGui::GetCursorScreenPos(); |
| 1329 | |
| 1330 | // Background rectangle |
| 1331 | drawList->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0, 0, 0, 128)); |
| 1332 | |
| 1333 | // Location marker |
| 1334 | bool dragging = false; |
| 1335 | ImVec2 tl = ImGui_DragPoint("SL", pt + 0, pos, size, &dragging); |
| 1336 | drawList->AddCircle(tl, 5.0f, 0xFFFFFFFF); |
| 1337 | |
| 1338 | ImGui::SetCursorScreenPos(ImVec2(pos.x, pos.y + size.y)); |
| 1339 | ImGui::Spacing(); |
| 1340 | |
| 1341 | return dragging; |
| 1342 | } |
| 1343 | |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1344 | static bool ImGui_DragQuad(SkPoint* pts) { |
| 1345 | ImDrawList* drawList = ImGui::GetWindowDrawList(); |
| 1346 | |
| 1347 | // Fit our image/canvas to the available width, and scale the height to maintain aspect ratio. |
| 1348 | float canvasWidth = SkTMax(ImGui::GetContentRegionAvailWidth(), 50.0f); |
| 1349 | ImVec2 size = ImVec2(canvasWidth, canvasWidth); |
| 1350 | ImVec2 pos = ImGui::GetCursorScreenPos(); |
| 1351 | |
| 1352 | // Background rectangle |
| 1353 | drawList->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0, 0, 0, 128)); |
| 1354 | |
| 1355 | // Corner markers |
| 1356 | bool dragging = false; |
| 1357 | ImVec2 tl = ImGui_DragPoint("TL", pts + 0, pos, size, &dragging); |
| 1358 | ImVec2 tr = ImGui_DragPoint("TR", pts + 1, pos, size, &dragging); |
| 1359 | ImVec2 bl = ImGui_DragPoint("BL", pts + 2, pos, size, &dragging); |
| 1360 | ImVec2 br = ImGui_DragPoint("BR", pts + 3, pos, size, &dragging); |
| 1361 | |
| 1362 | // Draw markers and quad |
| 1363 | drawList->AddCircle(tl, 5.0f, 0xFFFFFFFF); |
| 1364 | drawList->AddCircle(tr, 5.0f, 0xFFFFFFFF); |
| 1365 | drawList->AddCircle(bl, 5.0f, 0xFFFFFFFF); |
| 1366 | drawList->AddCircle(br, 5.0f, 0xFFFFFFFF); |
| 1367 | drawList->AddLine(tl, tr, 0xFFFFFFFF); |
| 1368 | drawList->AddLine(tr, br, 0xFFFFFFFF); |
| 1369 | drawList->AddLine(br, bl, 0xFFFFFFFF); |
| 1370 | drawList->AddLine(bl, tl, 0xFFFFFFFF); |
| 1371 | |
| 1372 | ImGui::SetCursorScreenPos(ImVec2(pos.x, pos.y + size.y)); |
| 1373 | ImGui::Spacing(); |
| 1374 | |
| 1375 | return dragging; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1376 | } |
| 1377 | |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 1378 | void Viewer::drawImGui() { |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1379 | // Support drawing the ImGui demo window. Superfluous, but gives a good idea of what's possible |
| 1380 | if (fShowImGuiTestWindow) { |
Brian Osman | 7197e05 | 2018-06-29 14:30:48 -0400 | [diff] [blame] | 1381 | ImGui::ShowDemoWindow(&fShowImGuiTestWindow); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | if (fShowImGuiDebugWindow) { |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1385 | // We have some dynamic content that sizes to fill available size. If the scroll bar isn't |
| 1386 | // always visible, we can end up in a layout feedback loop. |
Brian Osman | 7197e05 | 2018-06-29 14:30:48 -0400 | [diff] [blame] | 1387 | ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver); |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1388 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 1389 | bool paramsChanged = false; |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1390 | if (ImGui::Begin("Tools", &fShowImGuiDebugWindow, |
| 1391 | ImGuiWindowFlags_AlwaysVerticalScrollbar)) { |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 1392 | if (ImGui::CollapsingHeader("Backend")) { |
| 1393 | int newBackend = static_cast<int>(fBackendType); |
| 1394 | ImGui::RadioButton("Raster", &newBackend, sk_app::Window::kRaster_BackendType); |
| 1395 | ImGui::SameLine(); |
| 1396 | ImGui::RadioButton("OpenGL", &newBackend, sk_app::Window::kNativeGL_BackendType); |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 1397 | #if SK_ANGLE && defined(SK_BUILD_FOR_WIN) |
| 1398 | ImGui::SameLine(); |
| 1399 | ImGui::RadioButton("ANGLE", &newBackend, sk_app::Window::kANGLE_BackendType); |
| 1400 | #endif |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 1401 | #if defined(SK_VULKAN) |
| 1402 | ImGui::SameLine(); |
| 1403 | ImGui::RadioButton("Vulkan", &newBackend, sk_app::Window::kVulkan_BackendType); |
| 1404 | #endif |
| 1405 | if (newBackend != fBackendType) { |
| 1406 | fDeferredActions.push_back([=]() { |
| 1407 | this->setBackend(static_cast<sk_app::Window::BackendType>(newBackend)); |
| 1408 | }); |
| 1409 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1410 | |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1411 | const GrContext* ctx = fWindow->getGrContext(); |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 1412 | bool* wire = ¶ms.fGrContextOptions.fWireframeMode; |
| 1413 | if (ctx && ImGui::Checkbox("Wireframe Mode", wire)) { |
| 1414 | paramsChanged = true; |
| 1415 | } |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1416 | |
Brian Osman | 28b1252 | 2017-03-08 17:10:24 -0500 | [diff] [blame] | 1417 | if (ctx) { |
| 1418 | int sampleCount = fWindow->sampleCount(); |
| 1419 | ImGui::Text("MSAA: "); ImGui::SameLine(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1420 | ImGui::RadioButton("1", &sampleCount, 1); ImGui::SameLine(); |
Brian Osman | 28b1252 | 2017-03-08 17:10:24 -0500 | [diff] [blame] | 1421 | ImGui::RadioButton("4", &sampleCount, 4); ImGui::SameLine(); |
| 1422 | ImGui::RadioButton("8", &sampleCount, 8); ImGui::SameLine(); |
| 1423 | ImGui::RadioButton("16", &sampleCount, 16); |
| 1424 | |
| 1425 | if (sampleCount != params.fMSAASampleCount) { |
| 1426 | params.fMSAASampleCount = sampleCount; |
| 1427 | paramsChanged = true; |
| 1428 | } |
| 1429 | } |
| 1430 | |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 1431 | int pixelGeometryIdx = 0; |
| 1432 | if (fPixelGeometryOverrides) { |
| 1433 | pixelGeometryIdx = params.fSurfaceProps.pixelGeometry() + 1; |
| 1434 | } |
| 1435 | if (ImGui::Combo("Pixel Geometry", &pixelGeometryIdx, |
| 1436 | "Default\0Flat\0RGB\0BGR\0RGBV\0BGRV\0\0")) |
| 1437 | { |
| 1438 | uint32_t flags = params.fSurfaceProps.flags(); |
| 1439 | if (pixelGeometryIdx == 0) { |
| 1440 | fPixelGeometryOverrides = false; |
| 1441 | params.fSurfaceProps = SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1442 | } else { |
| 1443 | fPixelGeometryOverrides = true; |
| 1444 | SkPixelGeometry pixelGeometry = SkTo<SkPixelGeometry>(pixelGeometryIdx - 1); |
| 1445 | params.fSurfaceProps = SkSurfaceProps(flags, pixelGeometry); |
| 1446 | } |
| 1447 | paramsChanged = true; |
| 1448 | } |
| 1449 | |
| 1450 | bool useDFT = params.fSurfaceProps.isUseDeviceIndependentFonts(); |
| 1451 | if (ImGui::Checkbox("DFT", &useDFT)) { |
| 1452 | uint32_t flags = params.fSurfaceProps.flags(); |
| 1453 | if (useDFT) { |
| 1454 | flags |= SkSurfaceProps::kUseDeviceIndependentFonts_Flag; |
| 1455 | } else { |
| 1456 | flags &= ~SkSurfaceProps::kUseDeviceIndependentFonts_Flag; |
| 1457 | } |
| 1458 | SkPixelGeometry pixelGeometry = params.fSurfaceProps.pixelGeometry(); |
| 1459 | params.fSurfaceProps = SkSurfaceProps(flags, pixelGeometry); |
| 1460 | paramsChanged = true; |
| 1461 | } |
| 1462 | |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1463 | if (ImGui::TreeNode("Path Renderers")) { |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1464 | GpuPathRenderers prevPr = params.fGrContextOptions.fGpuPathRenderers; |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1465 | auto prButton = [&](GpuPathRenderers x) { |
| 1466 | if (ImGui::RadioButton(gPathRendererNames[x].c_str(), prevPr == x)) { |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1467 | if (x != params.fGrContextOptions.fGpuPathRenderers) { |
| 1468 | params.fGrContextOptions.fGpuPathRenderers = x; |
| 1469 | paramsChanged = true; |
| 1470 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1471 | } |
| 1472 | }; |
| 1473 | |
| 1474 | if (!ctx) { |
| 1475 | ImGui::RadioButton("Software", true); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1476 | } else if (fWindow->sampleCount() > 1) { |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1477 | prButton(GpuPathRenderers::kAll); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1478 | if (ctx->contextPriv().caps()->shaderCaps()->pathRenderingSupport()) { |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1479 | prButton(GpuPathRenderers::kStencilAndCover); |
| 1480 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1481 | prButton(GpuPathRenderers::kTessellating); |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1482 | prButton(GpuPathRenderers::kNone); |
| 1483 | } else { |
| 1484 | prButton(GpuPathRenderers::kAll); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1485 | if (GrCoverageCountingPathRenderer::IsSupported( |
| 1486 | *ctx->contextPriv().caps())) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 1487 | prButton(GpuPathRenderers::kCoverageCounting); |
| 1488 | } |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 1489 | prButton(GpuPathRenderers::kSmall); |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1490 | prButton(GpuPathRenderers::kTessellating); |
| 1491 | prButton(GpuPathRenderers::kNone); |
| 1492 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 1493 | ImGui::TreePop(); |
| 1494 | } |
Brian Osman | 621491e | 2017-02-28 15:45:01 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 1497 | if (ImGui::CollapsingHeader("Transform")) { |
| 1498 | float zoom = fZoomLevel; |
| 1499 | if (ImGui::SliderFloat("Zoom", &zoom, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL)) { |
| 1500 | fZoomLevel = zoom; |
| 1501 | this->preTouchMatrixChanged(); |
| 1502 | paramsChanged = true; |
| 1503 | } |
| 1504 | float deg = fRotation; |
Ben Wagner | cb13935 | 2018-05-04 10:33:04 -0400 | [diff] [blame] | 1505 | if (ImGui::SliderFloat("Rotate", °, -30, 360, "%.3f deg")) { |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 1506 | fRotation = deg; |
| 1507 | this->preTouchMatrixChanged(); |
| 1508 | paramsChanged = true; |
| 1509 | } |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1510 | if (ImGui::CollapsingHeader("Subpixel offset", ImGuiTreeNodeFlags_NoTreePushOnOpen)) { |
| 1511 | if (ImGui_DragLocation(&fOffset)) { |
| 1512 | this->preTouchMatrixChanged(); |
| 1513 | paramsChanged = true; |
| 1514 | } |
| 1515 | } |
Brian Osman | 805a727 | 2018-05-02 15:40:20 -0400 | [diff] [blame] | 1516 | int perspectiveMode = static_cast<int>(fPerspectiveMode); |
| 1517 | if (ImGui::Combo("Perspective", &perspectiveMode, "Off\0Real\0Fake\0\0")) { |
| 1518 | fPerspectiveMode = static_cast<PerspectiveMode>(perspectiveMode); |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1519 | this->preTouchMatrixChanged(); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1520 | paramsChanged = true; |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1521 | } |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1522 | if (perspectiveMode != kPerspective_Off && ImGui_DragQuad(fPerspectivePoints)) { |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1523 | this->preTouchMatrixChanged(); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1524 | paramsChanged = true; |
Brian Osman | 9bb47cf | 2018-04-26 15:55:00 -0400 | [diff] [blame] | 1525 | } |
Ben Wagner | d02a74d | 2018-04-23 12:55:06 -0400 | [diff] [blame] | 1526 | } |
| 1527 | |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 1528 | if (ImGui::CollapsingHeader("Paint")) { |
| 1529 | int hintingIdx = 0; |
| 1530 | if (fPaintOverrides.fHinting) { |
| 1531 | hintingIdx = fPaint.getHinting() + 1; |
| 1532 | } |
| 1533 | if (ImGui::Combo("Hinting", &hintingIdx, |
| 1534 | "Default\0None\0Slight\0Normal\0Full\0\0")) |
| 1535 | { |
| 1536 | if (hintingIdx == 0) { |
| 1537 | fPaintOverrides.fHinting = false; |
| 1538 | fPaint.setHinting(SkPaint::kNo_Hinting); |
| 1539 | } else { |
| 1540 | fPaintOverrides.fHinting = true; |
| 1541 | SkPaint::Hinting hinting = SkTo<SkPaint::Hinting>(hintingIdx - 1); |
| 1542 | fPaint.setHinting(hinting); |
| 1543 | } |
| 1544 | paramsChanged = true; |
| 1545 | } |
| 1546 | |
| 1547 | int aliasIdx = 0; |
| 1548 | if (fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag) { |
| 1549 | aliasIdx = SkTo<int>(fPaintOverrides.fAntiAlias) + 1; |
| 1550 | } |
| 1551 | if (ImGui::Combo("Anti-Alias", &aliasIdx, |
| 1552 | "Default\0Alias\0Normal\0AnalyticAAEnabled\0AnalyticAAForced\0" |
| 1553 | "DeltaAAEnabled\0DeltaAAForced\0\0")) |
| 1554 | { |
| 1555 | gSkUseAnalyticAA = fPaintOverrides.fOriginalSkUseAnalyticAA; |
| 1556 | gSkForceAnalyticAA = fPaintOverrides.fOriginalSkForceAnalyticAA; |
| 1557 | gSkUseDeltaAA = fPaintOverrides.fOriginalSkUseDeltaAA; |
| 1558 | gSkForceDeltaAA = fPaintOverrides.fOriginalSkForceDeltaAA; |
| 1559 | if (aliasIdx == 0) { |
| 1560 | fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias; |
| 1561 | fPaintOverrides.fFlags &= ~SkPaint::kAntiAlias_Flag; |
| 1562 | } else { |
| 1563 | fPaintOverrides.fFlags |= SkPaint::kAntiAlias_Flag; |
| 1564 | fPaintOverrides.fAntiAlias =SkTo<SkPaintFields::AntiAliasState>(aliasIdx-1); |
| 1565 | fPaint.setAntiAlias(aliasIdx > 1); |
| 1566 | switch (fPaintOverrides.fAntiAlias) { |
| 1567 | case SkPaintFields::AntiAliasState::Alias: |
| 1568 | break; |
| 1569 | case SkPaintFields::AntiAliasState::Normal: |
| 1570 | break; |
| 1571 | case SkPaintFields::AntiAliasState::AnalyticAAEnabled: |
| 1572 | gSkUseAnalyticAA = true; |
| 1573 | gSkForceAnalyticAA = false; |
| 1574 | gSkUseDeltaAA = gSkForceDeltaAA = false; |
| 1575 | break; |
| 1576 | case SkPaintFields::AntiAliasState::AnalyticAAForced: |
| 1577 | gSkUseAnalyticAA = gSkForceAnalyticAA = true; |
| 1578 | gSkUseDeltaAA = gSkForceDeltaAA = false; |
| 1579 | break; |
| 1580 | case SkPaintFields::AntiAliasState::DeltaAAEnabled: |
| 1581 | gSkUseAnalyticAA = gSkForceAnalyticAA = false; |
| 1582 | gSkUseDeltaAA = true; |
| 1583 | gSkForceDeltaAA = false; |
| 1584 | break; |
| 1585 | case SkPaintFields::AntiAliasState::DeltaAAForced: |
| 1586 | gSkUseAnalyticAA = gSkForceAnalyticAA = false; |
| 1587 | gSkUseDeltaAA = gSkForceDeltaAA = true; |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | paramsChanged = true; |
| 1592 | } |
| 1593 | |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1594 | auto paintFlag = [this, ¶msChanged](const char* label, const char* items, |
| 1595 | SkPaint::Flags flag, |
| 1596 | bool (SkPaint::* isFlag)() const, |
| 1597 | void (SkPaint::* setFlag)(bool) ) |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 1598 | { |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1599 | int itemIndex = 0; |
| 1600 | if (fPaintOverrides.fFlags & flag) { |
| 1601 | itemIndex = (fPaint.*isFlag)() ? 2 : 1; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 1602 | } |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1603 | if (ImGui::Combo(label, &itemIndex, items)) { |
| 1604 | if (itemIndex == 0) { |
| 1605 | fPaintOverrides.fFlags &= ~flag; |
| 1606 | } else { |
| 1607 | fPaintOverrides.fFlags |= flag; |
| 1608 | (fPaint.*setFlag)(itemIndex == 2); |
| 1609 | } |
| 1610 | paramsChanged = true; |
| 1611 | } |
| 1612 | }; |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 1613 | |
Ben Wagner | 99a78dc | 2018-05-09 18:23:51 -0400 | [diff] [blame] | 1614 | paintFlag("Dither", |
| 1615 | "Default\0No Dither\0Dither\0\0", |
| 1616 | SkPaint::kDither_Flag, |
| 1617 | &SkPaint::isDither, &SkPaint::setDither); |
| 1618 | |
| 1619 | paintFlag("Fake Bold Glyphs", |
| 1620 | "Default\0No Fake Bold\0Fake Bold\0\0", |
| 1621 | SkPaint::kFakeBoldText_Flag, |
| 1622 | &SkPaint::isFakeBoldText, &SkPaint::setFakeBoldText); |
| 1623 | |
| 1624 | paintFlag("Linear Text", |
| 1625 | "Default\0No Linear Text\0Linear Text\0\0", |
| 1626 | SkPaint::kLinearText_Flag, |
| 1627 | &SkPaint::isLinearText, &SkPaint::setLinearText); |
| 1628 | |
| 1629 | paintFlag("Subpixel Position Glyphs", |
| 1630 | "Default\0Pixel Text\0Subpixel Text\0\0", |
| 1631 | SkPaint::kSubpixelText_Flag, |
| 1632 | &SkPaint::isSubpixelText, &SkPaint::setSubpixelText); |
| 1633 | |
| 1634 | paintFlag("Subpixel Anti-Alias", |
| 1635 | "Default\0lcd\0LCD\0\0", |
| 1636 | SkPaint::kLCDRenderText_Flag, |
| 1637 | &SkPaint::isLCDRenderText, &SkPaint::setLCDRenderText); |
| 1638 | |
| 1639 | paintFlag("Embedded Bitmap Text", |
| 1640 | "Default\0No Embedded Bitmaps\0Embedded Bitmaps\0\0", |
| 1641 | SkPaint::kEmbeddedBitmapText_Flag, |
| 1642 | &SkPaint::isEmbeddedBitmapText, &SkPaint::setEmbeddedBitmapText); |
| 1643 | |
| 1644 | paintFlag("Force Auto-Hinting", |
| 1645 | "Default\0No Force Auto-Hinting\0Force Auto-Hinting\0\0", |
| 1646 | SkPaint::kAutoHinting_Flag, |
| 1647 | &SkPaint::isAutohinted, &SkPaint::setAutohinted); |
| 1648 | |
| 1649 | paintFlag("Vertical Text", |
| 1650 | "Default\0No Vertical Text\0Vertical Text\0\0", |
| 1651 | SkPaint::kVerticalText_Flag, |
| 1652 | &SkPaint::isVerticalText, &SkPaint::setVerticalText); |
Ben Wagner | d2ae4df | 2018-06-07 17:54:07 -0400 | [diff] [blame] | 1653 | |
| 1654 | ImGui::Checkbox("Override TextSize", &fPaintOverrides.fTextSize); |
| 1655 | if (fPaintOverrides.fTextSize) { |
| 1656 | ImGui::DragFloat2("TextRange", fPaintOverrides.fTextSizeRange, |
| 1657 | 0.001f, -10.0f, 300.0f, "%.6f", 2.0f); |
| 1658 | float textSize = fPaint.getTextSize(); |
| 1659 | if (ImGui::DragFloat("TextSize", &textSize, 0.001f, |
| 1660 | fPaintOverrides.fTextSizeRange[0], |
| 1661 | fPaintOverrides.fTextSizeRange[1], |
| 1662 | "%.6f", 2.0f)) |
| 1663 | { |
| 1664 | fPaint.setTextSize(textSize); |
| 1665 | this->preTouchMatrixChanged(); |
| 1666 | paramsChanged = true; |
| 1667 | } |
| 1668 | } |
Ben Wagner | a580fb3 | 2018-04-17 11:16:32 -0400 | [diff] [blame] | 1669 | } |
| 1670 | |
Mike Reed | 81f60ec | 2018-05-15 10:09:52 -0400 | [diff] [blame] | 1671 | { |
| 1672 | SkMetaData controls; |
| 1673 | if (fSlides[fCurrentSlide]->onGetControls(&controls)) { |
| 1674 | if (ImGui::CollapsingHeader("Current Slide")) { |
| 1675 | SkMetaData::Iter iter(controls); |
| 1676 | const char* name; |
| 1677 | SkMetaData::Type type; |
| 1678 | int count; |
| 1679 | bool found = false; |
| 1680 | while ((name = iter.next(&type, &count)) != nullptr && found == false) { |
| 1681 | if (type == SkMetaData::kScalar_Type) { |
| 1682 | float val[3]; |
| 1683 | SkASSERT(count == 3); |
| 1684 | controls.findScalars(name, &count, val); |
| 1685 | if (ImGui::SliderFloat(name, &val[0], val[1], val[2])) { |
| 1686 | controls.setScalars(name, 3, val); |
| 1687 | fSlides[fCurrentSlide]->onSetControls(controls); |
| 1688 | found = paramsChanged = true; |
| 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | } |
| 1695 | |
Ben Wagner | 7a3c674 | 2018-04-23 10:01:07 -0400 | [diff] [blame] | 1696 | if (fShowSlidePicker) { |
| 1697 | ImGui::SetNextTreeNodeOpen(true); |
| 1698 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1699 | if (ImGui::CollapsingHeader("Slide")) { |
| 1700 | static ImGuiTextFilter filter; |
Brian Osman | f479e42 | 2017-11-08 13:11:36 -0500 | [diff] [blame] | 1701 | static ImVector<const char*> filteredSlideNames; |
| 1702 | static ImVector<int> filteredSlideIndices; |
| 1703 | |
Brian Osman | fce09c5 | 2017-11-14 15:32:20 -0500 | [diff] [blame] | 1704 | if (fShowSlidePicker) { |
| 1705 | ImGui::SetKeyboardFocusHere(); |
| 1706 | fShowSlidePicker = false; |
| 1707 | } |
| 1708 | |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1709 | filter.Draw(); |
Brian Osman | f479e42 | 2017-11-08 13:11:36 -0500 | [diff] [blame] | 1710 | filteredSlideNames.clear(); |
| 1711 | filteredSlideIndices.clear(); |
| 1712 | int filteredIndex = 0; |
| 1713 | for (int i = 0; i < fSlides.count(); ++i) { |
| 1714 | const char* slideName = fSlides[i]->getName().c_str(); |
| 1715 | if (filter.PassFilter(slideName) || i == fCurrentSlide) { |
| 1716 | if (i == fCurrentSlide) { |
| 1717 | filteredIndex = filteredSlideIndices.size(); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1718 | } |
Brian Osman | f479e42 | 2017-11-08 13:11:36 -0500 | [diff] [blame] | 1719 | filteredSlideNames.push_back(slideName); |
| 1720 | filteredSlideIndices.push_back(i); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1721 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1722 | } |
Brian Osman | f479e42 | 2017-11-08 13:11:36 -0500 | [diff] [blame] | 1723 | |
Brian Osman | f479e42 | 2017-11-08 13:11:36 -0500 | [diff] [blame] | 1724 | if (ImGui::ListBox("", &filteredIndex, filteredSlideNames.begin(), |
| 1725 | filteredSlideNames.size(), 20)) { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 1726 | this->setCurrentSlide(filteredSlideIndices[filteredIndex]); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1727 | } |
| 1728 | } |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1729 | |
| 1730 | if (ImGui::CollapsingHeader("Color Mode")) { |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 1731 | ColorMode newMode = fColorMode; |
| 1732 | auto cmButton = [&](ColorMode mode, const char* label) { |
| 1733 | if (ImGui::RadioButton(label, mode == fColorMode)) { |
| 1734 | newMode = mode; |
| 1735 | } |
| 1736 | }; |
| 1737 | |
| 1738 | cmButton(ColorMode::kLegacy, "Legacy 8888"); |
| 1739 | cmButton(ColorMode::kColorManagedSRGB8888_NonLinearBlending, |
| 1740 | "Color Managed 8888 (Nonlinear blending)"); |
| 1741 | cmButton(ColorMode::kColorManagedSRGB8888, "Color Managed 8888"); |
| 1742 | cmButton(ColorMode::kColorManagedLinearF16, "Color Managed F16"); |
| 1743 | |
| 1744 | if (newMode != fColorMode) { |
Brian Osman | fd8f4d5 | 2017-02-24 11:57:23 -0500 | [diff] [blame] | 1745 | // It isn't safe to switch color mode now (in the middle of painting). We might |
| 1746 | // tear down the back-end, etc... Defer this change until the next onIdle. |
| 1747 | fDeferredActions.push_back([=]() { |
Brian Osman | 9200480 | 2017-03-06 11:47:26 -0500 | [diff] [blame] | 1748 | this->setColorMode(newMode); |
Brian Osman | fd8f4d5 | 2017-02-24 11:57:23 -0500 | [diff] [blame] | 1749 | }); |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | // Pick from common gamuts: |
| 1753 | int primariesIdx = 4; // Default: Custom |
| 1754 | for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) { |
| 1755 | if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) { |
| 1756 | primariesIdx = i; |
| 1757 | break; |
| 1758 | } |
| 1759 | } |
| 1760 | |
Brian Osman | fdab576 | 2017-11-09 10:27:55 -0500 | [diff] [blame] | 1761 | // When we're in xform canvas mode, we can alter the transfer function, too |
| 1762 | if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) { |
| 1763 | ImGui::SliderFloat("Gamma", &fColorSpaceTransferFn.fG, 0.5f, 3.5f); |
| 1764 | } |
| 1765 | |
Brian Osman | a109e39 | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 1766 | if (ImGui::Combo("Primaries", &primariesIdx, |
| 1767 | "sRGB\0AdobeRGB\0P3\0Rec. 2020\0Custom\0\0")) { |
| 1768 | if (primariesIdx >= 0 && primariesIdx <= 3) { |
| 1769 | fColorSpacePrimaries = *gNamedPrimaries[primariesIdx].fPrimaries; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | // Allow direct editing of gamut |
| 1774 | ImGui_Primaries(&fColorSpacePrimaries, &fImGuiGamutPaint); |
| 1775 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1776 | } |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1777 | if (paramsChanged) { |
| 1778 | fDeferredActions.push_back([=]() { |
| 1779 | fWindow->setRequestedDisplayParams(params); |
| 1780 | fWindow->inval(); |
| 1781 | this->updateTitle(); |
| 1782 | }); |
| 1783 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1784 | ImGui::End(); |
| 1785 | } |
| 1786 | |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1787 | if (fShowZoomWindow && fLastImage) { |
Brian Osman | 7197e05 | 2018-06-29 14:30:48 -0400 | [diff] [blame] | 1788 | ImGui::SetNextWindowSize(ImVec2(200, 200), ImGuiCond_FirstUseEver); |
| 1789 | if (ImGui::Begin("Zoom", &fShowZoomWindow)) { |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1790 | static int zoomFactor = 8; |
| 1791 | if (ImGui::Button("<<")) { |
| 1792 | zoomFactor = SkTMax(zoomFactor / 2, 4); |
| 1793 | } |
| 1794 | ImGui::SameLine(); ImGui::Text("%2d", zoomFactor); ImGui::SameLine(); |
| 1795 | if (ImGui::Button(">>")) { |
| 1796 | zoomFactor = SkTMin(zoomFactor * 2, 32); |
| 1797 | } |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1798 | |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1799 | if (!fZoomWindowFixed) { |
| 1800 | ImVec2 mousePos = ImGui::GetMousePos(); |
| 1801 | fZoomWindowLocation = SkPoint::Make(mousePos.x, mousePos.y); |
| 1802 | } |
| 1803 | SkScalar x = fZoomWindowLocation.x(); |
| 1804 | SkScalar y = fZoomWindowLocation.y(); |
| 1805 | int xInt = SkScalarRoundToInt(x); |
| 1806 | int yInt = SkScalarRoundToInt(y); |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1807 | ImVec2 avail = ImGui::GetContentRegionAvail(); |
| 1808 | |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1809 | uint32_t pixel = 0; |
| 1810 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1811 | if (fLastImage->readPixels(info, &pixel, info.minRowBytes(), xInt, yInt)) { |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1812 | ImGui::SameLine(); |
Brian Osman | 07b56b2 | 2017-11-21 14:59:31 -0500 | [diff] [blame] | 1813 | ImGui::Text("(X, Y): %d, %d RGBA: %x %x %x %x", |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1814 | xInt, yInt, |
Brian Osman | 07b56b2 | 2017-11-21 14:59:31 -0500 | [diff] [blame] | 1815 | SkGetPackedR32(pixel), SkGetPackedG32(pixel), |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1816 | SkGetPackedB32(pixel), SkGetPackedA32(pixel)); |
| 1817 | } |
| 1818 | |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 1819 | fImGuiLayer.skiaWidget(avail, [=](SkCanvas* c) { |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1820 | // Translate so the region of the image that's under the mouse cursor is centered |
| 1821 | // in the zoom canvas: |
| 1822 | c->scale(zoomFactor, zoomFactor); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1823 | c->translate(avail.x * 0.5f / zoomFactor - x - 0.5f, |
| 1824 | avail.y * 0.5f / zoomFactor - y - 0.5f); |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1825 | c->drawImage(this->fLastImage, 0, 0); |
| 1826 | |
| 1827 | SkPaint outline; |
| 1828 | outline.setStyle(SkPaint::kStroke_Style); |
Ben Wagner | 3627d2e | 2018-06-26 14:23:20 -0400 | [diff] [blame] | 1829 | c->drawRect(SkRect::MakeXYWH(x, y, 1, 1), outline); |
Brian Osman | ead517d | 2017-11-13 15:36:36 -0500 | [diff] [blame] | 1830 | }); |
Brian Osman | f687709 | 2017-02-13 09:39:57 -0500 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | ImGui::End(); |
| 1834 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1835 | } |
| 1836 | |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 1837 | void Viewer::onIdle() { |
Brian Osman | fd8f4d5 | 2017-02-24 11:57:23 -0500 | [diff] [blame] | 1838 | for (int i = 0; i < fDeferredActions.count(); ++i) { |
| 1839 | fDeferredActions[i](); |
| 1840 | } |
| 1841 | fDeferredActions.reset(); |
| 1842 | |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1843 | fStatsLayer.beginTiming(fAnimateTimer); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 1844 | fAnimTimer.updateTime(); |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 1845 | bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1846 | fStatsLayer.endTiming(fAnimateTimer); |
Brian Osman | 1df161a | 2017-02-09 12:10:20 -0500 | [diff] [blame] | 1847 | |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 1848 | ImGuiIO& io = ImGui::GetIO(); |
Brian Osman | 56a2481 | 2017-12-19 11:15:16 -0500 | [diff] [blame] | 1849 | if (animateWantsInval || fStatsLayer.getActive() || fRefresh || io.MetricsActiveWindows) { |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 1850 | fWindow->inval(); |
| 1851 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 1852 | } |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1853 | |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1854 | template <typename OptionsFunc> |
| 1855 | static void WriteStateObject(SkJSONWriter& writer, const char* name, const char* value, |
| 1856 | OptionsFunc&& optionsFunc) { |
| 1857 | writer.beginObject(); |
| 1858 | { |
| 1859 | writer.appendString(kName , name); |
| 1860 | writer.appendString(kValue, value); |
| 1861 | |
| 1862 | writer.beginArray(kOptions); |
| 1863 | { |
| 1864 | optionsFunc(writer); |
| 1865 | } |
| 1866 | writer.endArray(); |
| 1867 | } |
| 1868 | writer.endObject(); |
| 1869 | } |
| 1870 | |
| 1871 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1872 | void Viewer::updateUIState() { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 1873 | if (!fWindow) { |
| 1874 | return; |
| 1875 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 1876 | if (fWindow->sampleCount() < 1) { |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 1877 | return; // Surface hasn't been created yet. |
| 1878 | } |
| 1879 | |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1880 | SkDynamicMemoryWStream memStream; |
| 1881 | SkJSONWriter writer(&memStream); |
| 1882 | writer.beginArray(); |
| 1883 | |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 1884 | // Slide state |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1885 | WriteStateObject(writer, kSlideStateName, fSlides[fCurrentSlide]->getName().c_str(), |
| 1886 | [this](SkJSONWriter& writer) { |
| 1887 | for(const auto& slide : fSlides) { |
| 1888 | writer.appendString(slide->getName().c_str()); |
| 1889 | } |
| 1890 | }); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1891 | |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 1892 | // Backend state |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1893 | WriteStateObject(writer, kBackendStateName, kBackendTypeStrings[fBackendType], |
| 1894 | [](SkJSONWriter& writer) { |
| 1895 | for (const auto& str : kBackendTypeStrings) { |
| 1896 | writer.appendString(str); |
| 1897 | } |
| 1898 | }); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1899 | |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 1900 | // MSAA state |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1901 | const auto countString = SkStringPrintf("%d", fWindow->sampleCount()); |
| 1902 | WriteStateObject(writer, kMSAAStateName, countString.c_str(), |
| 1903 | [this](SkJSONWriter& writer) { |
| 1904 | writer.appendS32(0); |
| 1905 | |
| 1906 | if (sk_app::Window::kRaster_BackendType == fBackendType) { |
| 1907 | return; |
| 1908 | } |
| 1909 | |
| 1910 | for (int msaa : {4, 8, 16}) { |
| 1911 | writer.appendS32(msaa); |
| 1912 | } |
| 1913 | }); |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 1914 | |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 1915 | // Path renderer state |
| 1916 | GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers; |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1917 | WriteStateObject(writer, kPathRendererStateName, gPathRendererNames[pr].c_str(), |
| 1918 | [this](SkJSONWriter& writer) { |
| 1919 | const GrContext* ctx = fWindow->getGrContext(); |
| 1920 | if (!ctx) { |
| 1921 | writer.appendString("Software"); |
| 1922 | } else { |
| 1923 | const auto* caps = ctx->contextPriv().caps(); |
| 1924 | |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1925 | writer.appendString(gPathRendererNames[GpuPathRenderers::kAll].c_str()); |
| 1926 | if (fWindow->sampleCount() > 1) { |
| 1927 | if (caps->shaderCaps()->pathRenderingSupport()) { |
| 1928 | writer.appendString( |
| 1929 | gPathRendererNames[GpuPathRenderers::kStencilAndCover].c_str()); |
| 1930 | } |
| 1931 | } else { |
| 1932 | if(GrCoverageCountingPathRenderer::IsSupported(*caps)) { |
| 1933 | writer.appendString( |
| 1934 | gPathRendererNames[GpuPathRenderers::kCoverageCounting].c_str()); |
| 1935 | } |
| 1936 | writer.appendString(gPathRendererNames[GpuPathRenderers::kSmall].c_str()); |
| 1937 | } |
| 1938 | writer.appendString( |
| 1939 | gPathRendererNames[GpuPathRenderers::kTessellating].c_str()); |
| 1940 | writer.appendString(gPathRendererNames[GpuPathRenderers::kNone].c_str()); |
| 1941 | } |
| 1942 | }); |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 1943 | |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 1944 | // Softkey state |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1945 | WriteStateObject(writer, kSoftkeyStateName, kSoftkeyHint, |
| 1946 | [this](SkJSONWriter& writer) { |
| 1947 | writer.appendString(kSoftkeyHint); |
| 1948 | for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) { |
| 1949 | writer.appendString(softkey.c_str()); |
| 1950 | } |
| 1951 | }); |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 1952 | |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1953 | writer.endArray(); |
| 1954 | writer.flush(); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1955 | |
Florin Malita | b632df7 | 2018-06-18 21:23:06 -0400 | [diff] [blame] | 1956 | auto data = memStream.detachAsData(); |
| 1957 | |
| 1958 | // TODO: would be cool to avoid this copy |
| 1959 | const SkString cstring(static_cast<const char*>(data->data()), data->size()); |
| 1960 | |
| 1961 | fWindow->setUIState(cstring.c_str()); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateValue) { |
liyuqian | 6cb7025 | 2016-06-02 12:16:25 -0700 | [diff] [blame] | 1965 | // For those who will add more features to handle the state change in this function: |
| 1966 | // After the change, please call updateUIState no notify the frontend (e.g., Android app). |
| 1967 | // For example, after slide change, updateUIState is called inside setupCurrentSlide; |
| 1968 | // after backend change, updateUIState is called in this function. |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1969 | if (stateName.equals(kSlideStateName)) { |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 1970 | for (int i = 0; i < fSlides.count(); ++i) { |
| 1971 | if (fSlides[i]->getName().equals(stateValue)) { |
| 1972 | this->setCurrentSlide(i); |
| 1973 | return; |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1974 | } |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 1975 | } |
Florin Malita | ab99c34 | 2018-01-16 16:23:03 -0500 | [diff] [blame] | 1976 | |
| 1977 | SkDebugf("Slide not found: %s", stateValue.c_str()); |
liyuqian | 6cb7025 | 2016-06-02 12:16:25 -0700 | [diff] [blame] | 1978 | } else if (stateName.equals(kBackendStateName)) { |
| 1979 | for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) { |
| 1980 | if (stateValue.equals(kBackendTypeStrings[i])) { |
| 1981 | if (fBackendType != i) { |
| 1982 | fBackendType = (sk_app::Window::BackendType)i; |
| 1983 | fWindow->detach(); |
Brian Osman | 70d2f43 | 2017-11-08 09:54:10 -0500 | [diff] [blame] | 1984 | fWindow->attach(backend_type_for_window(fBackendType)); |
liyuqian | 6cb7025 | 2016-06-02 12:16:25 -0700 | [diff] [blame] | 1985 | } |
| 1986 | break; |
| 1987 | } |
| 1988 | } |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 1989 | } else if (stateName.equals(kMSAAStateName)) { |
| 1990 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 1991 | int sampleCount = atoi(stateValue.c_str()); |
| 1992 | if (sampleCount != params.fMSAASampleCount) { |
| 1993 | params.fMSAASampleCount = sampleCount; |
| 1994 | fWindow->setRequestedDisplayParams(params); |
| 1995 | fWindow->inval(); |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 1996 | this->updateTitle(); |
| 1997 | this->updateUIState(); |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 1998 | } |
| 1999 | } else if (stateName.equals(kPathRendererStateName)) { |
| 2000 | DisplayParams params = fWindow->getRequestedDisplayParams(); |
| 2001 | for (const auto& pair : gPathRendererNames) { |
| 2002 | if (pair.second == stateValue.c_str()) { |
| 2003 | if (params.fGrContextOptions.fGpuPathRenderers != pair.first) { |
| 2004 | params.fGrContextOptions.fGpuPathRenderers = pair.first; |
| 2005 | fWindow->setRequestedDisplayParams(params); |
| 2006 | fWindow->inval(); |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 2007 | this->updateTitle(); |
| 2008 | this->updateUIState(); |
csmartdalton | 61cd31a | 2017-02-27 17:00:53 -0700 | [diff] [blame] | 2009 | } |
| 2010 | break; |
| 2011 | } |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 2012 | } |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 2013 | } else if (stateName.equals(kSoftkeyStateName)) { |
| 2014 | if (!stateValue.equals(kSoftkeyHint)) { |
| 2015 | fCommands.onSoftkey(stateValue); |
Brian Salomon | 99a3390 | 2017-03-07 15:16:34 -0500 | [diff] [blame] | 2016 | this->updateUIState(); // This is still needed to reset the value to kSoftkeyHint |
liyuqian | b73c24b | 2016-06-03 08:47:23 -0700 | [diff] [blame] | 2017 | } |
liyuqian | 2edb0f4 | 2016-07-06 14:11:32 -0700 | [diff] [blame] | 2018 | } else if (stateName.equals(kRefreshStateName)) { |
| 2019 | // This state is actually NOT in the UI state. |
| 2020 | // We use this to allow Android to quickly set bool fRefresh. |
| 2021 | fRefresh = stateValue.equals(kON); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 2022 | } else { |
| 2023 | SkDebugf("Unknown stateName: %s", stateName.c_str()); |
| 2024 | } |
| 2025 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 2026 | |
| 2027 | bool Viewer::onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) { |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 2028 | return fCommands.onKey(key, state, modifiers); |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | bool Viewer::onChar(SkUnichar c, uint32_t modifiers) { |
Brian Osman | d67e518 | 2017-12-08 16:46:09 -0500 | [diff] [blame] | 2032 | if (fSlides[fCurrentSlide]->onChar(c)) { |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 2033 | fWindow->inval(); |
| 2034 | return true; |
Brian Osman | 80fc07e | 2017-12-08 16:45:43 -0500 | [diff] [blame] | 2035 | } else { |
| 2036 | return fCommands.onChar(c, modifiers); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 2037 | } |
Brian Osman | 79086b9 | 2017-02-10 13:36:16 -0500 | [diff] [blame] | 2038 | } |