blob: f379f992356505251683297fd038918d428fbcff [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
Scroggo2c8208f2011-06-15 16:49:08 +00007#include "SampleApp.h"
8
reed@google.com8a85d0c2011-06-24 19:12:12 +00009#include "SkData.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkCanvas.h"
11#include "SkDevice.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkGraphics.h"
scroggo@google.com74b7ffd2013-04-30 02:32:41 +000013#include "SkImageDecoder.h"
reed@android.comb08eb2b2009-01-06 20:16:26 +000014#include "SkImageEncoder.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkPaint.h"
16#include "SkPicture.h"
17#include "SkStream.h"
reed@android.com44177402009-11-23 21:07:51 +000018#include "SkTime.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#include "SkWindow.h"
20
21#include "SampleCode.h"
Scroggo0f185c22011-03-24 18:35:50 +000022#include "SkTypeface.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000023
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000024#if SK_SUPPORT_GPU
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000025#include "gl/GrGLInterface.h"
bsalomon@google.com9c1f1ac2012-05-07 17:09:37 +000026#include "gl/GrGLUtil.h"
bsalomon@google.com583a1e32011-08-17 13:42:46 +000027#include "GrRenderTarget.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000028#include "GrContext.h"
29#include "SkGpuDevice.h"
30#else
31class GrContext;
32#endif
Scroggo2c8208f2011-06-15 16:49:08 +000033
reed@google.com1830c7a2012-06-04 12:05:43 +000034#include "SkOSFile.h"
Scroggo8ac0d542011-06-21 14:44:57 +000035#include "SkPDFDevice.h"
36#include "SkPDFDocument.h"
37#include "SkStream.h"
38
scroggo@google.comb073d922012-06-08 15:35:03 +000039#include "SkGPipe.h"
40#include "SamplePipeControllers.h"
tfarina@chromium.orgb1b7f7072012-09-18 01:52:20 +000041#include "OverView.h"
epoger@google.com6a121782012-09-14 18:42:01 +000042#include "TransitionView.h"
scroggo@google.comb073d922012-06-08 15:35:03 +000043
robertphillips@google.coma22e2112012-08-16 14:58:06 +000044SK_DEFINE_INST_COUNT(SampleWindow::DeviceManager)
45
reed@google.com1830c7a2012-06-04 12:05:43 +000046extern SampleView* CreateSamplePictFileView(const char filename[]);
47
48class PictFileFactory : public SkViewFactory {
49 SkString fFilename;
50public:
51 PictFileFactory(const SkString& filename) : fFilename(filename) {}
52 virtual SkView* operator() () const SK_OVERRIDE {
53 return CreateSamplePictFileView(fFilename.c_str());
54 }
55};
56
yangsu@google.comdb03eaa2011-08-08 15:37:23 +000057#define PIPE_FILEx
58#ifdef PIPE_FILE
yangsu@google.com1f394212011-06-01 18:03:34 +000059#define FILE_PATH "/path/to/drawing.data"
60#endif
61
yangsu@google.comf121b052011-08-08 16:02:51 +000062#define PIPE_NETx
yangsu@google.comdb03eaa2011-08-08 15:37:23 +000063#ifdef PIPE_NET
64#include "SkSockets.h"
65SkTCPServer gServer;
66#endif
yangsu@google.comef7bdfa2011-08-12 14:27:47 +000067
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +000068#define USE_ARROWS_FOR_ZOOM true
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000069
70#if SK_ANGLE
71//#define DEFAULT_TO_ANGLE 1
72#else
73//#define DEFAULT_TO_GPU 1
74#endif
reed@android.comf2b98d62010-12-20 18:26:13 +000075
reed@android.com8a1c16f2008-12-17 15:59:43 +000076#define ANIMATING_EVENTTYPE "nextSample"
reed@google.com84cfce12013-05-29 19:22:20 +000077#define ANIMATING_DELAY 250
reed@android.com8a1c16f2008-12-17 15:59:43 +000078
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000079#ifdef SK_DEBUG
reed@google.combad8c872011-05-18 20:10:31 +000080 #define FPS_REPEAT_MULTIPLIER 1
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000081#else
reed@google.combad8c872011-05-18 20:10:31 +000082 #define FPS_REPEAT_MULTIPLIER 10
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000083#endif
reed@google.combad8c872011-05-18 20:10:31 +000084#define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER)
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000085
reed@google.com3cec4d72011-07-06 13:59:47 +000086static SampleWindow* gSampleWindow;
87
reed@google.coma4f81372012-11-15 15:56:38 +000088static bool gShowGMBounds;
89
reed@google.com2072db82011-11-08 15:18:10 +000090static void postEventToSink(SkEvent* evt, SkEventSink* sink) {
91 evt->setTargetID(sink->getSinkID())->post();
92}
93
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +000094///////////////////////////////////////////////////////////////////////////////
95
96static const char* skip_until(const char* str, const char* skip) {
97 if (!str) {
98 return NULL;
99 }
100 return strstr(str, skip);
101}
102
103static const char* skip_past(const char* str, const char* skip) {
104 const char* found = skip_until(str, skip);
105 if (!found) {
106 return NULL;
107 }
108 return found + strlen(skip);
109}
110
111static const char* gPrefFileName = "sampleapp_prefs.txt";
112
epoger@google.com6fc7cc22011-12-28 15:13:41 +0000113static bool readTitleFromPrefs(SkString* title) {
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +0000114 SkFILEStream stream(gPrefFileName);
115 if (!stream.isValid()) {
116 return false;
117 }
118
119 int len = stream.getLength();
120 SkString data(len);
121 stream.read(data.writable_str(), len);
122 const char* s = data.c_str();
123
124 s = skip_past(s, "curr-slide-title");
125 s = skip_past(s, "=");
126 s = skip_past(s, "\"");
127 const char* stop = skip_until(s, "\"");
128 if (stop > s) {
129 title->set(s, stop - s);
130 return true;
131 }
132 return false;
133}
134
epoger@google.com6fc7cc22011-12-28 15:13:41 +0000135static void writeTitleToPrefs(const char* title) {
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +0000136 SkFILEWStream stream(gPrefFileName);
137 SkString data;
138 data.printf("curr-slide-title = \"%s\"\n", title);
139 stream.write(data.c_str(), data.size());
140}
141
142///////////////////////////////////////////////////////////////////////////////
143
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000144class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
145public:
146
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000147 DefaultDeviceManager() {
148#if SK_SUPPORT_GPU
149 fCurContext = NULL;
150 fCurIntf = NULL;
151 fCurRenderTarget = NULL;
152 fMSAASampleCount = 0;
153#endif
154 fBackend = kNone_BackEndType;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000155 }
156
157 virtual ~DefaultDeviceManager() {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000158#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000159 SkSafeUnref(fCurContext);
160 SkSafeUnref(fCurIntf);
161 SkSafeUnref(fCurRenderTarget);
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000162#endif
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000163 }
164
bsalomon@google.com11959252012-04-06 20:13:38 +0000165 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) {
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000166 SkASSERT(kNone_BackEndType == fBackend);
robertphillips@google.com53e96a12012-03-30 14:47:53 +0000167
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000168 fBackend = kNone_BackEndType;
169
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000170#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000171 switch (win->getDeviceType()) {
172 case kRaster_DeviceType:
173 // fallthrough
174 case kPicture_DeviceType:
175 // fallthrough
176 case kGPU_DeviceType:
177 // fallthrough
178 case kNullGPU_DeviceType:
179 // all these guys use the native backend
180 fBackend = kNativeGL_BackEndType;
181 break;
robertphillips@google.combd8d7ad2012-03-30 15:18:14 +0000182#if SK_ANGLE
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000183 case kANGLE_DeviceType:
184 // ANGLE is really the only odd man out
185 fBackend = kANGLE_BackEndType;
186 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000187#endif // SK_ANGLE
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000188 default:
189 SkASSERT(false);
190 break;
robertphillips@google.combd8d7ad2012-03-30 15:18:14 +0000191 }
bsalomon@google.com64cc8102013-03-05 20:06:05 +0000192 AttachmentInfo attachmentInfo;
193 bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo);
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +0000194 if (!result) {
bsalomon@google.com74913722011-10-27 20:44:19 +0000195 SkDebugf("Failed to initialize GL");
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000196 return;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000197 }
bsalomon@google.com11959252012-04-06 20:13:38 +0000198 fMSAASampleCount = msaaSampleCount;
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000199
200 SkASSERT(NULL == fCurIntf);
201 switch (win->getDeviceType()) {
202 case kRaster_DeviceType:
203 // fallthrough
204 case kPicture_DeviceType:
205 // fallthrough
206 case kGPU_DeviceType:
207 // all these guys use the native interface
208 fCurIntf = GrGLCreateNativeInterface();
209 break;
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +0000210#if SK_ANGLE
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000211 case kANGLE_DeviceType:
212 fCurIntf = GrGLCreateANGLEInterface();
213 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000214#endif // SK_ANGLE
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000215 case kNullGPU_DeviceType:
216 fCurIntf = GrGLCreateNullInterface();
217 break;
218 default:
219 SkASSERT(false);
220 break;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000221 }
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000222
223 SkASSERT(NULL == fCurContext);
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000224 fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000225
226 if (NULL == fCurContext || NULL == fCurIntf) {
227 // We need some context and interface to see results
228 SkSafeUnref(fCurContext);
229 SkSafeUnref(fCurIntf);
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000230 SkDebugf("Failed to setup 3D");
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000231
232 win->detach();
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000233 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000234#endif // SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000235 // call windowSizeChanged to create the render target
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000236 this->windowSizeChanged(win);
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000237 }
238
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000239 virtual void tearDownBackend(SampleWindow *win) {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000240#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000241 SkSafeUnref(fCurContext);
242 fCurContext = NULL;
243
244 SkSafeUnref(fCurIntf);
245 fCurIntf = NULL;
246
247 SkSafeUnref(fCurRenderTarget);
248 fCurRenderTarget = NULL;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000249#endif
bsalomon@google.comddd40e52012-04-10 15:56:29 +0000250 win->detach();
251 fBackend = kNone_BackEndType;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000252 }
253
reed@google.com5957f472012-10-01 20:31:56 +0000254 virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType,
255 SampleWindow* win) {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000256#if SK_SUPPORT_GPU
bsalomon@google.com82502e22013-01-24 20:47:18 +0000257 if (IsGpuDeviceType(dType) && NULL != fCurContext) {
258 SkAutoTUnref<SkDevice> device(new SkGpuDevice(fCurContext, fCurRenderTarget));
259 return new SkCanvas(device);
260 } else
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000261#endif
bsalomon@google.com82502e22013-01-24 20:47:18 +0000262 {
263 return NULL;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000264 }
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000265 }
266
267 virtual void publishCanvas(SampleWindow::DeviceType dType,
268 SkCanvas* canvas,
269 SampleWindow* win) {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000270#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000271 if (fCurContext) {
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000272 // in case we have queued drawing calls
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000273 fCurContext->flush();
274
bsalomon@google.com82502e22013-01-24 20:47:18 +0000275 if (!IsGpuDeviceType(dType)) {
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000276 // need to send the raster bits to the (gpu) window
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000277 fCurContext->setRenderTarget(fCurRenderTarget);
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000278 const SkBitmap& bm = win->getBitmap();
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000279 fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000280 kSkia8888_GrPixelConfig,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000281 bm.getPixels(),
282 bm.rowBytes());
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000283 }
284 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000285#endif
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000286
287 win->present();
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000288 }
289
290 virtual void windowSizeChanged(SampleWindow* win) {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000291#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000292 if (fCurContext) {
bsalomon@google.com64cc8102013-03-05 20:06:05 +0000293 AttachmentInfo attachmentInfo;
294 win->attach(fBackend, fMSAASampleCount, &attachmentInfo);
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000295
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000296 GrBackendRenderTargetDesc desc;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000297 desc.fWidth = SkScalarRound(win->width());
298 desc.fHeight = SkScalarRound(win->height());
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000299 desc.fConfig = kSkia8888_GrPixelConfig;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000300 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
bsalomon@google.com64cc8102013-03-05 20:06:05 +0000301 desc.fSampleCnt = attachmentInfo.fSampleCount;
302 desc.fStencilBits = attachmentInfo.fStencilBits;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000303 GrGLint buffer;
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000304 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
bsalomon@google.come269f212011-11-07 13:29:52 +0000305 desc.fRenderTargetHandle = buffer;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000306
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000307 SkSafeUnref(fCurRenderTarget);
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000308 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
bsalomon@google.com74913722011-10-27 20:44:19 +0000309 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000310#endif
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000311 }
312
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000313 virtual GrContext* getGrContext() {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000314#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000315 return fCurContext;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000316#else
317 return NULL;
318#endif
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000319 }
bsalomon@google.com11959252012-04-06 20:13:38 +0000320
321 virtual GrRenderTarget* getGrRenderTarget() SK_OVERRIDE {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000322#if SK_SUPPORT_GPU
bsalomon@google.com11959252012-04-06 20:13:38 +0000323 return fCurRenderTarget;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000324#else
325 return NULL;
326#endif
bsalomon@google.com11959252012-04-06 20:13:38 +0000327 }
328
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000329private:
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000330
331#if SK_SUPPORT_GPU
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000332 GrContext* fCurContext;
333 const GrGLInterface* fCurIntf;
334 GrRenderTarget* fCurRenderTarget;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000335 int fMSAASampleCount;
336#endif
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000337
338 SkOSWindow::SkBackEndTypes fBackend;
339
340 typedef SampleWindow::DeviceManager INHERITED;
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000341};
342
343///////////////
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000344static const char view_inval_msg[] = "view-inval-msg";
345
Scroggo62b65b02011-06-21 16:01:26 +0000346void SampleWindow::postInvalDelay() {
reed@google.com87fac4a2011-08-04 13:50:17 +0000347 (new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000348}
349
350static bool isInvalEvent(const SkEvent& evt) {
351 return evt.isType(view_inval_msg);
352}
353//////////////////
354
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000355SkFuncViewFactory::SkFuncViewFactory(SkViewCreateFunc func)
356 : fCreateFunc(func) {
357}
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000358
bsalomon@google.com8301de12011-10-31 16:47:13 +0000359SkView* SkFuncViewFactory::operator() () const {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000360 return (*fCreateFunc)();
361}
362
363#include "GMSampleView.h"
364
365SkGMSampleViewFactory::SkGMSampleViewFactory(GMFactoryFunc func)
366 : fFunc(func) {
367}
368
369SkView* SkGMSampleViewFactory::operator() () const {
370 return new GMSampleView(fFunc(NULL));
371}
372
373SkViewRegister* SkViewRegister::gHead;
374SkViewRegister::SkViewRegister(SkViewFactory* fact) : fFact(fact) {
375 fFact->ref();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000376 fChain = gHead;
377 gHead = this;
378}
379
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000380SkViewRegister::SkViewRegister(SkViewCreateFunc func) {
381 fFact = new SkFuncViewFactory(func);
382 fChain = gHead;
383 gHead = this;
384}
385
386SkViewRegister::SkViewRegister(GMFactoryFunc func) {
387 fFact = new SkGMSampleViewFactory(func);
388 fChain = gHead;
389 gHead = this;
390}
391
392class AutoUnrefArray {
393public:
394 AutoUnrefArray() {}
395 ~AutoUnrefArray() {
396 int count = fObjs.count();
397 for (int i = 0; i < count; ++i) {
398 fObjs[i]->unref();
399 }
400 }
401 SkRefCnt*& push_back() { return *fObjs.append(); }
chudy@google.com4605a3f2012-08-01 17:58:01 +0000402
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000403private:
404 SkTDArray<SkRefCnt*> fObjs;
405};
406
407// registers GMs as Samples
408// This can't be performed during static initialization because it could be
409// run before GMRegistry has been fully built.
caryclark@google.com02939ce2012-06-06 12:09:51 +0000410static void SkGMRegistyToSampleRegistry() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000411 static bool gOnce;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000412 static AutoUnrefArray fRegisters;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000413
414 if (!gOnce) {
415 const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head();
416 while (gmreg) {
417 fRegisters.push_back() = new SkViewRegister(gmreg->factory());
418 gmreg = gmreg->next();
419 }
420 gOnce = true;
421 }
422}
423
reed@google.com29038ed2011-07-06 17:56:47 +0000424#if 0
reed@google.comf0b5f682011-03-11 20:08:25 +0000425#include <CoreFoundation/CoreFoundation.h>
426#include <CoreFoundation/CFURLAccess.h>
427
428static void testpdf() {
429 CFStringRef path = CFStringCreateWithCString(NULL, "/test.pdf",
430 kCFStringEncodingUTF8);
431 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path,
432 kCFURLPOSIXPathStyle,
433 false);
434 CFRelease(path);
435 CGRect box = CGRectMake(0, 0, 8*72, 10*72);
436 CGContextRef cg = CGPDFContextCreateWithURL(url, &box, NULL);
437 CFRelease(url);
438
439 CGContextBeginPage(cg, &box);
440 CGRect r = CGRectMake(10, 10, 40 + 0.5, 50 + 0.5);
441 CGContextFillEllipseInRect(cg, r);
442 CGContextEndPage(cg);
443 CGContextRelease(cg);
444
445 if (false) {
446 SkBitmap bm;
447 bm.setConfig(SkBitmap::kA8_Config, 64, 64);
448 bm.allocPixels();
junov@google.comdbfac8a2012-12-06 21:47:40 +0000449 bm.eraseColor(SK_ColorTRANSPARENT);
reed@google.comf0b5f682011-03-11 20:08:25 +0000450
451 SkCanvas canvas(bm);
452
453 }
454}
455#endif
456
457//////////////////////////////////////////////////////////////////////////////
458
reed@google.com569e0432011-04-05 13:07:03 +0000459enum FlipAxisEnum {
460 kFlipAxis_X = (1 << 0),
461 kFlipAxis_Y = (1 << 1)
462};
463
reed@google.comf0b5f682011-03-11 20:08:25 +0000464#include "SkDrawFilter.h"
465
bungeman@google.com96aabc82013-06-03 21:26:34 +0000466struct HintingState {
467 SkPaint::Hinting hinting;
468 const char* name;
469 const char* label;
470};
471static HintingState gHintingStates[] = {
472 {SkPaint::kNo_Hinting, "Mixed", NULL },
473 {SkPaint::kNo_Hinting, "None", "H0 " },
474 {SkPaint::kSlight_Hinting, "Slight", "Hs " },
475 {SkPaint::kNormal_Hinting, "Normal", "Hn " },
476 {SkPaint::kFull_Hinting, "Full", "Hf " },
477};
478
reed@google.com569e0432011-04-05 13:07:03 +0000479class FlagsDrawFilter : public SkDrawFilter {
reed@google.comf0b5f682011-03-11 20:08:25 +0000480public:
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000481 FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa, SkOSMenu::TriState filter,
bungeman@google.com96aabc82013-06-03 21:26:34 +0000482 SkOSMenu::TriState subpixel, int hinting)
483 : fLCDState(lcd), fAAState(aa), fFilterState(filter), fSubpixelState(subpixel)
484 , fHintingState(hinting) {}
reed@google.comf0b5f682011-03-11 20:08:25 +0000485
reed@google.com971aca72012-11-26 20:26:54 +0000486 virtual bool filter(SkPaint* paint, Type t) {
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000487 if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
488 paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
reed@google.com569e0432011-04-05 13:07:03 +0000489 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000490 if (SkOSMenu::kMixedState != fAAState) {
491 paint->setAntiAlias(SkOSMenu::kOnState == fAAState);
reed@google.comf0b5f682011-03-11 20:08:25 +0000492 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000493 if (SkOSMenu::kMixedState != fFilterState) {
494 paint->setFilterBitmap(SkOSMenu::kOnState == fFilterState);
reed@google.com176753a2011-05-17 15:32:04 +0000495 }
bungeman@google.com96aabc82013-06-03 21:26:34 +0000496 if (SkOSMenu::kMixedState != fSubpixelState) {
497 paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState);
498 }
bungeman@google.com055aa522013-06-03 21:35:03 +0000499 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) {
bungeman@google.com96aabc82013-06-03 21:26:34 +0000500 paint->setHinting(gHintingStates[fHintingState].hinting);
reed@google.com09e3baa2011-05-18 12:04:31 +0000501 }
reed@google.com971aca72012-11-26 20:26:54 +0000502 return true;
reed@google.comf0b5f682011-03-11 20:08:25 +0000503 }
504
505private:
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000506 SkOSMenu::TriState fLCDState;
507 SkOSMenu::TriState fAAState;
508 SkOSMenu::TriState fFilterState;
bungeman@google.com96aabc82013-06-03 21:26:34 +0000509 SkOSMenu::TriState fSubpixelState;
510 int fHintingState;
reed@google.comf0b5f682011-03-11 20:08:25 +0000511};
512
reed@android.com8a1c16f2008-12-17 15:59:43 +0000513//////////////////////////////////////////////////////////////////////////////
514
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000515#define MAX_ZOOM_LEVEL 8
516#define MIN_ZOOM_LEVEL -8
517
reed@android.comf2b98d62010-12-20 18:26:13 +0000518static const char gCharEvtName[] = "SampleCode_Char_Event";
519static const char gKeyEvtName[] = "SampleCode_Key_Event";
reed@android.com8a1c16f2008-12-17 15:59:43 +0000520static const char gTitleEvtName[] = "SampleCode_Title_Event";
521static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event";
reed@android.comf2b98d62010-12-20 18:26:13 +0000522static const char gFastTextEvtName[] = "SampleCode_FastText_Event";
reed@google.com2072db82011-11-08 15:18:10 +0000523static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle";
reed@android.comf2b98d62010-12-20 18:26:13 +0000524
525bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) {
526 if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) {
527 if (outUni) {
528 *outUni = evt.getFast32();
529 }
530 return true;
531 }
532 return false;
533}
534
535bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) {
536 if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) {
537 if (outKey) {
538 *outKey = (SkKey)evt.getFast32();
539 }
540 return true;
541 }
542 return false;
543}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000544
545bool SampleCode::TitleQ(const SkEvent& evt) {
546 return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1);
547}
548
549void SampleCode::TitleR(SkEvent* evt, const char title[]) {
550 SkASSERT(evt && TitleQ(*evt));
551 evt->setString(gTitleEvtName, title);
552}
553
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000554bool SampleCode::RequestTitle(SkView* view, SkString* title) {
555 SkEvent evt(gTitleEvtName);
556 if (view->doQuery(&evt)) {
557 title->set(evt.findString(gTitleEvtName));
558 return true;
559 }
560 return false;
561}
562
reed@android.com8a1c16f2008-12-17 15:59:43 +0000563bool SampleCode::PrefSizeQ(const SkEvent& evt) {
564 return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1);
565}
566
567void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) {
568 SkASSERT(evt && PrefSizeQ(*evt));
569 SkScalar size[2];
570 size[0] = width;
571 size[1] = height;
572 evt->setScalars(gPrefSizeEvtName, 2, size);
573}
574
reed@android.comf2b98d62010-12-20 18:26:13 +0000575bool SampleCode::FastTextQ(const SkEvent& evt) {
576 return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1);
577}
578
579///////////////////////////////////////////////////////////////////////////////
580
reed@android.com44177402009-11-23 21:07:51 +0000581static SkMSec gAnimTime;
reed@android.comf2b98d62010-12-20 18:26:13 +0000582static SkMSec gAnimTimePrev;
583
reed@android.com44177402009-11-23 21:07:51 +0000584SkMSec SampleCode::GetAnimTime() { return gAnimTime; }
reed@android.comf2b98d62010-12-20 18:26:13 +0000585SkMSec SampleCode::GetAnimTimeDelta() { return gAnimTime - gAnimTimePrev; }
586SkScalar SampleCode::GetAnimSecondsDelta() {
587 return SkDoubleToScalar(GetAnimTimeDelta() / 1000.0);
588}
reed@android.com44177402009-11-23 21:07:51 +0000589
590SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000591 // since gAnimTime can be up to 32 bits, we can't convert it to a float
592 // or we'll lose the low bits. Hence we use doubles for the intermediate
593 // calculations
594 double seconds = (double)gAnimTime / 1000.0;
595 double value = SkScalarToDouble(speed) * seconds;
reed@android.com44177402009-11-23 21:07:51 +0000596 if (period) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000597 value = ::fmod(value, SkScalarToDouble(period));
reed@android.com44177402009-11-23 21:07:51 +0000598 }
reed@android.comf2b98d62010-12-20 18:26:13 +0000599 return SkDoubleToScalar(value);
reed@android.com44177402009-11-23 21:07:51 +0000600}
601
bsalomon@google.com85003222012-03-28 14:44:37 +0000602SkScalar SampleCode::GetAnimSinScalar(SkScalar amplitude,
603 SkScalar periodInSec,
604 SkScalar phaseInSec) {
605 if (!periodInSec) {
606 return 0;
607 }
608 double t = (double)gAnimTime / 1000.0 + phaseInSec;
609 t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
610 amplitude = SK_ScalarHalf * amplitude;
611 return SkScalarMul(amplitude, SkDoubleToScalar(sin(t))) + amplitude;
612}
613
reed@google.com3cec4d72011-07-06 13:59:47 +0000614GrContext* SampleCode::GetGr() {
615 return gSampleWindow ? gSampleWindow->getGrContext() : NULL;
616}
617
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000618// some GMs rely on having a skiagm::GetGr function defined
619namespace skiagm {
caryclark@google.com02939ce2012-06-06 12:09:51 +0000620 // FIXME: this should be moved into a header
621 GrContext* GetGr();
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000622 GrContext* GetGr() { return SampleCode::GetGr(); }
623}
624
reed@android.com8a1c16f2008-12-17 15:59:43 +0000625//////////////////////////////////////////////////////////////////////////////
626
reed@android.comf2b98d62010-12-20 18:26:13 +0000627static SkView* curr_view(SkWindow* wind) {
628 SkView::F2BIter iter(wind);
629 return iter.next();
630}
631
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +0000632static bool curr_title(SkWindow* wind, SkString* title) {
633 SkView* view = curr_view(wind);
634 if (view) {
635 SkEvent evt(gTitleEvtName);
636 if (view->doQuery(&evt)) {
637 title->set(evt.findString(gTitleEvtName));
638 return true;
639 }
640 }
641 return false;
642}
643
Scroggo2c8208f2011-06-15 16:49:08 +0000644void SampleWindow::setZoomCenter(float x, float y)
645{
646 fZoomCenterX = SkFloatToScalar(x);
647 fZoomCenterY = SkFloatToScalar(y);
648}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000649
Scroggo0f185c22011-03-24 18:35:50 +0000650bool SampleWindow::zoomIn()
651{
652 // Arbitrarily decided
653 if (fFatBitsScale == 25) return false;
654 fFatBitsScale++;
655 this->inval(NULL);
656 return true;
657}
658
659bool SampleWindow::zoomOut()
660{
661 if (fFatBitsScale == 1) return false;
662 fFatBitsScale--;
663 this->inval(NULL);
664 return true;
665}
666
Scroggo0f185c22011-03-24 18:35:50 +0000667void SampleWindow::updatePointer(int x, int y)
668{
669 fMouseX = x;
670 fMouseY = y;
671 if (fShowZoomer) {
672 this->inval(NULL);
673 }
674}
675
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000676static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
677 static const SampleWindow::DeviceType gCT[] = {
678 SampleWindow::kPicture_DeviceType,
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000679#if SK_SUPPORT_GPU
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000680 SampleWindow::kGPU_DeviceType,
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000681#if SK_ANGLE
682 SampleWindow::kANGLE_DeviceType,
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000683#endif // SK_ANGLE
bsalomon@google.com74913722011-10-27 20:44:19 +0000684 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000685#endif // SK_SUPPORT_GPU
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000686 SampleWindow::kRaster_DeviceType
reed@android.com8a1c16f2008-12-17 15:59:43 +0000687 };
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000688 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array_size_mismatch);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000689 return gCT[ct];
690}
691
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000692static void usage(const char * argv0) {
chudy@google.com4605a3f2012-08-01 17:58:01 +0000693 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir dirPath] [--picture path]\n", argv0);
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000694 SkDebugf(" sampleName: sample at which to start.\n");
695 SkDebugf(" resourcePath: directory that stores image resources.\n");
bsalomon@google.com11959252012-04-06 20:13:38 +0000696 SkDebugf(" msaa: request multisampling with the given sample count.\n");
chudy@google.com4605a3f2012-08-01 17:58:01 +0000697 SkDebugf(" dirPath: path to directory skia pictures are read from\n");
698 SkDebugf(" path: path to skia picture\n");
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000699}
700
chudy@google.com4605a3f2012-08-01 17:58:01 +0000701SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager)
robertphillips@google.com4750fa52012-04-10 13:34:11 +0000702 : INHERITED(hwnd)
703 , fDevManager(NULL) {
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000704
reed@google.com7d05ac92013-06-06 13:14:13 +0000705 fCurrIndex = -1;
706
reed@google.com1830c7a2012-06-04 12:05:43 +0000707 this->registerPictFileSamples(argv, argc);
chudy@google.com4605a3f2012-08-01 17:58:01 +0000708 this->registerPictFileSample(argv, argc);
robertphillips@google.com76d40212012-03-22 14:12:15 +0000709 SkGMRegistyToSampleRegistry();
710 {
711 const SkViewRegister* reg = SkViewRegister::Head();
712 while (reg) {
713 *fSamples.append() = reg->factory();
714 reg = reg->next();
715 }
716 }
717
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000718 const char* resourcePath = NULL;
bsalomon@google.com11959252012-04-06 20:13:38 +0000719 fMSAASampleCount = 0;
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000720
721 const char* const commandName = argv[0];
722 char* const* stop = argv + argc;
723 for (++argv; argv < stop; ++argv) {
724 if (strcmp(*argv, "-i") == 0) {
725 argv++;
726 if (argv < stop && **argv) {
727 resourcePath = *argv;
728 }
robertphillips@google.com76d40212012-03-22 14:12:15 +0000729 } else if (strcmp(*argv, "--slide") == 0) {
730 argv++;
731 if (argv < stop && **argv) {
732 fCurrIndex = findByTitle(*argv);
733 if (fCurrIndex < 0) {
734 fprintf(stderr, "Unknown sample \"%s\"\n", *argv);
robertphillips@google.com7265e722012-05-03 18:22:28 +0000735 listTitles();
robertphillips@google.com76d40212012-03-22 14:12:15 +0000736 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000737 }
bsalomon@google.com11959252012-04-06 20:13:38 +0000738 } else if (strcmp(*argv, "--msaa") == 0) {
739 ++argv;
740 if (argv < stop && **argv) {
741 fMSAASampleCount = atoi(*argv);
742 }
robertphillips@google.com7265e722012-05-03 18:22:28 +0000743 } else if (strcmp(*argv, "--list") == 0) {
744 listTitles();
bsalomon@google.com11959252012-04-06 20:13:38 +0000745 }
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +0000746 else {
robertphillips@google.com76d40212012-03-22 14:12:15 +0000747 usage(commandName);
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000748 }
749 }
750
751 if (fCurrIndex < 0) {
752 SkString title;
753 if (readTitleFromPrefs(&title)) {
754 fCurrIndex = findByTitle(title.c_str());
755 }
756 }
757
758 if (fCurrIndex < 0) {
759 fCurrIndex = 0;
760 }
761
reed@google.com3cec4d72011-07-06 13:59:47 +0000762 gSampleWindow = this;
763
yangsu@google.com1f394212011-06-01 18:03:34 +0000764#ifdef PIPE_FILE
765 //Clear existing file or create file if it doesn't exist
766 FILE* f = fopen(FILE_PATH, "wb");
767 fclose(f);
768#endif
chudy@google.com4605a3f2012-08-01 17:58:01 +0000769
reed@android.com8a1c16f2008-12-17 15:59:43 +0000770 fPicture = NULL;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000771
robertphillips@google.combd8d7ad2012-03-30 15:18:14 +0000772 fDeviceType = kRaster_DeviceType;
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000773
774#if DEFAULT_TO_GPU
775 fDeviceType = kGPU_DeviceType;
reed@android.comf2b98d62010-12-20 18:26:13 +0000776#endif
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000777#if SK_ANGLE && DEFAULT_TO_ANGLE
778 fDeviceType = kANGLE_DeviceType;
779#endif
780
reed@android.com8a1c16f2008-12-17 15:59:43 +0000781 fUseClip = false;
reed@android.come522ca52009-11-23 20:10:41 +0000782 fNClip = false;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000783 fAnimating = false;
reed@android.com6c5f6f22009-08-14 16:08:38 +0000784 fRotate = false;
bungeman@google.comb1785912013-07-09 21:58:56 +0000785 fRotateAnimTime = 0;
bsalomon@google.come8f09102011-09-08 18:48:12 +0000786 fPerspAnim = false;
787 fPerspAnimTime = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000788 fRequestGrabImage = false;
scroggo@google.comb073d922012-06-08 15:35:03 +0000789 fPipeState = SkOSMenu::kOffState;
reed@google.com67b89ee2012-08-15 14:41:58 +0000790 fTilingState = SkOSMenu::kOffState;
scroggo@google.com85cade02012-08-17 13:29:50 +0000791 fTileCount.set(1, 1);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000792 fMeasureFPS = false;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000793 fLCDState = SkOSMenu::kMixedState;
794 fAAState = SkOSMenu::kMixedState;
795 fFilterState = SkOSMenu::kMixedState;
bungeman@google.com96aabc82013-06-03 21:26:34 +0000796 fSubpixelState = SkOSMenu::kMixedState;
797 fHintingState = 0;
reed@google.com569e0432011-04-05 13:07:03 +0000798 fFlipAxis = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000799 fScrollTestX = fScrollTestY = 0;
800
Scroggo0f185c22011-03-24 18:35:50 +0000801 fMouseX = fMouseY = 0;
mike@reedtribe.org3ce59dc2011-04-08 00:38:05 +0000802 fFatBitsScale = 8;
Scroggo0f185c22011-03-24 18:35:50 +0000803 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold);
804 fShowZoomer = false;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000805
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000806 fZoomLevel = 0;
807 fZoomScale = SK_Scalar1;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000808
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000809 fMagnify = false;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000810
Scroggo8ac0d542011-06-21 14:44:57 +0000811 fSaveToPdf = false;
812 fPdfCanvas = NULL;
813
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000814 fTransitionNext = 6;
815 fTransitionPrev = 2;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000816
yangsu@google.com921091f2011-08-02 13:39:12 +0000817 int sinkID = this->getSinkID();
scroggo@google.com7dadc742012-04-18 14:07:57 +0000818 fAppMenu = new SkOSMenu;
819 fAppMenu->setTitle("Global Settings");
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000820 int itemID;
chudy@google.com4605a3f2012-08-01 17:58:01 +0000821
822 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
823 "Raster", "Picture", "OpenGL",
robertphillips@google.comb442a6d2012-04-02 19:24:21 +0000824#if SK_ANGLE
825 "ANGLE",
826#endif
827 NULL);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000828 fAppMenu->assignKeyEquivalentToItem(itemID, 'd');
829 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState);
830 fAppMenu->assignKeyEquivalentToItem(itemID, 'b');
831 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState);
832 fAppMenu->assignKeyEquivalentToItem(itemID, 'l');
833 itemID = fAppMenu->appendTriState("Filter", "Filter", sinkID, fFilterState);
834 fAppMenu->assignKeyEquivalentToItem(itemID, 'n');
bungeman@google.com96aabc82013-06-03 21:26:34 +0000835 itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelState);
836 fAppMenu->assignKeyEquivalentToItem(itemID, 's');
837 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState,
838 gHintingStates[0].name,
839 gHintingStates[1].name,
840 gHintingStates[2].name,
841 gHintingStates[3].name,
bungeman@google.coma9133bb2013-06-04 17:49:20 +0000842 gHintingStates[4].name,
843 NULL);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000844 fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
reed@google.com67b89ee2012-08-15 14:41:58 +0000845
scroggo@google.comb073d922012-06-08 15:35:03 +0000846 fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID,
chudy@google.com4605a3f2012-08-01 17:58:01 +0000847 fPipeState);
scroggo@google.comb073d922012-06-08 15:35:03 +0000848 fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P');
reed@google.com67b89ee2012-08-15 14:41:58 +0000849
850 itemID = fAppMenu->appendTriState("Tiling", "Tiling", sinkID, fTilingState);
851 fAppMenu->assignKeyEquivalentToItem(itemID, 't');
852
chudy@google.com4605a3f2012-08-01 17:58:01 +0000853 itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false);
854 fAppMenu->assignKeyEquivalentToItem(itemID, 'a');
855 itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000856 fAppMenu->assignKeyEquivalentToItem(itemID, 'c');
chudy@google.com4605a3f2012-08-01 17:58:01 +0000857 itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000858 fAppMenu->assignKeyEquivalentToItem(itemID, 'x');
859 itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false);
860 fAppMenu->assignKeyEquivalentToItem(itemID, 'y');
861 itemID = fAppMenu->appendSwitch("Zoomer", "Zoomer" , sinkID, fShowZoomer);
862 fAppMenu->assignKeyEquivalentToItem(itemID, 'z');
863 itemID = fAppMenu->appendSwitch("Magnify", "Magnify" , sinkID, fMagnify);
864 fAppMenu->assignKeyEquivalentToItem(itemID, 'm');
chudy@google.com4605a3f2012-08-01 17:58:01 +0000865 itemID =fAppMenu->appendList("Transition-Next", "Transition-Next", sinkID,
866 fTransitionNext, "Up", "Up and Right", "Right",
867 "Down and Right", "Down", "Down and Left",
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000868 "Left", "Up and Left", NULL);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000869 fAppMenu->assignKeyEquivalentToItem(itemID, 'j');
chudy@google.com4605a3f2012-08-01 17:58:01 +0000870 itemID =fAppMenu->appendList("Transition-Prev", "Transition-Prev", sinkID,
871 fTransitionPrev, "Up", "Up and Right", "Right",
872 "Down and Right", "Down", "Down and Left",
yangsu@google.comdb03eaa2011-08-08 15:37:23 +0000873 "Left", "Up and Left", NULL);
scroggo@google.com7dadc742012-04-18 14:07:57 +0000874 fAppMenu->assignKeyEquivalentToItem(itemID, 'k');
875 itemID = fAppMenu->appendAction("Save to PDF", sinkID);
876 fAppMenu->assignKeyEquivalentToItem(itemID, 'e');
chudy@google.com4605a3f2012-08-01 17:58:01 +0000877
scroggo@google.com7dadc742012-04-18 14:07:57 +0000878 this->addMenu(fAppMenu);
879 fSlideMenu = new SkOSMenu;
880 this->addMenu(fSlideMenu);
chudy@google.com4605a3f2012-08-01 17:58:01 +0000881
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000882// this->setConfig(SkBitmap::kRGB_565_Config);
883 this->setConfig(SkBitmap::kARGB_8888_Config);
884 this->setVisibleP(true);
reed@android.comf2b98d62010-12-20 18:26:13 +0000885 this->setClipToBounds(false);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000886
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000887 skiagm::GM::SetResourcePath(resourcePath);
888
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000889 this->loadView((*fSamples[fCurrIndex])());
chudy@google.com4605a3f2012-08-01 17:58:01 +0000890
bsalomon@google.com840e9f32011-07-06 21:59:09 +0000891 fPDFData = NULL;
reed@google.comf0b5f682011-03-11 20:08:25 +0000892
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000893 if (NULL == devManager) {
894 fDevManager = new DefaultDeviceManager();
895 } else {
896 devManager->ref();
897 fDevManager = devManager;
898 }
bsalomon@google.com11959252012-04-06 20:13:38 +0000899 fDevManager->setUpBackend(this, fMSAASampleCount);
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000900
Scroggob4490c72011-06-17 13:53:05 +0000901 // If another constructor set our dimensions, ensure that our
902 // onSizeChange gets called.
903 if (this->height() && this->width()) {
904 this->onSizeChange();
905 }
reed@google.com2072db82011-11-08 15:18:10 +0000906
907 // can't call this synchronously, since it may require a subclass to
908 // to implement, or the caller may need us to have returned from the
909 // constructor first. Hence we post an event to ourselves.
910// this->updateTitle();
911 postEventToSink(new SkEvent(gUpdateWindowTitleEvtName), this);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000912}
913
914SampleWindow::~SampleWindow() {
915 delete fPicture;
Scroggo8ac0d542011-06-21 14:44:57 +0000916 delete fPdfCanvas;
Scroggo0f185c22011-03-24 18:35:50 +0000917 fTypeface->unref();
reed@google.com29038ed2011-07-06 17:56:47 +0000918
bsalomon@google.com098e96d2011-07-14 14:30:46 +0000919 SkSafeUnref(fDevManager);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000920}
921
reed@google.com1830c7a2012-06-04 12:05:43 +0000922static void make_filepath(SkString* path, const char* dir, const SkString& name) {
923 size_t len = strlen(dir);
924 path->set(dir);
925 if (len > 0 && dir[len - 1] != '/') {
926 path->append("/");
927 }
928 path->append(name);
929}
930
chudy@google.com4605a3f2012-08-01 17:58:01 +0000931void SampleWindow::registerPictFileSample(char** argv, int argc) {
932 const char* pict = NULL;
933
934 for (int i = 0; i < argc; ++i) {
935 if (!strcmp(argv[i], "--picture")) {
936 i += 1;
937 if (i < argc) {
938 pict = argv[i];
939 break;
940 }
941 }
942 }
943 if (pict) {
944 SkString path(pict);
reed@google.com7d05ac92013-06-06 13:14:13 +0000945 fCurrIndex = fSamples.count();
chudy@google.com4605a3f2012-08-01 17:58:01 +0000946 *fSamples.append() = new PictFileFactory(path);
947 }
948}
949
reed@google.com1830c7a2012-06-04 12:05:43 +0000950void SampleWindow::registerPictFileSamples(char** argv, int argc) {
951 const char* pictDir = NULL;
952
953 for (int i = 0; i < argc; ++i) {
954 if (!strcmp(argv[i], "--pictureDir")) {
955 i += 1;
956 if (i < argc) {
957 pictDir = argv[i];
958 break;
959 }
960 }
961 }
962 if (pictDir) {
963 SkOSFile::Iter iter(pictDir, "skp");
964 SkString filename;
965 while (iter.next(&filename)) {
966 SkString path;
967 make_filepath(&path, pictDir, filename);
968 *fSamples.append() = new PictFileFactory(path);
969 }
970 }
971}
972
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +0000973int SampleWindow::findByTitle(const char title[]) {
974 int i, count = fSamples.count();
975 for (i = 0; i < count; i++) {
976 if (getSampleTitle(i).equals(title)) {
977 return i;
978 }
979 }
mike@reedtribe.orgdd52caa2011-12-28 20:02:10 +0000980 return -1;
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +0000981}
982
robertphillips@google.com7265e722012-05-03 18:22:28 +0000983void SampleWindow::listTitles() {
984 int count = fSamples.count();
985 SkDebugf("All Slides:\n");
986 for (int i = 0; i < count; i++) {
987 SkDebugf(" %s\n", getSampleTitle(i).c_str());
988 }
989}
990
reed@android.com55e76b22009-11-23 21:46:47 +0000991static SkBitmap capture_bitmap(SkCanvas* canvas) {
992 SkBitmap bm;
993 const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
994 src.copyTo(&bm, src.config());
995 return bm;
996}
997
998static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
999 SkBitmap* diff) {
1000 const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001001
reed@android.com55e76b22009-11-23 21:46:47 +00001002 SkAutoLockPixels alp0(src);
1003 SkAutoLockPixels alp1(orig);
1004 for (int y = 0; y < src.height(); y++) {
1005 const void* srcP = src.getAddr(0, y);
1006 const void* origP = orig.getAddr(0, y);
1007 size_t bytes = src.width() * src.bytesPerPixel();
1008 if (memcmp(srcP, origP, bytes)) {
1009 SkDebugf("---------- difference on line %d\n", y);
1010 return true;
1011 }
1012 }
1013 return false;
1014}
1015
Scroggo0f185c22011-03-24 18:35:50 +00001016static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
1017{
1018 SkColor desiredColor = paint.getColor();
1019 paint.setColor(SK_ColorWHITE);
1020 const char* c_str = string.c_str();
1021 size_t size = string.size();
1022 SkRect bounds;
1023 paint.measureText(c_str, size, &bounds);
1024 bounds.offset(left, top);
1025 SkScalar inset = SkIntToScalar(-2);
1026 bounds.inset(inset, inset);
1027 canvas->drawRect(bounds, paint);
1028 if (desiredColor != SK_ColorBLACK) {
1029 paint.setColor(SK_ColorBLACK);
1030 canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint);
1031 }
1032 paint.setColor(desiredColor);
1033 canvas->drawText(c_str, size, left, top, paint);
1034}
1035
reed@android.com44177402009-11-23 21:07:51 +00001036#define XCLIP_N 8
1037#define YCLIP_N 8
reed@android.come522ca52009-11-23 20:10:41 +00001038
1039void SampleWindow::draw(SkCanvas* canvas) {
reed@android.com44177402009-11-23 21:07:51 +00001040 // update the animation time
bsalomon@google.come8f09102011-09-08 18:48:12 +00001041 if (!gAnimTimePrev && !gAnimTime) {
1042 // first time make delta be 0
1043 gAnimTime = SkTime::GetMSecs();
1044 gAnimTimePrev = gAnimTime;
1045 } else {
1046 gAnimTimePrev = gAnimTime;
1047 gAnimTime = SkTime::GetMSecs();
1048 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001049
reed@google.comf03bb562011-11-11 21:42:12 +00001050 if (fGesture.isActive()) {
1051 this->updateMatrix();
reed@google.com52f57e12011-03-16 12:10:02 +00001052 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001053
djsollen@google.com796763e2012-12-10 14:12:55 +00001054 if (fMeasureFPS) {
1055 fMeasureFPS_Time = 0;
1056 }
1057
reed@android.come522ca52009-11-23 20:10:41 +00001058 if (fNClip) {
reed@android.com55e76b22009-11-23 21:46:47 +00001059 this->INHERITED::draw(canvas);
1060 SkBitmap orig = capture_bitmap(canvas);
reed@android.come522ca52009-11-23 20:10:41 +00001061
1062 const SkScalar w = this->width();
1063 const SkScalar h = this->height();
1064 const SkScalar cw = w / XCLIP_N;
1065 const SkScalar ch = h / YCLIP_N;
1066 for (int y = 0; y < YCLIP_N; y++) {
reed@android.com55e76b22009-11-23 21:46:47 +00001067 SkRect r;
1068 r.fTop = y * ch;
1069 r.fBottom = (y + 1) * ch;
1070 if (y == YCLIP_N - 1) {
1071 r.fBottom = h;
1072 }
reed@android.come522ca52009-11-23 20:10:41 +00001073 for (int x = 0; x < XCLIP_N; x++) {
1074 SkAutoCanvasRestore acr(canvas, true);
reed@android.com55e76b22009-11-23 21:46:47 +00001075 r.fLeft = x * cw;
1076 r.fRight = (x + 1) * cw;
1077 if (x == XCLIP_N - 1) {
1078 r.fRight = w;
1079 }
reed@android.come522ca52009-11-23 20:10:41 +00001080 canvas->clipRect(r);
1081 this->INHERITED::draw(canvas);
1082 }
1083 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001084
reed@android.com55e76b22009-11-23 21:46:47 +00001085 SkBitmap diff;
1086 if (bitmap_diff(canvas, orig, &diff)) {
1087 }
reed@android.come522ca52009-11-23 20:10:41 +00001088 } else {
scroggo@google.com85cade02012-08-17 13:29:50 +00001089 const SkScalar cw = SkScalarDiv(this->width(), SkIntToScalar(fTileCount.width()));
1090 const SkScalar ch = SkScalarDiv(this->height(), SkIntToScalar(fTileCount.height()));
rmistry@google.comae933ce2012-08-23 18:19:56 +00001091
scroggo@google.com85cade02012-08-17 13:29:50 +00001092 for (int y = 0; y < fTileCount.height(); ++y) {
1093 for (int x = 0; x < fTileCount.width(); ++x) {
1094 SkAutoCanvasRestore acr(canvas, true);
1095 canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch));
1096 this->INHERITED::draw(canvas);
1097 }
1098 }
rmistry@google.comae933ce2012-08-23 18:19:56 +00001099
scroggo@google.com85cade02012-08-17 13:29:50 +00001100 if (!fTileCount.equals(1, 1)) {
1101 SkPaint paint;
1102 paint.setColor(0x60FF00FF);
1103 paint.setStyle(SkPaint::kStroke_Style);
1104 for (int y = 0; y < fTileCount.height(); ++y) {
1105 for (int x = 0; x < fTileCount.width(); ++x) {
1106 canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), paint);
1107 }
1108 }
1109 }
reed@android.come522ca52009-11-23 20:10:41 +00001110 }
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001111 if (fShowZoomer && !fSaveToPdf) {
Scroggo3272ba82011-05-25 20:50:42 +00001112 showZoomer(canvas);
1113 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001114 if (fMagnify && !fSaveToPdf) {
1115 magnify(canvas);
1116 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001117
djsollen@google.com796763e2012-12-10 14:12:55 +00001118 if (fMeasureFPS && fMeasureFPS_Time) {
1119 this->updateTitle();
1120 this->postInvalDelay();
1121 }
1122
reed@google.com29038ed2011-07-06 17:56:47 +00001123 // do this last
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001124 fDevManager->publishCanvas(fDeviceType, canvas, this);
Scroggo3272ba82011-05-25 20:50:42 +00001125}
1126
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001127static float clipW = 200;
1128static float clipH = 200;
1129void SampleWindow::magnify(SkCanvas* canvas) {
1130 SkRect r;
1131 int count = canvas->save();
chudy@google.com4605a3f2012-08-01 17:58:01 +00001132
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001133 SkMatrix m = canvas->getTotalMatrix();
robertphillips@google.com07ef9112012-06-04 13:22:14 +00001134 if (!m.invert(&m)) {
1135 return;
1136 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001137 SkPoint offset, center;
bsalomon@google.com820e80a2011-10-24 21:09:40 +00001138 SkScalar mouseX = fMouseX * SK_Scalar1;
1139 SkScalar mouseY = fMouseY * SK_Scalar1;
1140 m.mapXY(mouseX - clipW/2, mouseY - clipH/2, &offset);
1141 m.mapXY(mouseX, mouseY, &center);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001142
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001143 r.set(0, 0, clipW * m.getScaleX(), clipH * m.getScaleX());
1144 r.offset(offset.fX, offset.fY);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001145
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001146 SkPaint paint;
1147 paint.setColor(0xFF66AAEE);
1148 paint.setStyle(SkPaint::kStroke_Style);
bsalomon@google.com820e80a2011-10-24 21:09:40 +00001149 paint.setStrokeWidth(10.f * m.getScaleX());
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001150 //lense offset
1151 //canvas->translate(0, -250);
1152 canvas->drawRect(r, paint);
1153 canvas->clipRect(r);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001154
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001155 m = canvas->getTotalMatrix();
1156 m.setTranslate(-center.fX, -center.fY);
bsalomon@google.com820e80a2011-10-24 21:09:40 +00001157 m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001158 m.postTranslate(center.fX, center.fY);
1159 canvas->concat(m);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001160
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001161 this->INHERITED::draw(canvas);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001162
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001163 canvas->restoreToCount(count);
1164}
1165
Scroggo3272ba82011-05-25 20:50:42 +00001166void SampleWindow::showZoomer(SkCanvas* canvas) {
Scroggo0f185c22011-03-24 18:35:50 +00001167 int count = canvas->save();
1168 canvas->resetMatrix();
1169 // Ensure the mouse position is on screen.
reed@google.com261b8e22011-04-14 17:53:24 +00001170 int width = SkScalarRound(this->width());
1171 int height = SkScalarRound(this->height());
Scroggo0f185c22011-03-24 18:35:50 +00001172 if (fMouseX >= width) fMouseX = width - 1;
1173 else if (fMouseX < 0) fMouseX = 0;
1174 if (fMouseY >= height) fMouseY = height - 1;
1175 else if (fMouseY < 0) fMouseY = 0;
reed@google.comb36334d2011-05-18 15:07:20 +00001176
Scroggo0f185c22011-03-24 18:35:50 +00001177 SkBitmap bitmap = capture_bitmap(canvas);
reed@google.comb36334d2011-05-18 15:07:20 +00001178 bitmap.lockPixels();
1179
Scroggo0f185c22011-03-24 18:35:50 +00001180 // Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle.
mike@reedtribe.org3ce59dc2011-04-08 00:38:05 +00001181 int zoomedWidth = (width >> 1) | 1;
1182 int zoomedHeight = (height >> 1) | 1;
Scroggo0f185c22011-03-24 18:35:50 +00001183 SkIRect src;
1184 src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale);
1185 src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1));
1186 SkRect dest;
1187 dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight));
1188 dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight));
1189 SkPaint paint;
1190 // Clear the background behind our zoomed in view
1191 paint.setColor(SK_ColorWHITE);
1192 canvas->drawRect(dest, paint);
1193 canvas->drawBitmapRect(bitmap, &src, dest);
1194 paint.setColor(SK_ColorBLACK);
1195 paint.setStyle(SkPaint::kStroke_Style);
1196 // Draw a border around the pixel in the middle
1197 SkRect originalPixel;
1198 originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1));
1199 SkMatrix matrix;
1200 SkRect scalarSrc;
1201 scalarSrc.set(src);
1202 SkColor color = bitmap.getColor(fMouseX, fMouseY);
1203 if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) {
1204 SkRect pixel;
1205 matrix.mapRect(&pixel, originalPixel);
1206 // TODO Perhaps measure the values and make the outline white if it's "dark"
1207 if (color == SK_ColorBLACK) {
1208 paint.setColor(SK_ColorWHITE);
1209 }
1210 canvas->drawRect(pixel, paint);
1211 }
1212 paint.setColor(SK_ColorBLACK);
1213 // Draw a border around the destination rectangle
1214 canvas->drawRect(dest, paint);
1215 paint.setStyle(SkPaint::kStrokeAndFill_Style);
1216 // Identify the pixel and its color on screen
1217 paint.setTypeface(fTypeface);
1218 paint.setAntiAlias(true);
1219 SkScalar lineHeight = paint.getFontMetrics(NULL);
1220 SkString string;
1221 string.appendf("(%i, %i)", fMouseX, fMouseY);
1222 SkScalar left = dest.fLeft + SkIntToScalar(3);
1223 SkScalar i = SK_Scalar1;
1224 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1225 // Alpha
1226 i += SK_Scalar1;
1227 string.reset();
1228 string.appendf("A: %X", SkColorGetA(color));
1229 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1230 // Red
1231 i += SK_Scalar1;
1232 string.reset();
1233 string.appendf("R: %X", SkColorGetR(color));
1234 paint.setColor(SK_ColorRED);
1235 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1236 // Green
1237 i += SK_Scalar1;
1238 string.reset();
1239 string.appendf("G: %X", SkColorGetG(color));
1240 paint.setColor(SK_ColorGREEN);
1241 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1242 // Blue
1243 i += SK_Scalar1;
1244 string.reset();
1245 string.appendf("B: %X", SkColorGetB(color));
1246 paint.setColor(SK_ColorBLUE);
1247 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1248 canvas->restoreToCount(count);
reed@android.come522ca52009-11-23 20:10:41 +00001249}
1250
reed@android.com8a1c16f2008-12-17 15:59:43 +00001251void SampleWindow::onDraw(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001252}
1253
1254#include "SkColorPriv.h"
1255
caryclark@google.com02939ce2012-06-06 12:09:51 +00001256#if 0 // UNUSED
reed@android.com8a1c16f2008-12-17 15:59:43 +00001257static void reverseRedAndBlue(const SkBitmap& bm) {
1258 SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
1259 uint8_t* p = (uint8_t*)bm.getPixels();
1260 uint8_t* stop = p + bm.getSize();
1261 while (p < stop) {
1262 // swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply
1263 unsigned scale = SkAlpha255To256(p[3]);
1264 unsigned r = p[2];
1265 unsigned b = p[0];
1266 p[0] = SkAlphaMul(r, scale);
1267 p[1] = SkAlphaMul(p[1], scale);
1268 p[2] = SkAlphaMul(b, scale);
1269 p += 4;
1270 }
1271}
caryclark@google.com02939ce2012-06-06 12:09:51 +00001272#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00001273
Scroggo8ac0d542011-06-21 14:44:57 +00001274void SampleWindow::saveToPdf()
1275{
1276 fSaveToPdf = true;
1277 this->inval(NULL);
1278}
1279
reed@android.com8a1c16f2008-12-17 15:59:43 +00001280SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
Scroggo8ac0d542011-06-21 14:44:57 +00001281 if (fSaveToPdf) {
1282 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false);
1283 SkISize size = SkISize::Make(bmp.width(), bmp.height());
1284 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size,
1285 canvas->getTotalMatrix());
1286 fPdfCanvas = new SkCanvas(pdfDevice);
1287 pdfDevice->unref();
1288 canvas = fPdfCanvas;
bsalomon@google.com82502e22013-01-24 20:47:18 +00001289 } else if (kPicture_DeviceType == fDeviceType) {
1290 fPicture = new SkPicture;
1291 canvas = fPicture->beginRecording(9999, 9999);
Scroggo8ac0d542011-06-21 14:44:57 +00001292 } else {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001293#if SK_SUPPORT_GPU
bsalomon@google.com82502e22013-01-24 20:47:18 +00001294 if (kNullGPU_DeviceType != fDeviceType)
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001295#endif
bsalomon@google.com82502e22013-01-24 20:47:18 +00001296 {
1297 canvas = this->INHERITED::beforeChildren(canvas);
reed@google.comac10a2d2010-12-22 21:39:39 +00001298 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001299 }
1300
1301 if (fUseClip) {
1302 canvas->drawColor(0xFFFF88FF);
reed@google.com045e62d2011-10-24 12:19:46 +00001303 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001304 }
1305
1306 return canvas;
1307}
1308
1309static void paint_rgn(const SkBitmap& bm, const SkIRect& r,
1310 const SkRegion& rgn) {
1311 SkCanvas canvas(bm);
1312 SkRegion inval(rgn);
1313
1314 inval.translate(r.fLeft, r.fTop);
1315 canvas.clipRegion(inval);
1316 canvas.drawColor(0xFFFF8080);
1317}
yangsu@google.com501775e2011-06-24 16:04:50 +00001318#include "SkData.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00001319void SampleWindow::afterChildren(SkCanvas* orig) {
Scroggo8ac0d542011-06-21 14:44:57 +00001320 if (fSaveToPdf) {
1321 fSaveToPdf = false;
1322 if (fShowZoomer) {
1323 showZoomer(fPdfCanvas);
1324 }
1325 SkString name;
1326 name.printf("%s.pdf", this->getTitle());
1327 SkPDFDocument doc;
1328 SkPDFDevice* device = static_cast<SkPDFDevice*>(fPdfCanvas->getDevice());
1329 doc.appendPage(device);
djsollen@google.com56c69772011-11-08 19:00:26 +00001330#ifdef SK_BUILD_FOR_ANDROID
Scroggo8ac0d542011-06-21 14:44:57 +00001331 name.prepend("/sdcard/");
1332#endif
chudy@google.com4605a3f2012-08-01 17:58:01 +00001333
yangsu@google.com501775e2011-06-24 16:04:50 +00001334#ifdef SK_BUILD_FOR_IOS
1335 SkDynamicMemoryWStream mstream;
1336 doc.emitPDF(&mstream);
yangsu@google.comae8a2e52011-06-24 21:09:39 +00001337 fPDFData = mstream.copyToData();
yangsu@google.com501775e2011-06-24 16:04:50 +00001338#endif
Scroggo8ac0d542011-06-21 14:44:57 +00001339 SkFILEWStream stream(name.c_str());
1340 if (stream.isValid()) {
1341 doc.emitPDF(&stream);
1342 const char* desc = "File saved from Skia SampleApp";
1343 this->onPDFSaved(this->getTitle(), desc, name.c_str());
1344 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001345
Scroggo8ac0d542011-06-21 14:44:57 +00001346 delete fPdfCanvas;
1347 fPdfCanvas = NULL;
1348
1349 // We took over the draw calls in order to create the PDF, so we need
1350 // to redraw.
1351 this->inval(NULL);
1352 return;
1353 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001354
reed@android.comf2b98d62010-12-20 18:26:13 +00001355 if (fRequestGrabImage) {
1356 fRequestGrabImage = false;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001357
reed@google.com29038ed2011-07-06 17:56:47 +00001358 SkDevice* device = orig->getDevice();
bsalomon@google.com669fdc42011-04-05 17:08:27 +00001359 SkBitmap bmp;
1360 if (device->accessBitmap(false).copyTo(&bmp, SkBitmap::kARGB_8888_Config)) {
reed@android.comf2b98d62010-12-20 18:26:13 +00001361 static int gSampleGrabCounter;
1362 SkString name;
reed@google.com7c57e0e2012-09-08 21:20:33 +00001363 name.printf("sample_grab_%d.png", gSampleGrabCounter++);
bsalomon@google.com669fdc42011-04-05 17:08:27 +00001364 SkImageEncoder::EncodeFile(name.c_str(), bmp,
reed@android.comf2b98d62010-12-20 18:26:13 +00001365 SkImageEncoder::kPNG_Type, 100);
1366 }
1367 }
1368
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001369 if (kPicture_DeviceType == fDeviceType) {
1370 if (true) {
1371 SkPicture* pict = new SkPicture(*fPicture);
1372 fPicture->unref();
reed@google.come23f1942011-12-08 19:36:00 +00001373 this->installDrawFilter(orig);
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001374 orig->drawPicture(*pict);
1375 pict->unref();
1376 } else if (true) {
1377 SkDynamicMemoryWStream ostream;
1378 fPicture->serialize(&ostream);
1379 fPicture->unref();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001380
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001381 SkAutoDataUnref data(ostream.copyToData());
robertphillips@google.com59f46b82012-07-10 17:30:58 +00001382 SkMemoryStream istream(data->data(), data->size());
scroggo@google.comf1754ec2013-06-28 21:32:00 +00001383 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream));
1384 if (pict.get() != NULL) {
1385 orig->drawPicture(*pict.get());
1386 }
bsalomon@google.com098e96d2011-07-14 14:30:46 +00001387 } else {
1388 fPicture->draw(orig);
1389 fPicture->unref();
1390 }
1391 fPicture = NULL;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001392 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001393
reed@google.com17d7aec2011-04-25 14:31:44 +00001394 // Do this after presentGL and other finishing, rather than in afterChild
djsollen@google.com796763e2012-12-10 14:12:55 +00001395 if (fMeasureFPS && fMeasureFPS_StartTime) {
1396 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime;
reed@google.com17d7aec2011-04-25 14:31:44 +00001397 }
1398
1399 // if ((fScrollTestX | fScrollTestY) != 0)
reed@android.comf2b98d62010-12-20 18:26:13 +00001400 if (false) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001401 const SkBitmap& bm = orig->getDevice()->accessBitmap(true);
1402 int dx = fScrollTestX * 7;
1403 int dy = fScrollTestY * 7;
1404 SkIRect r;
1405 SkRegion inval;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001406
reed@android.com8a1c16f2008-12-17 15:59:43 +00001407 r.set(50, 50, 50+100, 50+100);
1408 bm.scrollRect(&r, dx, dy, &inval);
1409 paint_rgn(bm, r, inval);
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001410 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001411}
1412
reed@android.com6c5f6f22009-08-14 16:08:38 +00001413void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
reed@android.com6c5f6f22009-08-14 16:08:38 +00001414 if (fRotate) {
bungeman@google.comb1785912013-07-09 21:58:56 +00001415 fRotateAnimTime += SampleCode::GetAnimSecondsDelta();
1416
reed@android.com6c5f6f22009-08-14 16:08:38 +00001417 SkScalar cx = this->width() / 2;
1418 SkScalar cy = this->height() / 2;
1419 canvas->translate(cx, cy);
bungeman@google.comb1785912013-07-09 21:58:56 +00001420 canvas->rotate(fRotateAnimTime * 10);
reed@android.com6c5f6f22009-08-14 16:08:38 +00001421 canvas->translate(-cx, -cy);
1422 }
bungeman@google.comb1785912013-07-09 21:58:56 +00001423
bsalomon@google.come8f09102011-09-08 18:48:12 +00001424 if (fPerspAnim) {
bsalomon@google.com6fb736f2011-09-16 18:51:57 +00001425 fPerspAnimTime += SampleCode::GetAnimSecondsDelta();
1426
1427 static const SkScalar gAnimPeriod = 10 * SK_Scalar1;
1428 static const SkScalar gAnimMag = SK_Scalar1 / 1000;
1429 SkScalar t = SkScalarMod(fPerspAnimTime, gAnimPeriod);
1430 if (SkScalarFloorToInt(SkScalarDiv(fPerspAnimTime, gAnimPeriod)) & 0x1) {
1431 t = gAnimPeriod - t;
1432 }
1433 t = 2 * t - gAnimPeriod;
1434 t = SkScalarMul(SkScalarDiv(t, gAnimPeriod), gAnimMag);
1435 SkMatrix m;
1436 m.reset();
1437 m.setPerspY(t);
bsalomon@google.come8f09102011-09-08 18:48:12 +00001438 canvas->concat(m);
1439 }
reed@google.comf0b5f682011-03-11 20:08:25 +00001440
reed@google.come23f1942011-12-08 19:36:00 +00001441 this->installDrawFilter(canvas);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001442
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001443 if (fMeasureFPS) {
reed@google.comf2183392011-04-22 14:10:48 +00001444 if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
djsollen@google.com796763e2012-12-10 14:12:55 +00001445 fMeasureFPS_StartTime = SkTime::GetMSecs();
reed@google.comf2183392011-04-22 14:10:48 +00001446 }
1447 } else {
1448 (void)SampleView::SetRepeatDraw(child, 1);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001449 }
bungeman@google.comb1785912013-07-09 21:58:56 +00001450 if (fPerspAnim || fRotate) {
bsalomon@google.come8f09102011-09-08 18:48:12 +00001451 this->inval(NULL);
1452 }
reed@android.com6c5f6f22009-08-14 16:08:38 +00001453}
1454
1455void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
reed@google.comf0b5f682011-03-11 20:08:25 +00001456 canvas->setDrawFilter(NULL);
reed@android.com6c5f6f22009-08-14 16:08:38 +00001457}
1458
reed@android.com8a1c16f2008-12-17 15:59:43 +00001459static SkBitmap::Config gConfigCycle[] = {
1460 SkBitmap::kNo_Config, // none -> none
1461 SkBitmap::kNo_Config, // a1 -> none
1462 SkBitmap::kNo_Config, // a8 -> none
1463 SkBitmap::kNo_Config, // index8 -> none
1464 SkBitmap::kARGB_4444_Config, // 565 -> 4444
1465 SkBitmap::kARGB_8888_Config, // 4444 -> 8888
1466 SkBitmap::kRGB_565_Config // 8888 -> 565
1467};
1468
1469static SkBitmap::Config cycle_configs(SkBitmap::Config c) {
1470 return gConfigCycle[c];
1471}
1472
djsollen@google.come32b5832011-06-13 16:58:40 +00001473void SampleWindow::changeZoomLevel(float delta) {
1474 fZoomLevel += SkFloatToScalar(delta);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001475 if (fZoomLevel > 0) {
djsollen@google.come32b5832011-06-13 16:58:40 +00001476 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
1477 fZoomScale = fZoomLevel + SK_Scalar1;
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001478 } else if (fZoomLevel < 0) {
djsollen@google.come32b5832011-06-13 16:58:40 +00001479 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
1480 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001481 } else {
1482 fZoomScale = SK_Scalar1;
1483 }
reed@google.comf03bb562011-11-11 21:42:12 +00001484 this->updateMatrix();
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001485}
1486
reed@google.comf03bb562011-11-11 21:42:12 +00001487void SampleWindow::updateMatrix(){
1488 SkMatrix m;
1489 m.reset();
1490 if (fZoomLevel) {
1491 SkPoint center;
1492 //m = this->getLocalMatrix();//.invert(&m);
1493 m.mapXY(fZoomCenterX, fZoomCenterY, &center);
1494 SkScalar cx = center.fX;
1495 SkScalar cy = center.fY;
chudy@google.com4605a3f2012-08-01 17:58:01 +00001496
reed@google.comf03bb562011-11-11 21:42:12 +00001497 m.setTranslate(-cx, -cy);
1498 m.postScale(fZoomScale, fZoomScale);
1499 m.postTranslate(cx, cy);
1500 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001501
reed@google.comf03bb562011-11-11 21:42:12 +00001502 if (fFlipAxis) {
1503 m.preTranslate(fZoomCenterX, fZoomCenterY);
1504 if (fFlipAxis & kFlipAxis_X) {
1505 m.preScale(-SK_Scalar1, SK_Scalar1);
1506 }
1507 if (fFlipAxis & kFlipAxis_Y) {
1508 m.preScale(SK_Scalar1, -SK_Scalar1);
1509 }
1510 m.preTranslate(-fZoomCenterX, -fZoomCenterY);
1511 //canvas->concat(m);
1512 }
1513 // Apply any gesture matrix
1514 m.preConcat(fGesture.localM());
1515 m.preConcat(fGesture.globalM());
chudy@google.com4605a3f2012-08-01 17:58:01 +00001516
reed@google.comf03bb562011-11-11 21:42:12 +00001517 this->setLocalMatrix(m);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001518
reed@google.comf03bb562011-11-11 21:42:12 +00001519 this->updateTitle();
1520 this->inval(NULL);
1521}
Scroggo2c8208f2011-06-15 16:49:08 +00001522bool SampleWindow::previousSample() {
Scroggo62b65b02011-06-21 16:01:26 +00001523 fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
chudy@google.com4605a3f2012-08-01 17:58:01 +00001524 this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(),
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001525 fTransitionPrev));
Scroggo2c8208f2011-06-15 16:49:08 +00001526 return true;
1527}
1528
reed@android.com8a1c16f2008-12-17 15:59:43 +00001529bool SampleWindow::nextSample() {
reed@android.com34245c72009-11-03 04:00:48 +00001530 fCurrIndex = (fCurrIndex + 1) % fSamples.count();
chudy@google.com4605a3f2012-08-01 17:58:01 +00001531 this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(),
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001532 fTransitionNext));
reed@android.com34245c72009-11-03 04:00:48 +00001533 return true;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001534}
1535
yangsu@google.com501775e2011-06-24 16:04:50 +00001536bool SampleWindow::goToSample(int i) {
1537 fCurrIndex = (i) % fSamples.count();
bsalomon@google.com48dd1a22011-10-31 14:18:20 +00001538 this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(), 6));
yangsu@google.com501775e2011-06-24 16:04:50 +00001539 return true;
1540}
1541
1542SkString SampleWindow::getSampleTitle(int i) {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +00001543 SkView* view = (*fSamples[i])();
yangsu@google.com501775e2011-06-24 16:04:50 +00001544 SkString title;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001545 SampleCode::RequestTitle(view, &title);
yangsu@google.com501775e2011-06-24 16:04:50 +00001546 view->unref();
1547 return title;
1548}
1549
1550int SampleWindow::sampleCount() {
1551 return fSamples.count();
1552}
1553
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001554void SampleWindow::showOverview() {
chudy@google.com4605a3f2012-08-01 17:58:01 +00001555 this->loadView(create_transition(curr_view(this),
1556 create_overview(fSamples.count(), fSamples.begin()),
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001557 4));
1558}
1559
reed@google.come23f1942011-12-08 19:36:00 +00001560void SampleWindow::installDrawFilter(SkCanvas* canvas) {
bungeman@google.com96aabc82013-06-03 21:26:34 +00001561 canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fFilterState, fSubpixelState,
1562 fHintingState))->unref();
reed@google.come23f1942011-12-08 19:36:00 +00001563}
1564
Scroggo2c8208f2011-06-15 16:49:08 +00001565void SampleWindow::postAnimatingEvent() {
1566 if (fAnimating) {
reed@google.com87fac4a2011-08-04 13:50:17 +00001567 (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATING_DELAY);
Scroggo2c8208f2011-06-15 16:49:08 +00001568 }
1569}
reed@google.come23f1942011-12-08 19:36:00 +00001570
reed@android.com8a1c16f2008-12-17 15:59:43 +00001571bool SampleWindow::onEvent(const SkEvent& evt) {
reed@google.com2072db82011-11-08 15:18:10 +00001572 if (evt.isType(gUpdateWindowTitleEvtName)) {
1573 this->updateTitle();
1574 return true;
1575 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001576 if (evt.isType(ANIMATING_EVENTTYPE)) {
1577 if (fAnimating) {
1578 this->nextSample();
1579 this->postAnimatingEvent();
1580 }
1581 return true;
1582 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001583 if (evt.isType("replace-transition-view")) {
1584 this->loadView((SkView*)SkEventSink::FindSink(evt.getFast32()));
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001585 return true;
1586 }
reed@android.com34245c72009-11-03 04:00:48 +00001587 if (evt.isType("set-curr-index")) {
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001588 this->goToSample(evt.getFast32());
reed@android.com34245c72009-11-03 04:00:48 +00001589 return true;
1590 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001591 if (isInvalEvent(evt)) {
1592 this->inval(NULL);
1593 return true;
1594 }
yangsu@google.com921091f2011-08-02 13:39:12 +00001595 int selected = -1;
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001596 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001597 this->setDeviceType((DeviceType)selected);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001598 return true;
yangsu@google.com921091f2011-08-02 13:39:12 +00001599 }
scroggo@google.comb073d922012-06-08 15:35:03 +00001600 if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) {
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001601#ifdef PIPE_NET
scroggo@google.comb073d922012-06-08 15:35:03 +00001602 if (!fPipeState != SkOSMenu::kOnState)
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001603 gServer.disconnectAll();
1604#endif
scroggo@google.comb073d922012-06-08 15:35:03 +00001605 (void)SampleView::SetUsePipe(curr_view(this), fPipeState);
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001606 this->updateTitle();
1607 this->inval(NULL);
yangsu@google.com921091f2011-08-02 13:39:12 +00001608 return true;
1609 }
reed@google.com67b89ee2012-08-15 14:41:58 +00001610 if (SkOSMenu::FindTriState(evt, "Tiling", &fTilingState)) {
1611 int nx = 1, ny = 1;
1612 switch (fTilingState) {
1613 case SkOSMenu::kOffState: nx = 1; ny = 1; break;
reed@google.com56b64a52012-08-15 20:44:36 +00001614 case SkOSMenu::kMixedState: nx = 1; ny = 16; break;
1615 case SkOSMenu::kOnState: nx = 4; ny = 4; break;
reed@google.com67b89ee2012-08-15 14:41:58 +00001616 }
scroggo@google.com85cade02012-08-17 13:29:50 +00001617 fTileCount.set(nx, ny);
reed@google.com67b89ee2012-08-15 14:41:58 +00001618 this->inval(NULL);
1619 return true;
1620 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001621 if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001622 this->toggleSlideshow();
1623 return true;
1624 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001625 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) ||
1626 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) ||
1627 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) ||
bungeman@google.com96aabc82013-06-03 21:26:34 +00001628 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) ||
1629 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) ||
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001630 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) ||
1631 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) ||
1632 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) ||
1633 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) ||
1634 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001635 this->inval(NULL);
1636 this->updateTitle();
1637 return true;
1638 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001639 if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001640 fFlipAxis ^= kFlipAxis_X;
reed@google.comf03bb562011-11-11 21:42:12 +00001641 this->updateMatrix();
yangsu@google.com921091f2011-08-02 13:39:12 +00001642 return true;
1643 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001644 if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001645 fFlipAxis ^= kFlipAxis_Y;
reed@google.comf03bb562011-11-11 21:42:12 +00001646 this->updateMatrix();
yangsu@google.com921091f2011-08-02 13:39:12 +00001647 return true;
1648 }
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001649 if (SkOSMenu::FindAction(evt,"Save to PDF")) {
yangsu@google.com921091f2011-08-02 13:39:12 +00001650 this->saveToPdf();
1651 return true;
chudy@google.com4605a3f2012-08-01 17:58:01 +00001652 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001653 return this->INHERITED::onEvent(evt);
1654}
1655
reed@android.comf2b98d62010-12-20 18:26:13 +00001656bool SampleWindow::onQuery(SkEvent* query) {
1657 if (query->isType("get-slide-count")) {
1658 query->setFast32(fSamples.count());
1659 return true;
1660 }
1661 if (query->isType("get-slide-title")) {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +00001662 SkView* view = (*fSamples[query->getFast32()])();
reed@android.comf2b98d62010-12-20 18:26:13 +00001663 SkEvent evt(gTitleEvtName);
1664 if (view->doQuery(&evt)) {
1665 query->setString("title", evt.findString(gTitleEvtName));
1666 }
1667 SkSafeUnref(view);
1668 return true;
1669 }
1670 if (query->isType("use-fast-text")) {
1671 SkEvent evt(gFastTextEvtName);
1672 return curr_view(this)->doQuery(&evt);
1673 }
reed@google.com29038ed2011-07-06 17:56:47 +00001674 if (query->isType("ignore-window-bitmap")) {
1675 query->setFast32(this->getGrContext() != NULL);
1676 return true;
1677 }
reed@android.comf2b98d62010-12-20 18:26:13 +00001678 return this->INHERITED::onQuery(query);
1679}
1680
caryclark@google.com02939ce2012-06-06 12:09:51 +00001681#if 0 // UNUSED
reed@android.com0ae6b242008-12-23 16:49:54 +00001682static void cleanup_for_filename(SkString* name) {
1683 char* str = name->writable_str();
reed@android.come191b162009-12-18 21:33:39 +00001684 for (size_t i = 0; i < name->size(); i++) {
reed@android.com0ae6b242008-12-23 16:49:54 +00001685 switch (str[i]) {
1686 case ':': str[i] = '-'; break;
1687 case '/': str[i] = '-'; break;
1688 case ' ': str[i] = '_'; break;
1689 default: break;
1690 }
1691 }
1692}
caryclark@google.com02939ce2012-06-06 12:09:51 +00001693#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00001694
reed@google.coma4f81372012-11-15 15:56:38 +00001695//extern bool gIgnoreFastBlurRect;
1696
reed@android.com8a1c16f2008-12-17 15:59:43 +00001697bool SampleWindow::onHandleChar(SkUnichar uni) {
reed@android.comf2b98d62010-12-20 18:26:13 +00001698 {
1699 SkView* view = curr_view(this);
1700 if (view) {
1701 SkEvent evt(gCharEvtName);
1702 evt.setFast32(uni);
1703 if (view->doQuery(&evt)) {
1704 return true;
1705 }
1706 }
1707 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001708
reed@android.com8a1c16f2008-12-17 15:59:43 +00001709 int dx = 0xFF;
1710 int dy = 0xFF;
1711
1712 switch (uni) {
1713 case '5': dx = 0; dy = 0; break;
1714 case '8': dx = 0; dy = -1; break;
1715 case '6': dx = 1; dy = 0; break;
1716 case '2': dx = 0; dy = 1; break;
1717 case '4': dx = -1; dy = 0; break;
1718 case '7': dx = -1; dy = -1; break;
1719 case '9': dx = 1; dy = -1; break;
1720 case '3': dx = 1; dy = 1; break;
1721 case '1': dx = -1; dy = 1; break;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001722
reed@android.com8a1c16f2008-12-17 15:59:43 +00001723 default:
1724 break;
1725 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001726
reed@android.com8a1c16f2008-12-17 15:59:43 +00001727 if (0xFF != dx && 0xFF != dy) {
1728 if ((dx | dy) == 0) {
1729 fScrollTestX = fScrollTestY = 0;
1730 } else {
1731 fScrollTestX += dx;
1732 fScrollTestY += dy;
1733 }
1734 this->inval(NULL);
1735 return true;
1736 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001737
reed@android.com0ae6b242008-12-23 16:49:54 +00001738 switch (uni) {
djsollen@google.com796763e2012-12-10 14:12:55 +00001739 case 'b':
1740 {
1741 postEventToSink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
1742 this->updateTitle();
1743 this->inval(NULL);
1744 break;
1745 }
reed@google.coma4f81372012-11-15 15:56:38 +00001746 case 'B':
1747// gIgnoreFastBlurRect = !gIgnoreFastBlurRect;
1748 this->inval(NULL);
1749 break;
1750
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001751 case 'f':
chudy@google.com4605a3f2012-08-01 17:58:01 +00001752 // only
djsollen@google.com6ff82552011-11-07 15:43:57 +00001753 toggleFPS();
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00001754 break;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001755 case 'g':
1756 fRequestGrabImage = true;
1757 this->inval(NULL);
1758 break;
reed@google.coma4f81372012-11-15 15:56:38 +00001759 case 'G':
1760 gShowGMBounds = !gShowGMBounds;
1761 postEventToSink(GMSampleView::NewShowSizeEvt(gShowGMBounds),
1762 curr_view(this));
1763 this->inval(NULL);
1764 break;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001765 case 'i':
1766 this->zoomIn();
1767 break;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001768 case 'o':
1769 this->zoomOut();
1770 break;
reed@android.com6c5f6f22009-08-14 16:08:38 +00001771 case 'r':
1772 fRotate = !fRotate;
bungeman@google.comb1785912013-07-09 21:58:56 +00001773 fRotateAnimTime = 0;
reed@android.com6c5f6f22009-08-14 16:08:38 +00001774 this->inval(NULL);
1775 this->updateTitle();
1776 return true;
bsalomon@google.come8f09102011-09-08 18:48:12 +00001777 case 'k':
1778 fPerspAnim = !fPerspAnim;
1779 this->inval(NULL);
1780 this->updateTitle();
1781 return true;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001782#if SK_SUPPORT_GPU
bsalomon@google.com74913722011-10-27 20:44:19 +00001783 case '\\':
robertphillips@google.comb442a6d2012-04-02 19:24:21 +00001784 this->setDeviceType(kNullGPU_DeviceType);
1785 this->inval(NULL);
1786 this->updateTitle();
bsalomon@google.com74913722011-10-27 20:44:19 +00001787 return true;
twiz@google.com05e70242012-01-27 19:12:00 +00001788 case 'p':
1789 {
1790 GrContext* grContext = this->getGrContext();
1791 if (grContext) {
1792 size_t cacheBytes = grContext->getGpuTextureCacheBytes();
1793 grContext->freeGpuResources();
1794 SkDebugf("Purged %d bytes from the GPU resource cache.\n",
1795 cacheBytes);
1796 }
1797 }
1798 return true;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001799#endif
reed@android.com0ae6b242008-12-23 16:49:54 +00001800 default:
1801 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001802 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001803
scroggo@google.com7dadc742012-04-18 14:07:57 +00001804 if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni)) {
1805 this->onUpdateMenu(fAppMenu);
1806 this->onUpdateMenu(fSlideMenu);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001807 return true;
1808 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001809 return this->INHERITED::onHandleChar(uni);
1810}
1811
yangsu@google.com921091f2011-08-02 13:39:12 +00001812void SampleWindow::setDeviceType(DeviceType type) {
robertphillips@google.comb442a6d2012-04-02 19:24:21 +00001813 if (type == fDeviceType)
1814 return;
1815
1816 fDevManager->tearDownBackend(this);
1817
1818 fDeviceType = type;
1819
bsalomon@google.com11959252012-04-06 20:13:38 +00001820 fDevManager->setUpBackend(this, fMSAASampleCount);
robertphillips@google.comb442a6d2012-04-02 19:24:21 +00001821
yangsu@google.com921091f2011-08-02 13:39:12 +00001822 this->updateTitle();
1823 this->inval(NULL);
1824}
1825
Scroggo2c8208f2011-06-15 16:49:08 +00001826void SampleWindow::toggleSlideshow() {
1827 fAnimating = !fAnimating;
1828 this->postAnimatingEvent();
1829 this->updateTitle();
1830}
1831
1832void SampleWindow::toggleRendering() {
robertphillips@google.comb442a6d2012-04-02 19:24:21 +00001833 this->setDeviceType(cycle_devicetype(fDeviceType));
Scroggo2c8208f2011-06-15 16:49:08 +00001834 this->updateTitle();
1835 this->inval(NULL);
1836}
1837
djsollen@google.com6ff82552011-11-07 15:43:57 +00001838void SampleWindow::toggleFPS() {
1839 fMeasureFPS = !fMeasureFPS;
1840 this->updateTitle();
1841 this->inval(NULL);
1842}
1843
reed@android.com8a1c16f2008-12-17 15:59:43 +00001844#include "SkDumpCanvas.h"
1845
1846bool SampleWindow::onHandleKey(SkKey key) {
reed@android.comf2b98d62010-12-20 18:26:13 +00001847 {
1848 SkView* view = curr_view(this);
1849 if (view) {
1850 SkEvent evt(gKeyEvtName);
1851 evt.setFast32(key);
1852 if (view->doQuery(&evt)) {
1853 return true;
1854 }
1855 }
1856 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001857 switch (key) {
1858 case kRight_SkKey:
1859 if (this->nextSample()) {
1860 return true;
1861 }
1862 break;
1863 case kLeft_SkKey:
scroggo@google.come2dd9732012-08-15 20:03:06 +00001864 if (this->previousSample()) {
1865 return true;
1866 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001867 return true;
1868 case kUp_SkKey:
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001869 if (USE_ARROWS_FOR_ZOOM) {
bungeman@google.comcefd9812013-05-15 15:07:32 +00001870 this->changeZoomLevel(1.f / 32.f);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001871 } else {
1872 fNClip = !fNClip;
1873 this->inval(NULL);
djsollen@google.come32b5832011-06-13 16:58:40 +00001874 this->updateTitle();
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001875 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001876 return true;
1877 case kDown_SkKey:
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001878 if (USE_ARROWS_FOR_ZOOM) {
bungeman@google.comcefd9812013-05-15 15:07:32 +00001879 this->changeZoomLevel(-1.f / 32.f);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001880 } else {
1881 this->setConfig(cycle_configs(this->getBitmap().config()));
djsollen@google.come32b5832011-06-13 16:58:40 +00001882 this->updateTitle();
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001883 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001884 return true;
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +00001885 case kOK_SkKey: {
1886 SkString title;
1887 if (curr_title(this, &title)) {
1888 writeTitleToPrefs(title.c_str());
reed@android.com8a1c16f2008-12-17 15:59:43 +00001889 }
1890 return true;
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +00001891 }
reed@android.com34245c72009-11-03 04:00:48 +00001892 case kBack_SkKey:
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001893 this->showOverview();
reed@android.com34245c72009-11-03 04:00:48 +00001894 return true;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001895 default:
1896 break;
1897 }
1898 return this->INHERITED::onHandleKey(key);
1899}
1900
reed@google.com52f57e12011-03-16 12:10:02 +00001901///////////////////////////////////////////////////////////////////////////////
1902
1903static const char gGestureClickType[] = "GestureClickType";
1904
Scroggod3aed392011-06-22 13:26:56 +00001905bool SampleWindow::onDispatchClick(int x, int y, Click::State state,
reed@google.com4d5c26d2013-01-08 16:17:50 +00001906 void* owner, unsigned modi) {
Scroggo0f185c22011-03-24 18:35:50 +00001907 if (Click::kMoved_State == state) {
1908 updatePointer(x, y);
1909 }
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001910 int w = SkScalarRound(this->width());
1911 int h = SkScalarRound(this->height());
1912
1913 // check for the resize-box
1914 if (w - x < 16 && h - y < 16) {
1915 return false; // let the OS handle the click
chudy@google.com4605a3f2012-08-01 17:58:01 +00001916 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00001917 else if (fMagnify) {
1918 //it's only necessary to update the drawing if there's a click
1919 this->inval(NULL);
1920 return false; //prevent dragging while magnify is enabled
reed@google.com4d5c26d2013-01-08 16:17:50 +00001921 } else {
1922 // capture control+option, and trigger debugger
1923 if ((modi & kControl_SkModifierKey) && (modi & kOption_SkModifierKey)) {
1924 if (Click::kDown_State == state) {
1925 SkEvent evt("debug-hit-test");
1926 evt.setS32("debug-hit-test-x", x);
1927 evt.setS32("debug-hit-test-y", y);
1928 curr_view(this)->doEvent(evt);
1929 }
1930 return true;
1931 } else {
1932 return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
1933 }
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001934 }
1935}
1936
reed@google.com52f57e12011-03-16 12:10:02 +00001937class GestureClick : public SkView::Click {
1938public:
1939 GestureClick(SkView* target) : SkView::Click(target) {
1940 this->setType(gGestureClickType);
1941 }
1942
1943 static bool IsGesture(Click* click) {
1944 return click->isType(gGestureClickType);
1945 }
1946};
1947
reed@google.com4d5c26d2013-01-08 16:17:50 +00001948SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y,
1949 unsigned modi) {
reed@google.com52f57e12011-03-16 12:10:02 +00001950 return new GestureClick(this);
1951}
1952
1953bool SampleWindow::onClick(Click* click) {
1954 if (GestureClick::IsGesture(click)) {
bsalomon@google.com4d4f2812011-12-12 18:34:01 +00001955 float x = static_cast<float>(click->fICurr.fX);
1956 float y = static_cast<float>(click->fICurr.fY);
chudy@google.com4605a3f2012-08-01 17:58:01 +00001957
reed@google.com52f57e12011-03-16 12:10:02 +00001958 switch (click->fState) {
1959 case SkView::Click::kDown_State:
Scroggod3aed392011-06-22 13:26:56 +00001960 fGesture.touchBegin(click->fOwner, x, y);
reed@google.com52f57e12011-03-16 12:10:02 +00001961 break;
1962 case SkView::Click::kMoved_State:
Scroggod3aed392011-06-22 13:26:56 +00001963 fGesture.touchMoved(click->fOwner, x, y);
reed@google.comf03bb562011-11-11 21:42:12 +00001964 this->updateMatrix();
reed@google.com52f57e12011-03-16 12:10:02 +00001965 break;
1966 case SkView::Click::kUp_State:
Scroggod3aed392011-06-22 13:26:56 +00001967 fGesture.touchEnd(click->fOwner);
reed@google.comf03bb562011-11-11 21:42:12 +00001968 this->updateMatrix();
reed@google.com52f57e12011-03-16 12:10:02 +00001969 break;
1970 }
1971 return true;
1972 }
1973 return false;
1974}
1975
1976///////////////////////////////////////////////////////////////////////////////
1977
reed@android.com8a1c16f2008-12-17 15:59:43 +00001978void SampleWindow::loadView(SkView* view) {
1979 SkView::F2BIter iter(this);
1980 SkView* prev = iter.next();
1981 if (prev) {
1982 prev->detachFromParent();
1983 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00001984
reed@android.com8a1c16f2008-12-17 15:59:43 +00001985 view->setVisibleP(true);
reed@android.comf2b98d62010-12-20 18:26:13 +00001986 view->setClipToBounds(false);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001987 this->attachChildToFront(view)->unref();
1988 view->setSize(this->width(), this->height());
1989
yangsu@google.com921091f2011-08-02 13:39:12 +00001990 //repopulate the slide menu when a view is loaded
scroggo@google.com7dadc742012-04-18 14:07:57 +00001991 fSlideMenu->reset();
djsollen@google.com388974f2013-01-17 13:20:01 +00001992
scroggo@google.comb073d922012-06-08 15:35:03 +00001993 (void)SampleView::SetUsePipe(view, fPipeState);
yangsu@google.com921091f2011-08-02 13:39:12 +00001994 if (SampleView::IsSampleView(view))
scroggo@google.com7dadc742012-04-18 14:07:57 +00001995 ((SampleView*)view)->requestMenu(fSlideMenu);
1996 this->onUpdateMenu(fSlideMenu);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001997 this->updateTitle();
1998}
1999
2000static const char* gConfigNames[] = {
2001 "unknown config",
2002 "A1",
2003 "A8",
2004 "Index8",
2005 "565",
2006 "4444",
2007 "8888"
2008};
2009
2010static const char* configToString(SkBitmap::Config c) {
2011 return gConfigNames[c];
2012}
2013
bsalomon@google.com098e96d2011-07-14 14:30:46 +00002014static const char* gDeviceTypePrefix[] = {
reed@android.com8a1c16f2008-12-17 15:59:43 +00002015 "raster: ",
2016 "picture: ",
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002017#if SK_SUPPORT_GPU
bsalomon@google.com74913722011-10-27 20:44:19 +00002018 "opengl: ",
robertphillips@google.comb442a6d2012-04-02 19:24:21 +00002019#if SK_ANGLE
2020 "angle: ",
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002021#endif // SK_ANGLE
bsalomon@google.com74913722011-10-27 20:44:19 +00002022 "null-gl: "
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002023#endif // SK_SUPPORT_GPU
reed@android.com8a1c16f2008-12-17 15:59:43 +00002024};
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002025SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt,
2026 array_size_mismatch);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002027
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002028static const char* trystate_str(SkOSMenu::TriState state,
reed@google.com569e0432011-04-05 13:07:03 +00002029 const char trueStr[], const char falseStr[]) {
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002030 if (SkOSMenu::kOnState == state) {
reed@google.com569e0432011-04-05 13:07:03 +00002031 return trueStr;
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002032 } else if (SkOSMenu::kOffState == state) {
reed@google.com569e0432011-04-05 13:07:03 +00002033 return falseStr;
2034 }
2035 return NULL;
2036}
2037
reed@android.com8a1c16f2008-12-17 15:59:43 +00002038void SampleWindow::updateTitle() {
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +00002039 SkView* view = curr_view(this);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002040
mike@reedtribe.org6f6e8c32011-12-27 22:33:50 +00002041 SkString title;
2042 if (!curr_title(this, &title)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00002043 title.set("<unknown>");
2044 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002045
bsalomon@google.com098e96d2011-07-14 14:30:46 +00002046 title.prepend(gDeviceTypePrefix[fDeviceType]);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002047
2048 title.prepend(" ");
2049 title.prepend(configToString(this->getBitmap().config()));
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002050
reed@android.com8a1c16f2008-12-17 15:59:43 +00002051 if (fAnimating) {
2052 title.prepend("<A> ");
2053 }
reed@android.com6c5f6f22009-08-14 16:08:38 +00002054 if (fRotate) {
2055 title.prepend("<R> ");
2056 }
reed@android.come522ca52009-11-23 20:10:41 +00002057 if (fNClip) {
2058 title.prepend("<C> ");
2059 }
bsalomon@google.come8f09102011-09-08 18:48:12 +00002060 if (fPerspAnim) {
2061 title.prepend("<K> ");
2062 }
reed@google.com569e0432011-04-05 13:07:03 +00002063
2064 title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
2065 title.prepend(trystate_str(fAAState, "AA ", "aa "));
bungeman@google.com96aabc82013-06-03 21:26:34 +00002066 title.prepend(trystate_str(fFilterState, "N ", "n "));
2067 title.prepend(trystate_str(fSubpixelState, "S ", "s "));
reed@google.com569e0432011-04-05 13:07:03 +00002068 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL);
2069 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
bungeman@google.com96aabc82013-06-03 21:26:34 +00002070 title.prepend(gHintingStates[fHintingState].label);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00002071
2072 if (fZoomLevel) {
djsollen@google.come32b5832011-06-13 16:58:40 +00002073 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00002074 }
chudy@google.com4605a3f2012-08-01 17:58:01 +00002075
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002076 if (fMeasureFPS) {
reed@google.com43e10142012-09-10 11:52:52 +00002077 title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002078 }
reed@google.coma6ff4dc2011-05-12 22:08:24 +00002079 if (SampleView::IsSampleView(view)) {
scroggo@google.comb073d922012-06-08 15:35:03 +00002080 switch (fPipeState) {
2081 case SkOSMenu::kOnState:
2082 title.prepend("<Pipe> ");
2083 break;
2084 case SkOSMenu::kMixedState:
2085 title.prepend("<Tiled Pipe> ");
2086 break;
chudy@google.com4605a3f2012-08-01 17:58:01 +00002087
scroggo@google.comb073d922012-06-08 15:35:03 +00002088 default:
2089 break;
2090 }
reed@google.coma6ff4dc2011-05-12 22:08:24 +00002091 title.prepend("! ");
2092 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002093
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002094#if SK_SUPPORT_GPU
bsalomon@google.com82502e22013-01-24 20:47:18 +00002095 if (IsGpuDeviceType(fDeviceType) &&
robertphillips@google.com4750fa52012-04-10 13:34:11 +00002096 NULL != fDevManager &&
bsalomon@google.com82502e22013-01-24 20:47:18 +00002097 fDevManager->getGrRenderTarget() &&
bsalomon@google.com11959252012-04-06 20:13:38 +00002098 fDevManager->getGrRenderTarget()->numSamples() > 0) {
2099 title.appendf(" [MSAA: %d]",
2100 fDevManager->getGrRenderTarget()->numSamples());
2101 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002102#endif
bsalomon@google.com11959252012-04-06 20:13:38 +00002103
reed@android.com8a1c16f2008-12-17 15:59:43 +00002104 this->setTitle(title.c_str());
2105}
2106
2107void SampleWindow::onSizeChange() {
2108 this->INHERITED::onSizeChange();
chudy@google.com4605a3f2012-08-01 17:58:01 +00002109
reed@android.com8a1c16f2008-12-17 15:59:43 +00002110 SkView::F2BIter iter(this);
2111 SkView* view = iter.next();
2112 view->setSize(this->width(), this->height());
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002113
reed@android.com8a1c16f2008-12-17 15:59:43 +00002114 // rebuild our clippath
2115 {
2116 const SkScalar W = this->width();
2117 const SkScalar H = this->height();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002118
reed@android.com8a1c16f2008-12-17 15:59:43 +00002119 fClipPath.reset();
2120#if 0
2121 for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) {
2122 SkRect r;
2123 r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30));
2124 for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0))
2125 fClipPath.addRect(r);
2126 }
2127#else
2128 SkRect r;
2129 r.set(0, 0, W, H);
2130 fClipPath.addRect(r, SkPath::kCCW_Direction);
2131 r.set(W/4, H/4, W*3/4, H*3/4);
2132 fClipPath.addRect(r, SkPath::kCW_Direction);
2133#endif
2134 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002135
Scroggo2c8208f2011-06-15 16:49:08 +00002136 fZoomCenterX = SkScalarHalf(this->width());
2137 fZoomCenterY = SkScalarHalf(this->height());
2138
djsollen@google.com56c69772011-11-08 19:00:26 +00002139#ifdef SK_BUILD_FOR_ANDROID
Scroggob4490c72011-06-17 13:53:05 +00002140 // FIXME: The first draw after a size change does not work on Android, so
2141 // we post an invalidate.
Scroggo62b65b02011-06-21 16:01:26 +00002142 this->postInvalDelay();
Scroggo716a0382011-06-16 14:00:15 +00002143#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00002144 this->updateTitle(); // to refresh our config
bsalomon@google.com098e96d2011-07-14 14:30:46 +00002145 fDevManager->windowSizeChanged(this);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002146}
2147
2148///////////////////////////////////////////////////////////////////////////////
2149
reed@google.coma6ff4dc2011-05-12 22:08:24 +00002150static const char is_sample_view_tag[] = "sample-is-sample-view";
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002151static const char repeat_count_tag[] = "sample-set-repeat-count";
reed@google.com0faac1e2011-05-11 05:58:58 +00002152static const char set_use_pipe_tag[] = "sample-set-use-pipe";
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002153
reed@google.coma6ff4dc2011-05-12 22:08:24 +00002154bool SampleView::IsSampleView(SkView* view) {
2155 SkEvent evt(is_sample_view_tag);
2156 return view->doQuery(&evt);
2157}
2158
reed@google.comf2183392011-04-22 14:10:48 +00002159bool SampleView::SetRepeatDraw(SkView* view, int count) {
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002160 SkEvent evt(repeat_count_tag);
2161 evt.setFast32(count);
reed@google.comf2183392011-04-22 14:10:48 +00002162 return view->doEvent(evt);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002163}
2164
scroggo@google.comb073d922012-06-08 15:35:03 +00002165bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) {
2166 SkEvent evt;
2167 evt.setS32(set_use_pipe_tag, state);
reed@google.com0faac1e2011-05-11 05:58:58 +00002168 return view->doEvent(evt);
2169}
2170
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002171bool SampleView::onEvent(const SkEvent& evt) {
2172 if (evt.isType(repeat_count_tag)) {
2173 fRepeatCount = evt.getFast32();
2174 return true;
2175 }
reed@google.com4d5c26d2013-01-08 16:17:50 +00002176
scroggo@google.comb073d922012-06-08 15:35:03 +00002177 int32_t pipeHolder;
2178 if (evt.findS32(set_use_pipe_tag, &pipeHolder)) {
2179 fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder);
reed@google.com0faac1e2011-05-11 05:58:58 +00002180 return true;
2181 }
reed@google.com4d5c26d2013-01-08 16:17:50 +00002182
2183 if (evt.isType("debug-hit-test")) {
2184 fDebugHitTest = true;
2185 evt.findS32("debug-hit-test-x", &fDebugHitTestLoc.fX);
2186 evt.findS32("debug-hit-test-y", &fDebugHitTestLoc.fY);
2187 this->inval(NULL);
2188 return true;
2189 }
2190
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002191 return this->INHERITED::onEvent(evt);
2192}
2193
2194bool SampleView::onQuery(SkEvent* evt) {
reed@google.coma6ff4dc2011-05-12 22:08:24 +00002195 if (evt->isType(is_sample_view_tag)) {
2196 return true;
2197 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002198 return this->INHERITED::onQuery(evt);
2199}
2200
reed@google.com64e3eb22011-05-04 14:32:04 +00002201
2202class SimplePC : public SkGPipeController {
2203public:
2204 SimplePC(SkCanvas* target);
2205 ~SimplePC();
chudy@google.com4605a3f2012-08-01 17:58:01 +00002206
reed@google.com64e3eb22011-05-04 14:32:04 +00002207 virtual void* requestBlock(size_t minRequest, size_t* actual);
2208 virtual void notifyWritten(size_t bytes);
2209
2210private:
reed@google.com961ddb02011-05-05 14:03:48 +00002211 SkGPipeReader fReader;
2212 void* fBlock;
2213 size_t fBlockSize;
2214 size_t fBytesWritten;
2215 int fAtomsWritten;
reed@google.com64e3eb22011-05-04 14:32:04 +00002216 SkGPipeReader::Status fStatus;
2217
2218 size_t fTotalWritten;
2219};
2220
2221SimplePC::SimplePC(SkCanvas* target) : fReader(target) {
2222 fBlock = NULL;
2223 fBlockSize = fBytesWritten = 0;
2224 fStatus = SkGPipeReader::kDone_Status;
2225 fTotalWritten = 0;
reed@google.com961ddb02011-05-05 14:03:48 +00002226 fAtomsWritten = 0;
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00002227 fReader.setBitmapDecoder(&SkImageDecoder::DecodeMemory);
reed@google.com64e3eb22011-05-04 14:32:04 +00002228}
2229
2230SimplePC::~SimplePC() {
2231// SkASSERT(SkGPipeReader::kDone_Status == fStatus);
reed@google.com0faac1e2011-05-11 05:58:58 +00002232 if (fTotalWritten) {
scroggo@google.comb073d922012-06-08 15:35:03 +00002233 SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten,
2234 fAtomsWritten, fStatus);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002235#ifdef PIPE_FILE
scroggo@google.comb073d922012-06-08 15:35:03 +00002236 //File is open in append mode
2237 FILE* f = fopen(FILE_PATH, "ab");
2238 SkASSERT(f != NULL);
2239 fwrite((const char*)fBlock + fBytesWritten, 1, bytes, f);
2240 fclose(f);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002241#endif
2242#ifdef PIPE_NET
scroggo@google.comb073d922012-06-08 15:35:03 +00002243 if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done
2244 gServer.acceptConnections();
2245 gServer.writePacket(fBlock, fTotalWritten);
2246 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002247#endif
reed@google.com0faac1e2011-05-11 05:58:58 +00002248 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002249 sk_free(fBlock);
reed@google.com64e3eb22011-05-04 14:32:04 +00002250}
2251
2252void* SimplePC::requestBlock(size_t minRequest, size_t* actual) {
2253 sk_free(fBlock);
2254
2255 fBlockSize = minRequest * 4;
2256 fBlock = sk_malloc_throw(fBlockSize);
2257 fBytesWritten = 0;
2258 *actual = fBlockSize;
2259 return fBlock;
2260}
2261
2262void SimplePC::notifyWritten(size_t bytes) {
2263 SkASSERT(fBytesWritten + bytes <= fBlockSize);
reed@google.com64e3eb22011-05-04 14:32:04 +00002264 fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes);
2265 SkASSERT(SkGPipeReader::kError_Status != fStatus);
2266 fBytesWritten += bytes;
2267 fTotalWritten += bytes;
chudy@google.com4605a3f2012-08-01 17:58:01 +00002268
reed@google.com961ddb02011-05-05 14:03:48 +00002269 fAtomsWritten += 1;
reed@google.com64e3eb22011-05-04 14:32:04 +00002270}
2271
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002272void SampleView::draw(SkCanvas* canvas) {
scroggo@google.comb073d922012-06-08 15:35:03 +00002273 if (SkOSMenu::kOffState == fPipeState) {
2274 this->INHERITED::draw(canvas);
2275 } else {
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002276 SkGPipeWriter writer;
2277 SimplePC controller(canvas);
scroggo@google.comb073d922012-06-08 15:35:03 +00002278 TiledPipeController tc(canvas->getDevice()->accessBitmap(false),
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00002279 &SkImageDecoder::DecodeMemory,
scroggo@google.comb073d922012-06-08 15:35:03 +00002280 &canvas->getTotalMatrix());
2281 SkGPipeController* pc;
2282 if (SkOSMenu::kMixedState == fPipeState) {
2283 pc = &tc;
2284 } else {
2285 pc = &controller;
2286 }
reed@google.comdde09562011-05-23 12:21:05 +00002287 uint32_t flags = SkGPipeWriter::kCrossProcess_Flag;
chudy@google.com4605a3f2012-08-01 17:58:01 +00002288
scroggo@google.comb073d922012-06-08 15:35:03 +00002289 canvas = writer.startRecording(pc, flags);
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002290 //Must draw before controller goes out of scope and sends data
2291 this->INHERITED::draw(canvas);
yangsu@google.comef7bdfa2011-08-12 14:27:47 +00002292 //explicitly end recording to ensure writer is flushed before the memory
2293 //is freed in the deconstructor of the controller
2294 writer.endRecording();
reed@google.com0faac1e2011-05-11 05:58:58 +00002295 }
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002296}
reed@google.com4d5c26d2013-01-08 16:17:50 +00002297
2298#include "SkBounder.h"
2299
2300class DebugHitTestBounder : public SkBounder {
2301public:
2302 DebugHitTestBounder(int x, int y) {
2303 fLoc.set(x, y);
2304 }
2305
2306 virtual bool onIRect(const SkIRect& bounds) SK_OVERRIDE {
2307 if (bounds.contains(fLoc.x(), fLoc.y())) {
2308 //
2309 // Set a break-point here to see what was being drawn under
2310 // the click point (just needed a line of code to stop the debugger)
2311 //
2312 bounds.centerX();
2313 }
2314 return true;
2315 }
2316
2317private:
2318 SkIPoint fLoc;
2319 typedef SkBounder INHERITED;
2320};
2321
yangsu@google.comdb03eaa2011-08-08 15:37:23 +00002322void SampleView::onDraw(SkCanvas* canvas) {
reed@google.com81e3d7f2011-06-01 12:42:36 +00002323 this->onDrawBackground(canvas);
2324
reed@google.com4d5c26d2013-01-08 16:17:50 +00002325 DebugHitTestBounder bounder(fDebugHitTestLoc.x(), fDebugHitTestLoc.y());
2326 if (fDebugHitTest) {
2327 canvas->setBounder(&bounder);
2328 }
2329
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002330 for (int i = 0; i < fRepeatCount; i++) {
scroggo@google.com85cade02012-08-17 13:29:50 +00002331 SkAutoCanvasRestore acr(canvas, true);
2332 this->onDrawContent(canvas);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002333 }
reed@google.com4d5c26d2013-01-08 16:17:50 +00002334
2335 fDebugHitTest = false;
2336 canvas->setBounder(NULL);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002337}
2338
2339void SampleView::onDrawBackground(SkCanvas* canvas) {
reed@google.comf2183392011-04-22 14:10:48 +00002340 canvas->drawColor(fBGColor);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00002341}
2342
2343///////////////////////////////////////////////////////////////////////////////
2344
reed@android.comf2b98d62010-12-20 18:26:13 +00002345template <typename T> void SkTBSort(T array[], int count) {
2346 for (int i = 1; i < count - 1; i++) {
2347 bool didSwap = false;
2348 for (int j = count - 1; j > i; --j) {
2349 if (array[j] < array[j-1]) {
2350 T tmp(array[j-1]);
2351 array[j-1] = array[j];
2352 array[j] = tmp;
2353 didSwap = true;
2354 }
2355 }
2356 if (!didSwap) {
2357 break;
2358 }
2359 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002360
reed@android.comf2b98d62010-12-20 18:26:13 +00002361 for (int k = 0; k < count - 1; k++) {
2362 SkASSERT(!(array[k+1] < array[k]));
2363 }
2364}
2365
2366#include "SkRandom.h"
2367
2368static void rand_rect(SkIRect* rect, SkRandom& rand) {
2369 int bits = 8;
2370 int shift = 32 - bits;
2371 rect->set(rand.nextU() >> shift, rand.nextU() >> shift,
2372 rand.nextU() >> shift, rand.nextU() >> shift);
2373 rect->sort();
2374}
2375
2376static void dumpRect(const SkIRect& r) {
2377 SkDebugf(" { %d, %d, %d, %d },\n",
2378 r.fLeft, r.fTop,
2379 r.fRight, r.fBottom);
2380}
2381
2382static void test_rects(const SkIRect rect[], int count) {
2383 SkRegion rgn0, rgn1;
2384
2385 for (int i = 0; i < count; i++) {
2386 rgn0.op(rect[i], SkRegion::kUnion_Op);
2387 // dumpRect(rect[i]);
2388 }
2389 rgn1.setRects(rect, count);
2390
2391 if (rgn0 != rgn1) {
2392 SkDebugf("\n");
2393 for (int i = 0; i < count; i++) {
2394 dumpRect(rect[i]);
2395 }
2396 SkDebugf("\n");
2397 }
2398}
2399
2400static void test() {
2401 size_t i;
2402
2403 const SkIRect r0[] = {
2404 { 0, 0, 1, 1 },
2405 { 2, 2, 3, 3 },
2406 };
2407 const SkIRect r1[] = {
2408 { 0, 0, 1, 3 },
2409 { 1, 1, 2, 2 },
2410 { 2, 0, 3, 3 },
2411 };
2412 const SkIRect r2[] = {
2413 { 0, 0, 1, 2 },
2414 { 2, 1, 3, 3 },
2415 { 4, 0, 5, 1 },
2416 { 6, 0, 7, 4 },
2417 };
2418
2419 static const struct {
2420 const SkIRect* fRects;
2421 int fCount;
2422 } gRecs[] = {
2423 { r0, SK_ARRAY_COUNT(r0) },
2424 { r1, SK_ARRAY_COUNT(r1) },
2425 { r2, SK_ARRAY_COUNT(r2) },
2426 };
2427
2428 for (i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
2429 test_rects(gRecs[i].fRects, gRecs[i].fCount);
2430 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002431
reed@android.comf2b98d62010-12-20 18:26:13 +00002432 SkRandom rand;
2433 for (i = 0; i < 10000; i++) {
2434 SkRegion rgn0, rgn1;
2435
2436 const int N = 8;
2437 SkIRect rect[N];
2438 for (int j = 0; j < N; j++) {
2439 rand_rect(&rect[j], rand);
2440 }
2441 test_rects(rect, N);
2442 }
2443}
2444
caryclark@google.com02939ce2012-06-06 12:09:51 +00002445// FIXME: this should be in a header
2446SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
senorblanco@chromium.org78b82532011-06-28 19:44:03 +00002447SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
caryclark@google.com02939ce2012-06-06 12:09:51 +00002448 if (false) { // avoid bit rot, suppress warning
2449 test();
2450 }
bsalomon@google.com098e96d2011-07-14 14:30:46 +00002451 return new SampleWindow(hwnd, argc, argv, NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002452}
2453
caryclark@google.com02939ce2012-06-06 12:09:51 +00002454// FIXME: this should be in a header
2455void get_preferred_size(int* x, int* y, int* width, int* height);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002456void get_preferred_size(int* x, int* y, int* width, int* height) {
2457 *x = 10;
2458 *y = 50;
2459 *width = 640;
2460 *height = 480;
2461}
2462
caryclark@google.com5987f582012-10-02 18:33:14 +00002463#ifdef SK_BUILD_FOR_IOS
2464void save_args(int argc, char *argv[]) {
2465}
2466#endif
2467
caryclark@google.com02939ce2012-06-06 12:09:51 +00002468// FIXME: this should be in a header
2469void application_init();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002470void application_init() {
2471// setenv("ANDROID_ROOT", "../../../data", 0);
reed@android.come191b162009-12-18 21:33:39 +00002472#ifdef SK_BUILD_FOR_MAC
reed@android.com8a1c16f2008-12-17 15:59:43 +00002473 setenv("ANDROID_ROOT", "/android/device/data", 0);
reed@android.come191b162009-12-18 21:33:39 +00002474#endif
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +00002475 SkGraphics::Init();
2476 SkEvent::Init();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002477}
2478
caryclark@google.com02939ce2012-06-06 12:09:51 +00002479// FIXME: this should be in a header
2480void application_term();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002481void application_term() {
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +00002482 SkEvent::Term();
2483 SkGraphics::Term();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002484}