Add DeviceManager to SampleWindow
Review URL: http://codereview.appspot.com/4715045/
git-svn-id: http://skia.googlecode.com/svn/trunk@1857 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 9b47b8e..770d620 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -44,7 +44,48 @@
class SampleWindow : public SkOSWindow {
SkTDArray<SkViewFactory> fSamples;
public:
- SampleWindow(void* hwnd, int argc, char** argv);
+ enum DeviceType {
+ kRaster_DeviceType,
+ kPicture_DeviceType,
+ kGPU_DeviceType
+ };
+ /**
+ * SampleApp ports can subclass this manager class if they want to:
+ * * filter the types of devices supported
+ * * customize plugging of SkDevice objects into an SkCanvas
+ * * customize publishing the results of draw to the OS window
+ * * manage GrContext / GrRenderTarget lifetimes
+ */
+ class DeviceManager : public SkRefCnt {
+ public:
+ // called at end of SampleWindow cons
+ virtual void init(SampleWindow* win) = 0;
+
+ // called when selecting a new device type
+ // can disallow a device type by returning false.
+ virtual bool supportsDeviceType(DeviceType dType) = 0;
+
+ // called before drawing. should install correct device
+ // type on the canvas. Will skip drawing if returns false.
+ virtual bool prepareCanvas(DeviceType dType,
+ SkCanvas* canvas,
+ SampleWindow* win) = 0;
+
+ // called after drawing, should get the results onto the
+ // screen.
+ virtual void publishCanvas(DeviceType dType,
+ SkCanvas* canvas,
+ SampleWindow* win) = 0;
+
+ // called when window changes size, guaranteed to be called
+ // at least once before first draw (after init)
+ virtual void windowSizeChanged(SampleWindow* win) = 0;
+
+ // return the GrContext backing gpu devices
+ virtual GrContext* getGrContext() = 0;
+ };
+
+ SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
virtual ~SampleWindow();
virtual void draw(SkCanvas* canvas);
@@ -52,9 +93,9 @@
void toggleRendering();
void toggleSlideshow();
void toggleFPS();
- bool drawsToHardware() { return fCanvasType == kGPU_CanvasType; }
- bool setGrContext(GrContext*);
- GrContext* getGrContext();
+
+ GrContext* getGrContext() const { return fDevManager->getGrContext(); }
+
void setZoomCenter(float x, float y);
void changeZoomLevel(float delta);
bool nextSample();
@@ -87,23 +128,19 @@
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
private:
+ class DefaultDeviceManager;
+
int fCurrIndex;
SkPicture* fPicture;
- GrContext* fGrContext;
- GrRenderTarget* fGrRenderTarget;
SkPath fClipPath;
SkTouchGesture fGesture;
SkScalar fZoomLevel;
SkScalar fZoomScale;
- enum CanvasType {
- kRaster_CanvasType,
- kPicture_CanvasType,
- kGPU_CanvasType
- };
- CanvasType fCanvasType;
+ DeviceType fDeviceType;
+ DeviceManager* fDevManager;
bool fSaveToPdf;
SkCanvas* fPdfCanvas;
@@ -137,8 +174,6 @@
int fScrollTestX, fScrollTestY;
SkScalar fZoomCenterX, fZoomCenterY;
- bool make3DReady();
-
void loadView(SkView*);
void updateTitle();
@@ -150,8 +185,6 @@
void postAnimatingEvent();
- static CanvasType cycle_canvastype(CanvasType);
-
typedef SkOSWindow INHERITED;
};