| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 //#include <tchar.h> | 8 //#include <tchar.h> |
| 9 | 9 |
| 10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
| 11 #include "Timer.h" | 11 #include "Timer.h" |
| 12 #include "../GLWindowContext.h" | 12 #include "../GLWindowContext.h" |
| 13 #ifdef SK_VULKAN | 13 #include "Window_mac.h" |
| 14 #include "../VulkanWindowContext.h" | |
| 15 #endif | |
| 16 #include "Window_unix.h" | |
| 17 | |
| 18 extern "C" { | |
| 19 #include "keysym2ucs.h" | |
| 20 } | |
| 21 #include <X11/Xutil.h> | |
| 22 #include <X11/XKBlib.h> | |
| 23 | 14 |
| 24 namespace sk_app { | 15 namespace sk_app { |
| 25 | 16 |
| 26 SkTDynamicHash<Window_unix, XWindow> Window_unix::gWindowMap; | |
| 27 | |
| 28 Window* Window::CreateNativeWindow(void* platformData) { | 17 Window* Window::CreateNativeWindow(void* platformData) { |
| 18 #if 0 |
| 19 // TODO: platform-specific window creation |
| 29 Display* display = (Display*)platformData; | 20 Display* display = (Display*)platformData; |
| 30 | 21 |
| 31 Window_unix* window = new Window_unix(); | 22 Window_mac* window = new Window_mac(); |
| 32 if (!window->initWindow(display, nullptr)) { | 23 if (!window->initWindow(display, nullptr)) { |
| 33 delete window; | 24 delete window; |
| 34 return nullptr; | 25 return nullptr; |
| 35 } | 26 } |
| 36 | 27 |
| 37 return window; | 28 return window; |
| 29 #else |
| 30 return nullptr; |
| 31 #endif |
| 38 } | 32 } |
| 33 |
| 34 #if 0 |
| 35 // TODO: Implement Mac window code |
| 39 | 36 |
| 40 const long kEventMask = ExposureMask | StructureNotifyMask | | 37 const long kEventMask = ExposureMask | StructureNotifyMask | |
| 41 KeyPressMask | KeyReleaseMask | | 38 KeyPressMask | KeyReleaseMask | |
| 42 PointerMotionMask | ButtonPressMask | ButtonReleaseMask; | 39 PointerMotionMask | ButtonPressMask | ButtonReleaseMask; |
| 43 | 40 |
| 44 bool Window_unix::initWindow(Display* display, const DisplayParams* params) { | 41 bool Window_mac::initWindow(Display* display, const DisplayParams* params) { |
| 45 if (params && params->fMSAASampleCount != fMSAASampleCount) { | 42 if (params && params->fMSAASampleCount != fMSAASampleCount) { |
| 46 this->closeWindow(); | 43 this->closeWindow(); |
| 47 } | 44 } |
| 48 // we already have a window | 45 // we already have a window |
| 49 if (fDisplay) { | 46 if (fDisplay) { |
| 50 return true; | 47 return true; |
| 51 } | 48 } |
| 52 fDisplay = display; | 49 fDisplay = display; |
| 53 | 50 |
| 54 fWidth = 1280; | 51 fWidth = 1280; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // add to hashtable of windows | 119 // add to hashtable of windows |
| 123 gWindowMap.add(this); | 120 gWindowMap.add(this); |
| 124 | 121 |
| 125 // init event variables | 122 // init event variables |
| 126 fPendingPaint = false; | 123 fPendingPaint = false; |
| 127 fPendingResize = false; | 124 fPendingResize = false; |
| 128 | 125 |
| 129 return true; | 126 return true; |
| 130 } | 127 } |
| 131 | 128 |
| 132 void Window_unix::closeWindow() { | 129 void Window_mac::closeWindow() { |
| 133 if (fDisplay) { | 130 if (fDisplay) { |
| 134 this->detach(); | 131 this->detach(); |
| 135 SkASSERT(fGC); | 132 SkASSERT(fGC); |
| 136 XFreeGC(fDisplay, fGC); | 133 XFreeGC(fDisplay, fGC); |
| 137 fGC = nullptr; | 134 fGC = nullptr; |
| 138 gWindowMap.remove(fWindow); | 135 gWindowMap.remove(fWindow); |
| 139 XDestroyWindow(fDisplay, fWindow); | 136 XDestroyWindow(fDisplay, fWindow); |
| 140 fWindow = 0; | 137 fWindow = 0; |
| 141 fVisualInfo = nullptr; | 138 fVisualInfo = nullptr; |
| 142 fDisplay = nullptr; | 139 fDisplay = nullptr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 174 |
| 178 auto modifiers = 0; | 175 auto modifiers = 0; |
| 179 for (size_t i = 0; i < SK_ARRAY_COUNT(gModifiers); ++i) { | 176 for (size_t i = 0; i < SK_ARRAY_COUNT(gModifiers); ++i) { |
| 180 if (event.xkey.state & gModifiers[i].fXMask) { | 177 if (event.xkey.state & gModifiers[i].fXMask) { |
| 181 modifiers |= gModifiers[i].fSkMask; | 178 modifiers |= gModifiers[i].fSkMask; |
| 182 } | 179 } |
| 183 } | 180 } |
| 184 return modifiers; | 181 return modifiers; |
| 185 } | 182 } |
| 186 | 183 |
| 187 bool Window_unix::handleEvent(const XEvent& event) { | 184 bool Window_mac::handleEvent(const XEvent& event) { |
| 188 switch (event.type) { | 185 switch (event.type) { |
| 189 case MapNotify: | 186 case MapNotify: |
| 190 if (!fGC) { | 187 if (!fGC) { |
| 191 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr); | 188 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr); |
| 192 } | 189 } |
| 193 break; | 190 break; |
| 194 | 191 |
| 195 case ClientMessage: | 192 case ClientMessage: |
| 196 if ((Atom)event.xclient.data.l[0] == fWmDeleteMessage && | 193 if ((Atom)event.xclient.data.l[0] == fWmDeleteMessage && |
| 197 gWindowMap.count() == 1) { | 194 gWindowMap.count() == 1) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 250 |
| 254 default: | 251 default: |
| 255 // these events should be handled in the main event loop | 252 // these events should be handled in the main event loop |
| 256 SkASSERT(event.type != Expose && event.type != ConfigureNotify); | 253 SkASSERT(event.type != Expose && event.type != ConfigureNotify); |
| 257 break; | 254 break; |
| 258 } | 255 } |
| 259 | 256 |
| 260 return false; | 257 return false; |
| 261 } | 258 } |
| 262 | 259 |
| 263 void Window_unix::setTitle(const char* title) { | 260 void Window_mac::setTitle(const char* title) { |
| 264 XTextProperty textproperty; | 261 XTextProperty textproperty; |
| 265 XStringListToTextProperty(const_cast<char**>(&title), 1, &textproperty); | 262 XStringListToTextProperty(const_cast<char**>(&title), 1, &textproperty); |
| 266 XSetWMName(fDisplay, fWindow, &textproperty); | 263 XSetWMName(fDisplay, fWindow, &textproperty); |
| 267 } | 264 } |
| 268 | 265 |
| 269 void Window_unix::show() { | 266 void Window_mac::show() { |
| 270 XMapWindow(fDisplay, fWindow); | 267 XMapWindow(fDisplay, fWindow); |
| 271 } | 268 } |
| 272 | 269 |
| 273 bool Window_unix::attach(BackendType attachType, const DisplayParams& params) { | 270 bool Window_mac::attach(BackendType attachType, const DisplayParams& params) { |
| 274 this->initWindow(fDisplay, ¶ms); | 271 this->initWindow(fDisplay, ¶ms); |
| 275 | 272 |
| 276 ContextPlatformData_unix platformData; | 273 ContextPlatformData_mac platformData; |
| 277 platformData.fDisplay = fDisplay; | 274 platformData.fDisplay = fDisplay; |
| 278 platformData.fWindow = fWindow; | 275 platformData.fWindow = fWindow; |
| 279 platformData.fVisualInfo = fVisualInfo; | 276 platformData.fVisualInfo = fVisualInfo; |
| 280 switch (attachType) { | 277 switch (attachType) { |
| 281 #ifdef SK_VULKAN | 278 #ifdef SK_VULKAN |
| 282 case kVulkan_BackendType: | 279 case kVulkan_BackendType: |
| 283 fWindowContext = VulkanWindowContext::Create((void*)&platformData, p
arams); | 280 fWindowContext = VulkanWindowContext::Create((void*)&platformData, p
arams); |
| 284 break; | 281 break; |
| 285 #endif | 282 #endif |
| 286 case kNativeGL_BackendType: | 283 case kNativeGL_BackendType: |
| 287 default: | 284 default: |
| 288 fWindowContext = GLWindowContext::Create((void*)&platformData, param
s); | 285 fWindowContext = GLWindowContext::Create((void*)&platformData, param
s); |
| 289 break; | 286 break; |
| 290 } | 287 } |
| 291 | 288 |
| 292 return (SkToBool(fWindowContext)); | 289 return (SkToBool(fWindowContext)); |
| 293 } | 290 } |
| 294 | 291 |
| 295 void Window_unix::onInval() { | 292 void Window_mac::onInval() { |
| 296 XEvent event; | 293 XEvent event; |
| 297 event.type = Expose; | 294 event.type = Expose; |
| 298 event.xexpose.send_event = True; | 295 event.xexpose.send_event = True; |
| 299 event.xexpose.display = fDisplay; | 296 event.xexpose.display = fDisplay; |
| 300 event.xexpose.window = fWindow; | 297 event.xexpose.window = fWindow; |
| 301 event.xexpose.x = 0; | 298 event.xexpose.x = 0; |
| 302 event.xexpose.y = 0; | 299 event.xexpose.y = 0; |
| 303 event.xexpose.width = fWidth; | 300 event.xexpose.width = fWidth; |
| 304 event.xexpose.height = fHeight; | 301 event.xexpose.height = fHeight; |
| 305 event.xexpose.count = 0; | 302 event.xexpose.count = 0; |
| 306 | 303 |
| 307 XSendEvent(fDisplay, fWindow, False, 0, &event); | 304 XSendEvent(fDisplay, fWindow, False, 0, &event); |
| 308 } | 305 } |
| 309 | 306 #endif |
| 307 |
| 310 } // namespace sk_app | 308 } // namespace sk_app |
| OLD | NEW |