Qt 4.8
Public Functions | Protected Functions | Protected Variables | Private Functions | List of all members
QDri2Context Class Reference

#include <qdri2context.h>

Inheritance diagram for QDri2Context:
QPlatformGLContext

Public Functions

void doneCurrent ()
 Reimplement in subclass to release current context. More...
 
void * eglContext () const
 
void * getProcAddress (const QString &procName)
 Reimplement in subclass to native getProcAddr calls. More...
 
void makeCurrent ()
 Reimplement in subclass to do makeCurrent on native GL context. More...
 
QPlatformWindowFormat platformWindowFormat () const
 QWidget has the function qplatformWindowFormat(). More...
 
 QDri2Context (QXcbWindow *window)
 
void resize (const QSize &size)
 
void swapBuffers ()
 Reimplement in subclass to native swap buffers calls. More...
 
 ~QDri2Context ()
 
- Public Functions inherited from QPlatformGLContext
 QPlatformGLContext ()
 All subclasses needs to specify the platformWindow. More...
 
virtual ~QPlatformGLContext ()
 If this is the current context for the thread, doneCurrent is called. More...
 

Protected Functions

xcb_dri2_dri2_buffer_t * backBuffer ()
 

Protected Variables

QScopedPointer< QDri2ContextPrivated_ptr
 
- Protected Variables inherited from QPlatformGLContext
QScopedPointer< QPlatformGLContextPrivated_ptr
 

Private Functions

 Q_DECLARE_PRIVATE (QDri2Context)
 

Additional Inherited Members

- Static Public Functions inherited from QPlatformGLContext
static const QPlatformGLContextcurrentContext ()
 Returns the last context which called makeCurrent. More...
 

Detailed Description

Definition at line 52 of file qdri2context.h.

Constructors and Destructors

◆ QDri2Context()

QDri2Context::QDri2Context ( QXcbWindow window)

Definition at line 89 of file qdri2context.cpp.

90  : d_ptr(new QDri2ContextPrivate(window))
91 {
93 
94  static const EGLint contextAttribs[] = {
95  EGL_CONTEXT_CLIENT_VERSION, 2,
96  EGL_NONE
97  };
98 
99  eglBindAPI(EGL_OPENGL_ES_API);
100 
101  EGLContext shareContext = EGL_NO_CONTEXT;
102  if (window->widget()->platformWindowFormat().sharedGLContext()) {
103  QDri2Context *context = static_cast<QDri2Context *>(window->widget()->platformWindowFormat().sharedGLContext());
104  shareContext = context->d_func()->eglContext;
105  }
106  d->eglContext = eglCreateContext(EGL_DISPLAY_FROM_XCB(d->qXcbWindow), NULL,
107  shareContext, contextAttribs);
108 
109  if (d->eglContext == EGL_NO_CONTEXT) {
110  qDebug() << "No eglContext!" << eglGetError();
111  }
112 
113  EGLBoolean makeCurrentSuccess = eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,d->eglContext);
114  if (!makeCurrentSuccess) {
115  qDebug() << "eglMakeCurrent failed!" << eglGetError();
116  }
117 
118  xcb_dri2_create_drawable (d->xcbConnection(), d->xcbWindow());
119 
120  glGenFramebuffers(1,&d->fbo);
123 
124  glGenRenderbuffers(1, &d->rbo);
126 
127  glGenRenderbuffers(1,&d->depth);
129 
130  resize(d->qXcbWindow->widget()->geometry().size());
131 
135 
136  //restore the old current context
138  if (currentContext)
140 }
static const QPlatformGLContext * currentContext()
Returns the last context which called makeCurrent.
double d
Definition: qnumeric_p.h:62
#define glGenRenderbuffers
#define glBindFramebuffer
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_RENDERBUFFER
#define GL_DEPTH_ATTACHMENT
Q_CORE_EXPORT void qDebug(const char *,...)
#define GL_TEXTURE0
Definition: glfunctions.h:61
#define glGenFramebuffers
void * eglContext() const
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
#define GL_FRAMEBUFFER
void resize(const QSize &size)
#define glBindRenderbuffer
#define glActiveTexture
Definition: glfunctions.h:69
The QPlatformGLContext class provides an abstraction for native GL contexts.
#define GL_RENDERER
#define GL_STENCIL_ATTACHMENT
#define GL_COLOR_ATTACHMENT0
#define glFramebufferRenderbuffer
QScopedPointer< QDri2ContextPrivate > d_ptr
Definition: qdri2context.h:72
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ ~QDri2Context()

QDri2Context::~QDri2Context ( )

Definition at line 142 of file qdri2context.cpp.

143 {
144  //cleanup
145 }

Functions

◆ backBuffer()

xcb_dri2_dri2_buffer_t * QDri2Context::backBuffer ( )
protected

Definition at line 239 of file qdri2context.cpp.

Referenced by resize().

240 {
241  Q_D(QDri2Context);
242 
243  unsigned int backBufferAttachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT;
244  xcb_dri2_get_buffers_cookie_t cookie = xcb_dri2_get_buffers_unchecked (d->xcbConnection(),
245  d->xcbWindow(),
246  1, 1, &backBufferAttachment);
247 
248  xcb_dri2_get_buffers_reply_t *reply = xcb_dri2_get_buffers_reply (d->xcbConnection(), cookie, NULL);
249  if (!reply) {
250  qDebug() << "failed to get buffers reply";
251  return 0;
252  }
253 
254  xcb_dri2_dri2_buffer_t *buffers = xcb_dri2_get_buffers_buffers (reply);
255  if (!buffers) {
256  qDebug() << "failed to get buffers";
257  return 0;
258  }
259 
260  Q_ASSERT(reply->count == 1);
261 
262  delete reply;
263 
264  return buffers;
265 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)

