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