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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Determine which events to listen for. | 31 // Determine which events to listen for. |
32 const long EVENT_MASK = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask | 32 const long EVENT_MASK = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask |
33 |ExposureMask|PointerMotionMask|KeyPressMask|KeyReleaseMask; | 33 |ExposureMask|PointerMotionMask|KeyPressMask|KeyReleaseMask; |
34 | 34 |
35 SkOSWindow::SkOSWindow(void* unused) | 35 SkOSWindow::SkOSWindow(void* unused) |
36 : fVi(NULL) | 36 : fVi(NULL) |
37 , fMSAASampleCount(0) { | 37 , fMSAASampleCount(0) { |
38 fUnixWindow.fDisplay = NULL; | 38 fUnixWindow.fDisplay = NULL; |
39 fUnixWindow.fGLContext = NULL; | 39 fUnixWindow.fGLContext = NULL; |
40 this->initWindow(0); | 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 (NULL != fUnixWindow.fDisplay) { |
50 this->detach(); | 50 this->detach(); |
51 SkASSERT(NULL != fUnixWindow.fGc); | 51 SkASSERT(NULL != 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) { | 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 (NULL != fUnixWindow.fDisplay) { |
| 68 if (NULL != info) { |
| 69 if (NULL != fVi) { |
| 70 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_SAMPLES_ARB, &info->
fSampleCount); |
| 71 glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_STENCIL_SIZE, &info-
>fStencilBits); |
| 72 } else { |
| 73 info->fSampleCount = 0; |
| 74 info->fStencilBits = 0; |
| 75 } |
| 76 } |
68 return; | 77 return; |
69 } | 78 } |
70 fUnixWindow.fDisplay = XOpenDisplay(NULL); | 79 fUnixWindow.fDisplay = XOpenDisplay(NULL); |
71 Display* dsp = fUnixWindow.fDisplay; | 80 Display* dsp = fUnixWindow.fDisplay; |
72 if (NULL == dsp) { | 81 if (NULL == dsp) { |
73 SkDebugf("Could not open an X Display"); | 82 SkDebugf("Could not open an X Display"); |
74 return; | 83 return; |
75 } | 84 } |
76 // Attempt to create a window that supports GL | 85 // Attempt to create a window that supports GL |
77 GLint att[] = { | 86 GLint att[] = { |
(...skipping 16 matching lines...) Expand all Loading... |
94 msaaAtt[kAttCount + 3] = None; | 103 msaaAtt[kAttCount + 3] = None; |
95 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt); | 104 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt); |
96 fMSAASampleCount = requestedMSAASampleCount; | 105 fMSAASampleCount = requestedMSAASampleCount; |
97 } | 106 } |
98 if (NULL == fVi) { | 107 if (NULL == fVi) { |
99 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att); | 108 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att); |
100 fMSAASampleCount = 0; | 109 fMSAASampleCount = 0; |
101 } | 110 } |
102 | 111 |
103 if (fVi) { | 112 if (fVi) { |
| 113 if (NULL != info) { |
| 114 glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &info->fSampleCount); |
| 115 glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits); |
| 116 } |
104 Colormap colorMap = XCreateColormap(dsp, | 117 Colormap colorMap = XCreateColormap(dsp, |
105 RootWindow(dsp, fVi->screen), | 118 RootWindow(dsp, fVi->screen), |
106 fVi->visual, | 119 fVi->visual, |
107 AllocNone); | 120 AllocNone); |
108 XSetWindowAttributes swa; | 121 XSetWindowAttributes swa; |
109 swa.colormap = colorMap; | 122 swa.colormap = colorMap; |
110 swa.event_mask = EVENT_MASK; | 123 swa.event_mask = EVENT_MASK; |
111 fUnixWindow.fWin = XCreateWindow(dsp, | 124 fUnixWindow.fWin = XCreateWindow(dsp, |
112 RootWindow(dsp, fVi->screen), | 125 RootWindow(dsp, fVi->screen), |
113 0, 0, // x, y | 126 0, 0, // x, y |
114 WIDTH, HEIGHT, | 127 WIDTH, HEIGHT, |
115 0, // border width | 128 0, // border width |
116 fVi->depth, | 129 fVi->depth, |
117 InputOutput, | 130 InputOutput, |
118 fVi->visual, | 131 fVi->visual, |
119 CWEventMask | CWColormap, | 132 CWEventMask | CWColormap, |
120 &swa); | 133 &swa); |
121 } else { | 134 } else { |
| 135 if (NULL != info) { |
| 136 info->fSampleCount = 0; |
| 137 info->fStencilBits = 0; |
| 138 } |
122 // 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 |
123 fUnixWindow.fWin = XCreateSimpleWindow(dsp, | 140 fUnixWindow.fWin = XCreateSimpleWindow(dsp, |
124 DefaultRootWindow(dsp), | 141 DefaultRootWindow(dsp), |
125 0, 0, // x, y | 142 0, 0, // x, y |
126 WIDTH, HEIGHT, | 143 WIDTH, HEIGHT, |
127 0, // border width | 144 0, // border width |
128 0, // border value | 145 0, // border value |
129 0); // background value | 146 0); // background value |
130 } | 147 } |
131 this->mapWindowAndWait(); | 148 this->mapWindowAndWait(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 XSelectInput(dsp, win, eventMask); | 260 XSelectInput(dsp, win, eventMask); |
244 | 261 |
245 // Wait until screen is ready. | 262 // Wait until screen is ready. |
246 XEvent evt; | 263 XEvent evt; |
247 do { | 264 do { |
248 XNextEvent(dsp, &evt); | 265 XNextEvent(dsp, &evt); |
249 } while(evt.type != MapNotify); | 266 } while(evt.type != MapNotify); |
250 | 267 |
251 } | 268 } |
252 | 269 |
253 bool SkOSWindow::attach(SkBackEndTypes /* attachType */, int msaaSampleCount) { | 270 bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, AttachmentInfo* inf
o) { |
254 this->initWindow(msaaSampleCount); | 271 this->initWindow(msaaSampleCount, info); |
| 272 |
255 if (NULL == fUnixWindow.fDisplay) { | 273 if (NULL == fUnixWindow.fDisplay) { |
256 return false; | 274 return false; |
257 } | 275 } |
258 if (NULL == fUnixWindow.fGLContext) { | 276 if (NULL == fUnixWindow.fGLContext) { |
259 SkASSERT(NULL != fVi); | 277 SkASSERT(NULL != fVi); |
260 | 278 |
261 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, | 279 fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay, |
262 fVi, | 280 fVi, |
263 NULL, | 281 NULL, |
264 GL_TRUE); | 282 GL_TRUE); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 return false; | 381 return false; |
364 } | 382 } |
365 | 383 |
366 bool SkOSWindow::onHandleKey(SkKey key) { | 384 bool SkOSWindow::onHandleKey(SkKey key) { |
367 return false; | 385 return false; |
368 } | 386 } |
369 | 387 |
370 bool SkOSWindow::onHandleKeyUp(SkKey key) { | 388 bool SkOSWindow::onHandleKeyUp(SkKey key) { |
371 return false; | 389 return false; |
372 } | 390 } |
OLD | NEW |