Qt 4.8
Public Functions | Public Variables | Properties | List of all members
QX11GLSharedContexts Class Reference

Public Functions

void cleanup ()
 
bool isValid ()
 
 QX11GLSharedContexts ()
 
 ~QX11GLSharedContexts ()
 

Public Variables

QEglContextargbContext
 
QEglContextrgbContext
 
QGLContextsharedQGLContext
 

Properties

QPixmapsharePixmap
 
bool valid
 

Detailed Description

Definition at line 65 of file qpixmapdata_x11gl_egl.cpp.

Constructors and Destructors

◆ QX11GLSharedContexts()

QX11GLSharedContexts::QX11GLSharedContexts ( )
inline

Definition at line 68 of file qpixmapdata_x11gl_egl.cpp.

69  : rgbContext(0)
70  , argbContext(0)
71  , sharedQGLContext(0)
72  , sharePixmap(0)
73  {
74  EGLint rgbConfigId;
75  EGLint argbConfigId;
76 
77  do {
79  EGLConfig argbConfig = QEgl::defaultConfig(QInternal::Pixmap, QEgl::OpenGL,
81 
82  eglGetConfigAttrib(QEgl::display(), rgbConfig, EGL_CONFIG_ID, &rgbConfigId);
83  eglGetConfigAttrib(QEgl::display(), argbConfig, EGL_CONFIG_ID, &argbConfigId);
84 
85  rgbContext = new QEglContext;
86  rgbContext->setConfig(rgbConfig);
88 
89  if (!rgbContext->isValid())
90  break;
91 
92  // If the RGB & ARGB configs are the same, use the same egl context for both:
93  if (rgbConfig == argbConfig)
95 
96  // Otherwise, create a separate context to be used for ARGB pixmaps:
97  if (!argbContext) {
99  argbContext->setConfig(argbConfig);
100  bool success = argbContext->createContext(rgbContext);
101  if (!success) {
102  qWarning("QX11GLPixmapData - RGB & ARGB contexts aren't shared");
103  success = argbContext->createContext();
104  if (!success)
105  argbContext = rgbContext; // Might work, worth a shot at least.
106  }
107  }
108 
109  if (!argbContext->isValid())
110  break;
111 
112  // Create the pixmap which will be used to create the egl surface for the share QGLContext
114  rgbPixmapData->resize(8, 8);
115  rgbPixmapData->fill(Qt::red);
116  sharePixmap = new QPixmap(rgbPixmapData);
117  EGLSurface sharePixmapSurface = QEgl::createSurface(sharePixmap, rgbConfig);
118  rgbPixmapData->gl_surface = (void*)sharePixmapSurface;
119 
120  // Create the actual QGLContext which will be used for sharing
122  sharedQGLContext->d_func()->eglContext = rgbContext;
123  sharedQGLContext->d_func()->eglSurface = sharePixmapSurface;
124  sharedQGLContext->d_func()->valid = true;
125  qt_glformat_from_eglconfig(sharedQGLContext->d_func()->glFormat, rgbConfig);
126 
127 
128  valid = rgbContext->makeCurrent(sharePixmapSurface);
129 
130  // If the ARGB & RGB configs are different, check ARGB works too:
131  if (argbConfig != rgbConfig) {
133  argbPixmapData->resize(8, 8);
134  argbPixmapData->fill(Qt::transparent); // Force ARGB
135  QPixmap argbPixmap(argbPixmapData); // destroys pixmap data when goes out of scope
136  EGLSurface argbPixmapSurface = QEgl::createSurface(&argbPixmap, argbConfig);
137  valid = argbContext->makeCurrent(argbPixmapSurface);
139  eglDestroySurface(QEgl::display(), argbPixmapSurface);
140  argbPixmapData->gl_surface = 0;
141  }
142 
143  if (!valid) {
144  qWarning() << "Unable to make pixmap surface current:" << QEgl::errorString();
145  break;
146  }
147 
148  // The pixmap surface destruction hooks are installed by QGLTextureCache, so we
149  // must make sure this is instanciated:
151  } while(0);
152 
153  if (!valid)
154  cleanup();
155  else
156  qDebug("Using QX11GLPixmapData with EGL config %d for ARGB and config %d for RGB", argbConfigId, rgbConfigId);
157 
158  }
void qt_glformat_from_eglconfig(QGLFormat &format, const EGLConfig config)
Definition: qgl_egl.cpp:145
bool createContext(QEglContext *shareContext=0, const QEglProperties *properties=0)
Definition: qegl.cpp:361
bool isValid() const
Definition: qegl.cpp:116
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
static QGLFormat glFormat()
void resize(int width, int height)
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
Q_CORE_EXPORT void qDebug(const char *,...)
bool doneCurrent()
Definition: qegl.cpp:485
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
Q_GUI_EXPORT EGLConfig defaultConfig(int devType, API api, ConfigOptions options)
Definition: qegl.cpp:126
void fill(const QColor &color)
Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs=0)
Definition: qegl_x11.cpp:333
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433
void setConfig(EGLConfig config)
Definition: qeglcontext_p.h:97
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ ~QX11GLSharedContexts()

QX11GLSharedContexts::~QX11GLSharedContexts ( )
inline

Definition at line 160 of file qpixmapdata_x11gl_egl.cpp.

160  {
161  cleanup();
162  }

Functions

◆ cleanup()

void QX11GLSharedContexts::cleanup ( )
inline

Definition at line 164 of file qpixmapdata_x11gl_egl.cpp.

Referenced by QX11GLSharedContexts(), and ~QX11GLSharedContexts().

164  {
165  if (sharedQGLContext) {
166  delete sharedQGLContext;
167  sharedQGLContext = 0;
168  }
170  delete argbContext;
171  argbContext = 0;
172 
173  if (rgbContext) {
174  delete rgbContext;
175  rgbContext = 0;
176  }
177 
178  // Deleting the QPixmap will fire the pixmap destruction cleanup hooks which in turn
179  // will destroy the egl surface:
180  if (sharePixmap) {
181  delete sharePixmap;
182  sharePixmap = 0;
183  }
184  }

◆ isValid()

bool QX11GLSharedContexts::isValid ( )
inline

Definition at line 186 of file qpixmapdata_x11gl_egl.cpp.

Properties

◆ argbContext

QEglContext* QX11GLSharedContexts::argbContext

◆ rgbContext

QEglContext* QX11GLSharedContexts::rgbContext

◆ sharedQGLContext

QGLContext* QX11GLSharedContexts::sharedQGLContext

Definition at line 196 of file qpixmapdata_x11gl_egl.cpp.

Referenced by cleanup(), and QX11GLSharedContexts().

◆ sharePixmap

QPixmap* QX11GLSharedContexts::sharePixmap
private

Definition at line 198 of file qpixmapdata_x11gl_egl.cpp.

Referenced by cleanup(), and QX11GLSharedContexts().

◆ valid

bool QX11GLSharedContexts::valid
private

Definition at line 199 of file qpixmapdata_x11gl_egl.cpp.

Referenced by isValid(), and QX11GLSharedContexts().


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