summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-12-20 15:12:29 +0100
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-12-20 15:12:29 +0100
commit4fd7a1c816a2105f93c2bd28055920da792f1ce1 (patch)
tree321d855ff0ea27d3e45fd08c54a45e31253b9755
parente9365b6bb7c73ba5e696581e13ff47a204502014 (diff)
got partial uploader working
-rw-r--r--src/adaptationlayers/qsgpartialuploadtexturemanager.cpp330
-rw-r--r--src/adaptationlayers/qsgpartialuploadtexturemanager.h51
-rw-r--r--src/scenegraph/coreapi/qsgcontext.cpp14
-rw-r--r--src/scenegraph/coreapi/qsgtexturemanager.cpp87
-rw-r--r--src/scenegraph/coreapi/qsgtexturemanager.h9
-rw-r--r--src/scenegraph/coreapi/qsgtexturemanager_p.h80
-rw-r--r--src/scenegraph/scenegraph.pri3
-rw-r--r--tests/auto/texturemanager/tst_texturemanagertest.cpp4
8 files changed, 432 insertions, 146 deletions
diff --git a/src/adaptationlayers/qsgpartialuploadtexturemanager.cpp b/src/adaptationlayers/qsgpartialuploadtexturemanager.cpp
index dd8af85..ba162c3 100644
--- a/src/adaptationlayers/qsgpartialuploadtexturemanager.cpp
+++ b/src/adaptationlayers/qsgpartialuploadtexturemanager.cpp
@@ -1,110 +1,258 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt scene graph research project.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include "qsgpartialuploadtexturemanager.h"
+#include "qsgtexturemanager_p.h"
+
+#include <qdatetime.h>
+
+
+class QSGPartialUploadTexture : public QSGTexture
+{
+ Q_OBJECT
+public:
+ int chunkCount;
+ int progress;
+
+ QImage image;
+};
+
+
+
+
+class QSGPartialUploadTextureManagerPrivate : public QSGTextureManagerPrivate
+{
+public:
+
+ QSGPartialUploadTextureManagerPrivate()
+ : uploadChunkSize(64)
+ , maxUploadTime(5)
+ , timerId(0)
+ {
+ }
+
+ int uploadChunkSize;
+ int maxUploadTime;
+
+ int timerId;
+ QList<QSGPartialUploadTexture *> requests;
+};
QSGPartialUploadTextureManager::QSGPartialUploadTextureManager()
+ : QSGTextureManager(*(new QSGPartialUploadTextureManagerPrivate))
{
}
+void QSGPartialUploadTextureManager::setContext(QSGContext *context)
+{
+ connect(context, SIGNAL(aboutToRenderNextFrame()), this, SLOT(processAsyncTextures()));
+ QSGTextureManager::setContext(context);
+}
+
+
+QSGTextureRef QSGPartialUploadTextureManager::requestUpload(const QImage &image,
+ const QObject *listener,
+ const char *slot)
+{
+ Q_D(QSGPartialUploadTextureManager);
+
+ QSGTextureCacheKey key = { image.cacheKey() };
+ QSGTexture *texture = d->cache.value(key);
+ if (texture)
+ return QSGTextureRef(texture);
+
+ QSGPartialUploadTexture *ptex = new QSGPartialUploadTexture;
+ ptex->progress = 0;
+ ptex->image = image;
+
+ int hChunkCount = (image.width() + d->uploadChunkSize - 1) / d->uploadChunkSize;
+ int vChunkCount = (image.height() + d->uploadChunkSize - 1) / d->uploadChunkSize;
+ ptex->chunkCount = hChunkCount * vChunkCount;
+
+ if (listener && slot)
+ connect(ptex, SIGNAL(statusChanged(int)), listener, slot);
+
+ ptex->setStatus(QSGTexture::Loading);
+
+ d->cache.insert(key, ptex);
+
+ d->requests << ptex;
+ if (d->timerId == 0)
+ d->timerId = startTimer(100);
+
+ return QSGTextureRef(ptex);
+}
+
+QSGTextureRef QSGPartialUploadTextureManager::upload(const QImage &image)
+{
+ Q_D(QSGPartialUploadTextureManager);
+
+ QSGTextureCacheKey key = { image.cacheKey() };
+ QSGTexture *texture = d->cache.value(key);
+ if (texture) {
+
+ QSGPartialUploadTexture *ptex = qobject_cast<QSGPartialUploadTexture *>(texture);
+ if (ptex && ptex->progress == ptex->chunkCount || !ptex) {
+ // Already fully uploaded... Just return
+ return QSGTextureRef(texture);
+
+ } else {
+ // Image is not fully uploaded, force upload and return it.
+ GLuint id = d->upload(image, ptex->textureId());
+ if (id != 0) {
+ ptex->progress = ptex->chunkCount;
+ ptex->setTextureId(id);
+ ptex->setAlphaChannel(image.hasAlphaChannel());
+ ptex->setTextureSize(image.size());
+ ptex->setStatus(QSGTexture::Ready);
+ } else {
+ ptex->setStatus(QSGTexture::Null);
+ }
+ d->requests.removeOne(ptex);
+ return QSGTextureRef(ptex);
+ }
+ }
+
+ return d->upload(image, 0, 0);
+}
-void QSGPartialUploadTextureManager::timerEvent(QTimerEvent *)
+void QSGPartialUploadTextureManager::timerEvent(QTimerEvent *event)
{
-// // ### gunnar:
-// // In the future, I forsee us starting / stopping this timer based
-// // on wether the vsync animation driver is running or not.
-// // Then we can also skip the "time since last upload" logic which
-// // is currently kinda messy and unpredictable.
-// if (d->lastUpload.elapsed() > 50) {
-// processAsyncTextures();
-// }
+ Q_D(QSGPartialUploadTextureManager);
+
+ // ### We should be listening for vsync driver to stop animating here...
+ if (event->timerId() == d->timerId) {
+ int old = d->maxUploadTime;
+ d->maxUploadTime = 100;
+ processAsyncTextures();
+ d->maxUploadTime = old;
+ }
}
void QSGPartialUploadTextureManager::processAsyncTextures()
{
-// QTime time;
-// time.start();
-
-// while (!d->requests.isEmpty()) {
-
-// UploadRequest *request = d->requests.first();
-
-// int w = request->image.width();
-// int h = request->image.height();
-
-// int hChunkCount = (w + d->uploadChunkSize - 1) / d->uploadChunkSize;
-// int vChunkCount = (h + d->uploadChunkSize - 1) / d->uploadChunkSize;
-// int chunkCount = hChunkCount * vChunkCount;
-// QSGTexture *t = request->texture;
-
-//// printf("\nASYNC: texture: %p, id=%d, size=(%dx%d), progress: %d / %d (%dx%d)\n",
-//// t,
-//// t->textureId(),
-//// w, h,
-//// request->progress, chunkCount, hChunkCount, vChunkCount);
-
-// // Create or bind the texture...
-// if (request->texture->textureId() == 0) {
-// while (glGetError() != GL_NO_ERROR) {}
-// GLuint id;
-// glGenTextures(1, &id);
-// glBindTexture(GL_TEXTURE_2D, id);
-// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
-// // Clean up
-// // Gracefully fail in case of an error...
-// GLuint error = glGetError();
-// if (error != GL_NO_ERROR) {
-// glBindTexture(GL_TEXTURE_2D, 0);
-// glDeleteTextures(1, &id);
-// d->requests.dequeue();
-// t->setStatus(QSGTexture::Null);
-// delete request;
-// return;
-// }
-
-// t->setTextureId(id);
-// t->setTextureSize(QSize(w, h));
-// t->setAlphaChannel(request->image.hasAlphaChannel());
-//// printf("ASYNC: created texture %p with id=%d\n", t, id);
-// } else {
-// glBindTexture(GL_TEXTURE_2D, t->textureId());
-// }
-
-// if (time.elapsed() > d->maxUploadTime)
-// break;
-
-// while (request->progress < chunkCount && time.elapsed() < d->maxUploadTime) {
-// int x = (request->progress % hChunkCount) * d->uploadChunkSize;
-// int y = (request->progress / hChunkCount) * d->uploadChunkSize;
-
-// QRect area = QRect(x, y, d->uploadChunkSize, d->uploadChunkSize) & request->image.rect();
-// QImage subImage = request->image.copy(area);
-//// printf("ASYNC: - doing another batch: %d (x=%d, y=%d, w=%d, h=%d\n",
-//// request->progress,
-//// x, y, subImage.width(), subImage.height());
-
-// swizzleBGRAToRGBA(&subImage);
-// glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, subImage.width(), subImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, subImage.constBits());
-
-// ++request->progress;
-// }
-
-// if (request->progress == chunkCount) {
-// t->setStatus(QSGTexture::Ready);
-// QSGTextureCacheKey key = { request->image.cacheKey() };
-// d->cache.insert(key, t);
-// d->requests.dequeue();
-// delete request;
-// if (d->requests.size() == 0) {
-// killTimer(d->uploadTimer);
-// d->uploadTimer = 0;
-// }
-// }
-// }
-
-// glBindTexture(GL_TEXTURE_2D, 0);
+ Q_D(QSGPartialUploadTextureManager);
+
+ QTime time;
+ time.start();
+
+ while (!d->requests.isEmpty()) {
+
+ QSGPartialUploadTexture *t = d->requests.at(0);
+
+ int w = t->image.width();
+ int h = t->image.height();
+
+// printf("\nASYNC: texture: %p, id=%d, size=(%dx%d), progress: %d / %d\n",
+// t,
+// t->textureId(),
+// w, h,
+// t->progress, t->chunkCount);
+
+ // Create or bind the texture...
+ if (t->textureId() == 0) {
+ while (glGetError() != GL_NO_ERROR) {}
+ GLuint id;
+ glGenTextures(1, &id);
+ glBindTexture(GL_TEXTURE_2D, id);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+
+ // Clean up
+ // Gracefully fail in case of an error...
+ GLuint error = glGetError();
+ if (error != GL_NO_ERROR) {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDeleteTextures(1, &id);
+ d->requests.removeAt(0);
+ t->setStatus(QSGTexture::Null);
+ return;
+ }
+
+ t->setTextureId(id);
+ t->setTextureSize(QSize(w, h));
+ t->setAlphaChannel(t->image.hasAlphaChannel());
+
+// printf("ASYNC: created texture %p with id=%d\n", t, id);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, t->textureId());
+ }
+
+ if (time.elapsed() > d->maxUploadTime)
+ break;
+
+ int hChunkCount = (t->image.width() + d->uploadChunkSize - 1) / d->uploadChunkSize;
+
+ while (t->progress < t->chunkCount && time.elapsed() < d->maxUploadTime) {
+ int x = (t->progress % hChunkCount) * d->uploadChunkSize;
+ int y = (t->progress / hChunkCount) * d->uploadChunkSize;
+
+ QRect area = QRect(x, y, d->uploadChunkSize, d->uploadChunkSize) & t->image.rect();
+ QImage subImage = t->image.copy(area);
+// printf("ASYNC: - doing another batch: %d (x=%d, y=%d, w=%d, h=%d\n",
+// request->progress,
+// x, y, subImage.width(), subImage.height());
+
+ swizzleBGRAToRGBA(&subImage);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, subImage.width(), subImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, subImage.constBits());
+
+ ++t->progress;
+ }
+
+ if (t->progress == t->chunkCount) {
+ t->setStatus(QSGTexture::Ready);
+ d->requests.removeAt(0);
+ if (d->requests.size() == 0) {
+ killTimer(d->timerId);
+ d->timerId = 0;
+ }
+ }
+ }
+
+ glBindTexture(GL_TEXTURE_2D, 0);
}
+
+#include "qsgpartialuploadtexturemanager.moc"
diff --git a/src/adaptationlayers/qsgpartialuploadtexturemanager.h b/src/adaptationlayers/qsgpartialuploadtexturemanager.h
index c9f7773..c6c8146 100644
--- a/src/adaptationlayers/qsgpartialuploadtexturemanager.h
+++ b/src/adaptationlayers/qsgpartialuploadtexturemanager.h
@@ -1,20 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt scene graph research project.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
#ifndef QSGPARTIALUPLOADTEXTUREMANAGER_H
#define QSGPARTIALUPLOADTEXTUREMANAGER_H
#include "qsgtexturemanager.h"
+class QSGPartialUploadTextureManagerPrivate;
+
class QSGPartialUploadTextureManager : public QSGTextureManager
{
+ Q_DECLARE_PRIVATE(QSGPartialUploadTextureManager);
+ Q_OBJECT
public:
QSGPartialUploadTextureManager();
void setContext(QSGContext *context);
+ QSGTextureRef upload(const QImage &image);
QSGTextureRef requestUpload(const QImage &image, const QObject *listener, const char *slot);
+private slots:
+ void processAsyncTextures();
+
protected:
void timerEvent(QTimerEvent *);
- void processAsyncTextures();
};
diff --git a/src/scenegraph/coreapi/qsgcontext.cpp b/src/scenegraph/coreapi/qsgcontext.cpp
index 152452c..a52bd95 100644
--- a/src/scenegraph/coreapi/qsgcontext.cpp
+++ b/src/scenegraph/coreapi/qsgcontext.cpp
@@ -8,6 +8,7 @@
#include "default/default_glyphnode.h"
#include "qsgtexturemanager.h"
+#include "qsgpartialuploadtexturemanager.h"
#include <QApplication>
@@ -184,10 +185,15 @@ QSGTextureManager *QSGContext::createTextureManager()
QSGTextureManager *manager;
-// if (args.contains("--basic-texture-manager")) {
-// printf("QSGContext: Using basic texture manager\n");
- manager = new QSGTextureManager;
-// } else if (args.contains("--threaded-texture-manager")) {
+// if (args.contains("--partial-texture-manager")) {
+// printf("QSGContext: Using partial upload texture manager\n");
+ manager = new QSGPartialUploadTextureManager;
+// } else {
+// printf("QSGContext: Using basic texture manager\n");
+// manager = new QSGTextureManager;
+// }
+
+ // } else if (args.contains("--threaded-texture-manager")) {
// printf("QSGContext: Using threaded texture manager\n");
// return new QSGThreadedTextureManager;
// }
diff --git a/src/scenegraph/coreapi/qsgtexturemanager.cpp b/src/scenegraph/coreapi/qsgtexturemanager.cpp
index 9a4d1f0..c0ba364 100644
--- a/src/scenegraph/coreapi/qsgtexturemanager.cpp
+++ b/src/scenegraph/coreapi/qsgtexturemanager.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "qsgtexturemanager.h"
+#include "qsgtexturemanager_p.h"
#include <QImage>
@@ -80,37 +80,11 @@ void QSGTexture::setStatus(Status s)
}
-struct QSGTextureCacheKey {
- quint64 cacheKey;
-
- bool operator==(const QSGTextureCacheKey &other) const {
- return other.cacheKey == cacheKey;
- }
-};
-
uint qHash(const QSGTextureCacheKey &key)
{
return (key.cacheKey >> 32) ^ uint(key.cacheKey);
}
-class QSGTextureManagerPrivate
-{
-public:
- QSGTextureManagerPrivate()
- : context(0)
- {
- }
-
- QSGTextureRef upload(const QImage &image, const QObject *listener, const char *slot);
-
- QSGContext *context;
- QHash<QSGTextureCacheKey, QSGTexture *> cache;
-
- int maxTextureSize;
-
- QSGTextureManager *q;
-};
-
/*!
The QSGTextureManager class is responsible for converting QImages into texture ids
@@ -121,33 +95,49 @@ public:
GL context is bound and make GL calls.
*/
QSGTextureManager::QSGTextureManager()
- : d(new QSGTextureManagerPrivate)
+ : QObject(*new QSGTextureManagerPrivate)
{
+ Q_D(QSGTextureManager);
d->q = this;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &d->maxTextureSize);
+}
+
+
+/*!
+ \internal
+ */
+QSGTextureManager::QSGTextureManager(QSGTextureManagerPrivate &dd)
+ : QObject(dd)
+{
+ dd.q = this;
}
int QSGTextureManager::maxTextureSize() const
{
+ Q_D(const QSGTextureManager);
+ if (d->maxTextureSize < 0)
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &const_cast<QSGTextureManagerPrivate *>(d)->maxTextureSize);
return d->maxTextureSize;
}
void QSGTextureManager::setContext(QSGContext *context)
{
+ Q_D(QSGTextureManager);
Q_ASSERT(!d->context);
d->context = context;
}
QSGContext *QSGTextureManager::context() const
{
+ Q_D(const QSGTextureManager);
return d->context;
}
void QSGTextureManager::textureDestroyed(QObject *destroyed)
{
+ Q_D(QSGTextureManager);
for (QHash<QSGTextureCacheKey, QSGTexture *>::iterator it = d->cache.begin();
it != d->cache.end(); ++it) {
if (it.value() == destroyed) {
@@ -169,22 +159,14 @@ void QSGTextureManager::swizzleBGRAToRGBA(QImage *image)
}
}
-
-QSGTextureRef QSGTextureManagerPrivate::upload(const QImage &image, const QObject *listener, const char *slot)
+uint QSGTextureManagerPrivate::upload(const QImage &image, GLuint id)
{
- Q_ASSERT(!image.isNull());
-
- // Check if the image is already uploaded and cached
- QSGTextureCacheKey key = { image.cacheKey() };
- QSGTexture *texture = cache.value(key);
- if (texture)
- return QSGTextureRef(texture);
-
// image not already scheduled, upload normally...
while (glGetError() != GL_NO_ERROR) {}
- GLuint id;
- glGenTextures(1, &id);
+ if (id == 0)
+ glGenTextures(1, &id);
+
glBindTexture(GL_TEXTURE_2D, id);
#ifdef QT_OPENGL_ES
@@ -200,11 +182,26 @@ QSGTextureRef QSGTextureManagerPrivate::upload(const QImage &image, const QObjec
if (error != GL_NO_ERROR) {
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &id);
- if (error != GL_OUT_OF_MEMORY)
- qWarning("QSGTextureManager::upload failed, OpenGL error code: %x", error);
- return QSGTextureRef();
+ return 0;
}
+ return id;
+}
+
+QSGTextureRef QSGTextureManagerPrivate::upload(const QImage &image, const QObject *listener, const char *slot)
+{
+ Q_ASSERT(!image.isNull());
+
+ // Check if the image is already uploaded and cached
+ QSGTextureCacheKey key = { image.cacheKey() };
+ QSGTexture *texture = cache.value(key);
+ if (texture)
+ return QSGTextureRef(texture);
+
+ GLuint id = upload(image, 0);
+ if (id == 0)
+ return QSGTextureRef();
+
texture = new QSGTexture;
if (listener && slot)
QObject::connect(texture, SIGNAL(statusChanged(int)), listener, slot);
@@ -224,6 +221,7 @@ QSGTextureRef QSGTextureManagerPrivate::upload(const QImage &image, const QObjec
QSGTextureRef QSGTextureManager::upload(const QImage &image)
{
+ Q_D(QSGTextureManager);
return d->upload(image, 0, 0);
}
@@ -236,6 +234,7 @@ QSGTextureRef QSGTextureManager::requestUpload(const QImage &image,
const QObject *listener,
const char *slot)
{
+ Q_D(QSGTextureManager);
return d->upload(image, listener, slot);
}
diff --git a/src/scenegraph/coreapi/qsgtexturemanager.h b/src/scenegraph/coreapi/qsgtexturemanager.h
index 45f0170..1abca84 100644
--- a/src/scenegraph/coreapi/qsgtexturemanager.h
+++ b/src/scenegraph/coreapi/qsgtexturemanager.h
@@ -162,11 +162,12 @@ private:
QRectF m_sub_rect;
};
-
+class QSGTextureManagerPrivate;
class QT_SCENEGRAPH_EXPORT QSGTextureManager : public QObject
{
Q_OBJECT
+ Q_DECLARE_PRIVATE(QSGTextureManager);
public:
QSGTextureManager();
@@ -183,10 +184,8 @@ public:
private slots:
void textureDestroyed(QObject *texture);
-private:
- friend class QSGTextureManagerPrivate;
-
- QSGTextureManagerPrivate *d;
+protected:
+ QSGTextureManager(QSGTextureManagerPrivate &);
};
#endif // QSGTEXTUREMANAGER_H
diff --git a/src/scenegraph/coreapi/qsgtexturemanager_p.h b/src/scenegraph/coreapi/qsgtexturemanager_p.h
new file mode 100644
index 0000000..8ed7a17
--- /dev/null
+++ b/src/scenegraph/coreapi/qsgtexturemanager_p.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt scene graph research project.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGTEXTUREMANAGER_P_H
+#define QSGTEXTUREMANAGER_P_H
+
+#include "qsgtexturemanager.h"
+
+#include <private/qobject_p.h>
+
+struct QSGTextureCacheKey {
+ quint64 cacheKey;
+
+ bool operator==(const QSGTextureCacheKey &other) const {
+ return other.cacheKey == cacheKey;
+ }
+};
+
+uint qHash(const QSGTextureCacheKey &key);
+
+
+class QSGTextureManagerPrivate : public QObjectPrivate
+{
+public:
+ QSGTextureManagerPrivate()
+ : context(0), maxTextureSize(-1)
+ {
+ }
+
+ uint upload(const QImage &image, GLuint id);
+ QSGTextureRef upload(const QImage &image, const QObject *listener, const char *slot);
+
+ QSGContext *context;
+ QHash<QSGTextureCacheKey, QSGTexture *> cache;
+
+ int maxTextureSize;
+
+ QSGTextureManager *q;
+};
+
+
+#endif // QSGTEXTUREMANAGER_P_H
diff --git a/src/scenegraph/scenegraph.pri b/src/scenegraph/scenegraph.pri
index b48d8a4..a150442 100644
--- a/src/scenegraph/scenegraph.pri
+++ b/src/scenegraph/scenegraph.pri
@@ -9,7 +9,8 @@ HEADERS += $$PWD/coreapi/geometry.h \
$$PWD/coreapi/renderer.h \
$$PWD/coreapi/qmlrenderer.h \
$$PWD/coreapi/qsgcontext.h \
- scenegraph/coreapi/qsgtexturemanager.h
+ scenegraph/coreapi/qsgtexturemanager.h \
+ scenegraph/coreapi/qsgtexturemanager_p.h
SOURCES += $$PWD/coreapi/geometry.cpp \
$$PWD/coreapi/material.cpp \
diff --git a/tests/auto/texturemanager/tst_texturemanagertest.cpp b/tests/auto/texturemanager/tst_texturemanagertest.cpp
index f69a76a..3d29eb4 100644
--- a/tests/auto/texturemanager/tst_texturemanagertest.cpp
+++ b/tests/auto/texturemanager/tst_texturemanagertest.cpp
@@ -151,6 +151,8 @@ void TextureManagerTest::requestUpload()
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
QSGTextureRef t = tm->requestUpload(image, 0, 0);
+ QVERIFY(!t.isNull());
+
QVERIFY(t->status() == QSGTexture::Ready || t->status() == QSGTexture::Loading);
QTime time;
time.start();
@@ -175,6 +177,8 @@ void TextureManagerTest::requestUploadSameImageTwiceWithDelay()
{
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
QSGTextureRef t = tm->requestUpload(image, 0, 0);
+ QVERIFY(!t.isNull());
+
QTime time;
time.start();
while (t->status() == QSGTexture::Loading && time.elapsed() < 1000) {