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
46private:
47 enum UpdateUniformOption {
48 NeedsRedBlueSwap = 1 << 0,
49 NeedsAlphaRotate = 1 << 1
50 };
51 Q_DECLARE_FLAGS(UpdateUniformOptions, UpdateUniformOption)
52 enum UpdateQuadDataOption {
53 NeedsLinearFiltering = 1 << 0
54 };
55 Q_DECLARE_FLAGS(UpdateQuadDataOptions, UpdateQuadDataOption)
56
57 void ensureResources(QRhiSwapChain *swapchain, QRhiResourceUpdateBatch *resourceUpdates);
58 QRhiTexture *toTexture(const QImage &image,
59 QRhi *rhi,
60 QRhiResourceUpdateBatch *resourceUpdates,
61 const QRegion &dirtyRegion,
62 QPlatformBackingStore::TextureFlags *flags) const;
63
64 mutable QRhi *m_rhi = nullptr;
65 mutable QRhiTexture *m_texture = nullptr;
66
67 QRhiBuffer *m_vbuf = nullptr;
68 QRhiSampler *m_samplerNearest = nullptr;
69 QRhiSampler *m_samplerLinear = nullptr;
70 QRhiGraphicsPipeline *m_psNoBlend = nullptr;
71 QRhiGraphicsPipeline *m_psBlend = nullptr;
72 QRhiGraphicsPipeline *m_psPremulBlend = nullptr;
73
74 struct PerQuadData {
75 QRhiBuffer *ubuf = nullptr;
76 // All srbs are layout-compatible.
77 QRhiShaderResourceBindings *srb = nullptr;
78 QRhiShaderResourceBindings *srbExtra = nullptr; // may be null (used for stereo)
79 QRhiTexture *lastUsedTexture = nullptr;
80 QRhiTexture *lastUsedTextureExtra = nullptr; // may be null (used for stereo)
81 QRhiSampler::Filter lastUsedFilter = QRhiSampler::None;
82 bool isValid() const { return ubuf && srb; }
83 void reset() {
84 delete ubuf;
85 ubuf = nullptr;
86 delete srb;
87 srb = nullptr;
88 if (srbExtra) {
89 delete srbExtra;
90 srbExtra = nullptr;
91 }
92 lastUsedTexture = nullptr;
93 lastUsedTextureExtra = nullptr;
94 lastUsedFilter = QRhiSampler::None;
95 }
96 };
97 PerQuadData m_widgetQuadData;
98 QVarLengthArray<PerQuadData, 8> m_textureQuadData;
99
100 PerQuadData createPerQuadData(QRhiTexture *texture, QRhiTexture *textureExtra = nullptr);
101 void updatePerQuadData(PerQuadData *d, QRhiTexture *texture, QRhiTexture *textureExtra = nullptr,
102 UpdateQuadDataOptions options = {});
103 void updateUniforms(PerQuadData *d, QRhiResourceUpdateBatch *resourceUpdates,
104 const QMatrix4x4 &target, const QMatrix3x3 &source,
105 UpdateUniformOptions options = {});
106};
107
108QT_END_NAMESPACE
109
110#endif // QBACKINGSTOREDEFAULTCOMPOSITOR_P_H
111

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