blob: 99ceb3e9b231ed4ef94ea7f597043f9d686ad542 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SkCanvas.h"
2#include "SkDevice.h"
reed@google.comac10a2d2010-12-22 21:39:39 +00003#include "SkGpuCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00004#include "SkGraphics.h"
reed@android.comb08eb2b2009-01-06 20:16:26 +00005#include "SkImageEncoder.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00006#include "SkPaint.h"
7#include "SkPicture.h"
8#include "SkStream.h"
reed@android.com44177402009-11-23 21:07:51 +00009#include "SkTime.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkWindow.h"
11
12#include "SampleCode.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013#include "GrContext.h"
reed@google.com52f57e12011-03-16 12:10:02 +000014#include "SkTouchGesture.h"
Scroggo0f185c22011-03-24 18:35:50 +000015#include "SkTypeface.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000016
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +000017#define USE_ARROWS_FOR_ZOOM true
reed@android.comf2b98d62010-12-20 18:26:13 +000018//#define DEFAULT_TO_GPU
19
reed@android.come191b162009-12-18 21:33:39 +000020extern SkView* create_overview(int, const SkViewFactory[]);
reed@android.com34245c72009-11-03 04:00:48 +000021
reed@android.comcb342352010-07-22 18:27:53 +000022#define SK_SUPPORT_GL
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
24#define ANIMATING_EVENTTYPE "nextSample"
25#define ANIMATING_DELAY 750
26
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000027#ifdef SK_DEBUG
28 #define FPS_REPEAT_COUNT 10
29#else
30 #define FPS_REPEAT_COUNT 100
31#endif
32
reed@google.comac10a2d2010-12-22 21:39:39 +000033#ifdef SK_SUPPORT_GL
34 #include "GrGLConfig.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000035#endif
36
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000037///////////////
38static const char view_inval_msg[] = "view-inval-msg";
39
40static void postInvalDelay(SkEventSinkID sinkID) {
41 SkEvent* evt = new SkEvent(view_inval_msg);
reed@google.comf2183392011-04-22 14:10:48 +000042 evt->post(sinkID, 1);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000043}
44
45static bool isInvalEvent(const SkEvent& evt) {
46 return evt.isType(view_inval_msg);
47}
48//////////////////
49
reed@android.com8a1c16f2008-12-17 15:59:43 +000050SkViewRegister* SkViewRegister::gHead;
51SkViewRegister::SkViewRegister(SkViewFactory fact) : fFact(fact) {
52 static bool gOnce;
53 if (!gOnce) {
54 gHead = NULL;
55 gOnce = true;
56 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 fChain = gHead;
59 gHead = this;
60}
61
reed@android.comf2b98d62010-12-20 18:26:13 +000062#if defined(SK_SUPPORT_GL)
63 #define SK_USE_SHADERS
64#endif
65
twiz@google.com06c3b6b2011-03-14 16:58:39 +000066#ifdef SK_BUILD_FOR_MAC
reed@google.comf0b5f682011-03-11 20:08:25 +000067#include <CoreFoundation/CoreFoundation.h>
68#include <CoreFoundation/CFURLAccess.h>
69
70static void testpdf() {
71 CFStringRef path = CFStringCreateWithCString(NULL, "/test.pdf",
72 kCFStringEncodingUTF8);
73 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path,
74 kCFURLPOSIXPathStyle,
75 false);
76 CFRelease(path);
77 CGRect box = CGRectMake(0, 0, 8*72, 10*72);
78 CGContextRef cg = CGPDFContextCreateWithURL(url, &box, NULL);
79 CFRelease(url);
80
81 CGContextBeginPage(cg, &box);
82 CGRect r = CGRectMake(10, 10, 40 + 0.5, 50 + 0.5);
83 CGContextFillEllipseInRect(cg, r);
84 CGContextEndPage(cg);
85 CGContextRelease(cg);
86
87 if (false) {
88 SkBitmap bm;
89 bm.setConfig(SkBitmap::kA8_Config, 64, 64);
90 bm.allocPixels();
91 bm.eraseColor(0);
92
93 SkCanvas canvas(bm);
94
95 }
96}
97#endif
98
99//////////////////////////////////////////////////////////////////////////////
100
reed@google.com569e0432011-04-05 13:07:03 +0000101enum FlipAxisEnum {
102 kFlipAxis_X = (1 << 0),
103 kFlipAxis_Y = (1 << 1)
104};
105
106enum SkTriState {
107 kFalse_SkTriState,
108 kTrue_SkTriState,
109 kUnknown_SkTriState,
110};
111
112static SkTriState cycle_tristate(SkTriState state) {
113 static const SkTriState gCycle[] = {
114 /* kFalse_SkTriState -> */ kUnknown_SkTriState,
115 /* kTrue_SkTriState -> */ kFalse_SkTriState,
116 /* kUnknown_SkTriState -> */ kTrue_SkTriState,
117 };
118 return gCycle[state];
119}
120
reed@google.comf0b5f682011-03-11 20:08:25 +0000121#include "SkDrawFilter.h"
122
reed@google.com569e0432011-04-05 13:07:03 +0000123class FlagsDrawFilter : public SkDrawFilter {
reed@google.comf0b5f682011-03-11 20:08:25 +0000124public:
reed@google.com569e0432011-04-05 13:07:03 +0000125 FlagsDrawFilter(SkTriState lcd, SkTriState aa) : fLCDState(lcd), fAAState(aa) {}
reed@google.comf0b5f682011-03-11 20:08:25 +0000126
mike@reedtribe.org3ce59dc2011-04-08 00:38:05 +0000127 virtual void filter(SkPaint* paint, Type t) {
reed@google.com569e0432011-04-05 13:07:03 +0000128 if (kText_Type == t && kUnknown_SkTriState != fLCDState) {
reed@google.com569e0432011-04-05 13:07:03 +0000129 paint->setLCDRenderText(kTrue_SkTriState == fLCDState);
130 }
131 if (kUnknown_SkTriState != fAAState) {
reed@google.com569e0432011-04-05 13:07:03 +0000132 paint->setAntiAlias(kTrue_SkTriState == fAAState);
reed@google.comf0b5f682011-03-11 20:08:25 +0000133 }
reed@google.comf0b5f682011-03-11 20:08:25 +0000134 }
135
136private:
reed@google.com569e0432011-04-05 13:07:03 +0000137 SkTriState fLCDState;
reed@google.com569e0432011-04-05 13:07:03 +0000138 SkTriState fAAState;
reed@google.comf0b5f682011-03-11 20:08:25 +0000139};
140
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141//////////////////////////////////////////////////////////////////////////////
142
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000143#define MAX_ZOOM_LEVEL 8
144#define MIN_ZOOM_LEVEL -8
145
reed@android.comf2b98d62010-12-20 18:26:13 +0000146static const char gCharEvtName[] = "SampleCode_Char_Event";
147static const char gKeyEvtName[] = "SampleCode_Key_Event";
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148static const char gTitleEvtName[] = "SampleCode_Title_Event";
149static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event";
reed@android.comf2b98d62010-12-20 18:26:13 +0000150static const char gFastTextEvtName[] = "SampleCode_FastText_Event";
151
152bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) {
153 if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) {
154 if (outUni) {
155 *outUni = evt.getFast32();
156 }
157 return true;
158 }
159 return false;
160}
161
162bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) {
163 if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) {
164 if (outKey) {
165 *outKey = (SkKey)evt.getFast32();
166 }
167 return true;
168 }
169 return false;
170}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000171
172bool SampleCode::TitleQ(const SkEvent& evt) {
173 return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1);
174}
175
176void SampleCode::TitleR(SkEvent* evt, const char title[]) {
177 SkASSERT(evt && TitleQ(*evt));
178 evt->setString(gTitleEvtName, title);
179}
180
181bool SampleCode::PrefSizeQ(const SkEvent& evt) {
182 return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1);
183}
184
185void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) {
186 SkASSERT(evt && PrefSizeQ(*evt));
187 SkScalar size[2];
188 size[0] = width;
189 size[1] = height;
190 evt->setScalars(gPrefSizeEvtName, 2, size);
191}
192
reed@android.comf2b98d62010-12-20 18:26:13 +0000193bool SampleCode::FastTextQ(const SkEvent& evt) {
194 return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1);
195}
196
197///////////////////////////////////////////////////////////////////////////////
198
reed@android.com44177402009-11-23 21:07:51 +0000199static SkMSec gAnimTime;
reed@android.comf2b98d62010-12-20 18:26:13 +0000200static SkMSec gAnimTimePrev;
201
reed@android.com44177402009-11-23 21:07:51 +0000202SkMSec SampleCode::GetAnimTime() { return gAnimTime; }
reed@android.comf2b98d62010-12-20 18:26:13 +0000203SkMSec SampleCode::GetAnimTimeDelta() { return gAnimTime - gAnimTimePrev; }
204SkScalar SampleCode::GetAnimSecondsDelta() {
205 return SkDoubleToScalar(GetAnimTimeDelta() / 1000.0);
206}
reed@android.com44177402009-11-23 21:07:51 +0000207
208SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000209 // since gAnimTime can be up to 32 bits, we can't convert it to a float
210 // or we'll lose the low bits. Hence we use doubles for the intermediate
211 // calculations
212 double seconds = (double)gAnimTime / 1000.0;
213 double value = SkScalarToDouble(speed) * seconds;
reed@android.com44177402009-11-23 21:07:51 +0000214 if (period) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000215 value = ::fmod(value, SkScalarToDouble(period));
reed@android.com44177402009-11-23 21:07:51 +0000216 }
reed@android.comf2b98d62010-12-20 18:26:13 +0000217 return SkDoubleToScalar(value);
reed@android.com44177402009-11-23 21:07:51 +0000218}
219
reed@android.com8a1c16f2008-12-17 15:59:43 +0000220//////////////////////////////////////////////////////////////////////////////
221
reed@android.comf2b98d62010-12-20 18:26:13 +0000222static SkView* curr_view(SkWindow* wind) {
223 SkView::F2BIter iter(wind);
224 return iter.next();
225}
226
reed@android.com8a1c16f2008-12-17 15:59:43 +0000227class SampleWindow : public SkOSWindow {
reed@android.com34245c72009-11-03 04:00:48 +0000228 SkTDArray<SkViewFactory> fSamples;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000229public:
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000230 SampleWindow(void* hwnd);
231 virtual ~SampleWindow();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000232
reed@android.come522ca52009-11-23 20:10:41 +0000233 virtual void draw(SkCanvas* canvas);
234
reed@android.com8a1c16f2008-12-17 15:59:43 +0000235protected:
236 virtual void onDraw(SkCanvas* canvas);
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000237 virtual bool onHandleKey(SkKey key);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000238 virtual bool onHandleChar(SkUnichar);
239 virtual void onSizeChange();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000240
reed@android.com8a1c16f2008-12-17 15:59:43 +0000241 virtual SkCanvas* beforeChildren(SkCanvas*);
242 virtual void afterChildren(SkCanvas*);
reed@android.com6c5f6f22009-08-14 16:08:38 +0000243 virtual void beforeChild(SkView* child, SkCanvas* canvas);
244 virtual void afterChild(SkView* child, SkCanvas* canvas);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000245
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000246 virtual bool onEvent(const SkEvent& evt);
reed@android.comf2b98d62010-12-20 18:26:13 +0000247 virtual bool onQuery(SkEvent* evt);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000248
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000249 virtual bool onDispatchClick(int x, int y, Click::State);
reed@google.com52f57e12011-03-16 12:10:02 +0000250 virtual bool onClick(Click* click);
251 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
252
reed@android.com8a1c16f2008-12-17 15:59:43 +0000253#if 0
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000254 virtual bool handleChar(SkUnichar uni);
255 virtual bool handleEvent(const SkEvent& evt);
256 virtual bool handleKey(SkKey key);
257 virtual bool handleKeyUp(SkKey key);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000258 virtual bool onHandleKeyUp(SkKey key);
259#endif
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000260
reed@android.com8a1c16f2008-12-17 15:59:43 +0000261private:
reed@android.com34245c72009-11-03 04:00:48 +0000262 int fCurrIndex;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000263
reed@android.com8a1c16f2008-12-17 15:59:43 +0000264 SkPicture* fPicture;
reed@android.comf2b98d62010-12-20 18:26:13 +0000265 SkGpuCanvas* fGpuCanvas;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000266 GrContext* fGrContext;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000267 SkPath fClipPath;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000268
reed@google.com52f57e12011-03-16 12:10:02 +0000269 SkTouchGesture fGesture;
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000270 int fZoomLevel;
271 SkScalar fZoomScale;
reed@google.com52f57e12011-03-16 12:10:02 +0000272
reed@android.com8a1c16f2008-12-17 15:59:43 +0000273 enum CanvasType {
274 kRaster_CanvasType,
275 kPicture_CanvasType,
reed@android.comf2b98d62010-12-20 18:26:13 +0000276 kGPU_CanvasType
reed@android.com8a1c16f2008-12-17 15:59:43 +0000277 };
278 CanvasType fCanvasType;
279
280 bool fUseClip;
reed@android.come522ca52009-11-23 20:10:41 +0000281 bool fNClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000282 bool fRepeatDrawing;
283 bool fAnimating;
reed@android.com6c5f6f22009-08-14 16:08:38 +0000284 bool fRotate;
285 bool fScale;
reed@android.comf2b98d62010-12-20 18:26:13 +0000286 bool fRequestGrabImage;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000287 bool fMeasureFPS;
288 SkMSec fMeasureFPS_Time;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000289
Scroggo0f185c22011-03-24 18:35:50 +0000290 // The following are for the 'fatbits' drawing
291 // Latest position of the mouse.
292 int fMouseX, fMouseY;
293 int fFatBitsScale;
294 // Used by the text showing position and color values.
295 SkTypeface* fTypeface;
296 bool fShowZoomer;
297
reed@google.com569e0432011-04-05 13:07:03 +0000298 SkTriState fLCDState;
299 SkTriState fAAState;
300 unsigned fFlipAxis;
reed@google.comf0b5f682011-03-11 20:08:25 +0000301
reed@android.com8a1c16f2008-12-17 15:59:43 +0000302 int fScrollTestX, fScrollTestY;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000303
304 bool make3DReady();
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000305 void changeZoomLevel(int delta);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000306
reed@android.com8a1c16f2008-12-17 15:59:43 +0000307 void loadView(SkView*);
308 void updateTitle();
309 bool nextSample();
310
Scroggo0f185c22011-03-24 18:35:50 +0000311 void toggleZoomer();
312 bool zoomIn();
313 bool zoomOut();
314 void updatePointer(int x, int y);
315
reed@android.com8a1c16f2008-12-17 15:59:43 +0000316 void postAnimatingEvent() {
317 if (fAnimating) {
318 SkEvent* evt = new SkEvent(ANIMATING_EVENTTYPE);
319 evt->post(this->getSinkID(), ANIMATING_DELAY);
320 }
321 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000322
323
reed@android.com8a1c16f2008-12-17 15:59:43 +0000324 static CanvasType cycle_canvastype(CanvasType);
325
326 typedef SkOSWindow INHERITED;
327};
328
Scroggo0f185c22011-03-24 18:35:50 +0000329bool SampleWindow::zoomIn()
330{
331 // Arbitrarily decided
332 if (fFatBitsScale == 25) return false;
333 fFatBitsScale++;
334 this->inval(NULL);
335 return true;
336}
337
338bool SampleWindow::zoomOut()
339{
340 if (fFatBitsScale == 1) return false;
341 fFatBitsScale--;
342 this->inval(NULL);
343 return true;
344}
345
346void SampleWindow::toggleZoomer()
347{
348 fShowZoomer = !fShowZoomer;
349 this->inval(NULL);
350}
351
352void SampleWindow::updatePointer(int x, int y)
353{
354 fMouseX = x;
355 fMouseY = y;
356 if (fShowZoomer) {
357 this->inval(NULL);
358 }
359}
360
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000361bool SampleWindow::make3DReady() {
362
363#if defined(SK_SUPPORT_GL)
bsalomon@google.com498a6232011-03-10 18:24:15 +0000364 if (attachGL()) {
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000365 if (NULL != fGrContext) {
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000366 // various gr lifecycle tests
367 #if 0
368 fGrContext->freeGpuResources();
369 #elif 0
370 // this will leak resources.
371 fGrContext->contextLost();
372 #elif 0
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000373 GrAssert(1 == fGrContext->refcnt());
374 fGrContext->unref();
375 fGrContext = NULL;
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000376 #endif
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000377 }
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000378
bsalomon@google.com498a6232011-03-10 18:24:15 +0000379 if (NULL == fGrContext) {
380 #if defined(SK_USE_SHADERS)
381 fGrContext = GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
382 #else
383 fGrContext = GrContext::Create(GrGpu::kOpenGL_Fixed_Engine, NULL);
384 #endif
reed@google.com569e0432011-04-05 13:07:03 +0000385 SkDebugf("---- constructor\n");
bsalomon@google.com498a6232011-03-10 18:24:15 +0000386 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000387
bsalomon@google.com498a6232011-03-10 18:24:15 +0000388 if (NULL != fGrContext) {
389 return true;
390 } else {
391 detachGL();
392 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000393 }
394#endif
395 SkDebugf("Failed to setup 3D");
396 return false;
397}
398
reed@android.com8a1c16f2008-12-17 15:59:43 +0000399SampleWindow::CanvasType SampleWindow::cycle_canvastype(CanvasType ct) {
400 static const CanvasType gCT[] = {
401 kPicture_CanvasType,
reed@android.comf2b98d62010-12-20 18:26:13 +0000402 kGPU_CanvasType,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000403 kRaster_CanvasType
404 };
405 return gCT[ct];
406}
407
408SampleWindow::SampleWindow(void* hwnd) : INHERITED(hwnd) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000409 fPicture = NULL;
reed@android.comf2b98d62010-12-20 18:26:13 +0000410 fGpuCanvas = NULL;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000411
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000412 fGrContext = NULL;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000413
reed@android.comf2b98d62010-12-20 18:26:13 +0000414#ifdef DEFAULT_TO_GPU
415 fCanvasType = kGPU_CanvasType;
416#else
reed@android.com8a1c16f2008-12-17 15:59:43 +0000417 fCanvasType = kRaster_CanvasType;
reed@android.comf2b98d62010-12-20 18:26:13 +0000418#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000419 fUseClip = false;
reed@android.come522ca52009-11-23 20:10:41 +0000420 fNClip = false;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000421 fRepeatDrawing = false;
422 fAnimating = false;
reed@android.com6c5f6f22009-08-14 16:08:38 +0000423 fRotate = false;
424 fScale = false;
reed@android.comf2b98d62010-12-20 18:26:13 +0000425 fRequestGrabImage = false;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000426 fMeasureFPS = false;
reed@google.com569e0432011-04-05 13:07:03 +0000427 fLCDState = kUnknown_SkTriState;
428 fAAState = kUnknown_SkTriState;
429 fFlipAxis = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000430 fScrollTestX = fScrollTestY = 0;
431
Scroggo0f185c22011-03-24 18:35:50 +0000432 fMouseX = fMouseY = 0;
mike@reedtribe.org3ce59dc2011-04-08 00:38:05 +0000433 fFatBitsScale = 8;
Scroggo0f185c22011-03-24 18:35:50 +0000434 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold);
435 fShowZoomer = false;
436
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000437 fZoomLevel = 0;
438 fZoomScale = SK_Scalar1;
439
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000440// this->setConfig(SkBitmap::kRGB_565_Config);
441 this->setConfig(SkBitmap::kARGB_8888_Config);
442 this->setVisibleP(true);
reed@android.comf2b98d62010-12-20 18:26:13 +0000443 this->setClipToBounds(false);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000444
reed@android.com34245c72009-11-03 04:00:48 +0000445 {
446 const SkViewRegister* reg = SkViewRegister::Head();
447 while (reg) {
448 *fSamples.append() = reg->factory();
449 reg = reg->next();
450 }
451 }
452 fCurrIndex = 0;
reed@android.come0f13ee2009-11-04 19:40:25 +0000453 this->loadView(fSamples[fCurrIndex]());
reed@google.comf0b5f682011-03-11 20:08:25 +0000454
twiz@google.com06c3b6b2011-03-14 16:58:39 +0000455#ifdef SK_BUILD_FOR_MAC
reed@google.comf0b5f682011-03-11 20:08:25 +0000456 testpdf();
twiz@google.com06c3b6b2011-03-14 16:58:39 +0000457#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000458}
459
460SampleWindow::~SampleWindow() {
461 delete fPicture;
reed@android.comf2b98d62010-12-20 18:26:13 +0000462 delete fGpuCanvas;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000463 if (NULL != fGrContext) {
464 fGrContext->unref();
465 }
Scroggo0f185c22011-03-24 18:35:50 +0000466 fTypeface->unref();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000467}
468
reed@android.com55e76b22009-11-23 21:46:47 +0000469static SkBitmap capture_bitmap(SkCanvas* canvas) {
470 SkBitmap bm;
471 const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
472 src.copyTo(&bm, src.config());
473 return bm;
474}
475
476static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
477 SkBitmap* diff) {
478 const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000479
reed@android.com55e76b22009-11-23 21:46:47 +0000480 SkAutoLockPixels alp0(src);
481 SkAutoLockPixels alp1(orig);
482 for (int y = 0; y < src.height(); y++) {
483 const void* srcP = src.getAddr(0, y);
484 const void* origP = orig.getAddr(0, y);
485 size_t bytes = src.width() * src.bytesPerPixel();
486 if (memcmp(srcP, origP, bytes)) {
487 SkDebugf("---------- difference on line %d\n", y);
488 return true;
489 }
490 }
491 return false;
492}
493
Scroggo0f185c22011-03-24 18:35:50 +0000494static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
495{
496 SkColor desiredColor = paint.getColor();
497 paint.setColor(SK_ColorWHITE);
498 const char* c_str = string.c_str();
499 size_t size = string.size();
500 SkRect bounds;
501 paint.measureText(c_str, size, &bounds);
502 bounds.offset(left, top);
503 SkScalar inset = SkIntToScalar(-2);
504 bounds.inset(inset, inset);
505 canvas->drawRect(bounds, paint);
506 if (desiredColor != SK_ColorBLACK) {
507 paint.setColor(SK_ColorBLACK);
508 canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint);
509 }
510 paint.setColor(desiredColor);
511 canvas->drawText(c_str, size, left, top, paint);
512}
513
reed@android.com44177402009-11-23 21:07:51 +0000514#define XCLIP_N 8
515#define YCLIP_N 8
reed@android.come522ca52009-11-23 20:10:41 +0000516
517void SampleWindow::draw(SkCanvas* canvas) {
reed@android.com44177402009-11-23 21:07:51 +0000518 // update the animation time
reed@android.comf2b98d62010-12-20 18:26:13 +0000519 gAnimTimePrev = gAnimTime;
reed@android.com44177402009-11-23 21:07:51 +0000520 gAnimTime = SkTime::GetMSecs();
521
reed@google.com569e0432011-04-05 13:07:03 +0000522 SkScalar cx = SkScalarHalf(this->width());
523 SkScalar cy = SkScalarHalf(this->height());
524
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000525 if (fZoomLevel) {
526 SkMatrix m;
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000527 SkPoint center;
528 m = canvas->getTotalMatrix();//.invert(&m);
529 m.mapXY(cx, cy, &center);
530 cx = center.fX;
531 cy = center.fY;
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000532
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000533 m.setTranslate(-cx, -cy);
534 m.postScale(fZoomScale, fZoomScale);
535 m.postTranslate(cx, cy);
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000536
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000537 canvas->concat(m);
538 }
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000539
reed@google.com569e0432011-04-05 13:07:03 +0000540 if (fFlipAxis) {
541 SkMatrix m;
542 m.setTranslate(cx, cy);
543 if (fFlipAxis & kFlipAxis_X) {
544 m.preScale(-SK_Scalar1, SK_Scalar1);
545 }
546 if (fFlipAxis & kFlipAxis_Y) {
547 m.preScale(SK_Scalar1, -SK_Scalar1);
548 }
549 m.preTranslate(-cx, -cy);
550 canvas->concat(m);
551 }
552
reed@google.com52f57e12011-03-16 12:10:02 +0000553 // Apply any gesture matrix
554 if (true) {
555 const SkMatrix& localM = fGesture.localM();
556 if (localM.getType() & SkMatrix::kScale_Mask) {
557 canvas->setExternalMatrix(&localM);
558 }
559 canvas->concat(localM);
560 canvas->concat(fGesture.globalM());
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000561
reed@google.com52f57e12011-03-16 12:10:02 +0000562 if (fGesture.isActive()) {
563 this->inval(NULL);
564 }
565 }
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000566
reed@android.come522ca52009-11-23 20:10:41 +0000567 if (fNClip) {
reed@android.com55e76b22009-11-23 21:46:47 +0000568 this->INHERITED::draw(canvas);
569 SkBitmap orig = capture_bitmap(canvas);
reed@android.come522ca52009-11-23 20:10:41 +0000570
571 const SkScalar w = this->width();
572 const SkScalar h = this->height();
573 const SkScalar cw = w / XCLIP_N;
574 const SkScalar ch = h / YCLIP_N;
575 for (int y = 0; y < YCLIP_N; y++) {
reed@android.com55e76b22009-11-23 21:46:47 +0000576 SkRect r;
577 r.fTop = y * ch;
578 r.fBottom = (y + 1) * ch;
579 if (y == YCLIP_N - 1) {
580 r.fBottom = h;
581 }
reed@android.come522ca52009-11-23 20:10:41 +0000582 for (int x = 0; x < XCLIP_N; x++) {
583 SkAutoCanvasRestore acr(canvas, true);
reed@android.com55e76b22009-11-23 21:46:47 +0000584 r.fLeft = x * cw;
585 r.fRight = (x + 1) * cw;
586 if (x == XCLIP_N - 1) {
587 r.fRight = w;
588 }
reed@android.come522ca52009-11-23 20:10:41 +0000589 canvas->clipRect(r);
590 this->INHERITED::draw(canvas);
591 }
592 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000593
reed@android.com55e76b22009-11-23 21:46:47 +0000594 SkBitmap diff;
595 if (bitmap_diff(canvas, orig, &diff)) {
596 }
reed@android.come522ca52009-11-23 20:10:41 +0000597 } else {
598 this->INHERITED::draw(canvas);
599 }
Scroggo0f185c22011-03-24 18:35:50 +0000600 if (fShowZoomer) {
601 int count = canvas->save();
602 canvas->resetMatrix();
603 // Ensure the mouse position is on screen.
reed@google.com261b8e22011-04-14 17:53:24 +0000604 int width = SkScalarRound(this->width());
605 int height = SkScalarRound(this->height());
Scroggo0f185c22011-03-24 18:35:50 +0000606 if (fMouseX >= width) fMouseX = width - 1;
607 else if (fMouseX < 0) fMouseX = 0;
608 if (fMouseY >= height) fMouseY = height - 1;
609 else if (fMouseY < 0) fMouseY = 0;
610 SkBitmap bitmap = capture_bitmap(canvas);
611 // 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 +0000612 int zoomedWidth = (width >> 1) | 1;
613 int zoomedHeight = (height >> 1) | 1;
Scroggo0f185c22011-03-24 18:35:50 +0000614 SkIRect src;
615 src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale);
616 src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1));
617 SkRect dest;
618 dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight));
619 dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight));
620 SkPaint paint;
621 // Clear the background behind our zoomed in view
622 paint.setColor(SK_ColorWHITE);
623 canvas->drawRect(dest, paint);
624 canvas->drawBitmapRect(bitmap, &src, dest);
625 paint.setColor(SK_ColorBLACK);
626 paint.setStyle(SkPaint::kStroke_Style);
627 // Draw a border around the pixel in the middle
628 SkRect originalPixel;
629 originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1));
630 SkMatrix matrix;
631 SkRect scalarSrc;
632 scalarSrc.set(src);
633 SkColor color = bitmap.getColor(fMouseX, fMouseY);
634 if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) {
635 SkRect pixel;
636 matrix.mapRect(&pixel, originalPixel);
637 // TODO Perhaps measure the values and make the outline white if it's "dark"
638 if (color == SK_ColorBLACK) {
639 paint.setColor(SK_ColorWHITE);
640 }
641 canvas->drawRect(pixel, paint);
642 }
643 paint.setColor(SK_ColorBLACK);
644 // Draw a border around the destination rectangle
645 canvas->drawRect(dest, paint);
646 paint.setStyle(SkPaint::kStrokeAndFill_Style);
647 // Identify the pixel and its color on screen
648 paint.setTypeface(fTypeface);
649 paint.setAntiAlias(true);
650 SkScalar lineHeight = paint.getFontMetrics(NULL);
651 SkString string;
652 string.appendf("(%i, %i)", fMouseX, fMouseY);
653 SkScalar left = dest.fLeft + SkIntToScalar(3);
654 SkScalar i = SK_Scalar1;
655 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
656 // Alpha
657 i += SK_Scalar1;
658 string.reset();
659 string.appendf("A: %X", SkColorGetA(color));
660 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
661 // Red
662 i += SK_Scalar1;
663 string.reset();
664 string.appendf("R: %X", SkColorGetR(color));
665 paint.setColor(SK_ColorRED);
666 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
667 // Green
668 i += SK_Scalar1;
669 string.reset();
670 string.appendf("G: %X", SkColorGetG(color));
671 paint.setColor(SK_ColorGREEN);
672 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
673 // Blue
674 i += SK_Scalar1;
675 string.reset();
676 string.appendf("B: %X", SkColorGetB(color));
677 paint.setColor(SK_ColorBLUE);
678 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
679 canvas->restoreToCount(count);
680 }
reed@android.come522ca52009-11-23 20:10:41 +0000681}
682
reed@android.com8a1c16f2008-12-17 15:59:43 +0000683void SampleWindow::onDraw(SkCanvas* canvas) {
684 if (fRepeatDrawing) {
685 this->inval(NULL);
686 }
687}
688
689#include "SkColorPriv.h"
690
691static void reverseRedAndBlue(const SkBitmap& bm) {
692 SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
693 uint8_t* p = (uint8_t*)bm.getPixels();
694 uint8_t* stop = p + bm.getSize();
695 while (p < stop) {
696 // swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply
697 unsigned scale = SkAlpha255To256(p[3]);
698 unsigned r = p[2];
699 unsigned b = p[0];
700 p[0] = SkAlphaMul(r, scale);
701 p[1] = SkAlphaMul(p[1], scale);
702 p[2] = SkAlphaMul(b, scale);
703 p += 4;
704 }
705}
706
707SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000708 SkIPoint viewport;
709 bool alreadyGPU = canvas->getViewport(&viewport);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000710
reed@android.comf2b98d62010-12-20 18:26:13 +0000711 if (kGPU_CanvasType != fCanvasType) {
reed@android.com6efdc472008-12-19 18:24:35 +0000712#ifdef SK_SUPPORT_GL
reed@android.comf2b98d62010-12-20 18:26:13 +0000713 detachGL();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000714#endif
reed@android.comf2b98d62010-12-20 18:26:13 +0000715 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000716
reed@android.com8a1c16f2008-12-17 15:59:43 +0000717 switch (fCanvasType) {
718 case kRaster_CanvasType:
719 canvas = this->INHERITED::beforeChildren(canvas);
720 break;
721 case kPicture_CanvasType:
722 fPicture = new SkPicture;
723 canvas = fPicture->beginRecording(9999, 9999);
724 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000725 case kGPU_CanvasType: {
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000726 if (!alreadyGPU && make3DReady()) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000727 SkDevice* device = canvas->getDevice();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000728 const SkBitmap& bitmap = device->accessBitmap(true);
729
bsalomon@google.com5782d712011-01-21 21:03:59 +0000730 GrRenderTarget* renderTarget;
731 renderTarget = fGrContext->createRenderTargetFrom3DApiState();
732 fGpuCanvas = new SkGpuCanvas(fGrContext, renderTarget);
733 renderTarget->unref();
734
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +0000735 device = fGpuCanvas->createDevice(SkBitmap::kARGB_8888_Config,
736 bitmap.width(), bitmap.height(),
737 false, false);
reed@google.comac10a2d2010-12-22 21:39:39 +0000738 fGpuCanvas->setDevice(device)->unref();
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000739
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000740 fGpuCanvas->concat(canvas->getTotalMatrix());
reed@android.comf2b98d62010-12-20 18:26:13 +0000741 canvas = fGpuCanvas;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000742
reed@android.comf2b98d62010-12-20 18:26:13 +0000743 } else {
744 canvas = this->INHERITED::beforeChildren(canvas);
745 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000746 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000747 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000748 }
749
750 if (fUseClip) {
751 canvas->drawColor(0xFFFF88FF);
752 canvas->clipPath(fClipPath);
753 }
754
755 return canvas;
756}
757
758static void paint_rgn(const SkBitmap& bm, const SkIRect& r,
759 const SkRegion& rgn) {
760 SkCanvas canvas(bm);
761 SkRegion inval(rgn);
762
763 inval.translate(r.fLeft, r.fTop);
764 canvas.clipRegion(inval);
765 canvas.drawColor(0xFFFF8080);
766}
767
768void SampleWindow::afterChildren(SkCanvas* orig) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000769 if (fRequestGrabImage) {
770 fRequestGrabImage = false;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000771
reed@android.comf2b98d62010-12-20 18:26:13 +0000772 SkCanvas* canvas = fGpuCanvas ? fGpuCanvas : orig;
773 SkDevice* device = canvas->getDevice();
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000774 SkBitmap bmp;
775 if (device->accessBitmap(false).copyTo(&bmp, SkBitmap::kARGB_8888_Config)) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000776 static int gSampleGrabCounter;
777 SkString name;
778 name.printf("sample_grab_%d", gSampleGrabCounter++);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000779 SkImageEncoder::EncodeFile(name.c_str(), bmp,
reed@android.comf2b98d62010-12-20 18:26:13 +0000780 SkImageEncoder::kPNG_Type, 100);
781 }
782 }
783
reed@android.com8a1c16f2008-12-17 15:59:43 +0000784 switch (fCanvasType) {
785 case kRaster_CanvasType:
786 break;
787 case kPicture_CanvasType:
reed@android.comaefd2bc2009-03-30 21:02:14 +0000788 if (true) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000789 SkPicture* pict = new SkPicture(*fPicture);
790 fPicture->unref();
791 orig->drawPicture(*pict);
792 pict->unref();
reed@android.comaefd2bc2009-03-30 21:02:14 +0000793 } else if (true) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000794 SkDynamicMemoryWStream ostream;
795 fPicture->serialize(&ostream);
796 fPicture->unref();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000797
reed@android.com8a1c16f2008-12-17 15:59:43 +0000798 SkMemoryStream istream(ostream.getStream(), ostream.getOffset());
799 SkPicture pict(&istream);
800 orig->drawPicture(pict);
801 } else {
802 fPicture->draw(orig);
803 fPicture->unref();
804 }
805 fPicture = NULL;
806 break;
reed@android.com6efdc472008-12-19 18:24:35 +0000807#ifdef SK_SUPPORT_GL
reed@android.comf2b98d62010-12-20 18:26:13 +0000808 case kGPU_CanvasType:
809 delete fGpuCanvas;
810 fGpuCanvas = NULL;
811 presentGL();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000812 break;
reed@android.com6efdc472008-12-19 18:24:35 +0000813#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000814 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000815
reed@android.com8a1c16f2008-12-17 15:59:43 +0000816// if ((fScrollTestX | fScrollTestY) != 0)
reed@android.comf2b98d62010-12-20 18:26:13 +0000817 if (false) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000818 const SkBitmap& bm = orig->getDevice()->accessBitmap(true);
819 int dx = fScrollTestX * 7;
820 int dy = fScrollTestY * 7;
821 SkIRect r;
822 SkRegion inval;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000823
reed@android.com8a1c16f2008-12-17 15:59:43 +0000824 r.set(50, 50, 50+100, 50+100);
825 bm.scrollRect(&r, dx, dy, &inval);
826 paint_rgn(bm, r, inval);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000827 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000828}
829
reed@android.com6c5f6f22009-08-14 16:08:38 +0000830void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
831 if (fScale) {
832 SkScalar scale = SK_Scalar1 * 7 / 10;
833 SkScalar cx = this->width() / 2;
834 SkScalar cy = this->height() / 2;
835 canvas->translate(cx, cy);
836 canvas->scale(scale, scale);
837 canvas->translate(-cx, -cy);
838 }
839 if (fRotate) {
840 SkScalar cx = this->width() / 2;
841 SkScalar cy = this->height() / 2;
842 canvas->translate(cx, cy);
843 canvas->rotate(SkIntToScalar(30));
844 canvas->translate(-cx, -cy);
845 }
reed@google.comf0b5f682011-03-11 20:08:25 +0000846
reed@google.com569e0432011-04-05 13:07:03 +0000847 if (kUnknown_SkTriState != fLCDState ||
848 kUnknown_SkTriState != fAAState) {
849 canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState))->unref();
reed@google.comf0b5f682011-03-11 20:08:25 +0000850 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000851
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000852 if (fMeasureFPS) {
reed@google.comf2183392011-04-22 14:10:48 +0000853 fMeasureFPS_Time = 0; // 0 means the child is not aware of repeat-draw
854 if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
855 fMeasureFPS_Time = SkTime::GetMSecs();
856 }
857 } else {
858 (void)SampleView::SetRepeatDraw(child, 1);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000859 }
reed@android.com6c5f6f22009-08-14 16:08:38 +0000860}
861
862void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
reed@google.comf0b5f682011-03-11 20:08:25 +0000863 canvas->setDrawFilter(NULL);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000864
reed@google.comf2183392011-04-22 14:10:48 +0000865 if (fMeasureFPS && fMeasureFPS_Time) {
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000866 fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time;
867 this->updateTitle();
868 postInvalDelay(this->getSinkID());
869 }
reed@android.com6c5f6f22009-08-14 16:08:38 +0000870}
871
reed@android.com8a1c16f2008-12-17 15:59:43 +0000872static SkBitmap::Config gConfigCycle[] = {
873 SkBitmap::kNo_Config, // none -> none
874 SkBitmap::kNo_Config, // a1 -> none
875 SkBitmap::kNo_Config, // a8 -> none
876 SkBitmap::kNo_Config, // index8 -> none
877 SkBitmap::kARGB_4444_Config, // 565 -> 4444
878 SkBitmap::kARGB_8888_Config, // 4444 -> 8888
879 SkBitmap::kRGB_565_Config // 8888 -> 565
880};
881
882static SkBitmap::Config cycle_configs(SkBitmap::Config c) {
883 return gConfigCycle[c];
884}
885
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +0000886void SampleWindow::changeZoomLevel(int delta) {
887 fZoomLevel += delta;
888 if (fZoomLevel > 0) {
889 fZoomLevel = SkMin32(fZoomLevel, MAX_ZOOM_LEVEL);
890 fZoomScale = SkIntToScalar(fZoomLevel + 1);
891 } else if (fZoomLevel < 0) {
892 fZoomLevel = SkMax32(fZoomLevel, MIN_ZOOM_LEVEL);
893 fZoomScale = SK_Scalar1 / (1 - fZoomLevel);
894 } else {
895 fZoomScale = SK_Scalar1;
896 }
897
898 this->inval(NULL);
899}
900
reed@android.com8a1c16f2008-12-17 15:59:43 +0000901bool SampleWindow::nextSample() {
reed@android.com34245c72009-11-03 04:00:48 +0000902 fCurrIndex = (fCurrIndex + 1) % fSamples.count();
903 this->loadView(fSamples[fCurrIndex]());
904 return true;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000905}
906
907bool SampleWindow::onEvent(const SkEvent& evt) {
908 if (evt.isType(ANIMATING_EVENTTYPE)) {
909 if (fAnimating) {
910 this->nextSample();
911 this->postAnimatingEvent();
912 }
913 return true;
914 }
reed@android.com34245c72009-11-03 04:00:48 +0000915 if (evt.isType("set-curr-index")) {
916 fCurrIndex = evt.getFast32() % fSamples.count();
917 this->loadView(fSamples[fCurrIndex]());
918 return true;
919 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +0000920 if (isInvalEvent(evt)) {
921 this->inval(NULL);
922 return true;
923 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000924 return this->INHERITED::onEvent(evt);
925}
926
reed@android.comf2b98d62010-12-20 18:26:13 +0000927bool SampleWindow::onQuery(SkEvent* query) {
928 if (query->isType("get-slide-count")) {
929 query->setFast32(fSamples.count());
930 return true;
931 }
932 if (query->isType("get-slide-title")) {
933 SkView* view = fSamples[query->getFast32()]();
934 SkEvent evt(gTitleEvtName);
935 if (view->doQuery(&evt)) {
936 query->setString("title", evt.findString(gTitleEvtName));
937 }
938 SkSafeUnref(view);
939 return true;
940 }
941 if (query->isType("use-fast-text")) {
942 SkEvent evt(gFastTextEvtName);
943 return curr_view(this)->doQuery(&evt);
944 }
945 return this->INHERITED::onQuery(query);
946}
947
reed@android.com0ae6b242008-12-23 16:49:54 +0000948static void cleanup_for_filename(SkString* name) {
949 char* str = name->writable_str();
reed@android.come191b162009-12-18 21:33:39 +0000950 for (size_t i = 0; i < name->size(); i++) {
reed@android.com0ae6b242008-12-23 16:49:54 +0000951 switch (str[i]) {
952 case ':': str[i] = '-'; break;
953 case '/': str[i] = '-'; break;
954 case ' ': str[i] = '_'; break;
955 default: break;
956 }
957 }
958}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000959
960bool SampleWindow::onHandleChar(SkUnichar uni) {
reed@android.comf2b98d62010-12-20 18:26:13 +0000961 {
962 SkView* view = curr_view(this);
963 if (view) {
964 SkEvent evt(gCharEvtName);
965 evt.setFast32(uni);
966 if (view->doQuery(&evt)) {
967 return true;
968 }
969 }
970 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000971
reed@android.com8a1c16f2008-12-17 15:59:43 +0000972 int dx = 0xFF;
973 int dy = 0xFF;
974
975 switch (uni) {
976 case '5': dx = 0; dy = 0; break;
977 case '8': dx = 0; dy = -1; break;
978 case '6': dx = 1; dy = 0; break;
979 case '2': dx = 0; dy = 1; break;
980 case '4': dx = -1; dy = 0; break;
981 case '7': dx = -1; dy = -1; break;
982 case '9': dx = 1; dy = -1; break;
983 case '3': dx = 1; dy = 1; break;
984 case '1': dx = -1; dy = 1; break;
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000985
reed@android.com8a1c16f2008-12-17 15:59:43 +0000986 default:
987 break;
988 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000989
reed@android.com8a1c16f2008-12-17 15:59:43 +0000990 if (0xFF != dx && 0xFF != dy) {
991 if ((dx | dy) == 0) {
992 fScrollTestX = fScrollTestY = 0;
993 } else {
994 fScrollTestX += dx;
995 fScrollTestY += dy;
996 }
997 this->inval(NULL);
998 return true;
999 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001000
reed@android.com0ae6b242008-12-23 16:49:54 +00001001 switch (uni) {
1002 case 'a':
1003 fAnimating = !fAnimating;
1004 this->postAnimatingEvent();
1005 this->updateTitle();
1006 return true;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001007 case 'b':
1008 fAAState = cycle_tristate(fAAState);
1009 this->updateTitle();
1010 this->inval(NULL);
1011 break;
1012 case 'c':
1013 fUseClip = !fUseClip;
1014 this->inval(NULL);
1015 this->updateTitle();
reed@android.com0ae6b242008-12-23 16:49:54 +00001016 return true;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001017 case 'd':
1018 SkGraphics::SetFontCacheUsed(0);
1019 return true;
1020 case 'f':
1021 fMeasureFPS = !fMeasureFPS;
1022 this->inval(NULL);
1023 break;
1024 case 'g':
1025 fRequestGrabImage = true;
1026 this->inval(NULL);
1027 break;
1028 case 'i':
1029 this->zoomIn();
1030 break;
1031 case 'l':
1032 fLCDState = cycle_tristate(fLCDState);
1033 this->updateTitle();
1034 this->inval(NULL);
1035 break;
1036 case 'o':
1037 this->zoomOut();
1038 break;
reed@android.com6c5f6f22009-08-14 16:08:38 +00001039 case 'r':
1040 fRotate = !fRotate;
1041 this->inval(NULL);
1042 this->updateTitle();
1043 return true;
1044 case 's':
1045 fScale = !fScale;
1046 this->inval(NULL);
1047 this->updateTitle();
1048 return true;
reed@google.com569e0432011-04-05 13:07:03 +00001049 case 'x':
1050 fFlipAxis ^= kFlipAxis_X;
1051 this->updateTitle();
1052 this->inval(NULL);
1053 break;
1054 case 'y':
1055 fFlipAxis ^= kFlipAxis_Y;
1056 this->updateTitle();
1057 this->inval(NULL);
1058 break;
scroggo08526c02011-03-22 14:03:21 +00001059 case 'z':
1060 this->toggleZoomer();
1061 break;
reed@android.com0ae6b242008-12-23 16:49:54 +00001062 default:
1063 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001064 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001065
reed@android.com8a1c16f2008-12-17 15:59:43 +00001066 return this->INHERITED::onHandleChar(uni);
1067}
1068
1069#include "SkDumpCanvas.h"
1070
1071bool SampleWindow::onHandleKey(SkKey key) {
reed@android.comf2b98d62010-12-20 18:26:13 +00001072 {
1073 SkView* view = curr_view(this);
1074 if (view) {
1075 SkEvent evt(gKeyEvtName);
1076 evt.setFast32(key);
1077 if (view->doQuery(&evt)) {
1078 return true;
1079 }
1080 }
1081 }
1082
reed@android.com8a1c16f2008-12-17 15:59:43 +00001083 switch (key) {
1084 case kRight_SkKey:
1085 if (this->nextSample()) {
1086 return true;
1087 }
1088 break;
1089 case kLeft_SkKey:
1090 fCanvasType = cycle_canvastype(fCanvasType);
1091 this->updateTitle();
1092 this->inval(NULL);
1093 return true;
1094 case kUp_SkKey:
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001095 if (USE_ARROWS_FOR_ZOOM) {
1096 this->changeZoomLevel(1);
1097 } else {
1098 fNClip = !fNClip;
1099 this->inval(NULL);
1100 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001101 this->updateTitle();
reed@android.com8a1c16f2008-12-17 15:59:43 +00001102 return true;
1103 case kDown_SkKey:
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001104 if (USE_ARROWS_FOR_ZOOM) {
1105 this->changeZoomLevel(-1);
1106 } else {
1107 this->setConfig(cycle_configs(this->getBitmap().config()));
1108 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001109 this->updateTitle();
1110 return true;
1111 case kOK_SkKey:
reed@android.comf2b98d62010-12-20 18:26:13 +00001112 if (false) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001113 SkDebugfDumper dumper;
1114 SkDumpCanvas dc(&dumper);
1115 this->draw(&dc);
1116 } else {
1117 fRepeatDrawing = !fRepeatDrawing;
1118 if (fRepeatDrawing) {
1119 this->inval(NULL);
1120 }
1121 }
1122 return true;
reed@android.com34245c72009-11-03 04:00:48 +00001123 case kBack_SkKey:
1124 this->loadView(NULL);
1125 return true;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001126 default:
1127 break;
1128 }
1129 return this->INHERITED::onHandleKey(key);
1130}
1131
reed@google.com52f57e12011-03-16 12:10:02 +00001132///////////////////////////////////////////////////////////////////////////////
1133
1134static const char gGestureClickType[] = "GestureClickType";
1135
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001136bool SampleWindow::onDispatchClick(int x, int y, Click::State state) {
Scroggo0f185c22011-03-24 18:35:50 +00001137 if (Click::kMoved_State == state) {
1138 updatePointer(x, y);
1139 }
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001140 int w = SkScalarRound(this->width());
1141 int h = SkScalarRound(this->height());
1142
1143 // check for the resize-box
1144 if (w - x < 16 && h - y < 16) {
1145 return false; // let the OS handle the click
1146 } else {
1147 return this->INHERITED::onDispatchClick(x, y, state);
1148 }
1149}
1150
reed@google.com52f57e12011-03-16 12:10:02 +00001151class GestureClick : public SkView::Click {
1152public:
1153 GestureClick(SkView* target) : SkView::Click(target) {
1154 this->setType(gGestureClickType);
1155 }
1156
1157 static bool IsGesture(Click* click) {
1158 return click->isType(gGestureClickType);
1159 }
1160};
1161
1162SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y) {
1163 return new GestureClick(this);
1164}
1165
1166bool SampleWindow::onClick(Click* click) {
1167 if (GestureClick::IsGesture(click)) {
1168 float x = SkScalarToFloat(click->fCurr.fX);
1169 float y = SkScalarToFloat(click->fCurr.fY);
1170 switch (click->fState) {
1171 case SkView::Click::kDown_State:
1172 fGesture.touchBegin(click, x, y);
1173 break;
1174 case SkView::Click::kMoved_State:
1175 fGesture.touchMoved(click, x, y);
1176 this->inval(NULL);
1177 break;
1178 case SkView::Click::kUp_State:
1179 fGesture.touchEnd(click);
1180 this->inval(NULL);
1181 break;
1182 }
1183 return true;
1184 }
1185 return false;
1186}
1187
1188///////////////////////////////////////////////////////////////////////////////
1189
reed@android.com8a1c16f2008-12-17 15:59:43 +00001190void SampleWindow::loadView(SkView* view) {
1191 SkView::F2BIter iter(this);
1192 SkView* prev = iter.next();
1193 if (prev) {
1194 prev->detachFromParent();
1195 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001196
reed@android.com34245c72009-11-03 04:00:48 +00001197 if (NULL == view) {
1198 view = create_overview(fSamples.count(), fSamples.begin());
1199 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001200 view->setVisibleP(true);
reed@android.comf2b98d62010-12-20 18:26:13 +00001201 view->setClipToBounds(false);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001202 this->attachChildToFront(view)->unref();
1203 view->setSize(this->width(), this->height());
1204
1205 this->updateTitle();
1206}
1207
1208static const char* gConfigNames[] = {
1209 "unknown config",
1210 "A1",
1211 "A8",
1212 "Index8",
1213 "565",
1214 "4444",
1215 "8888"
1216};
1217
1218static const char* configToString(SkBitmap::Config c) {
1219 return gConfigNames[c];
1220}
1221
1222static const char* gCanvasTypePrefix[] = {
1223 "raster: ",
1224 "picture: ",
1225 "opengl: "
1226};
1227
reed@google.com569e0432011-04-05 13:07:03 +00001228static const char* trystate_str(SkTriState state,
1229 const char trueStr[], const char falseStr[]) {
1230 if (kTrue_SkTriState == state) {
1231 return trueStr;
1232 } else if (kFalse_SkTriState == state) {
1233 return falseStr;
1234 }
1235 return NULL;
1236}
1237
reed@android.com8a1c16f2008-12-17 15:59:43 +00001238void SampleWindow::updateTitle() {
1239 SkString title;
1240
1241 SkView::F2BIter iter(this);
1242 SkView* view = iter.next();
1243 SkEvent evt(gTitleEvtName);
1244 if (view->doQuery(&evt)) {
1245 title.set(evt.findString(gTitleEvtName));
1246 }
1247 if (title.size() == 0) {
1248 title.set("<unknown>");
1249 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001250
reed@android.com8a1c16f2008-12-17 15:59:43 +00001251 title.prepend(gCanvasTypePrefix[fCanvasType]);
1252
1253 title.prepend(" ");
1254 title.prepend(configToString(this->getBitmap().config()));
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001255
reed@android.com8a1c16f2008-12-17 15:59:43 +00001256 if (fAnimating) {
1257 title.prepend("<A> ");
1258 }
reed@android.com6c5f6f22009-08-14 16:08:38 +00001259 if (fScale) {
1260 title.prepend("<S> ");
1261 }
1262 if (fRotate) {
1263 title.prepend("<R> ");
1264 }
reed@android.come522ca52009-11-23 20:10:41 +00001265 if (fNClip) {
1266 title.prepend("<C> ");
1267 }
reed@google.com569e0432011-04-05 13:07:03 +00001268
1269 title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
1270 title.prepend(trystate_str(fAAState, "AA ", "aa "));
1271 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL);
1272 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +00001273
1274 if (fZoomLevel) {
1275 title.prependf("{%d} ", fZoomLevel);
1276 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001277
1278 if (fMeasureFPS) {
1279 title.appendf(" %4d ms", fMeasureFPS_Time);
1280 }
1281
reed@android.com8a1c16f2008-12-17 15:59:43 +00001282 this->setTitle(title.c_str());
1283}
1284
1285void SampleWindow::onSizeChange() {
1286 this->INHERITED::onSizeChange();
1287
1288 SkView::F2BIter iter(this);
1289 SkView* view = iter.next();
1290 view->setSize(this->width(), this->height());
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001291
reed@android.com8a1c16f2008-12-17 15:59:43 +00001292 // rebuild our clippath
1293 {
1294 const SkScalar W = this->width();
1295 const SkScalar H = this->height();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001296
reed@android.com8a1c16f2008-12-17 15:59:43 +00001297 fClipPath.reset();
1298#if 0
1299 for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) {
1300 SkRect r;
1301 r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30));
1302 for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0))
1303 fClipPath.addRect(r);
1304 }
1305#else
1306 SkRect r;
1307 r.set(0, 0, W, H);
1308 fClipPath.addRect(r, SkPath::kCCW_Direction);
1309 r.set(W/4, H/4, W*3/4, H*3/4);
1310 fClipPath.addRect(r, SkPath::kCW_Direction);
1311#endif
1312 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001313
reed@android.com8a1c16f2008-12-17 15:59:43 +00001314 this->updateTitle(); // to refresh our config
1315}
1316
1317///////////////////////////////////////////////////////////////////////////////
1318
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001319static const char repeat_count_tag[] = "sample-set-repeat-count";
1320
reed@google.comf2183392011-04-22 14:10:48 +00001321bool SampleView::SetRepeatDraw(SkView* view, int count) {
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001322 SkEvent evt(repeat_count_tag);
1323 evt.setFast32(count);
reed@google.comf2183392011-04-22 14:10:48 +00001324 return view->doEvent(evt);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001325}
1326
1327bool SampleView::onEvent(const SkEvent& evt) {
1328 if (evt.isType(repeat_count_tag)) {
1329 fRepeatCount = evt.getFast32();
1330 return true;
1331 }
1332 return this->INHERITED::onEvent(evt);
1333}
1334
1335bool SampleView::onQuery(SkEvent* evt) {
1336 return this->INHERITED::onQuery(evt);
1337}
1338
1339void SampleView::onDraw(SkCanvas* canvas) {
1340 this->onDrawBackground(canvas);
1341 for (int i = 0; i < fRepeatCount; i++) {
1342 SkAutoCanvasRestore acr(canvas, true);
1343 this->onDrawContent(canvas);
1344 }
1345}
1346
1347void SampleView::onDrawBackground(SkCanvas* canvas) {
reed@google.comf2183392011-04-22 14:10:48 +00001348 canvas->drawColor(fBGColor);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00001349}
1350
1351///////////////////////////////////////////////////////////////////////////////
1352
reed@android.comf2b98d62010-12-20 18:26:13 +00001353template <typename T> void SkTBSort(T array[], int count) {
1354 for (int i = 1; i < count - 1; i++) {
1355 bool didSwap = false;
1356 for (int j = count - 1; j > i; --j) {
1357 if (array[j] < array[j-1]) {
1358 T tmp(array[j-1]);
1359 array[j-1] = array[j];
1360 array[j] = tmp;
1361 didSwap = true;
1362 }
1363 }
1364 if (!didSwap) {
1365 break;
1366 }
1367 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001368
reed@android.comf2b98d62010-12-20 18:26:13 +00001369 for (int k = 0; k < count - 1; k++) {
1370 SkASSERT(!(array[k+1] < array[k]));
1371 }
1372}
1373
1374#include "SkRandom.h"
1375
1376static void rand_rect(SkIRect* rect, SkRandom& rand) {
1377 int bits = 8;
1378 int shift = 32 - bits;
1379 rect->set(rand.nextU() >> shift, rand.nextU() >> shift,
1380 rand.nextU() >> shift, rand.nextU() >> shift);
1381 rect->sort();
1382}
1383
1384static void dumpRect(const SkIRect& r) {
1385 SkDebugf(" { %d, %d, %d, %d },\n",
1386 r.fLeft, r.fTop,
1387 r.fRight, r.fBottom);
1388}
1389
1390static void test_rects(const SkIRect rect[], int count) {
1391 SkRegion rgn0, rgn1;
1392
1393 for (int i = 0; i < count; i++) {
1394 rgn0.op(rect[i], SkRegion::kUnion_Op);
1395 // dumpRect(rect[i]);
1396 }
1397 rgn1.setRects(rect, count);
1398
1399 if (rgn0 != rgn1) {
1400 SkDebugf("\n");
1401 for (int i = 0; i < count; i++) {
1402 dumpRect(rect[i]);
1403 }
1404 SkDebugf("\n");
1405 }
1406}
1407
1408static void test() {
1409 size_t i;
1410
1411 const SkIRect r0[] = {
1412 { 0, 0, 1, 1 },
1413 { 2, 2, 3, 3 },
1414 };
1415 const SkIRect r1[] = {
1416 { 0, 0, 1, 3 },
1417 { 1, 1, 2, 2 },
1418 { 2, 0, 3, 3 },
1419 };
1420 const SkIRect r2[] = {
1421 { 0, 0, 1, 2 },
1422 { 2, 1, 3, 3 },
1423 { 4, 0, 5, 1 },
1424 { 6, 0, 7, 4 },
1425 };
1426
1427 static const struct {
1428 const SkIRect* fRects;
1429 int fCount;
1430 } gRecs[] = {
1431 { r0, SK_ARRAY_COUNT(r0) },
1432 { r1, SK_ARRAY_COUNT(r1) },
1433 { r2, SK_ARRAY_COUNT(r2) },
1434 };
1435
1436 for (i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
1437 test_rects(gRecs[i].fRects, gRecs[i].fCount);
1438 }
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001439
reed@android.comf2b98d62010-12-20 18:26:13 +00001440 SkRandom rand;
1441 for (i = 0; i < 10000; i++) {
1442 SkRegion rgn0, rgn1;
1443
1444 const int N = 8;
1445 SkIRect rect[N];
1446 for (int j = 0; j < N; j++) {
1447 rand_rect(&rect[j], rand);
1448 }
1449 test_rects(rect, N);
1450 }
1451}
1452
reed@android.com8a1c16f2008-12-17 15:59:43 +00001453SkOSWindow* create_sk_window(void* hwnd) {
reed@android.comf2b98d62010-12-20 18:26:13 +00001454// test();
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +00001455 return new SampleWindow(hwnd);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001456}
1457
1458void get_preferred_size(int* x, int* y, int* width, int* height) {
1459 *x = 10;
1460 *y = 50;
1461 *width = 640;
1462 *height = 480;
1463}
1464
1465void application_init() {
1466// setenv("ANDROID_ROOT", "../../../data", 0);
reed@android.come191b162009-12-18 21:33:39 +00001467#ifdef SK_BUILD_FOR_MAC
reed@android.com8a1c16f2008-12-17 15:59:43 +00001468 setenv("ANDROID_ROOT", "/android/device/data", 0);
reed@android.come191b162009-12-18 21:33:39 +00001469#endif
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +00001470 SkGraphics::Init();
1471 SkEvent::Init();
reed@android.com8a1c16f2008-12-17 15:59:43 +00001472}
1473
1474void application_term() {
bsalomon@google.com2fbc7fa2011-01-05 16:34:41 +00001475 SkEvent::Term();
1476 SkGraphics::Term();
reed@android.com8a1c16f2008-12-17 15:59:43 +00001477}