MythTV  master
mythpainteropengl.h
Go to the documentation of this file.
1 #ifndef MYTHPAINTER_OPENGL_H_
2 #define MYTHPAINTER_OPENGL_H_
3 
4 // Std
5 #include <array>
6 #include <list>
7 
8 // Qt
9 #include <QMutex>
10 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
11 #include <QRecursiveMutex>
12 #endif
13 #include <QQueue>
14 
15 // MythTV
16 #include "libmythui/mythimage.h"
18 
19 class MythMainWindow;
20 class MythGLTexture;
21 class MythRenderOpenGL;
22 class QOpenGLBuffer;
23 class QOpenGLFramebufferObject;
24 class QOpenGLShaderProgram;
25 
26 static constexpr size_t MAX_BUFFER_POOL { 70 };
27 
29 {
30  Q_OBJECT
31 
32  public:
34  ~MythOpenGLPainter() override;
35 
36  void DeleteTextures(void);
37 
38  QString GetName(void) override { return {"OpenGL"}; }
39  bool SupportsAnimation(void) override { return true; }
40  bool SupportsAlpha(void) override { return true; }
41  bool SupportsClipping(void) override { return false; }
42  void FreeResources(void) override;
43  void Begin(QPaintDevice *Parent) override;
44  void End() override;
45  void DrawImage(QRect Dest, MythImage *Image, QRect Source, int Alpha) override;
46  void DrawProcedural(QRect Dest, int Alpha, const ProcSource& VertexSource, const ProcSource& FragmentSource, const QString& SourceHash) override;
47 
48  void DrawRect(QRect Area, const QBrush &FillBrush,
49  const QPen &LinePen, int Alpha) override;
50  void DrawRoundRect(QRect Area, int CornerRadius,
51  const QBrush &FillBrush, const QPen &LinePen, int Alpha) override;
52  void PushTransformation(const UIEffects &Fx, QPointF Center = QPointF()) override;
53  void PopTransformation(void) override;
54 
55  protected:
56  void ClearCache(void);
57  MythGLTexture* GetTextureFromCache(MythImage *Image);
58  QOpenGLShaderProgram* GetProceduralShader(const ProcSource& VertexSource, const ProcSource& FragmentSource, const QString& SourceHash);
59 
60  MythImage* GetFormatImagePriv(void) override { return new MythImage(this); }
61  void DeleteFormatImagePriv(MythImage *Image) override;
62 
63  protected:
64  MythRenderOpenGL *m_render { nullptr };
65 
66 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
67  QMutex m_imageAndTextureLock { QMutex::Recursive };
68 #else
69  QRecursiveMutex m_imageAndTextureLock;
70 #endif
71  QMap<MythImage *, MythGLTexture*> m_imageToTextureMap;
72  std::list<MythImage *> m_imageExpireList;
73  std::list<MythGLTexture*> m_textureDeleteList;
74 
75  QVector<MythGLTexture*> m_mappedTextures;
76  std::array<QOpenGLBuffer*,MAX_BUFFER_POOL> m_mappedBufferPool { nullptr };
77  size_t m_mappedBufferPoolIdx { 0 };
78  bool m_mappedBufferPoolReady { false };
79 
80  QHash<QString,QOpenGLShaderProgram*> m_procedurals;
81 };
82 
83 #endif
MythOpenGLPainter
Definition: mythpainteropengl.h:28
MythOpenGLPainter::m_imageExpireList
std::list< MythImage * > m_imageExpireList
Definition: mythpainteropengl.h:72
MythOpenGLPainter::SupportsAlpha
bool SupportsAlpha(void) override
Definition: mythpainteropengl.h:40
MythGLTexture
Definition: mythrenderopengl.h:60
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythPainter::DrawProcedural
virtual void DrawProcedural(QRect, int, const ProcSource &, const ProcSource &, const QString &)
Definition: mythpainter.h:65
mythpaintergpu.h
MythOpenGLPainter::GetFormatImagePriv
MythImage * GetFormatImagePriv(void) override
Creates a reference counted image, call DecrRef() to delete.
Definition: mythpainteropengl.h:60
MythOpenGLPainter::m_imageAndTextureLock
QRecursiveMutex m_imageAndTextureLock
Definition: mythpainteropengl.h:69
MAX_BUFFER_POOL
static constexpr size_t MAX_BUFFER_POOL
Definition: mythpainteropengl.h:26
MythPainter::DrawRect
virtual void DrawRect(QRect area, const QBrush &fillBrush, const QPen &linePen, int alpha)
Definition: mythpainter.cpp:157
MythOpenGLPainter::SupportsAnimation
bool SupportsAnimation(void) override
Definition: mythpainteropengl.h:39
Image
Definition: image.h:33
MythPainter::PushTransformation
virtual void PushTransformation(const UIEffects &zoom, QPointF center=QPointF())
Definition: mythpainter.cpp:191
MythPainter::DeleteFormatImagePriv
virtual void DeleteFormatImagePriv(MythImage *im)=0
Source
Definition: channelsettings.cpp:93
MythOpenGLPainter::SupportsClipping
bool SupportsClipping(void) override
Definition: mythpainteropengl.h:41
MythPainter::DrawImage
virtual void DrawImage(QRect dest, MythImage *im, QRect src, int alpha)=0
MythPainter::FreeResources
virtual void FreeResources(void)
Definition: mythpainter.h:53
MythOpenGLPainter::m_procedurals
QHash< QString, QOpenGLShaderProgram * > m_procedurals
Definition: mythpainteropengl.h:80
MythPainter::End
virtual void End()
Definition: mythpainter.h:55
MythRenderOpenGL
Definition: mythrenderopengl.h:100
mythimage.h
ProcSource
std::shared_ptr< QByteArray > ProcSource
Definition: mythpainter.h:32
MythOpenGLPainter::GetName
QString GetName(void) override
Definition: mythpainteropengl.h:38
MythOpenGLPainter::m_mappedTextures
QVector< MythGLTexture * > m_mappedTextures
Definition: mythpainteropengl.h:75
MythImage
Definition: mythimage.h:36
UIEffects
Definition: mythuianimation.h:13
MythPainter::PopTransformation
virtual void PopTransformation(void)
Definition: mythpainter.h:87
MythPainter::Begin
virtual void Begin(QPaintDevice *)
Definition: mythpainter.h:54
MythPainter::DrawRoundRect
virtual void DrawRoundRect(QRect area, int cornerRadius, const QBrush &fillBrush, const QPen &linePen, int alpha)
Definition: mythpainter.cpp:168
MythMainWindow
Definition: mythmainwindow.h:28
MythOpenGLPainter::m_imageToTextureMap
QMap< MythImage *, MythGLTexture * > m_imageToTextureMap
Definition: mythpainteropengl.h:71
MythOpenGLPainter::m_textureDeleteList
std::list< MythGLTexture * > m_textureDeleteList
Definition: mythpainteropengl.h:73
MythPainterGPU
Definition: mythpaintergpu.h:11