aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/SkiaExamples/SkExample.h
blob: 4b84723ac2435546abb260e74ca9d29b989379b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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) {}

    virtual ~SkExample() {}

    // 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;
    GrContext* fContext;
    GrRenderTarget* fRenderTarget;
    AttachmentInfo fAttachmentInfo;
    const GrGLInterface* fInterface;

    typedef SkOSWindow INHERITED;
};

#endif