forked from carlonluca/pot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omx_texture.h
164 lines (138 loc) · 4.21 KB
/
omx_texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Project: PiOmxTextures
* Author: Luca Carlon
* Date: 11.01.2012
*
* Copyright (c) 2012, 2013 Luca Carlon. All rights reserved.
*
* This file is part of PiOmxTextures.
*
* PiOmxTextures is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PiOmxTextures is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PiOmxTextures. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OMX_TEXTURE_H
#define OMX_TEXTURE_H
/*------------------------------------------------------------------------------
| OMX_VideoProcessorTexture class
+-----------------------------------------------------------------------------*/
#include <QSize>
#include <QSGTexture>
#include <QSGTextureProvider>
#include <QMutex>
#include <QMutexLocker>
#define EGL_EGLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "lc_logging.h"
/*------------------------------------------------------------------------------
| OMX_Texture class
+-----------------------------------------------------------------------------*/
class OMX_Texture
{
public:
OMX_Texture(EGLDisplay eglDisplay) :
m_textureId(0), m_eglImage(0), m_eglDisplay(eglDisplay) {
// Do nothing.
}
OMX_Texture(const OMX_Texture& texture) :
m_textureId(texture.textureId()),
m_textureSize(texture.textureSize()),
m_eglImage(texture.eglImage()),
m_eglDisplay(texture.eglDisplay()) {
// Do nothing.
}
~OMX_Texture() {
resetTexture();
}
inline void setTexture(EGLImageKHR eglImage, uint textureId, QSize textureSize) {
resetTexture();
m_eglImage = eglImage;
m_textureId = textureId;
m_textureSize = textureSize;
}
inline void resetTexture() {
if (m_textureId) {
assert(m_eglImage);
assert(m_eglDisplay);
glDeleteTextures(1, &m_textureId);
eglDestroyImageKHR(m_eglDisplay, m_eglImage);
}
m_textureId = 0;
m_textureSize = QSize();
}
inline int textureId() const {
return m_textureId;
}
inline QSize textureSize() const {
return m_textureSize;
}
inline EGLImageKHR eglImage() const {
return m_eglImage;
}
inline EGLDisplay eglDisplay() const {
return m_eglDisplay;
}
OMX_Texture& operator =(const OMX_Texture&) {
return *this;
}
protected:
uint m_textureId;
QSize m_textureSize;
EGLImageKHR m_eglImage;
EGLDisplay m_eglDisplay;
};
/*------------------------------------------------------------------------------
| OMX_SGTexture class
+-----------------------------------------------------------------------------*/
/**
* @brief The OMX_SGTexture class Convenience class to be used in QQuickItem
* subclass for Scene Graph.
*/
class OMX_SGTexture : public QSGTexture, public QSGTextureProvider
{
public:
OMX_SGTexture(GLuint textureId, QSize textureSize) :
QSGTexture()
{
this->m_textureId = textureId;
this->m_textureSize = textureSize;
}
inline void bind() {
glBindTexture(GL_TEXTURE_2D, m_textureId);
}
inline void setTexture(GLuint textureId, QSize textureSize) {
LOG_VERBOSE(LOG_TAG, "Setting tex: %u.", textureId);
this->m_textureId = textureId;
this->m_textureSize = textureSize;
}
int textureId() const {
int tex = (int)m_textureId;
return tex;
}
inline QSize textureSize() const {
return m_textureSize;
}
inline bool hasAlphaChannel() const {
return false;
}
inline bool hasMipmaps() const {
return false;
}
inline QSGTexture* texture() const {
return (QSGTexture*)this;
}
private:
GLuint m_textureId;
QSize m_textureSize;
};
#endif // OMX_TEXTURE_H