SkiaExamples improvements.
Make it possible for a client to write a Hello World in less than 50 lines.
R=caryclark@google.com
Review URL: https://codereview.chromium.org/18574002
git-svn-id: http://skia.googlecode.com/svn/trunk@10319 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/SkiaExamples/SkExample.h b/experimental/SkiaExamples/SkExample.h
new file mode 100644
index 0000000..05b2ccd
--- /dev/null
+++ b/experimental/SkiaExamples/SkExample.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+
+#ifndef SkExample_DEFINED
+#define SkExample_DEFINED
+
+#include "SkWindow.h"
+#include "SkTRegistry.h"
+
+class GrContext;
+struct GrGLInterface;
+class GrRenderTarget;
+class SkCanvas;
+class SkExampleWindow;
+
+class SkExample : public SkNoncopyable {
+public:
+ SkExample(SkExampleWindow* window) : fWindow(window) {}
+
+ // Your class should override this method to do its thing.
+ virtual void draw(SkCanvas* canvas) = 0;
+
+ SkString getName() { return fName; };
+ // Use this public registry to tell the world about your sample.
+ typedef SkTRegistry<SkExample*, SkExampleWindow*> Registry;
+
+protected:
+ SkExampleWindow* fWindow;
+ SkString fName;
+};
+
+class SkExampleWindow : public SkOSWindow {
+public:
+ enum DeviceType {
+ kRaster_DeviceType,
+ kGPU_DeviceType,
+ };
+ SkExampleWindow(void* hwnd);
+
+ // Changes the device type of the object.
+ bool setupBackend(DeviceType type);
+ void tearDownBackend();
+
+ DeviceType getDeviceType() const { return fType; }
+
+protected:
+ virtual void draw(SkCanvas* canvas) SK_OVERRIDE;
+
+ virtual void onSizeChange() SK_OVERRIDE;
+
+#ifdef SK_BUILD_FOR_WIN
+ virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
+#endif
+
+ SkCanvas* createCanvas() SK_OVERRIDE;
+
+private:
+ bool findNextMatch(); // Set example to the first one that matches FLAGS_match.
+ void setupRenderTarget();
+ bool onHandleChar(SkUnichar unichar) SK_OVERRIDE;
+
+ DeviceType fType;
+
+ SkExample* fCurrExample;
+ const SkExample::Registry* fRegistry;
+ SkTDArray<const char*> fMatchStrs;
+ GrContext* fContext;
+ GrRenderTarget* fRenderTarget;
+ AttachmentInfo fAttachmentInfo;
+ const GrGLInterface* fInterface;
+
+ typedef SkOSWindow INHERITED;
+};
+
+#endif
+