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