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