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"
30 class SampleWindow : public SkOSWindow {
31 SkTDArray<const SkViewFactory*> fSamples;
42 #endif // SK_SUPPORT_GPU
47 static bool IsGpuDeviceType(DeviceType devType) {
52 case kANGLE_DeviceType:
54 case kNullGPU_DeviceType:
59 #endif // SK_SUPPORT_GPU
64 * SampleApp ports can subclass this manager class if they want to:
65 * * filter the types of devices supported
66 * * customize plugging of SkBaseDevice objects into an SkCanvas
67 * * customize publishing the results of draw to the OS window
68 * * manage GrContext / GrRenderTarget lifetimes
70 class DeviceManager : public SkRefCnt {
72 SK_DECLARE_INST_COUNT(DeviceManager)
74 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
76 virtual void tearDownBackend(SampleWindow* win) = 0;
78 // called before drawing. should install correct device
79 // type on the canvas. Will skip drawing if returns false.
80 virtual SkSurface* createSurface(DeviceType dType, SampleWindow* win) = 0;
82 // called after drawing, should get the results onto the
84 virtual void publishCanvas(DeviceType dType,
86 SampleWindow* win) = 0;
88 // called when window changes size, guaranteed to be called
89 // at least once before first draw (after init)
90 virtual void windowSizeChanged(SampleWindow* win) = 0;
92 // return the GrContext backing gpu devices (NULL if not built with GPU support)
93 virtual GrContext* getGrContext() = 0;
95 // return the GrRenderTarget backing gpu devices (NULL if not built with GPU support)
96 virtual GrRenderTarget* getGrRenderTarget() = 0;
98 typedef SkRefCnt INHERITED;
101 SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
102 virtual ~SampleWindow();
104 virtual SkSurface* createSurface() SK_OVERRIDE {
105 SkSurface* surface = NULL;
107 surface = fDevManager->createSurface(fDeviceType, this);
109 if (NULL == surface) {
110 surface = this->INHERITED::createSurface();
115 virtual void draw(SkCanvas*) SK_OVERRIDE;
117 void setDeviceType(DeviceType type);
118 void toggleRendering();
119 void toggleSlideshow();
122 void toggleDistanceFieldFonts();
124 GrContext* getGrContext() const { return fDevManager->getGrContext(); }
126 void setZoomCenter(float x, float y);
127 void changeZoomLevel(float delta);
129 bool previousSample();
130 bool goToSample(int i);
131 SkString getSampleTitle(int i);
133 bool handleTouch(int ownerId, float x, float y,
134 SkView::Click::State state);
136 void postInvalDelay();
138 DeviceType getDeviceType() const { return fDeviceType; }
141 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
142 virtual bool onHandleKey(SkKey key) SK_OVERRIDE;
143 virtual bool onHandleChar(SkUnichar) SK_OVERRIDE;
144 virtual void onSizeChange() SK_OVERRIDE;
146 virtual SkCanvas* beforeChildren(SkCanvas*) SK_OVERRIDE;
147 virtual void afterChildren(SkCanvas*) SK_OVERRIDE;
148 virtual void beforeChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
149 virtual void afterChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
151 virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE;
152 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE;
154 virtual bool onDispatchClick(int x, int y, Click::State, void* owner,
155 unsigned modi) SK_OVERRIDE;
156 virtual bool onClick(Click* click) SK_OVERRIDE;
157 virtual Click* onFindClickHandler(SkScalar x, SkScalar y,
158 unsigned modi) SK_OVERRIDE;
161 class DefaultDeviceManager;
165 SkPictureRecorder fRecorder;
168 SkTouchGesture fGesture;
172 DeviceType fDeviceType;
173 DeviceManager* fDevManager;
176 SkAutoTUnref<SkDocument> fPDFDocument;
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*);
228 bool getRawTitle(SkString*);
232 void updatePointer(int x, int y);
233 void magnify(SkCanvas* canvas);
234 void showZoomer(SkCanvas* canvas);
236 void postAnimatingEvent();
237 void installDrawFilter(SkCanvas*);
238 int findByTitle(const char*);
240 SkSize tileSize() const;
242 typedef SkOSWindow INHERITED;