• 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 "include/private/SkChecksum.h"
12 #include "src/core/SkTDynamicHash.h"
13 #include "tools/sk_app/Window.h"
14 
15 #include <GL/glx.h>
16 #include <X11/Xlib.h>
17 
18 typedef Window XWindow;
19 
20 namespace sk_app {
21 
22 class Window_unix : public Window {
23 public:
Window_unix()24     Window_unix()
25             : Window()
26             , fDisplay(nullptr)
27             , fWindow(0)
28             , fGC(nullptr)
29             , fFBConfig(nullptr)
30             , fVisualInfo(nullptr)
31             , fMSAASampleCount(1) {}
~Window_unix()32     ~Window_unix() override { this->closeWindow(); }
33 
34     bool initWindow(Display* display);
35 
36     void setTitle(const char*) override;
37     void show() override;
38 
39     bool attach(BackendType) override;
40 
41     void onInval() override;
42 
43     bool handleEvent(const XEvent& event);
44 
GetKey(const Window_unix & w)45     static const XWindow& GetKey(const Window_unix& w) {
46         return w.fWindow;
47     }
48 
Hash(const XWindow & w)49     static uint32_t Hash(const XWindow& w) {
50         return SkChecksum::Mix(w);
51     }
52 
53     static SkTDynamicHash<Window_unix, XWindow> gWindowMap;
54 
markPendingPaint()55     void markPendingPaint() { fPendingPaint = true; }
finishPaint()56     void finishPaint() {
57         if (fPendingPaint) {
58             this->onPaint();
59             fPendingPaint = false;
60         }
61     }
62 
markPendingResize(int width,int height)63     void markPendingResize(int width, int height) {
64         if (width != this->width() || height != this->height()){
65             fPendingResize = true;
66             fPendingWidth = width;
67             fPendingHeight = height;
68         }
69     }
finishResize()70     void finishResize() {
71         if (fPendingResize) {
72             this->onResize(fPendingWidth, fPendingHeight);
73             fPendingResize = false;
74         }
75     }
76 
77     void setRequestedDisplayParams(const DisplayParams&, bool allowReattach) override;
78 
79 private:
80     void closeWindow();
81 
82     Display*     fDisplay;
83     XWindow      fWindow;
84     GC           fGC;
85     GLXFBConfig* fFBConfig;
86     XVisualInfo* fVisualInfo;
87     int          fMSAASampleCount;
88 
89     Atom     fWmDeleteMessage;
90 
91     bool     fPendingPaint;
92     int      fPendingWidth;
93     int      fPendingHeight;
94     bool     fPendingResize;
95 
96     BackendType fBackend;
97 
98     typedef Window INHERITED;
99 };
100 
101 }   // namespace sk_app
102 
103 #endif
104