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