forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglwidget.h
More file actions
265 lines (238 loc) · 6.29 KB
/
glwidget.h
File metadata and controls
265 lines (238 loc) · 6.29 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* Copyright (c) 2011-2020 Meltytech, LLC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QSemaphore>
#include <QQuickWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLFramebufferObject>
#include <QOpenGLContext>
#include <QOffscreenSurface>
#include <QMutex>
#include <QThread>
#include <QRectF>
#include <QTimer>
#include "mltcontroller.h"
#include "sharedframe.h"
class QOpenGLFunctions_3_2_Core;
class QOpenGLTexture;
class QmlFilter;
class QmlMetadata;
namespace Mlt {
class Filter;
class RenderThread;
class FrameRenderer;
typedef void *( *thread_function_t )( void * );
class GLWidget : public QQuickWidget, public Controller, protected QOpenGLFunctions
{
Q_OBJECT
Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
Q_PROPERTY(int grid READ grid NOTIFY gridChanged)
Q_PROPERTY(bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
Q_PROPERTY(float zoom READ zoom NOTIFY zoomChanged)
Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
public:
GLWidget(QObject *parent = 0);
~GLWidget();
void createThread(RenderThread **thread, thread_function_t function, void *data);
void startGlsl();
void stopGlsl();
int setProducer(Mlt::Producer *, bool isMulti = false);
int reconfigure(bool isMulti);
void play(double speed = 1.0)
{
Controller::play(speed);
if (speed == 0) emit paused();
else emit playing();
}
void seek(int position)
{
Controller::seek(position);
emit paused();
}
void refreshConsumer(bool scrubAudio = false);
void pause()
{
Controller::pause();
emit paused();
}
int displayWidth() const
{
return m_rect.width();
}
int displayHeight() const
{
return m_rect.height();
}
QObject *videoWidget()
{
return this;
}
Filter *glslManager() const
{
return m_glslManager;
}
QRectF rect() const
{
return m_rect;
}
int grid() const
{
return m_grid;
}
float zoom() const
{
return m_zoom * MLT.profile().width() / m_rect.width();
}
QPoint offset() const;
QImage image() const;
bool imageIsProxy() const;
void requestImage() const;
bool snapToGrid() const
{
return m_snapToGrid;
}
int maxTextureSize() const
{
return m_maxTextureSize;
}
public slots:
void onFrameDisplayed(const SharedFrame &frame);
void setGrid(int grid);
void setZoom(float zoom);
void setOffsetX(int x);
void setOffsetY(int y);
void setBlankScene();
void setCurrentFilter(QmlFilter *filter, QmlMetadata *meta);
void setSnapToGrid(bool snap);
signals:
void frameDisplayed(const SharedFrame &frame);
void dragStarted();
void seekTo(int x);
void gpuNotSupported();
void started();
void paused();
void playing();
void rectChanged();
void gridChanged();
void zoomChanged();
void offsetChanged();
void imageReady();
void snapToGridChanged();
void toggleZoom(bool);
private:
QRectF m_rect;
int m_grid;
GLuint m_texture[3];
QOpenGLShaderProgram *m_shader;
QPoint m_dragStart;
Filter *m_glslManager;
QSemaphore m_initSem;
bool m_isInitialized;
Event *m_threadStartEvent;
Event *m_threadStopEvent;
Event *m_threadCreateEvent;
Event *m_threadJoinEvent;
FrameRenderer *m_frameRenderer;
int m_projectionLocation;
int m_modelViewLocation;
int m_vertexLocation;
int m_texCoordLocation;
int m_colorspaceLocation;
int m_textureLocation[3];
float m_zoom;
QPoint m_offset;
QOffscreenSurface m_offscreenSurface;
QOpenGLContext *m_shareContext;
SharedFrame m_sharedFrame;
QMutex m_mutex;
QUrl m_savedQmlSource;
bool m_snapToGrid;
QTimer m_refreshTimer;
bool m_scrubAudio;
GLint m_maxTextureSize;
static void on_frame_show(mlt_consumer, GLWidget *widget, mlt_event_data);
private slots:
void initializeGL();
void resizeGL(int width, int height);
void updateTexture(GLuint yName, GLuint uName, GLuint vName);
void paintGL();
void onRefreshTimeout();
protected:
void resizeEvent(QResizeEvent *event);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *event);
bool event(QEvent *event);
void createShader();
};
class RenderThread : public QThread
{
Q_OBJECT
public:
RenderThread(thread_function_t function, void *data, QOpenGLContext *context, QSurface *surface);
protected:
void run();
private:
thread_function_t m_function;
void *m_data;
QOpenGLContext *m_context;
QSurface *m_surface;
};
class FrameRenderer : public QThread
{
Q_OBJECT
public:
FrameRenderer(QOpenGLContext *shareContext, QSurface *surface);
~FrameRenderer();
QSemaphore *semaphore()
{
return &m_semaphore;
}
QOpenGLContext *context() const
{
return m_context;
}
SharedFrame getDisplayFrame();
Q_INVOKABLE void showFrame(Mlt::Frame frame);
void requestImage();
QImage image() const
{
return m_image;
}
public slots:
void cleanup();
signals:
void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
void frameDisplayed(const SharedFrame &frame);
void imageReady();
private:
QSemaphore m_semaphore;
SharedFrame m_displayFrame;
QOpenGLContext *m_context;
QSurface *m_surface;
qint64 m_previousMSecs;
bool m_imageRequested;
QImage m_image;
public:
GLuint m_renderTexture[3];
GLuint m_displayTexture[3];
QOpenGLFunctions_3_2_Core *m_gl32;
};
} // namespace
#endif