aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-04 10:24:46 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-04 10:28:48 +0200
commit9556f6d075b61fa95d6e1057f305e522a26f71d6 (patch)
tree53190472453390810c47b9b5a47b23188a00267e /examples/quick
parent42ffe9b193a5bd958b0853233fd0d94170722bd1 (diff)
parent1fd0cdc6a2e01775d8a79c6614910cc5a2fbf2b3 (diff)
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts: src/qml/jsruntime/qv4engine_p.h src/quick/items/qquickitemsmodule.cpp src/quick/items/qquicktext.cpp src/quick/util/qquickpixmapcache.cpp tests/auto/quick/qquickwindow/tst_qquickwindow.cpp Change-Id: I90ecaad6a4bfaa4f36149a7463f4d7141f4a516a
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/demos/calqlatr/content/Display.qml2
-rw-r--r--examples/quick/rendercontrol/window_multithreaded.cpp12
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.cpp50
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.h3
4 files changed, 59 insertions, 8 deletions
diff --git a/examples/quick/demos/calqlatr/content/Display.qml b/examples/quick/demos/calqlatr/content/Display.qml
index 119e99602f..cf93d878bb 100644
--- a/examples/quick/demos/calqlatr/content/Display.qml
+++ b/examples/quick/demos/calqlatr/content/Display.qml
@@ -168,7 +168,7 @@ Item {
width: display.width
height: display.height - 50 - y
delegate: Item {
- height: 20
+ height: display.fontSize * 1.1
width: parent.width
Text {
id: operator
diff --git a/examples/quick/rendercontrol/window_multithreaded.cpp b/examples/quick/rendercontrol/window_multithreaded.cpp
index 9b6020a347..8de5a7776d 100644
--- a/examples/quick/rendercontrol/window_multithreaded.cpp
+++ b/examples/quick/rendercontrol/window_multithreaded.cpp
@@ -213,6 +213,16 @@ void QuickRenderer::aboutToQuit()
m_quit = true;
}
+class RenderControl : public QQuickRenderControl
+{
+public:
+ RenderControl(QWindow *w) : m_window(w) { }
+ QWindow *renderWindow(QPoint *offset) Q_DECL_OVERRIDE;
+
+private:
+ QWindow *m_window;
+};
+
WindowMultiThreaded::WindowMultiThreaded()
: m_qmlComponent(Q_NULLPTR),
m_rootItem(0),
@@ -239,7 +249,7 @@ WindowMultiThreaded::WindowMultiThreaded()
m_offscreenSurface->setFormat(m_context->format());
m_offscreenSurface->create();
- m_renderControl = new QQuickRenderControl(this);
+ m_renderControl = new RenderControl(this);
// Create a QQuickWindow that is associated with out render control. Note that this
// window never gets created or shown, meaning that it will never get an underlying
diff --git a/examples/quick/rendercontrol/window_singlethreaded.cpp b/examples/quick/rendercontrol/window_singlethreaded.cpp
index 5377c56376..1e81f08f7e 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.cpp
+++ b/examples/quick/rendercontrol/window_singlethreaded.cpp
@@ -48,6 +48,7 @@
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include <QOffscreenSurface>
+#include <QScreen>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickItem>
@@ -55,11 +56,29 @@
#include <QQuickRenderControl>
#include <QCoreApplication>
+class RenderControl : public QQuickRenderControl
+{
+public:
+ RenderControl(QWindow *w) : m_window(w) { }
+ QWindow *renderWindow(QPoint *offset) Q_DECL_OVERRIDE;
+
+private:
+ QWindow *m_window;
+};
+
+QWindow *RenderControl::renderWindow(QPoint *offset)
+{
+ if (offset)
+ *offset = QPoint(0, 0);
+ return m_window;
+}
+
WindowSingleThreaded::WindowSingleThreaded()
: m_rootItem(0),
m_fbo(0),
m_quickInitialized(false),
- m_quickReady(false)
+ m_quickReady(false),
+ m_dpr(0)
{
setSurfaceType(QSurface::OpenGLSurface);
@@ -83,7 +102,7 @@ WindowSingleThreaded::WindowSingleThreaded()
m_cubeRenderer = new CubeRenderer(m_offscreenSurface);
- m_renderControl = new QQuickRenderControl(this);
+ m_renderControl = new RenderControl(this);
// Create a QQuickWindow that is associated with out render control. Note that this
// window never gets created or shown, meaning that it will never get an underlying
@@ -108,6 +127,11 @@ WindowSingleThreaded::WindowSingleThreaded()
connect(m_quickWindow, &QQuickWindow::sceneGraphInvalidated, this, &WindowSingleThreaded::destroyFbo);
connect(m_renderControl, &QQuickRenderControl::renderRequested, this, &WindowSingleThreaded::requestUpdate);
connect(m_renderControl, &QQuickRenderControl::sceneChanged, this, &WindowSingleThreaded::requestUpdate);
+
+ // Just recreating the FBO on resize is not sufficient, when moving between screens
+ // with different devicePixelRatio the QWindow size may remain the same but the FBO
+ // dimension is to change regardless.
+ connect(this, &QWindow::screenChanged, this, &WindowSingleThreaded::handleScreenChange);
}
WindowSingleThreaded::~WindowSingleThreaded()
@@ -139,7 +163,8 @@ void WindowSingleThreaded::createFbo()
{
// The scene graph has been initialized. It is now time to create an FBO and associate
// it with the QQuickWindow.
- m_fbo = new QOpenGLFramebufferObject(size() * devicePixelRatio(), QOpenGLFramebufferObject::CombinedDepthStencil);
+ m_dpr = devicePixelRatio();
+ m_fbo = new QOpenGLFramebufferObject(size() * m_dpr, QOpenGLFramebufferObject::CombinedDepthStencil);
m_quickWindow->setRenderTarget(m_fbo);
}
@@ -246,18 +271,31 @@ void WindowSingleThreaded::exposeEvent(QExposeEvent *)
}
}
-void WindowSingleThreaded::resizeEvent(QResizeEvent *)
+void WindowSingleThreaded::resizeFbo()
{
- // If this is a resize after the scene is up and running, recreate the fbo and the
- // Quick item and scene.
if (m_rootItem && m_context->makeCurrent(m_offscreenSurface)) {
delete m_fbo;
createFbo();
m_context->doneCurrent();
updateSizes();
+ render();
}
}
+void WindowSingleThreaded::resizeEvent(QResizeEvent *)
+{
+ // If this is a resize after the scene is up and running, recreate the fbo and the
+ // Quick item and scene.
+ if (m_fbo && m_fbo->size() != size() * devicePixelRatio())
+ resizeFbo();
+}
+
+void WindowSingleThreaded::handleScreenChange()
+{
+ if (m_dpr != devicePixelRatio())
+ resizeFbo();
+}
+
void WindowSingleThreaded::mousePressEvent(QMouseEvent *e)
{
// Use the constructor taking localPos and screenPos. That puts localPos into the
diff --git a/examples/quick/rendercontrol/window_singlethreaded.h b/examples/quick/rendercontrol/window_singlethreaded.h
index 5344199c18..534d6b9bc3 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.h
+++ b/examples/quick/rendercontrol/window_singlethreaded.h
@@ -77,10 +77,12 @@ private slots:
void destroyFbo();
void render();
void requestUpdate();
+ void handleScreenChange();
private:
void startQuick(const QString &filename);
void updateSizes();
+ void resizeFbo();
QOpenGLContext *m_context;
QOffscreenSurface *m_offscreenSurface;
@@ -94,6 +96,7 @@ private:
bool m_quickReady;
QTimer m_updateTimer;
CubeRenderer *m_cubeRenderer;
+ qreal m_dpr;
};
#endif