Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "SkTypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #if defined(SK_BUILD_FOR_WIN) |
michael@0 | 11 | |
michael@0 | 12 | #include <GL/gl.h> |
michael@0 | 13 | #include <WindowsX.h> |
michael@0 | 14 | #include "SkWGL.h" |
michael@0 | 15 | #include "SkWindow.h" |
michael@0 | 16 | #include "SkCanvas.h" |
michael@0 | 17 | #include "SkOSMenu.h" |
michael@0 | 18 | #include "SkTime.h" |
michael@0 | 19 | #include "SkUtils.h" |
michael@0 | 20 | |
michael@0 | 21 | #include "SkGraphics.h" |
michael@0 | 22 | |
michael@0 | 23 | #if SK_ANGLE |
michael@0 | 24 | #include "gl/GrGLInterface.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "GLES2/gl2.h" |
michael@0 | 27 | |
michael@0 | 28 | #define ANGLE_GL_CALL(IFACE, X) \ |
michael@0 | 29 | do { \ |
michael@0 | 30 | (IFACE)->fFunctions.f##X; \ |
michael@0 | 31 | } while (false) |
michael@0 | 32 | |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | #define INVALIDATE_DELAY_MS 200 |
michael@0 | 36 | |
michael@0 | 37 | static SkOSWindow* gCurrOSWin; |
michael@0 | 38 | static HWND gEventTarget; |
michael@0 | 39 | |
michael@0 | 40 | #define WM_EVENT_CALLBACK (WM_USER+0) |
michael@0 | 41 | |
michael@0 | 42 | void post_skwinevent() |
michael@0 | 43 | { |
michael@0 | 44 | PostMessage(gEventTarget, WM_EVENT_CALLBACK, 0, 0); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | SkOSWindow::SkOSWindow(void* hWnd) { |
michael@0 | 48 | fHWND = hWnd; |
michael@0 | 49 | #if SK_SUPPORT_GPU |
michael@0 | 50 | #if SK_ANGLE |
michael@0 | 51 | fDisplay = EGL_NO_DISPLAY; |
michael@0 | 52 | fContext = EGL_NO_CONTEXT; |
michael@0 | 53 | fSurface = EGL_NO_SURFACE; |
michael@0 | 54 | #endif |
michael@0 | 55 | fHGLRC = NULL; |
michael@0 | 56 | #endif |
michael@0 | 57 | fAttached = kNone_BackEndType; |
michael@0 | 58 | gEventTarget = (HWND)hWnd; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | SkOSWindow::~SkOSWindow() { |
michael@0 | 62 | #if SK_SUPPORT_GPU |
michael@0 | 63 | if (NULL != fHGLRC) { |
michael@0 | 64 | wglDeleteContext((HGLRC)fHGLRC); |
michael@0 | 65 | } |
michael@0 | 66 | #if SK_ANGLE |
michael@0 | 67 | if (EGL_NO_CONTEXT != fContext) { |
michael@0 | 68 | eglDestroyContext(fDisplay, fContext); |
michael@0 | 69 | fContext = EGL_NO_CONTEXT; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | if (EGL_NO_SURFACE != fSurface) { |
michael@0 | 73 | eglDestroySurface(fDisplay, fSurface); |
michael@0 | 74 | fSurface = EGL_NO_SURFACE; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | if (EGL_NO_DISPLAY != fDisplay) { |
michael@0 | 78 | eglTerminate(fDisplay); |
michael@0 | 79 | fDisplay = EGL_NO_DISPLAY; |
michael@0 | 80 | } |
michael@0 | 81 | #endif // SK_ANGLE |
michael@0 | 82 | #endif // SK_SUPPORT_GPU |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | static SkKey winToskKey(WPARAM vk) { |
michael@0 | 86 | static const struct { |
michael@0 | 87 | WPARAM fVK; |
michael@0 | 88 | SkKey fKey; |
michael@0 | 89 | } gPair[] = { |
michael@0 | 90 | { VK_BACK, kBack_SkKey }, |
michael@0 | 91 | { VK_CLEAR, kBack_SkKey }, |
michael@0 | 92 | { VK_RETURN, kOK_SkKey }, |
michael@0 | 93 | { VK_UP, kUp_SkKey }, |
michael@0 | 94 | { VK_DOWN, kDown_SkKey }, |
michael@0 | 95 | { VK_LEFT, kLeft_SkKey }, |
michael@0 | 96 | { VK_RIGHT, kRight_SkKey } |
michael@0 | 97 | }; |
michael@0 | 98 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) { |
michael@0 | 99 | if (gPair[i].fVK == vk) { |
michael@0 | 100 | return gPair[i].fKey; |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | return kNONE_SkKey; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | static unsigned getModifiers(UINT message) { |
michael@0 | 107 | return 0; // TODO |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | bool SkOSWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
michael@0 | 111 | switch (message) { |
michael@0 | 112 | case WM_KEYDOWN: { |
michael@0 | 113 | SkKey key = winToskKey(wParam); |
michael@0 | 114 | if (kNONE_SkKey != key) { |
michael@0 | 115 | this->handleKey(key); |
michael@0 | 116 | return true; |
michael@0 | 117 | } |
michael@0 | 118 | } break; |
michael@0 | 119 | case WM_KEYUP: { |
michael@0 | 120 | SkKey key = winToskKey(wParam); |
michael@0 | 121 | if (kNONE_SkKey != key) { |
michael@0 | 122 | this->handleKeyUp(key); |
michael@0 | 123 | return true; |
michael@0 | 124 | } |
michael@0 | 125 | } break; |
michael@0 | 126 | case WM_UNICHAR: |
michael@0 | 127 | this->handleChar((SkUnichar) wParam); |
michael@0 | 128 | return true; |
michael@0 | 129 | case WM_CHAR: { |
michael@0 | 130 | this->handleChar(SkUTF8_ToUnichar((char*)&wParam)); |
michael@0 | 131 | return true; |
michael@0 | 132 | } break; |
michael@0 | 133 | case WM_SIZE: { |
michael@0 | 134 | INT width = LOWORD(lParam); |
michael@0 | 135 | INT height = HIWORD(lParam); |
michael@0 | 136 | this->resize(width, height); |
michael@0 | 137 | break; |
michael@0 | 138 | } |
michael@0 | 139 | case WM_PAINT: { |
michael@0 | 140 | PAINTSTRUCT ps; |
michael@0 | 141 | HDC hdc = BeginPaint(hWnd, &ps); |
michael@0 | 142 | this->doPaint(hdc); |
michael@0 | 143 | EndPaint(hWnd, &ps); |
michael@0 | 144 | return true; |
michael@0 | 145 | } break; |
michael@0 | 146 | |
michael@0 | 147 | case WM_TIMER: { |
michael@0 | 148 | RECT* rect = (RECT*)wParam; |
michael@0 | 149 | InvalidateRect(hWnd, rect, FALSE); |
michael@0 | 150 | KillTimer(hWnd, (UINT_PTR)rect); |
michael@0 | 151 | delete rect; |
michael@0 | 152 | return true; |
michael@0 | 153 | } break; |
michael@0 | 154 | |
michael@0 | 155 | case WM_LBUTTONDOWN: |
michael@0 | 156 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
michael@0 | 157 | Click::kDown_State, NULL, getModifiers(message)); |
michael@0 | 158 | return true; |
michael@0 | 159 | |
michael@0 | 160 | case WM_MOUSEMOVE: |
michael@0 | 161 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
michael@0 | 162 | Click::kMoved_State, NULL, getModifiers(message)); |
michael@0 | 163 | return true; |
michael@0 | 164 | |
michael@0 | 165 | case WM_LBUTTONUP: |
michael@0 | 166 | this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), |
michael@0 | 167 | Click::kUp_State, NULL, getModifiers(message)); |
michael@0 | 168 | return true; |
michael@0 | 169 | |
michael@0 | 170 | case WM_EVENT_CALLBACK: |
michael@0 | 171 | if (SkEvent::ProcessEvent()) { |
michael@0 | 172 | post_skwinevent(); |
michael@0 | 173 | } |
michael@0 | 174 | return true; |
michael@0 | 175 | } |
michael@0 | 176 | return false; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | void SkOSWindow::doPaint(void* ctx) { |
michael@0 | 180 | this->update(NULL); |
michael@0 | 181 | |
michael@0 | 182 | if (kNone_BackEndType == fAttached) |
michael@0 | 183 | { |
michael@0 | 184 | HDC hdc = (HDC)ctx; |
michael@0 | 185 | const SkBitmap& bitmap = this->getBitmap(); |
michael@0 | 186 | |
michael@0 | 187 | BITMAPINFO bmi; |
michael@0 | 188 | memset(&bmi, 0, sizeof(bmi)); |
michael@0 | 189 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
michael@0 | 190 | bmi.bmiHeader.biWidth = bitmap.width(); |
michael@0 | 191 | bmi.bmiHeader.biHeight = -bitmap.height(); // top-down image |
michael@0 | 192 | bmi.bmiHeader.biPlanes = 1; |
michael@0 | 193 | bmi.bmiHeader.biBitCount = 32; |
michael@0 | 194 | bmi.bmiHeader.biCompression = BI_RGB; |
michael@0 | 195 | bmi.bmiHeader.biSizeImage = 0; |
michael@0 | 196 | |
michael@0 | 197 | // |
michael@0 | 198 | // Do the SetDIBitsToDevice. |
michael@0 | 199 | // |
michael@0 | 200 | // TODO(wjmaclean): |
michael@0 | 201 | // Fix this call to handle SkBitmaps that have rowBytes != width, |
michael@0 | 202 | // i.e. may have padding at the end of lines. The SkASSERT below |
michael@0 | 203 | // may be ignored by builds, and the only obviously safe option |
michael@0 | 204 | // seems to be to copy the bitmap to a temporary (contiguous) |
michael@0 | 205 | // buffer before passing to SetDIBitsToDevice(). |
michael@0 | 206 | SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes()); |
michael@0 | 207 | bitmap.lockPixels(); |
michael@0 | 208 | int ret = SetDIBitsToDevice(hdc, |
michael@0 | 209 | 0, 0, |
michael@0 | 210 | bitmap.width(), bitmap.height(), |
michael@0 | 211 | 0, 0, |
michael@0 | 212 | 0, bitmap.height(), |
michael@0 | 213 | bitmap.getPixels(), |
michael@0 | 214 | &bmi, |
michael@0 | 215 | DIB_RGB_COLORS); |
michael@0 | 216 | (void)ret; // we're ignoring potential failures for now. |
michael@0 | 217 | bitmap.unlockPixels(); |
michael@0 | 218 | } |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | #if 0 |
michael@0 | 222 | void SkOSWindow::updateSize() |
michael@0 | 223 | { |
michael@0 | 224 | RECT r; |
michael@0 | 225 | GetWindowRect((HWND)this->getHWND(), &r); |
michael@0 | 226 | this->resize(r.right - r.left, r.bottom - r.top); |
michael@0 | 227 | } |
michael@0 | 228 | #endif |
michael@0 | 229 | |
michael@0 | 230 | void SkOSWindow::onHandleInval(const SkIRect& r) { |
michael@0 | 231 | RECT* rect = new RECT; |
michael@0 | 232 | rect->left = r.fLeft; |
michael@0 | 233 | rect->top = r.fTop; |
michael@0 | 234 | rect->right = r.fRight; |
michael@0 | 235 | rect->bottom = r.fBottom; |
michael@0 | 236 | SetTimer((HWND)fHWND, (UINT_PTR)rect, INVALIDATE_DELAY_MS, NULL); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu) |
michael@0 | 240 | { |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | void SkOSWindow::onSetTitle(const char title[]){ |
michael@0 | 244 | SetWindowTextA((HWND)fHWND, title); |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | enum { |
michael@0 | 248 | SK_MacReturnKey = 36, |
michael@0 | 249 | SK_MacDeleteKey = 51, |
michael@0 | 250 | SK_MacEndKey = 119, |
michael@0 | 251 | SK_MacLeftKey = 123, |
michael@0 | 252 | SK_MacRightKey = 124, |
michael@0 | 253 | SK_MacDownKey = 125, |
michael@0 | 254 | SK_MacUpKey = 126, |
michael@0 | 255 | |
michael@0 | 256 | SK_Mac0Key = 0x52, |
michael@0 | 257 | SK_Mac1Key = 0x53, |
michael@0 | 258 | SK_Mac2Key = 0x54, |
michael@0 | 259 | SK_Mac3Key = 0x55, |
michael@0 | 260 | SK_Mac4Key = 0x56, |
michael@0 | 261 | SK_Mac5Key = 0x57, |
michael@0 | 262 | SK_Mac6Key = 0x58, |
michael@0 | 263 | SK_Mac7Key = 0x59, |
michael@0 | 264 | SK_Mac8Key = 0x5b, |
michael@0 | 265 | SK_Mac9Key = 0x5c |
michael@0 | 266 | }; |
michael@0 | 267 | |
michael@0 | 268 | static SkKey raw2key(uint32_t raw) |
michael@0 | 269 | { |
michael@0 | 270 | static const struct { |
michael@0 | 271 | uint32_t fRaw; |
michael@0 | 272 | SkKey fKey; |
michael@0 | 273 | } gKeys[] = { |
michael@0 | 274 | { SK_MacUpKey, kUp_SkKey }, |
michael@0 | 275 | { SK_MacDownKey, kDown_SkKey }, |
michael@0 | 276 | { SK_MacLeftKey, kLeft_SkKey }, |
michael@0 | 277 | { SK_MacRightKey, kRight_SkKey }, |
michael@0 | 278 | { SK_MacReturnKey, kOK_SkKey }, |
michael@0 | 279 | { SK_MacDeleteKey, kBack_SkKey }, |
michael@0 | 280 | { SK_MacEndKey, kEnd_SkKey }, |
michael@0 | 281 | { SK_Mac0Key, k0_SkKey }, |
michael@0 | 282 | { SK_Mac1Key, k1_SkKey }, |
michael@0 | 283 | { SK_Mac2Key, k2_SkKey }, |
michael@0 | 284 | { SK_Mac3Key, k3_SkKey }, |
michael@0 | 285 | { SK_Mac4Key, k4_SkKey }, |
michael@0 | 286 | { SK_Mac5Key, k5_SkKey }, |
michael@0 | 287 | { SK_Mac6Key, k6_SkKey }, |
michael@0 | 288 | { SK_Mac7Key, k7_SkKey }, |
michael@0 | 289 | { SK_Mac8Key, k8_SkKey }, |
michael@0 | 290 | { SK_Mac9Key, k9_SkKey } |
michael@0 | 291 | }; |
michael@0 | 292 | |
michael@0 | 293 | for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++) |
michael@0 | 294 | if (gKeys[i].fRaw == raw) |
michael@0 | 295 | return gKeys[i].fKey; |
michael@0 | 296 | return kNONE_SkKey; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | /////////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 300 | |
michael@0 | 301 | void SkEvent::SignalNonEmptyQueue() |
michael@0 | 302 | { |
michael@0 | 303 | post_skwinevent(); |
michael@0 | 304 | //SkDebugf("signal nonempty\n"); |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | static UINT_PTR gTimer; |
michael@0 | 308 | |
michael@0 | 309 | VOID CALLBACK sk_timer_proc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
michael@0 | 310 | { |
michael@0 | 311 | SkEvent::ServiceQueueTimer(); |
michael@0 | 312 | //SkDebugf("timer task fired\n"); |
michael@0 | 313 | } |
michael@0 | 314 | |
michael@0 | 315 | void SkEvent::SignalQueueTimer(SkMSec delay) |
michael@0 | 316 | { |
michael@0 | 317 | if (gTimer) |
michael@0 | 318 | { |
michael@0 | 319 | KillTimer(NULL, gTimer); |
michael@0 | 320 | gTimer = NULL; |
michael@0 | 321 | } |
michael@0 | 322 | if (delay) |
michael@0 | 323 | { |
michael@0 | 324 | gTimer = SetTimer(NULL, 0, delay, sk_timer_proc); |
michael@0 | 325 | //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer); |
michael@0 | 326 | } |
michael@0 | 327 | } |
michael@0 | 328 | |
michael@0 | 329 | #if SK_SUPPORT_GPU |
michael@0 | 330 | |
michael@0 | 331 | bool SkOSWindow::attachGL(int msaaSampleCount, AttachmentInfo* info) { |
michael@0 | 332 | HDC dc = GetDC((HWND)fHWND); |
michael@0 | 333 | if (NULL == fHGLRC) { |
michael@0 | 334 | fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, false); |
michael@0 | 335 | if (NULL == fHGLRC) { |
michael@0 | 336 | return false; |
michael@0 | 337 | } |
michael@0 | 338 | glClearStencil(0); |
michael@0 | 339 | glClearColor(0, 0, 0, 0); |
michael@0 | 340 | glStencilMask(0xffffffff); |
michael@0 | 341 | glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
michael@0 | 342 | } |
michael@0 | 343 | if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) { |
michael@0 | 344 | // use DescribePixelFormat to get the stencil bit depth. |
michael@0 | 345 | int pixelFormat = GetPixelFormat(dc); |
michael@0 | 346 | PIXELFORMATDESCRIPTOR pfd; |
michael@0 | 347 | DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd); |
michael@0 | 348 | info->fStencilBits = pfd.cStencilBits; |
michael@0 | 349 | |
michael@0 | 350 | // Get sample count if the MSAA WGL extension is present |
michael@0 | 351 | SkWGLExtensions extensions; |
michael@0 | 352 | if (extensions.hasExtension(dc, "WGL_ARB_multisample")) { |
michael@0 | 353 | static const int kSampleCountAttr = SK_WGL_SAMPLES; |
michael@0 | 354 | extensions.getPixelFormatAttribiv(dc, |
michael@0 | 355 | pixelFormat, |
michael@0 | 356 | 0, |
michael@0 | 357 | 1, |
michael@0 | 358 | &kSampleCountAttr, |
michael@0 | 359 | &info->fSampleCount); |
michael@0 | 360 | } else { |
michael@0 | 361 | info->fSampleCount = 0; |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | glViewport(0, 0, |
michael@0 | 365 | SkScalarRoundToInt(this->width()), |
michael@0 | 366 | SkScalarRoundToInt(this->height())); |
michael@0 | 367 | return true; |
michael@0 | 368 | } |
michael@0 | 369 | return false; |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | void SkOSWindow::detachGL() { |
michael@0 | 373 | wglMakeCurrent(GetDC((HWND)fHWND), 0); |
michael@0 | 374 | wglDeleteContext((HGLRC)fHGLRC); |
michael@0 | 375 | fHGLRC = NULL; |
michael@0 | 376 | } |
michael@0 | 377 | |
michael@0 | 378 | void SkOSWindow::presentGL() { |
michael@0 | 379 | glFlush(); |
michael@0 | 380 | HDC dc = GetDC((HWND)fHWND); |
michael@0 | 381 | SwapBuffers(dc); |
michael@0 | 382 | ReleaseDC((HWND)fHWND, dc); |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | #if SK_ANGLE |
michael@0 | 386 | bool create_ANGLE(EGLNativeWindowType hWnd, |
michael@0 | 387 | int msaaSampleCount, |
michael@0 | 388 | EGLDisplay* eglDisplay, |
michael@0 | 389 | EGLContext* eglContext, |
michael@0 | 390 | EGLSurface* eglSurface, |
michael@0 | 391 | EGLConfig* eglConfig) { |
michael@0 | 392 | static const EGLint contextAttribs[] = { |
michael@0 | 393 | EGL_CONTEXT_CLIENT_VERSION, 2, |
michael@0 | 394 | EGL_NONE, EGL_NONE |
michael@0 | 395 | }; |
michael@0 | 396 | static const EGLint configAttribList[] = { |
michael@0 | 397 | EGL_RED_SIZE, 8, |
michael@0 | 398 | EGL_GREEN_SIZE, 8, |
michael@0 | 399 | EGL_BLUE_SIZE, 8, |
michael@0 | 400 | EGL_ALPHA_SIZE, 8, |
michael@0 | 401 | EGL_DEPTH_SIZE, 8, |
michael@0 | 402 | EGL_STENCIL_SIZE, 8, |
michael@0 | 403 | EGL_NONE |
michael@0 | 404 | }; |
michael@0 | 405 | static const EGLint surfaceAttribList[] = { |
michael@0 | 406 | EGL_NONE, EGL_NONE |
michael@0 | 407 | }; |
michael@0 | 408 | |
michael@0 | 409 | EGLDisplay display = eglGetDisplay(GetDC(hWnd)); |
michael@0 | 410 | if (display == EGL_NO_DISPLAY ) { |
michael@0 | 411 | return false; |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | // Initialize EGL |
michael@0 | 415 | EGLint majorVersion, minorVersion; |
michael@0 | 416 | if (!eglInitialize(display, &majorVersion, &minorVersion)) { |
michael@0 | 417 | return false; |
michael@0 | 418 | } |
michael@0 | 419 | |
michael@0 | 420 | EGLint numConfigs; |
michael@0 | 421 | if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { |
michael@0 | 422 | return false; |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | // Choose config |
michael@0 | 426 | bool foundConfig = false; |
michael@0 | 427 | if (msaaSampleCount) { |
michael@0 | 428 | static const int kConfigAttribListCnt = |
michael@0 | 429 | SK_ARRAY_COUNT(configAttribList); |
michael@0 | 430 | EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; |
michael@0 | 431 | memcpy(msaaConfigAttribList, |
michael@0 | 432 | configAttribList, |
michael@0 | 433 | sizeof(configAttribList)); |
michael@0 | 434 | SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); |
michael@0 | 435 | msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; |
michael@0 | 436 | msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; |
michael@0 | 437 | msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; |
michael@0 | 438 | msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; |
michael@0 | 439 | msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; |
michael@0 | 440 | if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { |
michael@0 | 441 | SkASSERT(numConfigs > 0); |
michael@0 | 442 | foundConfig = true; |
michael@0 | 443 | } |
michael@0 | 444 | } |
michael@0 | 445 | if (!foundConfig) { |
michael@0 | 446 | if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { |
michael@0 | 447 | return false; |
michael@0 | 448 | } |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | // Create a surface |
michael@0 | 452 | EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, |
michael@0 | 453 | (EGLNativeWindowType)hWnd, |
michael@0 | 454 | surfaceAttribList); |
michael@0 | 455 | if (surface == EGL_NO_SURFACE) { |
michael@0 | 456 | return false; |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | // Create a GL context |
michael@0 | 460 | EGLContext context = eglCreateContext(display, *eglConfig, |
michael@0 | 461 | EGL_NO_CONTEXT, |
michael@0 | 462 | contextAttribs ); |
michael@0 | 463 | if (context == EGL_NO_CONTEXT ) { |
michael@0 | 464 | return false; |
michael@0 | 465 | } |
michael@0 | 466 | |
michael@0 | 467 | // Make the context current |
michael@0 | 468 | if (!eglMakeCurrent(display, surface, surface, context)) { |
michael@0 | 469 | return false; |
michael@0 | 470 | } |
michael@0 | 471 | |
michael@0 | 472 | *eglDisplay = display; |
michael@0 | 473 | *eglContext = context; |
michael@0 | 474 | *eglSurface = surface; |
michael@0 | 475 | return true; |
michael@0 | 476 | } |
michael@0 | 477 | |
michael@0 | 478 | bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) { |
michael@0 | 479 | if (EGL_NO_DISPLAY == fDisplay) { |
michael@0 | 480 | bool bResult = create_ANGLE((HWND)fHWND, |
michael@0 | 481 | msaaSampleCount, |
michael@0 | 482 | &fDisplay, |
michael@0 | 483 | &fContext, |
michael@0 | 484 | &fSurface, |
michael@0 | 485 | &fConfig); |
michael@0 | 486 | if (false == bResult) { |
michael@0 | 487 | return false; |
michael@0 | 488 | } |
michael@0 | 489 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
michael@0 | 490 | |
michael@0 | 491 | if (intf) { |
michael@0 | 492 | ANGLE_GL_CALL(intf, ClearStencil(0)); |
michael@0 | 493 | ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
michael@0 | 494 | ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); |
michael@0 | 495 | ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT)); |
michael@0 | 496 | } |
michael@0 | 497 | } |
michael@0 | 498 | if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
michael@0 | 499 | eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilBits); |
michael@0 | 500 | eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); |
michael@0 | 501 | |
michael@0 | 502 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
michael@0 | 503 | |
michael@0 | 504 | if (intf ) { |
michael@0 | 505 | ANGLE_GL_CALL(intf, Viewport(0, 0, |
michael@0 | 506 | SkScalarRoundToInt(this->width()), |
michael@0 | 507 | SkScalarRoundToInt(this->height()))); |
michael@0 | 508 | } |
michael@0 | 509 | return true; |
michael@0 | 510 | } |
michael@0 | 511 | return false; |
michael@0 | 512 | } |
michael@0 | 513 | |
michael@0 | 514 | void SkOSWindow::detachANGLE() { |
michael@0 | 515 | eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT); |
michael@0 | 516 | |
michael@0 | 517 | eglDestroyContext(fDisplay, fContext); |
michael@0 | 518 | fContext = EGL_NO_CONTEXT; |
michael@0 | 519 | |
michael@0 | 520 | eglDestroySurface(fDisplay, fSurface); |
michael@0 | 521 | fSurface = EGL_NO_SURFACE; |
michael@0 | 522 | |
michael@0 | 523 | eglTerminate(fDisplay); |
michael@0 | 524 | fDisplay = EGL_NO_DISPLAY; |
michael@0 | 525 | } |
michael@0 | 526 | |
michael@0 | 527 | void SkOSWindow::presentANGLE() { |
michael@0 | 528 | SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
michael@0 | 529 | |
michael@0 | 530 | if (intf) { |
michael@0 | 531 | ANGLE_GL_CALL(intf, Flush()); |
michael@0 | 532 | } |
michael@0 | 533 | |
michael@0 | 534 | eglSwapBuffers(fDisplay, fSurface); |
michael@0 | 535 | } |
michael@0 | 536 | #endif // SK_ANGLE |
michael@0 | 537 | #endif // SK_SUPPORT_GPU |
michael@0 | 538 | |
michael@0 | 539 | // return true on success |
michael@0 | 540 | bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo* info) { |
michael@0 | 541 | |
michael@0 | 542 | // attach doubles as "windowResize" so we need to allo |
michael@0 | 543 | // already bound states to pass through again |
michael@0 | 544 | // TODO: split out the resize functionality |
michael@0 | 545 | // SkASSERT(kNone_BackEndType == fAttached); |
michael@0 | 546 | bool result = true; |
michael@0 | 547 | |
michael@0 | 548 | switch (attachType) { |
michael@0 | 549 | case kNone_BackEndType: |
michael@0 | 550 | // nothing to do |
michael@0 | 551 | break; |
michael@0 | 552 | #if SK_SUPPORT_GPU |
michael@0 | 553 | case kNativeGL_BackEndType: |
michael@0 | 554 | result = attachGL(msaaSampleCount, info); |
michael@0 | 555 | break; |
michael@0 | 556 | #if SK_ANGLE |
michael@0 | 557 | case kANGLE_BackEndType: |
michael@0 | 558 | result = attachANGLE(msaaSampleCount, info); |
michael@0 | 559 | break; |
michael@0 | 560 | #endif // SK_ANGLE |
michael@0 | 561 | #endif // SK_SUPPORT_GPU |
michael@0 | 562 | default: |
michael@0 | 563 | SkASSERT(false); |
michael@0 | 564 | result = false; |
michael@0 | 565 | break; |
michael@0 | 566 | } |
michael@0 | 567 | |
michael@0 | 568 | if (result) { |
michael@0 | 569 | fAttached = attachType; |
michael@0 | 570 | } |
michael@0 | 571 | |
michael@0 | 572 | return result; |
michael@0 | 573 | } |
michael@0 | 574 | |
michael@0 | 575 | void SkOSWindow::detach() { |
michael@0 | 576 | switch (fAttached) { |
michael@0 | 577 | case kNone_BackEndType: |
michael@0 | 578 | // nothing to do |
michael@0 | 579 | break; |
michael@0 | 580 | #if SK_SUPPORT_GPU |
michael@0 | 581 | case kNativeGL_BackEndType: |
michael@0 | 582 | detachGL(); |
michael@0 | 583 | break; |
michael@0 | 584 | #if SK_ANGLE |
michael@0 | 585 | case kANGLE_BackEndType: |
michael@0 | 586 | detachANGLE(); |
michael@0 | 587 | break; |
michael@0 | 588 | #endif // SK_ANGLE |
michael@0 | 589 | #endif // SK_SUPPORT_GPU |
michael@0 | 590 | default: |
michael@0 | 591 | SkASSERT(false); |
michael@0 | 592 | break; |
michael@0 | 593 | } |
michael@0 | 594 | fAttached = kNone_BackEndType; |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | void SkOSWindow::present() { |
michael@0 | 598 | switch (fAttached) { |
michael@0 | 599 | case kNone_BackEndType: |
michael@0 | 600 | // nothing to do |
michael@0 | 601 | return; |
michael@0 | 602 | #if SK_SUPPORT_GPU |
michael@0 | 603 | case kNativeGL_BackEndType: |
michael@0 | 604 | presentGL(); |
michael@0 | 605 | break; |
michael@0 | 606 | #if SK_ANGLE |
michael@0 | 607 | case kANGLE_BackEndType: |
michael@0 | 608 | presentANGLE(); |
michael@0 | 609 | break; |
michael@0 | 610 | #endif // SK_ANGLE |
michael@0 | 611 | #endif // SK_SUPPORT_GPU |
michael@0 | 612 | default: |
michael@0 | 613 | SkASSERT(false); |
michael@0 | 614 | break; |
michael@0 | 615 | } |
michael@0 | 616 | } |
michael@0 | 617 | |
michael@0 | 618 | #endif |