aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SampleApp.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-07-14 14:30:46 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-07-14 14:30:46 +0000
commit098e96df6ab0327f18537c7006ff2b0b4116ee30 (patch)
treea705f207f4541103b6e13c6ba5696db65cd656d1 /samplecode/SampleApp.h
parent7d04280a68430d6b472ee67dc8f6092127625e73 (diff)
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
Diffstat (limited to 'samplecode/SampleApp.h')
-rw-r--r--samplecode/SampleApp.h65
1 files changed, 49 insertions, 16 deletions
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 9b47b8e0dd..770d620690 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -44,7 +44,48 @@ enum SkTriState {
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 @@ public:
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 @@ protected:
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 @@ private:
int fScrollTestX, fScrollTestY;
SkScalar fZoomCenterX, fZoomCenterY;
- bool make3DReady();
-
void loadView(SkView*);
void updateTitle();
@@ -150,8 +185,6 @@ private:
void postAnimatingEvent();
- static CanvasType cycle_canvastype(CanvasType);
-
typedef SkOSWindow INHERITED;
};