OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 2 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 12 matching lines...) Expand all Loading... |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "GLXSurface.h" | 27 #include "GLXSurface.h" |
28 | 28 |
29 #if USE(ACCELERATED_COMPOSITING) && USE(GLX) | 29 #if USE(ACCELERATED_COMPOSITING) && USE(GLX) |
30 | 30 |
31 namespace WebCore { | 31 namespace WebCore { |
32 | 32 |
33 static PFNGLXBINDTEXIMAGEEXTPROC pGlXBindTexImageEXT = 0; | 33 static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGH
T, 1, 0 }; |
34 static PFNGLXRELEASETEXIMAGEEXTPROC pGlXReleaseTexImageEXT = 0; | |
35 | 34 |
36 static bool resolveGLMethods() | 35 GLXTransportSurface::GLXTransportSurface(SurfaceAttributes attributes) |
37 { | 36 : GLTransportSurface(attributes) |
38 static bool resolved = false; | |
39 if (resolved) | |
40 return true; | |
41 | |
42 pGlXBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glXGetProc
Address(reinterpret_cast<const GLubyte*>("glXBindTexImageEXT"))); | |
43 pGlXReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glXG
etProcAddress(reinterpret_cast<const GLubyte*>("glXReleaseTexImageEXT"))); | |
44 | |
45 resolved = pGlXBindTexImageEXT && pGlXReleaseTexImageEXT; | |
46 | |
47 return resolved; | |
48 } | |
49 | |
50 static int glxAttributes[] = { | |
51 GLX_TEXTURE_FORMAT_EXT, | |
52 GLX_TEXTURE_FORMAT_RGBA_EXT, | |
53 GLX_TEXTURE_TARGET_EXT, | |
54 GLX_TEXTURE_2D_EXT, | |
55 0 | |
56 }; | |
57 | |
58 static bool isMesaGLX() | |
59 { | |
60 static bool isMesa = !!strstr(glXGetClientString(X11Helper::nativeDisplay(),
GLX_VENDOR), "Mesa"); | |
61 return isMesa; | |
62 } | |
63 | |
64 GLXTransportSurface::GLXTransportSurface(const IntSize& size, SurfaceAttributes
attributes) | |
65 : GLTransportSurface(size, attributes) | |
66 { | 37 { |
67 m_sharedDisplay = X11Helper::nativeDisplay(); | 38 m_sharedDisplay = X11Helper::nativeDisplay(); |
68 attributes |= GLPlatformSurface::DoubleBuffered; | 39 attributes |= GLPlatformSurface::DoubleBuffered; |
69 m_configSelector = adoptPtr(new GLXConfigSelector(attributes)); | 40 m_configSelector = adoptPtr(new GLXConfigSelector(attributes)); |
70 OwnPtrX11<XVisualInfo> visInfo(m_configSelector->visualInfo(m_configSelector
->surfaceContextConfig())); | 41 OwnPtrX11<XVisualInfo> visInfo(m_configSelector->visualInfo(m_configSelector
->surfaceContextConfig())); |
71 | 42 |
72 if (!visInfo.get()) { | 43 if (!visInfo.get()) { |
73 destroy(); | 44 destroy(); |
74 return; | 45 return; |
75 } | 46 } |
76 | 47 |
77 X11Helper::createOffScreenWindow(&m_bufferHandle, *visInfo.get(), size); | 48 X11Helper::createOffScreenWindow(&m_bufferHandle, *visInfo.get()); |
78 | 49 |
79 if (!m_bufferHandle) { | 50 if (!m_bufferHandle) { |
80 destroy(); | 51 destroy(); |
81 return; | 52 return; |
82 } | 53 } |
83 | 54 |
84 m_drawable = m_bufferHandle; | 55 m_drawable = m_bufferHandle; |
85 } | 56 } |
86 | 57 |
87 GLXTransportSurface::~GLXTransportSurface() | 58 GLXTransportSurface::~GLXTransportSurface() |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 159 |
189 if (m_pixmap) { | 160 if (m_pixmap) { |
190 X11Helper::destroyPixmap(m_pixmap); | 161 X11Helper::destroyPixmap(m_pixmap); |
191 m_pixmap = 0; | 162 m_pixmap = 0; |
192 } | 163 } |
193 | 164 |
194 m_configSelector = nullptr; | 165 m_configSelector = nullptr; |
195 m_drawable = 0; | 166 m_drawable = 0; |
196 } | 167 } |
197 | 168 |
198 GLXTransportSurfaceClient::GLXTransportSurfaceClient(const PlatformBufferHandle
handle) | |
199 : GLTransportSurfaceClient(handle) | |
200 { | |
201 if (!resolveGLMethods()) | |
202 return; | |
203 | |
204 XWindowAttributes attr; | |
205 Display* display = X11Helper::nativeDisplay(); | |
206 if (!XGetWindowAttributes(display, handle, &attr)) | |
207 return; | |
208 | |
209 // Ensure that the window is mapped. | |
210 if (attr.map_state == IsUnmapped || attr.map_state == IsUnviewable) | |
211 return; | |
212 | |
213 ScopedXPixmapCreationErrorHandler handler; | |
214 | |
215 XRenderPictFormat* format = XRenderFindVisualFormat(display, attr.visual); | |
216 bool hasAlpha = (format->type == PictTypeDirect && format->direct.alphaMask)
; | |
217 m_xPixmap = XCompositeNameWindowPixmap(display, handle); | |
218 | |
219 if (!m_xPixmap) | |
220 return; | |
221 | |
222 glxAttributes[1] = (format->depth == 32 && hasAlpha) ? GLX_TEXTURE_FORMAT_RG
BA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT; | |
223 | |
224 GLPlatformSurface::SurfaceAttributes sharedSurfaceAttributes = GLPlatformSur
face::Default; | |
225 | |
226 if (hasAlpha) { | |
227 sharedSurfaceAttributes = GLPlatformSurface::SupportAlpha; | |
228 m_hasAlpha = true; | |
229 } | |
230 | |
231 GLXConfigSelector configSelector(sharedSurfaceAttributes); | |
232 | |
233 m_glxPixmap = glXCreatePixmap(display, configSelector.surfaceClientConfig(fo
rmat->depth, XVisualIDFromVisual(attr.visual)), m_xPixmap, glxAttributes); | |
234 | |
235 if (!m_glxPixmap || !handler.isValidOperation()) { | |
236 destroy(); | |
237 return; | |
238 } | |
239 | |
240 createTexture(); | |
241 glXWaitX(); | |
242 pGlXBindTexImageEXT(display, m_glxPixmap, GLX_FRONT_EXT, 0); | |
243 } | |
244 | |
245 GLXTransportSurfaceClient::~GLXTransportSurfaceClient() | |
246 { | |
247 } | |
248 | |
249 void GLXTransportSurfaceClient::destroy() | |
250 { | |
251 Display* display = X11Helper::nativeDisplay(); | |
252 if (!display) | |
253 return; | |
254 | |
255 if (m_texture) { | |
256 pGlXReleaseTexImageEXT(display, m_glxPixmap, GLX_FRONT_EXT); | |
257 GLTransportSurfaceClient::destroy(); | |
258 } | |
259 | |
260 if (m_glxPixmap) { | |
261 glXDestroyPixmap(display, m_glxPixmap); | |
262 m_glxPixmap = 0; | |
263 glXWaitGL(); | |
264 } | |
265 | |
266 if (m_xPixmap) { | |
267 X11Helper::destroyPixmap(m_xPixmap); | |
268 m_xPixmap = 0; | |
269 } | |
270 } | |
271 | |
272 void GLXTransportSurfaceClient::prepareTexture() | |
273 { | |
274 if (isMesaGLX() && m_texture) { | |
275 Display* display = X11Helper::nativeDisplay(); | |
276 glBindTexture(GL_TEXTURE_2D, m_texture); | |
277 // Mesa doesn't re-bind texture to the front buffer on glXSwapBufer | |
278 // Manually release previous lock and rebind texture to surface to ensur
e frame updates. | |
279 pGlXReleaseTexImageEXT(display, m_glxPixmap, GLX_FRONT_EXT); | |
280 pGlXBindTexImageEXT(display, m_glxPixmap, GLX_FRONT_EXT, 0); | |
281 } | |
282 } | |
283 | |
284 } | 169 } |
285 | 170 |
286 #endif | 171 #endif |
OLD | NEW |