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