MythTV  master
mythpainter_vdpau.cpp
Go to the documentation of this file.
1 // Config header
2 #include "config.h"
3 
4 // QT headers
5 #include <QCoreApplication>
6 #include <QPainter>
7 #include <QMutex>
8 
9 // Mythdb headers
10 #include "mythlogging.h"
11 
12 // Mythui headers
13 #include "mythrender_vdpau.h"
14 
15 // Own header
16 #include "mythpainter_vdpau.h"
17 
18 #define LOC QString("VDPAU Painter: ")
19 
21  m_render(render)
22 {
23  if (m_render)
24  m_render->IncrRef();
25 }
26 
28 {
30 }
31 
32 bool MythVDPAUPainter::InitVDPAU(QPaintDevice *parent)
33 {
34  if (m_render)
35  return true;
36 
37  QWidget *real_parent = (QWidget*)parent;
38  if (!real_parent)
39  return false;
40 
41  m_render = new MythRenderVDPAU();
42  if (!m_render)
43  return false;
44 
45  if (m_render->Create(real_parent->size(), real_parent->winId()))
46  return true;
47 
48  Teardown();
49  return false;
50 }
51 
53 {
55 
57 
58  m_ImageBitmapMap.clear();
59  m_ImageExpireList.clear();
60  m_bitmapDeleteList.clear();
61 
62  if (m_render)
63  {
64  m_render->DecrRef();
65  m_render = nullptr;
66  }
67 }
68 
70 {
71  ClearCache();
72  DeleteBitmaps();
73 }
74 
75 void MythVDPAUPainter::Begin(QPaintDevice *parent)
76 {
77  if (!m_render)
78  {
79  if (!InitVDPAU(parent))
80  {
81  LOG(VB_GENERAL, LOG_ERR, "Failed to create VDPAU render.");
82  return;
83  }
84  }
85 
86  if (m_render->WasPreempted())
87  ClearCache();
88  DeleteBitmaps();
89 
90  if (m_target)
91  m_render->DrawBitmap(0, m_target, nullptr, nullptr);
92  else if (m_swap_control)
94 
95  MythPainter::Begin(parent);
96 }
97 
99 {
100  if (m_render && m_swap_control)
101  m_render->Flip();
103 }
104 
106 {
107  LOG(VB_GENERAL, LOG_INFO, LOC + "Clearing VDPAU painter cache.");
108 
109  QMutexLocker locker(&m_bitmapDeleteLock);
110  QMapIterator<MythImage *, uint32_t> it(m_ImageBitmapMap);
111  while (it.hasNext())
112  {
113  it.next();
114  m_bitmapDeleteList.push_back(m_ImageBitmapMap[it.key()]);
115  m_ImageExpireList.remove(it.key());
116  }
117  m_ImageBitmapMap.clear();
118 }
119 
121 {
122  QMutexLocker locker(&m_bitmapDeleteLock);
123  while (!m_bitmapDeleteList.empty())
124  {
125  uint bitmap = m_bitmapDeleteList.front();
126  m_bitmapDeleteList.pop_front();
129  }
130 }
131 
132 void MythVDPAUPainter::DrawImage(const QRect &r, MythImage *im,
133  const QRect &src, int alpha)
134 {
135  if (m_render)
137  &src, &r /*dst*/, kVDPBlendNormal,
138  alpha, 255, 255, 255);
139 }
140 
142 {
143  if (m_ImageBitmapMap.contains(im))
144  {
145  QMutexLocker locker(&m_bitmapDeleteLock);
146  m_bitmapDeleteList.push_back(m_ImageBitmapMap[im]);
147  m_ImageBitmapMap.remove(im);
148  m_ImageExpireList.remove(im);
149  }
150 }
151 
153 {
154  if (m_ImageBitmapMap.contains(im))
155  {
156  if (!im->IsChanged())
157  {
158  m_ImageExpireList.remove(im);
159  m_ImageExpireList.push_back(im);
160  return m_ImageBitmapMap[im];
161  }
163  }
164 
165  im->SetChanged(false);
166  uint newbitmap = 0;
167  if (m_render)
168  newbitmap = m_render->CreateBitmapSurface(im->size());
169 
170  if (newbitmap)
171  {
172  CheckFormatImage(im);
173  m_render->UploadMythImage(newbitmap, im);
174  m_ImageBitmapMap[im] = newbitmap;
175  m_ImageExpireList.push_back(im);
178  {
179  MythImage *expiredIm = m_ImageExpireList.front();
180  m_ImageExpireList.pop_front();
181  DeleteFormatImagePriv(expiredIm);
182  DeleteBitmaps();
183  }
184  }
185  else
186  {
187  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create VDPAU UI bitmap.");
188  }
189 
190  return newbitmap;
191 }
virtual void Teardown(void)
Definition: mythpainter.cpp:29
std::list< uint32_t > m_bitmapDeleteList
void DeleteFormatImagePriv(MythImage *im) override
bool InitVDPAU(QPaintDevice *parent)
bool Create(const QSize &size, WId window, uint colorkey=VDPAU_COLORKEY)
#define LOC
void DrawImage(const QRect &r, MythImage *im, const QRect &src, int alpha) override
void Begin(QPaintDevice *parent) override
virtual void SetChanged(bool change=true)
Definition: mythimage.h:45
bool DrawBitmap(uint id, uint target, const QRect *src, const QRect *dst, VDPBlendType blendi=kVDPBlendNormal, int alpha=0, int red=0, int green=0, int blue=0)
MythVDPAUPainter(MythRenderVDPAU *render=nullptr)
unsigned int uint
Definition: compat.h:140
void DestroyBitmapSurface(uint id)
uint CreateBitmapSurface(const QSize &size, VdpRGBAFormat fmt=VDP_RGBA_FORMAT_B8G8R8A8, uint existing=0)
uint GetTextureFromCache(MythImage *im)
unsigned char r
Definition: ParseText.cpp:329
int m_HardwareCacheSize
Definition: mythpainter.h:129
virtual void End()
Definition: mythpainter.h:51
virtual int IncrRef(void)
Increments reference count.
void Teardown(void) override
int GetBitmapSize(uint id)
std::list< MythImage * > m_ImageExpireList
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool UploadMythImage(uint id, MythImage *image)
void CheckFormatImage(MythImage *im)
void FreeResources(void) override
bool IsChanged() const
Definition: mythimage.h:46
MythRenderVDPAU * m_render
QMap< MythImage *, uint32_t > m_ImageBitmapMap
void End() override
virtual void Begin(QPaintDevice *parent)
Definition: mythpainter.h:50
int m_MaxHardwareCacheSize
Definition: mythpainter.h:130