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