◆ doneCurrent()

void QDri2Context::doneCurrent ( )
virtual

Reimplement in subclass to release current context.

Typically this is calling makeCurrent with 0 "surface"

Reimplemented from QPlatformGLContext.

Definition at line 157 of file qdri2context.cpp.

158 {
160  Q_D(QDri2Context);
161  eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
162 }
double d
Definition: qnumeric_p.h:62
virtual void doneCurrent()
Reimplement in subclass to release current context.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ eglContext()

void * QDri2Context::eglContext ( ) const

Definition at line 267 of file qdri2context.cpp.

Referenced by QXcbNativeInterface::eglContextForWidget(), and QDri2Context().

268 {
269  Q_D(const QDri2Context);
270  return d->eglContext;
271 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ getProcAddress()

void * QDri2Context::getProcAddress ( const QString procName)
virtual

Reimplement in subclass to native getProcAddr calls.

Note: its convenient to use qPrintable(const QString &str) to get the const char * pointer

Implements QPlatformGLContext.

Definition at line 191 of file qdri2context.cpp.

192 {
193  return (void *)eglGetProcAddress(qPrintable(procName));
194 }
#define qPrintable(string)
Definition: qglobal.h:1750

◆ makeCurrent()

void QDri2Context::makeCurrent ( )
virtual

Reimplement in subclass to do makeCurrent on native GL context.

Reimplemented from QPlatformGLContext.

Definition at line 147 of file qdri2context.cpp.

Referenced by QDri2Context().

148 {
150  Q_D(QDri2Context);
151 
152  eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,d->eglContext);
154 
155 }
double d
Definition: qnumeric_p.h:62
#define glBindFramebuffer
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
#define GL_FRAMEBUFFER

◆ platformWindowFormat()

QPlatformWindowFormat QDri2Context::platformWindowFormat ( ) const
virtual

QWidget has the function qplatformWindowFormat().

That function is for the application programmer to request the format of the window and the context that he wants.

Reimplement this function in a subclass to indicate what format the glContext actually has.

Implements QPlatformGLContext.

Definition at line 233 of file qdri2context.cpp.

234 {
235  Q_D(const QDri2Context);
236  return d->windowFormat;
237 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ Q_DECLARE_PRIVATE()

QDri2Context::Q_DECLARE_PRIVATE ( QDri2Context  )
private

◆ resize()

void QDri2Context::resize ( const QSize size)

Definition at line 196 of file qdri2context.cpp.

Referenced by QDri2Context().

197 {
198  Q_D(QDri2Context);
199  d->size= size;
200 
202 
203  xcb_dri2_dri2_buffer_t *backBfr = backBuffer();
204 
205  if (d->image) {
206  qDebug() << "destroing image";
207  eglDestroyImageKHR(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),d->image);
208  }
209 
210  EGLint imgAttribs[] = {
211  EGL_WIDTH, d->size.width(),
212  EGL_HEIGHT, d->size.height(),
213  EGL_DRM_BUFFER_STRIDE_MESA, backBfr->pitch /4,
214  EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
215  EGL_NONE
216  };
217 
218  d->image = eglCreateImageKHR(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),
219  EGL_NO_CONTEXT,
220  EGL_DRM_BUFFER_MESA,
221  (EGLClientBuffer) backBfr->name,
222  imgAttribs);
223 
226  d->image);
227 
229  glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8_OES,d->size.width(), d->size.height());
230 
231 }
double d
Definition: qnumeric_p.h:62
#define glBindFramebuffer
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_RENDERBUFFER
Q_CORE_EXPORT void qDebug(const char *,...)
Q_GUI_EXPORT EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
Definition: qegl.cpp:638
void * EGLClientBuffer
Definition: qegl_p.h:70
#define GL_FRAMEBUFFER
#define glBindRenderbuffer
#define glEGLImageTargetRenderbufferStorageOES
Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
Definition: qegl.cpp:625
#define glRenderbufferStorage
xcb_dri2_dri2_buffer_t * backBuffer()

◆ swapBuffers()

void QDri2Context::swapBuffers ( )
virtual

Reimplement in subclass to native swap buffers calls.

Implements QPlatformGLContext.

Definition at line 164 of file qdri2context.cpp.

165 {
166  Q_D(QDri2Context);
167  xcb_rectangle_t rectangle;
168  rectangle.x = 0;
169  rectangle.y = 0;
170  rectangle.width = d->qXcbWindow->widget()->geometry().width();
171  rectangle.height = d->qXcbWindow->widget()->geometry().height();
172 
173  xcb_xfixes_region_t xfixesRegion = xcb_generate_id(d->xcbConnection());
174  xcb_xfixes_create_region(d->xcbConnection(), xfixesRegion,
175  1, &rectangle);
176 
177  xcb_dri2_copy_region_cookie_t cookie = xcb_dri2_copy_region_unchecked(d->xcbConnection(),
178  d->qXcbWindow->window(),
179  xfixesRegion,
180  XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
181  XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
182 
183  xcb_dri2_copy_region_reply_t *reply = xcb_dri2_copy_region_reply(d->xcbConnection(),cookie,NULL);
184 
185  //cleanup
186  delete reply;
187  xcb_xfixes_destroy_region(d->xcbConnection(), xfixesRegion);
188 
189 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

Properties

◆ d_ptr

QScopedPointer<QDri2ContextPrivate> QDri2Context::d_ptr
protected

Definition at line 72 of file qdri2context.h.


The documentation for this class was generated from the following files: