Window_unix.h 2.3 KB

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