1// Copyright (C) 2020 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#include "qsgvideotexture_p.h"
5#include <QtQuick/qsgtexturematerial.h>
6#include <QtQuick/qsgmaterial.h>
7
8QT_BEGIN_NAMESPACE
9
10class QSGVideoTexturePrivate
11{
12 Q_DECLARE_PUBLIC(QSGVideoTexture)
13
14private:
15 QSGVideoTexture *q_ptr = nullptr;
16 QRhiTexture::Format m_format;
17 QSize m_size;
18 QByteArray m_data;
19 QRhiTexture *m_texture = nullptr;
20};
21
22QSGVideoTexture::QSGVideoTexture()
23 : d_ptr(new QSGVideoTexturePrivate)
24{
25 d_ptr->q_ptr = this;
26
27 // Nearest filtering just looks bad for any text in videos
28 setFiltering(Linear);
29}
30
31QSGVideoTexture::~QSGVideoTexture() = default;
32
33qint64 QSGVideoTexture::comparisonKey() const
34{
35 Q_D(const QSGVideoTexture);
36 if (d->m_texture)
37 return qint64(qintptr(d->m_texture));
38
39 // two textures (and so materials) with not-yet-created texture underneath are never equal
40 return qint64(qintptr(this));
41}
42
43QRhiTexture *QSGVideoTexture::rhiTexture() const
44{
45 return d_func()->m_texture;
46}
47
48QSize QSGVideoTexture::textureSize() const
49{
50 return d_func()->m_size;
51}
52
53bool QSGVideoTexture::hasAlphaChannel() const
54{
55 Q_D(const QSGVideoTexture);
56 return d->m_format == QRhiTexture::RGBA8 || d->m_format == QRhiTexture::BGRA8;
57}
58
59bool QSGVideoTexture::hasMipmaps() const
60{
61 return mipmapFiltering() != QSGTexture::None;
62}
63
64void QSGVideoTexture::setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes)
65{
66 Q_D(QSGVideoTexture);
67 d->m_size = s;
68 d->m_format = f;
69 d->m_data = {reinterpret_cast<const char *>(data), bytes};
70}
71
72void QSGVideoTexture::setRhiTexture(QRhiTexture *texture)
73{
74 d_func()->m_texture = texture;
75}
76
77QT_END_NAMESPACE
78

source code of qtmultimedia/src/multimediaquick/qsgvideotexture.cpp