22 #include <QQuickWidget>
23 #include <QOpenGLFunctions>
24 #include <QOpenGLShaderProgram>
25 #include <QOpenGLFramebufferObject>
26 #include <QOpenGLContext>
27 #include <QOffscreenSurface>
32 #include "mltcontroller.h"
33 #include "sharedframe.h"
35 class QOpenGLFunctions_3_2_Core;
46 typedef void* ( *thread_function_t )(
void* );
48 class GLWidget :
public QQuickWidget,
public Controller,
protected QOpenGLFunctions
51 Q_PROPERTY(QRectF rect READ rect NOTIFY rectChanged)
52 Q_PROPERTY(
int grid READ grid NOTIFY gridChanged)
53 Q_PROPERTY(
bool snapToGrid READ snapToGrid NOTIFY snapToGridChanged)
54 Q_PROPERTY(
float zoom READ zoom NOTIFY zoomChanged)
55 Q_PROPERTY(QPoint offset READ offset NOTIFY offsetChanged)
58 GLWidget(QObject *parent = 0);
61 void createThread(RenderThread** thread, thread_function_t
function,
void* data);
64 int setProducer(Mlt::Producer*,
bool isMulti =
false);
65 int reconfigure(
bool isMulti);
67 void play(
double speed = 1.0) {
68 Controller::play(speed);
69 if (speed == 0) emit paused();
72 void seek(
int position) {
73 Controller::seek(position);
76 void refreshConsumer(
bool scrubAudio =
false);
81 int displayWidth()
const {
return m_rect.width(); }
82 int displayHeight()
const {
return m_rect.height(); }
84 QObject* videoWidget() {
return this; }
85 Filter* glslManager()
const {
return m_glslManager; }
86 QRectF rect()
const {
return m_rect; }
87 int grid()
const {
return m_grid; }
88 float zoom()
const {
return m_zoom * MLT.profile().width() / m_rect.width(); }
89 QPoint offset()
const;
91 bool imageIsProxy()
const;
92 void requestImage()
const;
93 bool snapToGrid()
const {
return m_snapToGrid; }
94 int maxTextureSize()
const {
return m_maxTextureSize; }
98 void setGrid(
int grid);
99 void setZoom(
float zoom);
100 void setOffsetX(
int x);
101 void setOffsetY(
int y);
102 void setBlankScene();
103 void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
104 void setSnapToGrid(
bool snap);
110 void gpuNotSupported();
117 void offsetChanged();
119 void snapToGridChanged();
120 void toggleZoom(
bool);
126 QOpenGLShaderProgram* m_shader;
128 Filter* m_glslManager;
129 QSemaphore m_initSem;
130 bool m_isInitialized;
131 Event* m_threadStartEvent;
132 Event* m_threadStopEvent;
133 Event* m_threadCreateEvent;
134 Event* m_threadJoinEvent;
135 FrameRenderer* m_frameRenderer;
136 int m_projectionLocation;
137 int m_modelViewLocation;
138 int m_vertexLocation;
139 int m_texCoordLocation;
140 int m_colorspaceLocation;
141 int m_textureLocation[3];
144 QOffscreenSurface m_offscreenSurface;
145 QOpenGLContext* m_shareContext;
148 QUrl m_savedQmlSource;
150 QTimer m_refreshTimer;
152 GLint m_maxTextureSize;
154 static void on_frame_show(mlt_consumer, GLWidget* widget, mlt_event_data);
158 void resizeGL(
int width,
int height);
159 void updateTexture(GLuint yName, GLuint uName, GLuint vName);
161 void onRefreshTimeout();
164 void resizeEvent(QResizeEvent* event);
165 void mousePressEvent(QMouseEvent *);
166 void mouseMoveEvent(QMouseEvent *);
167 void keyPressEvent(QKeyEvent* event);
168 bool event(QEvent* event);
172 class RenderThread :
public QThread
176 RenderThread(thread_function_t
function,
void* data, QOpenGLContext *context, QSurface* surface);
182 thread_function_t m_function;
184 QOpenGLContext* m_context;
188 class FrameRenderer :
public QThread
192 FrameRenderer(QOpenGLContext* shareContext, QSurface* surface);
194 QSemaphore* semaphore() {
return &m_semaphore; }
195 QOpenGLContext* context()
const {
return m_context; }
197 Q_INVOKABLE
void showFrame(Mlt::Frame frame);
199 QImage image()
const {
return m_image; }
205 void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
210 QSemaphore m_semaphore;
212 QOpenGLContext* m_context;
214 qint64 m_previousMSecs;
215 bool m_imageRequested;
219 GLuint m_renderTexture[3];
220 GLuint m_displayTexture[3];
221 QOpenGLFunctions_3_2_Core* m_gl32;
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:49