summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qgl_p.h')
-rw-r--r--src/opengl/qgl_p.h363
1 files changed, 52 insertions, 311 deletions
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 4c22f0f3d7..668728be20 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -60,24 +60,18 @@
#include "QtCore/qthreadstorage.h"
#include "QtCore/qhash.h"
#include "QtCore/qatomic.h"
-#include "private/qwidget_p.h"
+#include "QtWidgets/private/qwidget_p.h"
+#include "QtGui/private/qopenglcontext_p.h"
#include "qcache.h"
#include "qglpaintdevice_p.h"
-#ifndef QT_NO_EGL
-#include <QtGui/private/qegl_p.h>
-#endif
-
-#if defined(Q_WS_QPA)
-#include <QtGui/QPlatformGLContext>
-#endif
+#include <QtGui/QOpenGLContext>
QT_BEGIN_NAMESPACE
class QGLContext;
class QGLOverlayWidget;
class QPixmap;
-class QPixmapFilter;
#ifdef Q_WS_MAC
# ifdef qDebug
# define old_qDebug qDebug
@@ -96,14 +90,6 @@ QT_END_INCLUDE_NAMESPACE
class QMacWindowChangeEvent;
#endif
-#ifdef Q_WS_QWS
-class QWSGLWindowSurface;
-#endif
-
-#ifndef QT_NO_EGL
-class QEglContext;
-#endif
-
QT_BEGIN_INCLUDE_NAMESPACE
#include <QtOpenGL/private/qglextensions_p.h>
QT_END_INCLUDE_NAMESPACE
@@ -165,15 +151,6 @@ class Q_OPENGL_EXPORT QGLWidgetPrivate : public QWidgetPrivate
public:
QGLWidgetPrivate() : QWidgetPrivate()
, disable_clear_on_painter_begin(false)
-#if defined(Q_WS_QWS)
- , wsurf(0)
-#endif
-#if defined(Q_WS_X11) && !defined(QT_NO_EGL)
- , eglSurfaceWindowId(0)
-#endif
-#if defined(Q_OS_SYMBIAN)
- , eglSurfaceWindowId(0)
-#endif
{
isGLWidget = 1;
}
@@ -199,31 +176,8 @@ public:
#endif
bool disable_clear_on_painter_begin;
-
-#if defined(Q_WS_WIN)
- void updateColormap();
- QGLContext *olcx;
-#elif defined(Q_WS_X11)
- QGLOverlayWidget *olw;
-#ifndef QT_NO_EGL
- void recreateEglSurface();
- WId eglSurfaceWindowId;
-#endif
-#elif defined(Q_WS_MAC)
- QGLContext *olcx;
- void updatePaintDevice();
-#elif defined(Q_WS_QWS)
- QWSGLWindowSurface *wsurf;
-#endif
-#ifdef Q_OS_SYMBIAN
- void recreateEglSurface();
- WId eglSurfaceWindowId;
-#endif
};
-class QGLContextGroupResourceBase;
-class QGLSharedResourceGuard;
-
// QGLContextPrivate has the responsibility of creating context groups.
// QGLContextPrivate maintains the reference counter and destroys
// context groups when needed.
@@ -237,9 +191,6 @@ public:
bool isSharing() const { return m_shares.size() >= 2; }
QList<const QGLContext *> shares() const { return m_shares; }
- void addGuard(QGLSharedResourceGuard *guard);
- void removeGuard(QGLSharedResourceGuard *guard);
-
static void addShare(const QGLContext *context, const QGLContext *share);
static void removeShare(const QGLContext *context);
@@ -249,12 +200,8 @@ private:
QGLExtensionFuncs m_extensionFuncs;
const QGLContext *m_context; // context group's representative
QList<const QGLContext *> m_shares;
- QHash<QGLContextGroupResourceBase *, void *> m_resources;
- QGLSharedResourceGuard *m_guards; // double-linked list of active guards.
QAtomicInt m_refs;
- void cleanupResources(const QGLContext *ctx);
-
friend class QGLContext;
friend class QGLContextPrivate;
friend class QGLContextGroupResourceBase;
@@ -262,7 +209,7 @@ private:
// Get the context that resources for "ctx" will transfer to once
// "ctx" is destroyed. Returns null if nothing is sharing with ctx.
-Q_OPENGL_EXPORT const QGLContext *qt_gl_transfer_context(const QGLContext *);
+const QGLContext *qt_gl_transfer_context(const QGLContext *);
// GL extension definitions
class QGLExtensions {
@@ -351,54 +298,11 @@ public:
void syncGlState(); // Makes sure the GL context's state is what we think it is
void swapRegion(const QRegion &region);
-#if defined(Q_WS_WIN)
- void updateFormatVersion();
-#endif
+ QOpenGLContext *guiGlContext;
+ bool ownContext;
-#if defined(Q_WS_WIN)
- HGLRC rc;
- HDC dc;
- WId win;
- int pixelFormatId;
- QGLCmap* cmap;
- HBITMAP hbitmap;
- HDC hbitmap_hdc;
- Qt::HANDLE threadId;
-#endif
-#ifndef QT_NO_EGL
- QEglContext *eglContext;
- EGLSurface eglSurface;
- void destroyEglSurfaceForDevice();
- EGLSurface eglSurfaceForDevice() const;
- static QEglProperties *extraWindowSurfaceCreationProps;
- static void setExtraWindowSurfaceCreationProps(QEglProperties *props);
-#endif
-
-#if defined(Q_WS_QPA)
- QPlatformGLContext *platformContext;
void setupSharing();
-#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
- void* cx;
-#endif
-#if defined(Q_WS_X11) || defined(Q_WS_MAC)
- void* vi;
-#endif
-#if defined(Q_WS_X11)
- void* pbuf;
- quint32 gpm;
- int screen;
- QHash<QPixmapData*, QPixmap> boundPixmaps;
- QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key,
- QGLContext::BindOptions options);
- static void destroyGlSurfaceForPixmap(QPixmapData*);
- static void unbindPixmapFromTexture(QPixmapData*);
-#endif
-#if defined(Q_WS_MAC)
- bool update;
- void *tryFormat(const QGLFormat &format);
- void clearDrawable();
-#endif
QGLFormat glFormat;
QGLFormat reqFormat;
GLuint fbo;
@@ -423,10 +327,6 @@ public:
uint workaround_brokenAlphaTexSubImage : 1;
uint workaround_brokenAlphaTexSubImage_init : 1;
-#ifndef QT_NO_EGL
- uint ownsEglContext : 1;
-#endif
-
QPaintDevice *paintDevice;
QColor transpColor;
QGLContext *q_ptr;
@@ -439,7 +339,6 @@ public:
GLuint current_fbo;
GLuint default_fbo;
QPaintEngine *active_engine;
- QHash<QGLContextResourceBase *, void *> m_resources;
QGLTextureDestroyer *texture_destroyer;
QGLFunctions *functions;
@@ -448,14 +347,8 @@ public:
static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
-#ifdef Q_WS_WIN
- static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
-#endif
-
-#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN)
static Q_OPENGL_EXPORT QGLExtensionFuncs qt_extensionFuncs;
static Q_OPENGL_EXPORT QGLExtensionFuncs& extensionFuncs(const QGLContext *);
-#endif
static void setCurrentContext(QGLContext *context);
};
@@ -508,34 +401,19 @@ class Q_OPENGL_EXPORT QGLTextureDestroyer : public QObject
public:
QGLTextureDestroyer() : QObject() {
qRegisterMetaType<GLuint>("GLuint");
- connect(this, SIGNAL(freeTexture(QGLContext *, QPixmapData *, GLuint)),
- this, SLOT(freeTexture_slot(QGLContext *, QPixmapData *, GLuint)));
+ connect(this, SIGNAL(freeTexture(QGLContext *, QPlatformPixmap *, GLuint)),
+ this, SLOT(freeTexture_slot(QGLContext *, QPlatformPixmap *, GLuint)));
}
- void emitFreeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
+ void emitFreeTexture(QGLContext *context, QPlatformPixmap *boundPixmap, GLuint id) {
emit freeTexture(context, boundPixmap, id);
}
Q_SIGNALS:
- void freeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id);
+ void freeTexture(QGLContext *context, QPlatformPixmap *boundPixmap, GLuint id);
private slots:
- void freeTexture_slot(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
+ void freeTexture_slot(QGLContext *context, QPlatformPixmap *boundPixmap, GLuint id) {
Q_UNUSED(boundPixmap);
-#if defined(Q_WS_X11)
- if (boundPixmap) {
- QGLContext *oldContext = const_cast<QGLContext *>(QGLContext::currentContext());
- context->makeCurrent();
- // Although glXReleaseTexImage is a glX call, it must be called while there
- // is a current context - the context the pixmap was bound to a texture in.
- // Otherwise the release doesn't do anything and you get BadDrawable errors
- // when you come to delete the context.
- QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
- glDeleteTextures(1, &id);
- if (oldContext)
- oldContext->makeCurrent();
- return;
- }
-#endif
QGLShareContextScope scope(context);
glDeleteTextures(1, &id);
}
@@ -562,17 +440,12 @@ public:
id(tx_id),
target(tx_target),
options(opt)
-#if defined(Q_WS_X11)
- , boundPixmap(0)
-#endif
{}
~QGLTexture() {
if (options & QGLContext::MemoryManagedBindOption) {
Q_ASSERT(context);
-#if !defined(Q_WS_X11)
- QPixmapData *boundPixmap = 0;
-#endif
+ QPlatformPixmap *boundPixmap = 0;
context->d_ptr->texture_destroyer->emitFreeTexture(context, boundPixmap, id);
}
}
@@ -583,10 +456,6 @@ public:
QGLContext::BindOptions options;
-#if defined(Q_WS_X11)
- QPixmapData* boundPixmap;
-#endif
-
bool canBindCompressedTexture
(const char *buf, int len, const char *format, bool *hasAlpha);
QSize bindCompressedTexture
@@ -629,8 +498,8 @@ public:
void removeContextTextures(QGLContext *ctx);
static QGLTextureCache *instance();
static void cleanupTexturesForCacheKey(qint64 cacheKey);
- static void cleanupTexturesForPixampData(QPixmapData* pixmap);
- static void cleanupBeforePixmapDestruction(QPixmapData* pixmap);
+ static void cleanupTexturesForPixampData(QPlatformPixmap* pixmap);
+ static void cleanupBeforePixmapDestruction(QPlatformPixmap* pixmap);
private:
QCache<QGLTextureCacheKey, QGLTexture> m_cache;
@@ -661,199 +530,71 @@ QGLTexture* QGLTextureCache::getTexture(QGLContext *ctx, qint64 key)
return m_cache.object(cacheKey);
}
-extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
-
-bool qt_gl_preferGL2Engine();
-
-inline GLenum qt_gl_preferredTextureFormat()
-{
- return (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian
- ? GL_BGRA : GL_RGBA;
-}
-
-inline GLenum qt_gl_preferredTextureTarget()
-{
-#if defined(QT_OPENGL_ES_2)
- return GL_TEXTURE_2D;
-#else
- return (QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle)
- && !qt_gl_preferGL2Engine()
- ? GL_TEXTURE_RECTANGLE_NV
- : GL_TEXTURE_2D;
-#endif
-}
+extern QPaintEngine* qt_qgl_paint_engine();
-/*
- Base for resources that are shared in a context group.
-*/
-class Q_OPENGL_EXPORT QGLContextGroupResourceBase
-{
-public:
- QGLContextGroupResourceBase();
- virtual ~QGLContextGroupResourceBase();
- void insert(const QGLContext *context, void *value);
- void *value(const QGLContext *context);
- void cleanup(const QGLContext *context);
- void cleanup(const QGLContext *context, void *value);
- virtual void freeResource(void *value) = 0;
-
-protected:
- QList<QGLContextGroup *> m_groups;
-
-private:
- QAtomicInt active;
-};
-
-/*
- The QGLContextGroupResource template is used to manage a resource
- for a group of sharing GL contexts. When the last context in the
- group is destroyed, or when the QGLContextGroupResource object
- itself is destroyed (implies potential context switches), the
- resource will be freed.
-
- The class used as the template class type needs to have a
- constructor with the following signature:
- T(const QGLContext *);
-*/
-template <class T>
-class QGLContextGroupResource : public QGLContextGroupResourceBase
+// Put a guard around a GL object identifier and its context.
+// When the context goes away, a shared context will be used
+// in its place. If there are no more shared contexts, then
+// the identifier is returned as zero - it is assumed that the
+// context destruction cleaned up the identifier in this case.
+class QGLSharedResourceGuardBase : public QOpenGLSharedResource
{
public:
- ~QGLContextGroupResource() {
- for (int i = 0; i < m_groups.size(); ++i) {
- const QGLContext *context = m_groups.at(i)->context();
- T *resource = reinterpret_cast<T *>(QGLContextGroupResourceBase::value(context));
- if (resource) {
- QGLShareContextScope scope(context);
- delete resource;
- }
- }
+ QGLSharedResourceGuardBase(QGLContext *context, GLuint id)
+ : QOpenGLSharedResource(context->contextHandle()->shareGroup())
+ , m_id(id)
+ {
}
- T *value(const QGLContext *context) {
- T *resource = reinterpret_cast<T *>(QGLContextGroupResourceBase::value(context));
- if (!resource) {
- resource = new T(context);
- insert(context, resource);
- }
- return resource;
+ GLuint id() const
+ {
+ return m_id;
}
protected:
- void freeResource(void *resource) {
- delete reinterpret_cast<T *>(resource);
- }
-};
-
-/*
- Base for resources that are context specific.
-*/
-class Q_OPENGL_EXPORT QGLContextResourceBase
-{
-public:
- virtual ~QGLContextResourceBase() {
- for (int i = 0; i < m_contexts.size(); ++i)
- m_contexts.at(i)->d_ptr->m_resources.remove(this);
- }
-
- void insert(const QGLContext *context, void *value) {
- context->d_ptr->m_resources.insert(this, value);
- }
-
- void *value(const QGLContext *context) {
- return context->d_ptr->m_resources.value(this, 0);
+ void invalidateResource()
+ {
+ m_id = 0;
}
- virtual void freeResource(void *value) = 0;
-protected:
- QList<const QGLContext *> m_contexts;
-};
-
-/*
- The QGLContextResource template is used to manage a resource for a
- single GL context. Just before the context is destroyed (while it's
- still the current context), or when the QGLContextResource object
- itself is destroyed (implies potential context switches), the
- resource will be freed. The class used as the template class type
- needs to have a constructor with the following signature: T(const
- QGLContext *);
-*/
-template <class T>
-class QGLContextResource : public QGLContextResourceBase
-{
-public:
- ~QGLContextResource() {
- for (int i = 0; i < m_contexts.size(); ++i) {
- const QGLContext *context = m_contexts.at(i);
- T *resource = reinterpret_cast<T *>(QGLContextResourceBase::value(context));
- if (resource) {
- QGLShareContextScope scope(context);
- delete resource;
- }
+ void freeResource(QOpenGLContext *context)
+ {
+ if (m_id) {
+ freeResource(QGLContext::fromOpenGLContext(context), m_id);
}
}
- T *value(const QGLContext *context) {
- T *resource = reinterpret_cast<T *>(QGLContextResourceBase::value(context));
- if (!resource) {
- resource = new T(context);
- insert(context, resource);
- }
- return resource;
- }
+ virtual void freeResource(QGLContext *ctx, GLuint id) = 0;
-protected:
- void freeResource(void *resource) {
- delete reinterpret_cast<T *>(resource);
- }
+private:
+ GLuint m_id;
};
-// Put a guard around a GL object identifier and its context.
-// When the context goes away, a shared context will be used
-// in its place. If there are no more shared contexts, then
-// the identifier is returned as zero - it is assumed that the
-// context destruction cleaned up the identifier in this case.
-class Q_OPENGL_EXPORT QGLSharedResourceGuard
+template <typename Func>
+class QGLSharedResourceGuard : public QGLSharedResourceGuardBase
{
public:
- QGLSharedResourceGuard(const QGLContext *context)
- : m_group(0), m_id(0), m_next(0), m_prev(0)
- {
- setContext(context);
- }
- QGLSharedResourceGuard(const QGLContext *context, GLuint id)
- : m_group(0), m_id(id), m_next(0), m_prev(0)
+ QGLSharedResourceGuard(QGLContext *context, GLuint id, Func func)
+ : QGLSharedResourceGuardBase(context, id)
+ , m_func(func)
{
- setContext(context);
}
- ~QGLSharedResourceGuard();
- const QGLContext *context() const
- {
- return m_group ? m_group->context() : 0;
- }
-
- void setContext(const QGLContext *context);
-
- GLuint id() const
- {
- return m_id;
- }
-
- void setId(GLuint id)
+protected:
+ void freeResource(QGLContext *ctx, GLuint id)
{
- m_id = id;
+ m_func(ctx, id);
}
private:
- QGLContextGroup *m_group;
- GLuint m_id;
- QGLSharedResourceGuard *m_next;
- QGLSharedResourceGuard *m_prev;
-
- friend class QGLContextGroup;
+ Func m_func;
};
+template <typename Func>
+QGLSharedResourceGuardBase *createSharedResourceGuard(QGLContext *context, GLuint id, Func cleanupFunc)
+{
+ return new QGLSharedResourceGuard<Func>(context, id, cleanupFunc);
+}
class QGLExtensionMatcher
{