| 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 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | class QSGVideoTexturePrivate |
| 11 | { |
| 12 | Q_DECLARE_PUBLIC(QSGVideoTexture) |
| 13 | |
| 14 | private: |
| 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 | |
| 22 | QSGVideoTexture::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 | |
| 31 | QSGVideoTexture::~QSGVideoTexture() = default; |
| 32 | |
| 33 | qint64 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 | |
| 43 | QRhiTexture *QSGVideoTexture::rhiTexture() const |
| 44 | { |
| 45 | return d_func()->m_texture; |
| 46 | } |
| 47 | |
| 48 | QSize QSGVideoTexture::textureSize() const |
| 49 | { |
| 50 | return d_func()->m_size; |
| 51 | } |
| 52 | |
| 53 | bool QSGVideoTexture::hasAlphaChannel() const |
| 54 | { |
| 55 | Q_D(const QSGVideoTexture); |
| 56 | return d->m_format == QRhiTexture::RGBA8 || d->m_format == QRhiTexture::BGRA8; |
| 57 | } |
| 58 | |
| 59 | bool QSGVideoTexture::hasMipmaps() const |
| 60 | { |
| 61 | return mipmapFiltering() != QSGTexture::None; |
| 62 | } |
| 63 | |
| 64 | void 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 | |
| 72 | void QSGVideoTexture::setRhiTexture(QRhiTexture *texture) |
| 73 | { |
| 74 | d_func()->m_texture = texture; |
| 75 | } |
| 76 | |
| 77 | QT_END_NAMESPACE |
| 78 |
