Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbackingstoredefaultcompositor_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBACKINGSTOREDEFAULTCOMPOSITOR_P_H
5#define QBACKINGSTOREDEFAULTCOMPOSITOR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qpa/qplatformbackingstore.h>
19#include <rhi/qrhi.h>
20
22
24{
25public:
27
28 void reset();
29
30 QRhiTexture *toTexture(const QPlatformBackingStore *backingStore,
31 QRhi *rhi,
32 QRhiResourceUpdateBatch *resourceUpdates,
33 const QRegion &dirtyRegion,
34 QPlatformBackingStore::TextureFlags *flags) const;
35
36 QPlatformBackingStore::FlushResult flush(QPlatformBackingStore *backingStore,
37 QRhi *rhi,
38 QRhiSwapChain *swapchain,
39 QWindow *window,
40 qreal sourceDevicePixelRatio,
41 const QRegion &region,
42 const QPoint &offset,
43 QPlatformTextureList *textures,
44 bool translucentBackground,
45 qreal sourceTransformFactor);
46
47private:
48 enum UpdateUniformOption {
49 NeedsRedBlueSwap = 1 << 0,
50 NeedsAlphaRotate = 1 << 1
51 };
52 Q_DECLARE_FLAGS(UpdateUniformOptions, UpdateUniformOption)
55 };
56 Q_DECLARE_FLAGS(UpdateQuadDataOptions, UpdateQuadDataOption)
57
59 QRhiTexture *toTexture(const QImage &image,
60 QRhi *rhi,
61 QRhiResourceUpdateBatch *resourceUpdates,
62 const QRegion &dirtyRegion,
63 QPlatformBackingStore::TextureFlags *flags) const;
64
65 mutable QRhi *m_rhi = nullptr;
66 mutable std::unique_ptr<QRhiTexture> m_texture;
67
68 std::unique_ptr<QRhiBuffer> m_vbuf;
69 std::unique_ptr<QRhiSampler> m_samplerNearest;
70 std::unique_ptr<QRhiSampler> m_samplerLinear;
71 std::unique_ptr<QRhiGraphicsPipeline> m_psNoBlend;
72 std::unique_ptr<QRhiGraphicsPipeline> m_psBlend;
73 std::unique_ptr<QRhiGraphicsPipeline> m_psPremulBlend;
74
75 struct PerQuadData {
76 QRhiBuffer *ubuf = nullptr;
77 // All srbs are layout-compatible.
78 QRhiShaderResourceBindings *srb = nullptr;
79 QRhiShaderResourceBindings *srbExtra = nullptr; // may be null (used for stereo)
80 QRhiTexture *lastUsedTexture = nullptr;
81 QRhiTexture *lastUsedTextureExtra = nullptr; // may be null (used for stereo)
82 QRhiSampler::Filter lastUsedFilter = QRhiSampler::None;
83 bool isValid() const { return ubuf && srb; }
84 void reset() {
85 delete ubuf;
86 ubuf = nullptr;
87 delete srb;
88 srb = nullptr;
89 if (srbExtra) {
90 delete srbExtra;
91 srbExtra = nullptr;
92 }
93 lastUsedTexture = nullptr;
94 lastUsedTextureExtra = nullptr;
95 lastUsedFilter = QRhiSampler::None;
96 }
97 };
98 PerQuadData m_widgetQuadData;
99 QVarLengthArray<PerQuadData, 8> m_textureQuadData;
100
101 PerQuadData createPerQuadData(QRhiTexture *texture, QRhiTexture *textureExtra = nullptr);
102 void updatePerQuadData(PerQuadData *d, QRhiTexture *texture, QRhiTexture *textureExtra = nullptr,
103 UpdateQuadDataOptions options = {});
104 void updateUniforms(PerQuadData *d, QRhiResourceUpdateBatch *resourceUpdates,
105 const QMatrix4x4 &target, const QMatrix3x3 &source,
106 UpdateUniformOptions options = {});
107};
108
109QT_END_NAMESPACE
110
111#endif // QBACKINGSTOREDEFAULTCOMPOSITOR_P_H
QRhiTexture * toTexture(const QPlatformBackingStore *backingStore, QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates, const QRegion &dirtyRegion, QPlatformBackingStore::TextureFlags *flags) const
QPlatformBackingStore::FlushResult flush(QPlatformBackingStore *backingStore, QRhi *rhi, QRhiSwapChain *swapchain, QWindow *window, qreal sourceDevicePixelRatio, const QRegion &region, const QPoint &offset, QPlatformTextureList *textures, bool translucentBackground, qreal sourceTransformFactor)
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:661
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:721
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:322
static QRegion scaledRegion(const QRegion &region, qreal factor, const QPoint &offset)
static QMatrix4x4 targetTransform(const QRectF &target, const QRect &viewport, bool invertY)
static QRect scaledRect(const QRect &rect, qreal factor)
static QMatrix3x3 sourceTransform(const QRectF &subTexture, const QSize &textureSize, SourceTransformOrigin origin)
static void updateMatrix3x3(QRhiResourceUpdateBatch *resourceUpdates, QRhiBuffer *ubuf, const QMatrix3x3 &m)
static QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight)
static QShader getShader(const QString &name)
static QPoint scaledOffset(const QPoint &pt, qreal factor)
static bool prepareDrawForRenderToTextureWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect, const QPoint &offset, bool invertTargetY, bool invertSource, QMatrix4x4 *target, QMatrix3x3 *source)
static const int UBUF_SIZE
static QRhiGraphicsPipeline * createGraphicsPipeline(QRhi *rhi, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc, PipelineBlend blend)