| Index: tools/viewer/sk_app/unix/Window_unix.cpp
|
| diff --git a/tools/viewer/sk_app/unix/Window_unix.cpp b/tools/viewer/sk_app/unix/Window_unix.cpp
|
| index 431f1564911d5b752c91cc4ecbf6c1256b550c21..953eb36d74413ea41568de340883f28f6e7e43e5 100644
|
| --- a/tools/viewer/sk_app/unix/Window_unix.cpp
|
| +++ b/tools/viewer/sk_app/unix/Window_unix.cpp
|
| @@ -9,7 +9,6 @@
|
|
|
| #include "SkUtils.h"
|
| #include "Timer.h"
|
| -#include "../GLWindowContext.h"
|
| #include "../VulkanWindowContext.h"
|
| #include "Window_unix.h"
|
|
|
| @@ -27,7 +26,7 @@
|
| Display* display = (Display*)platformData;
|
|
|
| Window_unix* window = new Window_unix();
|
| - if (!window->initWindow(display, nullptr)) {
|
| + if (!window->init(display)) {
|
| delete window;
|
| return nullptr;
|
| }
|
| @@ -35,87 +34,27 @@
|
| return window;
|
| }
|
|
|
| -const long kEventMask = ExposureMask | StructureNotifyMask |
|
| - KeyPressMask | KeyReleaseMask |
|
| - PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
| -
|
| -bool Window_unix::initWindow(Display* display, const DisplayParams* params) {
|
| - if (params && params->fMSAASampleCount != fMSAASampleCount) {
|
| - this->closeWindow();
|
| - }
|
| - // we already have a window
|
| - if (fDisplay) {
|
| - return true;
|
| - }
|
| +bool Window_unix::init(Display* display) {
|
| fDisplay = display;
|
|
|
| fWidth = 1280;
|
| fHeight = 960;
|
| -
|
| - // Attempt to create a window that supports GL
|
| - GLint att[] = {
|
| - GLX_RGBA,
|
| - GLX_DEPTH_SIZE, 24,
|
| - GLX_DOUBLEBUFFER,
|
| - GLX_STENCIL_SIZE, 8,
|
| - None
|
| - };
|
| - SkASSERT(nullptr == fVisualInfo);
|
| - if (params && params->fMSAASampleCount > 0) {
|
| - static const GLint kAttCount = SK_ARRAY_COUNT(att);
|
| - GLint msaaAtt[kAttCount + 4];
|
| - memcpy(msaaAtt, att, sizeof(att));
|
| - SkASSERT(None == msaaAtt[kAttCount - 1]);
|
| - msaaAtt[kAttCount - 1] = GLX_SAMPLE_BUFFERS_ARB;
|
| - msaaAtt[kAttCount + 0] = 1;
|
| - msaaAtt[kAttCount + 1] = GLX_SAMPLES_ARB;
|
| - msaaAtt[kAttCount + 2] = params->fMSAASampleCount;
|
| - msaaAtt[kAttCount + 3] = None;
|
| - fVisualInfo = glXChooseVisual(display, DefaultScreen(display), msaaAtt);
|
| - fMSAASampleCount = params->fMSAASampleCount;
|
| - }
|
| - if (nullptr == fVisualInfo) {
|
| - fVisualInfo = glXChooseVisual(display, DefaultScreen(display), att);
|
| - fMSAASampleCount = 0;
|
| - }
|
| -
|
| - 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
|
| - fWidth, fHeight,
|
| - 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
|
| - fWidth, fHeight,
|
| - 0, // border width
|
| - 0, // border value
|
| - 0); // background value
|
| - XSelectInput(display, fWindow, kEventMask);
|
| - }
|
| -
|
| - if (!fWindow) {
|
| + fHWnd = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, fWidth, fHeight,
|
| + 0, BlackPixel(display, DefaultScreen(display)),
|
| + BlackPixel(display, DefaultScreen(display)));
|
| +
|
| + if (!fHWnd) {
|
| return false;
|
| }
|
| +
|
| + // choose the events we care about
|
| + XSelectInput(display, fHWnd,
|
| + ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask |
|
| + PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
|
|
|
| // set up to catch window delete message
|
| fWmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
| - XSetWMProtocols(display, fWindow, &fWmDeleteMessage, 1);
|
| + XSetWMProtocols(display, fHWnd, &fWmDeleteMessage, 1);
|
|
|
| // add to hashtable of windows
|
| gWindowMap.add(this);
|
| @@ -125,21 +64,6 @@
|
| fPendingResize = false;
|
|
|
| return true;
|
| -}
|
| -
|
| -void Window_unix::closeWindow() {
|
| - if (fDisplay) {
|
| - this->detach();
|
| - SkASSERT(fGC);
|
| - XFreeGC(fDisplay, fGC);
|
| - fGC = nullptr;
|
| - gWindowMap.remove(fWindow);
|
| - XDestroyWindow(fDisplay, fWindow);
|
| - fWindow = 0;
|
| - fVisualInfo = nullptr;
|
| - fDisplay = nullptr;
|
| - fMSAASampleCount = 0;
|
| - }
|
| }
|
|
|
| static Window::Key get_key(KeySym keysym) {
|
| @@ -184,12 +108,6 @@
|
|
|
| bool Window_unix::handleEvent(const XEvent& event) {
|
| switch (event.type) {
|
| - case MapNotify:
|
| - if (!fGC) {
|
| - fGC = XCreateGC(fDisplay, fWindow, 0, nullptr);
|
| - }
|
| - break;
|
| -
|
| case ClientMessage:
|
| if ((Atom)event.xclient.data.l[0] == fWmDeleteMessage &&
|
| gWindowMap.count() == 1) {
|
| @@ -261,28 +179,24 @@
|
| void Window_unix::setTitle(const char* title) {
|
| XTextProperty textproperty;
|
| XStringListToTextProperty(const_cast<char**>(&title), 1, &textproperty);
|
| - XSetWMName(fDisplay, fWindow, &textproperty);
|
| + XSetWMName(fDisplay, fHWnd, &textproperty);
|
| }
|
|
|
| void Window_unix::show() {
|
| - XMapWindow(fDisplay, fWindow);
|
| + XMapWindow(fDisplay, fHWnd);
|
| }
|
|
|
| bool Window_unix::attach(BackendType attachType, const DisplayParams& params) {
|
| - this->initWindow(fDisplay, ¶ms);
|
| -
|
| ContextPlatformData_unix platformData;
|
| platformData.fDisplay = fDisplay;
|
| - platformData.fWindow = fWindow;
|
| - platformData.fVisualInfo = fVisualInfo;
|
| + platformData.fHWnd = fHWnd;
|
| + XWindowAttributes attribs;
|
| + XGetWindowAttributes(fDisplay, fHWnd, &attribs);
|
| + platformData.fVisualID = XVisualIDFromVisual(attribs.visual);
|
| switch (attachType) {
|
| case kVulkan_BackendType:
|
| + default:
|
| fWindowContext = VulkanWindowContext::Create((void*)&platformData, params);
|
| - break;
|
| -
|
| - case kNativeGL_BackendType:
|
| - default:
|
| - fWindowContext = GLWindowContext::Create((void*)&platformData, params);
|
| break;
|
| }
|
|
|
| @@ -294,14 +208,14 @@
|
| event.type = Expose;
|
| event.xexpose.send_event = True;
|
| event.xexpose.display = fDisplay;
|
| - event.xexpose.window = fWindow;
|
| + event.xexpose.window = fHWnd;
|
| event.xexpose.x = 0;
|
| event.xexpose.y = 0;
|
| event.xexpose.width = fWidth;
|
| event.xexpose.height = fHeight;
|
| event.xexpose.count = 0;
|
|
|
| - XSendEvent(fDisplay, fWindow, False, 0, &event);
|
| + XSendEvent(fDisplay, fHWnd, False, 0, &event);
|
| }
|
|
|
| } // namespace sk_app
|
|
|