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> |
11 #include <GL/glx.h> | 11 #include <GL/glx.h> |
12 #include <GL/gl.h> | 12 #include <GL/gl.h> |
13 #include <GL/glu.h> | 13 #include <GL/glu.h> |
14 | 14 |
15 #include "SkWindow.h" | 15 #include "SkWindow.h" |
16 | 16 |
17 #include "gl/glx/GrNativeDisplay_glx.h" | |
18 | |
17 #include "SkBitmap.h" | 19 #include "SkBitmap.h" |
18 #include "SkCanvas.h" | 20 #include "SkCanvas.h" |
19 #include "SkColor.h" | 21 #include "SkColor.h" |
20 #include "SkEvent.h" | 22 #include "SkEvent.h" |
21 #include "SkKey.h" | 23 #include "SkKey.h" |
22 #include "SkWindow.h" | 24 #include "SkWindow.h" |
23 #include "XkeysToSkKeys.h" | 25 #include "XkeysToSkKeys.h" |
24 extern "C" { | 26 extern "C" { |
25 #include "keysym2ucs.h" | 27 #include "keysym2ucs.h" |
26 } | 28 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 } | 77 } |
76 } | 78 } |
77 return; | 79 return; |
78 } | 80 } |
79 fUnixWindow.fDisplay = XOpenDisplay(nullptr); | 81 fUnixWindow.fDisplay = XOpenDisplay(nullptr); |
80 Display* dsp = fUnixWindow.fDisplay; | 82 Display* dsp = fUnixWindow.fDisplay; |
81 if (nullptr == dsp) { | 83 if (nullptr == dsp) { |
82 SkDebugf("Could not open an X Display"); | 84 SkDebugf("Could not open an X Display"); |
83 return; | 85 return; |
84 } | 86 } |
85 // Attempt to create a window that supports GL | 87 |
robertphillips
2015/10/16 14:54:40
static const int attrs[] ?
| |
86 GLint att[] = { | 88 int att[] = { |
87 GLX_RGBA, | |
88 GLX_DEPTH_SIZE, 24, | 89 GLX_DEPTH_SIZE, 24, |
89 GLX_DOUBLEBUFFER, | 90 GLX_DOUBLEBUFFER, true, |
robertphillips
2015/10/16 14:54:40
Don't we need these stencil settings in the other
| |
90 GLX_STENCIL_SIZE, 8, | 91 GLX_STENCIL_SIZE, 8, |
91 None | 92 None |
92 }; | 93 }; |
93 SkASSERT(nullptr == fVi); | |
94 if (requestedMSAASampleCount > 0) { | |
95 static const GLint kAttCount = SK_ARRAY_COUNT(att); | |
96 GLint msaaAtt[kAttCount + 4]; | |
97 memcpy(msaaAtt, att, sizeof(att)); | |
98 SkASSERT(None == msaaAtt[kAttCount - 1]); | |
99 msaaAtt[kAttCount - 1] = GLX_SAMPLE_BUFFERS_ARB; | |
100 msaaAtt[kAttCount + 0] = 1; | |
101 msaaAtt[kAttCount + 1] = GLX_SAMPLES_ARB; | |
102 msaaAtt[kAttCount + 2] = requestedMSAASampleCount; | |
103 msaaAtt[kAttCount + 3] = None; | |
104 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt); | |
105 fMSAASampleCount = requestedMSAASampleCount; | |
106 } | |
107 if (nullptr == fVi) { | |
108 fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att); | |
109 fMSAASampleCount = 0; | |
110 } | |
111 | 94 |
112 if (fVi) { | 95 GLXFBConfig bestFbConfig; |
96 if (!GrNativeDisplay::Initialize(att, fUnixWindow.fDisplay, &bestFbConfig)) { | |
113 if (info) { | 97 if (info) { |
114 glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &info->fSampleCount); | 98 info->fSampleCount = 0; |
99 info->fStencilBits = 0; | |
100 } | |
101 // Create a simple window instead. We will not be able to show GL | |
102 fUnixWindow.fWin = XCreateSimpleWindow(dsp, | |
103 DefaultRootWindow(dsp), | |
104 0, 0, // x, y | |
105 WIDTH, HEIGHT, | |
106 0, // border width | |
107 0, // border value | |
108 0); // background value | |
109 } else { | |
110 glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &fMSAASampleCount); | |
111 if (fMSAASampleCount < requestedMSAASampleCount) { | |
112 SkDebugf("Requested samples exceeds the maximum allowed on this plat form\n"); | |
113 } | |
114 | |
115 if (info) { | |
robertphillips
2015/10/16 14:54:40
Shouldn't this be requestedMSAASampleCount ?
| |
116 info->fSampleCount = fMSAASampleCount; | |
115 glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits); | 117 glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits); |
116 } | 118 } |
119 | |
120 fVi = glXGetVisualFromFBConfig(fUnixWindow.fDisplay, bestFbConfig); | |
121 SkASSERT(fVi); | |
122 | |
117 Colormap colorMap = XCreateColormap(dsp, | 123 Colormap colorMap = XCreateColormap(dsp, |
118 RootWindow(dsp, fVi->screen), | 124 RootWindow(dsp, fVi->screen), |
119 fVi->visual, | 125 fVi->visual, |
120 AllocNone); | 126 AllocNone); |
121 XSetWindowAttributes swa; | 127 XSetWindowAttributes swa; |
122 swa.colormap = colorMap; | 128 swa.colormap = colorMap; |
123 swa.event_mask = EVENT_MASK; | 129 swa.event_mask = EVENT_MASK; |
124 fUnixWindow.fWin = XCreateWindow(dsp, | 130 fUnixWindow.fWin = XCreateWindow(dsp, |
125 RootWindow(dsp, fVi->screen), | 131 RootWindow(dsp, fVi->screen), |
126 0, 0, // x, y | 132 0, 0, // x, y |
127 WIDTH, HEIGHT, | 133 WIDTH, HEIGHT, |
128 0, // border width | 134 0, // border width |
129 fVi->depth, | 135 fVi->depth, |
130 InputOutput, | 136 InputOutput, |
131 fVi->visual, | 137 fVi->visual, |
132 CWEventMask | CWColormap, | 138 CWEventMask | CWColormap, |
133 &swa); | 139 &swa); |
134 } else { | 140 |
135 if (info) { | |
136 info->fSampleCount = 0; | |
137 info->fStencilBits = 0; | |
138 } | |
139 // Create a simple window instead. We will not be able to show GL | |
140 fUnixWindow.fWin = XCreateSimpleWindow(dsp, | |
141 DefaultRootWindow(dsp), | |
142 0, 0, // x, y | |
143 WIDTH, HEIGHT, | |
144 0, // border width | |
145 0, // border value | |
146 0); // background value | |
147 } | 141 } |
142 | |
148 this->mapWindowAndWait(); | 143 this->mapWindowAndWait(); |
149 fUnixWindow.fGc = XCreateGC(dsp, fUnixWindow.fWin, 0, nullptr); | 144 fUnixWindow.fGc = XCreateGC(dsp, fUnixWindow.fWin, 0, nullptr); |
150 } | 145 } |
151 | 146 |
152 static unsigned getModi(const XEvent& evt) { | 147 static unsigned getModi(const XEvent& evt) { |
153 static const struct { | 148 static const struct { |
154 unsigned fXMask; | 149 unsigned fXMask; |
155 unsigned fSkMask; | 150 unsigned fSkMask; |
156 } gModi[] = { | 151 } gModi[] = { |
157 // X values found by experiment. Is there a better way? | 152 // X values found by experiment. Is there a better way? |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 | 505 |
511 void SkEvent::SignalNonEmptyQueue() { | 506 void SkEvent::SignalNonEmptyQueue() { |
512 // nothing to do, since we spin on our event-queue, polling for XPending | 507 // nothing to do, since we spin on our event-queue, polling for XPending |
513 } | 508 } |
514 | 509 |
515 void SkEvent::SignalQueueTimer(SkMSec delay) { | 510 void SkEvent::SignalQueueTimer(SkMSec delay) { |
516 // just need to record the delay time. We handle waking up for it in | 511 // just need to record the delay time. We handle waking up for it in |
517 // MyXNextEventWithDelay() | 512 // MyXNextEventWithDelay() |
518 gTimerDelay = delay; | 513 gTimerDelay = delay; |
519 } | 514 } |
OLD | NEW |