epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 7 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 8 | #include "SampleApp.h" |
| 9 | |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 10 | #include "OverView.h" |
caryclark | f568f6a | 2014-07-18 10:58:56 -0700 | [diff] [blame] | 11 | #include "Resources.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 12 | #include "SampleCode.h" |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 13 | #include "SkAnimTimer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkCanvas.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 15 | #include "SkCommandLineFlags.h" |
| 16 | #include "SkData.h" |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 17 | #include "SkDocument.h" |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 18 | #include "SkGammaColorFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 20 | #include "SkImage_Base.h" |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 21 | #include "SkImageEncoder.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 22 | #include "SkOSFile.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #include "SkPaint.h" |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 24 | #include "SkPaintFilterCanvas.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 26 | #include "SkPictureRecorder.h" |
brianosman | 36db3f4 | 2016-04-20 09:20:46 -0700 | [diff] [blame] | 27 | #include "SkPM4fPriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | #include "SkStream.h" |
commit-bot@chromium.org | 9a558d4 | 2014-05-30 15:06:24 +0000 | [diff] [blame] | 29 | #include "SkSurface.h" |
scroggo | 565901d | 2015-12-10 10:44:13 -0800 | [diff] [blame] | 30 | #include "SkTemplates.h" |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 31 | #include "SkTSort.h" |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 32 | #include "SkTime.h" |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 33 | #include "SkTypeface.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 34 | #include "SkWindow.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 35 | #include "sk_tool_utils.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 36 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 37 | #include "SkReadBuffer.h" |
| 38 | #include "SkStream.h" |
| 39 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 40 | #if SK_SUPPORT_GPU |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 41 | # include "gl/GrGLInterface.h" |
| 42 | # include "gl/GrGLUtil.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 43 | # include "GrContext.h" |
robertphillips | 7715e06 | 2016-04-22 10:57:16 -0700 | [diff] [blame] | 44 | # include "SkGr.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 45 | # if SK_ANGLE |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 46 | # include "gl/angle/GLTestContext_angle.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 47 | # endif |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 48 | #else |
| 49 | class GrContext; |
| 50 | #endif |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 51 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 52 | const struct { |
| 53 | SkColorType fColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 54 | bool fSRGB; |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 55 | const char* fName; |
| 56 | } gConfig[] = { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 57 | { kN32_SkColorType, false, "L32" }, |
| 58 | { kN32_SkColorType, true, "S32" }, |
brianosman | efded51 | 2016-07-26 08:11:50 -0700 | [diff] [blame] | 59 | { kRGBA_F16_SkColorType, true, "F16" }, |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static const char* find_config_name(const SkImageInfo& info) { |
| 63 | for (const auto& config : gConfig) { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 64 | if (config.fColorType == info.colorType() && |
| 65 | config.fSRGB == (info.colorSpace() != nullptr)) { |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 66 | return config.fName; |
| 67 | } |
| 68 | } |
| 69 | return "???"; |
| 70 | } |
| 71 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 72 | // Should be 3x + 1 |
| 73 | #define kMaxFatBitsScale 28 |
| 74 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 75 | extern SampleView* CreateSamplePictFileView(const char filename[]); |
| 76 | |
| 77 | class PictFileFactory : public SkViewFactory { |
| 78 | SkString fFilename; |
| 79 | public: |
| 80 | PictFileFactory(const SkString& filename) : fFilename(filename) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 81 | SkView* operator() () const override { |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 82 | return CreateSamplePictFileView(fFilename.c_str()); |
| 83 | } |
| 84 | }; |
| 85 | |
fmalita | 851d68a | 2016-08-15 07:48:47 -0700 | [diff] [blame] | 86 | extern SampleView* CreateSampleSVGFileView(const SkString& filename); |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 87 | |
| 88 | class SVGFileFactory : public SkViewFactory { |
| 89 | SkString fFilename; |
| 90 | public: |
| 91 | SVGFileFactory(const SkString& filename) : fFilename(filename) {} |
| 92 | SkView* operator() () const override { |
fmalita | 851d68a | 2016-08-15 07:48:47 -0700 | [diff] [blame] | 93 | return CreateSampleSVGFileView(fFilename); |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 94 | } |
| 95 | }; |
| 96 | |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 97 | #ifdef SAMPLE_PDF_FILE_VIEWER |
| 98 | extern SampleView* CreateSamplePdfFileViewer(const char filename[]); |
| 99 | |
| 100 | class PdfFileViewerFactory : public SkViewFactory { |
| 101 | SkString fFilename; |
| 102 | public: |
| 103 | PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 104 | SkView* operator() () const override { |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 105 | return CreateSamplePdfFileViewer(fFilename.c_str()); |
| 106 | } |
| 107 | }; |
| 108 | #endif // SAMPLE_PDF_FILE_VIEWER |
| 109 | |
bsalomon | 4999616 | 2016-06-14 09:43:52 -0700 | [diff] [blame] | 110 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 111 | //#define DEFAULT_TO_ANGLE 1 |
| 112 | #else |
bsalomon@google.com | 82d1223 | 2013-09-09 15:36:26 +0000 | [diff] [blame] | 113 | #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 114 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 115 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | #define ANIMATING_EVENTTYPE "nextSample" |
reed@google.com | 84cfce1 | 2013-05-29 19:22:20 +0000 | [diff] [blame] | 117 | #define ANIMATING_DELAY 250 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 118 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 119 | #ifdef SK_DEBUG |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 120 | #define FPS_REPEAT_MULTIPLIER 1 |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 121 | #else |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 122 | #define FPS_REPEAT_MULTIPLIER 10 |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 123 | #endif |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 124 | #define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER) |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 125 | |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 126 | static SampleWindow* gSampleWindow; |
| 127 | |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 128 | static bool gShowGMBounds; |
| 129 | |
commit-bot@chromium.org | 6de4a78 | 2013-12-11 17:05:23 +0000 | [diff] [blame] | 130 | static void post_event_to_sink(SkEvent* evt, SkEventSink* sink) { |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 131 | evt->setTargetID(sink->getSinkID())->post(); |
| 132 | } |
| 133 | |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 134 | static SkAnimTimer gAnimTimer; |
| 135 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 136 | /////////////////////////////////////////////////////////////////////////////// |
| 137 | |
| 138 | static const char* skip_until(const char* str, const char* skip) { |
| 139 | if (!str) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 140 | return nullptr; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 141 | } |
| 142 | return strstr(str, skip); |
| 143 | } |
| 144 | |
| 145 | static const char* skip_past(const char* str, const char* skip) { |
| 146 | const char* found = skip_until(str, skip); |
| 147 | if (!found) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 148 | return nullptr; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 149 | } |
| 150 | return found + strlen(skip); |
| 151 | } |
| 152 | |
| 153 | static const char* gPrefFileName = "sampleapp_prefs.txt"; |
| 154 | |
epoger@google.com | 6fc7cc2 | 2011-12-28 15:13:41 +0000 | [diff] [blame] | 155 | static bool readTitleFromPrefs(SkString* title) { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 156 | SkFILEStream stream(gPrefFileName); |
| 157 | if (!stream.isValid()) { |
| 158 | return false; |
| 159 | } |
| 160 | |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 161 | size_t len = stream.getLength(); |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 162 | SkString data(len); |
| 163 | stream.read(data.writable_str(), len); |
| 164 | const char* s = data.c_str(); |
| 165 | |
| 166 | s = skip_past(s, "curr-slide-title"); |
| 167 | s = skip_past(s, "="); |
| 168 | s = skip_past(s, "\""); |
| 169 | const char* stop = skip_until(s, "\""); |
| 170 | if (stop > s) { |
| 171 | title->set(s, stop - s); |
| 172 | return true; |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
epoger@google.com | 6fc7cc2 | 2011-12-28 15:13:41 +0000 | [diff] [blame] | 177 | static void writeTitleToPrefs(const char* title) { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 178 | SkFILEWStream stream(gPrefFileName); |
| 179 | SkString data; |
| 180 | data.printf("curr-slide-title = \"%s\"\n", title); |
| 181 | stream.write(data.c_str(), data.size()); |
| 182 | } |
| 183 | |
| 184 | /////////////////////////////////////////////////////////////////////////////// |
| 185 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 186 | class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager { |
| 187 | public: |
| 188 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 189 | DefaultDeviceManager() { |
| 190 | #if SK_SUPPORT_GPU |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 191 | fCurContext = nullptr; |
| 192 | fCurIntf = nullptr; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 193 | fMSAASampleCount = 0; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 194 | fDeepColor = false; |
| 195 | fActualColorBits = 0; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 196 | #endif |
| 197 | fBackend = kNone_BackEndType; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | virtual ~DefaultDeviceManager() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 201 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 202 | SkSafeUnref(fCurContext); |
| 203 | SkSafeUnref(fCurIntf); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 204 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 205 | } |
| 206 | |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 207 | void setUpBackend(SampleWindow* win, int msaaSampleCount, bool deepColor) override { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 208 | SkASSERT(kNone_BackEndType == fBackend); |
robertphillips@google.com | 53e96a1 | 2012-03-30 14:47:53 +0000 | [diff] [blame] | 209 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 210 | fBackend = kNone_BackEndType; |
| 211 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 212 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 213 | switch (win->getDeviceType()) { |
reed | beedb81 | 2015-05-05 12:14:45 -0700 | [diff] [blame] | 214 | case kRaster_DeviceType: // fallthrough |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 215 | case kGPU_DeviceType: |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 216 | // all these guys use the native backend |
| 217 | fBackend = kNativeGL_BackEndType; |
| 218 | break; |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 219 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 220 | case kANGLE_DeviceType: |
| 221 | // ANGLE is really the only odd man out |
| 222 | fBackend = kANGLE_BackEndType; |
| 223 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 224 | #endif // SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 225 | default: |
| 226 | SkASSERT(false); |
| 227 | break; |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 228 | } |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 229 | AttachmentInfo attachmentInfo; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 230 | bool result = win->attach(fBackend, msaaSampleCount, deepColor, &attachmentInfo); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 231 | if (!result) { |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 232 | SkDebugf("Failed to initialize GL"); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 233 | return; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 234 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 235 | fMSAASampleCount = msaaSampleCount; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 236 | fDeepColor = deepColor; |
| 237 | // Assume that we have at least 24-bit output, for backends that don't supply this data |
| 238 | fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 239 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 240 | SkASSERT(nullptr == fCurIntf); |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 241 | SkAutoTUnref<const GrGLInterface> glInterface; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 242 | switch (win->getDeviceType()) { |
reed | beedb81 | 2015-05-05 12:14:45 -0700 | [diff] [blame] | 243 | case kRaster_DeviceType: // fallthrough |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 244 | case kGPU_DeviceType: |
| 245 | // all these guys use the native interface |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 246 | glInterface.reset(GrGLCreateNativeInterface()); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 247 | break; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 248 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 249 | case kANGLE_DeviceType: |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 250 | glInterface.reset(sk_gpu_test::CreateANGLEGLInterface()); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 251 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 252 | #endif // SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 253 | default: |
| 254 | SkASSERT(false); |
| 255 | break; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 256 | } |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 257 | |
commit-bot@chromium.org | d8ed851 | 2014-01-24 20:49:44 +0000 | [diff] [blame] | 258 | // Currently SampleApp does not use NVPR. TODO: Provide an NVPR device type that is skipped |
| 259 | // when the driver doesn't support NVPR. |
| 260 | fCurIntf = GrGLInterfaceRemoveNVPR(glInterface.get()); |
| 261 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 262 | SkASSERT(nullptr == fCurContext); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 263 | fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 264 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 265 | if (nullptr == fCurContext || nullptr == fCurIntf) { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 266 | // We need some context and interface to see results |
| 267 | SkSafeUnref(fCurContext); |
| 268 | SkSafeUnref(fCurIntf); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 269 | fCurContext = nullptr; |
| 270 | fCurIntf = nullptr; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 271 | SkDebugf("Failed to setup 3D"); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 272 | |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 273 | win->release(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 274 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 275 | #endif // SK_SUPPORT_GPU |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 276 | // call windowSizeChanged to create the gpu-backed Surface |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 277 | this->windowSizeChanged(win); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 278 | } |
| 279 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 280 | void tearDownBackend(SampleWindow *win) override { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 281 | #if SK_SUPPORT_GPU |
reed | 789e327 | 2014-10-30 11:29:08 -0700 | [diff] [blame] | 282 | if (fCurContext) { |
| 283 | // in case we have outstanding refs to this guy (lua?) |
| 284 | fCurContext->abandonContext(); |
| 285 | fCurContext->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 286 | fCurContext = nullptr; |
reed | 789e327 | 2014-10-30 11:29:08 -0700 | [diff] [blame] | 287 | } |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 288 | |
| 289 | SkSafeUnref(fCurIntf); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 290 | fCurIntf = nullptr; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 291 | |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 292 | fGpuSurface = nullptr; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 293 | #endif |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 294 | win->release(); |
bsalomon@google.com | ddd40e5 | 2012-04-10 15:56:29 +0000 | [diff] [blame] | 295 | fBackend = kNone_BackEndType; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 296 | } |
| 297 | |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 298 | sk_sp<SkSurface> makeSurface(SampleWindow::DeviceType dType, SampleWindow* win) override { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 299 | #if SK_SUPPORT_GPU |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 300 | if (IsGpuDeviceType(dType) && fCurContext) { |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 301 | SkSurfaceProps props(win->getSurfaceProps()); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 302 | if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColorBits > 24) { |
| 303 | // If we're rendering to F16, we need an off-screen surface - the current render |
| 304 | // target is most likely the wrong format. |
| 305 | // |
| 306 | // If we're using a deep (10-bit or higher) surface, we probably need an off-screen |
| 307 | // surface. 10-bit, in particular, has strange gamma behavior. |
brianosman | 6b08652 | 2016-04-14 12:39:00 -0700 | [diff] [blame] | 308 | return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(), |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 309 | fMSAASampleCount, &props); |
brianosman | 6b08652 | 2016-04-14 12:39:00 -0700 | [diff] [blame] | 310 | } else { |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 311 | return fGpuSurface; |
brianosman | 6b08652 | 2016-04-14 12:39:00 -0700 | [diff] [blame] | 312 | } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 313 | } |
reed | 0397e9f | 2014-09-18 11:29:01 -0700 | [diff] [blame] | 314 | #endif |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 315 | return nullptr; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 316 | } |
| 317 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 318 | void publishCanvas(SampleWindow::DeviceType dType, |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 319 | SkCanvas* renderingCanvas, SampleWindow* win) override { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 320 | #if SK_SUPPORT_GPU |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 321 | if (!IsGpuDeviceType(dType) || |
| 322 | kRGBA_F16_SkColorType == win->info().colorType() || |
| 323 | fActualColorBits > 24) { |
| 324 | // We made/have an off-screen surface. Get the contents as an SkImage: |
| 325 | SkBitmap bm; |
| 326 | bm.allocPixels(win->info()); |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 327 | renderingCanvas->readPixels(&bm, 0, 0); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 328 | SkPixmap pm; |
| 329 | bm.peekPixels(&pm); |
| 330 | sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm, |
| 331 | SkBudgeted::kNo)); |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 332 | |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 333 | SkCanvas* gpuCanvas = fGpuSurface->getCanvas(); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 334 | |
| 335 | // With ten-bit output, we need to manually apply the gamma of the output device |
| 336 | // (unless we're in non-gamma correct mode, in which case our data is already |
| 337 | // fake-sRGB, like we're expected to put in the 10-bit buffer): |
| 338 | bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect(win->info()); |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 339 | |
| 340 | SkPaint gammaPaint; |
| 341 | gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 342 | if (doGamma) { |
| 343 | gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f)); |
| 344 | } |
| 345 | |
| 346 | gpuCanvas->drawImage(image, 0, 0, &gammaPaint); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 347 | } |
robertphillips | 1e87618 | 2016-07-29 08:28:25 -0700 | [diff] [blame] | 348 | |
| 349 | fGpuSurface->prepareForExternalIO(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 350 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 351 | |
| 352 | win->present(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 353 | } |
| 354 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 355 | void windowSizeChanged(SampleWindow* win) override { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 356 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 357 | if (fCurContext) { |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 358 | AttachmentInfo attachmentInfo; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 359 | win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 360 | fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24); |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 361 | fGpuSurface = win->makeGpuBackedSurface(attachmentInfo, fCurIntf, fCurContext); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 362 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 363 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 364 | } |
| 365 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 366 | GrContext* getGrContext() override { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 367 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 368 | return fCurContext; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 369 | #else |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 370 | return nullptr; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 371 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 372 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 373 | |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 374 | int numColorSamples() const override { |
brianosman | 1dfec74 | 2016-09-15 07:19:53 -0700 | [diff] [blame] | 375 | #if SK_SUPPORT_GPU |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 376 | return fMSAASampleCount; |
brianosman | 1dfec74 | 2016-09-15 07:19:53 -0700 | [diff] [blame] | 377 | #else |
| 378 | return 0; |
| 379 | #endif |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 380 | } |
| 381 | |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 382 | int getColorBits() override { |
| 383 | #if SK_SUPPORT_GPU |
| 384 | return fActualColorBits; |
| 385 | #else |
| 386 | return 24; |
| 387 | #endif |
| 388 | } |
| 389 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 390 | private: |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 391 | |
| 392 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 393 | GrContext* fCurContext; |
| 394 | const GrGLInterface* fCurIntf; |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 395 | sk_sp<SkSurface> fGpuSurface; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 396 | int fMSAASampleCount; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 397 | bool fDeepColor; |
| 398 | int fActualColorBits; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 399 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 400 | |
| 401 | SkOSWindow::SkBackEndTypes fBackend; |
| 402 | |
| 403 | typedef SampleWindow::DeviceManager INHERITED; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | /////////////// |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 407 | static const char view_inval_msg[] = "view-inval-msg"; |
| 408 | |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 409 | void SampleWindow::postInvalDelay() { |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 410 | (new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static bool isInvalEvent(const SkEvent& evt) { |
| 414 | return evt.isType(view_inval_msg); |
| 415 | } |
| 416 | ////////////////// |
| 417 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 418 | #include "GMSampleView.h" |
| 419 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 420 | class AutoUnrefArray { |
| 421 | public: |
| 422 | AutoUnrefArray() {} |
| 423 | ~AutoUnrefArray() { |
| 424 | int count = fObjs.count(); |
| 425 | for (int i = 0; i < count; ++i) { |
| 426 | fObjs[i]->unref(); |
| 427 | } |
| 428 | } |
| 429 | SkRefCnt*& push_back() { return *fObjs.append(); } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 430 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 431 | private: |
| 432 | SkTDArray<SkRefCnt*> fObjs; |
| 433 | }; |
| 434 | |
| 435 | // registers GMs as Samples |
| 436 | // This can't be performed during static initialization because it could be |
| 437 | // run before GMRegistry has been fully built. |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 438 | static void SkGMRegistyToSampleRegistry() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 439 | static bool gOnce; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 440 | static AutoUnrefArray fRegisters; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 441 | |
| 442 | if (!gOnce) { |
| 443 | const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head(); |
| 444 | while (gmreg) { |
| 445 | fRegisters.push_back() = new SkViewRegister(gmreg->factory()); |
| 446 | gmreg = gmreg->next(); |
| 447 | } |
| 448 | gOnce = true; |
| 449 | } |
| 450 | } |
| 451 | |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 452 | ////////////////////////////////////////////////////////////////////////////// |
| 453 | |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 454 | enum FlipAxisEnum { |
| 455 | kFlipAxis_X = (1 << 0), |
| 456 | kFlipAxis_Y = (1 << 1) |
| 457 | }; |
| 458 | |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 459 | #include "SkDrawFilter.h" |
| 460 | |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 461 | struct HintingState { |
| 462 | SkPaint::Hinting hinting; |
| 463 | const char* name; |
| 464 | const char* label; |
| 465 | }; |
| 466 | static HintingState gHintingStates[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 467 | {SkPaint::kNo_Hinting, "Mixed", nullptr }, |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 468 | {SkPaint::kNo_Hinting, "None", "H0 " }, |
| 469 | {SkPaint::kSlight_Hinting, "Slight", "Hs " }, |
| 470 | {SkPaint::kNormal_Hinting, "Normal", "Hn " }, |
| 471 | {SkPaint::kFull_Hinting, "Full", "Hf " }, |
| 472 | }; |
| 473 | |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 474 | struct PixelGeometryState { |
| 475 | SkPixelGeometry pixelGeometry; |
| 476 | const char* name; |
| 477 | const char* label; |
| 478 | }; |
| 479 | static PixelGeometryState gPixelGeometryStates[] = { |
| 480 | {SkPixelGeometry::kUnknown_SkPixelGeometry, "Mixed", nullptr }, |
| 481 | {SkPixelGeometry::kUnknown_SkPixelGeometry, "Flat", "{Flat} " }, |
| 482 | {SkPixelGeometry::kRGB_H_SkPixelGeometry, "RGB H", "{RGB H} " }, |
| 483 | {SkPixelGeometry::kBGR_H_SkPixelGeometry, "BGR H", "{BGR H} " }, |
| 484 | {SkPixelGeometry::kRGB_V_SkPixelGeometry, "RGB_V", "{RGB V} " }, |
| 485 | {SkPixelGeometry::kBGR_V_SkPixelGeometry, "BGR_V", "{BGR V} " }, |
| 486 | }; |
| 487 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 488 | struct FilterQualityState { |
| 489 | SkFilterQuality fQuality; |
| 490 | const char* fName; |
| 491 | const char* fLabel; |
reed@google.com | 15bc13d | 2013-12-10 16:53:13 +0000 | [diff] [blame] | 492 | }; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 493 | static FilterQualityState gFilterQualityStates[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 494 | { kNone_SkFilterQuality, "Mixed", nullptr }, |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 495 | { kNone_SkFilterQuality, "None", "F0 " }, |
| 496 | { kLow_SkFilterQuality, "Low", "F1 " }, |
| 497 | { kMedium_SkFilterQuality, "Medium", "F2 " }, |
| 498 | { kHigh_SkFilterQuality, "High", "F3 " }, |
reed@google.com | 15bc13d | 2013-12-10 16:53:13 +0000 | [diff] [blame] | 499 | }; |
| 500 | |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 501 | class FlagsFilterCanvas : public SkPaintFilterCanvas { |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 502 | public: |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 503 | FlagsFilterCanvas(SkCanvas* canvas, SkOSMenu::TriState lcd, SkOSMenu::TriState aa, |
| 504 | SkOSMenu::TriState subpixel, int hinting, int filterQuality) |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 505 | : INHERITED(canvas) |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 506 | , fLCDState(lcd) |
reed@google.com | 15bc13d | 2013-12-10 16:53:13 +0000 | [diff] [blame] | 507 | , fAAState(aa) |
| 508 | , fSubpixelState(subpixel) |
| 509 | , fHintingState(hinting) |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 510 | , fFilterQualityIndex(filterQuality) { |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 511 | SkASSERT((unsigned)filterQuality < SK_ARRAY_COUNT(gFilterQualityStates)); |
reed@google.com | 15bc13d | 2013-12-10 16:53:13 +0000 | [diff] [blame] | 512 | } |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 513 | |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 514 | protected: |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 515 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type t) const override { |
| 516 | if (!*paint) { |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 517 | return true; |
| 518 | } |
| 519 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 520 | if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 521 | paint->writable()->setLCDRenderText(SkOSMenu::kOnState == fLCDState); |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 522 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 523 | if (SkOSMenu::kMixedState != fAAState) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 524 | paint->writable()->setAntiAlias(SkOSMenu::kOnState == fAAState); |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 525 | } |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 526 | if (0 != fFilterQualityIndex) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 527 | paint->writable()->setFilterQuality(gFilterQualityStates[fFilterQualityIndex].fQuality); |
reed@google.com | 176753a | 2011-05-17 15:32:04 +0000 | [diff] [blame] | 528 | } |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 529 | if (SkOSMenu::kMixedState != fSubpixelState) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 530 | paint->writable()->setSubpixelText(SkOSMenu::kOnState == fSubpixelState); |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 531 | } |
bungeman@google.com | 055aa52 | 2013-06-03 21:35:03 +0000 | [diff] [blame] | 532 | if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) { |
fmalita | 32cdc32 | 2016-01-12 07:21:11 -0800 | [diff] [blame] | 533 | paint->writable()->setHinting(gHintingStates[fHintingState].hinting); |
reed@google.com | 09e3baa | 2011-05-18 12:04:31 +0000 | [diff] [blame] | 534 | } |
fmalita | bad23dc | 2016-01-11 13:58:29 -0800 | [diff] [blame] | 535 | return true; |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | private: |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 539 | SkOSMenu::TriState fLCDState; |
| 540 | SkOSMenu::TriState fAAState; |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 541 | SkOSMenu::TriState fSubpixelState; |
| 542 | int fHintingState; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 543 | int fFilterQualityIndex; |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 544 | |
| 545 | typedef SkPaintFilterCanvas INHERITED; |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 546 | }; |
| 547 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 548 | /////////////////////////////////////////////////////////////////////////////// |
| 549 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 550 | class SampleTFSerializer : public SkTypefaceSerializer { |
| 551 | public: |
| 552 | sk_sp<SkData> serialize(SkTypeface* tf) override { |
| 553 | tf->ref(); |
| 554 | return SkData::MakeWithCopy(&tf, sizeof(tf)); |
| 555 | } |
| 556 | }; |
| 557 | |
| 558 | class SampleTFDeserializer : public SkTypefaceDeserializer { |
| 559 | public: |
| 560 | sk_sp<SkTypeface> deserialize(const void* data, size_t size) override { |
| 561 | SkASSERT(sizeof(SkTypeface*) == size); |
| 562 | SkTypeface* tf; |
| 563 | memcpy(&tf, data, size); |
| 564 | return sk_sp<SkTypeface>(tf); // this was ref'd in SampleTFSerializer |
| 565 | } |
| 566 | }; |
| 567 | |
| 568 | /////////////////////////////////////////////////////////////////////////////// |
| 569 | |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 570 | enum TilingMode { |
| 571 | kNo_Tiling, |
| 572 | kAbs_128x128_Tiling, |
| 573 | kAbs_256x256_Tiling, |
| 574 | kRel_4x4_Tiling, |
| 575 | kRel_1x16_Tiling, |
| 576 | kRel_16x1_Tiling, |
| 577 | |
| 578 | kLast_TilingMode_Enum |
| 579 | }; |
| 580 | |
| 581 | struct TilingInfo { |
| 582 | const char* label; |
| 583 | SkScalar w, h; |
| 584 | }; |
| 585 | |
commit-bot@chromium.org | bbe43a9 | 2013-12-10 21:51:06 +0000 | [diff] [blame] | 586 | static const struct TilingInfo gTilingInfo[] = { |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 587 | { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling |
| 588 | { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Tiling |
| 589 | { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Tiling |
| 590 | { "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling |
| 591 | { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling |
| 592 | { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling |
| 593 | }; |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 594 | static_assert((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum), |
| 595 | "Incomplete_tiling_labels"); |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 596 | |
commit-bot@chromium.org | bbe43a9 | 2013-12-10 21:51:06 +0000 | [diff] [blame] | 597 | SkSize SampleWindow::tileSize() const { |
| 598 | SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum); |
| 599 | const struct TilingInfo* info = gTilingInfo + fTilingMode; |
| 600 | return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w, |
| 601 | info->h > SK_Scalar1 ? info->h : this->height() * info->h); |
| 602 | } |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 603 | ////////////////////////////////////////////////////////////////////////////// |
| 604 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 605 | static SkView* curr_view(SkWindow* wind) { |
| 606 | SkView::F2BIter iter(wind); |
| 607 | return iter.next(); |
| 608 | } |
| 609 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 610 | static bool curr_title(SkWindow* wind, SkString* title) { |
| 611 | SkView* view = curr_view(wind); |
| 612 | if (view) { |
| 613 | SkEvent evt(gTitleEvtName); |
| 614 | if (view->doQuery(&evt)) { |
| 615 | title->set(evt.findString(gTitleEvtName)); |
| 616 | return true; |
| 617 | } |
| 618 | } |
| 619 | return false; |
| 620 | } |
| 621 | |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 622 | bool SampleWindow::sendAnimatePulse() { |
| 623 | SkView* view = curr_view(this); |
| 624 | if (SampleView::IsSampleView(view)) { |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 625 | return ((SampleView*)view)->animate(gAnimTimer); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 626 | } |
| 627 | return false; |
| 628 | } |
| 629 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 630 | void SampleWindow::setZoomCenter(float x, float y) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 631 | fZoomCenterX = x; |
| 632 | fZoomCenterY = y; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 633 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 634 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 635 | bool SampleWindow::zoomIn() { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 636 | // Arbitrarily decided |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 637 | if (fFatBitsScale == kMaxFatBitsScale) return false; |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 638 | fFatBitsScale++; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 639 | this->inval(nullptr); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 640 | return true; |
| 641 | } |
| 642 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 643 | bool SampleWindow::zoomOut() { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 644 | if (fFatBitsScale == 1) return false; |
| 645 | fFatBitsScale--; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 646 | this->inval(nullptr); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 647 | return true; |
| 648 | } |
| 649 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 650 | void SampleWindow::updatePointer(int x, int y) { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 651 | fMouseX = x; |
| 652 | fMouseY = y; |
| 653 | if (fShowZoomer) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 654 | this->inval(nullptr); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 658 | static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) { |
| 659 | static const SampleWindow::DeviceType gCT[] = { |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 660 | SampleWindow::kRaster_DeviceType |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 661 | #if SK_SUPPORT_GPU |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 662 | , SampleWindow::kGPU_DeviceType |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 663 | #if SK_ANGLE |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 664 | , SampleWindow::kANGLE_DeviceType |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 665 | #endif // SK_ANGLE |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 666 | #endif // SK_SUPPORT_GPU |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 667 | }; |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 668 | static_assert(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, "array_size_mismatch"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 669 | return gCT[ct]; |
| 670 | } |
| 671 | |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 672 | static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
| 673 | SkView* view = (*sampleFactory)(); |
| 674 | SkString title; |
| 675 | SampleCode::RequestTitle(view, &title); |
| 676 | view->unref(); |
| 677 | return title; |
| 678 | } |
| 679 | |
edisonn@google.com | de36b69 | 2013-07-11 15:40:31 +0000 | [diff] [blame] | 680 | static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory* second) { |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 681 | return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str()) < 0; |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 682 | } |
| 683 | |
reed | b7ffe03 | 2015-11-05 11:59:17 -0800 | [diff] [blame] | 684 | static int find_by_title(const SkViewFactory* const* factories, int count, const char title[]) { |
| 685 | for (int i = 0; i < count; i++) { |
| 686 | if (getSampleTitle(factories[i]).equals(title)) { |
| 687 | return i; |
| 688 | } |
| 689 | } |
| 690 | return -1; |
| 691 | } |
| 692 | |
| 693 | static void restrict_samples(SkTDArray<const SkViewFactory*>& factories, const SkString titles[], |
| 694 | int count) { |
| 695 | int newCount = 0; |
| 696 | for (int i = 0; i < count; ++i) { |
| 697 | int index = find_by_title(factories.begin(), factories.count(), titles[i].c_str()); |
| 698 | if (index >= 0) { |
| 699 | SkTSwap(factories.begin()[newCount], factories.begin()[index]); |
| 700 | newCount += 1; |
| 701 | } |
| 702 | } |
| 703 | if (newCount) { |
| 704 | factories.setCount(newCount); |
| 705 | } |
| 706 | } |
| 707 | |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 708 | DEFINE_string(slide, "", "Start on this sample."); |
| 709 | DEFINE_int32(msaa, 0, "Request multisampling with this count."); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 710 | DEFINE_bool(deepColor, false, "Request deep color (10-bit/channel or more) display buffer."); |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 711 | DEFINE_string(pictureDir, "", "Read pictures from here."); |
| 712 | DEFINE_string(picture, "", "Path to single picture."); |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 713 | DEFINE_string(svg, "", "Path to single SVG file."); |
| 714 | DEFINE_string(svgDir, "", "Read SVGs from here."); |
reed | b7ffe03 | 2015-11-05 11:59:17 -0800 | [diff] [blame] | 715 | DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to show."); |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 716 | DEFINE_bool(sort, false, "Sort samples by title."); |
| 717 | DEFINE_bool(list, false, "List samples?"); |
jvanverth | 44dcb8a | 2015-10-02 09:12:05 -0700 | [diff] [blame] | 718 | DEFINE_bool(gpu, false, "Start up with gpu?"); |
brianosman | ca34846 | 2016-02-24 11:47:47 -0800 | [diff] [blame] | 719 | DEFINE_bool(redraw, false, "Force continuous redrawing, for profiling or debugging tools."); |
caryclark | 6531c36 | 2015-07-20 13:38:56 -0700 | [diff] [blame] | 720 | DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-specific names |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 721 | #ifdef SAMPLE_PDF_FILE_VIEWER |
| 722 | DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); |
| 723 | #endif |
| 724 | |
reed | 89889b6 | 2014-10-29 12:36:45 -0700 | [diff] [blame] | 725 | #include "SkTaskGroup.h" |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 726 | #include "SkForceLinking.h" |
reed | 89889b6 | 2014-10-29 12:36:45 -0700 | [diff] [blame] | 727 | |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 728 | SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) |
robertphillips@google.com | 4750fa5 | 2012-04-10 13:34:11 +0000 | [diff] [blame] | 729 | : INHERITED(hwnd) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 730 | , fDevManager(nullptr) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 731 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 732 | SkForceLinking(false); |
| 733 | |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 734 | SkCommandLineFlags::Parse(argc, argv); |
| 735 | |
reed@google.com | 7d05ac9 | 2013-06-06 13:14:13 +0000 | [diff] [blame] | 736 | fCurrIndex = -1; |
| 737 | |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 738 | if (!FLAGS_pictureDir.isEmpty()) { |
| 739 | SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); |
| 740 | SkString filename; |
| 741 | while (iter.next(&filename)) { |
| 742 | *fSamples.append() = new PictFileFactory( |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 743 | SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str())); |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | if (!FLAGS_picture.isEmpty()) { |
| 747 | SkString path(FLAGS_picture[0]); |
| 748 | fCurrIndex = fSamples.count(); |
| 749 | *fSamples.append() = new PictFileFactory(path); |
| 750 | } |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 751 | if (!FLAGS_svg.isEmpty()) { |
| 752 | SkString path(FLAGS_svg[0]); |
| 753 | fCurrIndex = fSamples.count(); |
| 754 | *fSamples.append() = new SVGFileFactory(path); |
| 755 | } |
| 756 | if (!FLAGS_svgDir.isEmpty()) { |
| 757 | SkOSFile::Iter iter(FLAGS_svgDir[0], "svg"); |
| 758 | SkString filename; |
| 759 | while (iter.next(&filename)) { |
| 760 | *fSamples.append() = new SVGFileFactory( |
| 761 | SkOSPath::Join(FLAGS_svgDir[0], filename.c_str())); |
| 762 | } |
| 763 | } |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 764 | #ifdef SAMPLE_PDF_FILE_VIEWER |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 765 | if (!FLAGS_pdfPath.isEmpty()) { |
| 766 | SkOSFile::Iter iter(FLAGS_pdfPath[0], "pdf"); |
| 767 | SkString filename; |
| 768 | while (iter.next(&filename)) { |
| 769 | *fSamples.append() = new PdfFileViewerFactory( |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 770 | SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str())); |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | #endif |
robertphillips@google.com | 76d4021 | 2012-03-22 14:12:15 +0000 | [diff] [blame] | 774 | SkGMRegistyToSampleRegistry(); |
| 775 | { |
| 776 | const SkViewRegister* reg = SkViewRegister::Head(); |
| 777 | while (reg) { |
| 778 | *fSamples.append() = reg->factory(); |
| 779 | reg = reg->next(); |
| 780 | } |
| 781 | } |
| 782 | |
reed | b7ffe03 | 2015-11-05 11:59:17 -0800 | [diff] [blame] | 783 | if (!FLAGS_sequence.isEmpty()) { |
| 784 | // The sequence file just contains a list (separated by CRs) of the samples or GM:gms |
| 785 | // you want to restrict to. Only these will appear when you cycle through. |
| 786 | // If none are found, or the file is empty, then it will be ignored, and all samples |
| 787 | // will be available. |
| 788 | SkFILEStream stream(FLAGS_sequence[0]); |
| 789 | if (stream.isValid()) { |
| 790 | size_t len = stream.getLength(); |
scroggo | 565901d | 2015-12-10 10:44:13 -0800 | [diff] [blame] | 791 | SkAutoTMalloc<char> storage(len + 1); |
| 792 | char* buffer = storage.get(); |
reed | b7ffe03 | 2015-11-05 11:59:17 -0800 | [diff] [blame] | 793 | stream.read(buffer, len); |
| 794 | buffer[len] = 0; |
| 795 | |
| 796 | SkTArray<SkString> titles; |
| 797 | SkStrSplit(buffer, "\n\r", &titles); |
| 798 | restrict_samples(fSamples, titles.begin(), titles.count()); |
| 799 | } |
| 800 | } |
| 801 | |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 802 | if (FLAGS_sort) { |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 803 | // Sort samples, so foo.skp and foo.pdf are consecutive and we can quickly spot where |
| 804 | // skp -> pdf -> png fails. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 805 | SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : nullptr, compareSampleTitle); |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 806 | } |
| 807 | |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 808 | if (!FLAGS_slide.isEmpty()) { |
| 809 | fCurrIndex = findByTitle(FLAGS_slide[0]); |
| 810 | if (fCurrIndex < 0) { |
| 811 | fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 812 | listTitles(); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 813 | } |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | fMSAASampleCount = FLAGS_msaa; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 817 | fDeepColor = FLAGS_deepColor; |
mtklein | fd117d8 | 2014-06-19 14:18:56 -0700 | [diff] [blame] | 818 | |
| 819 | if (FLAGS_list) { |
| 820 | listTitles(); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | if (fCurrIndex < 0) { |
| 824 | SkString title; |
| 825 | if (readTitleFromPrefs(&title)) { |
| 826 | fCurrIndex = findByTitle(title.c_str()); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (fCurrIndex < 0) { |
| 831 | fCurrIndex = 0; |
| 832 | } |
| 833 | |
reed | 89889b6 | 2014-10-29 12:36:45 -0700 | [diff] [blame] | 834 | static SkTaskGroup::Enabler enabled(-1); |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 835 | gSampleWindow = this; |
| 836 | |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 837 | fDeviceType = kRaster_DeviceType; |
jvanverth | 41518eb | 2015-10-02 10:42:36 -0700 | [diff] [blame] | 838 | #if SK_SUPPORT_GPU |
jvanverth | 44dcb8a | 2015-10-02 09:12:05 -0700 | [diff] [blame] | 839 | if (FLAGS_gpu) { |
| 840 | fDeviceType = kGPU_DeviceType; |
| 841 | } |
jvanverth | 41518eb | 2015-10-02 10:42:36 -0700 | [diff] [blame] | 842 | #endif |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 843 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 844 | #if DEFAULT_TO_GPU |
| 845 | fDeviceType = kGPU_DeviceType; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 846 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 847 | #if SK_ANGLE && DEFAULT_TO_ANGLE |
| 848 | fDeviceType = kANGLE_DeviceType; |
| 849 | #endif |
| 850 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 851 | fUseClip = false; |
reed | 91b4dfb | 2016-01-08 08:23:19 -0800 | [diff] [blame] | 852 | fUsePicture = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 853 | fAnimating = false; |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 854 | fRotate = false; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 855 | fPerspAnim = false; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 856 | fRequestGrabImage = false; |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 857 | fTilingMode = kNo_Tiling; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 858 | fMeasureFPS = false; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 859 | fUseDeferredCanvas = false; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 860 | fLCDState = SkOSMenu::kMixedState; |
| 861 | fAAState = SkOSMenu::kMixedState; |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 862 | fSubpixelState = SkOSMenu::kMixedState; |
| 863 | fHintingState = 0; |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 864 | fPixelGeometryIndex = 0; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 865 | fFilterQualityIndex = 0; |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 866 | fFlipAxis = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 867 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 868 | fMouseX = fMouseY = 0; |
mike@reedtribe.org | 3ce59dc | 2011-04-08 00:38:05 +0000 | [diff] [blame] | 869 | fFatBitsScale = 8; |
reed | 5755cd9 | 2016-08-21 19:30:13 -0700 | [diff] [blame] | 870 | fTypeface = SkTypeface::MakeFromName("Courier", SkFontStyle(SkFontStyle::kBold_Weight, |
| 871 | SkFontStyle::kNormal_Width, |
| 872 | SkFontStyle::kUpright_Slant)); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 873 | fShowZoomer = false; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 874 | |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 875 | fZoomLevel = 0; |
| 876 | fZoomScale = SK_Scalar1; |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 877 | fOffset = { 0, 0 }; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 878 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 879 | fMagnify = false; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 880 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 881 | fSaveToPdf = false; |
reed | 093b4e8 | 2015-08-04 18:46:38 -0700 | [diff] [blame] | 882 | fSaveToSKP = false; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 883 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 884 | if (true) { |
| 885 | fPipeSerializer.setTypefaceSerializer(new SampleTFSerializer); |
| 886 | fPipeDeserializer.setTypefaceDeserializer(new SampleTFDeserializer); |
| 887 | } |
| 888 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 889 | int sinkID = this->getSinkID(); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 890 | fAppMenu = new SkOSMenu; |
| 891 | fAppMenu->setTitle("Global Settings"); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 892 | int itemID; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 893 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 894 | itemID = fAppMenu->appendList("ColorType", "ColorType", sinkID, 0, |
| 895 | gConfig[0].fName, gConfig[1].fName, gConfig[2].fName, nullptr); |
| 896 | fAppMenu->assignKeyEquivalentToItem(itemID, 'C'); |
| 897 | |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 898 | itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
| 899 | "Raster", |
| 900 | "OpenGL", |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 901 | #if SK_ANGLE |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 902 | "ANGLE", |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 903 | #endif |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 904 | nullptr); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 905 | fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); |
| 906 | itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); |
| 907 | fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); |
| 908 | itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); |
| 909 | fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 910 | itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFilterQualityIndex, |
| 911 | gFilterQualityStates[0].fName, |
| 912 | gFilterQualityStates[1].fName, |
| 913 | gFilterQualityStates[2].fName, |
| 914 | gFilterQualityStates[3].fName, |
| 915 | gFilterQualityStates[4].fName, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 916 | nullptr); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 917 | fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 918 | itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelState); |
| 919 | fAppMenu->assignKeyEquivalentToItem(itemID, 's'); |
| 920 | itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, |
| 921 | gHintingStates[0].name, |
| 922 | gHintingStates[1].name, |
| 923 | gHintingStates[2].name, |
| 924 | gHintingStates[3].name, |
bungeman@google.com | a9133bb | 2013-06-04 17:49:20 +0000 | [diff] [blame] | 925 | gHintingStates[4].name, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 926 | nullptr); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 927 | fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 928 | |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 929 | itemID = fAppMenu->appendList("Pixel Geometry", "Pixel Geometry", sinkID, fPixelGeometryIndex, |
| 930 | gPixelGeometryStates[0].name, |
| 931 | gPixelGeometryStates[1].name, |
| 932 | gPixelGeometryStates[2].name, |
| 933 | gPixelGeometryStates[3].name, |
| 934 | gPixelGeometryStates[4].name, |
| 935 | gPixelGeometryStates[5].name, |
| 936 | nullptr); |
| 937 | fAppMenu->assignKeyEquivalentToItem(itemID, 'P'); |
| 938 | |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 939 | itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, |
| 940 | gTilingInfo[kNo_Tiling].label, |
| 941 | gTilingInfo[kAbs_128x128_Tiling].label, |
| 942 | gTilingInfo[kAbs_256x256_Tiling].label, |
| 943 | gTilingInfo[kRel_4x4_Tiling].label, |
| 944 | gTilingInfo[kRel_1x16_Tiling].label, |
| 945 | gTilingInfo[kRel_16x1_Tiling].label, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 946 | nullptr); |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 947 | fAppMenu->assignKeyEquivalentToItem(itemID, 't'); |
| 948 | |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 949 | itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); |
| 950 | fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); |
| 951 | itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 952 | fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 953 | itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 954 | fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); |
| 955 | itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); |
| 956 | fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); |
| 957 | itemID = fAppMenu->appendSwitch("Zoomer", "Zoomer" , sinkID, fShowZoomer); |
| 958 | fAppMenu->assignKeyEquivalentToItem(itemID, 'z'); |
| 959 | itemID = fAppMenu->appendSwitch("Magnify", "Magnify" , sinkID, fMagnify); |
| 960 | fAppMenu->assignKeyEquivalentToItem(itemID, 'm'); |
reed | 093b4e8 | 2015-08-04 18:46:38 -0700 | [diff] [blame] | 961 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 962 | itemID = fAppMenu->appendAction("Save to PDF", sinkID); |
| 963 | fAppMenu->assignKeyEquivalentToItem(itemID, 'e'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 964 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 965 | this->addMenu(fAppMenu); |
| 966 | fSlideMenu = new SkOSMenu; |
| 967 | this->addMenu(fSlideMenu); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 968 | |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 969 | this->setVisibleP(true); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 970 | this->setClipToBounds(false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 971 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 972 | this->loadView((*fSamples[fCurrIndex])()); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 973 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 974 | if (nullptr == devManager) { |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 975 | fDevManager = new DefaultDeviceManager(); |
| 976 | } else { |
| 977 | devManager->ref(); |
| 978 | fDevManager = devManager; |
| 979 | } |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 980 | fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 981 | |
Scroggo | b4490c7 | 2011-06-17 13:53:05 +0000 | [diff] [blame] | 982 | // If another constructor set our dimensions, ensure that our |
| 983 | // onSizeChange gets called. |
| 984 | if (this->height() && this->width()) { |
| 985 | this->onSizeChange(); |
| 986 | } |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 987 | |
| 988 | // can't call this synchronously, since it may require a subclass to |
| 989 | // to implement, or the caller may need us to have returned from the |
| 990 | // constructor first. Hence we post an event to ourselves. |
| 991 | // this->updateTitle(); |
commit-bot@chromium.org | 6de4a78 | 2013-12-11 17:05:23 +0000 | [diff] [blame] | 992 | post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 993 | |
| 994 | gAnimTimer.run(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | SampleWindow::~SampleWindow() { |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 998 | SkSafeUnref(fDevManager); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 1001 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1002 | int SampleWindow::findByTitle(const char title[]) { |
| 1003 | int i, count = fSamples.count(); |
| 1004 | for (i = 0; i < count; i++) { |
| 1005 | if (getSampleTitle(i).equals(title)) { |
| 1006 | return i; |
| 1007 | } |
| 1008 | } |
mike@reedtribe.org | dd52caa | 2011-12-28 20:02:10 +0000 | [diff] [blame] | 1009 | return -1; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 1012 | void SampleWindow::listTitles() { |
| 1013 | int count = fSamples.count(); |
| 1014 | SkDebugf("All Slides:\n"); |
| 1015 | for (int i = 0; i < count; i++) { |
| 1016 | SkDebugf(" %s\n", getSampleTitle(i).c_str()); |
| 1017 | } |
| 1018 | } |
| 1019 | |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1020 | static SkBitmap capture_bitmap(SkCanvas* canvas) { |
| 1021 | SkBitmap bm; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 1022 | if (bm.tryAllocPixels(canvas->imageInfo())) { |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1023 | canvas->readPixels(&bm, 0, 0); |
| 1024 | } |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1025 | return bm; |
| 1026 | } |
| 1027 | |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1028 | static void drawText(SkCanvas* canvas, SkString str, SkScalar left, SkScalar top, SkPaint& paint) { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1029 | SkColor desiredColor = paint.getColor(); |
| 1030 | paint.setColor(SK_ColorWHITE); |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1031 | const char* c_str = str.c_str(); |
| 1032 | size_t size = str.size(); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1033 | SkRect bounds; |
| 1034 | paint.measureText(c_str, size, &bounds); |
| 1035 | bounds.offset(left, top); |
| 1036 | SkScalar inset = SkIntToScalar(-2); |
| 1037 | bounds.inset(inset, inset); |
| 1038 | canvas->drawRect(bounds, paint); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1039 | paint.setColor(desiredColor); |
| 1040 | canvas->drawText(c_str, size, left, top, paint); |
| 1041 | } |
| 1042 | |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 1043 | #define XCLIP_N 8 |
| 1044 | #define YCLIP_N 8 |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1045 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 1046 | #include "SkDeferredCanvas.h" |
| 1047 | #include "SkDumpCanvas.h" |
| 1048 | |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1049 | void SampleWindow::draw(SkCanvas* canvas) { |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1050 | gAnimTimer.updateTime(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1051 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1052 | if (fGesture.isActive()) { |
| 1053 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1054 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1055 | |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1056 | if (fMeasureFPS) { |
| 1057 | fMeasureFPS_Time = 0; |
| 1058 | } |
| 1059 | |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1060 | SkSize tile = this->tileSize(); |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1061 | |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1062 | if (kNo_Tiling == fTilingMode) { |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 1063 | SkDebugfDumper dumper; |
| 1064 | SkDumpCanvas dump(&dumper); |
| 1065 | SkDeferredCanvas deferred(canvas); |
| 1066 | SkCanvas* c = fUseDeferredCanvas ? &deferred : canvas; |
| 1067 | this->INHERITED::draw(c); // no looping or surfaces needed |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1068 | } else { |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1069 | const SkScalar w = SkScalarCeilToScalar(tile.width()); |
| 1070 | const SkScalar h = SkScalarCeilToScalar(tile.height()); |
| 1071 | SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarTruncToInt(w), SkScalarTruncToInt(h)); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1072 | auto surface(canvas->makeSurface(info)); |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1073 | SkCanvas* tileCanvas = surface->getCanvas(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 1074 | |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1075 | for (SkScalar y = 0; y < height(); y += h) { |
| 1076 | for (SkScalar x = 0; x < width(); x += w) { |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1077 | SkAutoCanvasRestore acr(tileCanvas, true); |
| 1078 | tileCanvas->translate(-x, -y); |
| 1079 | tileCanvas->clear(0); |
| 1080 | this->INHERITED::draw(tileCanvas); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1081 | surface->draw(canvas, x, y, nullptr); |
commit-bot@chromium.org | 9a558d4 | 2014-05-30 15:06:24 +0000 | [diff] [blame] | 1082 | } |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1083 | } |
commit-bot@chromium.org | 9a558d4 | 2014-05-30 15:06:24 +0000 | [diff] [blame] | 1084 | |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1085 | // for drawing the borders between tiles |
| 1086 | SkPaint paint; |
| 1087 | paint.setColor(0x60FF00FF); |
| 1088 | paint.setStyle(SkPaint::kStroke_Style); |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 1089 | |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1090 | for (SkScalar y = 0; y < height(); y += tile.height()) { |
| 1091 | for (SkScalar x = 0; x < width(); x += tile.width()) { |
| 1092 | canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.height()), paint); |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1095 | } |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1096 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1097 | if (fShowZoomer && !fSaveToPdf) { |
Scroggo | 3272ba8 | 2011-05-25 20:50:42 +0000 | [diff] [blame] | 1098 | showZoomer(canvas); |
| 1099 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1100 | if (fMagnify && !fSaveToPdf) { |
| 1101 | magnify(canvas); |
| 1102 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1103 | |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1104 | if (fMeasureFPS && fMeasureFPS_Time) { |
| 1105 | this->updateTitle(); |
| 1106 | this->postInvalDelay(); |
| 1107 | } |
| 1108 | |
brianosman | ca34846 | 2016-02-24 11:47:47 -0800 | [diff] [blame] | 1109 | if (this->sendAnimatePulse() || FLAGS_redraw) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1110 | this->inval(nullptr); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1113 | // do this last |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1114 | fDevManager->publishCanvas(fDeviceType, canvas, this); |
Scroggo | 3272ba8 | 2011-05-25 20:50:42 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1117 | static float clipW = 200; |
| 1118 | static float clipH = 200; |
| 1119 | void SampleWindow::magnify(SkCanvas* canvas) { |
| 1120 | SkRect r; |
| 1121 | int count = canvas->save(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1122 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1123 | SkMatrix m = canvas->getTotalMatrix(); |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 1124 | if (!m.invert(&m)) { |
| 1125 | return; |
| 1126 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1127 | SkPoint offset, center; |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1128 | SkScalar mouseX = fMouseX * SK_Scalar1; |
| 1129 | SkScalar mouseY = fMouseY * SK_Scalar1; |
| 1130 | m.mapXY(mouseX - clipW/2, mouseY - clipH/2, &offset); |
| 1131 | m.mapXY(mouseX, mouseY, ¢er); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1132 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1133 | r.set(0, 0, clipW * m.getScaleX(), clipH * m.getScaleX()); |
| 1134 | r.offset(offset.fX, offset.fY); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1135 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1136 | SkPaint paint; |
| 1137 | paint.setColor(0xFF66AAEE); |
| 1138 | paint.setStyle(SkPaint::kStroke_Style); |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1139 | paint.setStrokeWidth(10.f * m.getScaleX()); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1140 | //lense offset |
| 1141 | //canvas->translate(0, -250); |
| 1142 | canvas->drawRect(r, paint); |
| 1143 | canvas->clipRect(r); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1144 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1145 | m = canvas->getTotalMatrix(); |
| 1146 | m.setTranslate(-center.fX, -center.fY); |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1147 | m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1148 | m.postTranslate(center.fX, center.fY); |
| 1149 | canvas->concat(m); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1150 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1151 | this->INHERITED::draw(canvas); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1152 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1153 | canvas->restoreToCount(count); |
| 1154 | } |
| 1155 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1156 | static SkPaint& set_color_ref(SkPaint& paint, SkColor c) { |
| 1157 | paint.setColor(c); |
| 1158 | return paint; |
| 1159 | } |
reed@google.com | b36334d | 2011-05-18 15:07:20 +0000 | [diff] [blame] | 1160 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1161 | static void show_lcd_box(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c, |
| 1162 | SkScalar sx, SkScalar sy) { |
| 1163 | const SkScalar w = (1 - 1/sx) / 3; |
| 1164 | SkPaint paint; |
| 1165 | SkRect r = SkRect::MakeXYWH(x, y, w, 1 - 1/sy); |
| 1166 | canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0))); |
| 1167 | r.offset(w, 0); |
| 1168 | canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0))); |
| 1169 | r.offset(w, 0); |
| 1170 | canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB(c)))); |
| 1171 | } |
reed@google.com | b36334d | 2011-05-18 15:07:20 +0000 | [diff] [blame] | 1172 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1173 | static void show_lcd_circle(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c, |
| 1174 | SkScalar, SkScalar) { |
| 1175 | const SkRect r = SkRect::MakeXYWH(x, y, 1, 1); |
| 1176 | const SkScalar cx = x + 0.5f; |
| 1177 | const SkScalar cy = y + 0.5f; |
| 1178 | |
| 1179 | SkPaint paint; |
| 1180 | paint.setAntiAlias(true); |
| 1181 | |
| 1182 | SkPath path; |
| 1183 | path.addArc(r, 0, 120); path.lineTo(cx, cy); |
| 1184 | canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0))); |
| 1185 | |
| 1186 | path.reset(); path.addArc(r, 120, 120); path.lineTo(cx, cy); |
| 1187 | canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0))); |
| 1188 | |
| 1189 | path.reset(); path.addArc(r, 240, 120); path.lineTo(cx, cy); |
| 1190 | canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB(c)))); |
| 1191 | } |
| 1192 | |
| 1193 | typedef void (*ShowLCDProc)(SkCanvas*, SkScalar, SkScalar, SkColor, SkScalar, SkScalar); |
| 1194 | |
| 1195 | /* |
| 1196 | * Like drawBitmapRect but we manually draw each pixels in RGB |
| 1197 | */ |
| 1198 | static void show_lcd_grid(SkCanvas* canvas, const SkBitmap& bitmap, |
reed | 8a41adb | 2015-08-15 14:02:29 -0700 | [diff] [blame] | 1199 | const SkIRect& origSrc, const SkRect& dst, ShowLCDProc proc) { |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1200 | SkIRect src; |
| 1201 | if (!src.intersect(origSrc, bitmap.bounds())) { |
| 1202 | return; |
| 1203 | } |
| 1204 | const SkScalar sx = dst.width() / src.width(); |
| 1205 | const SkScalar sy = dst.height() / src.height(); |
| 1206 | |
| 1207 | SkAutoCanvasRestore acr(canvas, true); |
| 1208 | canvas->translate(dst.left(), dst.top()); |
| 1209 | canvas->scale(sx, sy); |
| 1210 | |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1211 | for (int y = 0; y < src.height(); ++y) { |
| 1212 | for (int x = 0; x < src.width(); ++x) { |
| 1213 | proc(canvas, SkIntToScalar(x), SkIntToScalar(y), |
| 1214 | bitmap.getColor(src.left() + x, src.top() + y), sx, sy); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1215 | } |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | void SampleWindow::showZoomer(SkCanvas* canvas) { |
| 1220 | int count = canvas->save(); |
| 1221 | canvas->resetMatrix(); |
| 1222 | // Ensure the mouse position is on screen. |
| 1223 | int width = SkScalarRoundToInt(this->width()); |
| 1224 | int height = SkScalarRoundToInt(this->height()); |
| 1225 | if (fMouseX >= width) fMouseX = width - 1; |
| 1226 | else if (fMouseX < 0) fMouseX = 0; |
| 1227 | if (fMouseY >= height) fMouseY = height - 1; |
| 1228 | else if (fMouseY < 0) fMouseY = 0; |
| 1229 | |
| 1230 | SkBitmap bitmap = capture_bitmap(canvas); |
| 1231 | bitmap.lockPixels(); |
| 1232 | |
| 1233 | // Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle. |
| 1234 | int zoomedWidth = (width >> 1) | 1; |
| 1235 | int zoomedHeight = (height >> 1) | 1; |
| 1236 | SkIRect src; |
| 1237 | src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale); |
| 1238 | src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1)); |
| 1239 | SkRect dest; |
| 1240 | dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight)); |
| 1241 | dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight)); |
| 1242 | SkPaint paint; |
| 1243 | // Clear the background behind our zoomed in view |
| 1244 | paint.setColor(SK_ColorWHITE); |
| 1245 | canvas->drawRect(dest, paint); |
reed | 8a41adb | 2015-08-15 14:02:29 -0700 | [diff] [blame] | 1246 | switch (fFatBitsScale) { |
| 1247 | case kMaxFatBitsScale: |
| 1248 | show_lcd_grid(canvas, bitmap, src, dest, show_lcd_box); |
| 1249 | break; |
| 1250 | case kMaxFatBitsScale - 1: |
| 1251 | show_lcd_grid(canvas, bitmap, src, dest, show_lcd_circle); |
| 1252 | break; |
| 1253 | default: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1254 | canvas->drawBitmapRect(bitmap, src, dest, nullptr); |
reed | 8a41adb | 2015-08-15 14:02:29 -0700 | [diff] [blame] | 1255 | break; |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | paint.setColor(SK_ColorBLACK); |
| 1259 | paint.setStyle(SkPaint::kStroke_Style); |
| 1260 | // Draw a border around the pixel in the middle |
| 1261 | SkRect originalPixel; |
| 1262 | originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1)); |
| 1263 | SkMatrix matrix; |
| 1264 | SkRect scalarSrc; |
| 1265 | scalarSrc.set(src); |
| 1266 | SkColor color = bitmap.getColor(fMouseX, fMouseY); |
| 1267 | if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) { |
| 1268 | SkRect pixel; |
| 1269 | matrix.mapRect(&pixel, originalPixel); |
| 1270 | // TODO Perhaps measure the values and make the outline white if it's "dark" |
| 1271 | if (color == SK_ColorBLACK) { |
| 1272 | paint.setColor(SK_ColorWHITE); |
| 1273 | } |
| 1274 | canvas->drawRect(pixel, paint); |
| 1275 | } |
| 1276 | paint.setColor(SK_ColorBLACK); |
| 1277 | // Draw a border around the destination rectangle |
| 1278 | canvas->drawRect(dest, paint); |
| 1279 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 1280 | // Identify the pixel and its color on screen |
| 1281 | paint.setTypeface(fTypeface); |
| 1282 | paint.setAntiAlias(true); |
reed | 5755cd9 | 2016-08-21 19:30:13 -0700 | [diff] [blame] | 1283 | paint.setTextSize(18); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1284 | SkScalar lineHeight = paint.getFontMetrics(nullptr); |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1285 | SkString string; |
| 1286 | string.appendf("(%i, %i)", fMouseX, fMouseY); |
| 1287 | SkScalar left = dest.fLeft + SkIntToScalar(3); |
| 1288 | SkScalar i = SK_Scalar1; |
| 1289 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1290 | // Alpha |
| 1291 | i += SK_Scalar1; |
| 1292 | string.reset(); |
| 1293 | string.appendf("A: %X", SkColorGetA(color)); |
| 1294 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1295 | // Red |
| 1296 | i += SK_Scalar1; |
| 1297 | string.reset(); |
| 1298 | string.appendf("R: %X", SkColorGetR(color)); |
| 1299 | paint.setColor(SK_ColorRED); |
| 1300 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1301 | // Green |
| 1302 | i += SK_Scalar1; |
| 1303 | string.reset(); |
| 1304 | string.appendf("G: %X", SkColorGetG(color)); |
reed | 5755cd9 | 2016-08-21 19:30:13 -0700 | [diff] [blame] | 1305 | paint.setColor(0xFF008800); |
reed | 5f629b4 | 2015-08-15 11:57:23 -0700 | [diff] [blame] | 1306 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1307 | // Blue |
| 1308 | i += SK_Scalar1; |
| 1309 | string.reset(); |
| 1310 | string.appendf("B: %X", SkColorGetB(color)); |
| 1311 | paint.setColor(SK_ColorBLUE); |
| 1312 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1313 | canvas->restoreToCount(count); |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1316 | void SampleWindow::onDraw(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | #include "SkColorPriv.h" |
| 1320 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1321 | void SampleWindow::saveToPdf() |
| 1322 | { |
| 1323 | fSaveToPdf = true; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1324 | this->inval(nullptr); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1327 | SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1328 | if (fSaveToPdf) { |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 1329 | SkString name; |
| 1330 | if (!this->getRawTitle(&name)) { |
| 1331 | name.set("unknown_sample"); |
| 1332 | } |
| 1333 | name.append(".pdf"); |
| 1334 | #ifdef SK_BUILD_FOR_ANDROID |
| 1335 | name.prepend("/sdcard/"); |
| 1336 | #endif |
halcanary | 676ab68 | 2016-05-03 12:10:04 -0700 | [diff] [blame] | 1337 | fPDFDocument = SkDocument::MakePDF(name.c_str()); |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 1338 | canvas = fPDFDocument->beginPage(this->width(), this->height()); |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1339 | } else if (fSaveToSKP) { |
| 1340 | canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0); |
reed | 91b4dfb | 2016-01-08 08:23:19 -0800 | [diff] [blame] | 1341 | } else if (fUsePicture) { |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 1342 | fPipeStream.reset(new SkDynamicMemoryWStream); |
| 1343 | canvas = fPipeSerializer.beginWrite(SkRect::MakeWH(this->width(), this->height()), |
| 1344 | fPipeStream.get()); |
| 1345 | // canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1346 | } else { |
bsalomon | bb0502e | 2015-02-11 11:11:11 -0800 | [diff] [blame] | 1347 | canvas = this->INHERITED::beforeChildren(canvas); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | if (fUseClip) { |
| 1351 | canvas->drawColor(0xFFFF88FF); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame^] | 1352 | canvas->clipPath(fClipPath, SkCanvas::kIntersect_Op, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 1355 | // Install a flags filter proxy canvas if needed |
| 1356 | if (fLCDState != SkOSMenu::kMixedState || |
| 1357 | fAAState != SkOSMenu::kMixedState || |
| 1358 | fSubpixelState != SkOSMenu::kMixedState || |
| 1359 | fHintingState > 0 || |
| 1360 | fFilterQualityIndex > 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1361 | canvas = new FlagsFilterCanvas(canvas, fLCDState, fAAState, fSubpixelState, fHintingState, |
| 1362 | fFilterQualityIndex); |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 1363 | fFlagsFilterCanvas.reset(canvas); |
| 1364 | } |
| 1365 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1366 | return canvas; |
| 1367 | } |
reed | 89889b6 | 2014-10-29 12:36:45 -0700 | [diff] [blame] | 1368 | #include "SkMultiPictureDraw.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1369 | void SampleWindow::afterChildren(SkCanvas* orig) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1370 | fFlagsFilterCanvas.reset(nullptr); |
fmalita | 822ace9 | 2015-06-15 07:07:32 -0700 | [diff] [blame] | 1371 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1372 | if (fSaveToPdf) { |
| 1373 | fSaveToPdf = false; |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 1374 | fPDFDocument->endPage(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1375 | fPDFDocument.reset(nullptr); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1376 | // We took over the draw calls in order to create the PDF, so we need |
| 1377 | // to redraw. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1378 | this->inval(nullptr); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1379 | return; |
| 1380 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1381 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1382 | if (fRequestGrabImage) { |
| 1383 | fRequestGrabImage = false; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1384 | |
reed | 52d9ac6 | 2014-06-30 09:05:34 -0700 | [diff] [blame] | 1385 | SkBitmap bmp = capture_bitmap(orig); |
| 1386 | if (!bmp.isNull()) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1387 | static int gSampleGrabCounter; |
| 1388 | SkString name; |
reed@google.com | 7c57e0e | 2012-09-08 21:20:33 +0000 | [diff] [blame] | 1389 | name.printf("sample_grab_%d.png", gSampleGrabCounter++); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1390 | SkImageEncoder::EncodeFile(name.c_str(), bmp, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1391 | SkImageEncoder::kPNG_Type, 100); |
| 1392 | } |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1393 | this->inval(nullptr); |
| 1394 | return; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1397 | if (fSaveToSKP) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1398 | sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture()); |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1399 | SkFILEWStream stream("sample_app.skp"); |
| 1400 | picture->serialize(&stream); |
| 1401 | fSaveToSKP = false; |
| 1402 | this->inval(nullptr); |
| 1403 | return; |
| 1404 | } |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 1405 | |
reed | 91b4dfb | 2016-01-08 08:23:19 -0800 | [diff] [blame] | 1406 | if (fUsePicture) { |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 1407 | if (true) { |
| 1408 | fPipeSerializer.endWrite(); |
| 1409 | sk_sp<SkData> data(fPipeStream->detachAsData()); |
| 1410 | fPipeDeserializer.playback(data->data(), data->size(), orig); |
| 1411 | fPipeStream.reset(); |
| 1412 | } else { |
| 1413 | sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture()); |
| 1414 | orig->drawPicture(picture.get()); |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 1415 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1416 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1417 | |
reed@google.com | 17d7aec | 2011-04-25 14:31:44 +0000 | [diff] [blame] | 1418 | // Do this after presentGL and other finishing, rather than in afterChild |
jvanverth | 4d0d81a | 2015-08-11 11:07:07 -0700 | [diff] [blame] | 1419 | if (fMeasureFPS) { |
reed | b2ce0b0 | 2015-11-09 13:10:30 -0800 | [diff] [blame] | 1420 | orig->flush(); |
jvanverth | 4d0d81a | 2015-08-11 11:07:07 -0700 | [diff] [blame] | 1421 | fTimer.end(); |
| 1422 | fMeasureFPS_Time += fTimer.fWall; |
reed@google.com | 17d7aec | 2011-04-25 14:31:44 +0000 | [diff] [blame] | 1423 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1426 | void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1427 | if (fRotate) { |
| 1428 | SkScalar cx = this->width() / 2; |
| 1429 | SkScalar cy = this->height() / 2; |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 1430 | canvas->rotate(gAnimTimer.scaled(10), cx, cy); |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1431 | } |
bungeman@google.com | b178591 | 2013-07-09 21:58:56 +0000 | [diff] [blame] | 1432 | |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1433 | if (fPerspAnim) { |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1434 | SkScalar secs = gAnimTimer.scaled(1); |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 1435 | |
| 1436 | static const SkScalar gAnimPeriod = 10 * SK_Scalar1; |
| 1437 | static const SkScalar gAnimMag = SK_Scalar1 / 1000; |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1438 | SkScalar t = SkScalarMod(secs, gAnimPeriod); |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1439 | if (SkScalarFloorToInt(secs / gAnimPeriod) & 0x1) { |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 1440 | t = gAnimPeriod - t; |
| 1441 | } |
| 1442 | t = 2 * t - gAnimPeriod; |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1443 | t *= gAnimMag / gAnimPeriod; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 1444 | SkMatrix m; |
| 1445 | m.reset(); |
reed | 5d9ab28 | 2014-09-19 13:04:17 -0700 | [diff] [blame] | 1446 | #if 1 |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 1447 | m.setPerspY(t); |
reed | 5d9ab28 | 2014-09-19 13:04:17 -0700 | [diff] [blame] | 1448 | #else |
| 1449 | m.setPerspY(SK_Scalar1 / 1000); |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1450 | m.setSkewX(8.0f / 25); |
reed | 5d9ab28 | 2014-09-19 13:04:17 -0700 | [diff] [blame] | 1451 | m.dump(); |
| 1452 | #endif |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1453 | canvas->concat(m); |
| 1454 | } |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 1455 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1456 | if (fMeasureFPS) { |
jvanverth | 4d0d81a | 2015-08-11 11:07:07 -0700 | [diff] [blame] | 1457 | (void)SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT); |
| 1458 | fTimer.start(); |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 1459 | } else { |
| 1460 | (void)SampleView::SetRepeatDraw(child, 1); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1461 | } |
bungeman@google.com | b178591 | 2013-07-09 21:58:56 +0000 | [diff] [blame] | 1462 | if (fPerspAnim || fRotate) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1463 | this->inval(nullptr); |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1464 | } |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1467 | void SampleWindow::changeOffset(SkVector delta) { |
| 1468 | fOffset += delta; |
| 1469 | this->updateMatrix(); |
| 1470 | } |
| 1471 | |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1472 | void SampleWindow::changeZoomLevel(float delta) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 1473 | fZoomLevel += delta; |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1474 | if (fZoomLevel > 0) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1475 | fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); |
| 1476 | fZoomScale = fZoomLevel + SK_Scalar1; |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1477 | } else if (fZoomLevel < 0) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1478 | fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); |
| 1479 | fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1480 | } else { |
| 1481 | fZoomScale = SK_Scalar1; |
| 1482 | } |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1483 | this->updateMatrix(); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1486 | void SampleWindow::updateMatrix(){ |
| 1487 | SkMatrix m; |
| 1488 | m.reset(); |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1489 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1490 | if (fZoomLevel) { |
| 1491 | SkPoint center; |
| 1492 | //m = this->getLocalMatrix();//.invert(&m); |
| 1493 | m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); |
| 1494 | SkScalar cx = center.fX; |
| 1495 | SkScalar cy = center.fY; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1496 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1497 | m.setTranslate(-cx, -cy); |
| 1498 | m.postScale(fZoomScale, fZoomScale); |
| 1499 | m.postTranslate(cx, cy); |
| 1500 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1501 | |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1502 | m.postTranslate(fOffset.fX, fOffset.fY); |
| 1503 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1504 | if (fFlipAxis) { |
| 1505 | m.preTranslate(fZoomCenterX, fZoomCenterY); |
| 1506 | if (fFlipAxis & kFlipAxis_X) { |
| 1507 | m.preScale(-SK_Scalar1, SK_Scalar1); |
| 1508 | } |
| 1509 | if (fFlipAxis & kFlipAxis_Y) { |
| 1510 | m.preScale(SK_Scalar1, -SK_Scalar1); |
| 1511 | } |
| 1512 | m.preTranslate(-fZoomCenterX, -fZoomCenterY); |
| 1513 | //canvas->concat(m); |
| 1514 | } |
| 1515 | // Apply any gesture matrix |
| 1516 | m.preConcat(fGesture.localM()); |
| 1517 | m.preConcat(fGesture.globalM()); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1518 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1519 | this->setLocalMatrix(m); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1520 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1521 | this->updateTitle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1522 | this->inval(nullptr); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1523 | } |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1524 | bool SampleWindow::previousSample() { |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 1525 | fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count(); |
reed | 63121f0 | 2015-01-13 19:43:04 -0800 | [diff] [blame] | 1526 | this->loadView((*fSamples[fCurrIndex])()); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1527 | return true; |
| 1528 | } |
| 1529 | |
reed | 216b643 | 2015-08-19 12:25:40 -0700 | [diff] [blame] | 1530 | #include "SkResourceCache.h" |
| 1531 | #include "SkGlyphCache.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1532 | bool SampleWindow::nextSample() { |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1533 | fCurrIndex = (fCurrIndex + 1) % fSamples.count(); |
reed | 63121f0 | 2015-01-13 19:43:04 -0800 | [diff] [blame] | 1534 | this->loadView((*fSamples[fCurrIndex])()); |
reed | 216b643 | 2015-08-19 12:25:40 -0700 | [diff] [blame] | 1535 | |
| 1536 | if (false) { |
| 1537 | SkResourceCache::TestDumpMemoryStatistics(); |
| 1538 | SkGlyphCache::Dump(); |
| 1539 | SkDebugf("\n"); |
| 1540 | } |
| 1541 | |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1542 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1545 | bool SampleWindow::goToSample(int i) { |
| 1546 | fCurrIndex = (i) % fSamples.count(); |
reed | 63121f0 | 2015-01-13 19:43:04 -0800 | [diff] [blame] | 1547 | this->loadView((*fSamples[fCurrIndex])()); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1548 | return true; |
| 1549 | } |
| 1550 | |
| 1551 | SkString SampleWindow::getSampleTitle(int i) { |
edisonn@google.com | f8b6b01 | 2013-07-11 14:28:04 +0000 | [diff] [blame] | 1552 | return ::getSampleTitle(fSamples[i]); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | int SampleWindow::sampleCount() { |
| 1556 | return fSamples.count(); |
| 1557 | } |
| 1558 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1559 | void SampleWindow::showOverview() { |
reed | 63121f0 | 2015-01-13 19:43:04 -0800 | [diff] [blame] | 1560 | this->loadView(create_overview(fSamples.count(), fSamples.begin())); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1563 | void SampleWindow::postAnimatingEvent() { |
| 1564 | if (fAnimating) { |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 1565 | (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATING_DELAY); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 1568 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1569 | bool SampleWindow::onEvent(const SkEvent& evt) { |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 1570 | if (evt.isType(gUpdateWindowTitleEvtName)) { |
| 1571 | this->updateTitle(); |
| 1572 | return true; |
| 1573 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1574 | if (evt.isType(ANIMATING_EVENTTYPE)) { |
| 1575 | if (fAnimating) { |
| 1576 | this->nextSample(); |
| 1577 | this->postAnimatingEvent(); |
| 1578 | } |
| 1579 | return true; |
| 1580 | } |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1581 | if (evt.isType("set-curr-index")) { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1582 | this->goToSample(evt.getFast32()); |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1583 | return true; |
| 1584 | } |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1585 | if (isInvalEvent(evt)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1586 | this->inval(nullptr); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1587 | return true; |
| 1588 | } |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1589 | int selected = -1; |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1590 | if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1591 | this->setDeviceType((DeviceType)selected); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1592 | return true; |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1593 | } |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 1594 | if (SkOSMenu::FindListIndex(evt, "ColorType", &selected)) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 1595 | auto colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 1596 | if (kRGBA_F16_SkColorType == gConfig[selected].fColorType) { |
| 1597 | colorSpace = colorSpace->makeLinearGamma(); |
| 1598 | } |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 1599 | this->setDeviceColorType(gConfig[selected].fColorType, |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 1600 | gConfig[selected].fSRGB ? colorSpace : nullptr); |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 1601 | return true; |
| 1602 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1603 | if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1604 | this->toggleSlideshow(); |
| 1605 | return true; |
| 1606 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1607 | if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
| 1608 | SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 1609 | SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 1610 | SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || |
| 1611 | SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1612 | SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || |
| 1613 | SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || |
reed | a84d660 | 2016-06-24 18:14:07 -0700 | [diff] [blame] | 1614 | SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify)) |
reed | 093b4e8 | 2015-08-04 18:46:38 -0700 | [diff] [blame] | 1615 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1616 | this->inval(nullptr); |
commit-bot@chromium.org | bbe43a9 | 2013-12-10 21:51:06 +0000 | [diff] [blame] | 1617 | this->updateTitle(); |
| 1618 | return true; |
| 1619 | } |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 1620 | if (SkOSMenu::FindListIndex(evt, "Pixel Geometry", &fPixelGeometryIndex)) { |
| 1621 | this->setPixelGeometry(fPixelGeometryIndex); |
| 1622 | return true; |
| 1623 | } |
commit-bot@chromium.org | bbe43a9 | 2013-12-10 21:51:06 +0000 | [diff] [blame] | 1624 | if (SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) { |
| 1625 | if (SampleView::IsSampleView(curr_view(this))) { |
| 1626 | ((SampleView*)curr_view(this))->onTileSizeChanged(this->tileSize()); |
| 1627 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1628 | this->inval(nullptr); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1629 | this->updateTitle(); |
| 1630 | return true; |
| 1631 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1632 | if (SkOSMenu::FindSwitchState(evt, "Flip X", nullptr)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1633 | fFlipAxis ^= kFlipAxis_X; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1634 | this->updateMatrix(); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1635 | return true; |
| 1636 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1637 | if (SkOSMenu::FindSwitchState(evt, "Flip Y", nullptr)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1638 | fFlipAxis ^= kFlipAxis_Y; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1639 | this->updateMatrix(); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1640 | return true; |
| 1641 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1642 | if (SkOSMenu::FindAction(evt,"Save to PDF")) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1643 | this->saveToPdf(); |
| 1644 | return true; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1645 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1646 | return this->INHERITED::onEvent(evt); |
| 1647 | } |
| 1648 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1649 | bool SampleWindow::onQuery(SkEvent* query) { |
| 1650 | if (query->isType("get-slide-count")) { |
| 1651 | query->setFast32(fSamples.count()); |
| 1652 | return true; |
| 1653 | } |
| 1654 | if (query->isType("get-slide-title")) { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 1655 | SkView* view = (*fSamples[query->getFast32()])(); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1656 | SkEvent evt(gTitleEvtName); |
| 1657 | if (view->doQuery(&evt)) { |
| 1658 | query->setString("title", evt.findString(gTitleEvtName)); |
| 1659 | } |
| 1660 | SkSafeUnref(view); |
| 1661 | return true; |
| 1662 | } |
| 1663 | if (query->isType("use-fast-text")) { |
| 1664 | SkEvent evt(gFastTextEvtName); |
| 1665 | return curr_view(this)->doQuery(&evt); |
| 1666 | } |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1667 | if (query->isType("ignore-window-bitmap")) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1668 | query->setFast32(this->getGrContext() != nullptr); |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1669 | return true; |
| 1670 | } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1671 | return this->INHERITED::onQuery(query); |
| 1672 | } |
| 1673 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 1674 | DECLARE_bool(portableFonts); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 1675 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1676 | bool SampleWindow::onHandleChar(SkUnichar uni) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1677 | { |
| 1678 | SkView* view = curr_view(this); |
| 1679 | if (view) { |
| 1680 | SkEvent evt(gCharEvtName); |
| 1681 | evt.setFast32(uni); |
| 1682 | if (view->doQuery(&evt)) { |
| 1683 | return true; |
| 1684 | } |
| 1685 | } |
| 1686 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1687 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1688 | int dx = 0xFF; |
| 1689 | int dy = 0xFF; |
| 1690 | |
| 1691 | switch (uni) { |
| 1692 | case '5': dx = 0; dy = 0; break; |
| 1693 | case '8': dx = 0; dy = -1; break; |
| 1694 | case '6': dx = 1; dy = 0; break; |
| 1695 | case '2': dx = 0; dy = 1; break; |
| 1696 | case '4': dx = -1; dy = 0; break; |
| 1697 | case '7': dx = -1; dy = -1; break; |
| 1698 | case '9': dx = 1; dy = -1; break; |
| 1699 | case '3': dx = 1; dy = 1; break; |
| 1700 | case '1': dx = -1; dy = 1; break; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1701 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1702 | default: |
| 1703 | break; |
| 1704 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1705 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1706 | if (0xFF != dx && 0xFF != dy) { |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1707 | this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)}); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1708 | return true; |
| 1709 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1710 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1711 | switch (uni) { |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1712 | case 27: // ESC |
| 1713 | gAnimTimer.stop(); |
| 1714 | if (this->sendAnimatePulse()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1715 | this->inval(nullptr); |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1716 | } |
| 1717 | break; |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 1718 | case ' ': |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 1719 | gAnimTimer.togglePauseResume(); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 1720 | if (this->sendAnimatePulse()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1721 | this->inval(nullptr); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 1722 | } |
| 1723 | break; |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1724 | case 'B': |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1725 | post_event_to_sink(new SkEvent("PictFileView::toggleBBox"), curr_view(this)); |
commit-bot@chromium.org | 6de4a78 | 2013-12-11 17:05:23 +0000 | [diff] [blame] | 1726 | // Cannot call updateTitle() synchronously, because the toggleBBox event is still in |
| 1727 | // the queue. |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1728 | post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1729 | this->inval(nullptr); |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1730 | break; |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 1731 | case 'D': |
| 1732 | toggleDistanceFieldFonts(); |
| 1733 | break; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 1734 | case 'E': |
| 1735 | fUseDeferredCanvas = !fUseDeferredCanvas; |
| 1736 | this->inval(nullptr); |
| 1737 | break; |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1738 | case 'f': |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1739 | // only |
djsollen@google.com | 6ff8255 | 2011-11-07 15:43:57 +0000 | [diff] [blame] | 1740 | toggleFPS(); |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1741 | break; |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 1742 | case 'F': |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 1743 | FLAGS_portableFonts ^= true; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1744 | this->inval(nullptr); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 1745 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1746 | case 'g': |
| 1747 | fRequestGrabImage = true; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1748 | this->inval(nullptr); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1749 | break; |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1750 | case 'G': |
| 1751 | gShowGMBounds = !gShowGMBounds; |
commit-bot@chromium.org | 6de4a78 | 2013-12-11 17:05:23 +0000 | [diff] [blame] | 1752 | post_event_to_sink(GMSampleView::NewShowSizeEvt(gShowGMBounds), |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1753 | curr_view(this)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1754 | this->inval(nullptr); |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1755 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1756 | case 'i': |
| 1757 | this->zoomIn(); |
| 1758 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1759 | case 'o': |
| 1760 | this->zoomOut(); |
| 1761 | break; |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1762 | case 'r': |
| 1763 | fRotate = !fRotate; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1764 | this->inval(nullptr); |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1765 | this->updateTitle(); |
| 1766 | return true; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1767 | case 'k': |
| 1768 | fPerspAnim = !fPerspAnim; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1769 | this->inval(nullptr); |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1770 | this->updateTitle(); |
| 1771 | return true; |
reed | 093b4e8 | 2015-08-04 18:46:38 -0700 | [diff] [blame] | 1772 | case 'K': |
| 1773 | fSaveToSKP = true; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1774 | this->inval(nullptr); |
reed | 093b4e8 | 2015-08-04 18:46:38 -0700 | [diff] [blame] | 1775 | return true; |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1776 | case 'M': |
reed | 91b4dfb | 2016-01-08 08:23:19 -0800 | [diff] [blame] | 1777 | fUsePicture = !fUsePicture; |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 1778 | this->inval(nullptr); |
| 1779 | this->updateTitle(); |
| 1780 | return true; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1781 | #if SK_SUPPORT_GPU |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 1782 | case 'p': |
| 1783 | { |
| 1784 | GrContext* grContext = this->getGrContext(); |
| 1785 | if (grContext) { |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1786 | size_t cacheBytes; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1787 | grContext->getResourceCacheUsage(nullptr, &cacheBytes); |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 1788 | grContext->freeGpuResources(); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1789 | SkDebugf("Purged %d bytes from the GPU resource cache.\n", cacheBytes); |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | return true; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1793 | #endif |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1794 | default: |
| 1795 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1796 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1797 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 1798 | if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni)) { |
| 1799 | this->onUpdateMenu(fAppMenu); |
| 1800 | this->onUpdateMenu(fSlideMenu); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1801 | return true; |
| 1802 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1803 | return this->INHERITED::onHandleChar(uni); |
| 1804 | } |
| 1805 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1806 | void SampleWindow::setDeviceType(DeviceType type) { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1807 | if (type == fDeviceType) |
| 1808 | return; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1809 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 1810 | fDevManager->tearDownBackend(this); |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 1811 | fDeviceType = type; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 1812 | fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1813 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 1814 | this->updateTitle(); |
| 1815 | this->inval(nullptr); |
| 1816 | } |
| 1817 | |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 1818 | void SampleWindow::setDeviceColorType(SkColorType ct, sk_sp<SkColorSpace> cs) { |
| 1819 | this->setColorType(ct, std::move(cs)); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1820 | |
| 1821 | fDevManager->tearDownBackend(this); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 1822 | fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1823 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1824 | this->updateTitle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1825 | this->inval(nullptr); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1828 | void SampleWindow::toggleSlideshow() { |
| 1829 | fAnimating = !fAnimating; |
| 1830 | this->postAnimatingEvent(); |
| 1831 | this->updateTitle(); |
| 1832 | } |
| 1833 | |
| 1834 | void SampleWindow::toggleRendering() { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1835 | this->setDeviceType(cycle_devicetype(fDeviceType)); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1836 | this->updateTitle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1837 | this->inval(nullptr); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
djsollen@google.com | 6ff8255 | 2011-11-07 15:43:57 +0000 | [diff] [blame] | 1840 | void SampleWindow::toggleFPS() { |
| 1841 | fMeasureFPS = !fMeasureFPS; |
| 1842 | this->updateTitle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1843 | this->inval(nullptr); |
djsollen@google.com | 6ff8255 | 2011-11-07 15:43:57 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 1846 | void SampleWindow::toggleDistanceFieldFonts() { |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 1847 | // reset backend |
| 1848 | fDevManager->tearDownBackend(this); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 1849 | fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 1850 | |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 1851 | SkSurfaceProps props = this->getSurfaceProps(); |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 1852 | uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_Flag; |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 1853 | this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); |
| 1854 | |
| 1855 | this->updateTitle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1856 | this->inval(nullptr); |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 1859 | void SampleWindow::setPixelGeometry(int pixelGeometryIndex) { |
| 1860 | // reset backend |
| 1861 | fDevManager->tearDownBackend(this); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 1862 | fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 1863 | |
| 1864 | const SkSurfaceProps& oldProps = this->getSurfaceProps(); |
| 1865 | SkSurfaceProps newProps(oldProps.flags(), SkSurfaceProps::kLegacyFontHost_InitType); |
| 1866 | if (pixelGeometryIndex > 0) { |
| 1867 | newProps = SkSurfaceProps(oldProps.flags(), |
| 1868 | gPixelGeometryStates[pixelGeometryIndex].pixelGeometry); |
| 1869 | } |
| 1870 | this->setSurfaceProps(newProps); |
| 1871 | |
| 1872 | this->updateTitle(); |
| 1873 | this->inval(nullptr); |
| 1874 | } |
| 1875 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1876 | #include "SkDumpCanvas.h" |
| 1877 | |
| 1878 | bool SampleWindow::onHandleKey(SkKey key) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1879 | { |
| 1880 | SkView* view = curr_view(this); |
| 1881 | if (view) { |
| 1882 | SkEvent evt(gKeyEvtName); |
| 1883 | evt.setFast32(key); |
| 1884 | if (view->doQuery(&evt)) { |
| 1885 | return true; |
| 1886 | } |
| 1887 | } |
| 1888 | } |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1889 | |
| 1890 | int dx = 0xFF; |
| 1891 | int dy = 0xFF; |
| 1892 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1893 | switch (key) { |
| 1894 | case kRight_SkKey: |
| 1895 | if (this->nextSample()) { |
| 1896 | return true; |
| 1897 | } |
| 1898 | break; |
| 1899 | case kLeft_SkKey: |
scroggo@google.com | e2dd973 | 2012-08-15 20:03:06 +0000 | [diff] [blame] | 1900 | if (this->previousSample()) { |
| 1901 | return true; |
| 1902 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1903 | return true; |
| 1904 | case kUp_SkKey: |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1905 | this->changeZoomLevel(1.f / 32.f); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1906 | return true; |
| 1907 | case kDown_SkKey: |
reed | f7f79d2 | 2015-02-21 09:03:20 -0800 | [diff] [blame] | 1908 | this->changeZoomLevel(-1.f / 32.f); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1909 | return true; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1910 | case kOK_SkKey: { |
| 1911 | SkString title; |
| 1912 | if (curr_title(this, &title)) { |
| 1913 | writeTitleToPrefs(title.c_str()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1914 | } |
| 1915 | return true; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1916 | } |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1917 | case kBack_SkKey: |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1918 | this->showOverview(); |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1919 | return true; |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1920 | |
| 1921 | case k5_SkKey: dx = 0; dy = 0; break; |
| 1922 | case k8_SkKey: dx = 0; dy = -1; break; |
| 1923 | case k6_SkKey: dx = 1; dy = 0; break; |
| 1924 | case k2_SkKey: dx = 0; dy = 1; break; |
| 1925 | case k4_SkKey: dx = -1; dy = 0; break; |
| 1926 | case k7_SkKey: dx = -1; dy = -1; break; |
| 1927 | case k9_SkKey: dx = 1; dy = -1; break; |
| 1928 | case k3_SkKey: dx = 1; dy = 1; break; |
| 1929 | case k1_SkKey: dx = -1; dy = 1; break; |
| 1930 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1931 | default: |
| 1932 | break; |
| 1933 | } |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 1934 | |
| 1935 | if (0xFF != dx && 0xFF != dy) { |
| 1936 | this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)}); |
| 1937 | return true; |
| 1938 | } |
| 1939 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1940 | return this->INHERITED::onHandleKey(key); |
| 1941 | } |
| 1942 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1943 | /////////////////////////////////////////////////////////////////////////////// |
| 1944 | |
| 1945 | static const char gGestureClickType[] = "GestureClickType"; |
| 1946 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 1947 | bool SampleWindow::onDispatchClick(int x, int y, Click::State state, |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1948 | void* owner, unsigned modi) { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1949 | if (Click::kMoved_State == state) { |
| 1950 | updatePointer(x, y); |
| 1951 | } |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 1952 | int w = SkScalarRoundToInt(this->width()); |
| 1953 | int h = SkScalarRoundToInt(this->height()); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1954 | |
| 1955 | // check for the resize-box |
| 1956 | if (w - x < 16 && h - y < 16) { |
| 1957 | return false; // let the OS handle the click |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1958 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1959 | else if (fMagnify) { |
| 1960 | //it's only necessary to update the drawing if there's a click |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1961 | this->inval(nullptr); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1962 | return false; //prevent dragging while magnify is enabled |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1963 | } else { |
| 1964 | // capture control+option, and trigger debugger |
| 1965 | if ((modi & kControl_SkModifierKey) && (modi & kOption_SkModifierKey)) { |
| 1966 | if (Click::kDown_State == state) { |
| 1967 | SkEvent evt("debug-hit-test"); |
| 1968 | evt.setS32("debug-hit-test-x", x); |
| 1969 | evt.setS32("debug-hit-test-y", y); |
| 1970 | curr_view(this)->doEvent(evt); |
| 1971 | } |
| 1972 | return true; |
| 1973 | } else { |
| 1974 | return this->INHERITED::onDispatchClick(x, y, state, owner, modi); |
| 1975 | } |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1979 | class GestureClick : public SkView::Click { |
| 1980 | public: |
| 1981 | GestureClick(SkView* target) : SkView::Click(target) { |
| 1982 | this->setType(gGestureClickType); |
| 1983 | } |
| 1984 | |
| 1985 | static bool IsGesture(Click* click) { |
| 1986 | return click->isType(gGestureClickType); |
| 1987 | } |
| 1988 | }; |
| 1989 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1990 | SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y, |
| 1991 | unsigned modi) { |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1992 | return new GestureClick(this); |
| 1993 | } |
| 1994 | |
| 1995 | bool SampleWindow::onClick(Click* click) { |
| 1996 | if (GestureClick::IsGesture(click)) { |
bsalomon@google.com | 4d4f281 | 2011-12-12 18:34:01 +0000 | [diff] [blame] | 1997 | float x = static_cast<float>(click->fICurr.fX); |
| 1998 | float y = static_cast<float>(click->fICurr.fY); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1999 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 2000 | switch (click->fState) { |
| 2001 | case SkView::Click::kDown_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 2002 | fGesture.touchBegin(click->fOwner, x, y); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 2003 | break; |
| 2004 | case SkView::Click::kMoved_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 2005 | fGesture.touchMoved(click->fOwner, x, y); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 2006 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 2007 | break; |
| 2008 | case SkView::Click::kUp_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 2009 | fGesture.touchEnd(click->fOwner); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 2010 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 2011 | break; |
| 2012 | } |
| 2013 | return true; |
| 2014 | } |
| 2015 | return false; |
| 2016 | } |
| 2017 | |
| 2018 | /////////////////////////////////////////////////////////////////////////////// |
| 2019 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2020 | void SampleWindow::loadView(SkView* view) { |
| 2021 | SkView::F2BIter iter(this); |
| 2022 | SkView* prev = iter.next(); |
| 2023 | if (prev) { |
| 2024 | prev->detachFromParent(); |
| 2025 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2026 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2027 | view->setVisibleP(true); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2028 | view->setClipToBounds(false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2029 | this->attachChildToFront(view)->unref(); |
| 2030 | view->setSize(this->width(), this->height()); |
| 2031 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 2032 | //repopulate the slide menu when a view is loaded |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 2033 | fSlideMenu->reset(); |
djsollen@google.com | 388974f | 2013-01-17 13:20:01 +0000 | [diff] [blame] | 2034 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 2035 | this->onUpdateMenu(fSlideMenu); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2036 | this->updateTitle(); |
| 2037 | } |
| 2038 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2039 | static const char* gDeviceTypePrefix[] = { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2040 | "raster: ", |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2041 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 2042 | "opengl: ", |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 2043 | #if SK_ANGLE |
| 2044 | "angle: ", |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2045 | #endif // SK_ANGLE |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2046 | #endif // SK_SUPPORT_GPU |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2047 | }; |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 2048 | static_assert(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt, |
| 2049 | "array_size_mismatch"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2050 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2051 | static const char* trystate_str(SkOSMenu::TriState state, |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2052 | const char trueStr[], const char falseStr[]) { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2053 | if (SkOSMenu::kOnState == state) { |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2054 | return trueStr; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2055 | } else if (SkOSMenu::kOffState == state) { |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2056 | return falseStr; |
| 2057 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2058 | return nullptr; |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 2061 | bool SampleWindow::getRawTitle(SkString* title) { |
| 2062 | return curr_title(this, title); |
| 2063 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2064 | |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 2065 | void SampleWindow::updateTitle() { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 2066 | SkString title; |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 2067 | if (!this->getRawTitle(&title)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2068 | title.set("<unknown>"); |
| 2069 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2070 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2071 | title.prepend(gDeviceTypePrefix[fDeviceType]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2072 | |
commit-bot@chromium.org | cc63b32 | 2013-12-06 20:14:55 +0000 | [diff] [blame] | 2073 | if (fTilingMode != kNo_Tiling) { |
| 2074 | title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); |
| 2075 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2076 | if (fAnimating) { |
| 2077 | title.prepend("<A> "); |
| 2078 | } |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 2079 | if (fRotate) { |
| 2080 | title.prepend("<R> "); |
| 2081 | } |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 2082 | if (fPerspAnim) { |
| 2083 | title.prepend("<K> "); |
| 2084 | } |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 2085 | if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDeviceIndependentFonts_Flag) { |
| 2086 | title.prepend("<DIF> "); |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 2087 | } |
reed | 91b4dfb | 2016-01-08 08:23:19 -0800 | [diff] [blame] | 2088 | if (fUsePicture) { |
| 2089 | title.prepend("<P> "); |
kkinnunen | 8686a5e | 2016-01-05 00:04:32 -0800 | [diff] [blame] | 2090 | } |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 2091 | if (fUseDeferredCanvas) { |
| 2092 | title.prepend("<E> "); |
| 2093 | } |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2094 | |
| 2095 | title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); |
| 2096 | title.prepend(trystate_str(fAAState, "AA ", "aa ")); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 2097 | title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel); |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 2098 | title.prepend(trystate_str(fSubpixelState, "S ", "s ")); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2099 | title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr); |
| 2100 | title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr); |
bungeman@google.com | 96aabc8 | 2013-06-03 21:26:34 +0000 | [diff] [blame] | 2101 | title.prepend(gHintingStates[fHintingState].label); |
bungeman | 5a59a42 | 2016-03-31 08:30:38 -0700 | [diff] [blame] | 2102 | title.prepend(gPixelGeometryStates[fPixelGeometryIndex].label); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 2103 | |
bungeman | ce56026 | 2016-03-03 13:32:38 -0800 | [diff] [blame] | 2104 | if (fOffset.fX || fOffset.fY) { |
| 2105 | title.prependf("(%.2f, %.2f) ", SkScalarToFloat(fOffset.fX), SkScalarToFloat(fOffset.fY)); |
| 2106 | } |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 2107 | if (fZoomLevel) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 2108 | title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 2109 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2110 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2111 | if (fMeasureFPS) { |
jvanverth | 4d0d81a | 2015-08-11 11:07:07 -0700 | [diff] [blame] | 2112 | title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2113 | } |
reed | ddb5eca | 2014-10-08 11:10:51 -0700 | [diff] [blame] | 2114 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2115 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame] | 2116 | if (IsGpuDeviceType(fDeviceType) && |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2117 | fDevManager && |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 2118 | fDevManager->numColorSamples() > 0) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 2119 | title.appendf(" [MSAA: %d]", |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 2120 | fDevManager->numColorSamples()); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 2121 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2122 | #endif |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 2123 | |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 2124 | title.appendf(" %s", find_config_name(this->info())); |
| 2125 | |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 2126 | if (fDevManager && fDevManager->getColorBits() > 24) { |
| 2127 | title.appendf(" %d bpc", fDevManager->getColorBits()); |
| 2128 | } |
| 2129 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2130 | this->setTitle(title.c_str()); |
| 2131 | } |
| 2132 | |
| 2133 | void SampleWindow::onSizeChange() { |
| 2134 | this->INHERITED::onSizeChange(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2135 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2136 | SkView::F2BIter iter(this); |
| 2137 | SkView* view = iter.next(); |
| 2138 | view->setSize(this->width(), this->height()); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2139 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2140 | // rebuild our clippath |
| 2141 | { |
| 2142 | const SkScalar W = this->width(); |
| 2143 | const SkScalar H = this->height(); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2144 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2145 | fClipPath.reset(); |
| 2146 | #if 0 |
| 2147 | for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) { |
| 2148 | SkRect r; |
| 2149 | r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30)); |
| 2150 | for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0)) |
| 2151 | fClipPath.addRect(r); |
| 2152 | } |
| 2153 | #else |
| 2154 | SkRect r; |
| 2155 | r.set(0, 0, W, H); |
| 2156 | fClipPath.addRect(r, SkPath::kCCW_Direction); |
| 2157 | r.set(W/4, H/4, W*3/4, H*3/4); |
| 2158 | fClipPath.addRect(r, SkPath::kCW_Direction); |
| 2159 | #endif |
| 2160 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2161 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 2162 | fZoomCenterX = SkScalarHalf(this->width()); |
| 2163 | fZoomCenterY = SkScalarHalf(this->height()); |
| 2164 | |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 2165 | #ifdef SK_BUILD_FOR_ANDROID |
Scroggo | b4490c7 | 2011-06-17 13:53:05 +0000 | [diff] [blame] | 2166 | // FIXME: The first draw after a size change does not work on Android, so |
| 2167 | // we post an invalidate. |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 2168 | this->postInvalDelay(); |
Scroggo | 716a038 | 2011-06-16 14:00:15 +0000 | [diff] [blame] | 2169 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2170 | this->updateTitle(); // to refresh our config |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2171 | fDevManager->windowSizeChanged(this); |
commit-bot@chromium.org | bbe43a9 | 2013-12-10 21:51:06 +0000 | [diff] [blame] | 2172 | |
| 2173 | if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) { |
| 2174 | ((SampleView*)view)->onTileSizeChanged(this->tileSize()); |
| 2175 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | /////////////////////////////////////////////////////////////////////////////// |
| 2179 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2180 | template <typename T> void SkTBSort(T array[], int count) { |
| 2181 | for (int i = 1; i < count - 1; i++) { |
| 2182 | bool didSwap = false; |
| 2183 | for (int j = count - 1; j > i; --j) { |
| 2184 | if (array[j] < array[j-1]) { |
| 2185 | T tmp(array[j-1]); |
| 2186 | array[j-1] = array[j]; |
| 2187 | array[j] = tmp; |
| 2188 | didSwap = true; |
| 2189 | } |
| 2190 | } |
| 2191 | if (!didSwap) { |
| 2192 | break; |
| 2193 | } |
| 2194 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2195 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2196 | for (int k = 0; k < count - 1; k++) { |
| 2197 | SkASSERT(!(array[k+1] < array[k])); |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | #include "SkRandom.h" |
| 2202 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 2203 | static void rand_rect(SkIRect* rect, SkRandom& rand) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2204 | int bits = 8; |
| 2205 | int shift = 32 - bits; |
| 2206 | rect->set(rand.nextU() >> shift, rand.nextU() >> shift, |
| 2207 | rand.nextU() >> shift, rand.nextU() >> shift); |
| 2208 | rect->sort(); |
| 2209 | } |
| 2210 | |
| 2211 | static void dumpRect(const SkIRect& r) { |
| 2212 | SkDebugf(" { %d, %d, %d, %d },\n", |
| 2213 | r.fLeft, r.fTop, |
| 2214 | r.fRight, r.fBottom); |
| 2215 | } |
| 2216 | |
| 2217 | static void test_rects(const SkIRect rect[], int count) { |
| 2218 | SkRegion rgn0, rgn1; |
| 2219 | |
| 2220 | for (int i = 0; i < count; i++) { |
| 2221 | rgn0.op(rect[i], SkRegion::kUnion_Op); |
| 2222 | // dumpRect(rect[i]); |
| 2223 | } |
| 2224 | rgn1.setRects(rect, count); |
| 2225 | |
| 2226 | if (rgn0 != rgn1) { |
| 2227 | SkDebugf("\n"); |
| 2228 | for (int i = 0; i < count; i++) { |
| 2229 | dumpRect(rect[i]); |
| 2230 | } |
| 2231 | SkDebugf("\n"); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | static void test() { |
| 2236 | size_t i; |
| 2237 | |
| 2238 | const SkIRect r0[] = { |
| 2239 | { 0, 0, 1, 1 }, |
| 2240 | { 2, 2, 3, 3 }, |
| 2241 | }; |
| 2242 | const SkIRect r1[] = { |
| 2243 | { 0, 0, 1, 3 }, |
| 2244 | { 1, 1, 2, 2 }, |
| 2245 | { 2, 0, 3, 3 }, |
| 2246 | }; |
| 2247 | const SkIRect r2[] = { |
| 2248 | { 0, 0, 1, 2 }, |
| 2249 | { 2, 1, 3, 3 }, |
| 2250 | { 4, 0, 5, 1 }, |
| 2251 | { 6, 0, 7, 4 }, |
| 2252 | }; |
| 2253 | |
| 2254 | static const struct { |
| 2255 | const SkIRect* fRects; |
| 2256 | int fCount; |
| 2257 | } gRecs[] = { |
| 2258 | { r0, SK_ARRAY_COUNT(r0) }, |
| 2259 | { r1, SK_ARRAY_COUNT(r1) }, |
| 2260 | { r2, SK_ARRAY_COUNT(r2) }, |
| 2261 | }; |
| 2262 | |
| 2263 | for (i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 2264 | test_rects(gRecs[i].fRects, gRecs[i].fCount); |
| 2265 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2266 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 2267 | SkRandom rand; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2268 | for (i = 0; i < 10000; i++) { |
| 2269 | SkRegion rgn0, rgn1; |
| 2270 | |
| 2271 | const int N = 8; |
| 2272 | SkIRect rect[N]; |
| 2273 | for (int j = 0; j < N; j++) { |
| 2274 | rand_rect(&rect[j], rand); |
| 2275 | } |
| 2276 | test_rects(rect, N); |
| 2277 | } |
| 2278 | } |
| 2279 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2280 | // FIXME: this should be in a header |
| 2281 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 2282 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2283 | if (false) { // avoid bit rot, suppress warning |
| 2284 | test(); |
| 2285 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2286 | return new SampleWindow(hwnd, argc, argv, nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2289 | // FIXME: this should be in a header |
| 2290 | void get_preferred_size(int* x, int* y, int* width, int* height); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2291 | void get_preferred_size(int* x, int* y, int* width, int* height) { |
| 2292 | *x = 10; |
| 2293 | *y = 50; |
| 2294 | *width = 640; |
| 2295 | *height = 480; |
| 2296 | } |
| 2297 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2298 | #ifdef SK_BUILD_FOR_IOS |
reed | f0b1710 | 2014-10-22 13:06:00 -0700 | [diff] [blame] | 2299 | #include "SkApplication.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 2300 | IOS_launch_type set_cmd_line_args(int , char *[], const char* resourceDir) { |
caryclark | f568f6a | 2014-07-18 10:58:56 -0700 | [diff] [blame] | 2301 | SetResourcePath(resourceDir); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 2302 | return kApplication__iOSLaunchType; |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2303 | } |
| 2304 | #endif |
| 2305 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2306 | void application_init() { |
| 2307 | // setenv("ANDROID_ROOT", "../../../data", 0); |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 2308 | #ifdef SK_BUILD_FOR_MAC |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2309 | setenv("ANDROID_ROOT", "/android/device/data", 0); |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 2310 | #endif |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 2311 | SkGraphics::Init(); |
| 2312 | SkEvent::Init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | void application_term() { |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 2316 | SkEvent::Term(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2317 | } |