From 969e6e925f24635a2a080175a3ff9799fb6bd087 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 25 Jul 2016 01:19:32 +0000 Subject: [PATCH] remove redundant QGLTexturePool Signed-off-by: Ivailo Monev --- src/opengl/qgltexturepool.cpp | 240 ------------------------------------------ src/opengl/qgltexturepool_p.h | 144 ------------------------- 2 files changed, 384 deletions(-) delete mode 100644 src/opengl/qgltexturepool.cpp delete mode 100644 src/opengl/qgltexturepool_p.h diff --git a/src/opengl/qgltexturepool.cpp b/src/opengl/qgltexturepool.cpp deleted file mode 100644 index 783b07cd8..000000000 --- a/src/opengl/qgltexturepool.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgltexturepool_p.h" -#include "qpixmapdata_gl_p.h" -#include "qgl_p.h" - -QT_BEGIN_NAMESPACE - -Q_OPENGL_EXPORT extern QGLWidget* qt_gl_share_widget(); - -static QGLTexturePool *qt_gl_texture_pool = 0; - -class QGLTexturePoolPrivate -{ -public: - QGLTexturePoolPrivate() : lruFirst(0), lruLast(0) {} - - QGLTexture *lruFirst; - QGLTexture *lruLast; -}; - -QGLTexturePool::QGLTexturePool() - : d_ptr(new QGLTexturePoolPrivate()) -{ -} - -QGLTexturePool::~QGLTexturePool() -{ -} - -QGLTexturePool *QGLTexturePool::instance() -{ - if (!qt_gl_texture_pool) - qt_gl_texture_pool = new QGLTexturePool(); - return qt_gl_texture_pool; -} - -GLuint QGLTexturePool::createTexture(GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - QGLTexture *texture) -{ - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(target, tex); - do { - glTexImage2D(target, level, internalformat, width, height, 0, format, type, 0); - GLenum error = glGetError(); - if (error == GL_NO_ERROR) { - if (texture) - moveToHeadOfLRU(texture); - return tex; - } else if (error != GL_OUT_OF_MEMORY) { - qWarning("QGLTexturePool: cannot create temporary texture because of invalid params"); - return 0; - } - } while (reclaimSpace(internalformat, width, height, format, type, texture)); - qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture", - width, height); - return 0; -} - -bool QGLTexturePool::createPermanentTexture(GLuint tex, - GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - const GLvoid *data) -{ - glBindTexture(target, tex); - do { - glTexImage2D(target, level, internalformat, width, height, 0, format, type, data); - - GLenum error = glGetError(); - if (error == GL_NO_ERROR) { - return true; - } else if (error != GL_OUT_OF_MEMORY) { - qWarning("QGLTexturePool: cannot create permanent texture because of invalid params"); - return false; - } - } while (reclaimSpace(internalformat, width, height, format, type, 0)); - qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture", - width, height); - return 0; -} - -void QGLTexturePool::useTexture(QGLTexture *texture) -{ - moveToHeadOfLRU(texture); - texture->inTexturePool = true; -} - -void QGLTexturePool::detachTexture(QGLTexture *texture) -{ - removeFromLRU(texture); - texture->inTexturePool = false; -} - -bool QGLTexturePool::reclaimSpace(GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - QGLTexture *texture) -{ - Q_UNUSED(internalformat); // For future use in picking the best texture to eject. - Q_UNUSED(width); - Q_UNUSED(height); - Q_UNUSED(format); - Q_UNUSED(type); - - bool succeeded = false; - bool wasInLRU = false; - if (texture) { - wasInLRU = texture->inLRU; - moveToHeadOfLRU(texture); - } - - QGLTexture *lrutexture = textureLRU(); - if (lrutexture && lrutexture != texture) { - if (lrutexture->boundPixmap) - lrutexture->boundPixmap->reclaimTexture(); - else - QGLTextureCache::instance()->remove(lrutexture->boundKey); - succeeded = true; - } - - if (texture && !wasInLRU) - removeFromLRU(texture); - - return succeeded; -} - -void QGLTexturePool::hibernate() -{ - Q_D(QGLTexturePool); - QGLTexture *texture = d->lruLast; - while (texture) { - QGLTexture *prevLRU = texture->prevLRU; - texture->inTexturePool = false; - texture->inLRU = false; - texture->nextLRU = 0; - texture->prevLRU = 0; - if (texture->boundPixmap) - texture->boundPixmap->hibernate(); - else - QGLTextureCache::instance()->remove(texture->boundKey); - texture = prevLRU; - } - d->lruFirst = 0; - d->lruLast = 0; -} - -void QGLTexturePool::moveToHeadOfLRU(QGLTexture *texture) -{ - Q_D(QGLTexturePool); - if (texture->inLRU) { - if (!texture->prevLRU) - return; // Already at the head of the list. - removeFromLRU(texture); - } - texture->inLRU = true; - texture->nextLRU = d->lruFirst; - texture->prevLRU = 0; - if (d->lruFirst) - d->lruFirst->prevLRU = texture; - else - d->lruLast = texture; - d->lruFirst = texture; -} - -void QGLTexturePool::removeFromLRU(QGLTexture *texture) -{ - Q_D(QGLTexturePool); - if (!texture->inLRU) - return; - if (texture->nextLRU) - texture->nextLRU->prevLRU = texture->prevLRU; - else - d->lruLast = texture->prevLRU; - if (texture->prevLRU) - texture->prevLRU->nextLRU = texture->nextLRU; - else - d->lruFirst = texture->nextLRU; - texture->inLRU = false; -} - -QGLTexture *QGLTexturePool::textureLRU() -{ - Q_D(QGLTexturePool); - return d->lruLast; -} - -QT_END_NAMESPACE diff --git a/src/opengl/qgltexturepool_p.h b/src/opengl/qgltexturepool_p.h deleted file mode 100644 index 7d40154c4..000000000 --- a/src/opengl/qgltexturepool_p.h +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLTEXTUREPOOL_P_H -#define QGLTEXTUREPOOL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qgl.h" -#include - -QT_BEGIN_NAMESPACE - -class QGLTexture; -class QGLTexturePoolPrivate; - -class QGLTexturePool -{ -public: - QGLTexturePool(); - virtual ~QGLTexturePool(); - - static QGLTexturePool *instance(); - - // Create a new texture with the specified parameters and associate - // it with "texture". The QGLTexture will be notified when the - // texture needs to be reclaimed by the pool. - // - // This function will call reclaimSpace() when texture creation fails. - GLuint createTexture(GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - QGLTexture *texture); - - // Create a permanent texture with the specified parameters. - // If there is insufficient space for the texture, - // then this function will call reclaimSpace() and try again. - // - // The caller is responsible for calling glDeleteTextures() - // when it no longer needs the texture, as the texture is not - // recorded in the texture pool. - bool createPermanentTexture(GLuint texture, - GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - const GLvoid *data); - - // Notify the pool that a QGLTexture object is using - // an texture again. This allows the pool to move the texture - // within a least-recently-used list of QGLTexture objects. - void useTexture(QGLTexture *texture); - - // Notify the pool that the texture associated with a - // QGLTexture is being detached from the pool. The caller - // will become responsible for calling glDeleteTextures(). - void detachTexture(QGLTexture *texture); - - // Reclaim space for an image allocation with the specified parameters. - // Returns true if space was reclaimed, or false if there is no - // further space that can be reclaimed. The "texture" parameter - // indicates the texture that is trying to obtain space which should - // not itself be reclaimed. - bool reclaimSpace(GLint internalformat, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - QGLTexture *data); - - // Hibernate the texture pool because the context is about to be - // destroyed. All textures left in the pool should be released. - void hibernate(); - -protected: - // Helper functions for managing the LRU list of QGLTexture objects. - void moveToHeadOfLRU(QGLTexture *texture); - void removeFromLRU(QGLTexture *texture); - QGLTexture *textureLRU(); - -private: - QScopedPointer d_ptr; - - Q_DECLARE_PRIVATE(QGLTexturePool) - Q_DISABLE_COPY(QGLTexturePool) -}; - -QT_END_NAMESPACE - -#endif -- 2.11.0