<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>window_singlethreaded.cpp Example File | Qt Quick 5.11</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtquick-index.html">Qt Quick</a></td><td ><a href="qtquick-rendercontrol-example.html">QQuickRenderControl Example</a></td><td >window_singlethreaded.cpp Example File</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">window_singlethreaded.cpp Example File</h1> <span class="subtitle">rendercontrol/window_singlethreaded.cpp</span> <!-- $$$rendercontrol/window_singlethreaded.cpp-description --> <div class="descr"> <a name="details"></a> <pre class="cpp"> <span class="comment">/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/</span> <span class="preprocessor">#include "window_singlethreaded.h"</span> <span class="preprocessor">#include "cuberenderer.h"</span> <span class="preprocessor">#include <QOpenGLContext></span> <span class="preprocessor">#include <QOpenGLFunctions></span> <span class="preprocessor">#include <QOpenGLFramebufferObject></span> <span class="preprocessor">#include <QOpenGLShaderProgram></span> <span class="preprocessor">#include <QOpenGLVertexArrayObject></span> <span class="preprocessor">#include <QOpenGLBuffer></span> <span class="preprocessor">#include <QOpenGLVertexArrayObject></span> <span class="preprocessor">#include <QOffscreenSurface></span> <span class="preprocessor">#include <QScreen></span> <span class="preprocessor">#include <QQmlEngine></span> <span class="preprocessor">#include <QQmlComponent></span> <span class="preprocessor">#include <QQuickItem></span> <span class="preprocessor">#include <QQuickWindow></span> <span class="preprocessor">#include <QQuickRenderControl></span> <span class="preprocessor">#include <QCoreApplication></span> <span class="keyword">class</span> RenderControl : <span class="keyword">public</span> <span class="type"><a href="qquickrendercontrol.html">QQuickRenderControl</a></span> { <span class="keyword">public</span>: RenderControl(<span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span> <span class="operator">*</span>w) : m_window(w) { } <span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span> <span class="operator">*</span>renderWindow(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> <span class="operator">*</span>offset) override; <span class="keyword">private</span>: <span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span> <span class="operator">*</span>m_window; }; <span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span> <span class="operator">*</span>RenderControl<span class="operator">::</span>renderWindow(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> <span class="operator">*</span>offset) { <span class="keyword">if</span> (offset) <span class="operator">*</span>offset <span class="operator">=</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); <span class="keyword">return</span> m_window; } WindowSingleThreaded<span class="operator">::</span>WindowSingleThreaded() : m_rootItem(nullptr)<span class="operator">,</span> m_fbo(nullptr)<span class="operator">,</span> m_quickInitialized(<span class="keyword">false</span>)<span class="operator">,</span> m_quickReady(<span class="keyword">false</span>)<span class="operator">,</span> m_dpr(<span class="number">0</span>) { setSurfaceType(<span class="type"><a href="../qtgui/qsurface.html">QSurface</a></span><span class="operator">::</span>OpenGLSurface); <span class="comment">// The rendercontrol does not necessarily need an FBO. Demonstrate this</span> <span class="comment">// when requested.</span> m_onscreen <span class="operator">=</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>arguments()<span class="operator">.</span>contains(<span class="type"><a href="../qtcore/qstring.html#QStringLiteral">QStringLiteral</a></span>(<span class="string">"--onscreen"</span>)); <span class="type"><a href="../qtgui/qsurfaceformat.html">QSurfaceFormat</a></span> format; <span class="comment">// Qt Quick may need a depth and stencil buffer. Always make sure these are available.</span> format<span class="operator">.</span>setDepthBufferSize(<span class="number">16</span>); format<span class="operator">.</span>setStencilBufferSize(<span class="number">8</span>); setFormat(format); m_context <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtgui/qopenglcontext.html">QOpenGLContext</a></span>; m_context<span class="operator">-</span><span class="operator">></span>setFormat(format); m_context<span class="operator">-</span><span class="operator">></span>create(); m_offscreenSurface <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtgui/qoffscreensurface.html">QOffscreenSurface</a></span>; <span class="comment">// Pass m_context->format(), not format. Format does not specify and color buffer</span> <span class="comment">// sizes, while the context, that has just been created, reports a format that has</span> <span class="comment">// these values filled in. Pass this to the offscreen surface to make sure it will be</span> <span class="comment">// compatible with the context's configuration.</span> m_offscreenSurface<span class="operator">-</span><span class="operator">></span>setFormat(m_context<span class="operator">-</span><span class="operator">></span>format()); m_offscreenSurface<span class="operator">-</span><span class="operator">></span>create(); m_cubeRenderer <span class="operator">=</span> <span class="keyword">new</span> CubeRenderer(m_offscreenSurface); m_renderControl <span class="operator">=</span> <span class="keyword">new</span> RenderControl(<span class="keyword">this</span>); <span class="comment">// Create a QQuickWindow that is associated with out render control. Note that this</span> <span class="comment">// window never gets created or shown, meaning that it will never get an underlying</span> <span class="comment">// native (platform) window.</span> m_quickWindow <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qquickwindow.html">QQuickWindow</a></span>(m_renderControl); <span class="comment">// Create a QML engine.</span> m_qmlEngine <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtqml/qqmlengine.html">QQmlEngine</a></span>; <span class="keyword">if</span> (<span class="operator">!</span>m_qmlEngine<span class="operator">-</span><span class="operator">></span>incubationController()) m_qmlEngine<span class="operator">-</span><span class="operator">></span>setIncubationController(m_quickWindow<span class="operator">-</span><span class="operator">></span>incubationController()); <span class="comment">// When Quick says there is a need to render, we will not render immediately. Instead,</span> <span class="comment">// a timer with a small interval is used to get better performance.</span> m_updateTimer<span class="operator">.</span>setSingleShot(<span class="keyword">true</span>); m_updateTimer<span class="operator">.</span>setInterval(<span class="number">5</span>); connect(<span class="operator">&</span>m_updateTimer<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtcore/qtimer.html">QTimer</a></span><span class="operator">::</span>timeout<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>render); <span class="comment">// Now hook up the signals. For simplicy we don't differentiate between</span> <span class="comment">// renderRequested (only render is needed, no sync) and sceneChanged (polish and sync</span> <span class="comment">// is needed too).</span> connect(m_quickWindow<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qquickwindow.html">QQuickWindow</a></span><span class="operator">::</span>sceneGraphInitialized<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>createFbo); connect(m_quickWindow<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qquickwindow.html">QQuickWindow</a></span><span class="operator">::</span>sceneGraphInvalidated<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>destroyFbo); connect(m_renderControl<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qquickrendercontrol.html">QQuickRenderControl</a></span><span class="operator">::</span>renderRequested<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>requestUpdate); connect(m_renderControl<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qquickrendercontrol.html">QQuickRenderControl</a></span><span class="operator">::</span>sceneChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>requestUpdate); <span class="comment">// Just recreating the FBO on resize is not sufficient, when moving between screens</span> <span class="comment">// with different devicePixelRatio the QWindow size may remain the same but the FBO</span> <span class="comment">// dimension is to change regardless.</span> connect(<span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span><span class="operator">::</span>screenChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>handleScreenChange); } WindowSingleThreaded<span class="operator">::</span><span class="operator">~</span>WindowSingleThreaded() { <span class="comment">// Make sure the context is current while doing cleanup. Note that we use the</span> <span class="comment">// offscreen surface here because passing 'this' at this point is not safe: the</span> <span class="comment">// underlying platform window may already be destroyed. To avoid all the trouble, use</span> <span class="comment">// another surface that is valid for sure.</span> m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(m_offscreenSurface); <span class="comment">// Delete the render control first since it will free the scenegraph resources.</span> <span class="comment">// Destroy the QQuickWindow only afterwards.</span> <span class="keyword">delete</span> m_renderControl; <span class="keyword">delete</span> m_qmlComponent; <span class="keyword">delete</span> m_quickWindow; <span class="keyword">delete</span> m_qmlEngine; <span class="keyword">delete</span> m_fbo; m_context<span class="operator">-</span><span class="operator">></span>doneCurrent(); <span class="keyword">delete</span> m_cubeRenderer; <span class="keyword">delete</span> m_offscreenSurface; <span class="keyword">delete</span> m_context; } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>createFbo() { <span class="comment">// The scene graph has been initialized. It is now time to create an FBO and associate</span> <span class="comment">// it with the QQuickWindow.</span> m_dpr <span class="operator">=</span> devicePixelRatio(); <span class="keyword">if</span> (<span class="operator">!</span>m_onscreen) { m_fbo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtgui/qopenglframebufferobject.html">QOpenGLFramebufferObject</a></span>(size() <span class="operator">*</span> m_dpr<span class="operator">,</span> <span class="type"><a href="../qtgui/qopenglframebufferobject.html">QOpenGLFramebufferObject</a></span><span class="operator">::</span>CombinedDepthStencil); m_quickWindow<span class="operator">-</span><span class="operator">></span>setRenderTarget(m_fbo); } <span class="keyword">else</span> { <span class="comment">// Special case: No FBO. Render directly to the window's default framebuffer.</span> m_onscreenSize <span class="operator">=</span> size() <span class="operator">*</span> m_dpr; m_quickWindow<span class="operator">-</span><span class="operator">></span>setRenderTarget(<span class="number">0</span><span class="operator">,</span> m_onscreenSize); } } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>destroyFbo() { <span class="keyword">delete</span> m_fbo; m_fbo <span class="operator">=</span> nullptr; } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>render() { <span class="type"><a href="../qtgui/qsurface.html">QSurface</a></span> <span class="operator">*</span>surface <span class="operator">=</span> m_offscreenSurface; <span class="keyword">if</span> (m_onscreen) surface <span class="operator">=</span> <span class="keyword">this</span>; <span class="keyword">if</span> (<span class="operator">!</span>m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(surface)) <span class="keyword">return</span>; <span class="comment">// Polish, synchronize and render the next frame (into our fbo). In this example</span> <span class="comment">// everything happens on the same thread and therefore all three steps are performed</span> <span class="comment">// in succession from here. In a threaded setup the render() call would happen on a</span> <span class="comment">// separate thread.</span> m_renderControl<span class="operator">-</span><span class="operator">></span>polishItems(); m_renderControl<span class="operator">-</span><span class="operator">></span>sync(); m_renderControl<span class="operator">-</span><span class="operator">></span>render(); m_quickWindow<span class="operator">-</span><span class="operator">></span>resetOpenGLState(); <span class="type"><a href="../qtgui/qopenglframebufferobject.html">QOpenGLFramebufferObject</a></span><span class="operator">::</span>bindDefault(); m_context<span class="operator">-</span><span class="operator">></span>functions()<span class="operator">-</span><span class="operator">></span>glFlush(); m_quickReady <span class="operator">=</span> <span class="keyword">true</span>; <span class="comment">// Get something onto the screen.</span> <span class="keyword">if</span> (<span class="operator">!</span>m_onscreen) m_cubeRenderer<span class="operator">-</span><span class="operator">></span>render(<span class="keyword">this</span><span class="operator">,</span> m_context<span class="operator">,</span> m_quickReady <span class="operator">?</span> m_fbo<span class="operator">-</span><span class="operator">></span>texture() : <span class="number">0</span>); <span class="keyword">else</span> m_context<span class="operator">-</span><span class="operator">></span>swapBuffers(<span class="keyword">this</span>); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>requestUpdate() { <span class="keyword">if</span> (<span class="operator">!</span>m_updateTimer<span class="operator">.</span>isActive()) m_updateTimer<span class="operator">.</span>start(); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>run() { disconnect(m_qmlComponent<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtqml/qqmlcomponent.html">QQmlComponent</a></span><span class="operator">::</span>statusChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>run); <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">></span>isError()) { <span class="keyword">const</span> <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="../qtqml/qqmlerror.html">QQmlError</a></span><span class="operator">></span> errorList <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">></span>errors(); <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type"><a href="../qtqml/qqmlerror.html">QQmlError</a></span> <span class="operator">&</span>error : errorList) <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator"><</span><span class="operator"><</span> error<span class="operator">.</span>url() <span class="operator"><</span><span class="operator"><</span> error<span class="operator">.</span>line() <span class="operator"><</span><span class="operator"><</span> error; <span class="keyword">return</span>; } <span class="type"><a href="../qtcore/qobject.html">QObject</a></span> <span class="operator">*</span>rootObject <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">></span>create(); <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">></span>isError()) { <span class="keyword">const</span> <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="../qtqml/qqmlerror.html">QQmlError</a></span><span class="operator">></span> errorList <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">></span>errors(); <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type"><a href="../qtqml/qqmlerror.html">QQmlError</a></span> <span class="operator">&</span>error : errorList) <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator"><</span><span class="operator"><</span> error<span class="operator">.</span>url() <span class="operator"><</span><span class="operator"><</span> error<span class="operator">.</span>line() <span class="operator"><</span><span class="operator"><</span> error; <span class="keyword">return</span>; } m_rootItem <span class="operator">=</span> qobject_cast<span class="operator"><</span><span class="type"><a href="qquickitem.html">QQuickItem</a></span> <span class="operator">*</span><span class="operator">></span>(rootObject); <span class="keyword">if</span> (<span class="operator">!</span>m_rootItem) { <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>(<span class="string">"run: Not a QQuickItem"</span>); <span class="keyword">delete</span> rootObject; <span class="keyword">return</span>; } <span class="comment">// The root item is ready. Associate it with the window.</span> m_rootItem<span class="operator">-</span><span class="operator">></span>setParentItem(m_quickWindow<span class="operator">-</span><span class="operator">></span>contentItem()); <span class="comment">// Update item and rendering related geometries.</span> updateSizes(); <span class="comment">// Initialize the render control and our OpenGL resources.</span> <span class="type"><a href="../qtgui/qsurface.html">QSurface</a></span> <span class="operator">*</span>surface <span class="operator">=</span> m_offscreenSurface; <span class="keyword">if</span> (m_onscreen) surface <span class="operator">=</span> <span class="keyword">this</span>; m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(surface); m_renderControl<span class="operator">-</span><span class="operator">></span>initialize(m_context); m_quickInitialized <span class="operator">=</span> <span class="keyword">true</span>; } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>updateSizes() { <span class="comment">// Behave like SizeRootObjectToView.</span> m_rootItem<span class="operator">-</span><span class="operator">></span>setWidth(width()); m_rootItem<span class="operator">-</span><span class="operator">></span>setHeight(height()); m_quickWindow<span class="operator">-</span><span class="operator">></span>setGeometry(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> width()<span class="operator">,</span> height()); m_cubeRenderer<span class="operator">-</span><span class="operator">></span>resize(width()<span class="operator">,</span> height()); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>startQuick(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&</span>filename) { m_qmlComponent <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtqml/qqmlcomponent.html">QQmlComponent</a></span>(m_qmlEngine<span class="operator">,</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span>(filename)); <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">></span>isLoading()) connect(m_qmlComponent<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtqml/qqmlcomponent.html">QQmlComponent</a></span><span class="operator">::</span>statusChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>WindowSingleThreaded<span class="operator">::</span>run); <span class="keyword">else</span> run(); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>exposeEvent(<span class="type"><a href="../qtgui/qexposeevent.html">QExposeEvent</a></span> <span class="operator">*</span>) { <span class="keyword">if</span> (isExposed()) { <span class="keyword">if</span> (<span class="operator">!</span>m_quickInitialized) { <span class="keyword">if</span> (<span class="operator">!</span>m_onscreen) m_cubeRenderer<span class="operator">-</span><span class="operator">></span>render(<span class="keyword">this</span><span class="operator">,</span> m_context<span class="operator">,</span> m_quickReady <span class="operator">?</span> m_fbo<span class="operator">-</span><span class="operator">></span>texture() : <span class="number">0</span>); startQuick(<span class="type"><a href="../qtcore/qstring.html#QStringLiteral">QStringLiteral</a></span>(<span class="string">"qrc:/rendercontrol/demo.qml"</span>)); } } } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>resizeFbo() { <span class="type"><a href="../qtgui/qsurface.html">QSurface</a></span> <span class="operator">*</span>surface <span class="operator">=</span> m_offscreenSurface; <span class="keyword">if</span> (m_onscreen) surface <span class="operator">=</span> <span class="keyword">this</span>; <span class="keyword">if</span> (m_rootItem <span class="operator">&</span><span class="operator">&</span> m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(surface)) { <span class="keyword">delete</span> m_fbo; createFbo(); m_context<span class="operator">-</span><span class="operator">></span>doneCurrent(); updateSizes(); render(); } } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>resizeEvent(<span class="type"><a href="../qtgui/qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>) { <span class="comment">// If this is a resize after the scene is up and running, recreate the fbo and the</span> <span class="comment">// Quick item and scene.</span> <span class="keyword">if</span> (<span class="operator">!</span>m_onscreen) { <span class="keyword">if</span> (m_fbo <span class="operator">&</span><span class="operator">&</span> m_fbo<span class="operator">-</span><span class="operator">></span>size() <span class="operator">!</span><span class="operator">=</span> size() <span class="operator">*</span> devicePixelRatio()) resizeFbo(); } <span class="keyword">else</span> { <span class="keyword">if</span> (m_onscreenSize <span class="operator">!</span><span class="operator">=</span> size() <span class="operator">*</span> devicePixelRatio()) resizeFbo(); } } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>handleScreenChange() { <span class="keyword">if</span> (m_dpr <span class="operator">!</span><span class="operator">=</span> devicePixelRatio()) resizeFbo(); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e) { <span class="comment">// Use the constructor taking localPos and screenPos. That puts localPos into the</span> <span class="comment">// event's localPos and windowPos, and screenPos into the event's screenPos. This way</span> <span class="comment">// the windowPos in e is ignored and is replaced by localPos. This is necessary</span> <span class="comment">// because QQuickWindow thinks of itself as a top-level window always.</span> <span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> mappedEvent(e<span class="operator">-</span><span class="operator">></span>type()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>localPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>screenPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>button()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>buttons()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>modifiers()); <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>sendEvent(m_quickWindow<span class="operator">,</span> <span class="operator">&</span>mappedEvent); } <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>mouseReleaseEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e) { <span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> mappedEvent(e<span class="operator">-</span><span class="operator">></span>type()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>localPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>screenPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>button()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>buttons()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">></span>modifiers()); <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>sendEvent(m_quickWindow<span class="operator">,</span> <span class="operator">&</span>mappedEvent); } </pre> </div> <!-- @@@rendercontrol/window_singlethreaded.cpp --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>