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