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, |
| 39 | kNullGPU_DeviceType |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 40 | }; |
| 41 | /** |
| 42 | * SampleApp ports can subclass this manager class if they want to: |
| 43 | * * filter the types of devices supported |
| 44 | * * customize plugging of SkDevice objects into an SkCanvas |
| 45 | * * customize publishing the results of draw to the OS window |
| 46 | * * manage GrContext / GrRenderTarget lifetimes |
| 47 | */ |
| 48 | class DeviceManager : public SkRefCnt { |
| 49 | public: |
| 50 | // called at end of SampleWindow cons |
| 51 | virtual void init(SampleWindow* win) = 0; |
| 52 | |
| 53 | // called when selecting a new device type |
| 54 | // can disallow a device type by returning false. |
| 55 | virtual bool supportsDeviceType(DeviceType dType) = 0; |
| 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 |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 74 | virtual GrContext* getGrContext(DeviceType dType) = 0; |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 78 | virtual ~SampleWindow(); |
| 79 | |
| 80 | virtual void draw(SkCanvas* canvas); |
| 81 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 82 | void setDeviceType(DeviceType type); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 83 | void toggleRendering(); |
| 84 | void toggleSlideshow(); |
| 85 | void toggleFPS(); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 86 | void showOverview(); |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 87 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 88 | GrContext* getGrContext() const { return fDevManager->getGrContext(fDeviceType); } |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 89 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 90 | void setZoomCenter(float x, float y); |
| 91 | void changeZoomLevel(float delta); |
| 92 | bool nextSample(); |
| 93 | bool previousSample(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 94 | bool goToSample(int i); |
| 95 | SkString getSampleTitle(int i); |
| 96 | int sampleCount(); |
Scroggo | a54e2f6 | 2011-06-17 12:46:17 +0000 | [diff] [blame] | 97 | bool handleTouch(int ownerId, float x, float y, |
| 98 | SkView::Click::State state); |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 99 | void saveToPdf(); |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 100 | SkData* getPDFData() { return fPDFData; } |
Scroggo | 62b65b0 | 2011-06-21 16:01:26 +0000 | [diff] [blame] | 101 | void postInvalDelay(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 102 | |
| 103 | protected: |
| 104 | virtual void onDraw(SkCanvas* canvas); |
| 105 | virtual bool onHandleKey(SkKey key); |
| 106 | virtual bool onHandleChar(SkUnichar); |
| 107 | virtual void onSizeChange(); |
| 108 | |
| 109 | virtual SkCanvas* beforeChildren(SkCanvas*); |
| 110 | virtual void afterChildren(SkCanvas*); |
| 111 | virtual void beforeChild(SkView* child, SkCanvas* canvas); |
| 112 | virtual void afterChild(SkView* child, SkCanvas* canvas); |
| 113 | |
| 114 | virtual bool onEvent(const SkEvent& evt); |
| 115 | virtual bool onQuery(SkEvent* evt); |
| 116 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 117 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 118 | virtual bool onClick(Click* click); |
| 119 | virtual Click* onFindClickHandler(SkScalar x, SkScalar y); |
| 120 | |
| 121 | private: |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 122 | class DefaultDeviceManager; |
| 123 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 124 | int fCurrIndex; |
| 125 | |
| 126 | SkPicture* fPicture; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 127 | SkPath fClipPath; |
| 128 | |
| 129 | SkTouchGesture fGesture; |
| 130 | SkScalar fZoomLevel; |
| 131 | SkScalar fZoomScale; |
| 132 | |
bsalomon@google.com | 098e96d | 2011-07-14 14:30:46 +0000 | [diff] [blame] | 133 | DeviceType fDeviceType; |
| 134 | DeviceManager* fDevManager; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 135 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 136 | bool fSaveToPdf; |
| 137 | SkCanvas* fPdfCanvas; |
yangsu@google.com | 501775e | 2011-06-24 16:04:50 +0000 | [diff] [blame] | 138 | SkData* fPDFData; |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 139 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 140 | bool fUseClip; |
| 141 | bool fNClip; |
| 142 | bool fRepeatDrawing; |
| 143 | bool fAnimating; |
| 144 | bool fRotate; |
bsalomon@google.com | e8f0910 | 2011-09-08 18:48:12 +0000 | [diff] [blame] | 145 | bool fPerspAnim; |
| 146 | SkScalar fPerspAnimTime; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 147 | bool fScale; |
| 148 | bool fRequestGrabImage; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 149 | bool fMeasureFPS; |
| 150 | SkMSec fMeasureFPS_Time; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 151 | bool fMagnify; |
| 152 | |
yangsu@google.com | ef7bdfa | 2011-08-12 14:27:47 +0000 | [diff] [blame] | 153 | |
| 154 | bool fUsePipe; |
| 155 | int fUsePipeMenuItemID; |
| 156 | bool fDebugger; |
| 157 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 158 | // The following are for the 'fatbits' drawing |
| 159 | // Latest position of the mouse. |
| 160 | int fMouseX, fMouseY; |
| 161 | int fFatBitsScale; |
| 162 | // Used by the text showing position and color values. |
| 163 | SkTypeface* fTypeface; |
| 164 | bool fShowZoomer; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 165 | |
| 166 | SkOSMenu::TriState fLCDState; |
| 167 | SkOSMenu::TriState fAAState; |
| 168 | SkOSMenu::TriState fFilterState; |
| 169 | SkOSMenu::TriState fHintingState; |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 170 | unsigned fFlipAxis; |
| 171 | |
| 172 | int fScrollTestX, fScrollTestY; |
| 173 | SkScalar fZoomCenterX, fZoomCenterY; |
| 174 | |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 175 | //Stores global settings |
| 176 | SkOSMenu fAppMenu; |
| 177 | //Stores slide specific settings |
| 178 | SkOSMenu fSlideMenu; |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 179 | int fTransitionNext; |
| 180 | int fTransitionPrev; |
yangsu@google.com | 921091f | 2011-08-02 13:39:12 +0000 | [diff] [blame] | 181 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 182 | void loadView(SkView*); |
| 183 | void updateTitle(); |
| 184 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 185 | bool zoomIn(); |
| 186 | bool zoomOut(); |
| 187 | void updatePointer(int x, int y); |
yangsu@google.com | db03eaa | 2011-08-08 15:37:23 +0000 | [diff] [blame] | 188 | void magnify(SkCanvas* canvas); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 189 | void showZoomer(SkCanvas* canvas); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 190 | void updateMatrix(); |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 191 | void postAnimatingEvent(); |
| 192 | |
Scroggo | 2c8208f | 2011-06-15 16:49:08 +0000 | [diff] [blame] | 193 | typedef SkOSWindow INHERITED; |
| 194 | }; |
| 195 | |
| 196 | #endif |