1/*
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
22class SkExample : SkNoncopyable {
23public:
24    SkExample(SkExampleWindow* window) : fWindow(window) {}
25
26    virtual ~SkExample() {}
27
28    // 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.
33    typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry;
34
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;
74    GrContext* fContext;
75    GrRenderTarget* fRenderTarget;
76    AttachmentInfo fAttachmentInfo;
77    const GrGLInterface* fInterface;
78
79    typedef SkOSWindow INHERITED;
80};
81
82#endif
83