bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | #include "SkTypes.h" |
| 9 | |
| 10 | #if defined(SK_BUILD_FOR_WIN) |
| 11 | |
| 12 | #include <GL/gl.h> |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 13 | #include <WindowsX.h> |
djsollen | 082a462 | 2014-11-14 07:21:29 -0800 | [diff] [blame] | 14 | #include "win/SkWGL.h" |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 15 | #include "SkWindow.h" |
| 16 | #include "SkCanvas.h" |
| 17 | #include "SkOSMenu.h" |
| 18 | #include "SkTime.h" |
| 19 | #include "SkUtils.h" |
| 20 | |
| 21 | #include "SkGraphics.h" |
| 22 | |
| 23 | #if SK_ANGLE |
bsalomon | 4238017 | 2015-02-23 08:57:23 -0800 | [diff] [blame] | 24 | #include "gl/angle/SkANGLEGLContext.h" |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 25 | #include "gl/GrGLInterface.h" |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 26 | #include "GLES2/gl2.h" |
borenet@google.com | 0dd5ceb | 2012-08-28 15:15:49 +0000 | [diff] [blame] | 27 | |
| 28 | #define ANGLE_GL_CALL(IFACE, X) \ |
| 29 | do { \ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 30 | (IFACE)->fFunctions.f##X; \ |
borenet@google.com | 0dd5ceb | 2012-08-28 15:15:49 +0000 | [diff] [blame] | 31 | } while (false) |
| 32 | |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 33 | #endif // SK_ANGLE |
| 34 | |
| 35 | #if SK_COMMAND_BUFFER |
| 36 | #include "gl/command_buffer/SkCommandBufferGLContext.h" |
| 37 | |
| 38 | #define COMMAND_BUFFER_GL_CALL(IFACE, X) \ |
| 39 | do { \ |
| 40 | (IFACE)->fFunctions.f##X; \ |
| 41 | } while (false) |
| 42 | |
| 43 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 44 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 45 | #define WM_EVENT_CALLBACK (WM_USER+0) |
| 46 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 47 | void post_skwinevent(HWND hwnd) |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 48 | { |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 49 | PostMessage(hwnd, WM_EVENT_CALLBACK, 0, 0); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 52 | SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap; |
| 53 | |
| 54 | SkOSWindow::SkOSWindow(const void* winInit) { |
| 55 | fWinInit = *(const WindowInit*)winInit; |
| 56 | |
| 57 | fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW, |
| 58 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, fWinInit.fInstance, NULL); |
| 59 | gHwndToOSWindowMap.set(fHWND, this); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 60 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 61 | #if SK_ANGLE |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 62 | fDisplay = EGL_NO_DISPLAY; |
| 63 | fContext = EGL_NO_CONTEXT; |
| 64 | fSurface = EGL_NO_SURFACE; |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 65 | #endif |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 66 | #if SK_COMMAND_BUFFER |
| 67 | fCommandBuffer = nullptr; |
| 68 | #endif // SK_COMMAND_BUFFER |
| 69 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 70 | fHGLRC = NULL; |
| 71 | #endif |
| 72 | fAttached = kNone_BackEndType; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 73 | fFullscreen = false; |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | SkOSWindow::~SkOSWindow() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 77 | #if SK_SUPPORT_GPU |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 78 | if (fHGLRC) { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 79 | wglDeleteContext((HGLRC)fHGLRC); |
| 80 | } |
| 81 | #if SK_ANGLE |
| 82 | if (EGL_NO_CONTEXT != fContext) { |
| 83 | eglDestroyContext(fDisplay, fContext); |
| 84 | fContext = EGL_NO_CONTEXT; |
| 85 | } |
| 86 | |
| 87 | if (EGL_NO_SURFACE != fSurface) { |
| 88 | eglDestroySurface(fDisplay, fSurface); |
| 89 | fSurface = EGL_NO_SURFACE; |
| 90 | } |
| 91 | |
| 92 | if (EGL_NO_DISPLAY != fDisplay) { |
| 93 | eglTerminate(fDisplay); |
| 94 | fDisplay = EGL_NO_DISPLAY; |
| 95 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 96 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 97 | #if SK_COMMAND_BUFFER |
| 98 | delete fCommandBuffer; |
| 99 | #endif // SK_COMMAND_BUFFER |
| 100 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 101 | #endif // SK_SUPPORT_GPU |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 102 | this->closeWindow(); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static SkKey winToskKey(WPARAM vk) { |
| 106 | static const struct { |
| 107 | WPARAM fVK; |
| 108 | SkKey fKey; |
| 109 | } gPair[] = { |
| 110 | { VK_BACK, kBack_SkKey }, |
| 111 | { VK_CLEAR, kBack_SkKey }, |
| 112 | { VK_RETURN, kOK_SkKey }, |
| 113 | { VK_UP, kUp_SkKey }, |
| 114 | { VK_DOWN, kDown_SkKey }, |
| 115 | { VK_LEFT, kLeft_SkKey }, |
| 116 | { VK_RIGHT, kRight_SkKey } |
| 117 | }; |
| 118 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) { |
| 119 | if (gPair[i].fVK == vk) { |
| 120 | return gPair[i].fKey; |
| 121 | } |
| 122 | } |
| 123 | return kNONE_SkKey; |
| 124 | } |
| 125 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 126 | static unsigned getModifiers(UINT message) { |
| 127 | return 0; // TODO |
| 128 | } |
| 129 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 130 | bool SkOSWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
| 131 | switch (message) { |
| 132 | case WM_KEYDOWN: { |
| 133 | SkKey key = winToskKey(wParam); |
| 134 | if (kNONE_SkKey != key) { |
| 135 | this->handleKey(key); |
| 136 | return true; |
| 137 | } |
| 138 | } break; |
| 139 | case WM_KEYUP: { |
| 140 | SkKey key = winToskKey(wParam); |
| 141 | if (kNONE_SkKey != key) { |
| 142 | this->handleKeyUp(key); |
| 143 | return true; |
| 144 | } |
| 145 | } break; |
| 146 | case WM_UNICHAR: |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 147 | this->handleChar((SkUnichar) wParam); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 148 | return true; |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 149 | case WM_CHAR: { |
| 150 | this->handleChar(SkUTF8_ToUnichar((char*)&wParam)); |
| 151 | return true; |
| 152 | } break; |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 153 | case WM_SIZE: { |
| 154 | INT width = LOWORD(lParam); |
| 155 | INT height = HIWORD(lParam); |
| 156 | this->resize(width, height); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 157 | break; |
robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 158 | } |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 159 | case WM_PAINT: { |
| 160 | PAINTSTRUCT ps; |
| 161 | HDC hdc = BeginPaint(hWnd, &ps); |
| 162 | this->doPaint(hdc); |
| 163 | EndPaint(hWnd, &ps); |
| 164 | return true; |
| 165 | } break; |
| 166 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 167 | case WM_LBUTTONDOWN: |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 168 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
reed@google.com | 72708fa | 2013-01-08 16:22:44 +0000 | [diff] [blame] | 169 | Click::kDown_State, NULL, getModifiers(message)); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 170 | return true; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 171 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 172 | case WM_MOUSEMOVE: |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 173 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
reed@google.com | 72708fa | 2013-01-08 16:22:44 +0000 | [diff] [blame] | 174 | Click::kMoved_State, NULL, getModifiers(message)); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 175 | return true; |
| 176 | |
| 177 | case WM_LBUTTONUP: |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 178 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
reed@google.com | 72708fa | 2013-01-08 16:22:44 +0000 | [diff] [blame] | 179 | Click::kUp_State, NULL, getModifiers(message)); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 180 | return true; |
| 181 | |
| 182 | case WM_EVENT_CALLBACK: |
| 183 | if (SkEvent::ProcessEvent()) { |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 184 | post_skwinevent(hWnd); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | void SkOSWindow::doPaint(void* ctx) { |
| 192 | this->update(NULL); |
| 193 | |
| 194 | if (kNone_BackEndType == fAttached) |
| 195 | { |
| 196 | HDC hdc = (HDC)ctx; |
| 197 | const SkBitmap& bitmap = this->getBitmap(); |
| 198 | |
| 199 | BITMAPINFO bmi; |
| 200 | memset(&bmi, 0, sizeof(bmi)); |
| 201 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 202 | bmi.bmiHeader.biWidth = bitmap.width(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 203 | bmi.bmiHeader.biHeight = -bitmap.height(); // top-down image |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 204 | bmi.bmiHeader.biPlanes = 1; |
| 205 | bmi.bmiHeader.biBitCount = 32; |
| 206 | bmi.bmiHeader.biCompression = BI_RGB; |
| 207 | bmi.bmiHeader.biSizeImage = 0; |
| 208 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 209 | // |
| 210 | // Do the SetDIBitsToDevice. |
| 211 | // |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 212 | // TODO(wjmaclean): |
| 213 | // Fix this call to handle SkBitmaps that have rowBytes != width, |
| 214 | // i.e. may have padding at the end of lines. The SkASSERT below |
| 215 | // may be ignored by builds, and the only obviously safe option |
| 216 | // seems to be to copy the bitmap to a temporary (contiguous) |
| 217 | // buffer before passing to SetDIBitsToDevice(). |
| 218 | SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes()); |
| 219 | bitmap.lockPixels(); |
bsalomon@google.com | b58a639 | 2013-03-21 20:29:05 +0000 | [diff] [blame] | 220 | int ret = SetDIBitsToDevice(hdc, |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 221 | 0, 0, |
| 222 | bitmap.width(), bitmap.height(), |
| 223 | 0, 0, |
| 224 | 0, bitmap.height(), |
| 225 | bitmap.getPixels(), |
| 226 | &bmi, |
| 227 | DIB_RGB_COLORS); |
bsalomon@google.com | b58a639 | 2013-03-21 20:29:05 +0000 | [diff] [blame] | 228 | (void)ret; // we're ignoring potential failures for now. |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 229 | bitmap.unlockPixels(); |
| 230 | } |
| 231 | } |
| 232 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 233 | void SkOSWindow::updateSize() |
| 234 | { |
| 235 | RECT r; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 236 | GetWindowRect((HWND)fHWND, &r); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 237 | this->resize(r.right - r.left, r.bottom - r.top); |
| 238 | } |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 239 | |
| 240 | void SkOSWindow::onHandleInval(const SkIRect& r) { |
bsalomon | e0ef4a7 | 2015-06-15 12:49:55 -0700 | [diff] [blame] | 241 | RECT rect; |
| 242 | rect.left = r.fLeft; |
| 243 | rect.top = r.fTop; |
| 244 | rect.right = r.fRight; |
| 245 | rect.bottom = r.fBottom; |
| 246 | InvalidateRect((HWND)fHWND, &rect, FALSE); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu) |
| 250 | { |
| 251 | } |
| 252 | |
| 253 | void SkOSWindow::onSetTitle(const char title[]){ |
| 254 | SetWindowTextA((HWND)fHWND, title); |
| 255 | } |
| 256 | |
| 257 | enum { |
| 258 | SK_MacReturnKey = 36, |
| 259 | SK_MacDeleteKey = 51, |
| 260 | SK_MacEndKey = 119, |
| 261 | SK_MacLeftKey = 123, |
| 262 | SK_MacRightKey = 124, |
| 263 | SK_MacDownKey = 125, |
| 264 | SK_MacUpKey = 126, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 265 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 266 | SK_Mac0Key = 0x52, |
| 267 | SK_Mac1Key = 0x53, |
| 268 | SK_Mac2Key = 0x54, |
| 269 | SK_Mac3Key = 0x55, |
| 270 | SK_Mac4Key = 0x56, |
| 271 | SK_Mac5Key = 0x57, |
| 272 | SK_Mac6Key = 0x58, |
| 273 | SK_Mac7Key = 0x59, |
| 274 | SK_Mac8Key = 0x5b, |
| 275 | SK_Mac9Key = 0x5c |
| 276 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 277 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 278 | static SkKey raw2key(uint32_t raw) |
| 279 | { |
| 280 | static const struct { |
| 281 | uint32_t fRaw; |
| 282 | SkKey fKey; |
| 283 | } gKeys[] = { |
| 284 | { SK_MacUpKey, kUp_SkKey }, |
| 285 | { SK_MacDownKey, kDown_SkKey }, |
| 286 | { SK_MacLeftKey, kLeft_SkKey }, |
| 287 | { SK_MacRightKey, kRight_SkKey }, |
| 288 | { SK_MacReturnKey, kOK_SkKey }, |
| 289 | { SK_MacDeleteKey, kBack_SkKey }, |
| 290 | { SK_MacEndKey, kEnd_SkKey }, |
| 291 | { SK_Mac0Key, k0_SkKey }, |
| 292 | { SK_Mac1Key, k1_SkKey }, |
| 293 | { SK_Mac2Key, k2_SkKey }, |
| 294 | { SK_Mac3Key, k3_SkKey }, |
| 295 | { SK_Mac4Key, k4_SkKey }, |
| 296 | { SK_Mac5Key, k5_SkKey }, |
| 297 | { SK_Mac6Key, k6_SkKey }, |
| 298 | { SK_Mac7Key, k7_SkKey }, |
| 299 | { SK_Mac8Key, k8_SkKey }, |
| 300 | { SK_Mac9Key, k9_SkKey } |
| 301 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 302 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 303 | for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++) |
| 304 | if (gKeys[i].fRaw == raw) |
| 305 | return gKeys[i].fKey; |
| 306 | return kNONE_SkKey; |
| 307 | } |
| 308 | |
| 309 | /////////////////////////////////////////////////////////////////////////////////////// |
| 310 | |
| 311 | void SkEvent::SignalNonEmptyQueue() |
| 312 | { |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 313 | SkOSWindow::ForAllWindows([](void* hWND, SkOSWindow**) { |
| 314 | post_skwinevent((HWND)hWND); |
| 315 | }); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static UINT_PTR gTimer; |
| 319 | |
| 320 | VOID CALLBACK sk_timer_proc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
| 321 | { |
| 322 | SkEvent::ServiceQueueTimer(); |
| 323 | //SkDebugf("timer task fired\n"); |
| 324 | } |
| 325 | |
| 326 | void SkEvent::SignalQueueTimer(SkMSec delay) |
| 327 | { |
| 328 | if (gTimer) |
| 329 | { |
| 330 | KillTimer(NULL, gTimer); |
| 331 | gTimer = NULL; |
| 332 | } |
| 333 | if (delay) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 334 | { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 335 | gTimer = SetTimer(NULL, 0, delay, sk_timer_proc); |
| 336 | //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer); |
| 337 | } |
| 338 | } |
| 339 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 340 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 341 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 342 | bool SkOSWindow::attachGL(int msaaSampleCount, AttachmentInfo* info) { |
bsalomon@google.com | b7f20f2 | 2013-03-05 19:13:09 +0000 | [diff] [blame] | 343 | HDC dc = GetDC((HWND)fHWND); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 344 | if (NULL == fHGLRC) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 345 | fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, |
| 346 | kGLPreferCompatibilityProfile_SkWGLContextRequest); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 347 | if (NULL == fHGLRC) { |
| 348 | return false; |
| 349 | } |
| 350 | glClearStencil(0); |
| 351 | glClearColor(0, 0, 0, 0); |
| 352 | glStencilMask(0xffffffff); |
| 353 | glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
| 354 | } |
bsalomon@google.com | b7f20f2 | 2013-03-05 19:13:09 +0000 | [diff] [blame] | 355 | if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) { |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 356 | // use DescribePixelFormat to get the stencil bit depth. |
| 357 | int pixelFormat = GetPixelFormat(dc); |
| 358 | PIXELFORMATDESCRIPTOR pfd; |
| 359 | DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd); |
| 360 | info->fStencilBits = pfd.cStencilBits; |
| 361 | |
| 362 | // Get sample count if the MSAA WGL extension is present |
| 363 | SkWGLExtensions extensions; |
| 364 | if (extensions.hasExtension(dc, "WGL_ARB_multisample")) { |
| 365 | static const int kSampleCountAttr = SK_WGL_SAMPLES; |
| 366 | extensions.getPixelFormatAttribiv(dc, |
| 367 | pixelFormat, |
| 368 | 0, |
| 369 | 1, |
| 370 | &kSampleCountAttr, |
| 371 | &info->fSampleCount); |
| 372 | } else { |
| 373 | info->fSampleCount = 0; |
| 374 | } |
| 375 | |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 376 | glViewport(0, 0, |
| 377 | SkScalarRoundToInt(this->width()), |
| 378 | SkScalarRoundToInt(this->height())); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 379 | return true; |
| 380 | } |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | void SkOSWindow::detachGL() { |
| 385 | wglMakeCurrent(GetDC((HWND)fHWND), 0); |
| 386 | wglDeleteContext((HGLRC)fHGLRC); |
| 387 | fHGLRC = NULL; |
| 388 | } |
| 389 | |
| 390 | void SkOSWindow::presentGL() { |
bungeman@google.com | f44957e | 2013-03-12 17:27:10 +0000 | [diff] [blame] | 391 | HDC dc = GetDC((HWND)fHWND); |
| 392 | SwapBuffers(dc); |
| 393 | ReleaseDC((HWND)fHWND, dc); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | #if SK_ANGLE |
bsalomon | 4238017 | 2015-02-23 08:57:23 -0800 | [diff] [blame] | 397 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 398 | bool create_ANGLE(EGLNativeWindowType hWnd, |
| 399 | int msaaSampleCount, |
| 400 | EGLDisplay* eglDisplay, |
| 401 | EGLContext* eglContext, |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 402 | EGLSurface* eglSurface, |
| 403 | EGLConfig* eglConfig) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 404 | static const EGLint contextAttribs[] = { |
| 405 | EGL_CONTEXT_CLIENT_VERSION, 2, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 406 | EGL_NONE, EGL_NONE |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 407 | }; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 408 | static const EGLint configAttribList[] = { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 409 | EGL_RED_SIZE, 8, |
| 410 | EGL_GREEN_SIZE, 8, |
| 411 | EGL_BLUE_SIZE, 8, |
| 412 | EGL_ALPHA_SIZE, 8, |
| 413 | EGL_DEPTH_SIZE, 8, |
| 414 | EGL_STENCIL_SIZE, 8, |
| 415 | EGL_NONE |
| 416 | }; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 417 | static const EGLint surfaceAttribList[] = { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 418 | EGL_NONE, EGL_NONE |
| 419 | }; |
| 420 | |
hendrikw | eddbefb | 2015-09-11 13:07:29 -0700 | [diff] [blame^] | 421 | EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd), false); |
bsalomon | 4238017 | 2015-02-23 08:57:23 -0800 | [diff] [blame] | 422 | |
| 423 | if (EGL_NO_DISPLAY == display) { |
| 424 | SkDebugf("Could not create ANGLE egl display!\n"); |
| 425 | return false; |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // Initialize EGL |
| 429 | EGLint majorVersion, minorVersion; |
| 430 | if (!eglInitialize(display, &majorVersion, &minorVersion)) { |
| 431 | return false; |
| 432 | } |
| 433 | |
| 434 | EGLint numConfigs; |
| 435 | if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | // Choose config |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 440 | bool foundConfig = false; |
| 441 | if (msaaSampleCount) { |
| 442 | static const int kConfigAttribListCnt = |
| 443 | SK_ARRAY_COUNT(configAttribList); |
| 444 | EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; |
| 445 | memcpy(msaaConfigAttribList, |
| 446 | configAttribList, |
| 447 | sizeof(configAttribList)); |
| 448 | SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); |
| 449 | msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; |
| 450 | msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; |
| 451 | msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; |
| 452 | msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; |
| 453 | msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; |
hendrikw | 1512029 | 2015-09-08 05:53:23 -0700 | [diff] [blame] | 454 | if (eglChooseConfig(display, msaaConfigAttribList, eglConfig, 1, &numConfigs)) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 455 | SkASSERT(numConfigs > 0); |
| 456 | foundConfig = true; |
| 457 | } |
| 458 | } |
| 459 | if (!foundConfig) { |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 460 | if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 461 | return false; |
| 462 | } |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // Create a surface |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 466 | EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 467 | (EGLNativeWindowType)hWnd, |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 468 | surfaceAttribList); |
| 469 | if (surface == EGL_NO_SURFACE) { |
| 470 | return false; |
| 471 | } |
| 472 | |
| 473 | // Create a GL context |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 474 | EGLContext context = eglCreateContext(display, *eglConfig, |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 475 | EGL_NO_CONTEXT, |
| 476 | contextAttribs ); |
| 477 | if (context == EGL_NO_CONTEXT ) { |
| 478 | return false; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 479 | } |
| 480 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 481 | // Make the context current |
| 482 | if (!eglMakeCurrent(display, surface, surface, context)) { |
| 483 | return false; |
| 484 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 485 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 486 | *eglDisplay = display; |
| 487 | *eglContext = context; |
| 488 | *eglSurface = surface; |
| 489 | return true; |
| 490 | } |
| 491 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 492 | bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 493 | if (EGL_NO_DISPLAY == fDisplay) { |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 494 | bool bResult = create_ANGLE((HWND)fHWND, |
| 495 | msaaSampleCount, |
| 496 | &fDisplay, |
| 497 | &fContext, |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 498 | &fSurface, |
| 499 | &fConfig); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 500 | if (false == bResult) { |
| 501 | return false; |
| 502 | } |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame] | 503 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 504 | |
| 505 | if (intf) { |
borenet@google.com | 0dd5ceb | 2012-08-28 15:15:49 +0000 | [diff] [blame] | 506 | ANGLE_GL_CALL(intf, ClearStencil(0)); |
| 507 | ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
| 508 | ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); |
| 509 | ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT)); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 513 | eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilBits); |
| 514 | eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); |
| 515 | |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame] | 516 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 517 | |
| 518 | if (intf ) { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 519 | ANGLE_GL_CALL(intf, Viewport(0, 0, |
| 520 | SkScalarRoundToInt(this->width()), |
| 521 | SkScalarRoundToInt(this->height()))); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 522 | } |
| 523 | return true; |
| 524 | } |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | void SkOSWindow::detachANGLE() { |
| 529 | eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT); |
| 530 | |
| 531 | eglDestroyContext(fDisplay, fContext); |
| 532 | fContext = EGL_NO_CONTEXT; |
| 533 | |
| 534 | eglDestroySurface(fDisplay, fSurface); |
| 535 | fSurface = EGL_NO_SURFACE; |
| 536 | |
| 537 | eglTerminate(fDisplay); |
| 538 | fDisplay = EGL_NO_DISPLAY; |
| 539 | } |
| 540 | |
| 541 | void SkOSWindow::presentANGLE() { |
bsalomon@google.com | 82502e2 | 2013-01-24 20:47:18 +0000 | [diff] [blame] | 542 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 543 | |
| 544 | if (intf) { |
borenet@google.com | 0dd5ceb | 2012-08-28 15:15:49 +0000 | [diff] [blame] | 545 | ANGLE_GL_CALL(intf, Flush()); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | eglSwapBuffers(fDisplay, fSurface); |
| 549 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 550 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 551 | |
| 552 | #if SK_COMMAND_BUFFER |
| 553 | |
| 554 | bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info) { |
| 555 | if (!fCommandBuffer) { |
| 556 | fCommandBuffer = SkCommandBufferGLContext::Create((HWND)fHWND, msaaSampleCount); |
| 557 | if (!fCommandBuffer) |
| 558 | return false; |
| 559 | |
| 560 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface()); |
| 561 | if (intf) { |
| 562 | COMMAND_BUFFER_GL_CALL(intf, ClearStencil(0)); |
| 563 | COMMAND_BUFFER_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
| 564 | COMMAND_BUFFER_GL_CALL(intf, StencilMask(0xffffffff)); |
| 565 | COMMAND_BUFFER_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT)); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if (fCommandBuffer->makeCurrent()) { |
| 570 | info->fStencilBits = fCommandBuffer->getStencilBits(); |
| 571 | info->fSampleCount = fCommandBuffer->getSampleCount(); |
| 572 | |
| 573 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface()); |
| 574 | |
| 575 | if (intf ) { |
| 576 | COMMAND_BUFFER_GL_CALL(intf, Viewport(0, 0, |
| 577 | SkScalarRoundToInt(this->width()), |
| 578 | SkScalarRoundToInt(this->height()))); |
| 579 | } |
| 580 | return true; |
| 581 | } |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | void SkOSWindow::detachCommandBuffer() { |
| 586 | delete fCommandBuffer; |
| 587 | fCommandBuffer = nullptr; |
| 588 | } |
| 589 | |
| 590 | void SkOSWindow::presentCommandBuffer() { |
| 591 | fCommandBuffer->presentCommandBuffer(); |
| 592 | } |
| 593 | #endif // SK_COMMAND_BUFFER |
| 594 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 595 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 596 | |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 597 | // return true on success |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 598 | bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo* info) { |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 599 | |
| 600 | // attach doubles as "windowResize" so we need to allo |
| 601 | // already bound states to pass through again |
| 602 | // TODO: split out the resize functionality |
| 603 | // SkASSERT(kNone_BackEndType == fAttached); |
| 604 | bool result = true; |
| 605 | |
| 606 | switch (attachType) { |
| 607 | case kNone_BackEndType: |
| 608 | // nothing to do |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 609 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 610 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 611 | case kNativeGL_BackEndType: |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 612 | result = attachGL(msaaSampleCount, info); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 613 | break; |
| 614 | #if SK_ANGLE |
| 615 | case kANGLE_BackEndType: |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 616 | result = attachANGLE(msaaSampleCount, info); |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 617 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 618 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 619 | #if SK_COMMAND_BUFFER |
| 620 | case kCommandBuffer_BackEndType: |
| 621 | result = attachCommandBuffer(msaaSampleCount, info); |
| 622 | break; |
| 623 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 624 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 625 | default: |
| 626 | SkASSERT(false); |
| 627 | result = false; |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | if (result) { |
| 632 | fAttached = attachType; |
| 633 | } |
| 634 | |
| 635 | return result; |
| 636 | } |
| 637 | |
| 638 | void SkOSWindow::detach() { |
| 639 | switch (fAttached) { |
| 640 | case kNone_BackEndType: |
| 641 | // nothing to do |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 642 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 643 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 644 | case kNativeGL_BackEndType: |
| 645 | detachGL(); |
| 646 | break; |
| 647 | #if SK_ANGLE |
| 648 | case kANGLE_BackEndType: |
| 649 | detachANGLE(); |
| 650 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 651 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 652 | #if SK_COMMAND_BUFFER |
| 653 | case kCommandBuffer_BackEndType: |
| 654 | detachCommandBuffer(); |
| 655 | break; |
| 656 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 657 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 658 | default: |
| 659 | SkASSERT(false); |
| 660 | break; |
| 661 | } |
| 662 | fAttached = kNone_BackEndType; |
| 663 | } |
| 664 | |
| 665 | void SkOSWindow::present() { |
| 666 | switch (fAttached) { |
| 667 | case kNone_BackEndType: |
| 668 | // nothing to do |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 669 | return; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 670 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 671 | case kNativeGL_BackEndType: |
| 672 | presentGL(); |
| 673 | break; |
| 674 | #if SK_ANGLE |
| 675 | case kANGLE_BackEndType: |
| 676 | presentANGLE(); |
| 677 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 678 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 679 | #if SK_COMMAND_BUFFER |
| 680 | case kCommandBuffer_BackEndType: |
| 681 | presentCommandBuffer(); |
| 682 | break; |
| 683 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 684 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 685 | default: |
| 686 | SkASSERT(false); |
| 687 | break; |
| 688 | } |
| 689 | } |
| 690 | |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 691 | bool SkOSWindow::makeFullscreen() { |
| 692 | if (fFullscreen) { |
| 693 | return true; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 694 | } |
| 695 | if (fHGLRC) { |
| 696 | this->detachGL(); |
| 697 | } |
| 698 | // This is hacked together from various sources on the web. It can certainly be improved and be |
| 699 | // made more robust. |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 700 | |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 701 | // Save current window/resolution information. We do this in case we ever implement switching |
| 702 | // back to windowed mode. |
| 703 | fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND)); |
| 704 | if (fSavedWindowState.fZoomed) { |
| 705 | SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0); |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 706 | } |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 707 | fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE); |
| 708 | fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE); |
| 709 | GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect); |
| 710 | DEVMODE currScreenSettings; |
| 711 | memset(&currScreenSettings,0,sizeof(currScreenSettings)); |
| 712 | currScreenSettings.dmSize = sizeof(currScreenSettings); |
| 713 | EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &currScreenSettings); |
| 714 | fSavedWindowState.fScreenWidth = currScreenSettings.dmPelsWidth; |
| 715 | fSavedWindowState.fScreenHeight = currScreenSettings.dmPelsHeight; |
| 716 | fSavedWindowState.fScreenBits = currScreenSettings.dmBitsPerPel; |
| 717 | fSavedWindowState.fHWND = fHWND; |
| 718 | |
| 719 | // Try different sizes to find an allowed setting? Use ChangeDisplaySettingsEx? |
| 720 | static const int kWidth = 1280; |
| 721 | static const int kHeight = 1024; |
| 722 | DEVMODE newScreenSettings; |
| 723 | memset(&newScreenSettings, 0, sizeof(newScreenSettings)); |
| 724 | newScreenSettings.dmSize = sizeof(newScreenSettings); |
| 725 | newScreenSettings.dmPelsWidth = kWidth; |
| 726 | newScreenSettings.dmPelsHeight = kHeight; |
| 727 | newScreenSettings.dmBitsPerPel = 32; |
| 728 | newScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
| 729 | if (ChangeDisplaySettings(&newScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
| 730 | return false; |
| 731 | } |
| 732 | RECT WindowRect; |
| 733 | WindowRect.left = 0; |
| 734 | WindowRect.right = kWidth; |
| 735 | WindowRect.top = 0; |
| 736 | WindowRect.bottom = kHeight; |
| 737 | ShowCursor(FALSE); |
| 738 | AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW); |
| 739 | HWND fsHWND = CreateWindowEx( |
| 740 | WS_EX_APPWINDOW, |
| 741 | fWinInit.fClass, |
| 742 | NULL, |
| 743 | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, |
| 744 | 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, |
| 745 | NULL, |
| 746 | NULL, |
| 747 | fWinInit.fInstance, |
| 748 | NULL |
| 749 | ); |
| 750 | if (!fsHWND) { |
| 751 | return false; |
| 752 | } |
| 753 | // Hide the old window and set the entry in the global mapping for this SkOSWindow to the |
| 754 | // new HWND. |
| 755 | ShowWindow((HWND)fHWND, SW_HIDE); |
| 756 | gHwndToOSWindowMap.remove(fHWND); |
| 757 | fHWND = fsHWND; |
| 758 | gHwndToOSWindowMap.set(fHWND, this); |
| 759 | this->updateSize(); |
| 760 | |
| 761 | fFullscreen = true; |
| 762 | return true; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void SkOSWindow::setVsync(bool enable) { |
| 766 | SkWGLExtensions wgl; |
| 767 | wgl.swapInterval(enable ? 1 : 0); |
| 768 | } |
| 769 | |
| 770 | void SkOSWindow::closeWindow() { |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 771 | DestroyWindow((HWND)fHWND); |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 772 | if (fFullscreen) { |
| 773 | DestroyWindow((HWND)fSavedWindowState.fHWND); |
| 774 | } |
| 775 | gHwndToOSWindowMap.remove(fHWND); |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 776 | } |
bsalomon@google.com | 2858b31 | 2012-04-02 20:44:38 +0000 | [diff] [blame] | 777 | #endif |