aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sk_app/unix/Window_unix.h
blob: 62a2795098021891d67a418120f8e4529e784d15 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#ifndef Window_unix_DEFINED
#define Window_unix_DEFINED

#include <X11/Xlib.h>
#include <GL/glx.h>
#include "../Window.h"
#include "SkChecksum.h"
#include "SkTDynamicHash.h"

typedef Window XWindow;

namespace sk_app {

class Window_unix : public Window {
public:
    Window_unix()
            : Window()
            , fDisplay(nullptr)
            , fWindow(0)
            , fGC(nullptr)
            , fFBConfig(nullptr)
            , fVisualInfo(nullptr)
            , fMSAASampleCount(1) {}
    ~Window_unix() override { this->closeWindow(); }

    bool initWindow(Display* display);

    void setTitle(const char*) override;
    void show() override;

    bool attach(BackendType) override;

    void onInval() override;

    bool handleEvent(const XEvent& event);

    static const XWindow& GetKey(const Window_unix& w) {
        return w.fWindow;
    }

    static uint32_t Hash(const XWindow& w) {
        return SkChecksum::Mix(w);
    }

    static SkTDynamicHash<Window_unix, XWindow> gWindowMap;

    void markPendingPaint() { fPendingPaint = true; }
    void finishPaint() {
        if (fPendingPaint) {
            this->onPaint();
            fPendingPaint = false;
        }
    }

    void markPendingResize(int width, int height) {
        if (width != this->width() || height != this->height()){
            fPendingResize = true;
            fPendingWidth = width;
            fPendingHeight = height;
        }
    }
    void finishResize() {
        if (fPendingResize) {
            this->onResize(fPendingWidth, fPendingHeight);
            fPendingResize = false;
        }
    }

private:
    void closeWindow();

    Display*     fDisplay;
    XWindow      fWindow;
    GC           fGC;
    GLXFBConfig* fFBConfig;
    XVisualInfo* fVisualInfo;
    int          fMSAASampleCount;

    Atom     fWmDeleteMessage;

    bool     fPendingPaint;
    int      fPendingWidth;
    int      fPendingHeight;
    bool     fPendingResize;
};

}   // namespace sk_app

#endif