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
|
2019-07-08 20:07:57 +00:00
|
|
|
* f 49
|
|
|
|
* Prev
|
|
|
|
* Up
|
|
|
|
*
|
|
|
|
*
|
2016-05-23 20:13:36 +00:00
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#include <tchar.h>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/unix/WindowContextFactory_unix.h"
|
2016-07-26 19:02:50 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
#include "tools/sk_app/GLWindowContext.h"
|
|
|
|
#include "tools/sk_app/unix/Window_unix.h"
|
2019-08-29 14:39:22 +00:00
|
|
|
#include "tools/skui/ModifierKey.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/timer/Timer.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
extern "C" {
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/unix/keysym2ucs.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
SkTDynamicHash<Window_unix, XWindow> Window_unix::gWindowMap;
|
|
|
|
|
|
|
|
Window* Window::CreateNativeWindow(void* platformData) {
|
|
|
|
Display* display = (Display*)platformData;
|
2017-01-05 18:50:49 +00:00
|
|
|
SkASSERT(display);
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
Window_unix* window = new Window_unix();
|
2017-02-24 23:04:47 +00:00
|
|
|
if (!window->initWindow(display)) {
|
2016-05-23 20:13:36 +00:00
|
|
|
delete window;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2017-10-09 19:45:33 +00:00
|
|
|
const long kEventMask = ExposureMask | StructureNotifyMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
2016-05-27 13:47:08 +00:00
|
|
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
bool Window_unix::initWindow(Display* display) {
|
|
|
|
if (fRequestedDisplayParams.fMSAASampleCount != fMSAASampleCount) {
|
2016-05-27 13:47:08 +00:00
|
|
|
this->closeWindow();
|
|
|
|
}
|
|
|
|
// we already have a window
|
|
|
|
if (fDisplay) {
|
|
|
|
return true;
|
2016-07-26 19:56:32 +00:00
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
fDisplay = display;
|
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
constexpr int initialWidth = 1280;
|
|
|
|
constexpr int initialHeight = 960;
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-05-27 13:47:08 +00:00
|
|
|
// Attempt to create a window that supports GL
|
2017-03-08 15:50:21 +00:00
|
|
|
|
|
|
|
// We prefer the more recent glXChooseFBConfig but fall back to glXChooseVisual. They have
|
|
|
|
// slight differences in how attributes are specified.
|
|
|
|
static int constexpr kChooseFBConfigAtt[] = {
|
|
|
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
|
|
GLX_DOUBLEBUFFER, True,
|
|
|
|
GLX_STENCIL_SIZE, 8,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
// For some reason glXChooseVisual takes a non-const pointer to the attributes.
|
|
|
|
int chooseVisualAtt[] = {
|
2016-05-27 13:47:08 +00:00
|
|
|
GLX_RGBA,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_STENCIL_SIZE, 8,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
SkASSERT(nullptr == fVisualInfo);
|
2018-02-03 01:32:49 +00:00
|
|
|
if (fRequestedDisplayParams.fMSAASampleCount > 1) {
|
2017-03-08 15:50:21 +00:00
|
|
|
static const GLint kChooseFBConifgAttCnt = SK_ARRAY_COUNT(kChooseFBConfigAtt);
|
|
|
|
GLint msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 4];
|
|
|
|
memcpy(msaaChooseFBConfigAtt, kChooseFBConfigAtt, sizeof(kChooseFBConfigAtt));
|
|
|
|
SkASSERT(None == msaaChooseFBConfigAtt[kChooseFBConifgAttCnt - 1]);
|
|
|
|
msaaChooseFBConfigAtt[kChooseFBConifgAttCnt - 1] = GLX_SAMPLE_BUFFERS_ARB;
|
|
|
|
msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 0] = 1;
|
|
|
|
msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 1] = GLX_SAMPLES_ARB;
|
|
|
|
msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 2] = fRequestedDisplayParams.fMSAASampleCount;
|
|
|
|
msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 3] = None;
|
|
|
|
int n;
|
|
|
|
fFBConfig = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay), msaaChooseFBConfigAtt, &n);
|
|
|
|
if (n > 0) {
|
|
|
|
fVisualInfo = glXGetVisualFromFBConfig(fDisplay, *fFBConfig);
|
|
|
|
} else {
|
|
|
|
static const GLint kChooseVisualAttCnt = SK_ARRAY_COUNT(chooseVisualAtt);
|
|
|
|
GLint msaaChooseVisualAtt[kChooseVisualAttCnt + 4];
|
|
|
|
memcpy(msaaChooseVisualAtt, chooseVisualAtt, sizeof(chooseVisualAtt));
|
|
|
|
SkASSERT(None == msaaChooseVisualAtt[kChooseVisualAttCnt - 1]);
|
|
|
|
msaaChooseFBConfigAtt[kChooseVisualAttCnt - 1] = GLX_SAMPLE_BUFFERS_ARB;
|
|
|
|
msaaChooseFBConfigAtt[kChooseVisualAttCnt + 0] = 1;
|
|
|
|
msaaChooseFBConfigAtt[kChooseVisualAttCnt + 1] = GLX_SAMPLES_ARB;
|
|
|
|
msaaChooseFBConfigAtt[kChooseVisualAttCnt + 2] =
|
|
|
|
fRequestedDisplayParams.fMSAASampleCount;
|
|
|
|
msaaChooseFBConfigAtt[kChooseVisualAttCnt + 3] = None;
|
|
|
|
fVisualInfo = glXChooseVisual(display, DefaultScreen(display), msaaChooseVisualAtt);
|
|
|
|
fFBConfig = nullptr;
|
|
|
|
}
|
2016-05-27 13:47:08 +00:00
|
|
|
}
|
|
|
|
if (nullptr == fVisualInfo) {
|
2017-03-08 15:50:21 +00:00
|
|
|
int n;
|
|
|
|
fFBConfig = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay), kChooseFBConfigAtt, &n);
|
|
|
|
if (n > 0) {
|
|
|
|
fVisualInfo = glXGetVisualFromFBConfig(fDisplay, *fFBConfig);
|
|
|
|
} else {
|
|
|
|
fVisualInfo = glXChooseVisual(display, DefaultScreen(display), chooseVisualAtt);
|
|
|
|
fFBConfig = nullptr;
|
|
|
|
}
|
2016-05-27 12:47:00 +00:00
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-05-27 13:47:08 +00:00
|
|
|
if (fVisualInfo) {
|
|
|
|
Colormap colorMap = XCreateColormap(display,
|
|
|
|
RootWindow(display, fVisualInfo->screen),
|
|
|
|
fVisualInfo->visual,
|
|
|
|
AllocNone);
|
|
|
|
XSetWindowAttributes swa;
|
|
|
|
swa.colormap = colorMap;
|
|
|
|
swa.event_mask = kEventMask;
|
|
|
|
fWindow = XCreateWindow(display,
|
|
|
|
RootWindow(display, fVisualInfo->screen),
|
|
|
|
0, 0, // x, y
|
2017-02-24 20:22:53 +00:00
|
|
|
initialWidth, initialHeight,
|
2016-05-27 13:47:08 +00:00
|
|
|
0, // border width
|
|
|
|
fVisualInfo->depth,
|
|
|
|
InputOutput,
|
|
|
|
fVisualInfo->visual,
|
|
|
|
CWEventMask | CWColormap,
|
|
|
|
&swa);
|
|
|
|
} else {
|
|
|
|
// Create a simple window instead. We will not be able to show GL
|
|
|
|
fWindow = XCreateSimpleWindow(display,
|
|
|
|
DefaultRootWindow(display),
|
|
|
|
0, 0, // x, y
|
2017-02-24 20:22:53 +00:00
|
|
|
initialWidth, initialHeight,
|
2016-05-27 13:47:08 +00:00
|
|
|
0, // border width
|
|
|
|
0, // border value
|
|
|
|
0); // background value
|
|
|
|
XSelectInput(display, fWindow, kEventMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fWindow) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-27 13:20:10 +00:00
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
fMSAASampleCount = fRequestedDisplayParams.fMSAASampleCount;
|
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
// set up to catch window delete message
|
|
|
|
fWmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
2016-05-27 13:47:08 +00:00
|
|
|
XSetWMProtocols(display, fWindow, &fWmDeleteMessage, 1);
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
// add to hashtable of windows
|
|
|
|
gWindowMap.add(this);
|
|
|
|
|
|
|
|
// init event variables
|
|
|
|
fPendingPaint = false;
|
|
|
|
fPendingResize = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-27 13:47:08 +00:00
|
|
|
void Window_unix::closeWindow() {
|
|
|
|
if (fDisplay) {
|
|
|
|
this->detach();
|
2017-02-24 23:04:47 +00:00
|
|
|
if (fGC) {
|
|
|
|
XFreeGC(fDisplay, fGC);
|
|
|
|
fGC = nullptr;
|
|
|
|
}
|
2016-05-27 13:47:08 +00:00
|
|
|
gWindowMap.remove(fWindow);
|
|
|
|
XDestroyWindow(fDisplay, fWindow);
|
|
|
|
fWindow = 0;
|
2017-03-08 15:50:21 +00:00
|
|
|
if (fFBConfig) {
|
|
|
|
XFree(fFBConfig);
|
|
|
|
fFBConfig = nullptr;
|
|
|
|
}
|
|
|
|
if (fVisualInfo) {
|
|
|
|
XFree(fVisualInfo);
|
|
|
|
fVisualInfo = nullptr;
|
|
|
|
}
|
2016-05-27 13:47:08 +00:00
|
|
|
fDisplay = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
static skui::Key get_key(KeySym keysym) {
|
2016-05-23 20:13:36 +00:00
|
|
|
static const struct {
|
|
|
|
KeySym fXK;
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::Key fKey;
|
2016-05-23 20:13:36 +00:00
|
|
|
} gPair[] = {
|
2019-08-29 14:39:22 +00:00
|
|
|
{ XK_BackSpace, skui::Key::kBack },
|
|
|
|
{ XK_Clear, skui::Key::kBack },
|
|
|
|
{ XK_Return, skui::Key::kOK },
|
|
|
|
{ XK_Up, skui::Key::kUp },
|
|
|
|
{ XK_Down, skui::Key::kDown },
|
|
|
|
{ XK_Left, skui::Key::kLeft },
|
|
|
|
{ XK_Right, skui::Key::kRight },
|
|
|
|
{ XK_Tab, skui::Key::kTab },
|
|
|
|
{ XK_Page_Up, skui::Key::kPageUp },
|
|
|
|
{ XK_Page_Down, skui::Key::kPageDown },
|
|
|
|
{ XK_Home, skui::Key::kHome },
|
|
|
|
{ XK_End, skui::Key::kEnd },
|
|
|
|
{ XK_Delete, skui::Key::kDelete },
|
|
|
|
{ XK_Escape, skui::Key::kEscape },
|
|
|
|
{ XK_Shift_L, skui::Key::kShift },
|
|
|
|
{ XK_Shift_R, skui::Key::kShift },
|
|
|
|
{ XK_Control_L, skui::Key::kCtrl },
|
|
|
|
{ XK_Control_R, skui::Key::kCtrl },
|
|
|
|
{ XK_Alt_L, skui::Key::kOption },
|
|
|
|
{ XK_Alt_R, skui::Key::kOption },
|
|
|
|
{ 'A', skui::Key::kA },
|
|
|
|
{ 'C', skui::Key::kC },
|
|
|
|
{ 'V', skui::Key::kV },
|
|
|
|
{ 'X', skui::Key::kX },
|
|
|
|
{ 'Y', skui::Key::kY },
|
|
|
|
{ 'Z', skui::Key::kZ },
|
2016-05-23 20:13:36 +00:00
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
|
|
|
|
if (gPair[i].fXK == keysym) {
|
|
|
|
return gPair[i].fKey;
|
|
|
|
}
|
|
|
|
}
|
2019-08-29 14:39:22 +00:00
|
|
|
return skui::Key::kNONE;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
static skui::ModifierKey get_modifiers(const XEvent& event) {
|
2016-05-23 20:13:36 +00:00
|
|
|
static const struct {
|
|
|
|
unsigned fXMask;
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::ModifierKey fSkMask;
|
2016-05-23 20:13:36 +00:00
|
|
|
} gModifiers[] = {
|
2019-08-29 14:39:22 +00:00
|
|
|
{ ShiftMask, skui::ModifierKey::kShift },
|
|
|
|
{ ControlMask, skui::ModifierKey::kControl },
|
|
|
|
{ Mod1Mask, skui::ModifierKey::kOption },
|
2016-05-23 20:13:36 +00:00
|
|
|
};
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
|
2016-05-23 20:13:36 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gModifiers); ++i) {
|
|
|
|
if (event.xkey.state & gModifiers[i].fXMask) {
|
|
|
|
modifiers |= gModifiers[i].fSkMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window_unix::handleEvent(const XEvent& event) {
|
|
|
|
switch (event.type) {
|
2016-05-27 13:47:08 +00:00
|
|
|
case MapNotify:
|
|
|
|
if (!fGC) {
|
|
|
|
fGC = XCreateGC(fDisplay, fWindow, 0, nullptr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
case ClientMessage:
|
|
|
|
if ((Atom)event.xclient.data.l[0] == fWmDeleteMessage &&
|
|
|
|
gWindowMap.count() == 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
switch (event.xbutton.button) {
|
|
|
|
case Button1:
|
|
|
|
this->onMouse(event.xbutton.x, event.xbutton.y,
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::InputState::kDown, get_modifiers(event));
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
break;
|
|
|
|
case Button4:
|
|
|
|
this->onMouseWheel(1.0f, get_modifiers(event));
|
|
|
|
break;
|
|
|
|
case Button5:
|
|
|
|
this->onMouseWheel(-1.0f, get_modifiers(event));
|
|
|
|
break;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
|
|
|
if (event.xbutton.button == Button1) {
|
|
|
|
this->onMouse(event.xbutton.x, event.xbutton.y,
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::InputState::kUp, get_modifiers(event));
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
this->onMouse(event.xmotion.x, event.xmotion.y,
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::InputState::kMove, get_modifiers(event));
|
2016-05-23 20:13:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyPress: {
|
|
|
|
int shiftLevel = (event.xkey.state & ShiftMask) ? 1 : 0;
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
KeySym keysym = XkbKeycodeToKeysym(fDisplay, event.xkey.keycode, 0, shiftLevel);
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::Key key = get_key(keysym);
|
|
|
|
if (key != skui::Key::kNONE) {
|
|
|
|
if (!this->onKey(key, skui::InputState::kDown, get_modifiers(event))) {
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
if (keysym == XK_Escape) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
|
|
|
|
long uni = keysym2ucs(keysym);
|
|
|
|
if (uni != -1) {
|
|
|
|
(void) this->onChar((SkUnichar) uni, get_modifiers(event));
|
|
|
|
}
|
2016-05-23 20:13:36 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case KeyRelease: {
|
|
|
|
int shiftLevel = (event.xkey.state & ShiftMask) ? 1 : 0;
|
|
|
|
KeySym keysym = XkbKeycodeToKeysym(fDisplay, event.xkey.keycode,
|
|
|
|
0, shiftLevel);
|
2019-08-29 14:39:22 +00:00
|
|
|
skui::Key key = get_key(keysym);
|
|
|
|
(void) this->onKey(key, skui::InputState::kUp,
|
2016-05-23 20:13:36 +00:00
|
|
|
get_modifiers(event));
|
|
|
|
} break;
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// these events should be handled in the main event loop
|
|
|
|
SkASSERT(event.type != Expose && event.type != ConfigureNotify);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_unix::setTitle(const char* title) {
|
|
|
|
XTextProperty textproperty;
|
|
|
|
XStringListToTextProperty(const_cast<char**>(&title), 1, &textproperty);
|
2017-10-09 19:45:33 +00:00
|
|
|
XSetWMName(fDisplay, fWindow, &textproperty);
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window_unix::show() {
|
2016-05-27 13:47:08 +00:00
|
|
|
XMapWindow(fDisplay, fWindow);
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
bool Window_unix::attach(BackendType attachType) {
|
2019-03-25 17:42:33 +00:00
|
|
|
fBackend = attachType;
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
this->initWindow(fDisplay);
|
2016-05-27 13:47:08 +00:00
|
|
|
|
2016-07-26 19:56:32 +00:00
|
|
|
window_context_factory::XlibWindowInfo winInfo;
|
|
|
|
winInfo.fDisplay = fDisplay;
|
|
|
|
winInfo.fWindow = fWindow;
|
2017-03-08 15:50:21 +00:00
|
|
|
winInfo.fFBConfig = fFBConfig;
|
2016-07-26 19:56:32 +00:00
|
|
|
winInfo.fVisualInfo = fVisualInfo;
|
2017-02-24 20:22:53 +00:00
|
|
|
|
|
|
|
XWindowAttributes attrs;
|
|
|
|
if (XGetWindowAttributes(fDisplay, fWindow, &attrs)) {
|
|
|
|
winInfo.fWidth = attrs.width;
|
|
|
|
winInfo.fHeight = attrs.height;
|
|
|
|
} else {
|
|
|
|
winInfo.fWidth = winInfo.fHeight = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
switch (attachType) {
|
2019-08-02 19:04:52 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
case kDawn_BackendType:
|
|
|
|
fWindowContext =
|
|
|
|
window_context_factory::MakeDawnVulkanForXlib(winInfo, fRequestedDisplayParams);
|
|
|
|
break;
|
|
|
|
#endif
|
2016-06-17 16:29:14 +00:00
|
|
|
#ifdef SK_VULKAN
|
2016-05-23 20:13:36 +00:00
|
|
|
case kVulkan_BackendType:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext =
|
|
|
|
window_context_factory::MakeVulkanForXlib(winInfo, fRequestedDisplayParams);
|
2016-05-27 12:47:00 +00:00
|
|
|
break;
|
2016-06-17 16:29:14 +00:00
|
|
|
#endif
|
2016-05-27 13:47:08 +00:00
|
|
|
case kNativeGL_BackendType:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext =
|
|
|
|
window_context_factory::MakeGLForXlib(winInfo, fRequestedDisplayParams);
|
2016-07-26 19:56:32 +00:00
|
|
|
break;
|
|
|
|
case kRaster_BackendType:
|
2019-08-01 20:21:49 +00:00
|
|
|
fWindowContext =
|
|
|
|
window_context_factory::MakeRasterForXlib(winInfo, fRequestedDisplayParams);
|
2016-05-27 13:47:08 +00:00
|
|
|
break;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2017-02-24 20:22:53 +00:00
|
|
|
this->onBackendCreated();
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
return (SkToBool(fWindowContext));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_unix::onInval() {
|
|
|
|
XEvent event;
|
|
|
|
event.type = Expose;
|
|
|
|
event.xexpose.send_event = True;
|
|
|
|
event.xexpose.display = fDisplay;
|
2016-05-27 13:47:08 +00:00
|
|
|
event.xexpose.window = fWindow;
|
2016-05-23 20:13:36 +00:00
|
|
|
event.xexpose.x = 0;
|
|
|
|
event.xexpose.y = 0;
|
2017-02-24 20:22:53 +00:00
|
|
|
event.xexpose.width = this->width();
|
|
|
|
event.xexpose.height = this->height();
|
2016-05-23 20:13:36 +00:00
|
|
|
event.xexpose.count = 0;
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2016-05-27 13:47:08 +00:00
|
|
|
XSendEvent(fDisplay, fWindow, False, 0, &event);
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 17:42:33 +00:00
|
|
|
void Window_unix::setRequestedDisplayParams(const DisplayParams& params, bool allowReattach) {
|
|
|
|
#if defined(SK_VULKAN)
|
|
|
|
// Vulkan on unix crashes if we try to reinitialize the vulkan context without remaking the
|
|
|
|
// window.
|
|
|
|
if (fBackend == kVulkan_BackendType && allowReattach) {
|
|
|
|
// Need to change these early, so attach() creates the window context correctly
|
|
|
|
fRequestedDisplayParams = params;
|
|
|
|
|
|
|
|
this->detach();
|
|
|
|
this->attach(fBackend);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
INHERITED::setRequestedDisplayParams(params, allowReattach);
|
|
|
|
}
|
|
|
|
|
2016-05-23 20:13:36 +00:00
|
|
|
} // namespace sk_app
|