diff options
Diffstat (limited to 'src/declarative/scenegraph/util')
10 files changed, 131 insertions, 56 deletions
diff --git a/src/declarative/scenegraph/util/qsgflatcolormaterial.cpp b/src/declarative/scenegraph/util/qsgflatcolormaterial.cpp index d954f196ab..06ca28aff5 100644 --- a/src/declarative/scenegraph/util/qsgflatcolormaterial.cpp +++ b/src/declarative/scenegraph/util/qsgflatcolormaterial.cpp @@ -41,7 +41,7 @@ #include "qsgflatcolormaterial.h" -#include <qglshaderprogram.h> +#include <qopenglshaderprogram.h> QT_BEGIN_NAMESPACE diff --git a/src/declarative/scenegraph/util/qsgflatcolormaterial.h b/src/declarative/scenegraph/util/qsgflatcolormaterial.h index ffff7941a3..fb0411089a 100644 --- a/src/declarative/scenegraph/util/qsgflatcolormaterial.h +++ b/src/declarative/scenegraph/util/qsgflatcolormaterial.h @@ -43,6 +43,7 @@ #define FLATCOLORMATERIAL_H #include <qsgmaterial.h> +#include <qcolor.h> QT_BEGIN_HEADER diff --git a/src/declarative/scenegraph/util/qsgpainternode.cpp b/src/declarative/scenegraph/util/qsgpainternode.cpp index ab96591b76..9a02d8bedd 100644 --- a/src/declarative/scenegraph/util/qsgpainternode.cpp +++ b/src/declarative/scenegraph/util/qsgpainternode.cpp @@ -43,9 +43,10 @@ #include "qsgpainteditem.h" #include <private/qsgcontext_p.h> -#include <qglframebufferobject.h> -#include <qglfunctions.h> +#include <qopenglframebufferobject.h> +#include <qopenglfunctions.h> #include <qmath.h> +#include <qpainter.h> QT_BEGIN_NAMESPACE @@ -90,7 +91,7 @@ void QSGPainterTexture::bind() #endif if (m_has_mipmaps && !m_mipmaps_generated) { - const QGLContext *ctx = QGLContext::currentContext(); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); m_mipmaps_generated = true; } @@ -174,7 +175,7 @@ void QSGPainterNode::paint() m_texture->setImage(m_image); m_texture->setDirtyRect(dirtyRect); } else if (m_multisampledFbo) { - QGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect); + QOpenGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect); } m_dirtyRect = QRect(); @@ -249,8 +250,8 @@ void QSGPainterNode::updateRenderTarget() } if (m_actualRenderTarget == QSGPaintedItem::FramebufferObject) { - const QGLContext *ctx = QGLContext::currentContext(); - if (m_fbo && !m_dirtyGeometry && (!ctx->format().sampleBuffers() || !m_multisamplingSupported)) + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (m_fbo && !m_dirtyGeometry && (!ctx->format().samples() || !m_multisamplingSupported)) return; if (m_fboSize.isEmpty()) @@ -260,22 +261,22 @@ void QSGPainterNode::updateRenderTarget() delete m_multisampledFbo; m_fbo = m_multisampledFbo = 0; - if (m_smoothPainting && ctx->format().sampleBuffers() && m_multisamplingSupported) { + if (m_smoothPainting && ctx->format().samples() && m_multisamplingSupported) { { - QGLFramebufferObjectFormat format; - format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(ctx->format().samples()); - m_multisampledFbo = new QGLFramebufferObject(m_fboSize, format); + m_multisampledFbo = new QOpenGLFramebufferObject(m_fboSize, format); } { - QGLFramebufferObjectFormat format; - format.setAttachment(QGLFramebufferObject::NoAttachment); - m_fbo = new QGLFramebufferObject(m_fboSize, format); + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::NoAttachment); + m_fbo = new QOpenGLFramebufferObject(m_fboSize, format); } } else { - QGLFramebufferObjectFormat format; - format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); - m_fbo = new QGLFramebufferObject(m_fboSize, format); + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + m_fbo = new QOpenGLFramebufferObject(m_fboSize, format); } } else { if (!m_image.isNull() && !m_dirtyGeometry) diff --git a/src/declarative/scenegraph/util/qsgpainternode_p.h b/src/declarative/scenegraph/util/qsgpainternode_p.h index 5b0e9cef2c..50fb521405 100644 --- a/src/declarative/scenegraph/util/qsgpainternode_p.h +++ b/src/declarative/scenegraph/util/qsgpainternode_p.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QGLFramebufferObject; +class QOpenGLFramebufferObject; class Q_DECLARATIVE_EXPORT QSGPainterTexture : public QSGPlainTexture { @@ -115,8 +115,8 @@ private: QSGPaintedItem *m_item; - QGLFramebufferObject *m_fbo; - QGLFramebufferObject *m_multisampledFbo; + QOpenGLFramebufferObject *m_fbo; + QOpenGLFramebufferObject *m_multisampledFbo; QImage m_image; QSGOpaqueTextureMaterial m_material; diff --git a/src/declarative/scenegraph/util/qsgtexture.cpp b/src/declarative/scenegraph/util/qsgtexture.cpp index 536ac8d7fe..bec325f3bb 100644 --- a/src/declarative/scenegraph/util/qsgtexture.cpp +++ b/src/declarative/scenegraph/util/qsgtexture.cpp @@ -42,9 +42,15 @@ #define GL_GLEXT_PROTOTYPES #include <private/qsgtexture_p.h> -#include <qglfunctions.h> +#include <qopenglfunctions.h> #include <private/qsgcontext_p.h> #include <qthread.h> +#include <private/qdeclarativedebugtrace_p.h> + +#if !defined(QT_NO_DEBUG) && (defined(Q_OS_LINUX) || defined(Q_OS_MAC)) +#include <execinfo.h> +#include <QHash> +#endif QT_BEGIN_NAMESPACE @@ -65,36 +71,108 @@ QSGTexturePrivate::QSGTexturePrivate() } #ifndef QT_NO_DEBUG -static int qt_texture_count = 0; -static void qt_print_texture_count() +static int qt_debug_texture_count = 0; + +#if defined(Q_OS_LINUX) || defined (Q_OS_MAC) +DEFINE_BOOL_CONFIG_OPTION(qmlDebugLeakBacktrace, QML_DEBUG_LEAK_BACKTRACE) + +#define BACKTRACE_SIZE 20 +class SGTextureTraceItem { - qDebug("Number of leaked textures: %i", qt_texture_count); - qt_texture_count = -1; -} +public: + void *backTrace[BACKTRACE_SIZE]; + size_t backTraceSize; +}; + +static QHash<QSGTexture*, SGTextureTraceItem*> qt_debug_allocated_textures; #endif +inline static void qt_debug_print_texture_count() +{ + qDebug("Number of leaked textures: %i", qt_debug_texture_count); + qt_debug_texture_count = -1; +#if defined(Q_OS_LINUX) || defined (Q_OS_MAC) + if (qmlDebugLeakBacktrace()) { + while (!qt_debug_allocated_textures.isEmpty()) { + QHash<QSGTexture*, SGTextureTraceItem*>::Iterator it = qt_debug_allocated_textures.begin(); + QSGTexture* texture = it.key(); + SGTextureTraceItem* item = it.value(); -QSGTexture::QSGTexture() - : QObject(*(new QSGTexturePrivate)) + qt_debug_allocated_textures.erase(it); + + qDebug() << "------"; + qDebug() << "Leaked" << texture << "backtrace:"; + + char** symbols = backtrace_symbols(item->backTrace, item->backTraceSize); + + if (symbols) { + for (int i=0; i<(int) item->backTraceSize; i++) + qDebug("Backtrace <%02d>: %s", i, symbols[i]); + free(symbols); + } + + qDebug() << "------"; + + delete item; + } + } +#endif +} + +inline static void qt_debug_add_texture(QSGTexture* texture) { -#ifndef QT_NO_DEBUG - ++qt_texture_count; +#if defined(Q_OS_LINUX) || defined (Q_OS_MAC) + if (qmlDebugLeakBacktrace()) { + SGTextureTraceItem* item = new SGTextureTraceItem; + item->backTraceSize = backtrace(item->backTrace, BACKTRACE_SIZE); + qt_debug_allocated_textures.insert(texture, item); + } +#endif // Q_OS_LINUX + + ++qt_debug_texture_count; + static bool atexit_registered = false; if (!atexit_registered) { - atexit(qt_print_texture_count); + atexit(qt_debug_print_texture_count); atexit_registered = true; } +} + +static void qt_debug_remove_texture(QSGTexture* texture) +{ +#if defined(Q_OS_LINUX) || defined (Q_OS_MAC) + if (qmlDebugLeakBacktrace()) { + SGTextureTraceItem* item = qt_debug_allocated_textures.value(texture, 0); + if (item) { + qt_debug_allocated_textures.remove(texture); + delete item; + } + } +#endif + + --qt_debug_texture_count; + + if (qt_debug_texture_count < 0) + qDebug("Material destroyed after qt_debug_print_texture_count() was called."); +} + +#endif // QT_NO_DEBUG + + +QSGTexture::QSGTexture() + : QObject(*(new QSGTexturePrivate)) +{ +#ifndef QT_NO_DEBUG + qt_debug_add_texture(this); #endif } QSGTexture::~QSGTexture() { #ifndef QT_NO_DEBUG - --qt_texture_count; - if (qt_texture_count < 0) - qDebug("Material destroyed after qt_print_texture_count() was called."); + qt_debug_remove_texture(this); #endif } @@ -260,7 +338,7 @@ void QSGTexture::updateBindOptions(bool force) if (force || d->wrapChanged) { #if !defined(QT_NO_DEBUG) && defined(QT_OPENGL_ES_2) if (d->horizontalWrap == Repeat || d->verticalWrap == Repeat) { - bool npotSupported = QGLContext::currentContext()->functions()->hasOpenGLFeature(QGLFunctions::NPOTTextures); + bool npotSupported = QOpenGLFunctions(QOpenGLContext::currentContext()).hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); QSize size = textureSize(); bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); if (!npotSupported && isNpot) @@ -341,7 +419,7 @@ void QSGPlainTexture::bind() if (!m_dirty_texture) { glBindTexture(GL_TEXTURE_2D, m_texture_id); if (m_has_mipmaps && !m_mipmaps_generated) { - const QGLContext *ctx = QGLContext::currentContext(); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); m_mipmaps_generated = true; } @@ -377,7 +455,7 @@ void QSGPlainTexture::bind() #endif if (m_has_mipmaps) { - const QGLContext *ctx = QGLContext::currentContext(); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); m_mipmaps_generated = true; } diff --git a/src/declarative/scenegraph/util/qsgtexture_p.h b/src/declarative/scenegraph/util/qsgtexture_p.h index 971e5e686c..22812f8640 100644 --- a/src/declarative/scenegraph/util/qsgtexture_p.h +++ b/src/declarative/scenegraph/util/qsgtexture_p.h @@ -44,7 +44,7 @@ #include <private/qobject_p.h> -#include <QtOpenGL/qgl.h> +#include <QtGui/qopengl.h> #include "qsgtexture.h" #include <private/qsgcontext_p.h> diff --git a/src/declarative/scenegraph/util/qsgtexturematerial.cpp b/src/declarative/scenegraph/util/qsgtexturematerial.cpp index 7a7050e073..43bfbcad57 100644 --- a/src/declarative/scenegraph/util/qsgtexturematerial.cpp +++ b/src/declarative/scenegraph/util/qsgtexturematerial.cpp @@ -41,8 +41,8 @@ #include "qsgtexturematerial_p.h" -#include <QtOpenGL/qglshaderprogram.h> -#include <QtOpenGL/qglfunctions.h> +#include <QtGui/qopenglshaderprogram.h> +#include <QtGui/qopenglfunctions.h> QT_BEGIN_NAMESPACE @@ -103,7 +103,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa t->setFiltering(tx->filtering()); #ifdef QT_OPENGL_ES_2 - bool npotSupported = state.context()->functions()->hasOpenGLFeature(QGLFunctions::NPOTTextures); + bool npotSupported = QOpenGLFunctions(const_cast<QOpenGLContext *>(state.context())).hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); QSize size = t->textureSize(); bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); if (!npotSupported && isNpot) { diff --git a/src/declarative/scenegraph/util/qsgtextureprovider.cpp b/src/declarative/scenegraph/util/qsgtextureprovider.cpp index abaf96ed5a..49d157d480 100644 --- a/src/declarative/scenegraph/util/qsgtextureprovider.cpp +++ b/src/declarative/scenegraph/util/qsgtextureprovider.cpp @@ -41,6 +41,9 @@ #include "qsgtextureprovider_p.h" +#include <qsgimage_p.h> +#include <qsgshadereffectsource_p.h> + #ifndef GL_CLAMP_TO_EDGE #define GL_CLAMP_TO_EDGE 0x812F #endif @@ -50,16 +53,10 @@ QT_BEGIN_NAMESPACE /*! \class QSGTextureProvider \brief The QSGTextureProvider class encapsulates texture based entities in QML. - */ - -/*! - Convenience function for casting a QObject to a QSGTextureProvider + The QSGTextureProvider lives primarily in the scene graph rendering thread. */ -QSGTextureProvider *QSGTextureProvider::from(QObject *object) -{ - return object ? static_cast<QSGTextureProvider *>(object->qt_metacast("QSGTextureProvider")) : 0; -} + QT_END_NAMESPACE diff --git a/src/declarative/scenegraph/util/qsgtextureprovider_p.h b/src/declarative/scenegraph/util/qsgtextureprovider_p.h index 756f1c613a..ebb6ca8507 100644 --- a/src/declarative/scenegraph/util/qsgtextureprovider_p.h +++ b/src/declarative/scenegraph/util/qsgtextureprovider_p.h @@ -42,8 +42,6 @@ #ifndef QSGTEXTUREPROVIDER_H #define QSGTEXTUREPROVIDER_H -#include <qgl.h> - #include "qsgtexture.h" #include "qobject.h" @@ -53,15 +51,15 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QSGTextureProvider +class Q_DECLARATIVE_EXPORT QSGTextureProvider : public QObject { + Q_OBJECT public: virtual QSGTexture *texture() const = 0; - virtual const char *textureChangedSignal() const { return 0; } - static QSGTextureProvider *from(QObject *object); +Q_SIGNALS: + void textureChanged(); }; -Q_DECLARE_INTERFACE(QSGTextureProvider, "QSGTextureProvider") QT_END_NAMESPACE diff --git a/src/declarative/scenegraph/util/qsgvertexcolormaterial.cpp b/src/declarative/scenegraph/util/qsgvertexcolormaterial.cpp index 910d7a53f8..c31e9dc936 100644 --- a/src/declarative/scenegraph/util/qsgvertexcolormaterial.cpp +++ b/src/declarative/scenegraph/util/qsgvertexcolormaterial.cpp @@ -41,7 +41,7 @@ #include "qsgvertexcolormaterial_p.h" -#include <qglshaderprogram.h> +#include <qopenglshaderprogram.h> QT_BEGIN_NAMESPACE |