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
qcachedvalue_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QCACHEDVALUE_P_H
5#define QCACHEDVALUE_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 <QReadWriteLock>
19
20#include <optional>
21#include <unordered_map>
22
23QT_BEGIN_NAMESPACE
24
25template <typename T>
26class QCachedValue
27{
28public:
29 QCachedValue() = default;
30
31 Q_DISABLE_COPY(QCachedValue)
32
33 template <typename Creator>
34 T ensure(Creator &&creator)
35 {
36 {
37 QReadLocker locker(&m_lock);
38 if (m_cached)
39 return *m_cached;
40 }
41
42 {
43 QWriteLocker locker(&m_lock);
44 if (!m_cached)
45 m_cached = creator();
46 return *m_cached;
47 }
48 }
49
50 bool update(T value)
51 {
52 QWriteLocker locker(&m_lock);
53 if (value == m_cached)
54 return false;
55 auto temp = std::exchange(m_cached, std::move(value));
56 locker.unlock();
57 return true;
58 }
59
60 void reset()
61 {
62 QWriteLocker locker(&m_lock);
63 auto temp = std::exchange(m_cached, std::nullopt);
64 locker.unlock();
65 }
66
67private:
68 QReadWriteLock m_lock;
69 std::optional<T> m_cached;
70};
71
72template <typename Key, typename Value>
74{
75public:
76 QCachedValueMap() = default;
77
79
80 template <typename Creator>
82 {
83 {
85 auto it = m_map.find(key);
86 if (it != m_map.end())
87 return it->second;
88 }
89
90 {
93 return emplaceRes.first->second;
94 }
95 }
96
97private:
99 std::unordered_map<Key, Value> m_map;
100};
101
102QT_END_NAMESPACE
103
104#endif // QCACHEDVALUE_P_H
QCachedValueMap()=default
\inmodule QtGui
Definition qimage.h:37
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:782
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:440
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:322
\inmodule QtGui
Definition qshader.h:81
static QVideoFramePrivate * handle(QVideoFrame &frame)
static bool updateTextures(QRhi *rhi, std::unique_ptr< QRhiBuffer > &uniformBuffer, std::unique_ptr< QRhiSampler > &textureSampler, std::unique_ptr< QRhiShaderResourceBindings > &shaderResourceBindings, std::unique_ptr< QRhiGraphicsPipeline > &graphicsPipeline, std::unique_ptr< QRhiRenderPassDescriptor > &renderPass, QVideoFrame &frame, const QVideoFrameTexturesUPtr &videoFrameTextures)
static QImage convertJPEG(const QVideoFrame &frame, const VideoTransformation &transform)
QImage qImageFromVideoFrame(const QVideoFrame &frame, const VideoTransformation &transformation, bool forceCpu)
QImage qImageFromVideoFrame(const QVideoFrame &frame, bool forceCpu)
static QShader ensureShader(const QString &name)
static bool pixelFormatHasAlpha(QVideoFrameFormat::PixelFormat format)
static QImage convertCPU(const QVideoFrame &frame, const VideoTransformation &transform)
static void rasterTransform(QImage &image, VideoTransformation transformation)
QImage videoFramePlaneAsImage(QVideoFrame &frame, int plane, QImage::Format targetFormat, QSize targetSize)
Maps the video frame and returns an image having a shared ownership for the video frame and referenci...
static void imageCleanupHandler(void *info)