File indexing completed on 2024-06-16 04:38:29
0001 /* 0002 SPDX-FileCopyrightText: 2003 Fabrice Bellard 0003 SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef GLRENDERER_H 0009 #define GLRENDERER_H 0010 0011 #include <QOpenGLWidget> 0012 #include <QOpenGLFunctions> 0013 #include <QOpenGLVertexArrayObject> 0014 #include <QMatrix4x4> 0015 #include <QMutex> 0016 0017 extern "C" { 0018 #include <libavutil/frame.h> 0019 } 0020 0021 QT_FORWARD_DECLARE_CLASS(QOpenGLShader) 0022 QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram) 0023 0024 struct AVPixFmtDescriptor; 0025 struct SwsContext; 0026 0027 namespace SubtitleComposer { 0028 class SubtitleTextOverlay; 0029 0030 class GLRenderer : public QOpenGLWidget, private QOpenGLFunctions 0031 { 0032 Q_OBJECT 0033 0034 friend class FFPlayer; 0035 0036 explicit GLRenderer(QWidget *parent = nullptr); 0037 0038 public: 0039 ~GLRenderer(); 0040 0041 static void setupProfile(); 0042 void reset(); 0043 0044 void setFrameFormat(int width, int height, int compBits, int crWidthShift, int crHeightShift); 0045 void setColorspace(const AVFrame *frame); 0046 int uploadTexture(AVFrame *frame); 0047 void setFrameY(quint8 *buf, quint32 pitch); 0048 void setFrameU(quint8 *buf, quint32 pitch); 0049 void setFrameV(quint8 *buf, quint32 pitch); 0050 void setOverlay(SubtitleTextOverlay *overlay); 0051 0052 inline QMutex * mutex() { return &m_texMutex; } 0053 0054 signals: 0055 void resolutionChanged(); 0056 0057 protected: 0058 void initializeGL() override; 0059 void initShader(); 0060 void resizeGL(int width, int height) override; 0061 void paintGL() override; 0062 0063 private: 0064 template<class T, int D> void uploadMM(int texWidth, int texHeight, T *texBuf, const T *texSrc); 0065 void uploadYUV(); 0066 void uploadSubtitle(); 0067 bool validTextureFormat(const AVPixFmtDescriptor *fd); 0068 0069 private: 0070 SubtitleTextOverlay *m_overlay; 0071 GLfloat m_overlayPos[8] = {0}; 0072 quint8 *m_mmOvr; 0073 0074 QOpenGLVertexArrayObject m_vao; 0075 0076 SwsContext *m_frameConvCtx; 0077 quint8 *m_bufYUV, *m_mmYUV; 0078 quint32 m_bufSize; 0079 GLsizei m_bufWidth, m_bufHeight; 0080 GLsizei m_crWidth, m_crHeight; 0081 quint8 *m_pixels[3]; 0082 quint32 m_pitch[3]; 0083 QMutex m_texMutex; 0084 0085 bool m_csNeedInit; 0086 QString m_ctfOut, m_ctfIn; 0087 QMatrix4x4 m_csCM; 0088 0089 QOpenGLShader *m_vertShader; 0090 QOpenGLShader *m_fragShader; 0091 QOpenGLShaderProgram *m_shaderProg; 0092 0093 bool m_texNeedInit; 0094 bool m_texUploaded; 0095 int m_lastFormat; 0096 int m_vpWidth, m_vpHeight; 0097 int m_texY, m_texU, m_texV, m_texOvr; 0098 GLuint *m_idTex; 0099 GLuint *m_vaBuf; 0100 0101 GLenum m_glType, m_glFormat; 0102 }; 0103 } 0104 0105 #endif // GLRENDERER_H