diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-04-16 15:56:33 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-04-28 15:02:06 +0000 |
commit | e3f56a8b8d749f9eb4816ee7f6355f59dac173e6 (patch) | |
tree | 31678da718dad7ac048670aa4664831a1af0a69d | |
parent | 4da32851de3a1f462e1077fd9c59849863547af9 (diff) |
Fix rendercontrol example for screens with different dpr
renderWindow() was not reimplemented in the example. This is pretty
bad since renderWindowFor() fails to find a window and thus falls
back to using the default device pixel ratio (which is the highest
dpr present in the system). The result is broken content from Quick
because it operates with a dpr of 2 any time a retina screen is connected,
even when the example's own QWindow is placed on a normal screen.
Add also a note to the QQuickRenderControl docs because it is easy to
overlook.
Task-number: QTBUG-45613
Change-Id: I31bf92ec285f3d9867a5604a4b4e3bea73791932
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r-- | examples/quick/rendercontrol/window_multithreaded.cpp | 12 | ||||
-rw-r--r-- | examples/quick/rendercontrol/window_singlethreaded.cpp | 19 | ||||
-rw-r--r-- | src/quick/items/qquickrendercontrol.cpp | 5 |
3 files changed, 34 insertions, 2 deletions
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 a5748530df..1e81f08f7e 100644 --- a/examples/quick/rendercontrol/window_singlethreaded.cpp +++ b/examples/quick/rendercontrol/window_singlethreaded.cpp @@ -56,6 +56,23 @@ #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), @@ -85,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 diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index e1ca662277..fd4787be98 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -367,6 +367,11 @@ void QQuickRenderControlPrivate::maybeUpdate() If \a offset in non-null, it is set to the offset of the control inside the window. + + \note While not mandatory, reimplementing this function becomes essential for + supporting multiple screens with different device pixel ratios and properly positioning + popup windows opened from QML. Therefore providing it in subclasses is highly + recommended. */ /*! |