summaryrefslogtreecommitdiff
path: root/src/quick/items/qquickwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickwindow.cpp')
-rw-r--r--src/quick/items/qquickwindow.cpp70
1 files changed, 52 insertions, 18 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 4a34adabe8..619c72afb8 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -74,6 +74,8 @@ QT_BEGIN_NAMESPACE
extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
+bool QQuickWindowPrivate::defaultAlphaBuffer(0);
+
void QQuickWindowPrivate::updateFocusItemTransform()
{
Q_Q(QQuickWindow);
@@ -87,44 +89,49 @@ void QQuickWindowPrivate::updateFocusItemTransform()
#endif
}
-
class QQuickWindowIncubationController : public QObject, public QQmlIncubationController
{
Q_OBJECT
public:
- QQuickWindowIncubationController(const QQuickWindow *window)
- : m_window(QQuickWindowPrivate::get(const_cast<QQuickWindow *>(window)))
+ QQuickWindowIncubationController(QSGRenderLoop *loop)
+ : m_renderLoop(loop), m_timer(0)
{
// Allow incubation for 1/3 of a frame.
m_incubation_time = qMax(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3);
- m_animation_driver = m_window->windowManager->animationDriver();
+ m_animation_driver = m_renderLoop->animationDriver();
if (m_animation_driver) {
connect(m_animation_driver, SIGNAL(stopped()), this, SLOT(animationStopped()));
- connect(window, SIGNAL(frameSwapped()), this, SLOT(incubate()));
+ connect(m_renderLoop, SIGNAL(timeToIncubate()), this, SLOT(incubate()));
}
}
protected:
- virtual bool event(QEvent *e)
+ void timerEvent(QTimerEvent *)
{
- if (e->type() == QEvent::User) {
- incubate();
- return true;
+ killTimer(m_timer);
+ m_timer = 0;
+ incubate();
+ }
+
+ void incubateAgain() {
+ if (m_timer == 0) {
+ // Wait for a while before processing the next batch. Using a
+ // timer to avoid starvation of system events.
+ m_timer = startTimer(m_incubation_time);
}
- return QObject::event(e);
}
public slots:
void incubate() {
if (incubatingObjectCount()) {
- if (m_animation_driver && m_animation_driver->isRunning()) {
+ if (m_renderLoop->interleaveIncubation()) {
incubateFor(m_incubation_time);
} else {
incubateFor(m_incubation_time * 2);
if (incubatingObjectCount())
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
+ incubateAgain();
}
}
}
@@ -134,14 +141,15 @@ public slots:
protected:
virtual void incubatingObjectCountChanged(int count)
{
- if (count && (!m_animation_driver || !m_animation_driver->isRunning()))
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
+ if (count && !m_renderLoop->interleaveIncubation())
+ incubateAgain();
}
private:
- QQuickWindowPrivate *m_window;
+ QSGRenderLoop *m_renderLoop;
int m_incubation_time;
QAnimationDriver *m_animation_driver;
+ int m_timer;
};
#include "qquickwindow.moc"
@@ -347,6 +355,7 @@ QQuickWindowPrivate::QQuickWindowPrivate()
, persistentGLContext(true)
, persistentSceneGraph(true)
, lastWheelEventAccepted(false)
+ , componentCompleted(true)
, renderTarget(0)
, renderTargetId(0)
, incubationController(0)
@@ -2777,7 +2786,7 @@ QQmlIncubationController *QQuickWindow::incubationController() const
Q_D(const QQuickWindow);
if (!d->incubationController)
- d->incubationController = new QQuickWindowIncubationController(this);
+ d->incubationController = new QQuickWindowIncubationController(d->windowManager);
return d->incubationController;
}
@@ -2969,7 +2978,7 @@ QSGTexture *QQuickWindow::createTextureFromId(uint id, const QSize &size, Create
Setting the clear color has no effect when clearing is disabled.
By default, the clear color is white.
- \sa setClearBeforeRendering()
+ \sa setClearBeforeRendering(), setDefaultAlphaBuffer()
*/
void QQuickWindow::setColor(const QColor &color)
@@ -2979,7 +2988,7 @@ void QQuickWindow::setColor(const QColor &color)
return;
if (color.alpha() != d->clearColor.alpha()) {
- QSurfaceFormat fmt = format();
+ QSurfaceFormat fmt = requestedFormat();
if (color.alpha() < 255)
fmt.setAlphaBufferSize(8);
else
@@ -2997,6 +3006,31 @@ QColor QQuickWindow::color() const
}
/*!
+ \brief Returns whether to use alpha transparency on newly created windows.
+
+ \since Qt 5.1
+ \sa setDefaultAlphaBuffer()
+ */
+bool QQuickWindow::hasDefaultAlphaBuffer()
+{
+ return QQuickWindowPrivate::defaultAlphaBuffer;
+}
+
+/*!
+ \brief \a useAlpha specifies whether to use alpha transparency on newly created windows.
+ \since Qt 5.1
+
+ In any application which expects to create translucent windows, it's
+ necessary to set this to true before creating the first QQuickWindow,
+ because all windows will share the same \l QOpenGLContext. The default
+ value is false.
+ */
+void QQuickWindow::setDefaultAlphaBuffer(bool useAlpha)
+{
+ QQuickWindowPrivate::defaultAlphaBuffer = useAlpha;
+}
+
+/*!
\qmlproperty string QtQuick.Window2::Window::title
The window's title in the windowing system.