1 #include "xcompositeglxintegration.h"
3 #include "waylandobject.h"
4 #include "wayland_wrapper/wlcompositor.h"
5 #include "wayland-xcomposite-server-protocol.h"
7 #include <QtGui/QPlatformNativeInterface>
8 #include <QtGui/QPlatformGLContext>
9 #include <private/qapplication_p.h>
11 #include "xcompositebuffer.h"
12 #include "xcompositehandler.h"
13 #include <X11/extensions/Xcomposite.h>
15 #include <QtCore/QDebug>
17 QVector<int> qglx_buildSpec()
19 QVector<int> spec(48);
22 spec[i++] = GLX_LEVEL;
24 spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_PIXMAP_BIT;
25 spec[i++] = GLX_BIND_TO_TEXTURE_TARGETS_EXT; spec[i++] = GLX_TEXTURE_2D_BIT_EXT;
26 spec[i++] = GLX_BIND_TO_TEXTURE_RGB_EXT; spec[i++] = TRUE;
33 struct wl_xcomposite_interface XCompositeHandler::xcomposite_interface = {
34 XCompositeHandler::create_buffer
37 GraphicsHardwareIntegration *GraphicsHardwareIntegration::createGraphicsHardwareIntegration(WaylandCompositor *compositor)
39 return new XCompositeGLXIntegration(compositor);
42 XCompositeGLXIntegration::XCompositeGLXIntegration(WaylandCompositor *compositor)
43 : GraphicsHardwareIntegration(compositor)
46 QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
47 if (nativeInterface) {
48 mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWidget("Display",m_compositor->topLevelWidget()));
50 qFatal("could not retireve Display from platform integration");
52 qFatal("Platform integration doesn't have native interface");
54 mScreen = XDefaultScreen(mDisplay);
57 void XCompositeGLXIntegration::initializeHardware(Wayland::Display *waylandDisplay)
59 XCompositeHandler *handler = new XCompositeHandler(m_compositor->handle(),mDisplay,m_compositor->topLevelWidget());
60 waylandDisplay->addGlobalObject(handler->base(), &wl_xcomposite_interface, &XCompositeHandler::xcomposite_interface,XCompositeHandler::send_root_information);
62 QPlatformGLContext *glContext = m_compositor->topLevelWidget()->platformWindow()->glContext();
64 m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT"));
65 if (!m_glxBindTexImageEXT) {
66 qDebug() << "Did not find glxBindTexImageExt, everything will FAIL!";
68 m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT"));
69 if (!m_glxReleaseTexImageEXT) {
70 qDebug() << "Did not find glxReleaseTexImageExt";
74 GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer)
76 XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer);
77 Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
79 QVector<int> glxConfigSpec = qglx_buildSpec();
81 GLXFBConfig *configs = glXChooseFBConfig(mDisplay,mScreen,glxConfigSpec.constData(),&numberOfConfigs);
83 QVector<int> attribList;
84 attribList.append(GLX_TEXTURE_FORMAT_EXT);
85 attribList.append(GLX_TEXTURE_FORMAT_RGB_EXT);
86 attribList.append(GLX_TEXTURE_TARGET_EXT);
87 attribList.append(GLX_TEXTURE_2D_EXT);
89 GLXPixmap glxPixmap = glXCreatePixmap(mDisplay,*configs,pixmap,attribList.constData());
92 glXQueryDrawable(mDisplay, glxPixmap, GLX_Y_INVERTED_EXT,&inverted);
93 compositorBuffer->setInvertedY(!inverted);
98 glGenTextures(1,&textureId);
99 glBindTexture(GL_TEXTURE_2D, textureId);
100 m_glxBindTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT, 0);
101 //Do we need to change the api so that we do bind and release in the painevent?
102 //The specification states that when deleting the texture the color buffer is deleted
103 // m_glxReleaseTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT);
107 bool XCompositeGLXIntegration::isYInverted(wl_buffer *buffer) const
109 XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer);
110 return compositorBuffer->isYInverted();