MythTV  master
videovisualgoom.cpp
Go to the documentation of this file.
1 #include "mythlogging.h"
2 
3 #include "mythmainwindow.h"
4 
5 #ifdef USING_OPENGL
6 #include "mythrender_opengl.h"
7 #endif
8 
9 #ifdef USING_VDPAU
10 #include "mythrender_vdpau.h"
11 #endif
12 
13 extern "C" {
14 #include "goom/goom_tools.h"
15 #include "goom/goom_core.h"
16 }
17 
18 #include "videovisualgoom.h"
19 
21  : VideoVisual(audio, render), m_hd(hd)
22 {
23  int max_width = m_hd ? 1200 : 600;
24  int max_height = m_hd ? 800 : 400;
26  QSize sz = mw ? mw->GetUIScreenRect().size() : QSize(600, 400);
27  int width = (sz.width() > max_width) ? max_width : sz.width();
28  int height = (sz.height() > max_height) ? max_height : sz.height();
29  m_area = QRect(0, 0, width, height);
30  goom_init(width, height, 0);
31  LOG(VB_GENERAL, LOG_INFO, QString("Initialised Goom (%1x%2)")
32  .arg(width).arg(height));
33 }
34 
36 {
37 #ifdef USING_OPENGL
38  if (m_surface && m_render &&
39  (m_render->Type() == kRenderOpenGL1 ||
42  {
43  MythRenderOpenGL *glrender =
44  static_cast<MythRenderOpenGL*>(m_render);
45  if (glrender)
46  glrender->DeleteTexture(m_surface);
47  m_surface = 0;
48  }
49 #endif
50 
51 #ifdef USING_VDPAU
52  if (m_surface && m_render &&
53  (m_render->Type() == kRenderVDPAU))
54  {
55  MythRenderVDPAU *render =
56  static_cast<MythRenderVDPAU*>(m_render);
57  if (render)
59  m_surface = 0;
60  }
61 #endif
62 
63  goom_close();
64 }
65 
66 void VideoVisualGoom::Draw(const QRect &area, MythPainter */*painter*/,
67  QPaintDevice */*device*/)
68 {
69  if (m_disabled || !m_render || area.isEmpty())
70  return;
71 
72  QMutexLocker lock(mutex());
73  unsigned int* last = m_buffer;
74  VisualNode *node = GetNode();
75  if (node)
76  {
77  int numSamps = 512;
78  if (node->m_length < 512)
79  numSamps = node->m_length;
80 
81  signed short int data[2][512];
82  int i= 0;
83  for (; i < numSamps; i++)
84  {
85  data[0][i] = node->m_left[i];
86  data[1][i] = node->m_right ? node->m_right[i] : data[0][i];
87  }
88 
89  for (; i < 512; i++)
90  {
91  data[0][i] = 0;
92  data[1][i] = 0;
93  }
94 
95  m_buffer = goom_update(data, 0);
96  }
97 
98 #ifdef USING_OPENGL
99  if ((m_render->Type() == kRenderOpenGL1) ||
100  (m_render->Type() == kRenderOpenGL2) ||
102  {
103  MythRenderOpenGL *glrender =
104  static_cast<MythRenderOpenGL*>(m_render);
105  if (!m_surface && glrender && m_buffer)
106  {
107  m_surface = glrender->CreateTexture(m_area.size(),
108  (glrender->GetFeatures() & kGLExtPBufObj) != 0U, 0,
109  GL_UNSIGNED_BYTE, GL_RGBA, GL_RGBA8,
110  GL_LINEAR_MIPMAP_LINEAR);
111  }
112 
113  if (m_surface && glrender && m_buffer)
114  {
115  if (m_buffer != last)
116  {
117  bool copy = (glrender->GetFeatures() & kGLExtPBufObj) != 0U;
118  void* buf = glrender->GetTextureBuffer(m_surface, copy);
119  if (copy)
120  memcpy(buf, m_buffer, m_area.width() * m_area.height() * 4);
121  glrender->UpdateTexture(m_surface, (void*)m_buffer);
122  }
123  QRectF src(m_area);
124  QRectF dst(area);
125  glrender->DrawBitmap(&m_surface, 1, 0, &src, &dst, 0);
126  }
127  return;
128  }
129 #endif
130 
131 #ifdef USING_VDPAU
132  if (m_render->Type() == kRenderVDPAU)
133  {
134  MythRenderVDPAU *render =
135  static_cast<MythRenderVDPAU*>(m_render);
136 
137  if (!m_surface && render)
138  m_surface = render->CreateBitmapSurface(m_area.size());
139 
140  if (m_surface && render && m_buffer)
141  {
142  if (m_buffer != last)
143  {
144  void *plane[1] = { m_buffer };
145  uint32_t pitch[1] = { static_cast<uint32_t>(m_area.width() * 4) };
146  render->UploadBitmap(m_surface, plane, pitch);
147  }
148  render->DrawBitmap(m_surface, 0, nullptr, nullptr, kVDPBlendNull, 255, 255, 255, 255);
149  }
150  return;
151  }
152 #endif
153 }
154 
156 {
157  public:
158  const QString &name(void) const override // VideoVisualFactory
159  {
160  static QString name("Goom");
161  return name;
162  }
163 
165  MythRender *render) const override // VideoVisualFactory
166  {
167  return new VideoVisualGoom(audio, render, false);
168  }
169 
170  bool SupportedRenderer(RenderType type) override // VideoVisualFactory
171  {
172  return (type == kRenderVDPAU ||
173  type == kRenderOpenGL1 ||
174  type == kRenderOpenGL2 ||
176  }
178 
180 {
181  public:
182  const QString &name(void) const override // VideoVisualFactory
183  {
184  static QString name("Goom HD");
185  return name;
186  }
187 
189  MythRender *render) const override // VideoVisualFactory
190  {
191  return new VideoVisualGoom(audio, render, true);
192  }
193 
194  bool SupportedRenderer(RenderType type) override // VideoVisualFactory
195  {
196  return (type == kRenderVDPAU ||
197  type == kRenderOpenGL1 ||
198  type == kRenderOpenGL2 ||
200  }
void Draw(const QRect &area, MythPainter *painter, QPaintDevice *device) override
bool SupportedRenderer(RenderType type) override
bool SupportedRenderer(RenderType type) override
struct exc__state * last
Definition: pxsup2dast.c:98
VisualNode * GetNode(void)
Definition: videovisual.cpp:90
void goom_init(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.c:73
void DeleteTexture(uint tex)
VideoVisualGoomHDFactory VideoVisualGoomHDFactory
RenderType Type(void) const
VideoVisual * Create(AudioPlayer *audio, MythRender *render) const override
bool m_disabled
Definition: videovisual.h:63
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)
void DestroyBitmapSurface(uint id)
guint32 * goom_update(gint16 data[2][512], int forceMode)
Definition: goom_core.c:141
long long copy(QFile &dst, QFile &src, uint block_size)
Copies src file to dst file.
short * m_right
Definition: videovisual.h:34
uint CreateBitmapSurface(const QSize &size, VdpRGBAFormat fmt=VDP_RGBA_FORMAT_B8G8R8A8, uint existing=0)
void DrawBitmap(uint tex, uint target, const QRect *src, const QRect *dst, uint prog, int alpha=255, int red=255, int green=255, int blue=255)
VideoVisualGoom(AudioPlayer *audio, MythRender *render, bool hd)
const QString & name(void) const override
void UpdateTexture(uint tex, void *buf)
MythMainWindow * GetMythMainWindow(void)
virtual ~VideoVisualGoom()
void * GetTextureBuffer(uint tex, bool create_buffer=true)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
long m_length
Definition: videovisual.h:35
QMutex * mutex()
Definition: visual.h:25
#define GL_RGBA
VideoVisual * Create(AudioPlayer *audio, MythRender *render) const override
VideoVisualGoomFactory VideoVisualGoomFactory
void goom_close()
Definition: goom_core.c:830
RenderType
#define GL_RGBA8
uint CreateTexture(QSize act_size, bool use_pbo, uint type, uint data_type=GL_UNSIGNED_BYTE, uint data_fmt=GL_RGBA, uint internal_fmt=GL_RGBA8, uint filter=GL_LINEAR, uint wrap=GL_CLAMP_TO_EDGE)
MythRender * m_render
Definition: videovisual.h:65
QRect m_area
Definition: videovisual.h:64
bool UploadBitmap(uint id, void *const plane[1], uint32_t pitch[1])
const QString & name(void) const override
short * m_left
Definition: videovisual.h:33
unsigned int * m_buffer