4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SampleApp_DEFINED
9 #define SampleApp_DEFINED
13 #include "SkPicture.h"
14 #include "SkPictureRecorder.h"
16 #include "SkTDArray.h"
17 #include "SkTouchGesture.h"
29 class SampleWindow : public SkOSWindow {
30 SkTDArray<const SkViewFactory*> fSamples;
41 #endif // SK_SUPPORT_GPU
46 static bool IsGpuDeviceType(DeviceType devType) {
51 case kANGLE_DeviceType:
53 case kNullGPU_DeviceType:
58 #endif // SK_SUPPORT_GPU
63 * SampleApp ports can subclass this manager class if they want to:
64 * * filter the types of devices supported
65 * * customize plugging of SkBaseDevice objects into an SkCanvas
66 * * customize publishing the results of draw to the OS window
67 * * manage GrContext / GrRenderTarget lifetimes
69 class DeviceManager : public SkRefCnt {
71 SK_DECLARE_INST_COUNT(DeviceManager)
73 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
75 virtual void tearDownBackend(SampleWindow* win) = 0;
77 // called before drawing. should install correct device
78 // type on the canvas. Will skip drawing if returns false.
79 virtual SkCanvas* createCanvas(DeviceType dType, SampleWindow* win) = 0;
81 // called after drawing, should get the results onto the
83 virtual void publishCanvas(DeviceType dType,
85 SampleWindow* win) = 0;
87 // called when window changes size, guaranteed to be called
88 // at least once before first draw (after init)
89 virtual void windowSizeChanged(SampleWindow* win) = 0;
91 // return the GrContext backing gpu devices (NULL if not built with GPU support)
92 virtual GrContext* getGrContext() = 0;
94 // return the GrRenderTarget backing gpu devices (NULL if not built with GPU support)
95 virtual GrRenderTarget* getGrRenderTarget() = 0;
97 typedef SkRefCnt INHERITED;
100 SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
101 virtual ~SampleWindow();
103 virtual SkCanvas* createCanvas() SK_OVERRIDE {
104 SkCanvas* canvas = NULL;
106 canvas = fDevManager->createCanvas(fDeviceType, this);
108 if (NULL == canvas) {
109 canvas = this->INHERITED::createCanvas();
114 virtual void draw(SkCanvas* canvas);
116 void setDeviceType(DeviceType type);
117 void toggleRendering();
118 void toggleSlideshow();
122 GrContext* getGrContext() const { return fDevManager->getGrContext(); }
124 void setZoomCenter(float x, float y);
125 void changeZoomLevel(float delta);
127 bool previousSample();
128 bool goToSample(int i);
129 SkString getSampleTitle(int i);
131 bool handleTouch(int ownerId, float x, float y,
132 SkView::Click::State state);
134 SkData* getPDFData() { return fPDFData; }
135 void postInvalDelay();
137 DeviceType getDeviceType() const { return fDeviceType; }
140 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
141 virtual bool onHandleKey(SkKey key) SK_OVERRIDE;
142 virtual bool onHandleChar(SkUnichar) SK_OVERRIDE;
143 virtual void onSizeChange() SK_OVERRIDE;
145 virtual SkCanvas* beforeChildren(SkCanvas*) SK_OVERRIDE;
146 virtual void afterChildren(SkCanvas*) SK_OVERRIDE;
147 virtual void beforeChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
148 virtual void afterChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
150 virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE;
151 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE;
153 virtual bool onDispatchClick(int x, int y, Click::State, void* owner,
154 unsigned modi) SK_OVERRIDE;
155 virtual bool onClick(Click* click) SK_OVERRIDE;
156 virtual Click* onFindClickHandler(SkScalar x, SkScalar y,
157 unsigned modi) SK_OVERRIDE;
160 class DefaultDeviceManager;
164 SkPictureRecorder fRecorder;
167 SkTouchGesture fGesture;
171 DeviceType fDeviceType;
172 DeviceManager* fDevManager;
175 SkCanvas* fPdfCanvas;
182 SkScalar fRotateAnimTime;
184 SkScalar fPerspAnimTime;
185 bool fRequestGrabImage;
187 SkMSec fMeasureFPS_Time;
188 SkMSec fMeasureFPS_StartTime;
193 SkOSMenu::TriState fPipeState; // Mixed uses a tiled pipe
194 // On uses a normal pipe
196 int fUsePipeMenuItemID;
198 // The following are for the 'fatbits' drawing
199 // Latest position of the mouse.
200 int fMouseX, fMouseY;
202 // Used by the text showing position and color values.
203 SkTypeface* fTypeface;
206 SkOSMenu::TriState fLCDState;
207 SkOSMenu::TriState fAAState;
208 SkOSMenu::TriState fSubpixelState;
210 int fFilterLevelIndex;
213 int fMSAASampleCount;
215 int fScrollTestX, fScrollTestY;
216 SkScalar fZoomCenterX, fZoomCenterY;
218 //Stores global settings
219 SkOSMenu* fAppMenu; // We pass ownership to SkWindow, when we call addMenu
220 //Stores slide specific settings
221 SkOSMenu* fSlideMenu; // We pass ownership to SkWindow, when we call addMenu
226 void loadView(SkView*);
231 void updatePointer(int x, int y);
232 void magnify(SkCanvas* canvas);
233 void showZoomer(SkCanvas* canvas);
235 void postAnimatingEvent();
236 void installDrawFilter(SkCanvas*);
237 int findByTitle(const char*);
239 SkSize tileSize() const;
241 typedef SkOSWindow INHERITED;