Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 6e2327ca1c896c6d674ae53117299f21 > files > 1615

qtdeclarative5-doc-5.12.6-1.mga7.noarch.rpm

<?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.12.6</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.12</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"><a href="qtquick-index.html">Qt 5.12.6 Reference Documentation</a></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:
  **
  ** &quot;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
  ** &quot;AS IS&quot; 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.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;window_singlethreaded.h&quot;</span>
  <span class="preprocessor">#include &quot;cuberenderer.h&quot;</span>
  <span class="preprocessor">#include &lt;QOpenGLContext&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLFunctions&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLFramebufferObject&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLShaderProgram&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLVertexArrayObject&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLBuffer&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLVertexArrayObject&gt;</span>
  <span class="preprocessor">#include &lt;QOffscreenSurface&gt;</span>
  <span class="preprocessor">#include &lt;QScreen&gt;</span>
  <span class="preprocessor">#include &lt;QQmlEngine&gt;</span>
  <span class="preprocessor">#include &lt;QQmlComponent&gt;</span>
  <span class="preprocessor">#include &lt;QQuickItem&gt;</span>
  <span class="preprocessor">#include &lt;QQuickWindow&gt;</span>
  <span class="preprocessor">#include &lt;QQuickRenderControl&gt;</span>
  <span class="preprocessor">#include &lt;QCoreApplication&gt;</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">QWindow</span> <span class="operator">*</span>w) : m_window(w) { }
      <span class="type">QWindow</span> <span class="operator">*</span>renderWindow(<span class="type">QPoint</span> <span class="operator">*</span>offset) override;

  <span class="keyword">private</span>:
      <span class="type">QWindow</span> <span class="operator">*</span>m_window;
  };

  <span class="type">QWindow</span> <span class="operator">*</span>RenderControl<span class="operator">::</span>renderWindow(<span class="type">QPoint</span> <span class="operator">*</span>offset)
  {
      <span class="keyword">if</span> (offset)
          <span class="operator">*</span>offset <span class="operator">=</span> <span class="type">QPoint</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">QSurface</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">QCoreApplication</span><span class="operator">::</span>arguments()<span class="operator">.</span>contains(<span class="type">QStringLiteral</span>(<span class="string">&quot;--onscreen&quot;</span>));

      <span class="type">QSurfaceFormat</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">QOpenGLContext</span>;
      m_context<span class="operator">-</span><span class="operator">&gt;</span>setFormat(format);
      m_context<span class="operator">-</span><span class="operator">&gt;</span>create();

      m_offscreenSurface <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QOffscreenSurface</span>;
      <span class="comment">// Pass m_context-&gt;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">&gt;</span>setFormat(m_context<span class="operator">-</span><span class="operator">&gt;</span>format());
      m_offscreenSurface<span class="operator">-</span><span class="operator">&gt;</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">&gt;</span>incubationController())
          m_qmlEngine<span class="operator">-</span><span class="operator">&gt;</span>setIncubationController(m_quickWindow<span class="operator">-</span><span class="operator">&gt;</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">&amp;</span>m_updateTimer<span class="operator">,</span> <span class="operator">&amp;</span><span class="type">QTimer</span><span class="operator">::</span>timeout<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</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">&amp;</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">&amp;</span>WindowSingleThreaded<span class="operator">::</span>createFbo);
      connect(m_quickWindow<span class="operator">,</span> <span class="operator">&amp;</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">&amp;</span>WindowSingleThreaded<span class="operator">::</span>destroyFbo);
      connect(m_renderControl<span class="operator">,</span> <span class="operator">&amp;</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">&amp;</span>WindowSingleThreaded<span class="operator">::</span>requestUpdate);
      connect(m_renderControl<span class="operator">,</span> <span class="operator">&amp;</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">&amp;</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">&amp;</span><span class="type">QWindow</span><span class="operator">::</span>screenChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</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">&gt;</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">&gt;</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">QOpenGLFramebufferObject</span>(size() <span class="operator">*</span> m_dpr<span class="operator">,</span> <span class="type">QOpenGLFramebufferObject</span><span class="operator">::</span>CombinedDepthStencil);
          m_quickWindow<span class="operator">-</span><span class="operator">&gt;</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">&gt;</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">QSurface</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">&gt;</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">&gt;</span>polishItems();
      m_renderControl<span class="operator">-</span><span class="operator">&gt;</span>sync();
      m_renderControl<span class="operator">-</span><span class="operator">&gt;</span>render();

      m_quickWindow<span class="operator">-</span><span class="operator">&gt;</span>resetOpenGLState();
      <span class="type">QOpenGLFramebufferObject</span><span class="operator">::</span>bindDefault();

      m_context<span class="operator">-</span><span class="operator">&gt;</span>functions()<span class="operator">-</span><span class="operator">&gt;</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">&gt;</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">&gt;</span>texture() : <span class="number">0</span>);
      <span class="keyword">else</span>
          m_context<span class="operator">-</span><span class="operator">&gt;</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">&amp;</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">&amp;</span>WindowSingleThreaded<span class="operator">::</span>run);

      <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>isError()) {
          <span class="keyword">const</span> <span class="type">QList</span><span class="operator">&lt;</span><span class="type">QQmlError</span><span class="operator">&gt;</span> errorList <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>errors();
          <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type">QQmlError</span> <span class="operator">&amp;</span>error : errorList)
              qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> error<span class="operator">.</span>url() <span class="operator">&lt;</span><span class="operator">&lt;</span> error<span class="operator">.</span>line() <span class="operator">&lt;</span><span class="operator">&lt;</span> error;
          <span class="keyword">return</span>;
      }

      <span class="type">QObject</span> <span class="operator">*</span>rootObject <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>create();
      <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>isError()) {
          <span class="keyword">const</span> <span class="type">QList</span><span class="operator">&lt;</span><span class="type">QQmlError</span><span class="operator">&gt;</span> errorList <span class="operator">=</span> m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>errors();
          <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type">QQmlError</span> <span class="operator">&amp;</span>error : errorList)
              qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> error<span class="operator">.</span>url() <span class="operator">&lt;</span><span class="operator">&lt;</span> error<span class="operator">.</span>line() <span class="operator">&lt;</span><span class="operator">&lt;</span> error;
          <span class="keyword">return</span>;
      }

      m_rootItem <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qquickitem.html">QQuickItem</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(rootObject);
      <span class="keyword">if</span> (<span class="operator">!</span>m_rootItem) {
          qWarning(<span class="string">&quot;run: Not a QQuickItem&quot;</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">&gt;</span>setParentItem(m_quickWindow<span class="operator">-</span><span class="operator">&gt;</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">QSurface</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">&gt;</span>makeCurrent(surface);
      m_renderControl<span class="operator">-</span><span class="operator">&gt;</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">&gt;</span>setWidth(width());
      m_rootItem<span class="operator">-</span><span class="operator">&gt;</span>setHeight(height());

      m_quickWindow<span class="operator">-</span><span class="operator">&gt;</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">&gt;</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">QString</span> <span class="operator">&amp;</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">QUrl</span>(filename));
      <span class="keyword">if</span> (m_qmlComponent<span class="operator">-</span><span class="operator">&gt;</span>isLoading())
          connect(m_qmlComponent<span class="operator">,</span> <span class="operator">&amp;</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">&amp;</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">QExposeEvent</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">&gt;</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">&gt;</span>texture() : <span class="number">0</span>);
              startQuick(<span class="type">QStringLiteral</span>(<span class="string">&quot;qrc:/rendercontrol/demo.qml&quot;</span>));
          }
      }
  }

  <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>resizeFbo()
  {
      <span class="type">QSurface</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">&amp;</span><span class="operator">&amp;</span> m_context<span class="operator">-</span><span class="operator">&gt;</span>makeCurrent(surface)) {
          <span class="keyword">delete</span> m_fbo;
          createFbo();
          m_context<span class="operator">-</span><span class="operator">&gt;</span>doneCurrent();
          updateSizes();
          render();
      }
  }

  <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>resizeEvent(<span class="type">QResizeEvent</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">&amp;</span><span class="operator">&amp;</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</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">QMouseEvent</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">QMouseEvent</span> mappedEvent(e<span class="operator">-</span><span class="operator">&gt;</span>type()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>localPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>screenPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>button()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>buttons()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>modifiers());
      <span class="type">QCoreApplication</span><span class="operator">::</span>sendEvent(m_quickWindow<span class="operator">,</span> <span class="operator">&amp;</span>mappedEvent);
  }

  <span class="type">void</span> WindowSingleThreaded<span class="operator">::</span>mouseReleaseEvent(<span class="type">QMouseEvent</span> <span class="operator">*</span>e)
  {
      <span class="type">QMouseEvent</span> mappedEvent(e<span class="operator">-</span><span class="operator">&gt;</span>type()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>localPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>screenPos()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>button()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>buttons()<span class="operator">,</span> e<span class="operator">-</span><span class="operator">&gt;</span>modifiers());
      <span class="type">QCoreApplication</span><span class="operator">::</span>sendEvent(m_quickWindow<span class="operator">,</span> <span class="operator">&amp;</span>mappedEvent);
  }

</pre>
</div>
<!-- @@@rendercontrol/window_singlethreaded.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>