• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 
8 #ifndef Window_unix_DEFINED
9 #define Window_unix_DEFINED
10 
11 #include <X11/Xlib.h>
12 #include <GL/glx.h>
13 #include "../Window.h"
14 #include "SkChecksum.h"
15 #include "SkTDynamicHash.h"
16 
17 typedef Window XWindow;
18 
19 namespace sk_app {
20 
21 class Window_unix : public Window {
22 public:
Window_unix()23     Window_unix()
24             : Window()
25             , fDisplay(nullptr)
26             , fWindow(0)
27             , fGC(nullptr)
28             , fFBConfig(nullptr)
29             , fVisualInfo(nullptr)
30             , fMSAASampleCount(1) {}
~Window_unix()31     ~Window_unix() override { this->closeWindow(); }
32 
33     bool initWindow(Display* display);
34 
35     void setTitle(const char*) override;
36     void show() override;
37 
38     bool attach(BackendType) override;
39 
40     void onInval() override;
41 
42     bool handleEvent(const XEvent& event);
43 
GetKey(const Window_unix & w)44     static const XWindow& GetKey(const Window_unix& w) {
45         return w.fWindow;
46     }
47 
Hash(const XWindow & w)48     static uint32_t Hash(const XWindow& w) {
49         return SkChecksum::Mix(w);
50     }
51 
52     static SkTDynamicHash<Window_unix, XWindow> gWindowMap;
53 
markPendingPaint()54     void markPendingPaint() { fPendingPaint = true; }
finishPaint()55     void finishPaint() {
56         if (fPendingPaint) {
57             this->onPaint();
58             fPendingPaint = false;
59         }
60     }
61 
markPendingResize(int width,int height)62     void markPendingResize(int width, int height) {
63         if (width != this->width() || height != this->height()){
64             fPendingResize = true;
65             fPendingWidth = width;
66             fPendingHeight = height;
67         }
68     }
finishResize()69     void finishResize() {
70         if (fPendingResize) {
71             this->onResize(fPendingWidth, fPendingHeight);
72             fPendingResize = false;
73         }
74     }
75 
76 private:
77     void closeWindow();
78 
79     Display*     fDisplay;
80     XWindow      fWindow;
81     GC           fGC;
82     GLXFBConfig* fFBConfig;
83     XVisualInfo* fVisualInfo;
84     int          fMSAASampleCount;
85 
86     Atom     fWmDeleteMessage;
87 
88     bool     fPendingPaint;
89     int      fPendingWidth;
90     int      fPendingHeight;
91     bool     fPendingResize;
92 };
93 
94 }   // namespace sk_app
95 
96 #endif
97