blob: ea734dcdc69ec41ace5d1a17cb27c241d8d186d6 [file] [log] [blame]
sglez@google.com43f2b2c2013-07-24 17:48:03 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 *
8 */
9
10#ifndef SkExample_DEFINED
11#define SkExample_DEFINED
12
13#include "SkWindow.h"
14#include "SkTRegistry.h"
15
16class GrContext;
17struct GrGLInterface;
18class GrRenderTarget;
19class SkCanvas;
20class SkExampleWindow;
21
commit-bot@chromium.orge3beb6b2014-04-07 19:34:38 +000022class SkExample : SkNoncopyable {
sglez@google.com43f2b2c2013-07-24 17:48:03 +000023public:
24 SkExample(SkExampleWindow* window) : fWindow(window) {}
25
commit-bot@chromium.orgb09bfcb2013-12-17 23:37:38 +000026 virtual ~SkExample() {}
27
sglez@google.com43f2b2c2013-07-24 17:48:03 +000028 // Your class should override this method to do its thing.
29 virtual void draw(SkCanvas* canvas) = 0;
30
31 SkString getName() { return fName; };
32 // Use this public registry to tell the world about your sample.
mtklein@google.combd6343b2013-09-04 17:20:18 +000033 typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry;
sglez@google.com43f2b2c2013-07-24 17:48:03 +000034
35protected:
36 SkExampleWindow* fWindow;
37 SkString fName;
38};
39
40class SkExampleWindow : public SkOSWindow {
41public:
42 enum DeviceType {
43 kRaster_DeviceType,
44 kGPU_DeviceType,
45 };
46 SkExampleWindow(void* hwnd);
47
48 // Changes the device type of the object.
49 bool setupBackend(DeviceType type);
50 void tearDownBackend();
51
52 DeviceType getDeviceType() const { return fType; }
53
54protected:
55 virtual void draw(SkCanvas* canvas) SK_OVERRIDE;
56
57 virtual void onSizeChange() SK_OVERRIDE;
58
59#ifdef SK_BUILD_FOR_WIN
60 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
61#endif
62
63 SkCanvas* createCanvas() SK_OVERRIDE;
64
65private:
66 bool findNextMatch(); // Set example to the first one that matches FLAGS_match.
67 void setupRenderTarget();
68 bool onHandleChar(SkUnichar unichar) SK_OVERRIDE;
69
70 DeviceType fType;
71
72 SkExample* fCurrExample;
73 const SkExample::Registry* fRegistry;
sglez@google.com43f2b2c2013-07-24 17:48:03 +000074 GrContext* fContext;
75 GrRenderTarget* fRenderTarget;
76 AttachmentInfo fAttachmentInfo;
77 const GrGLInterface* fInterface;
78
79 typedef SkOSWindow INHERITED;
80};
81
82#endif