1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "rendersurfaceselector_p.h"
5#include <Qt3DRender/qrendersurfaceselector.h>
6#include <Qt3DRender/private/qrendersurfaceselector_p.h>
7#include <QtGui/qwindow.h>
8#include <QtGui/qscreen.h>
9#include <QtGui/qoffscreensurface.h>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace {
16
17QSurface *surfaceFromQObject(QObject *o)
18{
19 QSurface *surface = nullptr;
20 QWindow *window = qobject_cast<QWindow *>(o);
21 if (window) {
22 surface = static_cast<QSurface *>(window);
23 } else {
24 QOffscreenSurface *offscreen = qobject_cast<QOffscreenSurface *>(object: o);
25 if (offscreen)
26 surface = static_cast<QSurface *>(offscreen);
27 }
28 return surface;
29}
30
31}
32
33namespace Qt3DRender {
34namespace Render {
35
36RenderSurfaceSelector::RenderSurfaceSelector()
37 : FrameGraphNode(FrameGraphNode::Surface)
38 , m_surfaceObj(nullptr)
39 , m_surface(nullptr)
40 , m_width(0)
41 , m_height(0)
42 , m_devicePixelRatio(0.0f)
43{
44}
45
46void RenderSurfaceSelector::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
47{
48 const QRenderSurfaceSelector *node = qobject_cast<const QRenderSurfaceSelector *>(object: frontEnd);
49 if (!node)
50 return;
51
52 FrameGraphNode::syncFromFrontEnd(frontEnd, firstTime);
53
54 if (node->surface() != m_surfaceObj) {
55 m_surfaceObj = node->surface();
56 m_surface = surfaceFromQObject(o: m_surfaceObj);
57 markDirty(changes: AbstractRenderer::FrameGraphDirty);
58 }
59
60 if (m_surface && m_surface->surfaceClass() == QSurface::Window) {
61 QWindow *window = static_cast<QWindow *>(m_surface);
62 if (window->width() != m_width) {
63 m_width = window->width();
64 markDirty(changes: AbstractRenderer::FrameGraphDirty);
65 }
66 if (window->height() != m_height) {
67 m_height = window->height();
68 markDirty(changes: AbstractRenderer::FrameGraphDirty);
69 }
70 }
71
72 if (node->externalRenderTargetSize() != m_renderTargetSize) {
73 m_renderTargetSize = node->externalRenderTargetSize();
74 markDirty(changes: AbstractRenderer::FrameGraphDirty);
75 }
76
77 if (node->surfacePixelRatio() != m_devicePixelRatio) {
78 m_devicePixelRatio = node->surfacePixelRatio();
79 markDirty(changes: AbstractRenderer::FrameGraphDirty);
80 }
81}
82
83QSize RenderSurfaceSelector::renderTargetSize() const
84{
85 if (m_renderTargetSize.isValid())
86 return m_renderTargetSize;
87 return QSize(m_width, m_height);
88}
89
90} // namespace Render
91} // namespace Qt3DRender
92
93QT_END_NAMESPACE
94

source code of qt3d/src/render/framegraph/rendersurfaceselector.cpp