MythTV  master
mythpainter.h
Go to the documentation of this file.
1 #ifndef MYTHPAINTER_H_
2 #define MYTHPAINTER_H_
3 
4 #include <QMap>
5 #include <QString>
6 #include <QTextLayout>
7 #include <QWidget>
8 #include <QPaintDevice>
9 #include <QMutex>
10 #include <QSet>
11 
12 class QRect;
13 class QRegion;
14 class QPoint;
15 class QColor;
16 
17 #include "mythuiexp.h"
18 
19 #include <list>
20 
21 #ifdef _MSC_VER
22 # include <cstdint> // int64_t
23 #endif
24 
25 class MythFontProperties;
26 class MythImage;
27 class UIEffects;
28 
29 using LayoutVector = QVector<QTextLayout *>;
30 using FormatVector = QVector<QTextLayout::FormatRange>;
31 
32 class MUI_PUBLIC MythPainter : public QObject
33 {
34  Q_OBJECT
35 
36  public:
37  MythPainter();
45  ~MythPainter() override = default;
46 
47  virtual QString GetName(void) = 0;
48  virtual bool SupportsAnimation(void) = 0;
49  virtual bool SupportsAlpha(void) = 0;
50  virtual bool SupportsClipping(void) = 0;
51  virtual void FreeResources(void) { }
52  virtual void Begin(QPaintDevice* /*Parent*/) { }
53  virtual void End() { }
54 
55  virtual void SetClipRect(const QRect &clipRect);
56  virtual void SetClipRegion(const QRegion &clipRegion);
57  virtual void Clear(QPaintDevice *device, const QRegion &region);
58 
59  virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
60  int alpha) = 0;
61 
62  void DrawImage(int x, int y, MythImage *im, int alpha);
63  void DrawImage(const QPoint &topLeft, MythImage *im, int alph);
64 
65  virtual void DrawText(const QRect &r, const QString &msg, int flags,
66  const MythFontProperties &font, int alpha,
67  const QRect &boundRect);
68  virtual void DrawTextLayout(const QRect &canvasRect,
69  const LayoutVector & layouts,
70  const FormatVector & formats,
71  const MythFontProperties &font, int alpha,
72  const QRect &destRect);
73  virtual void DrawRect(const QRect &area, const QBrush &fillBrush,
74  const QPen &linePen, int alpha);
75  virtual void DrawRoundRect(const QRect &area, int cornerRadius,
76  const QBrush &fillBrush, const QPen &linePen,
77  int alpha);
78  virtual void DrawEllipse(const QRect &area, const QBrush &fillBrush,
79  const QPen &linePen, int alpha);
80 
81  virtual void PushTransformation(const UIEffects &zoom, QPointF center = QPointF());
82  virtual void PopTransformation(void) { }
83 
87  MythImage *GetFormatImage();
88  void DeleteFormatImage(MythImage *im);
89 
90  void SetDebugMode(bool showBorders, bool showNames)
91  {
92  m_showBorders = showBorders;
93  m_showNames = showNames;
94  }
95 
96  bool ShowBorders(void) const { return m_showBorders; }
97  bool ShowTypeNames(void) const { return m_showNames; }
98 
99  void SetMaximumCacheSizes(int hardware, int software);
100 
101  protected:
102  static void DrawTextPriv(MythImage *im, const QString &msg, int flags,
103  const QRect &r, const MythFontProperties &font);
104  static void DrawRectPriv(MythImage *im, const QRect &area, int radius, int ellipse,
105  const QBrush &fillBrush, const QPen &linePen);
106 
107  MythImage *GetImageFromString(const QString &msg, int flags, const QRect &r,
108  const MythFontProperties &font);
109  MythImage *GetImageFromTextLayout(const LayoutVector & layouts,
110  const FormatVector & formats,
111  const MythFontProperties &font,
112  QRect &canvas, QRect &dest);
113  MythImage *GetImageFromRect(const QRect &area, int radius, int ellipse,
114  const QBrush &fillBrush,
115  const QPen &linePen);
116 
118  virtual MythImage* GetFormatImagePriv(void) = 0;
119  virtual void DeleteFormatImagePriv(MythImage *im) = 0;
120  void ExpireImages(int64_t max = 0);
121 
122  // This needs to be called by classes inheriting from MythPainter
123  // in the destructor.
124  virtual void Teardown(void);
125 
126  void CheckFormatImage(MythImage *im);
127 
128  int m_hardwareCacheSize { 0 };
129  int m_maxHardwareCacheSize { 0 };
130 
131  private:
132  int64_t m_softwareCacheSize {0};
133  int64_t m_maxSoftwareCacheSize {1024 * 1024 * 48};
134 
136  QSet<MythImage*> m_allocatedImages;
137 
138  QMap<QString, MythImage *> m_stringToImageMap;
139  std::list<QString> m_stringExpireList;
140 
141  bool m_showBorders {false};
142  bool m_showNames {false};
143 };
144 
145 #endif
MythPainter::m_allocatedImages
QSet< MythImage * > m_allocatedImages
Definition: mythpainter.h:136
FormatVector
QVector< QTextLayout::FormatRange > FormatVector
Definition: mythpainter.h:30
build_compdb.dest
dest
Definition: build_compdb.py:9
MythPainter::SupportsAlpha
virtual bool SupportsAlpha(void)=0
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythPainter::m_allocationLock
QMutex m_allocationLock
Definition: mythpainter.h:135
MythPainter::SupportsAnimation
virtual bool SupportsAnimation(void)=0
MythPainter::SupportsClipping
virtual bool SupportsClipping(void)=0
MythPainter::m_stringExpireList
std::list< QString > m_stringExpireList
Definition: mythpainter.h:139
MythPainter::m_stringToImageMap
QMap< QString, MythImage * > m_stringToImageMap
Definition: mythpainter.h:138
MythPainter::DeleteFormatImagePriv
virtual void DeleteFormatImagePriv(MythImage *im)=0
MythPainter::GetFormatImagePriv
virtual MythImage * GetFormatImagePriv(void)=0
Creates a reference counted image, call DecrRef() to delete.
MythFontProperties
Definition: mythfontproperties.h:14
formats
const std::array< const std::string, 8 > formats
Definition: vbilut.cpp:189
MythPainter::DrawImage
virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src, int alpha)=0
MythPainter::FreeResources
virtual void FreeResources(void)
Definition: mythpainter.h:51
MythPainter::End
virtual void End()
Definition: mythpainter.h:53
MythPainter::ShowBorders
bool ShowBorders(void) const
Definition: mythpainter.h:96
MythPainter::~MythPainter
~MythPainter() override=default
MythPainter destructor.
MythPainter::GetName
virtual QString GetName(void)=0
MythPainter::ShowTypeNames
bool ShowTypeNames(void) const
Definition: mythpainter.h:97
MythPainter::SetDebugMode
void SetDebugMode(bool showBorders, bool showNames)
Definition: mythpainter.h:90
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:49
LayoutVector
QVector< QTextLayout * > LayoutVector
Definition: mythpainter.h:29
MythPainter
Definition: mythpainter.h:33
MythImage
Definition: mythimage.h:37
UIEffects
Definition: mythuianimation.h:10
MythPainter::PopTransformation
virtual void PopTransformation(void)
Definition: mythpainter.h:82
MythPainter::Begin
virtual void Begin(QPaintDevice *)
Definition: mythpainter.h:52
mythuiexp.h