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
21QT_BEGIN_NAMESPACE
22
23class QBackingStoreDefaultCompositor
24{
25public:
26 ~QBackingStoreDefaultCompositor();
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)
53 enum UpdateQuadDataOption {
54 NeedsLinearFiltering = 1 << 0
55 };
56 Q_DECLARE_FLAGS(UpdateQuadDataOptions, UpdateQuadDataOption)
57
58 void ensureResources(QRhiResourceUpdateBatch *resourceUpdates, QRhiRenderPassDescriptor *rpDesc);
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
112

source code of qtbase/src/gui/painting/qbackingstoredefaultcompositor_p.h