#include <QtCore/private/qabstractanimation_p.h>
#include <QtGui/QOpenGLContext>
-#include <QtGui/QPlatformIntegration>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qplatformintegration_qpa.h>
#include <QtDeclarative/private/qdeclarativeglobal_p.h>
//#define THREAD_DEBUG
+QQuickWindowManager::~QQuickWindowManager()
+{
+}
+
class QQuickRenderThreadSingleContextWindowManager : public QThread, public QQuickWindowManager
{
Q_OBJECT
, shouldExit(false)
, hasExited(false)
, isDeferredUpdatePosted(false)
- , runToReleaseResources(false)
, canvasToGrab(0)
{
sg->moveToThread(this);
connect(animationDriver, SIGNAL(stopped()), this, SLOT(animationStopped()));
}
- ~QQuickRenderThreadSingleContextWindowManager()
- {
- releaseResources();
- }
-
QSGContext *sceneGraphContext() const { return sg; }
+ void releaseResources() { }
+
void show(QQuickCanvas *canvas);
void hide(QQuickCanvas *canvas);
void sync(bool guiAlreadyLocked);
void initialize();
- void releaseResources();
- void releaseResourcesInThread();
bool *allowMainThreadProcessing() { return &allowMainThreadProcessingFlag; }
uint shouldExit : 1;
uint hasExited : 1;
uint isDeferredUpdatePosted : 1;
- uint runToReleaseResources : 1;
QQuickCanvas *canvasToGrab;
QImage grabContent;
{
public:
QQuickTrivialWindowManager();
- ~QQuickTrivialWindowManager()
- {
- releaseResources();
- }
void show(QQuickCanvas *canvas);
void hide(QQuickCanvas *canvas);
void canvasDestroyed(QQuickCanvas *canvas);
- void releaseResources();
void initializeGL();
void renderCanvas(QQuickCanvas *canvas);
void paint(QQuickCanvas *canvas);
void maybeUpdate(QQuickCanvas *canvas);
+ void releaseResources() { }
+
bool *allowMainThreadProcessing();
QSGContext *sceneGraphContext() const;
- QQuickCanvas *masterCanvas() const;
bool event(QEvent *);
#ifdef THREAD_DEBUG
printf("QML Rendering Thread Started\n");
#endif
- lock();
-
- if (runToReleaseResources) {
- releaseResourcesInThread();
- runToReleaseResources = false;
- unlock();
- return;
- }
-
- if (!gl)
- initialize();
+ lock();
+ Q_ASSERT(!gl);
+ initialize();
// Wake GUI as it is waiting for the GL context to have appeared, as
// an indication that the render thread is now running.
wake();
m_removed_windows << m_rendered_windows.keys();
handleRemovedWindows();
+ sg->invalidate();
+
+ gl->doneCurrent();
+ delete gl;
+ gl = 0;
+
#ifdef THREAD_DEBUG
printf(" RenderThread: render loop exited... Good Night!\n");
#endif
#endif
}
-void QQuickRenderThreadSingleContextWindowManager::releaseResourcesInThread()
-{
-#ifdef THREAD_DEBUG
- printf(" RenderThread: releasing resources...\n");
-#endif
- QQuickCanvas *canvas = masterCanvas();
- QWindow *tmpSurface = 0;
-
- if (canvas) {
- gl->makeCurrent(canvas);
- } else {
- tmpSurface = new QWindow();
- tmpSurface->setSurfaceType(QSurface::OpenGLSurface);
- tmpSurface->resize(4, 4);
- tmpSurface->create();
- gl->makeCurrent(tmpSurface);
- }
-
- sg->invalidate();
- gl->doneCurrent();
- delete gl;
- gl = 0;
-
- if (tmpSurface)
- delete tmpSurface;
-
- wake();
-}
-
-void QQuickRenderThreadSingleContextWindowManager::releaseResources()
-{
-#ifdef THREAD_DEBUG
- printf("GUI: releasing resources\n");
-#endif
-
- lockInGui();
- if (!isRunning() && gl) {
- runToReleaseResources = true;
- start();
-
- while (isRunning()) {
- wait();
- }
- }
-#ifdef THREAD_DEBUG
- else {
- printf("GUI: render thread running not releasing resources...\n");
- }
-#endif
- unlockInGui();
-
-}
-
bool QQuickRenderThreadSingleContextWindowManager::event(QEvent *e)
{
Q_ASSERT(QThread::currentThread() == qApp->thread());
animationTimer = -1;
}
+
}
m_windows.remove(canvas);
QQuickCanvasPrivate *cd = QQuickCanvasPrivate::get(canvas);
cd->cleanupNodesOnShutdown();
-}
-
-void QQuickTrivialWindowManager::canvasDestroyed(QQuickCanvas *canvas)
-{
- hide(canvas);
-}
-
-void QQuickTrivialWindowManager::releaseResources()
-{
- if (m_windows.size() == 0 && gl) {
- QQuickCanvas *canvas = masterCanvas();
- QWindow *tmpSurface = 0;
-
- if (canvas) {
- gl->makeCurrent(canvas);
- } else {
- tmpSurface = new QWindow();
- tmpSurface->setSurfaceType(QSurface::OpenGLSurface);
- tmpSurface->resize(4, 4);
- tmpSurface->create();
- gl->makeCurrent(tmpSurface);
- }
+ if (m_windows.size() == 0) {
sg->invalidate();
delete gl;
gl = 0;
-
- delete tmpSurface;
}
}
-QQuickCanvas *QQuickTrivialWindowManager::masterCanvas() const
+void QQuickTrivialWindowManager::canvasDestroyed(QQuickCanvas *canvas)
{
- // Find a "proper surface" to bind...
- for (QHash<QQuickCanvas *, CanvasData>::const_iterator it = m_windows.constBegin();
- it != m_windows.constEnd(); ++it) {
- if (it.key()->visible())
- return it.key();
- }
- return 0;
+ hide(canvas);
}
void QQuickTrivialWindowManager::renderCanvas(QQuickCanvas *canvas)
CanvasData &data = const_cast<CanvasData &>(m_windows[canvas]);
- QQuickCanvas *window = canvas->visible() ? canvas : masterCanvas();
+ QQuickCanvas *masterCanvas = 0;
+ if (!canvas->visible()) {
+ // Find a "proper surface" to bind...
+ for (QHash<QQuickCanvas *, CanvasData>::const_iterator it = m_windows.constBegin();
+ it != m_windows.constEnd() && !masterCanvas; ++it) {
+ if (it.key()->visible())
+ masterCanvas = it.key();
+ }
+ } else {
+ masterCanvas = canvas;
+ }
- if (!window)
+ if (!masterCanvas)
return;
if (!gl) {
gl = new QOpenGLContext();
- gl->setFormat(window->requestedFormat());
+ gl->setFormat(masterCanvas->requestedFormat());
gl->create();
- if (!gl->makeCurrent(window))
+ if (!gl->makeCurrent(masterCanvas))
qWarning("QQuickCanvas: makeCurrent() failed...");
sg->initialize(gl);
} else {
- gl->makeCurrent(window);
+ gl->makeCurrent(masterCanvas);
}
bool alsoSwap = data.updatePending;