/usr/share/qt5/doc/qtquick/qtquick-rendercontrol-window-singlethreaded-cpp.html is in qtdeclarative5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | <?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.9</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 >Qt 5.9</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.9.5 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) Q_DECL_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(<span class="number">0</span>)<span class="operator">,</span>
m_fbo(<span class="number">0</span>)<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="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">QQmlEngine</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();
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="type">void</span> WindowSingleThreaded<span class="operator">::</span>destroyFbo()
{
<span class="keyword">delete</span> m_fbo;
m_fbo <span class="operator">=</span> <span class="number">0</span>;
}
<span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>render()
{
<span class="keyword">if</span> (<span class="operator">!</span>m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(m_offscreenSurface))
<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>
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="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">QQmlComponent</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">QQmlError</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">QQmlError</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">QQmlError</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">QQmlError</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>
m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(m_offscreenSurface);
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">QQmlComponent</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">QQmlComponent</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) {
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="keyword">if</span> (m_rootItem <span class="operator">&</span><span class="operator">&</span> m_context<span class="operator">-</span><span class="operator">></span>makeCurrent(m_offscreenSurface)) {
<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> (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="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> 2017 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>
|