1// Copyright (C) 2019 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 QSGPLAINTEXTURE_P_H
5#define QSGPLAINTEXTURE_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 <QtQuick/private/qtquickglobal_p.h>
19#include <QtQuick/private/qsgtexture_p.h>
20#include <QtQuick/private/qquickwindow_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QSGPlainTexturePrivate;
25
26class Q_QUICK_PRIVATE_EXPORT QSGPlainTexture : public QSGTexture
27{
28 Q_OBJECT
29 Q_DECLARE_PRIVATE(QSGPlainTexture)
30public:
31 QSGPlainTexture();
32 ~QSGPlainTexture() override;
33
34 void setOwnsTexture(bool owns) { m_owns_texture = owns; }
35 bool ownsTexture() const { return m_owns_texture; }
36
37 void setTextureSize(const QSize &size) { m_texture_size = size; }
38 QSize textureSize() const override { return m_texture_size; }
39
40 void setHasAlphaChannel(bool alpha) { m_has_alpha = alpha; }
41 bool hasAlphaChannel() const override { return m_has_alpha; }
42
43 bool hasMipmaps() const override { return mipmapFiltering() != QSGTexture::None; }
44
45 void setImage(const QImage &image);
46 const QImage &image() { return m_image; }
47
48 qint64 comparisonKey() const override;
49
50 QRhiTexture *rhiTexture() const override;
51 void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
52
53 void setTexture(QRhiTexture *texture);
54 void setTextureFromNativeTexture(QRhi *rhi,
55 quint64 nativeObjectHandle,
56 int nativeLayoutOrState,
57 uint nativeFormat,
58 const QSize &size,
59 QQuickWindow::CreateTextureOptions options,
60 QQuickWindowPrivate::TextureFromNativeTextureFlags flags);
61
62 static QSGPlainTexture *fromImage(const QImage &image) {
63 QSGPlainTexture *t = new QSGPlainTexture();
64 t->setImage(image);
65 return t;
66 }
67
68protected:
69 QSGPlainTexture(QSGPlainTexturePrivate &dd);
70
71 QImage m_image;
72
73 QSize m_texture_size;
74 QRectF m_texture_rect;
75 QRhiTexture *m_texture;
76
77 uint m_has_alpha : 1;
78 uint m_dirty_texture : 1;
79 uint m_dirty_bind_options : 1; // legacy (GL-only)
80 uint m_owns_texture : 1;
81 uint m_mipmaps_generated : 1;
82 uint m_retain_image : 1;
83 uint m_mipmap_warned : 1; // RHI only
84};
85
86class QSGPlainTexturePrivate : public QSGTexturePrivate
87{
88 Q_DECLARE_PUBLIC(QSGPlainTexture)
89public:
90 QSGPlainTexturePrivate(QSGTexture *t) : QSGTexturePrivate(t) { }
91 QSGTexture::Filtering m_last_mipmap_filter = QSGTexture::None;
92};
93
94QT_END_NAMESPACE
95
96#endif // QSGPLAINTEXTURE_P_H
97

source code of qtdeclarative/src/quick/scenegraph/util/qsgplaintexture_p.h