43 #include <private/qt_x11_p.h> 44 #include <private/qpixmap_x11_p.h> 45 #include <private/qgl_p.h> 46 #include <private/qpaintengine_opengl_p.h> 73 d->initialized =
false;
84 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
86 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
91 eglChooseConfig(
d->display, attribs, &config, 1, &numConfigs);
93 qWarning(
"QGLTemporaryContext: No EGL configurations available.");
97 XVisualInfo visualInfo;
102 vi = XGetVisualInfo(
X11->display, VisualIDMask, &visualInfo, &numVisuals);
103 if (!vi || numVisuals < 1) {
104 qWarning(
"QGLTemporaryContext: Unable to get X11 visual info id.");
108 XSetWindowAttributes attr;
110 attr.background_pixel = 0;
111 attr.border_pixel = 0;
112 attr.colormap = XCreateColormap(
X11->display, DefaultRootWindow(
X11->display), vi->visual, AllocNone);
113 attr.event_mask = StructureNotifyMask | ExposureMask;
114 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
116 d->window = XCreateWindow(
X11->display, RootWindow(
X11->display, screen),
118 vi->depth, InputOutput, vi->visual,
123 if (
d->surface == EGL_NO_SURFACE) {
124 qWarning(
"QGLTemporaryContext: Error creating EGL surface.");
126 XDestroyWindow(
X11->display,
d->window);
130 EGLint contextAttribs[] = {
131 #ifdef QT_OPENGL_ES_2 132 EGL_CONTEXT_CLIENT_VERSION, 2,
136 d->context = eglCreateContext(
d->display, config, 0, contextAttribs);
137 if (
d->context != EGL_NO_CONTEXT
138 && eglMakeCurrent(
d->display,
d->surface,
d->surface,
d->context))
140 d->initialized =
true;
142 qWarning(
"QGLTemporaryContext: Error creating EGL context.");
143 eglDestroySurface(
d->display,
d->surface);
144 XDestroyWindow(
X11->display,
d->window);
151 if (
d->initialized) {
152 eglMakeCurrent(
d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
153 eglDestroyContext(
d->display,
d->context);
154 eglDestroySurface(
d->display,
d->surface);
155 XDestroyWindow(
X11->display,
d->window);
172 int devType = device()->devType();
178 x11PixmapData = static_cast<QX11PixmapData*>(pmd);
181 qWarning(
"WARNING: Creating a QGLContext on a QPixmap is only supported for X11 pixmap backend");
185 qWarning(
"WARNING: Creating a QGLContext not supported on device type %d", devType);
190 if (
d->eglContext == 0) {
192 d->ownsEglContext =
true;
200 d->glFormat.setAlpha(
true);
210 if ((devType ==
QInternal::Widget) && qobject_cast<QGLWidget*>(static_cast<QWidget*>(device())) == 0)
211 configProps.
setValue(EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
214 delete d->eglContext;
220 QEglContext* eglSharedContext = shareContext ? shareContext->d_func()->eglContext : 0;
221 if (!
d->eglContext->createContext(eglSharedContext)) {
222 delete d->eglContext;
226 d->sharing =
d->eglContext->isSharing();
227 if (
d->sharing && shareContext)
228 const_cast<QGLContext *
>(shareContext)->d_func()->sharing =
true;
241 if (
d->eglSurface != EGL_NO_SURFACE)
242 eglDestroySurface(
d->eglContext->display(),
d->eglSurface);
244 d->eglSurface =
QEgl::createSurface(device(),
d->eglContext->config(),
d->extraWindowSurfaceCreationProps);
245 XFlush(
X11->display);
246 setWindowCreated(
true);
252 eglDestroySurface(
d->eglContext->display(), (EGLSurface)x11PixmapData->
gl_surface);
262 qFatal(
"QGLContext::chooseVisual - this method must not be called as Qt is built with EGL support");
270 qFatal(
"QGLContext::tryVisual - this method must not be called as Qt is built with EGL support");
280 if (!
d->glcx->initialized())
282 resizeGL(width(), height());
305 qWarning(
"QGLWidget::setContext: Cannot set null context");
309 qWarning(
"QGLWidget::setContext: Context must refer to this widget");
314 d->glcx->doneCurrent();
318 bool createFailed =
false;
319 if (!
d->glcx->isValid()) {
322 if (!
d->glcx->create(shareContext ? shareContext : oldcx))
326 if (deleteOldContext)
332 d->eglSurfaceWindowId = winId();
339 initContext(context, shareWidget);
341 if (q->isValid() && glcx->format().hasOverlay()) {
343 qWarning(
"QtOpenGL ES doesn't currently support overlays");
353 return d_func()->cmap;
361 void QGLWidgetPrivate::recreateEglSurface()
365 Window currentId = q->winId();
370 if (glcx->d_func()->eglSurface != EGL_NO_SURFACE && (currentId != eglSurfaceWindowId)) {
371 qWarning(
"EGL surface for deleted window %lx was not destroyed",
uint(eglSurfaceWindowId));
372 glcx->d_func()->destroyEglSurfaceForDevice();
375 if (glcx->d_func()->eglSurface == EGL_NO_SURFACE) {
376 glcx->d_func()->eglSurface = glcx->d_func()->eglContext->createSurface(q);
377 eglSurfaceWindowId = currentId;
383 QGLContext::BindOptions options)
392 static bool checkedForTFP =
false;
393 static bool haveTFP =
false;
394 static bool checkedForEglImageTFP =
false;
395 static bool haveEglImageTFP =
false;
398 if (!checkedForEglImageTFP) {
399 checkedForEglImageTFP =
true;
413 qDebug(
"Found EGL_KHR_image_pixmap & GL_OES_EGL_image extensions (preferred method)!");
417 if (!checkedForTFP) {
419 checkedForTFP =
true;
423 qDebug(
"Found texture_from_pixmap EGL extension!");
428 if (!haveTFP && !haveEglImageTFP)
435 bool pixmapHasValidSurface =
false;
436 bool textureIsBound =
false;
438 glGenTextures(1, &textureId);
444 pixmapHasValidSurface =
true;
448 if (pixmapHasValidSurface) {
451 if (success == EGL_FALSE) {
454 pixmapData->
gl_surface = (
void*)EGL_NO_SURFACE;
456 textureIsBound =
true;
461 if (!textureIsBound && haveEglImageTFP) {
474 GLint err = glGetError();
476 textureIsBound =
true;
484 if (!textureIsBound && haveTFP) {
490 destroyGlSurfaceForPixmap(pixmapData);
499 if (pixmapData->
gl_surface == (
void*)EGL_NO_SURFACE)
505 if (success == EGL_FALSE) {
508 pixmapData->
gl_surface = (
void*)EGL_NO_SURFACE;
511 textureIsBound =
true;
516 if (textureIsBound) {
525 glDeleteTextures(1, &textureId);
535 if (pixmapData->gl_surface) {
537 success = eglDestroySurface(
QEgl::display(), (EGLSurface)pixmapData->gl_surface);
538 if (success == EGL_FALSE) {
539 qWarning() <<
"destroyGlSurfaceForPixmap() - Error deleting surface: " 542 pixmapData->gl_surface = 0;
550 if (pixmapData->gl_surface) {
553 (EGLSurface)pixmapData->gl_surface,
555 if (success == EGL_FALSE) {
556 qWarning() <<
"unbindPixmapFromTexture() - Unable to release bound texture: " void qt_glformat_from_eglconfig(QGLFormat &format, const EGLConfig config)
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost)
#define QT_END_NAMESPACE
This macro expands to.
static QGLTextureCache * instance()
virtual void * tryVisual(const QGLFormat &f, int bufDepth=1)
void setValue(int name, int value)
NativeWindowType EGLNativeWindowType
Q_GUI_EXPORT EGLNativePixmapType nativePixmap(QPixmap *)
QGLTexture * bindTextureFromNativePixmap(QPixmap *, const qint64 key, QGLContext::BindOptions options)
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Q_CORE_EXPORT void qDebug(const char *,...)
QPlatformGLContext * context
T * data() const
Returns a pointer to the shared data object.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT EGLDisplay display()
void setRenderableType(QEgl::API api)
Q_GUI_EXPORT EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
The QGLContext class encapsulates an OpenGL rendering context.
#define EGL_NATIVE_PIXMAP_KHR
The QResizeEvent class contains event parameters for resize events.
Q_CORE_EXPORT void qWarning(const char *,...)
QPaintDevice * device() const
Returns the paint device set for this context.
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
static void destroyGlSurfaceForPixmap(QPixmapData *)
The QGLColormap class is used for installing custom colormaps into a QGLWidget.
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
Q_GUI_EXPORT EGLConfig defaultConfig(int devType, API api, ConfigOptions options)
virtual void * chooseVisual()
X11 only: This virtual function tries to find a visual that matches the format, reducing the demands ...
Q_CORE_EXPORT void qFatal(const char *,...)
#define EGL_IMAGE_PRESERVED_KHR
virtual bool chooseContext(const QGLContext *shareContext=0)
This semi-internal function is called by create().
Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs=0)
bool hasAlphaChannel() const
void * data_ptr(const QTransform &t)
bool qt_resolve_eglimage_gl_extensions(QGLContext *ctx)
QGLTemporaryContext(bool directRendering=true, QWidget *parent=0)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT VisualID getCompatibleVisualId(EGLConfig config)
Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
static void unbindPixmapFromTexture(QPixmapData *)
void setDeviceType(int devType)
void qt_eglproperties_set_glformat(QEglProperties &eglProperties, const QGLFormat &glFormat)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
#define glEGLImageTargetTexture2DOES