|
Lines 43-67
std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(XID window, GLCo
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec1
|
| 43 |
visualInfo.visualid = XVisualIDFromVisual(attributes.visual); |
43 |
visualInfo.visualid = XVisualIDFromVisual(attributes.visual); |
| 44 |
|
44 |
|
| 45 |
int numReturned = 0; |
45 |
int numReturned = 0; |
| 46 |
XVisualInfo* visualInfoList = XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned); |
46 |
XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned)); |
| 47 |
|
|
|
| 48 |
GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0; |
| 49 |
GLXContext context = glXCreateContext(display, visualInfoList, glxSharingContext, True); |
| 50 |
XFree(visualInfoList); |
| 51 |
|
47 |
|
|
|
48 |
GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr; |
| 49 |
XUniqueGLXContext context(glXCreateContext(display, visualInfoList.get(), glxSharingContext, True)); |
| 52 |
if (!context) |
50 |
if (!context) |
| 53 |
return nullptr; |
51 |
return nullptr; |
| 54 |
|
52 |
|
| 55 |
// GLXPbuffer and XID are both the same types underneath, so we have to share |
53 |
return std::make_unique<GLContextGLX>(WTF::move(context), window); |
| 56 |
// a constructor here with the window path. |
|
|
| 57 |
auto contextWrapper = std::make_unique<GLContextGLX>(context); |
| 58 |
contextWrapper->m_window = window; |
| 59 |
return WTF::move(contextWrapper); |
| 60 |
} |
54 |
} |
| 61 |
|
55 |
|
| 62 |
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext) |
56 |
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext) |
| 63 |
{ |
57 |
{ |
| 64 |
int fbConfigAttributes[] = { |
58 |
static const int fbConfigAttributes[] = { |
| 65 |
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, |
59 |
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, |
| 66 |
GLX_RENDER_TYPE, GLX_RGBA_BIT, |
60 |
GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 67 |
GLX_RED_SIZE, 1, |
61 |
GLX_RED_SIZE, 1, |
|
Lines 74-105
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext shar
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec2
|
| 74 |
|
68 |
|
| 75 |
int returnedElements; |
69 |
int returnedElements; |
| 76 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
70 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
| 77 |
GLXFBConfig* configs = glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements); |
71 |
XUniquePtr<GLXFBConfig> configs(glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements)); |
| 78 |
if (!returnedElements) { |
72 |
if (!returnedElements) |
| 79 |
XFree(configs); |
|
|
| 80 |
return nullptr; |
73 |
return nullptr; |
| 81 |
} |
|
|
| 82 |
|
74 |
|
| 83 |
// We will be rendering to a texture, so our pbuffer does not need to be large. |
75 |
// We will be rendering to a texture, so our pbuffer does not need to be large. |
| 84 |
static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 }; |
76 |
static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 }; |
| 85 |
GLXPbuffer pbuffer = glXCreatePbuffer(display, configs[0], pbufferAttributes); |
77 |
XUniqueGLXPbuffer pbuffer(glXCreatePbuffer(display, configs.get()[0], pbufferAttributes)); |
| 86 |
if (!pbuffer) { |
78 |
if (!pbuffer) |
| 87 |
XFree(configs); |
|
|
| 88 |
return nullptr; |
79 |
return nullptr; |
| 89 |
} |
|
|
| 90 |
|
80 |
|
| 91 |
GLXContext context = glXCreateNewContext(display, configs[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE); |
81 |
XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE)); |
| 92 |
XFree(configs); |
82 |
if (!context) |
| 93 |
if (!context) { |
|
|
| 94 |
glXDestroyPbuffer(display, pbuffer); |
| 95 |
return nullptr; |
83 |
return nullptr; |
| 96 |
} |
|
|
| 97 |
|
84 |
|
| 98 |
// GLXPbuffer and XID are both the same types underneath, so we have to share |
85 |
return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pbuffer)); |
| 99 |
// a constructor here with the window path. |
|
|
| 100 |
auto contextWrapper = std::make_unique<GLContextGLX>(context); |
| 101 |
contextWrapper->m_pbuffer = pbuffer; |
| 102 |
return WTF::move(contextWrapper); |
| 103 |
} |
86 |
} |
| 104 |
|
87 |
|
| 105 |
std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext sharingContext) |
88 |
std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext sharingContext) |
|
Lines 114-144
std::unique_ptr<GLContextGLX> GLContextGLX::createPixmapContext(GLXContext shari
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec3
|
| 114 |
}; |
97 |
}; |
| 115 |
|
98 |
|
| 116 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
99 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
| 117 |
XVisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), visualAttributes); |
100 |
XUniquePtr<XVisualInfo> visualInfo(glXChooseVisual(display, DefaultScreen(display), visualAttributes)); |
| 118 |
if (!visualInfo) |
101 |
if (!visualInfo) |
| 119 |
return nullptr; |
102 |
return nullptr; |
| 120 |
|
103 |
|
| 121 |
GLXContext context = glXCreateContext(display, visualInfo, sharingContext, GL_TRUE); |
104 |
XUniqueGLXContext context(glXCreateContext(display, visualInfo.get(), sharingContext, GL_TRUE)); |
| 122 |
if (!context) { |
105 |
if (!context) |
| 123 |
XFree(visualInfo); |
|
|
| 124 |
return nullptr; |
106 |
return nullptr; |
| 125 |
} |
|
|
| 126 |
|
107 |
|
| 127 |
Pixmap pixmap = XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth); |
108 |
XUniquePixmap pixmap(XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth)); |
| 128 |
if (!pixmap) { |
109 |
if (!pixmap) |
| 129 |
XFree(visualInfo); |
|
|
| 130 |
return nullptr; |
110 |
return nullptr; |
| 131 |
} |
|
|
| 132 |
|
111 |
|
| 133 |
GLXPixmap glxPixmap = glXCreateGLXPixmap(display, visualInfo, pixmap); |
112 |
XUniqueGLXPixmap glxPixmap(glXCreateGLXPixmap(display, visualInfo.get(), pixmap.get())); |
| 134 |
if (!glxPixmap) { |
113 |
if (!glxPixmap) |
| 135 |
XFreePixmap(display, pixmap); |
|
|
| 136 |
XFree(visualInfo); |
| 137 |
return nullptr; |
114 |
return nullptr; |
| 138 |
} |
|
|
| 139 |
|
115 |
|
| 140 |
XFree(visualInfo); |
116 |
return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pixmap), WTF::move(glxPixmap)); |
| 141 |
return std::make_unique<GLContextGLX>(context, pixmap, glxPixmap); |
|
|
| 142 |
} |
117 |
} |
| 143 |
|
118 |
|
| 144 |
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* sharingContext) |
119 |
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* sharingContext) |
|
Lines 152-158
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext*
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec4
|
| 152 |
if (!success) |
127 |
if (!success) |
| 153 |
return nullptr; |
128 |
return nullptr; |
| 154 |
|
129 |
|
| 155 |
GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0; |
130 |
GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr; |
| 156 |
auto context = window ? createWindowContext(window, sharingContext) : nullptr; |
131 |
auto context = window ? createWindowContext(window, sharingContext) : nullptr; |
| 157 |
if (!context) |
132 |
if (!context) |
| 158 |
context = createPbufferContext(glxSharingContext); |
133 |
context = createPbufferContext(glxSharingContext); |
|
Lines 164-186
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext*
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec5
|
| 164 |
return WTF::move(context); |
139 |
return WTF::move(context); |
| 165 |
} |
140 |
} |
| 166 |
|
141 |
|
| 167 |
GLContextGLX::GLContextGLX(GLXContext context) |
142 |
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XID window) |
| 168 |
: m_context(context) |
143 |
: m_context(WTF::move(context)) |
| 169 |
, m_window(0) |
144 |
, m_window(window) |
| 170 |
, m_pbuffer(0) |
|
|
| 171 |
, m_pixmap(0) |
| 172 |
, m_glxPixmap(0) |
| 173 |
, m_cairoDevice(0) |
| 174 |
{ |
145 |
{ |
| 175 |
} |
146 |
} |
| 176 |
|
147 |
|
| 177 |
GLContextGLX::GLContextGLX(GLXContext context, Pixmap pixmap, GLXPixmap glxPixmap) |
148 |
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniqueGLXPbuffer&& pbuffer) |
| 178 |
: m_context(context) |
149 |
: m_context(WTF::move(context)) |
| 179 |
, m_window(0) |
150 |
, m_pbuffer(WTF::move(pbuffer)) |
| 180 |
, m_pbuffer(0) |
151 |
{ |
| 181 |
, m_pixmap(pixmap) |
152 |
} |
| 182 |
, m_glxPixmap(glxPixmap) |
153 |
|
| 183 |
, m_cairoDevice(0) |
154 |
GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniquePixmap&& pixmap, XUniqueGLXPixmap&& glxPixmap) |
|
|
155 |
: m_context(WTF::move(context)) |
| 156 |
, m_pixmap(WTF::move(pixmap)) |
| 157 |
, m_glxPixmap(WTF::move(glxPixmap)) |
| 184 |
{ |
158 |
{ |
| 185 |
} |
159 |
} |
| 186 |
|
160 |
|
|
Lines 189-214
GLContextGLX::~GLContextGLX()
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec6
|
| 189 |
if (m_cairoDevice) |
163 |
if (m_cairoDevice) |
| 190 |
cairo_device_destroy(m_cairoDevice); |
164 |
cairo_device_destroy(m_cairoDevice); |
| 191 |
|
165 |
|
| 192 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
|
|
| 193 |
if (m_context) { |
166 |
if (m_context) { |
| 194 |
// This may be necessary to prevent crashes with NVidia's closed source drivers. Originally |
167 |
// This may be necessary to prevent crashes with NVidia's closed source drivers. Originally |
| 195 |
// from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/ |
168 |
// from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/ |
|
|
169 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
| 196 |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
170 |
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
| 197 |
glXMakeCurrent(display, None, None); |
171 |
glXMakeCurrent(display, None, None); |
| 198 |
glXDestroyContext(display, m_context); |
|
|
| 199 |
} |
| 200 |
|
| 201 |
if (m_pbuffer) { |
| 202 |
glXDestroyPbuffer(display, m_pbuffer); |
| 203 |
m_pbuffer = 0; |
| 204 |
} |
| 205 |
if (m_glxPixmap) { |
| 206 |
glXDestroyGLXPixmap(display, m_glxPixmap); |
| 207 |
m_glxPixmap = 0; |
| 208 |
} |
| 209 |
if (m_pixmap) { |
| 210 |
XFreePixmap(display, m_pixmap); |
| 211 |
m_pixmap = 0; |
| 212 |
} |
172 |
} |
| 213 |
} |
173 |
} |
| 214 |
|
174 |
|
|
Lines 237-253
bool GLContextGLX::makeContextCurrent()
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec7
|
| 237 |
ASSERT(m_context && (m_window || m_pbuffer || m_glxPixmap)); |
197 |
ASSERT(m_context && (m_window || m_pbuffer || m_glxPixmap)); |
| 238 |
|
198 |
|
| 239 |
GLContext::makeContextCurrent(); |
199 |
GLContext::makeContextCurrent(); |
| 240 |
if (glXGetCurrentContext() == m_context) |
200 |
if (glXGetCurrentContext() == m_context.get()) |
| 241 |
return true; |
201 |
return true; |
| 242 |
|
202 |
|
| 243 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
203 |
Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); |
| 244 |
if (m_window) |
204 |
if (m_window) |
| 245 |
return glXMakeCurrent(display, m_window, m_context); |
205 |
return glXMakeCurrent(display, m_window, m_context.get()); |
| 246 |
|
206 |
|
| 247 |
if (m_pbuffer) |
207 |
if (m_pbuffer) |
| 248 |
return glXMakeCurrent(display, m_pbuffer, m_context); |
208 |
return glXMakeCurrent(display, m_pbuffer.get(), m_context.get()); |
| 249 |
|
209 |
|
| 250 |
return ::glXMakeCurrent(display, m_glxPixmap, m_context); |
210 |
return ::glXMakeCurrent(display, m_glxPixmap.get(), m_context.get()); |
| 251 |
} |
211 |
} |
| 252 |
|
212 |
|
| 253 |
void GLContextGLX::swapBuffers() |
213 |
void GLContextGLX::swapBuffers() |
|
Lines 267-273
cairo_device_t* GLContextGLX::cairoDevice()
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec8
|
| 267 |
return m_cairoDevice; |
227 |
return m_cairoDevice; |
| 268 |
|
228 |
|
| 269 |
#if ENABLE(ACCELERATED_2D_CANVAS) |
229 |
#if ENABLE(ACCELERATED_2D_CANVAS) |
| 270 |
m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context); |
230 |
m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context.get()); |
| 271 |
#endif |
231 |
#endif |
| 272 |
|
232 |
|
| 273 |
return m_cairoDevice; |
233 |
return m_cairoDevice; |
|
Lines 276-282
cairo_device_t* GLContextGLX::cairoDevice()
a/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp_sec9
|
| 276 |
#if ENABLE(GRAPHICS_CONTEXT_3D) |
236 |
#if ENABLE(GRAPHICS_CONTEXT_3D) |
| 277 |
PlatformGraphicsContext3D GLContextGLX::platformContext() |
237 |
PlatformGraphicsContext3D GLContextGLX::platformContext() |
| 278 |
{ |
238 |
{ |
| 279 |
return m_context; |
239 |
return m_context.get(); |
| 280 |
} |
240 |
} |
| 281 |
#endif |
241 |
#endif |
| 282 |
|
242 |
|