epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Skia |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 10 | #ifndef SampleWindow_DEFINED |
| 11 | #define SampleWindow_DEFINED |
| 12 | |
| 13 | #include "SkWindow.h" |
| 14 | |
| 15 | #include "SampleCode.h" |
| 16 | #include "SkPath.h" |
| 17 | #include "SkScalar.h" |
| 18 | #include "SkTDArray.h" |
| 19 | #include "SkTouchGesture.h" |
| 20 | #include "SkWindow.h" |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 21 | #include "SkOSMenu.h" |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 22 | |
| 23 | class GrContext; |
reed@google.com | 29038ed | 2011-07-06 17:56:47 +0000 | [diff] [blame] | 24 | class GrRenderTarget; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 25 | |
| 26 | class SkEvent; |
| 27 | class SkCanvas; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 28 | class SkPicture; |
| 29 | class SkTypeface; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 30 | class SkData; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 31 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 32 | class SampleWindow : public SkOSWindow { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 33 | SkTDArray<const SkViewFactory*> fSamples; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 34 | public: |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 35 | enum DeviceType { |
| 36 | kRaster_DeviceType, |
| 37 | kPicture_DeviceType, |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 38 | kGPU_DeviceType, |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 39 | #if SK_ANGLE |
| 40 | kANGLE_DeviceType, |
| 41 | #endif |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 42 | kNullGPU_DeviceType |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 43 | }; |
| 44 | /** |
| 45 | * SampleApp ports can subclass this manager class if they want to: |
| 46 | * * filter the types of devices supported |
| 47 | * * customize plugging of SkDevice objects into an SkCanvas |
| 48 | * * customize publishing the results of draw to the OS window |
| 49 | * * manage GrContext / GrRenderTarget lifetimes |
| 50 | */ |
| 51 | class DeviceManager : public SkRefCnt { |
| 52 | public: |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 53 | virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 54 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 55 | virtual void tearDownBackend(SampleWindow* win) = 0; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 56 | |
| 57 | // called before drawing. should install correct device |
| 58 | // type on the canvas. Will skip drawing if returns false. |
| 59 | virtual bool prepareCanvas(DeviceType dType, |
| 60 | SkCanvas* canvas, |
| 61 | SampleWindow* win) = 0; |
| 62 | |
| 63 | // called after drawing, should get the results onto the |
| 64 | // screen. |
| 65 | virtual void publishCanvas(DeviceType dType, |
| 66 | SkCanvas* canvas, |
| 67 | SampleWindow* win) = 0; |
| 68 | |
| 69 | // called when window changes size, guaranteed to be called |
| 70 | // at least once before first draw (after init) |
| 71 | virtual void windowSizeChanged(SampleWindow* win) = 0; |
| 72 | |
| 73 | // return the GrContext backing gpu devices |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 74 | virtual GrContext* getGrContext() = 0; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 75 | |
| 76 | // return the GrRenderTarget backing gpu devices |
| 77 | virtual GrRenderTarget* getGrRenderTarget() = 0; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 81 | virtual ~SampleWindow(); |
| 82 | |
| 83 | virtual void draw(SkCanvas* canvas); |
| 84 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 85 | void setDeviceType(DeviceType type); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 86 | void toggleRendering(); |
| 87 | void toggleSlideshow(); |
| 88 | void toggleFPS(); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 89 | void showOverview(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 90 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 91 | GrContext* getGrContext() const { return fDevManager->getGrContext(); } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 92 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 93 | void setZoomCenter(float x, float y); |
| 94 | void changeZoomLevel(float delta); |
| 95 | bool nextSample(); |
| 96 | bool previousSample(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 97 | bool goToSample(int i); |
| 98 | SkString getSampleTitle(int i); |
| 99 | int sampleCount(); |
Scroggo | a54e2f6 | 2011-06-17 12:46:17 +0000 | [diff] [blame] | 100 | bool handleTouch(int ownerId, float x, float y, |
| 101 | SkView::Click::State state); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 102 | void saveToPdf(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 103 | SkData* getPDFData() { return fPDFData; } |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 104 | void postInvalDelay(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 105 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 106 | DeviceType getDeviceType() const { return fDeviceType; } |
| 107 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 108 | protected: |
| 109 | virtual void onDraw(SkCanvas* canvas); |
| 110 | virtual bool onHandleKey(SkKey key); |
| 111 | virtual bool onHandleChar(SkUnichar); |
| 112 | virtual void onSizeChange(); |
| 113 | |
| 114 | virtual SkCanvas* beforeChildren(SkCanvas*); |
| 115 | virtual void afterChildren(SkCanvas*); |
| 116 | virtual void beforeChild(SkView* child, SkCanvas* canvas); |
| 117 | virtual void afterChild(SkView* child, SkCanvas* canvas); |
| 118 | |
| 119 | virtual bool onEvent(const SkEvent& evt); |
| 120 | virtual bool onQuery(SkEvent* evt); |
| 121 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 122 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 123 | virtual bool onClick(Click* click); |
| 124 | virtual Click* onFindClickHandler(SkScalar x, SkScalar y); |
| 125 | |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 126 | void registerPictFileSamples(char** argv, int argc); |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame^] | 127 | void registerPictFileSample(char** argv, int argc); |
reed@google.com | 1830c7a | 2012-06-04 12:05:43 +0000 | [diff] [blame] | 128 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 129 | private: |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 130 | class DefaultDeviceManager; |
| 131 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 132 | int fCurrIndex; |
| 133 | |
| 134 | SkPicture* fPicture; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 135 | SkPath fClipPath; |
| 136 | |
| 137 | SkTouchGesture fGesture; |
| 138 | SkScalar fZoomLevel; |
| 139 | SkScalar fZoomScale; |
| 140 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 141 | DeviceType fDeviceType; |
| 142 | DeviceManager* fDevManager; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 143 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 144 | bool fSaveToPdf; |
| 145 | SkCanvas* fPdfCanvas; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 146 | SkData* fPDFData; |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 147 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 148 | bool fUseClip; |
| 149 | bool fNClip; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 150 | bool fAnimating; |
| 151 | bool fRotate; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 152 | bool fPerspAnim; |
| 153 | SkScalar fPerspAnimTime; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 154 | bool fScale; |
| 155 | bool fRequestGrabImage; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 156 | bool fMeasureFPS; |
| 157 | SkMSec fMeasureFPS_Time; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 158 | bool fMagnify; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame^] | 159 | |
| 160 | |
scroggo@google.com | b073d92 | 2012-06-08 15:35:03 +0000 | [diff] [blame] | 161 | SkOSMenu::TriState fPipeState; // Mixed uses a tiled pipe |
| 162 | // On uses a normal pipe |
| 163 | // Off uses no pipe |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 164 | int fUsePipeMenuItemID; |
| 165 | bool fDebugger; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame^] | 166 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 167 | // The following are for the 'fatbits' drawing |
| 168 | // Latest position of the mouse. |
| 169 | int fMouseX, fMouseY; |
| 170 | int fFatBitsScale; |
| 171 | // Used by the text showing position and color values. |
| 172 | SkTypeface* fTypeface; |
| 173 | bool fShowZoomer; |
chudy@google.com | 4605a3f | 2012-08-01 17:58:01 +0000 | [diff] [blame^] | 174 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 175 | SkOSMenu::TriState fLCDState; |
| 176 | SkOSMenu::TriState fAAState; |
| 177 | SkOSMenu::TriState fFilterState; |
| 178 | SkOSMenu::TriState fHintingState; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 179 | unsigned fFlipAxis; |
| 180 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 181 | int fMSAASampleCount; |
| 182 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 183 | int fScrollTestX, fScrollTestY; |
| 184 | SkScalar fZoomCenterX, fZoomCenterY; |
| 185 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 186 | //Stores global settings |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 187 | SkOSMenu* fAppMenu; // We pass ownership to SkWindow, when we call addMenu |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 188 | //Stores slide specific settings |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 189 | SkOSMenu* fSlideMenu; // We pass ownership to SkWindow, when we call addMenu |
| 190 | |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 191 | int fTransitionNext; |
| 192 | int fTransitionPrev; |
scroggo@google.com | 7dadc74 | 2012-04-18 14:07:57 +0000 | [diff] [blame] | 193 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 194 | void loadView(SkView*); |
| 195 | void updateTitle(); |
| 196 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 197 | bool zoomIn(); |
| 198 | bool zoomOut(); |
| 199 | void updatePointer(int x, int y); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 200 | void magnify(SkCanvas* canvas); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 201 | void showZoomer(SkCanvas* canvas); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 202 | void updateMatrix(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 203 | void postAnimatingEvent(); |
reed@google.com | e23f194 | 2011-12-08 19:36:00 +0000 | [diff] [blame] | 204 | void installDrawFilter(SkCanvas*); |
mike@reedtribe.org | 6f6e8c3 | 2011-12-27 22:33:50 +0000 | [diff] [blame] | 205 | int findByTitle(const char*); |
robertphillips@google.com | 7265e72 | 2012-05-03 18:22:28 +0000 | [diff] [blame] | 206 | void listTitles(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 207 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 208 | typedef SkOSWindow INHERITED; |
| 209 | }; |
| 210 | |
| 211 | #endif |