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