| 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 28 matching lines...) Expand all Loading... |
| 39 fUnixWindow.fGLContext = NULL; | 39 fUnixWindow.fGLContext = NULL; |
| 40 this->initWindow(0, NULL); | 40 this->initWindow(0, NULL); |
| 41 this->resize(WIDTH, HEIGHT); | 41 this->resize(WIDTH, HEIGHT); |
| 42 } | 42 } |
| 43 | 43 |
| 44 SkOSWindow::~SkOSWindow() { | 44 SkOSWindow::~SkOSWindow() { |
| 45 this->closeWindow(); | 45 this->closeWindow(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void SkOSWindow::closeWindow() { | 48 void SkOSWindow::closeWindow() { |
| 49 if (NULL != fUnixWindow.fDisplay) { | 49 if (fUnixWindow.fDisplay) { |
| 50 this->detach(); | 50 this->detach(); |
| 51 SkASSERT(NULL != fUnixWindow.fGc); | 51 SkASSERT(fUnixWindow.fGc); |
| 52 XFreeGC(fUnixWindow.fDisplay, fUnixWindow.fGc); | 52 XFreeGC(fUnixWindow.fDisplay, fUnixWindow.fGc); |
| 53 fUnixWindow.fGc = NULL; | 53 fUnixWindow.fGc = NULL; |
| 54 XDestroyWindow(fUnixWindow.fDisplay, fUnixWindow.fWin); | 54 XDestroyWindow(fUnixWindow.fDisplay, fUnixWindow.fWin); |
| 55 fVi = NULL; | 55 fVi = NULL; |
| 56 XCloseDisplay(fUnixWindow.fDisplay); | 56 XCloseDisplay(fUnixWindow.fDisplay); |
| 57 fUnixWindow.fDisplay = NULL; | 57 fUnixWindow.fDisplay = NULL; |
| 58 fMSAASampleCount = 0; | 58 fMSAASampleCount = 0; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info)
{ | 62 void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info)
{ |
| 63 if (fMSAASampleCount != requestedMSAASampleCount) { | 63 if (fMSAASampleCount != requestedMSAASampleCount) { |
| 64 this->closeWindow(); | 64 this->closeWindow(); |
| 65 } | 65 } |
| 66 // presence of fDisplay means we already have a window | 66 // presence of fDisplay means we already have a window |
| 67 if (NULL != fUnixWindow.fDisplay) { | 67 if (fUnixWindow.fDisplay) { |
| 68 if (NULL != info) { | 68 if (info) { |
| 69 if (NULL != fVi) { | 69 if (fVi) { |
| 70 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_SAMPLES_ARB, &info->
fSampleCount); | 70 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_SAMPLES_ARB, &info->
fSampleCount); |
| 71 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_STENCIL_SIZE, &info-
>fStencilBits); | 71 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_STENCIL_SIZE, &info-
>fStencilBits); |
| 72 } else { | 72 } else { |
| 73 info->fSampleCount = 0; | 73 info->fSampleCount = 0; |
| 74 info->fStencilBits = 0; | 74 info->fStencilBits = 0; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 fUnixWindow.fDisplay = XOpenDisplay(NULL); | 79 fUnixWindow.fDisplay = XOpenDisplay(NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 103 msaaAtt[kAttCount + 3] = None; | 103 msaaAtt[kAttCount + 3] = None; |
| 104 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt); | 104 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt); |
| 105 fMSAASampleCount = requestedMSAASampleCount; | 105 fMSAASampleCount = requestedMSAASampleCount; |
| 106 } | 106 } |
| 107 if (NULL == fVi) { | 107 if (NULL == fVi) { |
| 108 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att); | 108 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att); |
| 109 fMSAASampleCount = 0; | 109 fMSAASampleCount = 0; |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (fVi) { | 112 if (fVi) { |
| 113 if (NULL != info) { | 113 if (info) { |
| 114 glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &info->fSampleCount); | 114 glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &info->fSampleCount); |
| 115 glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits); | 115 glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits); |
| 116 } | 116 } |
| 117 Colormap colorMap = XCreateColormap(dsp, | 117 Colormap colorMap = XCreateColormap(dsp, |
| 118 RootWindow(dsp, fVi->screen), | 118 RootWindow(dsp, fVi->screen), |
| 119 fVi->visual, | 119 fVi->visual, |
| 120 AllocNone); | 120 AllocNone); |
| 121 XSetWindowAttributes swa; | 121 XSetWindowAttributes swa; |
| 122 swa.colormap = colorMap; | 122 swa.colormap = colorMap; |
| 123 swa.event_mask = EVENT_MASK; | 123 swa.event_mask = EVENT_MASK; |
| 124 fUnixWindow.fWin = XCreateWindow(dsp, | 124 fUnixWindow.fWin = XCreateWindow(dsp, |
| 125 RootWindow(dsp, fVi->screen), | 125 RootWindow(dsp, fVi->screen), |
| 126 0, 0, // x, y | 126 0, 0, // x, y |
| 127 WIDTH, HEIGHT, | 127 WIDTH, HEIGHT, |
| 128 0, // border width | 128 0, // border width |
| 129 fVi->depth, | 129 fVi->depth, |
| 130 InputOutput, | 130 InputOutput, |
| 131 fVi->visual, | 131 fVi->visual, |
| 132 CWEventMask | CWColormap, | 132 CWEventMask | CWColormap, |
| 133 &swa); | 133 &swa); |
| 134 } else { | 134 } else { |
| 135 if (NULL != info) { | 135 if (info) { |
| 136 info->fSampleCount = 0; | 136 info->fSampleCount = 0; |
| 137 info->fStencilBits = 0; | 137 info->fStencilBits = 0; |
| 138 } | 138 } |
| 139 // Create a simple window instead. We will not be able to show GL | 139 // Create a simple window instead. We will not be able to show GL |
| 140 fUnixWindow.fWin = XCreateSimpleWindow(dsp, | 140 fUnixWindow.fWin = XCreateSimpleWindow(dsp, |
| 141 DefaultRootWindow(dsp), | 141 DefaultRootWindow(dsp), |
| 142 0, 0, // x, y | 142 0, 0, // x, y |
| 143 WIDTH, HEIGHT, | 143 WIDTH, HEIGHT, |
| 144 0, // border width | 144 0, // border width |
| 145 0, // border value | 145 0, // border value |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 this->doPaint(); | 303 this->doPaint(); |
| 304 break; | 304 break; |
| 305 case kQuitRequest_NextXEventResult: | 305 case kQuitRequest_NextXEventResult: |
| 306 return; | 306 return; |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 void SkOSWindow::mapWindowAndWait() { | 312 void SkOSWindow::mapWindowAndWait() { |
| 313 SkASSERT(NULL != fUnixWindow.fDisplay); | 313 SkASSERT(fUnixWindow.fDisplay); |
| 314 Display* dsp = fUnixWindow.fDisplay; | 314 Display* dsp = fUnixWindow.fDisplay; |
| 315 Window win = fUnixWindow.fWin; | 315 Window win = fUnixWindow.fWin; |
| 316 XMapWindow(dsp, win); | 316 XMapWindow(dsp, win); |
| 317 | 317 |
| 318 long eventMask = StructureNotifyMask; | 318 long eventMask = StructureNotifyMask; |
| 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 bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, AttachmentInfo* inf
o) { | 329 bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, AttachmentInfo* inf
o) { |
| 330 this->initWindow(msaaSampleCount, info); | 330 this->initWindow(msaaSampleCount, info); |
| 331 | 331 |
| 332 if (NULL == fUnixWindow.fDisplay) { | 332 if (NULL == fUnixWindow.fDisplay) { |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 if (NULL == fUnixWindow.fGLContext) { | 335 if (NULL == fUnixWindow.fGLContext) { |
| 336 SkASSERT(NULL != fVi); | 336 SkASSERT(fVi); |
| 337 | 337 |
| 338 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, | 338 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, |
| 339 fVi, | 339 fVi, |
| 340 NULL, | 340 NULL, |
| 341 GL_TRUE); | 341 GL_TRUE); |
| 342 if (NULL == fUnixWindow.fGLContext) { | 342 if (NULL == fUnixWindow.fGLContext) { |
| 343 return false; | 343 return false; |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 glXMakeCurrent(fUnixWindow.fDisplay, | 346 glXMakeCurrent(fUnixWindow.fDisplay, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 358 void SkOSWindow::detach() { | 358 void SkOSWindow::detach() { |
| 359 if (NULL == fUnixWindow.fDisplay || NULL == fUnixWindow.fGLContext) { | 359 if (NULL == fUnixWindow.fDisplay || NULL == fUnixWindow.fGLContext) { |
| 360 return; | 360 return; |
| 361 } | 361 } |
| 362 glXMakeCurrent(fUnixWindow.fDisplay, None, NULL); | 362 glXMakeCurrent(fUnixWindow.fDisplay, None, NULL); |
| 363 glXDestroyContext(fUnixWindow.fDisplay, fUnixWindow.fGLContext); | 363 glXDestroyContext(fUnixWindow.fDisplay, fUnixWindow.fGLContext); |
| 364 fUnixWindow.fGLContext = NULL; | 364 fUnixWindow.fGLContext = NULL; |
| 365 } | 365 } |
| 366 | 366 |
| 367 void SkOSWindow::present() { | 367 void SkOSWindow::present() { |
| 368 if (NULL != fUnixWindow.fDisplay && NULL != fUnixWindow.fGLContext) { | 368 if (fUnixWindow.fDisplay && fUnixWindow.fGLContext) { |
| 369 glXSwapBuffers(fUnixWindow.fDisplay, fUnixWindow.fWin); | 369 glXSwapBuffers(fUnixWindow.fDisplay, fUnixWindow.fWin); |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 void SkOSWindow::onSetTitle(const char title[]) { | 373 void SkOSWindow::onSetTitle(const char title[]) { |
| 374 if (NULL == fUnixWindow.fDisplay) { | 374 if (NULL == fUnixWindow.fDisplay) { |
| 375 return; | 375 return; |
| 376 } | 376 } |
| 377 XTextProperty textProp; | 377 XTextProperty textProp; |
| 378 textProp.value = (unsigned char*)title; | 378 textProp.value = (unsigned char*)title; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 398 image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * 4; | 398 image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * 4; |
| 399 image.bits_per_pixel = bitsPerPixel; | 399 image.bits_per_pixel = bitsPerPixel; |
| 400 return XInitImage(&image); | 400 return XInitImage(&image); |
| 401 } | 401 } |
| 402 | 402 |
| 403 void SkOSWindow::doPaint() { | 403 void SkOSWindow::doPaint() { |
| 404 if (NULL == fUnixWindow.fDisplay) { | 404 if (NULL == fUnixWindow.fDisplay) { |
| 405 return; | 405 return; |
| 406 } | 406 } |
| 407 // If we are drawing with GL, we don't need XPutImage. | 407 // If we are drawing with GL, we don't need XPutImage. |
| 408 if (NULL != fUnixWindow.fGLContext) { | 408 if (fUnixWindow.fGLContext) { |
| 409 return; | 409 return; |
| 410 } | 410 } |
| 411 // Draw the bitmap to the screen. | 411 // Draw the bitmap to the screen. |
| 412 const SkBitmap& bitmap = getBitmap(); | 412 const SkBitmap& bitmap = getBitmap(); |
| 413 int width = bitmap.width(); | 413 int width = bitmap.width(); |
| 414 int height = bitmap.height(); | 414 int height = bitmap.height(); |
| 415 | 415 |
| 416 XImage image; | 416 XImage image; |
| 417 if (!convertBitmapToXImage(image, bitmap)) { | 417 if (!convertBitmapToXImage(image, bitmap)) { |
| 418 return; | 418 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 431 | 431 |
| 432 void SkEvent::SignalNonEmptyQueue() { | 432 void SkEvent::SignalNonEmptyQueue() { |
| 433 // nothing to do, since we spin on our event-queue, polling for XPending | 433 // nothing to do, since we spin on our event-queue, polling for XPending |
| 434 } | 434 } |
| 435 | 435 |
| 436 void SkEvent::SignalQueueTimer(SkMSec delay) { | 436 void SkEvent::SignalQueueTimer(SkMSec delay) { |
| 437 // just need to record the delay time. We handle waking up for it in | 437 // just need to record the delay time. We handle waking up for it in |
| 438 // MyXNextEventWithDelay() | 438 // MyXNextEventWithDelay() |
| 439 gTimerDelay = delay; | 439 gTimerDelay = delay; |
| 440 } | 440 } |
| OLD | NEW |