OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 XSelectInput(dsp, win, eventMask); | 319 XSelectInput(dsp, win, eventMask); |
320 | 320 |
321 // Wait until screen is ready. | 321 // Wait until screen is ready. |
322 XEvent evt; | 322 XEvent evt; |
323 do { | 323 do { |
324 XNextEvent(dsp, &evt); | 324 XNextEvent(dsp, &evt); |
325 } while(evt.type != MapNotify); | 325 } while(evt.type != MapNotify); |
326 | 326 |
327 } | 327 } |
328 | 328 |
329 //////////////////////////////////////////////// | |
330 | |
331 // Some helper code to load the correct version of glXSwapInterval | |
332 #define GLX_GET_PROC_ADDR(name) glXGetProcAddress(reinterpret_cast<const GLubyte *>((name))) | |
333 #define EXT_WRANGLE(name, type, ...) \ | |
334 if (GLX_GET_PROC_ADDR(#name)) { \ | |
335 static type k##name; \ | |
336 if (!k##name) { \ | |
337 k##name = (type) GLX_GET_PROC_ADDR(#name); \ | |
338 } \ | |
339 k##name(__VA_ARGS__); \ | |
340 SkDebugf("using %s\n", #name); \ | |
341 return; \ | |
342 } | |
343 | |
344 static void glXSwapInterval(Display* dsp, GLXDrawable drawable, int interval) { | |
345 EXT_WRANGLE(glXSwapIntervalEXT, PFNGLXSWAPINTERVALEXTPROC, dsp, drawable, in terval); | |
346 EXT_WRANGLE(glXSwapIntervalMESA, PFNGLXSWAPINTERVALMESAPROC, interval); | |
347 EXT_WRANGLE(glXSwapIntervalSGI, PFNGLXSWAPINTERVALSGIPROC, interval); | |
348 } | |
349 | |
350 ///////////////////////////////////////////////////////////////////////// | |
351 | |
329 bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, AttachmentInfo* inf o) { | 352 bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, AttachmentInfo* inf o) { |
330 this->initWindow(msaaSampleCount, info); | 353 this->initWindow(msaaSampleCount, info); |
331 | 354 |
332 if (NULL == fUnixWindow.fDisplay) { | 355 if (NULL == fUnixWindow.fDisplay) { |
333 return false; | 356 return false; |
334 } | 357 } |
335 if (NULL == fUnixWindow.fGLContext) { | 358 if (NULL == fUnixWindow.fGLContext) { |
336 SkASSERT(fVi); | 359 SkASSERT(fVi); |
337 | 360 |
338 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, | 361 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 | 443 |
421 XPutImage(fUnixWindow.fDisplay, | 444 XPutImage(fUnixWindow.fDisplay, |
422 fUnixWindow.fWin, | 445 fUnixWindow.fWin, |
423 fUnixWindow.fGc, | 446 fUnixWindow.fGc, |
424 &image, | 447 &image, |
425 0, 0, // src x,y | 448 0, 0, // src x,y |
426 0, 0, // dst x,y | 449 0, 0, // dst x,y |
427 width, height); | 450 width, height); |
428 } | 451 } |
429 | 452 |
453 enum | |
454 { | |
455 _NET_WM_STATE_REMOVE =0, | |
bsalomon
2015/05/27 14:32:25
tab these out?
| |
456 _NET_WM_STATE_ADD = 1, | |
457 _NET_WM_STATE_TOGGLE =2 | |
458 }; | |
459 | |
460 void SkOSWindow::setFullscreen(bool setFullscreen) { | |
461 Display* dsp = fUnixWindow.fDisplay; | |
462 if (NULL == dsp) { | |
463 return; | |
464 } | |
465 Window win = fUnixWindow.fWin; | |
466 | |
467 // Full screen | |
468 Atom wm_state = XInternAtom(dsp, "_NET_WM_STATE", False); | |
469 Atom fullscreen = XInternAtom(dsp, "_NET_WM_STATE_FULLSCREEN", False); | |
470 | |
471 XEvent evt; | |
472 sk_bzero(&evt, sizeof(evt)); | |
473 evt.type = ClientMessage; | |
474 evt.xclient.window = win; | |
475 evt.xclient.message_type = wm_state; | |
476 evt.xclient.format = 32; | |
477 evt.xclient.data.l[0] = setFullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_RE MOVE; | |
478 evt.xclient.data.l[1] = fullscreen; | |
479 evt.xclient.data.l[2] = 0; | |
480 | |
481 XSendEvent(dsp, DefaultRootWindow(dsp), False, | |
482 SubstructureRedirectMask | SubstructureNotifyMask, &evt); | |
483 } | |
484 | |
485 void SkOSWindow::setVsync(bool vsync) { | |
486 if (fUnixWindow.fDisplay && fUnixWindow.fGLContext && fUnixWindow.fWin) { | |
487 int swapInterval = vsync ? 1 : 0; | |
488 glXSwapInterval(fUnixWindow.fDisplay, fUnixWindow.fWin, swapInterval); | |
489 } | |
490 } | |
491 | |
430 /////////////////////////////////////////////////////////////////////////////// | 492 /////////////////////////////////////////////////////////////////////////////// |
431 | 493 |
432 void SkEvent::SignalNonEmptyQueue() { | 494 void SkEvent::SignalNonEmptyQueue() { |
433 // nothing to do, since we spin on our event-queue, polling for XPending | 495 // nothing to do, since we spin on our event-queue, polling for XPending |
434 } | 496 } |
435 | 497 |
436 void SkEvent::SignalQueueTimer(SkMSec delay) { | 498 void SkEvent::SignalQueueTimer(SkMSec delay) { |
437 // just need to record the delay time. We handle waking up for it in | 499 // just need to record the delay time. We handle waking up for it in |
438 // MyXNextEventWithDelay() | 500 // MyXNextEventWithDelay() |
439 gTimerDelay = delay; | 501 gTimerDelay = delay; |
440 } | 502 } |
OLD | NEW |