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 | */ |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 7 | #include "SampleApp.h" |
| 8 | |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 9 | #include "SkData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkDevice.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkGraphics.h" |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 13 | #include "SkImageEncoder.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkPaint.h" |
| 15 | #include "SkPicture.h" |
| 16 | #include "SkStream.h" |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 17 | #include "SkTime.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | #include "SkWindow.h" |
| 19 | |
| 20 | #include "SampleCode.h" |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 21 | #include "SkTypeface.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 23 | #if SK_SUPPORT_GPU |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 24 | #include "gl/GrGLInterface.h" |
bsalomon@google.com | 9c1f1ac | 2012-05-07 17:09:37 +0000 | [diff] [blame] | 25 | #include "gl/GrGLUtil.h" |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 26 | #include "GrRenderTarget.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 27 | #include "GrContext.h" |
| 28 | #include "SkGpuDevice.h" |
| 29 | #else |
| 30 | class GrContext; |
| 31 | #endif |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 32 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 33 | #include "SkOSFile.h" |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 34 | #include "SkPDFDevice.h" |
| 35 | #include "SkPDFDocument.h" |
| 36 | #include "SkStream.h" |
| 37 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 38 | #include "SkGPipe.h" |
| 39 | #include "SamplePipeControllers.h" |
tfarina@chromium.org | b1b7f707 | 2012-09-18 01:52:20 +0000 | [diff] [blame] | 40 | #include "OverView.h" |
epoger@google.com | 6a12178 | 2012-09-14 18:42:01 +0000 | [diff] [blame] | 41 | #include "TransitionView.h" |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 42 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 43 | SK_DEFINE_INST_COUNT(SampleWindow::DeviceManager) |
| 44 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 45 | extern SampleView* CreateSamplePictFileView(const char filename[]); |
| 46 | |
| 47 | class PictFileFactory : public SkViewFactory { |
| 48 | SkString fFilename; |
| 49 | public: |
| 50 | PictFileFactory(const SkString& filename) : fFilename(filename) {} |
| 51 | virtual SkView* operator() () const SK_OVERRIDE { |
| 52 | return CreateSamplePictFileView(fFilename.c_str()); |
| 53 | } |
| 54 | }; |
| 55 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 56 | #define PIPE_FILEx |
| 57 | #ifdef PIPE_FILE |
yangsu@google.com | 1f39421 | 2011-06-01 18:03:34 +0000 | [diff] [blame] | 58 | #define FILE_PATH "/path/to/drawing.data" |
| 59 | #endif |
| 60 | |
yangsu@google.com | f121b05 | 2011-08-08 16:02:51 +0000 | [diff] [blame] | 61 | #define PIPE_NETx |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 62 | #ifdef PIPE_NET |
| 63 | #include "SkSockets.h" |
| 64 | SkTCPServer gServer; |
| 65 | #endif |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 66 | |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 67 | #define USE_ARROWS_FOR_ZOOM true |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 68 | |
| 69 | #if SK_ANGLE |
| 70 | //#define DEFAULT_TO_ANGLE 1 |
| 71 | #else |
| 72 | //#define DEFAULT_TO_GPU 1 |
| 73 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 74 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | #define ANIMATING_EVENTTYPE "nextSample" |
| 76 | #define ANIMATING_DELAY 750 |
| 77 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 78 | #ifdef SK_DEBUG |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 79 | #define FPS_REPEAT_MULTIPLIER 1 |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 80 | #else |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 81 | #define FPS_REPEAT_MULTIPLIER 10 |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 82 | #endif |
reed@google.com | bad8c87 | 2011-05-18 20:10:31 +0000 | [diff] [blame] | 83 | #define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER) |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 84 | |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 85 | static SampleWindow* gSampleWindow; |
| 86 | |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 87 | static bool gShowGMBounds; |
| 88 | |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 89 | static void postEventToSink(SkEvent* evt, SkEventSink* sink) { |
| 90 | evt->setTargetID(sink->getSinkID())->post(); |
| 91 | } |
| 92 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 93 | /////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | static const char* skip_until(const char* str, const char* skip) { |
| 96 | if (!str) { |
| 97 | return NULL; |
| 98 | } |
| 99 | return strstr(str, skip); |
| 100 | } |
| 101 | |
| 102 | static const char* skip_past(const char* str, const char* skip) { |
| 103 | const char* found = skip_until(str, skip); |
| 104 | if (!found) { |
| 105 | return NULL; |
| 106 | } |
| 107 | return found + strlen(skip); |
| 108 | } |
| 109 | |
| 110 | static const char* gPrefFileName = "sampleapp_prefs.txt"; |
| 111 | |
epoger@google.com | 6fc7cc2 | 2011-12-28 15:13:41 +0000 | [diff] [blame] | 112 | static bool readTitleFromPrefs(SkString* title) { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 113 | SkFILEStream stream(gPrefFileName); |
| 114 | if (!stream.isValid()) { |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | int len = stream.getLength(); |
| 119 | SkString data(len); |
| 120 | stream.read(data.writable_str(), len); |
| 121 | const char* s = data.c_str(); |
| 122 | |
| 123 | s = skip_past(s, "curr-slide-title"); |
| 124 | s = skip_past(s, "="); |
| 125 | s = skip_past(s, "\""); |
| 126 | const char* stop = skip_until(s, "\""); |
| 127 | if (stop > s) { |
| 128 | title->set(s, stop - s); |
| 129 | return true; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
epoger@google.com | 6fc7cc2 | 2011-12-28 15:13:41 +0000 | [diff] [blame] | 134 | static void writeTitleToPrefs(const char* title) { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 135 | SkFILEWStream stream(gPrefFileName); |
| 136 | SkString data; |
| 137 | data.printf("curr-slide-title = \"%s\"\n", title); |
| 138 | stream.write(data.c_str(), data.size()); |
| 139 | } |
| 140 | |
| 141 | /////////////////////////////////////////////////////////////////////////////// |
| 142 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 143 | class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager { |
| 144 | public: |
| 145 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 146 | DefaultDeviceManager() { |
| 147 | #if SK_SUPPORT_GPU |
| 148 | fCurContext = NULL; |
| 149 | fCurIntf = NULL; |
| 150 | fCurRenderTarget = NULL; |
| 151 | fMSAASampleCount = 0; |
| 152 | #endif |
| 153 | fBackend = kNone_BackEndType; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | virtual ~DefaultDeviceManager() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 157 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 158 | SkSafeUnref(fCurContext); |
| 159 | SkSafeUnref(fCurIntf); |
| 160 | SkSafeUnref(fCurRenderTarget); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 161 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 162 | } |
| 163 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 164 | virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 165 | SkASSERT(kNone_BackEndType == fBackend); |
robertphillips@google.com | 53e96a1 | 2012-03-30 14:47:53 +0000 | [diff] [blame] | 166 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 167 | fBackend = kNone_BackEndType; |
| 168 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 169 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 170 | switch (win->getDeviceType()) { |
| 171 | case kRaster_DeviceType: |
| 172 | // fallthrough |
| 173 | case kPicture_DeviceType: |
| 174 | // fallthrough |
| 175 | case kGPU_DeviceType: |
| 176 | // fallthrough |
| 177 | case kNullGPU_DeviceType: |
| 178 | // all these guys use the native backend |
| 179 | fBackend = kNativeGL_BackEndType; |
| 180 | break; |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 181 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 182 | case kANGLE_DeviceType: |
| 183 | // ANGLE is really the only odd man out |
| 184 | fBackend = kANGLE_BackEndType; |
| 185 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 186 | #endif // SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 187 | default: |
| 188 | SkASSERT(false); |
| 189 | break; |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 190 | } |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 191 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 192 | bool result = win->attach(fBackend, msaaSampleCount); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 193 | if (!result) { |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 194 | SkDebugf("Failed to initialize GL"); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 195 | return; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 196 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 197 | fMSAASampleCount = msaaSampleCount; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 198 | |
| 199 | SkASSERT(NULL == fCurIntf); |
| 200 | switch (win->getDeviceType()) { |
| 201 | case kRaster_DeviceType: |
| 202 | // fallthrough |
| 203 | case kPicture_DeviceType: |
| 204 | // fallthrough |
| 205 | case kGPU_DeviceType: |
| 206 | // all these guys use the native interface |
| 207 | fCurIntf = GrGLCreateNativeInterface(); |
| 208 | break; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 209 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 210 | case kANGLE_DeviceType: |
| 211 | fCurIntf = GrGLCreateANGLEInterface(); |
| 212 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 213 | #endif // SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 214 | case kNullGPU_DeviceType: |
| 215 | fCurIntf = GrGLCreateNullInterface(); |
| 216 | break; |
| 217 | default: |
| 218 | SkASSERT(false); |
| 219 | break; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 220 | } |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 221 | |
| 222 | SkASSERT(NULL == fCurContext); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 223 | fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 224 | |
| 225 | if (NULL == fCurContext || NULL == fCurIntf) { |
| 226 | // We need some context and interface to see results |
| 227 | SkSafeUnref(fCurContext); |
| 228 | SkSafeUnref(fCurIntf); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 229 | SkDebugf("Failed to setup 3D"); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 230 | |
| 231 | win->detach(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 232 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 233 | #endif // SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 234 | // call windowSizeChanged to create the render target |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 235 | this->windowSizeChanged(win); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 236 | } |
| 237 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 238 | virtual void tearDownBackend(SampleWindow *win) { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 239 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 240 | SkSafeUnref(fCurContext); |
| 241 | fCurContext = NULL; |
| 242 | |
| 243 | SkSafeUnref(fCurIntf); |
| 244 | fCurIntf = NULL; |
| 245 | |
| 246 | SkSafeUnref(fCurRenderTarget); |
| 247 | fCurRenderTarget = NULL; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 248 | #endif |
bsalomon@google.com | ddd40e5 | 2012-04-10 15:56:29 +0000 | [diff] [blame] | 249 | win->detach(); |
| 250 | fBackend = kNone_BackEndType; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 251 | } |
| 252 | |
reed@google.com | 5957f47 | 2012-10-01 20:31:56 +0000 | [diff] [blame] | 253 | virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType, |
| 254 | SampleWindow* win) { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 255 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 256 | if (IsGpuDeviceType(dType) && NULL != fCurContext) { |
| 257 | SkAutoTUnref<SkDevice> device(new SkGpuDevice(fCurContext, fCurRenderTarget)); |
| 258 | return new SkCanvas(device); |
| 259 | } else |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 260 | #endif |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 261 | { |
| 262 | return NULL; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 263 | } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | virtual void publishCanvas(SampleWindow::DeviceType dType, |
| 267 | SkCanvas* canvas, |
| 268 | SampleWindow* win) { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 269 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 270 | if (fCurContext) { |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 271 | // in case we have queued drawing calls |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 272 | fCurContext->flush(); |
| 273 | |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 274 | if (!IsGpuDeviceType(dType)) { |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 275 | // need to send the raster bits to the (gpu) window |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 276 | fCurContext->setRenderTarget(fCurRenderTarget); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 277 | const SkBitmap& bm = win->getBitmap(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 278 | fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(), |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 279 | kSkia8888_PM_GrPixelConfig, |
| 280 | bm.getPixels(), |
| 281 | bm.rowBytes()); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 284 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 285 | |
| 286 | win->present(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | virtual void windowSizeChanged(SampleWindow* win) { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 290 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 291 | if (fCurContext) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 292 | win->attach(fBackend, fMSAASampleCount); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 293 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 294 | GrBackendRenderTargetDesc desc; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 295 | desc.fWidth = SkScalarRound(win->width()); |
| 296 | desc.fHeight = SkScalarRound(win->height()); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 297 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 298 | GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); |
| 299 | GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 300 | GrGLint buffer; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 301 | GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 302 | desc.fRenderTargetHandle = buffer; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 303 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 304 | SkSafeUnref(fCurRenderTarget); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 305 | fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 306 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 307 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 308 | } |
| 309 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 310 | virtual GrContext* getGrContext() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 311 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 312 | return fCurContext; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 313 | #else |
| 314 | return NULL; |
| 315 | #endif |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 316 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 317 | |
| 318 | virtual GrRenderTarget* getGrRenderTarget() SK_OVERRIDE { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 319 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 320 | return fCurRenderTarget; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 321 | #else |
| 322 | return NULL; |
| 323 | #endif |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 324 | } |
| 325 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 326 | private: |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 327 | |
| 328 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 329 | GrContext* fCurContext; |
| 330 | const GrGLInterface* fCurIntf; |
| 331 | GrRenderTarget* fCurRenderTarget; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 332 | int fMSAASampleCount; |
| 333 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 334 | |
| 335 | SkOSWindow::SkBackEndTypes fBackend; |
| 336 | |
| 337 | typedef SampleWindow::DeviceManager INHERITED; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | /////////////// |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 341 | static const char view_inval_msg[] = "view-inval-msg"; |
| 342 | |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 343 | void SampleWindow::postInvalDelay() { |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 344 | (new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static bool isInvalEvent(const SkEvent& evt) { |
| 348 | return evt.isType(view_inval_msg); |
| 349 | } |
| 350 | ////////////////// |
| 351 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 352 | SkFuncViewFactory::SkFuncViewFactory(SkViewCreateFunc func) |
| 353 | : fCreateFunc(func) { |
| 354 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 355 | |
bsalomon@google.com | 8301de1 | 2011-10-31 16:47:13 +0000 | [diff] [blame] | 356 | SkView* SkFuncViewFactory::operator() () const { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 357 | return (*fCreateFunc)(); |
| 358 | } |
| 359 | |
| 360 | #include "GMSampleView.h" |
| 361 | |
| 362 | SkGMSampleViewFactory::SkGMSampleViewFactory(GMFactoryFunc func) |
| 363 | : fFunc(func) { |
| 364 | } |
| 365 | |
| 366 | SkView* SkGMSampleViewFactory::operator() () const { |
| 367 | return new GMSampleView(fFunc(NULL)); |
| 368 | } |
| 369 | |
| 370 | SkViewRegister* SkViewRegister::gHead; |
| 371 | SkViewRegister::SkViewRegister(SkViewFactory* fact) : fFact(fact) { |
| 372 | fFact->ref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 373 | fChain = gHead; |
| 374 | gHead = this; |
| 375 | } |
| 376 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 377 | SkViewRegister::SkViewRegister(SkViewCreateFunc func) { |
| 378 | fFact = new SkFuncViewFactory(func); |
| 379 | fChain = gHead; |
| 380 | gHead = this; |
| 381 | } |
| 382 | |
| 383 | SkViewRegister::SkViewRegister(GMFactoryFunc func) { |
| 384 | fFact = new SkGMSampleViewFactory(func); |
| 385 | fChain = gHead; |
| 386 | gHead = this; |
| 387 | } |
| 388 | |
| 389 | class AutoUnrefArray { |
| 390 | public: |
| 391 | AutoUnrefArray() {} |
| 392 | ~AutoUnrefArray() { |
| 393 | int count = fObjs.count(); |
| 394 | for (int i = 0; i < count; ++i) { |
| 395 | fObjs[i]->unref(); |
| 396 | } |
| 397 | } |
| 398 | SkRefCnt*& push_back() { return *fObjs.append(); } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 399 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 400 | private: |
| 401 | SkTDArray<SkRefCnt*> fObjs; |
| 402 | }; |
| 403 | |
| 404 | // registers GMs as Samples |
| 405 | // This can't be performed during static initialization because it could be |
| 406 | // run before GMRegistry has been fully built. |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 407 | static void SkGMRegistyToSampleRegistry() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 408 | static bool gOnce; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 409 | static AutoUnrefArray fRegisters; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 410 | |
| 411 | if (!gOnce) { |
| 412 | const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head(); |
| 413 | while (gmreg) { |
| 414 | fRegisters.push_back() = new SkViewRegister(gmreg->factory()); |
| 415 | gmreg = gmreg->next(); |
| 416 | } |
| 417 | gOnce = true; |
| 418 | } |
| 419 | } |
| 420 | |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 421 | #if 0 |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 422 | #include <CoreFoundation/CoreFoundation.h> |
| 423 | #include <CoreFoundation/CFURLAccess.h> |
| 424 | |
| 425 | static void testpdf() { |
| 426 | CFStringRef path = CFStringCreateWithCString(NULL, "/test.pdf", |
| 427 | kCFStringEncodingUTF8); |
| 428 | CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, |
| 429 | kCFURLPOSIXPathStyle, |
| 430 | false); |
| 431 | CFRelease(path); |
| 432 | CGRect box = CGRectMake(0, 0, 8*72, 10*72); |
| 433 | CGContextRef cg = CGPDFContextCreateWithURL(url, &box, NULL); |
| 434 | CFRelease(url); |
| 435 | |
| 436 | CGContextBeginPage(cg, &box); |
| 437 | CGRect r = CGRectMake(10, 10, 40 + 0.5, 50 + 0.5); |
| 438 | CGContextFillEllipseInRect(cg, r); |
| 439 | CGContextEndPage(cg); |
| 440 | CGContextRelease(cg); |
| 441 | |
| 442 | if (false) { |
| 443 | SkBitmap bm; |
| 444 | bm.setConfig(SkBitmap::kA8_Config, 64, 64); |
| 445 | bm.allocPixels(); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 446 | bm.eraseColor(SK_ColorTRANSPARENT); |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 447 | |
| 448 | SkCanvas canvas(bm); |
| 449 | |
| 450 | } |
| 451 | } |
| 452 | #endif |
| 453 | |
| 454 | ////////////////////////////////////////////////////////////////////////////// |
| 455 | |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 456 | enum FlipAxisEnum { |
| 457 | kFlipAxis_X = (1 << 0), |
| 458 | kFlipAxis_Y = (1 << 1) |
| 459 | }; |
| 460 | |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 461 | #include "SkDrawFilter.h" |
| 462 | |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 463 | class FlagsDrawFilter : public SkDrawFilter { |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 464 | public: |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 465 | FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa, SkOSMenu::TriState filter, |
| 466 | SkOSMenu::TriState hinting) : |
reed@google.com | 09e3baa | 2011-05-18 12:04:31 +0000 | [diff] [blame] | 467 | fLCDState(lcd), fAAState(aa), fFilterState(filter), fHintingState(hinting) {} |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 468 | |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 469 | virtual bool filter(SkPaint* paint, Type t) { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 470 | if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) { |
| 471 | paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState); |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 472 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 473 | if (SkOSMenu::kMixedState != fAAState) { |
| 474 | paint->setAntiAlias(SkOSMenu::kOnState == fAAState); |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 475 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 476 | if (SkOSMenu::kMixedState != fFilterState) { |
| 477 | paint->setFilterBitmap(SkOSMenu::kOnState == fFilterState); |
reed@google.com | 176753a | 2011-05-17 15:32:04 +0000 | [diff] [blame] | 478 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 479 | if (SkOSMenu::kMixedState != fHintingState) { |
| 480 | paint->setHinting(SkOSMenu::kOnState == fHintingState ? |
reed@google.com | 09e3baa | 2011-05-18 12:04:31 +0000 | [diff] [blame] | 481 | SkPaint::kNormal_Hinting : |
| 482 | SkPaint::kSlight_Hinting); |
| 483 | } |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 484 | return true; |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | private: |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 488 | SkOSMenu::TriState fLCDState; |
| 489 | SkOSMenu::TriState fAAState; |
| 490 | SkOSMenu::TriState fFilterState; |
| 491 | SkOSMenu::TriState fHintingState; |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 492 | }; |
| 493 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 494 | ////////////////////////////////////////////////////////////////////////////// |
| 495 | |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 496 | #define MAX_ZOOM_LEVEL 8 |
| 497 | #define MIN_ZOOM_LEVEL -8 |
| 498 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 499 | static const char gCharEvtName[] = "SampleCode_Char_Event"; |
| 500 | static const char gKeyEvtName[] = "SampleCode_Key_Event"; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 501 | static const char gTitleEvtName[] = "SampleCode_Title_Event"; |
| 502 | static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event"; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 503 | static const char gFastTextEvtName[] = "SampleCode_FastText_Event"; |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 504 | static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle"; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 505 | |
| 506 | bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) { |
| 507 | if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) { |
| 508 | if (outUni) { |
| 509 | *outUni = evt.getFast32(); |
| 510 | } |
| 511 | return true; |
| 512 | } |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) { |
| 517 | if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) { |
| 518 | if (outKey) { |
| 519 | *outKey = (SkKey)evt.getFast32(); |
| 520 | } |
| 521 | return true; |
| 522 | } |
| 523 | return false; |
| 524 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 525 | |
| 526 | bool SampleCode::TitleQ(const SkEvent& evt) { |
| 527 | return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1); |
| 528 | } |
| 529 | |
| 530 | void SampleCode::TitleR(SkEvent* evt, const char title[]) { |
| 531 | SkASSERT(evt && TitleQ(*evt)); |
| 532 | evt->setString(gTitleEvtName, title); |
| 533 | } |
| 534 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 535 | bool SampleCode::RequestTitle(SkView* view, SkString* title) { |
| 536 | SkEvent evt(gTitleEvtName); |
| 537 | if (view->doQuery(&evt)) { |
| 538 | title->set(evt.findString(gTitleEvtName)); |
| 539 | return true; |
| 540 | } |
| 541 | return false; |
| 542 | } |
| 543 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 544 | bool SampleCode::PrefSizeQ(const SkEvent& evt) { |
| 545 | return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1); |
| 546 | } |
| 547 | |
| 548 | void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) { |
| 549 | SkASSERT(evt && PrefSizeQ(*evt)); |
| 550 | SkScalar size[2]; |
| 551 | size[0] = width; |
| 552 | size[1] = height; |
| 553 | evt->setScalars(gPrefSizeEvtName, 2, size); |
| 554 | } |
| 555 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 556 | bool SampleCode::FastTextQ(const SkEvent& evt) { |
| 557 | return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1); |
| 558 | } |
| 559 | |
| 560 | /////////////////////////////////////////////////////////////////////////////// |
| 561 | |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 562 | static SkMSec gAnimTime; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 563 | static SkMSec gAnimTimePrev; |
| 564 | |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 565 | SkMSec SampleCode::GetAnimTime() { return gAnimTime; } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 566 | SkMSec SampleCode::GetAnimTimeDelta() { return gAnimTime - gAnimTimePrev; } |
| 567 | SkScalar SampleCode::GetAnimSecondsDelta() { |
| 568 | return SkDoubleToScalar(GetAnimTimeDelta() / 1000.0); |
| 569 | } |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 570 | |
| 571 | SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 572 | // since gAnimTime can be up to 32 bits, we can't convert it to a float |
| 573 | // or we'll lose the low bits. Hence we use doubles for the intermediate |
| 574 | // calculations |
| 575 | double seconds = (double)gAnimTime / 1000.0; |
| 576 | double value = SkScalarToDouble(speed) * seconds; |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 577 | if (period) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 578 | value = ::fmod(value, SkScalarToDouble(period)); |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 579 | } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 580 | return SkDoubleToScalar(value); |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 581 | } |
| 582 | |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 583 | SkScalar SampleCode::GetAnimSinScalar(SkScalar amplitude, |
| 584 | SkScalar periodInSec, |
| 585 | SkScalar phaseInSec) { |
| 586 | if (!periodInSec) { |
| 587 | return 0; |
| 588 | } |
| 589 | double t = (double)gAnimTime / 1000.0 + phaseInSec; |
| 590 | t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec; |
| 591 | amplitude = SK_ScalarHalf * amplitude; |
| 592 | return SkScalarMul(amplitude, SkDoubleToScalar(sin(t))) + amplitude; |
| 593 | } |
| 594 | |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 595 | GrContext* SampleCode::GetGr() { |
| 596 | return gSampleWindow ? gSampleWindow->getGrContext() : NULL; |
| 597 | } |
| 598 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 599 | // some GMs rely on having a skiagm::GetGr function defined |
| 600 | namespace skiagm { |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 601 | // FIXME: this should be moved into a header |
| 602 | GrContext* GetGr(); |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 603 | GrContext* GetGr() { return SampleCode::GetGr(); } |
| 604 | } |
| 605 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 606 | ////////////////////////////////////////////////////////////////////////////// |
| 607 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 608 | static SkView* curr_view(SkWindow* wind) { |
| 609 | SkView::F2BIter iter(wind); |
| 610 | return iter.next(); |
| 611 | } |
| 612 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 613 | static bool curr_title(SkWindow* wind, SkString* title) { |
| 614 | SkView* view = curr_view(wind); |
| 615 | if (view) { |
| 616 | SkEvent evt(gTitleEvtName); |
| 617 | if (view->doQuery(&evt)) { |
| 618 | title->set(evt.findString(gTitleEvtName)); |
| 619 | return true; |
| 620 | } |
| 621 | } |
| 622 | return false; |
| 623 | } |
| 624 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 625 | void SampleWindow::setZoomCenter(float x, float y) |
| 626 | { |
| 627 | fZoomCenterX = SkFloatToScalar(x); |
| 628 | fZoomCenterY = SkFloatToScalar(y); |
| 629 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 630 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 631 | bool SampleWindow::zoomIn() |
| 632 | { |
| 633 | // Arbitrarily decided |
| 634 | if (fFatBitsScale == 25) return false; |
| 635 | fFatBitsScale++; |
| 636 | this->inval(NULL); |
| 637 | return true; |
| 638 | } |
| 639 | |
| 640 | bool SampleWindow::zoomOut() |
| 641 | { |
| 642 | if (fFatBitsScale == 1) return false; |
| 643 | fFatBitsScale--; |
| 644 | this->inval(NULL); |
| 645 | return true; |
| 646 | } |
| 647 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 648 | void SampleWindow::updatePointer(int x, int y) |
| 649 | { |
| 650 | fMouseX = x; |
| 651 | fMouseY = y; |
| 652 | if (fShowZoomer) { |
| 653 | this->inval(NULL); |
| 654 | } |
| 655 | } |
| 656 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 657 | static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) { |
| 658 | static const SampleWindow::DeviceType gCT[] = { |
| 659 | SampleWindow::kPicture_DeviceType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 660 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 661 | SampleWindow::kGPU_DeviceType, |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 662 | #if SK_ANGLE |
| 663 | SampleWindow::kANGLE_DeviceType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 664 | #endif // SK_ANGLE |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 665 | SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 666 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 667 | SampleWindow::kRaster_DeviceType |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 668 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 669 | SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array_size_mismatch); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 670 | return gCT[ct]; |
| 671 | } |
| 672 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 673 | static void usage(const char * argv0) { |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 674 | SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir dirPath] [--picture path]\n", argv0); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 675 | SkDebugf(" sampleName: sample at which to start.\n"); |
| 676 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 677 | SkDebugf(" msaa: request multisampling with the given sample count.\n"); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 678 | SkDebugf(" dirPath: path to directory skia pictures are read from\n"); |
| 679 | SkDebugf(" path: path to skia picture\n"); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 680 | } |
| 681 | |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 682 | SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) |
robertphillips@google.com | 4750fa5 | 2012-04-10 13:34:11 +0000 | [diff] [blame] | 683 | : INHERITED(hwnd) |
| 684 | , fDevManager(NULL) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 685 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 686 | this->registerPictFileSamples(argv, argc); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 687 | this->registerPictFileSample(argv, argc); |
robertphillips@google.com | 76d4021 | 2012-03-22 14:12:15 +0000 | [diff] [blame] | 688 | SkGMRegistyToSampleRegistry(); |
| 689 | { |
| 690 | const SkViewRegister* reg = SkViewRegister::Head(); |
| 691 | while (reg) { |
| 692 | *fSamples.append() = reg->factory(); |
| 693 | reg = reg->next(); |
| 694 | } |
| 695 | } |
| 696 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 697 | const char* resourcePath = NULL; |
| 698 | fCurrIndex = -1; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 699 | fMSAASampleCount = 0; |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 700 | |
| 701 | const char* const commandName = argv[0]; |
| 702 | char* const* stop = argv + argc; |
| 703 | for (++argv; argv < stop; ++argv) { |
| 704 | if (strcmp(*argv, "-i") == 0) { |
| 705 | argv++; |
| 706 | if (argv < stop && **argv) { |
| 707 | resourcePath = *argv; |
| 708 | } |
robertphillips@google.com | 76d4021 | 2012-03-22 14:12:15 +0000 | [diff] [blame] | 709 | } else if (strcmp(*argv, "--slide") == 0) { |
| 710 | argv++; |
| 711 | if (argv < stop && **argv) { |
| 712 | fCurrIndex = findByTitle(*argv); |
| 713 | if (fCurrIndex < 0) { |
| 714 | fprintf(stderr, "Unknown sample \"%s\"\n", *argv); |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 715 | listTitles(); |
robertphillips@google.com | 76d4021 | 2012-03-22 14:12:15 +0000 | [diff] [blame] | 716 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 717 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 718 | } else if (strcmp(*argv, "--msaa") == 0) { |
| 719 | ++argv; |
| 720 | if (argv < stop && **argv) { |
| 721 | fMSAASampleCount = atoi(*argv); |
| 722 | } |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 723 | } else if (strcmp(*argv, "--list") == 0) { |
| 724 | listTitles(); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 725 | } |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 726 | else { |
robertphillips@google.com | 76d4021 | 2012-03-22 14:12:15 +0000 | [diff] [blame] | 727 | usage(commandName); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | if (fCurrIndex < 0) { |
| 732 | SkString title; |
| 733 | if (readTitleFromPrefs(&title)) { |
| 734 | fCurrIndex = findByTitle(title.c_str()); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | if (fCurrIndex < 0) { |
| 739 | fCurrIndex = 0; |
| 740 | } |
| 741 | |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 742 | gSampleWindow = this; |
| 743 | |
yangsu@google.com | 1f39421 | 2011-06-01 18:03:34 +0000 | [diff] [blame] | 744 | #ifdef PIPE_FILE |
| 745 | //Clear existing file or create file if it doesn't exist |
| 746 | FILE* f = fopen(FILE_PATH, "wb"); |
| 747 | fclose(f); |
| 748 | #endif |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 749 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 750 | fPicture = NULL; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 751 | |
robertphillips@google.com | bd8d7ad | 2012-03-30 15:18:14 +0000 | [diff] [blame] | 752 | fDeviceType = kRaster_DeviceType; |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 753 | |
| 754 | #if DEFAULT_TO_GPU |
| 755 | fDeviceType = kGPU_DeviceType; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 756 | #endif |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 757 | #if SK_ANGLE && DEFAULT_TO_ANGLE |
| 758 | fDeviceType = kANGLE_DeviceType; |
| 759 | #endif |
| 760 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 761 | fUseClip = false; |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 762 | fNClip = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 763 | fAnimating = false; |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 764 | fRotate = false; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 765 | fPerspAnim = false; |
| 766 | fPerspAnimTime = 0; |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 767 | fScale = false; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 768 | fRequestGrabImage = false; |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 769 | fPipeState = SkOSMenu::kOffState; |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 770 | fTilingState = SkOSMenu::kOffState; |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 771 | fTileCount.set(1, 1); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 772 | fMeasureFPS = false; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 773 | fLCDState = SkOSMenu::kMixedState; |
| 774 | fAAState = SkOSMenu::kMixedState; |
| 775 | fFilterState = SkOSMenu::kMixedState; |
| 776 | fHintingState = SkOSMenu::kMixedState; |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 777 | fFlipAxis = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 778 | fScrollTestX = fScrollTestY = 0; |
| 779 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 780 | fMouseX = fMouseY = 0; |
mike@reedtribe.org | 3ce59dc | 2011-04-08 00:38:05 +0000 | [diff] [blame] | 781 | fFatBitsScale = 8; |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 782 | fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold); |
| 783 | fShowZoomer = false; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 784 | |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 785 | fZoomLevel = 0; |
| 786 | fZoomScale = SK_Scalar1; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 787 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 788 | fMagnify = false; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 789 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 790 | fSaveToPdf = false; |
| 791 | fPdfCanvas = NULL; |
| 792 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 793 | fTransitionNext = 6; |
| 794 | fTransitionPrev = 2; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 795 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 796 | int sinkID = this->getSinkID(); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 797 | fAppMenu = new SkOSMenu; |
| 798 | fAppMenu->setTitle("Global Settings"); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 799 | int itemID; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 800 | |
| 801 | itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
| 802 | "Raster", "Picture", "OpenGL", |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 803 | #if SK_ANGLE |
| 804 | "ANGLE", |
| 805 | #endif |
| 806 | NULL); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 807 | fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); |
| 808 | itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); |
| 809 | fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); |
| 810 | itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); |
| 811 | fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); |
| 812 | itemID = fAppMenu->appendTriState("Filter", "Filter", sinkID, fFilterState); |
| 813 | fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); |
| 814 | itemID = fAppMenu->appendTriState("Hinting", "Hinting", sinkID, fHintingState); |
| 815 | fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 816 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 817 | fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID, |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 818 | fPipeState); |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 819 | fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P'); |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 820 | |
| 821 | itemID = fAppMenu->appendTriState("Tiling", "Tiling", sinkID, fTilingState); |
| 822 | fAppMenu->assignKeyEquivalentToItem(itemID, 't'); |
| 823 | |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 824 | itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); |
| 825 | fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); |
| 826 | itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 827 | fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 828 | itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 829 | fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); |
| 830 | itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); |
| 831 | fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); |
| 832 | itemID = fAppMenu->appendSwitch("Zoomer", "Zoomer" , sinkID, fShowZoomer); |
| 833 | fAppMenu->assignKeyEquivalentToItem(itemID, 'z'); |
| 834 | itemID = fAppMenu->appendSwitch("Magnify", "Magnify" , sinkID, fMagnify); |
| 835 | fAppMenu->assignKeyEquivalentToItem(itemID, 'm'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 836 | itemID =fAppMenu->appendList("Transition-Next", "Transition-Next", sinkID, |
| 837 | fTransitionNext, "Up", "Up and Right", "Right", |
| 838 | "Down and Right", "Down", "Down and Left", |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 839 | "Left", "Up and Left", NULL); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 840 | fAppMenu->assignKeyEquivalentToItem(itemID, 'j'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 841 | itemID =fAppMenu->appendList("Transition-Prev", "Transition-Prev", sinkID, |
| 842 | fTransitionPrev, "Up", "Up and Right", "Right", |
| 843 | "Down and Right", "Down", "Down and Left", |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 844 | "Left", "Up and Left", NULL); |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 845 | fAppMenu->assignKeyEquivalentToItem(itemID, 'k'); |
| 846 | itemID = fAppMenu->appendAction("Save to PDF", sinkID); |
| 847 | fAppMenu->assignKeyEquivalentToItem(itemID, 'e'); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 848 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 849 | this->addMenu(fAppMenu); |
| 850 | fSlideMenu = new SkOSMenu; |
| 851 | this->addMenu(fSlideMenu); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 852 | |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 853 | // this->setConfig(SkBitmap::kRGB_565_Config); |
| 854 | this->setConfig(SkBitmap::kARGB_8888_Config); |
| 855 | this->setVisibleP(true); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 856 | this->setClipToBounds(false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 857 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 858 | skiagm::GM::SetResourcePath(resourcePath); |
| 859 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 860 | this->loadView((*fSamples[fCurrIndex])()); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 861 | |
bsalomon@google.com | 840e9f3 | 2011-07-06 21:59:09 +0000 | [diff] [blame] | 862 | fPDFData = NULL; |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 863 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 864 | if (NULL == devManager) { |
| 865 | fDevManager = new DefaultDeviceManager(); |
| 866 | } else { |
| 867 | devManager->ref(); |
| 868 | fDevManager = devManager; |
| 869 | } |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 870 | fDevManager->setUpBackend(this, fMSAASampleCount); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 871 | |
Scroggo | b4490c7 | 2011-06-17 13:53:05 +0000 | [diff] [blame] | 872 | // If another constructor set our dimensions, ensure that our |
| 873 | // onSizeChange gets called. |
| 874 | if (this->height() && this->width()) { |
| 875 | this->onSizeChange(); |
| 876 | } |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 877 | |
| 878 | // can't call this synchronously, since it may require a subclass to |
| 879 | // to implement, or the caller may need us to have returned from the |
| 880 | // constructor first. Hence we post an event to ourselves. |
| 881 | // this->updateTitle(); |
| 882 | postEventToSink(new SkEvent(gUpdateWindowTitleEvtName), this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | SampleWindow::~SampleWindow() { |
| 886 | delete fPicture; |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 887 | delete fPdfCanvas; |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 888 | fTypeface->unref(); |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 889 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 890 | SkSafeUnref(fDevManager); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 891 | } |
| 892 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 893 | static void make_filepath(SkString* path, const char* dir, const SkString& name) { |
| 894 | size_t len = strlen(dir); |
| 895 | path->set(dir); |
| 896 | if (len > 0 && dir[len - 1] != '/') { |
| 897 | path->append("/"); |
| 898 | } |
| 899 | path->append(name); |
| 900 | } |
| 901 | |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 902 | void SampleWindow::registerPictFileSample(char** argv, int argc) { |
| 903 | const char* pict = NULL; |
| 904 | |
| 905 | for (int i = 0; i < argc; ++i) { |
| 906 | if (!strcmp(argv[i], "--picture")) { |
| 907 | i += 1; |
| 908 | if (i < argc) { |
| 909 | pict = argv[i]; |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | if (pict) { |
| 915 | SkString path(pict); |
| 916 | *fSamples.append() = new PictFileFactory(path); |
| 917 | } |
| 918 | } |
| 919 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 920 | void SampleWindow::registerPictFileSamples(char** argv, int argc) { |
| 921 | const char* pictDir = NULL; |
| 922 | |
| 923 | for (int i = 0; i < argc; ++i) { |
| 924 | if (!strcmp(argv[i], "--pictureDir")) { |
| 925 | i += 1; |
| 926 | if (i < argc) { |
| 927 | pictDir = argv[i]; |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | if (pictDir) { |
| 933 | SkOSFile::Iter iter(pictDir, "skp"); |
| 934 | SkString filename; |
| 935 | while (iter.next(&filename)) { |
| 936 | SkString path; |
| 937 | make_filepath(&path, pictDir, filename); |
| 938 | *fSamples.append() = new PictFileFactory(path); |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 943 | int SampleWindow::findByTitle(const char title[]) { |
| 944 | int i, count = fSamples.count(); |
| 945 | for (i = 0; i < count; i++) { |
| 946 | if (getSampleTitle(i).equals(title)) { |
| 947 | return i; |
| 948 | } |
| 949 | } |
mike@reedtribe.org | dd52caa | 2011-12-28 20:02:10 +0000 | [diff] [blame] | 950 | return -1; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 951 | } |
| 952 | |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 953 | void SampleWindow::listTitles() { |
| 954 | int count = fSamples.count(); |
| 955 | SkDebugf("All Slides:\n"); |
| 956 | for (int i = 0; i < count; i++) { |
| 957 | SkDebugf(" %s\n", getSampleTitle(i).c_str()); |
| 958 | } |
| 959 | } |
| 960 | |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 961 | static SkBitmap capture_bitmap(SkCanvas* canvas) { |
| 962 | SkBitmap bm; |
| 963 | const SkBitmap& src = canvas->getDevice()->accessBitmap(false); |
| 964 | src.copyTo(&bm, src.config()); |
| 965 | return bm; |
| 966 | } |
| 967 | |
| 968 | static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig, |
| 969 | SkBitmap* diff) { |
| 970 | const SkBitmap& src = canvas->getDevice()->accessBitmap(false); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 971 | |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 972 | SkAutoLockPixels alp0(src); |
| 973 | SkAutoLockPixels alp1(orig); |
| 974 | for (int y = 0; y < src.height(); y++) { |
| 975 | const void* srcP = src.getAddr(0, y); |
| 976 | const void* origP = orig.getAddr(0, y); |
| 977 | size_t bytes = src.width() * src.bytesPerPixel(); |
| 978 | if (memcmp(srcP, origP, bytes)) { |
| 979 | SkDebugf("---------- difference on line %d\n", y); |
| 980 | return true; |
| 981 | } |
| 982 | } |
| 983 | return false; |
| 984 | } |
| 985 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 986 | static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint) |
| 987 | { |
| 988 | SkColor desiredColor = paint.getColor(); |
| 989 | paint.setColor(SK_ColorWHITE); |
| 990 | const char* c_str = string.c_str(); |
| 991 | size_t size = string.size(); |
| 992 | SkRect bounds; |
| 993 | paint.measureText(c_str, size, &bounds); |
| 994 | bounds.offset(left, top); |
| 995 | SkScalar inset = SkIntToScalar(-2); |
| 996 | bounds.inset(inset, inset); |
| 997 | canvas->drawRect(bounds, paint); |
| 998 | if (desiredColor != SK_ColorBLACK) { |
| 999 | paint.setColor(SK_ColorBLACK); |
| 1000 | canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint); |
| 1001 | } |
| 1002 | paint.setColor(desiredColor); |
| 1003 | canvas->drawText(c_str, size, left, top, paint); |
| 1004 | } |
| 1005 | |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 1006 | #define XCLIP_N 8 |
| 1007 | #define YCLIP_N 8 |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1008 | |
| 1009 | void SampleWindow::draw(SkCanvas* canvas) { |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 1010 | // update the animation time |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1011 | if (!gAnimTimePrev && !gAnimTime) { |
| 1012 | // first time make delta be 0 |
| 1013 | gAnimTime = SkTime::GetMSecs(); |
| 1014 | gAnimTimePrev = gAnimTime; |
| 1015 | } else { |
| 1016 | gAnimTimePrev = gAnimTime; |
| 1017 | gAnimTime = SkTime::GetMSecs(); |
| 1018 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1019 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1020 | if (fGesture.isActive()) { |
| 1021 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1022 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1023 | |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1024 | if (fMeasureFPS) { |
| 1025 | fMeasureFPS_Time = 0; |
| 1026 | } |
| 1027 | |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1028 | if (fNClip) { |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1029 | this->INHERITED::draw(canvas); |
| 1030 | SkBitmap orig = capture_bitmap(canvas); |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1031 | |
| 1032 | const SkScalar w = this->width(); |
| 1033 | const SkScalar h = this->height(); |
| 1034 | const SkScalar cw = w / XCLIP_N; |
| 1035 | const SkScalar ch = h / YCLIP_N; |
| 1036 | for (int y = 0; y < YCLIP_N; y++) { |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1037 | SkRect r; |
| 1038 | r.fTop = y * ch; |
| 1039 | r.fBottom = (y + 1) * ch; |
| 1040 | if (y == YCLIP_N - 1) { |
| 1041 | r.fBottom = h; |
| 1042 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1043 | for (int x = 0; x < XCLIP_N; x++) { |
| 1044 | SkAutoCanvasRestore acr(canvas, true); |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1045 | r.fLeft = x * cw; |
| 1046 | r.fRight = (x + 1) * cw; |
| 1047 | if (x == XCLIP_N - 1) { |
| 1048 | r.fRight = w; |
| 1049 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1050 | canvas->clipRect(r); |
| 1051 | this->INHERITED::draw(canvas); |
| 1052 | } |
| 1053 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1054 | |
reed@android.com | 55e76b2 | 2009-11-23 21:46:47 +0000 | [diff] [blame] | 1055 | SkBitmap diff; |
| 1056 | if (bitmap_diff(canvas, orig, &diff)) { |
| 1057 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1058 | } else { |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 1059 | const SkScalar cw = SkScalarDiv(this->width(), SkIntToScalar(fTileCount.width())); |
| 1060 | const SkScalar ch = SkScalarDiv(this->height(), SkIntToScalar(fTileCount.height())); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 1061 | |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 1062 | for (int y = 0; y < fTileCount.height(); ++y) { |
| 1063 | for (int x = 0; x < fTileCount.width(); ++x) { |
| 1064 | SkAutoCanvasRestore acr(canvas, true); |
| 1065 | canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch)); |
| 1066 | this->INHERITED::draw(canvas); |
| 1067 | } |
| 1068 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 1069 | |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 1070 | if (!fTileCount.equals(1, 1)) { |
| 1071 | SkPaint paint; |
| 1072 | paint.setColor(0x60FF00FF); |
| 1073 | paint.setStyle(SkPaint::kStroke_Style); |
| 1074 | for (int y = 0; y < fTileCount.height(); ++y) { |
| 1075 | for (int x = 0; x < fTileCount.width(); ++x) { |
| 1076 | canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), paint); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1080 | } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1081 | if (fShowZoomer && !fSaveToPdf) { |
Scroggo | 3272ba8 | 2011-05-25 20:50:42 +0000 | [diff] [blame] | 1082 | showZoomer(canvas); |
| 1083 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1084 | if (fMagnify && !fSaveToPdf) { |
| 1085 | magnify(canvas); |
| 1086 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1087 | |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1088 | if (fMeasureFPS && fMeasureFPS_Time) { |
| 1089 | this->updateTitle(); |
| 1090 | this->postInvalDelay(); |
| 1091 | } |
| 1092 | |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1093 | // do this last |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1094 | fDevManager->publishCanvas(fDeviceType, canvas, this); |
Scroggo | 3272ba8 | 2011-05-25 20:50:42 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1097 | static float clipW = 200; |
| 1098 | static float clipH = 200; |
| 1099 | void SampleWindow::magnify(SkCanvas* canvas) { |
| 1100 | SkRect r; |
| 1101 | int count = canvas->save(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1102 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1103 | SkMatrix m = canvas->getTotalMatrix(); |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 1104 | if (!m.invert(&m)) { |
| 1105 | return; |
| 1106 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1107 | SkPoint offset, center; |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1108 | SkScalar mouseX = fMouseX * SK_Scalar1; |
| 1109 | SkScalar mouseY = fMouseY * SK_Scalar1; |
| 1110 | m.mapXY(mouseX - clipW/2, mouseY - clipH/2, &offset); |
| 1111 | m.mapXY(mouseX, mouseY, ¢er); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1112 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1113 | r.set(0, 0, clipW * m.getScaleX(), clipH * m.getScaleX()); |
| 1114 | r.offset(offset.fX, offset.fY); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1115 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1116 | SkPaint paint; |
| 1117 | paint.setColor(0xFF66AAEE); |
| 1118 | paint.setStyle(SkPaint::kStroke_Style); |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1119 | paint.setStrokeWidth(10.f * m.getScaleX()); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1120 | //lense offset |
| 1121 | //canvas->translate(0, -250); |
| 1122 | canvas->drawRect(r, paint); |
| 1123 | canvas->clipRect(r); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1124 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1125 | m = canvas->getTotalMatrix(); |
| 1126 | m.setTranslate(-center.fX, -center.fY); |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 1127 | m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1128 | m.postTranslate(center.fX, center.fY); |
| 1129 | canvas->concat(m); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1130 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1131 | this->INHERITED::draw(canvas); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1132 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1133 | canvas->restoreToCount(count); |
| 1134 | } |
| 1135 | |
Scroggo | 3272ba8 | 2011-05-25 20:50:42 +0000 | [diff] [blame] | 1136 | void SampleWindow::showZoomer(SkCanvas* canvas) { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1137 | int count = canvas->save(); |
| 1138 | canvas->resetMatrix(); |
| 1139 | // Ensure the mouse position is on screen. |
reed@google.com | 261b8e2 | 2011-04-14 17:53:24 +0000 | [diff] [blame] | 1140 | int width = SkScalarRound(this->width()); |
| 1141 | int height = SkScalarRound(this->height()); |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1142 | if (fMouseX >= width) fMouseX = width - 1; |
| 1143 | else if (fMouseX < 0) fMouseX = 0; |
| 1144 | if (fMouseY >= height) fMouseY = height - 1; |
| 1145 | else if (fMouseY < 0) fMouseY = 0; |
reed@google.com | b36334d | 2011-05-18 15:07:20 +0000 | [diff] [blame] | 1146 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1147 | SkBitmap bitmap = capture_bitmap(canvas); |
reed@google.com | b36334d | 2011-05-18 15:07:20 +0000 | [diff] [blame] | 1148 | bitmap.lockPixels(); |
| 1149 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1150 | // Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle. |
mike@reedtribe.org | 3ce59dc | 2011-04-08 00:38:05 +0000 | [diff] [blame] | 1151 | int zoomedWidth = (width >> 1) | 1; |
| 1152 | int zoomedHeight = (height >> 1) | 1; |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1153 | SkIRect src; |
| 1154 | src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale); |
| 1155 | src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1)); |
| 1156 | SkRect dest; |
| 1157 | dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight)); |
| 1158 | dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight)); |
| 1159 | SkPaint paint; |
| 1160 | // Clear the background behind our zoomed in view |
| 1161 | paint.setColor(SK_ColorWHITE); |
| 1162 | canvas->drawRect(dest, paint); |
| 1163 | canvas->drawBitmapRect(bitmap, &src, dest); |
| 1164 | paint.setColor(SK_ColorBLACK); |
| 1165 | paint.setStyle(SkPaint::kStroke_Style); |
| 1166 | // Draw a border around the pixel in the middle |
| 1167 | SkRect originalPixel; |
| 1168 | originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1)); |
| 1169 | SkMatrix matrix; |
| 1170 | SkRect scalarSrc; |
| 1171 | scalarSrc.set(src); |
| 1172 | SkColor color = bitmap.getColor(fMouseX, fMouseY); |
| 1173 | if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) { |
| 1174 | SkRect pixel; |
| 1175 | matrix.mapRect(&pixel, originalPixel); |
| 1176 | // TODO Perhaps measure the values and make the outline white if it's "dark" |
| 1177 | if (color == SK_ColorBLACK) { |
| 1178 | paint.setColor(SK_ColorWHITE); |
| 1179 | } |
| 1180 | canvas->drawRect(pixel, paint); |
| 1181 | } |
| 1182 | paint.setColor(SK_ColorBLACK); |
| 1183 | // Draw a border around the destination rectangle |
| 1184 | canvas->drawRect(dest, paint); |
| 1185 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 1186 | // Identify the pixel and its color on screen |
| 1187 | paint.setTypeface(fTypeface); |
| 1188 | paint.setAntiAlias(true); |
| 1189 | SkScalar lineHeight = paint.getFontMetrics(NULL); |
| 1190 | SkString string; |
| 1191 | string.appendf("(%i, %i)", fMouseX, fMouseY); |
| 1192 | SkScalar left = dest.fLeft + SkIntToScalar(3); |
| 1193 | SkScalar i = SK_Scalar1; |
| 1194 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1195 | // Alpha |
| 1196 | i += SK_Scalar1; |
| 1197 | string.reset(); |
| 1198 | string.appendf("A: %X", SkColorGetA(color)); |
| 1199 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1200 | // Red |
| 1201 | i += SK_Scalar1; |
| 1202 | string.reset(); |
| 1203 | string.appendf("R: %X", SkColorGetR(color)); |
| 1204 | paint.setColor(SK_ColorRED); |
| 1205 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1206 | // Green |
| 1207 | i += SK_Scalar1; |
| 1208 | string.reset(); |
| 1209 | string.appendf("G: %X", SkColorGetG(color)); |
| 1210 | paint.setColor(SK_ColorGREEN); |
| 1211 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1212 | // Blue |
| 1213 | i += SK_Scalar1; |
| 1214 | string.reset(); |
| 1215 | string.appendf("B: %X", SkColorGetB(color)); |
| 1216 | paint.setColor(SK_ColorBLUE); |
| 1217 | drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); |
| 1218 | canvas->restoreToCount(count); |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1221 | void SampleWindow::onDraw(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | #include "SkColorPriv.h" |
| 1225 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 1226 | #if 0 // UNUSED |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1227 | static void reverseRedAndBlue(const SkBitmap& bm) { |
| 1228 | SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config); |
| 1229 | uint8_t* p = (uint8_t*)bm.getPixels(); |
| 1230 | uint8_t* stop = p + bm.getSize(); |
| 1231 | while (p < stop) { |
| 1232 | // swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply |
| 1233 | unsigned scale = SkAlpha255To256(p[3]); |
| 1234 | unsigned r = p[2]; |
| 1235 | unsigned b = p[0]; |
| 1236 | p[0] = SkAlphaMul(r, scale); |
| 1237 | p[1] = SkAlphaMul(p[1], scale); |
| 1238 | p[2] = SkAlphaMul(b, scale); |
| 1239 | p += 4; |
| 1240 | } |
| 1241 | } |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 1242 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1243 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1244 | void SampleWindow::saveToPdf() |
| 1245 | { |
| 1246 | fSaveToPdf = true; |
| 1247 | this->inval(NULL); |
| 1248 | } |
| 1249 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1250 | SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1251 | if (fSaveToPdf) { |
| 1252 | const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false); |
| 1253 | SkISize size = SkISize::Make(bmp.width(), bmp.height()); |
| 1254 | SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, |
| 1255 | canvas->getTotalMatrix()); |
| 1256 | fPdfCanvas = new SkCanvas(pdfDevice); |
| 1257 | pdfDevice->unref(); |
| 1258 | canvas = fPdfCanvas; |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 1259 | } else if (kPicture_DeviceType == fDeviceType) { |
| 1260 | fPicture = new SkPicture; |
| 1261 | canvas = fPicture->beginRecording(9999, 9999); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1262 | } else { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1263 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 1264 | if (kNullGPU_DeviceType != fDeviceType) |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1265 | #endif |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 1266 | { |
| 1267 | canvas = this->INHERITED::beforeChildren(canvas); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1268 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | if (fUseClip) { |
| 1272 | canvas->drawColor(0xFFFF88FF); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1273 | canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | return canvas; |
| 1277 | } |
| 1278 | |
| 1279 | static void paint_rgn(const SkBitmap& bm, const SkIRect& r, |
| 1280 | const SkRegion& rgn) { |
| 1281 | SkCanvas canvas(bm); |
| 1282 | SkRegion inval(rgn); |
| 1283 | |
| 1284 | inval.translate(r.fLeft, r.fTop); |
| 1285 | canvas.clipRegion(inval); |
| 1286 | canvas.drawColor(0xFFFF8080); |
| 1287 | } |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1288 | #include "SkData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1289 | void SampleWindow::afterChildren(SkCanvas* orig) { |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1290 | if (fSaveToPdf) { |
| 1291 | fSaveToPdf = false; |
| 1292 | if (fShowZoomer) { |
| 1293 | showZoomer(fPdfCanvas); |
| 1294 | } |
| 1295 | SkString name; |
| 1296 | name.printf("%s.pdf", this->getTitle()); |
| 1297 | SkPDFDocument doc; |
| 1298 | SkPDFDevice* device = static_cast<SkPDFDevice*>(fPdfCanvas->getDevice()); |
| 1299 | doc.appendPage(device); |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 1300 | #ifdef SK_BUILD_FOR_ANDROID |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1301 | name.prepend("/sdcard/"); |
| 1302 | #endif |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1303 | |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1304 | #ifdef SK_BUILD_FOR_IOS |
| 1305 | SkDynamicMemoryWStream mstream; |
| 1306 | doc.emitPDF(&mstream); |
yangsu@google.com | ae8a2e5 | 2011-06-24 21:09:39 +0000 | [diff] [blame] | 1307 | fPDFData = mstream.copyToData(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1308 | #endif |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1309 | SkFILEWStream stream(name.c_str()); |
| 1310 | if (stream.isValid()) { |
| 1311 | doc.emitPDF(&stream); |
| 1312 | const char* desc = "File saved from Skia SampleApp"; |
| 1313 | this->onPDFSaved(this->getTitle(), desc, name.c_str()); |
| 1314 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1315 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 1316 | delete fPdfCanvas; |
| 1317 | fPdfCanvas = NULL; |
| 1318 | |
| 1319 | // We took over the draw calls in order to create the PDF, so we need |
| 1320 | // to redraw. |
| 1321 | this->inval(NULL); |
| 1322 | return; |
| 1323 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1324 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1325 | if (fRequestGrabImage) { |
| 1326 | fRequestGrabImage = false; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1327 | |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1328 | SkDevice* device = orig->getDevice(); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1329 | SkBitmap bmp; |
| 1330 | if (device->accessBitmap(false).copyTo(&bmp, SkBitmap::kARGB_8888_Config)) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1331 | static int gSampleGrabCounter; |
| 1332 | SkString name; |
reed@google.com | 7c57e0e | 2012-09-08 21:20:33 +0000 | [diff] [blame] | 1333 | name.printf("sample_grab_%d.png", gSampleGrabCounter++); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1334 | SkImageEncoder::EncodeFile(name.c_str(), bmp, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1335 | SkImageEncoder::kPNG_Type, 100); |
| 1336 | } |
| 1337 | } |
| 1338 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1339 | if (kPicture_DeviceType == fDeviceType) { |
| 1340 | if (true) { |
| 1341 | SkPicture* pict = new SkPicture(*fPicture); |
| 1342 | fPicture->unref(); |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 1343 | this->installDrawFilter(orig); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1344 | orig->drawPicture(*pict); |
| 1345 | pict->unref(); |
| 1346 | } else if (true) { |
| 1347 | SkDynamicMemoryWStream ostream; |
| 1348 | fPicture->serialize(&ostream); |
| 1349 | fPicture->unref(); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1350 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1351 | SkAutoDataUnref data(ostream.copyToData()); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 1352 | SkMemoryStream istream(data->data(), data->size()); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1353 | SkPicture pict(&istream); |
| 1354 | orig->drawPicture(pict); |
| 1355 | } else { |
| 1356 | fPicture->draw(orig); |
| 1357 | fPicture->unref(); |
| 1358 | } |
| 1359 | fPicture = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1360 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1361 | |
reed@google.com | 17d7aec | 2011-04-25 14:31:44 +0000 | [diff] [blame] | 1362 | // Do this after presentGL and other finishing, rather than in afterChild |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1363 | if (fMeasureFPS && fMeasureFPS_StartTime) { |
| 1364 | fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; |
reed@google.com | 17d7aec | 2011-04-25 14:31:44 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | // if ((fScrollTestX | fScrollTestY) != 0) |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1368 | if (false) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1369 | const SkBitmap& bm = orig->getDevice()->accessBitmap(true); |
| 1370 | int dx = fScrollTestX * 7; |
| 1371 | int dy = fScrollTestY * 7; |
| 1372 | SkIRect r; |
| 1373 | SkRegion inval; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1374 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1375 | r.set(50, 50, 50+100, 50+100); |
| 1376 | bm.scrollRect(&r, dx, dy, &inval); |
| 1377 | paint_rgn(bm, r, inval); |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1378 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1381 | void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { |
| 1382 | if (fScale) { |
| 1383 | SkScalar scale = SK_Scalar1 * 7 / 10; |
| 1384 | SkScalar cx = this->width() / 2; |
| 1385 | SkScalar cy = this->height() / 2; |
| 1386 | canvas->translate(cx, cy); |
| 1387 | canvas->scale(scale, scale); |
| 1388 | canvas->translate(-cx, -cy); |
| 1389 | } |
| 1390 | if (fRotate) { |
| 1391 | SkScalar cx = this->width() / 2; |
| 1392 | SkScalar cy = this->height() / 2; |
| 1393 | canvas->translate(cx, cy); |
| 1394 | canvas->rotate(SkIntToScalar(30)); |
| 1395 | canvas->translate(-cx, -cy); |
| 1396 | } |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1397 | if (fPerspAnim) { |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 1398 | fPerspAnimTime += SampleCode::GetAnimSecondsDelta(); |
| 1399 | |
| 1400 | static const SkScalar gAnimPeriod = 10 * SK_Scalar1; |
| 1401 | static const SkScalar gAnimMag = SK_Scalar1 / 1000; |
| 1402 | SkScalar t = SkScalarMod(fPerspAnimTime, gAnimPeriod); |
| 1403 | if (SkScalarFloorToInt(SkScalarDiv(fPerspAnimTime, gAnimPeriod)) & 0x1) { |
| 1404 | t = gAnimPeriod - t; |
| 1405 | } |
| 1406 | t = 2 * t - gAnimPeriod; |
| 1407 | t = SkScalarMul(SkScalarDiv(t, gAnimPeriod), gAnimMag); |
| 1408 | SkMatrix m; |
| 1409 | m.reset(); |
| 1410 | m.setPerspY(t); |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1411 | canvas->concat(m); |
| 1412 | } |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 1413 | |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 1414 | this->installDrawFilter(canvas); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1415 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1416 | if (fMeasureFPS) { |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 1417 | if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) { |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1418 | fMeasureFPS_StartTime = SkTime::GetMSecs(); |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 1419 | } |
| 1420 | } else { |
| 1421 | (void)SampleView::SetRepeatDraw(child, 1); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1422 | } |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1423 | if (fPerspAnim) { |
| 1424 | this->inval(NULL); |
| 1425 | } |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) { |
reed@google.com | f0b5f68 | 2011-03-11 20:08:25 +0000 | [diff] [blame] | 1429 | canvas->setDrawFilter(NULL); |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1432 | static SkBitmap::Config gConfigCycle[] = { |
| 1433 | SkBitmap::kNo_Config, // none -> none |
| 1434 | SkBitmap::kNo_Config, // a1 -> none |
| 1435 | SkBitmap::kNo_Config, // a8 -> none |
| 1436 | SkBitmap::kNo_Config, // index8 -> none |
| 1437 | SkBitmap::kARGB_4444_Config, // 565 -> 4444 |
| 1438 | SkBitmap::kARGB_8888_Config, // 4444 -> 8888 |
| 1439 | SkBitmap::kRGB_565_Config // 8888 -> 565 |
| 1440 | }; |
| 1441 | |
| 1442 | static SkBitmap::Config cycle_configs(SkBitmap::Config c) { |
| 1443 | return gConfigCycle[c]; |
| 1444 | } |
| 1445 | |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1446 | void SampleWindow::changeZoomLevel(float delta) { |
| 1447 | fZoomLevel += SkFloatToScalar(delta); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1448 | if (fZoomLevel > 0) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1449 | fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); |
| 1450 | fZoomScale = fZoomLevel + SK_Scalar1; |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1451 | } else if (fZoomLevel < 0) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1452 | fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); |
| 1453 | fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1454 | } else { |
| 1455 | fZoomScale = SK_Scalar1; |
| 1456 | } |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1457 | this->updateMatrix(); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1460 | void SampleWindow::updateMatrix(){ |
| 1461 | SkMatrix m; |
| 1462 | m.reset(); |
| 1463 | if (fZoomLevel) { |
| 1464 | SkPoint center; |
| 1465 | //m = this->getLocalMatrix();//.invert(&m); |
| 1466 | m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); |
| 1467 | SkScalar cx = center.fX; |
| 1468 | SkScalar cy = center.fY; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1469 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1470 | m.setTranslate(-cx, -cy); |
| 1471 | m.postScale(fZoomScale, fZoomScale); |
| 1472 | m.postTranslate(cx, cy); |
| 1473 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1474 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1475 | if (fFlipAxis) { |
| 1476 | m.preTranslate(fZoomCenterX, fZoomCenterY); |
| 1477 | if (fFlipAxis & kFlipAxis_X) { |
| 1478 | m.preScale(-SK_Scalar1, SK_Scalar1); |
| 1479 | } |
| 1480 | if (fFlipAxis & kFlipAxis_Y) { |
| 1481 | m.preScale(SK_Scalar1, -SK_Scalar1); |
| 1482 | } |
| 1483 | m.preTranslate(-fZoomCenterX, -fZoomCenterY); |
| 1484 | //canvas->concat(m); |
| 1485 | } |
| 1486 | // Apply any gesture matrix |
| 1487 | m.preConcat(fGesture.localM()); |
| 1488 | m.preConcat(fGesture.globalM()); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1489 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1490 | this->setLocalMatrix(m); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1491 | |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1492 | this->updateTitle(); |
| 1493 | this->inval(NULL); |
| 1494 | } |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1495 | bool SampleWindow::previousSample() { |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 1496 | fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1497 | this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(), |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1498 | fTransitionPrev)); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1499 | return true; |
| 1500 | } |
| 1501 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1502 | bool SampleWindow::nextSample() { |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1503 | fCurrIndex = (fCurrIndex + 1) % fSamples.count(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1504 | this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(), |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1505 | fTransitionNext)); |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1506 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1509 | bool SampleWindow::goToSample(int i) { |
| 1510 | fCurrIndex = (i) % fSamples.count(); |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 1511 | this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(), 6)); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1512 | return true; |
| 1513 | } |
| 1514 | |
| 1515 | SkString SampleWindow::getSampleTitle(int i) { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 1516 | SkView* view = (*fSamples[i])(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1517 | SkString title; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1518 | SampleCode::RequestTitle(view, &title); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 1519 | view->unref(); |
| 1520 | return title; |
| 1521 | } |
| 1522 | |
| 1523 | int SampleWindow::sampleCount() { |
| 1524 | return fSamples.count(); |
| 1525 | } |
| 1526 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1527 | void SampleWindow::showOverview() { |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1528 | this->loadView(create_transition(curr_view(this), |
| 1529 | create_overview(fSamples.count(), fSamples.begin()), |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1530 | 4)); |
| 1531 | } |
| 1532 | |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 1533 | void SampleWindow::installDrawFilter(SkCanvas* canvas) { |
| 1534 | canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, |
| 1535 | fFilterState, fHintingState))->unref(); |
| 1536 | } |
| 1537 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1538 | void SampleWindow::postAnimatingEvent() { |
| 1539 | if (fAnimating) { |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 1540 | (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATING_DELAY); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1541 | } |
| 1542 | } |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 1543 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1544 | bool SampleWindow::onEvent(const SkEvent& evt) { |
reed@google.com | 2072db8 | 2011-11-08 15:18:10 +0000 | [diff] [blame] | 1545 | if (evt.isType(gUpdateWindowTitleEvtName)) { |
| 1546 | this->updateTitle(); |
| 1547 | return true; |
| 1548 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1549 | if (evt.isType(ANIMATING_EVENTTYPE)) { |
| 1550 | if (fAnimating) { |
| 1551 | this->nextSample(); |
| 1552 | this->postAnimatingEvent(); |
| 1553 | } |
| 1554 | return true; |
| 1555 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1556 | if (evt.isType("replace-transition-view")) { |
| 1557 | this->loadView((SkView*)SkEventSink::FindSink(evt.getFast32())); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1558 | return true; |
| 1559 | } |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1560 | if (evt.isType("set-curr-index")) { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1561 | this->goToSample(evt.getFast32()); |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1562 | return true; |
| 1563 | } |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1564 | if (isInvalEvent(evt)) { |
| 1565 | this->inval(NULL); |
| 1566 | return true; |
| 1567 | } |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1568 | int selected = -1; |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1569 | if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1570 | this->setDeviceType((DeviceType)selected); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1571 | return true; |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1572 | } |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 1573 | if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) { |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1574 | #ifdef PIPE_NET |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 1575 | if (!fPipeState != SkOSMenu::kOnState) |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1576 | gServer.disconnectAll(); |
| 1577 | #endif |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 1578 | (void)SampleView::SetUsePipe(curr_view(this), fPipeState); |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1579 | this->updateTitle(); |
| 1580 | this->inval(NULL); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1581 | return true; |
| 1582 | } |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 1583 | if (SkOSMenu::FindTriState(evt, "Tiling", &fTilingState)) { |
| 1584 | int nx = 1, ny = 1; |
| 1585 | switch (fTilingState) { |
| 1586 | case SkOSMenu::kOffState: nx = 1; ny = 1; break; |
reed@google.com | 56b64a5 | 2012-08-15 20:44:36 +0000 | [diff] [blame] | 1587 | case SkOSMenu::kMixedState: nx = 1; ny = 16; break; |
| 1588 | case SkOSMenu::kOnState: nx = 4; ny = 4; break; |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 1589 | } |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 1590 | fTileCount.set(nx, ny); |
reed@google.com | 67b89ee | 2012-08-15 14:41:58 +0000 | [diff] [blame] | 1591 | this->inval(NULL); |
| 1592 | return true; |
| 1593 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1594 | if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1595 | this->toggleSlideshow(); |
| 1596 | return true; |
| 1597 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1598 | if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
| 1599 | SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
| 1600 | SkOSMenu::FindTriState(evt, "Filter", &fFilterState) || |
| 1601 | SkOSMenu::FindTriState(evt, "Hinting", &fHintingState) || |
| 1602 | SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || |
| 1603 | SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || |
| 1604 | SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) || |
| 1605 | SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) || |
| 1606 | SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1607 | this->inval(NULL); |
| 1608 | this->updateTitle(); |
| 1609 | return true; |
| 1610 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1611 | if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1612 | fFlipAxis ^= kFlipAxis_X; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1613 | this->updateMatrix(); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1614 | return true; |
| 1615 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1616 | if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1617 | fFlipAxis ^= kFlipAxis_Y; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1618 | this->updateMatrix(); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1619 | return true; |
| 1620 | } |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1621 | if (SkOSMenu::FindAction(evt,"Save to PDF")) { |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1622 | this->saveToPdf(); |
| 1623 | return true; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1624 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1625 | return this->INHERITED::onEvent(evt); |
| 1626 | } |
| 1627 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1628 | bool SampleWindow::onQuery(SkEvent* query) { |
| 1629 | if (query->isType("get-slide-count")) { |
| 1630 | query->setFast32(fSamples.count()); |
| 1631 | return true; |
| 1632 | } |
| 1633 | if (query->isType("get-slide-title")) { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 1634 | SkView* view = (*fSamples[query->getFast32()])(); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1635 | SkEvent evt(gTitleEvtName); |
| 1636 | if (view->doQuery(&evt)) { |
| 1637 | query->setString("title", evt.findString(gTitleEvtName)); |
| 1638 | } |
| 1639 | SkSafeUnref(view); |
| 1640 | return true; |
| 1641 | } |
| 1642 | if (query->isType("use-fast-text")) { |
| 1643 | SkEvent evt(gFastTextEvtName); |
| 1644 | return curr_view(this)->doQuery(&evt); |
| 1645 | } |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 1646 | if (query->isType("ignore-window-bitmap")) { |
| 1647 | query->setFast32(this->getGrContext() != NULL); |
| 1648 | return true; |
| 1649 | } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1650 | return this->INHERITED::onQuery(query); |
| 1651 | } |
| 1652 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 1653 | #if 0 // UNUSED |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1654 | static void cleanup_for_filename(SkString* name) { |
| 1655 | char* str = name->writable_str(); |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 1656 | for (size_t i = 0; i < name->size(); i++) { |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1657 | switch (str[i]) { |
| 1658 | case ':': str[i] = '-'; break; |
| 1659 | case '/': str[i] = '-'; break; |
| 1660 | case ' ': str[i] = '_'; break; |
| 1661 | default: break; |
| 1662 | } |
| 1663 | } |
| 1664 | } |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 1665 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1666 | |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1667 | //extern bool gIgnoreFastBlurRect; |
| 1668 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1669 | bool SampleWindow::onHandleChar(SkUnichar uni) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1670 | { |
| 1671 | SkView* view = curr_view(this); |
| 1672 | if (view) { |
| 1673 | SkEvent evt(gCharEvtName); |
| 1674 | evt.setFast32(uni); |
| 1675 | if (view->doQuery(&evt)) { |
| 1676 | return true; |
| 1677 | } |
| 1678 | } |
| 1679 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1680 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1681 | int dx = 0xFF; |
| 1682 | int dy = 0xFF; |
| 1683 | |
| 1684 | switch (uni) { |
| 1685 | case '5': dx = 0; dy = 0; break; |
| 1686 | case '8': dx = 0; dy = -1; break; |
| 1687 | case '6': dx = 1; dy = 0; break; |
| 1688 | case '2': dx = 0; dy = 1; break; |
| 1689 | case '4': dx = -1; dy = 0; break; |
| 1690 | case '7': dx = -1; dy = -1; break; |
| 1691 | case '9': dx = 1; dy = -1; break; |
| 1692 | case '3': dx = 1; dy = 1; break; |
| 1693 | case '1': dx = -1; dy = 1; break; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1694 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1695 | default: |
| 1696 | break; |
| 1697 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1698 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1699 | if (0xFF != dx && 0xFF != dy) { |
| 1700 | if ((dx | dy) == 0) { |
| 1701 | fScrollTestX = fScrollTestY = 0; |
| 1702 | } else { |
| 1703 | fScrollTestX += dx; |
| 1704 | fScrollTestY += dy; |
| 1705 | } |
| 1706 | this->inval(NULL); |
| 1707 | return true; |
| 1708 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1709 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1710 | switch (uni) { |
djsollen@google.com | 796763e | 2012-12-10 14:12:55 +0000 | [diff] [blame] | 1711 | case 'b': |
| 1712 | { |
| 1713 | postEventToSink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this)); |
| 1714 | this->updateTitle(); |
| 1715 | this->inval(NULL); |
| 1716 | break; |
| 1717 | } |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1718 | case 'B': |
| 1719 | // gIgnoreFastBlurRect = !gIgnoreFastBlurRect; |
| 1720 | this->inval(NULL); |
| 1721 | break; |
| 1722 | |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1723 | case 'f': |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1724 | // only |
djsollen@google.com | 6ff8255 | 2011-11-07 15:43:57 +0000 | [diff] [blame] | 1725 | toggleFPS(); |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 1726 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1727 | case 'g': |
| 1728 | fRequestGrabImage = true; |
| 1729 | this->inval(NULL); |
| 1730 | break; |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 1731 | case 'G': |
| 1732 | gShowGMBounds = !gShowGMBounds; |
| 1733 | postEventToSink(GMSampleView::NewShowSizeEvt(gShowGMBounds), |
| 1734 | curr_view(this)); |
| 1735 | this->inval(NULL); |
| 1736 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1737 | case 'i': |
| 1738 | this->zoomIn(); |
| 1739 | break; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 1740 | case 'o': |
| 1741 | this->zoomOut(); |
| 1742 | break; |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1743 | case 'r': |
| 1744 | fRotate = !fRotate; |
| 1745 | this->inval(NULL); |
| 1746 | this->updateTitle(); |
| 1747 | return true; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 1748 | case 'k': |
| 1749 | fPerspAnim = !fPerspAnim; |
| 1750 | this->inval(NULL); |
| 1751 | this->updateTitle(); |
| 1752 | return true; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1753 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 1754 | case '\\': |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1755 | this->setDeviceType(kNullGPU_DeviceType); |
| 1756 | this->inval(NULL); |
| 1757 | this->updateTitle(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 1758 | return true; |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 1759 | case 'p': |
| 1760 | { |
| 1761 | GrContext* grContext = this->getGrContext(); |
| 1762 | if (grContext) { |
| 1763 | size_t cacheBytes = grContext->getGpuTextureCacheBytes(); |
| 1764 | grContext->freeGpuResources(); |
| 1765 | SkDebugf("Purged %d bytes from the GPU resource cache.\n", |
| 1766 | cacheBytes); |
| 1767 | } |
| 1768 | } |
| 1769 | return true; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1770 | #endif |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 1771 | case 's': |
| 1772 | fScale = !fScale; |
| 1773 | this->inval(NULL); |
| 1774 | this->updateTitle(); |
| 1775 | return true; |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 1776 | default: |
| 1777 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1778 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1779 | |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 1780 | if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni)) { |
| 1781 | this->onUpdateMenu(fAppMenu); |
| 1782 | this->onUpdateMenu(fSlideMenu); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1783 | return true; |
| 1784 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1785 | return this->INHERITED::onHandleChar(uni); |
| 1786 | } |
| 1787 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1788 | void SampleWindow::setDeviceType(DeviceType type) { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1789 | if (type == fDeviceType) |
| 1790 | return; |
| 1791 | |
| 1792 | fDevManager->tearDownBackend(this); |
| 1793 | |
| 1794 | fDeviceType = type; |
| 1795 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 1796 | fDevManager->setUpBackend(this, fMSAASampleCount); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1797 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1798 | this->updateTitle(); |
| 1799 | this->inval(NULL); |
| 1800 | } |
| 1801 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1802 | void SampleWindow::toggleSlideshow() { |
| 1803 | fAnimating = !fAnimating; |
| 1804 | this->postAnimatingEvent(); |
| 1805 | this->updateTitle(); |
| 1806 | } |
| 1807 | |
| 1808 | void SampleWindow::toggleRendering() { |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1809 | this->setDeviceType(cycle_devicetype(fDeviceType)); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 1810 | this->updateTitle(); |
| 1811 | this->inval(NULL); |
| 1812 | } |
| 1813 | |
djsollen@google.com | 6ff8255 | 2011-11-07 15:43:57 +0000 | [diff] [blame] | 1814 | void SampleWindow::toggleFPS() { |
| 1815 | fMeasureFPS = !fMeasureFPS; |
| 1816 | this->updateTitle(); |
| 1817 | this->inval(NULL); |
| 1818 | } |
| 1819 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1820 | #include "SkDumpCanvas.h" |
| 1821 | |
| 1822 | bool SampleWindow::onHandleKey(SkKey key) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1823 | { |
| 1824 | SkView* view = curr_view(this); |
| 1825 | if (view) { |
| 1826 | SkEvent evt(gKeyEvtName); |
| 1827 | evt.setFast32(key); |
| 1828 | if (view->doQuery(&evt)) { |
| 1829 | return true; |
| 1830 | } |
| 1831 | } |
| 1832 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1833 | switch (key) { |
| 1834 | case kRight_SkKey: |
| 1835 | if (this->nextSample()) { |
| 1836 | return true; |
| 1837 | } |
| 1838 | break; |
| 1839 | case kLeft_SkKey: |
scroggo@google.com | e2dd973 | 2012-08-15 20:03:06 +0000 | [diff] [blame] | 1840 | if (this->previousSample()) { |
| 1841 | return true; |
| 1842 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1843 | return true; |
| 1844 | case kUp_SkKey: |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1845 | if (USE_ARROWS_FOR_ZOOM) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1846 | this->changeZoomLevel(1.f); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1847 | } else { |
| 1848 | fNClip = !fNClip; |
| 1849 | this->inval(NULL); |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1850 | this->updateTitle(); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1851 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1852 | return true; |
| 1853 | case kDown_SkKey: |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1854 | if (USE_ARROWS_FOR_ZOOM) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1855 | this->changeZoomLevel(-1.f); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1856 | } else { |
| 1857 | this->setConfig(cycle_configs(this->getBitmap().config())); |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 1858 | this->updateTitle(); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1859 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1860 | return true; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1861 | case kOK_SkKey: { |
| 1862 | SkString title; |
| 1863 | if (curr_title(this, &title)) { |
| 1864 | writeTitleToPrefs(title.c_str()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1865 | } |
| 1866 | return true; |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 1867 | } |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1868 | case kBack_SkKey: |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1869 | this->showOverview(); |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 1870 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1871 | default: |
| 1872 | break; |
| 1873 | } |
| 1874 | return this->INHERITED::onHandleKey(key); |
| 1875 | } |
| 1876 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1877 | /////////////////////////////////////////////////////////////////////////////// |
| 1878 | |
| 1879 | static const char gGestureClickType[] = "GestureClickType"; |
| 1880 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 1881 | bool SampleWindow::onDispatchClick(int x, int y, Click::State state, |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1882 | void* owner, unsigned modi) { |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame] | 1883 | if (Click::kMoved_State == state) { |
| 1884 | updatePointer(x, y); |
| 1885 | } |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1886 | int w = SkScalarRound(this->width()); |
| 1887 | int h = SkScalarRound(this->height()); |
| 1888 | |
| 1889 | // check for the resize-box |
| 1890 | if (w - x < 16 && h - y < 16) { |
| 1891 | return false; // let the OS handle the click |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1892 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 1893 | else if (fMagnify) { |
| 1894 | //it's only necessary to update the drawing if there's a click |
| 1895 | this->inval(NULL); |
| 1896 | return false; //prevent dragging while magnify is enabled |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1897 | } else { |
| 1898 | // capture control+option, and trigger debugger |
| 1899 | if ((modi & kControl_SkModifierKey) && (modi & kOption_SkModifierKey)) { |
| 1900 | if (Click::kDown_State == state) { |
| 1901 | SkEvent evt("debug-hit-test"); |
| 1902 | evt.setS32("debug-hit-test-x", x); |
| 1903 | evt.setS32("debug-hit-test-y", y); |
| 1904 | curr_view(this)->doEvent(evt); |
| 1905 | } |
| 1906 | return true; |
| 1907 | } else { |
| 1908 | return this->INHERITED::onDispatchClick(x, y, state, owner, modi); |
| 1909 | } |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1913 | class GestureClick : public SkView::Click { |
| 1914 | public: |
| 1915 | GestureClick(SkView* target) : SkView::Click(target) { |
| 1916 | this->setType(gGestureClickType); |
| 1917 | } |
| 1918 | |
| 1919 | static bool IsGesture(Click* click) { |
| 1920 | return click->isType(gGestureClickType); |
| 1921 | } |
| 1922 | }; |
| 1923 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 1924 | SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y, |
| 1925 | unsigned modi) { |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1926 | return new GestureClick(this); |
| 1927 | } |
| 1928 | |
| 1929 | bool SampleWindow::onClick(Click* click) { |
| 1930 | if (GestureClick::IsGesture(click)) { |
bsalomon@google.com | 4d4f281 | 2011-12-12 18:34:01 +0000 | [diff] [blame] | 1931 | float x = static_cast<float>(click->fICurr.fX); |
| 1932 | float y = static_cast<float>(click->fICurr.fY); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1933 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1934 | switch (click->fState) { |
| 1935 | case SkView::Click::kDown_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 1936 | fGesture.touchBegin(click->fOwner, x, y); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1937 | break; |
| 1938 | case SkView::Click::kMoved_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 1939 | fGesture.touchMoved(click->fOwner, x, y); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1940 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1941 | break; |
| 1942 | case SkView::Click::kUp_State: |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 1943 | fGesture.touchEnd(click->fOwner); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 1944 | this->updateMatrix(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 1945 | break; |
| 1946 | } |
| 1947 | return true; |
| 1948 | } |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
| 1952 | /////////////////////////////////////////////////////////////////////////////// |
| 1953 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1954 | void SampleWindow::loadView(SkView* view) { |
| 1955 | SkView::F2BIter iter(this); |
| 1956 | SkView* prev = iter.next(); |
| 1957 | if (prev) { |
| 1958 | prev->detachFromParent(); |
| 1959 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 1960 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1961 | view->setVisibleP(true); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1962 | view->setClipToBounds(false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1963 | this->attachChildToFront(view)->unref(); |
| 1964 | view->setSize(this->width(), this->height()); |
| 1965 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1966 | //repopulate the slide menu when a view is loaded |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 1967 | fSlideMenu->reset(); |
djsollen@google.com | 388974f | 2013-01-17 13:20:01 +0000 | [diff] [blame] | 1968 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 1969 | (void)SampleView::SetUsePipe(view, fPipeState); |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 1970 | if (SampleView::IsSampleView(view)) |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 1971 | ((SampleView*)view)->requestMenu(fSlideMenu); |
| 1972 | this->onUpdateMenu(fSlideMenu); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1973 | this->updateTitle(); |
| 1974 | } |
| 1975 | |
| 1976 | static const char* gConfigNames[] = { |
| 1977 | "unknown config", |
| 1978 | "A1", |
| 1979 | "A8", |
| 1980 | "Index8", |
| 1981 | "565", |
| 1982 | "4444", |
| 1983 | "8888" |
| 1984 | }; |
| 1985 | |
| 1986 | static const char* configToString(SkBitmap::Config c) { |
| 1987 | return gConfigNames[c]; |
| 1988 | } |
| 1989 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 1990 | static const char* gDeviceTypePrefix[] = { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1991 | "raster: ", |
| 1992 | "picture: ", |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1993 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 1994 | "opengl: ", |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 1995 | #if SK_ANGLE |
| 1996 | "angle: ", |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1997 | #endif // SK_ANGLE |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 1998 | "null-gl: " |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1999 | #endif // SK_SUPPORT_GPU |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2000 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2001 | SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt, |
| 2002 | array_size_mismatch); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2003 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2004 | static const char* trystate_str(SkOSMenu::TriState state, |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2005 | const char trueStr[], const char falseStr[]) { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2006 | if (SkOSMenu::kOnState == state) { |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2007 | return trueStr; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2008 | } else if (SkOSMenu::kOffState == state) { |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2009 | return falseStr; |
| 2010 | } |
| 2011 | return NULL; |
| 2012 | } |
| 2013 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2014 | void SampleWindow::updateTitle() { |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 2015 | SkView* view = curr_view(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2016 | |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 2017 | SkString title; |
| 2018 | if (!curr_title(this, &title)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2019 | title.set("<unknown>"); |
| 2020 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2021 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2022 | title.prepend(gDeviceTypePrefix[fDeviceType]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2023 | |
| 2024 | title.prepend(" "); |
| 2025 | title.prepend(configToString(this->getBitmap().config())); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2026 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2027 | if (fAnimating) { |
| 2028 | title.prepend("<A> "); |
| 2029 | } |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 2030 | if (fScale) { |
| 2031 | title.prepend("<S> "); |
| 2032 | } |
| 2033 | if (fRotate) { |
| 2034 | title.prepend("<R> "); |
| 2035 | } |
reed@android.com | e522ca5 | 2009-11-23 20:10:41 +0000 | [diff] [blame] | 2036 | if (fNClip) { |
| 2037 | title.prepend("<C> "); |
| 2038 | } |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 2039 | if (fPerspAnim) { |
| 2040 | title.prepend("<K> "); |
| 2041 | } |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2042 | |
| 2043 | title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); |
| 2044 | title.prepend(trystate_str(fAAState, "AA ", "aa ")); |
reed@google.com | 09e3baa | 2011-05-18 12:04:31 +0000 | [diff] [blame] | 2045 | title.prepend(trystate_str(fFilterState, "H ", "h ")); |
reed@google.com | 569e043 | 2011-04-05 13:07:03 +0000 | [diff] [blame] | 2046 | title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL); |
| 2047 | title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 2048 | |
| 2049 | if (fZoomLevel) { |
djsollen@google.com | e32b583 | 2011-06-13 16:58:40 +0000 | [diff] [blame] | 2050 | title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 2051 | } |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2052 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2053 | if (fMeasureFPS) { |
reed@google.com | 43e1014 | 2012-09-10 11:52:52 +0000 | [diff] [blame] | 2054 | title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2055 | } |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 2056 | if (SampleView::IsSampleView(view)) { |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2057 | switch (fPipeState) { |
| 2058 | case SkOSMenu::kOnState: |
| 2059 | title.prepend("<Pipe> "); |
| 2060 | break; |
| 2061 | case SkOSMenu::kMixedState: |
| 2062 | title.prepend("<Tiled Pipe> "); |
| 2063 | break; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2064 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2065 | default: |
| 2066 | break; |
| 2067 | } |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 2068 | title.prepend("! "); |
| 2069 | } |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2070 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2071 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 2072 | if (IsGpuDeviceType(fDeviceType) && |
robertphillips@google.com | 4750fa5 | 2012-04-10 13:34:11 +0000 | [diff] [blame] | 2073 | NULL != fDevManager && |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame^] | 2074 | fDevManager->getGrRenderTarget() && |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 2075 | fDevManager->getGrRenderTarget()->numSamples() > 0) { |
| 2076 | title.appendf(" [MSAA: %d]", |
| 2077 | fDevManager->getGrRenderTarget()->numSamples()); |
| 2078 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2079 | #endif |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 2080 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2081 | this->setTitle(title.c_str()); |
| 2082 | } |
| 2083 | |
| 2084 | void SampleWindow::onSizeChange() { |
| 2085 | this->INHERITED::onSizeChange(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2086 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2087 | SkView::F2BIter iter(this); |
| 2088 | SkView* view = iter.next(); |
| 2089 | view->setSize(this->width(), this->height()); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2090 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2091 | // rebuild our clippath |
| 2092 | { |
| 2093 | const SkScalar W = this->width(); |
| 2094 | const SkScalar H = this->height(); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2095 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2096 | fClipPath.reset(); |
| 2097 | #if 0 |
| 2098 | for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) { |
| 2099 | SkRect r; |
| 2100 | r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30)); |
| 2101 | for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0)) |
| 2102 | fClipPath.addRect(r); |
| 2103 | } |
| 2104 | #else |
| 2105 | SkRect r; |
| 2106 | r.set(0, 0, W, H); |
| 2107 | fClipPath.addRect(r, SkPath::kCCW_Direction); |
| 2108 | r.set(W/4, H/4, W*3/4, H*3/4); |
| 2109 | fClipPath.addRect(r, SkPath::kCW_Direction); |
| 2110 | #endif |
| 2111 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2112 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 2113 | fZoomCenterX = SkScalarHalf(this->width()); |
| 2114 | fZoomCenterY = SkScalarHalf(this->height()); |
| 2115 | |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 2116 | #ifdef SK_BUILD_FOR_ANDROID |
Scroggo | b4490c7 | 2011-06-17 13:53:05 +0000 | [diff] [blame] | 2117 | // FIXME: The first draw after a size change does not work on Android, so |
| 2118 | // we post an invalidate. |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 2119 | this->postInvalDelay(); |
Scroggo | 716a038 | 2011-06-16 14:00:15 +0000 | [diff] [blame] | 2120 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2121 | this->updateTitle(); // to refresh our config |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2122 | fDevManager->windowSizeChanged(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /////////////////////////////////////////////////////////////////////////////// |
| 2126 | |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 2127 | static const char is_sample_view_tag[] = "sample-is-sample-view"; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2128 | static const char repeat_count_tag[] = "sample-set-repeat-count"; |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2129 | static const char set_use_pipe_tag[] = "sample-set-use-pipe"; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2130 | |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 2131 | bool SampleView::IsSampleView(SkView* view) { |
| 2132 | SkEvent evt(is_sample_view_tag); |
| 2133 | return view->doQuery(&evt); |
| 2134 | } |
| 2135 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 2136 | bool SampleView::SetRepeatDraw(SkView* view, int count) { |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2137 | SkEvent evt(repeat_count_tag); |
| 2138 | evt.setFast32(count); |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 2139 | return view->doEvent(evt); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2142 | bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) { |
| 2143 | SkEvent evt; |
| 2144 | evt.setS32(set_use_pipe_tag, state); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2145 | return view->doEvent(evt); |
| 2146 | } |
| 2147 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2148 | bool SampleView::onEvent(const SkEvent& evt) { |
| 2149 | if (evt.isType(repeat_count_tag)) { |
| 2150 | fRepeatCount = evt.getFast32(); |
| 2151 | return true; |
| 2152 | } |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 2153 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2154 | int32_t pipeHolder; |
| 2155 | if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { |
| 2156 | fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2157 | return true; |
| 2158 | } |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 2159 | |
| 2160 | if (evt.isType("debug-hit-test")) { |
| 2161 | fDebugHitTest = true; |
| 2162 | evt.findS32("debug-hit-test-x", &fDebugHitTestLoc.fX); |
| 2163 | evt.findS32("debug-hit-test-y", &fDebugHitTestLoc.fY); |
| 2164 | this->inval(NULL); |
| 2165 | return true; |
| 2166 | } |
| 2167 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2168 | return this->INHERITED::onEvent(evt); |
| 2169 | } |
| 2170 | |
| 2171 | bool SampleView::onQuery(SkEvent* evt) { |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 2172 | if (evt->isType(is_sample_view_tag)) { |
| 2173 | return true; |
| 2174 | } |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2175 | return this->INHERITED::onQuery(evt); |
| 2176 | } |
| 2177 | |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2178 | |
| 2179 | class SimplePC : public SkGPipeController { |
| 2180 | public: |
| 2181 | SimplePC(SkCanvas* target); |
| 2182 | ~SimplePC(); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2183 | |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2184 | virtual void* requestBlock(size_t minRequest, size_t* actual); |
| 2185 | virtual void notifyWritten(size_t bytes); |
| 2186 | |
| 2187 | private: |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 2188 | SkGPipeReader fReader; |
| 2189 | void* fBlock; |
| 2190 | size_t fBlockSize; |
| 2191 | size_t fBytesWritten; |
| 2192 | int fAtomsWritten; |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2193 | SkGPipeReader::Status fStatus; |
| 2194 | |
| 2195 | size_t fTotalWritten; |
| 2196 | }; |
| 2197 | |
| 2198 | SimplePC::SimplePC(SkCanvas* target) : fReader(target) { |
| 2199 | fBlock = NULL; |
| 2200 | fBlockSize = fBytesWritten = 0; |
| 2201 | fStatus = SkGPipeReader::kDone_Status; |
| 2202 | fTotalWritten = 0; |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 2203 | fAtomsWritten = 0; |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | SimplePC::~SimplePC() { |
| 2207 | // SkASSERT(SkGPipeReader::kDone_Status == fStatus); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2208 | if (fTotalWritten) { |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2209 | SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten, |
| 2210 | fAtomsWritten, fStatus); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2211 | #ifdef PIPE_FILE |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2212 | //File is open in append mode |
| 2213 | FILE* f = fopen(FILE_PATH, "ab"); |
| 2214 | SkASSERT(f != NULL); |
| 2215 | fwrite((const char*)fBlock + fBytesWritten, 1, bytes, f); |
| 2216 | fclose(f); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2217 | #endif |
| 2218 | #ifdef PIPE_NET |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2219 | if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done |
| 2220 | gServer.acceptConnections(); |
| 2221 | gServer.writePacket(fBlock, fTotalWritten); |
| 2222 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2223 | #endif |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2224 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2225 | sk_free(fBlock); |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | void* SimplePC::requestBlock(size_t minRequest, size_t* actual) { |
| 2229 | sk_free(fBlock); |
| 2230 | |
| 2231 | fBlockSize = minRequest * 4; |
| 2232 | fBlock = sk_malloc_throw(fBlockSize); |
| 2233 | fBytesWritten = 0; |
| 2234 | *actual = fBlockSize; |
| 2235 | return fBlock; |
| 2236 | } |
| 2237 | |
| 2238 | void SimplePC::notifyWritten(size_t bytes) { |
| 2239 | SkASSERT(fBytesWritten + bytes <= fBlockSize); |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2240 | fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes); |
| 2241 | SkASSERT(SkGPipeReader::kError_Status != fStatus); |
| 2242 | fBytesWritten += bytes; |
| 2243 | fTotalWritten += bytes; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2244 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 2245 | fAtomsWritten += 1; |
reed@google.com | 64e3eb2 | 2011-05-04 14:32:04 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2248 | void SampleView::draw(SkCanvas* canvas) { |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2249 | if (SkOSMenu::kOffState == fPipeState) { |
| 2250 | this->INHERITED::draw(canvas); |
| 2251 | } else { |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2252 | SkGPipeWriter writer; |
| 2253 | SimplePC controller(canvas); |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2254 | TiledPipeController tc(canvas->getDevice()->accessBitmap(false), |
| 2255 | &canvas->getTotalMatrix()); |
| 2256 | SkGPipeController* pc; |
| 2257 | if (SkOSMenu::kMixedState == fPipeState) { |
| 2258 | pc = &tc; |
| 2259 | } else { |
| 2260 | pc = &controller; |
| 2261 | } |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 2262 | uint32_t flags = SkGPipeWriter::kCrossProcess_Flag; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame] | 2263 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 2264 | canvas = writer.startRecording(pc, flags); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2265 | //Must draw before controller goes out of scope and sends data |
| 2266 | this->INHERITED::draw(canvas); |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 2267 | //explicitly end recording to ensure writer is flushed before the memory |
| 2268 | //is freed in the deconstructor of the controller |
| 2269 | writer.endRecording(); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 2270 | } |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2271 | } |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 2272 | |
| 2273 | #include "SkBounder.h" |
| 2274 | |
| 2275 | class DebugHitTestBounder : public SkBounder { |
| 2276 | public: |
| 2277 | DebugHitTestBounder(int x, int y) { |
| 2278 | fLoc.set(x, y); |
| 2279 | } |
| 2280 | |
| 2281 | virtual bool onIRect(const SkIRect& bounds) SK_OVERRIDE { |
| 2282 | if (bounds.contains(fLoc.x(), fLoc.y())) { |
| 2283 | // |
| 2284 | // Set a break-point here to see what was being drawn under |
| 2285 | // the click point (just needed a line of code to stop the debugger) |
| 2286 | // |
| 2287 | bounds.centerX(); |
| 2288 | } |
| 2289 | return true; |
| 2290 | } |
| 2291 | |
| 2292 | private: |
| 2293 | SkIPoint fLoc; |
| 2294 | typedef SkBounder INHERITED; |
| 2295 | }; |
| 2296 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 2297 | void SampleView::onDraw(SkCanvas* canvas) { |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 2298 | this->onDrawBackground(canvas); |
| 2299 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 2300 | DebugHitTestBounder bounder(fDebugHitTestLoc.x(), fDebugHitTestLoc.y()); |
| 2301 | if (fDebugHitTest) { |
| 2302 | canvas->setBounder(&bounder); |
| 2303 | } |
| 2304 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2305 | for (int i = 0; i < fRepeatCount; i++) { |
scroggo@google.com | 85cade0 | 2012-08-17 13:29:50 +0000 | [diff] [blame] | 2306 | SkAutoCanvasRestore acr(canvas, true); |
| 2307 | this->onDrawContent(canvas); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2308 | } |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 2309 | |
| 2310 | fDebugHitTest = false; |
| 2311 | canvas->setBounder(NULL); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | void SampleView::onDrawBackground(SkCanvas* canvas) { |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 2315 | canvas->drawColor(fBGColor); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | /////////////////////////////////////////////////////////////////////////////// |
| 2319 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2320 | template <typename T> void SkTBSort(T array[], int count) { |
| 2321 | for (int i = 1; i < count - 1; i++) { |
| 2322 | bool didSwap = false; |
| 2323 | for (int j = count - 1; j > i; --j) { |
| 2324 | if (array[j] < array[j-1]) { |
| 2325 | T tmp(array[j-1]); |
| 2326 | array[j-1] = array[j]; |
| 2327 | array[j] = tmp; |
| 2328 | didSwap = true; |
| 2329 | } |
| 2330 | } |
| 2331 | if (!didSwap) { |
| 2332 | break; |
| 2333 | } |
| 2334 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2335 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2336 | for (int k = 0; k < count - 1; k++) { |
| 2337 | SkASSERT(!(array[k+1] < array[k])); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | #include "SkRandom.h" |
| 2342 | |
| 2343 | static void rand_rect(SkIRect* rect, SkRandom& rand) { |
| 2344 | int bits = 8; |
| 2345 | int shift = 32 - bits; |
| 2346 | rect->set(rand.nextU() >> shift, rand.nextU() >> shift, |
| 2347 | rand.nextU() >> shift, rand.nextU() >> shift); |
| 2348 | rect->sort(); |
| 2349 | } |
| 2350 | |
| 2351 | static void dumpRect(const SkIRect& r) { |
| 2352 | SkDebugf(" { %d, %d, %d, %d },\n", |
| 2353 | r.fLeft, r.fTop, |
| 2354 | r.fRight, r.fBottom); |
| 2355 | } |
| 2356 | |
| 2357 | static void test_rects(const SkIRect rect[], int count) { |
| 2358 | SkRegion rgn0, rgn1; |
| 2359 | |
| 2360 | for (int i = 0; i < count; i++) { |
| 2361 | rgn0.op(rect[i], SkRegion::kUnion_Op); |
| 2362 | // dumpRect(rect[i]); |
| 2363 | } |
| 2364 | rgn1.setRects(rect, count); |
| 2365 | |
| 2366 | if (rgn0 != rgn1) { |
| 2367 | SkDebugf("\n"); |
| 2368 | for (int i = 0; i < count; i++) { |
| 2369 | dumpRect(rect[i]); |
| 2370 | } |
| 2371 | SkDebugf("\n"); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | static void test() { |
| 2376 | size_t i; |
| 2377 | |
| 2378 | const SkIRect r0[] = { |
| 2379 | { 0, 0, 1, 1 }, |
| 2380 | { 2, 2, 3, 3 }, |
| 2381 | }; |
| 2382 | const SkIRect r1[] = { |
| 2383 | { 0, 0, 1, 3 }, |
| 2384 | { 1, 1, 2, 2 }, |
| 2385 | { 2, 0, 3, 3 }, |
| 2386 | }; |
| 2387 | const SkIRect r2[] = { |
| 2388 | { 0, 0, 1, 2 }, |
| 2389 | { 2, 1, 3, 3 }, |
| 2390 | { 4, 0, 5, 1 }, |
| 2391 | { 6, 0, 7, 4 }, |
| 2392 | }; |
| 2393 | |
| 2394 | static const struct { |
| 2395 | const SkIRect* fRects; |
| 2396 | int fCount; |
| 2397 | } gRecs[] = { |
| 2398 | { r0, SK_ARRAY_COUNT(r0) }, |
| 2399 | { r1, SK_ARRAY_COUNT(r1) }, |
| 2400 | { r2, SK_ARRAY_COUNT(r2) }, |
| 2401 | }; |
| 2402 | |
| 2403 | for (i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 2404 | test_rects(gRecs[i].fRects, gRecs[i].fCount); |
| 2405 | } |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2406 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2407 | SkRandom rand; |
| 2408 | for (i = 0; i < 10000; i++) { |
| 2409 | SkRegion rgn0, rgn1; |
| 2410 | |
| 2411 | const int N = 8; |
| 2412 | SkIRect rect[N]; |
| 2413 | for (int j = 0; j < N; j++) { |
| 2414 | rand_rect(&rect[j], rand); |
| 2415 | } |
| 2416 | test_rects(rect, N); |
| 2417 | } |
| 2418 | } |
| 2419 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2420 | // FIXME: this should be in a header |
| 2421 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); |
senorblanco@chromium.org | 78b8253 | 2011-06-28 19:44:03 +0000 | [diff] [blame] | 2422 | SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2423 | if (false) { // avoid bit rot, suppress warning |
| 2424 | test(); |
| 2425 | } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 2426 | return new SampleWindow(hwnd, argc, argv, NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2429 | // FIXME: this should be in a header |
| 2430 | 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] | 2431 | void get_preferred_size(int* x, int* y, int* width, int* height) { |
| 2432 | *x = 10; |
| 2433 | *y = 50; |
| 2434 | *width = 640; |
| 2435 | *height = 480; |
| 2436 | } |
| 2437 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2438 | #ifdef SK_BUILD_FOR_IOS |
| 2439 | void save_args(int argc, char *argv[]) { |
| 2440 | } |
| 2441 | #endif |
| 2442 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2443 | // FIXME: this should be in a header |
| 2444 | void application_init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2445 | void application_init() { |
| 2446 | // setenv("ANDROID_ROOT", "../../../data", 0); |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 2447 | #ifdef SK_BUILD_FOR_MAC |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2448 | setenv("ANDROID_ROOT", "/android/device/data", 0); |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 2449 | #endif |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 2450 | SkGraphics::Init(); |
| 2451 | SkEvent::Init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 2454 | // FIXME: this should be in a header |
| 2455 | void application_term(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2456 | void application_term() { |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 2457 | SkEvent::Term(); |
| 2458 | SkGraphics::Term(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2459 | } |