2016-05-23 20:13:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Window_unix_DEFINED
|
|
|
|
#define Window_unix_DEFINED
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2016-05-27 13:47:08 +00:00
|
|
|
#include <GL/glx.h>
|
2016-05-23 20:13:36 +00:00
|
|
|
#include "../Window.h"
|
|
|
|
#include "SkChecksum.h"
|
|
|
|
#include "SkTDynamicHash.h"
|
|
|
|
|
|
|
|
typedef Window XWindow;
|
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
class Window_unix : public Window {
|
|
|
|
public:
|
2018-02-03 01:32:49 +00:00
|
|
|
Window_unix()
|
|
|
|
: Window()
|
|
|
|
, fDisplay(nullptr)
|
|
|
|
, fWindow(0)
|
|
|
|
, fGC(nullptr)
|
|
|
|
, fFBConfig(nullptr)
|
|
|
|
, fVisualInfo(nullptr)
|
|
|
|
, fMSAASampleCount(1) {}
|
2016-05-27 13:47:08 +00:00
|
|
|
~Window_unix() override { this->closeWindow(); }
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
bool initWindow(Display* display);
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
void setTitle(const char*) override;
|
|
|
|
void show() override;
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
bool attach(BackendType) override;
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
void onInval() override;
|
|
|
|
|
|
|
|
bool handleEvent(const XEvent& event);
|
|
|
|
|
|
|
|
static const XWindow& GetKey(const Window_unix& w) {
|
2016-05-27 13:47:08 +00:00
|
|
|
return w.fWindow;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t Hash(const XWindow& w) {
|
|
|
|
return SkChecksum::Mix(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkTDynamicHash<Window_unix, XWindow> gWindowMap;
|
|
|
|
|
|
|
|
void markPendingPaint() { fPendingPaint = true; }
|
2017-10-09 19:45:33 +00:00
|
|
|
void finishPaint() {
|
2016-05-23 20:13:36 +00:00
|
|
|
if (fPendingPaint) {
|
2017-10-09 19:45:33 +00:00
|
|
|
this->onPaint();
|
|
|
|
fPendingPaint = false;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 15:50:26 +00:00
|
|
|
void markPendingResize(int width, int height) {
|
2017-02-24 20:22:53 +00:00
|
|
|
if (width != this->width() || height != this->height()){
|
2016-07-26 15:50:26 +00:00
|
|
|
fPendingResize = true;
|
|
|
|
fPendingWidth = width;
|
|
|
|
fPendingHeight = height;
|
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
void finishResize() {
|
2016-05-23 20:13:36 +00:00
|
|
|
if (fPendingResize) {
|
2017-10-09 19:45:33 +00:00
|
|
|
this->onResize(fPendingWidth, fPendingHeight);
|
2016-05-23 20:13:36 +00:00
|
|
|
fPendingResize = false;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-05-27 13:47:08 +00:00
|
|
|
void closeWindow();
|
|
|
|
|
|
|
|
Display* fDisplay;
|
|
|
|
XWindow fWindow;
|
|
|
|
GC fGC;
|
2017-03-08 15:50:21 +00:00
|
|
|
GLXFBConfig* fFBConfig;
|
2016-05-27 13:47:08 +00:00
|
|
|
XVisualInfo* fVisualInfo;
|
|
|
|
int fMSAASampleCount;
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
Atom fWmDeleteMessage;
|
|
|
|
|
|
|
|
bool fPendingPaint;
|
|
|
|
int fPendingWidth;
|
|
|
|
int fPendingHeight;
|
|
|
|
bool fPendingResize;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sk_app
|
|
|
|
|
|
|
|
#endif
|