MythTV  master
mythpainterwindow.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QWindow>
3 #include <QGuiApplication>
4 
5 // MythTV
6 #include "mythcorecontext.h"
7 #include "mythmainwindow.h"
8 #include "mythpainter_qt.h"
9 #include "mythpainterwindowqt.h"
10 #include "mythpainterwindow.h"
11 
12 #ifdef USING_OPENGL
15 #endif
16 
17 #ifdef USING_VULKAN
20 #endif
21 
22 #ifdef USING_WAYLANDEXTRAS
24 #endif
25 
26 #define MYTH_PAINTER_QT QString("Qt")
27 
29 
31 {
32 #ifdef USING_OPENGL
33  return MYTH_PAINTER_OPENGL;
34 #elif USING_VULKAN
35  return MYTH_PAINTER_VULKAN;
36 #else
37  return MYTH_PAINTER_QT;
38 #endif
39 }
40 
42 {
43  QStringList result;
44 #ifdef USING_OPENGL
45  result.append(MYTH_PAINTER_OPENGL);
46 #endif
47 #ifdef USING_VULKAN
48  result.append(MYTH_PAINTER_VULKAN);
49 #endif
50  return result;
51 }
52 
54  MythPainterWindow *&PaintWin,
55  MythPainter *&Paint)
56 {
57  bool warn = false;
58  QString painter = GetMythDB()->GetSetting("PaintEngine", GetDefaultPainter());
59 
60  // build a prioritised list of painters to try
61  QVector<TryPainter> painterstotry;
62 
63 #ifdef USING_OPENGL
64  auto TryOpenGL = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
65  MythPainter *&Painter, bool& /*unused*/)
66  {
67  auto* glwindow = new MythPainterWindowOpenGL(MainWindow);
68  if (glwindow && glwindow->IsValid())
69  {
70  PaintWindow = glwindow;
71  auto *render = dynamic_cast<MythRenderOpenGL*>(glwindow->GetRenderDevice());
72  Painter = new MythOpenGLPainter(render, MainWindow);
73  return true;
74  }
75  delete glwindow;
76  return false;
77  };
78 
79  if (painter.contains(MYTH_PAINTER_OPENGL, Qt::CaseInsensitive))
80  painterstotry.prepend(TryOpenGL);
81  else
82  painterstotry.append(TryOpenGL);
83 #endif
84 
85 #ifdef USING_VULKAN
86  auto TryVulkan = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
87  MythPainter *&Painter, bool& /*unused*/)
88  {
89  auto *vulkan = new MythPainterWindowVulkan(MainWindow);
90  if (vulkan && vulkan->IsValid())
91  {
92  PaintWindow = vulkan;
93  auto *render = dynamic_cast<MythRenderVulkan*>(vulkan->GetRenderDevice());
94  Painter = new MythPainterVulkan(render, MainWindow);
95  return true;
96  }
97  delete vulkan;
98  return false;
99  };
100 
101  if (painter.contains(MYTH_PAINTER_VULKAN, Qt::CaseInsensitive))
102  painterstotry.prepend(TryVulkan);
103  else
104  painterstotry.append(TryVulkan);
105 #endif
106 
107  // Fallback to Qt painter as the last resort.
108  auto TryQt = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
109  MythPainter *&Painter, bool& Warn)
110  {
111  LOG(VB_GENERAL, LOG_INFO, "Using the Qt painter. Video playback will not work!");
112  Painter = new MythQtPainter();
113  PaintWindow = new MythPainterWindowQt(MainWindow);
114  Warn = QCoreApplication::applicationName() == MYTH_APPNAME_MYTHFRONTEND;
115  return true;
116  };
117 
118  // N.B. this won't be selectable as a painter in the UI but can be forced
119  // from the command line again (-O ThemePainter=Qt)
120  if (painter.contains(MYTH_PAINTER_QT, Qt::CaseInsensitive))
121  painterstotry.prepend(TryQt);
122  else
123  painterstotry.append(TryQt);
124 
125  for (auto & trypainter : painterstotry)
126  if (trypainter(MainWin, PaintWin, Paint, warn))
127  break;
128 
129  return warn ? tr("Warning: No GPU acceleration") : QString();
130 }
131 
133 {
134  delete Painter;
135  delete PaintWin;
136  Painter = nullptr;
137  PaintWin = nullptr;
138 }
139 
141  : QWidget(MainWin)
142 {
143 #ifdef USING_WAYLANDEXTRAS
144  if (QGuiApplication::platformName().toLower().contains("wayland"))
145  m_waylandDev = new MythWaylandDevice(MainWin);
146 #endif
147 }
148 
149 // NOLINTNEXTLINE(modernize-use-equals-default)
151 {
152 #ifdef USING_WAYLAND_EXPOSE_HACK
153  delete m_exposureCheckTimer;
154 #endif
155 #ifdef USING_WAYLANDEXTRAS
156  delete m_waylandDev;
157 #endif
158 }
159 
161 {
162  return m_render;
163 }
164 
166 {
167  return m_render && m_render->IsShared();
168 }
169 
170 #if defined(DEBUG_PAINTERWIN_EVENTS)
171 bool MythPainterWindow::event(QEvent *Event)
172 {
173  qInfo() << Event;
174  return QWidget::event(Event);
175 }
176 #endif
177 
178 void MythPainterWindow::resizeEvent(QResizeEvent* /*ResizeEvent*/)
179 {
180 #ifdef USING_WAYLANDEXTRAS
181  if (m_waylandDev)
182  m_waylandDev->SetOpaqueRegion(rect());
183 #endif
184 
185 #ifdef USING_WAYLAND_EXPOSE_HACK
186  if (!m_exposureCheckTimer && (QGuiApplication::platformName().toLower().contains("wayland")))
187  {
188  m_exposureCheckTimer = new QTimer();
189  connect(m_exposureCheckTimer, &QTimer::timeout, this, &MythPainterWindow::CheckWindowIsExposed);
190  m_exposureCheckTimer->start(100ms);
191  }
192 }
193 
194 void MythPainterWindow::CheckWindowIsExposed()
195 {
196  if (auto handle = windowHandle(); handle && handle->isVisible())
197  {
198  if (handle->isExposed())
199  {
200  // Not sure whether this might re-occur and we should continue checking...
201  LOG(VB_GENERAL, LOG_INFO, "Stopping exposure check timer");
202  m_exposureCheckTimer->stop();
203  }
204  else
205  {
206  LOG(VB_GENERAL, LOG_INFO, "Trying to force window exposure");
207  setVisible(false);
208  setVisible(true);
209  }
210  }
211 }
212 #else
213 }
214 #endif
mythwaylandextras.h
MythPainterWindow::DestroyPainters
static void DestroyPainters(MythPainterWindow *&PaintWin, MythPainter *&Painter)
Definition: mythpainterwindow.cpp:132
MythOpenGLPainter
Definition: mythpainteropengl.h:23
bool
bool
Definition: pxsup2dast.c:30
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
mythpainter_qt.h
MythQtPainter
Definition: mythpainter_qt.h:13
mythpainterwindowqt.h
MythPainterWindow::~MythPainterWindow
~MythPainterWindow() override
Definition: mythpainterwindow.cpp:150
MythPainterWindow
Definition: mythpainterwindow.h:38
MythPainterWindowOpenGL
Definition: mythpainterwindowopengl.h:12
MYTH_PAINTER_QT
#define MYTH_PAINTER_QT
Definition: mythpainterwindow.cpp:26
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythPainterWindow::CreatePainters
static QString CreatePainters(MythMainWindow *MainWin, MythPainterWindow *&PaintWin, MythPainter *&Paint)
Definition: mythpainterwindow.cpp:53
MYTH_APPNAME_MYTHFRONTEND
#define MYTH_APPNAME_MYTHFRONTEND
Definition: mythcorecontext.h:21
MythPainterWindow::GetDefaultPainter
static MUI_PUBLIC QString GetDefaultPainter()
Definition: mythpainterwindow.cpp:30
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:46
mythpaintervulkan.h
MythPainterWindowQt
Definition: mythpainterwindowqt.h:7
mythpainterwindow.h
MythWaylandDevice
A simple wrapper to retrieve the major Wayland objects from the Qt Wayland native interface.
Definition: mythwaylandextras.h:27
MythPainterVulkan
Definition: mythpaintervulkan.h:19
Event
Event details.
Definition: zmdefines.h:26
MythPainterWindow::m_render
MythRender * m_render
Definition: mythpainterwindow.h:62
MythPainterWindow::GetRenderDevice
MythRender * GetRenderDevice()
Definition: mythpainterwindow.cpp:160
TryPainter
bool(*)(MythMainWindow *, MythPainterWindow *&, MythPainter *&, bool &) TryPainter
Definition: mythpainterwindow.cpp:28
mythpainteropengl.h
MythRenderOpenGL
Definition: mythrenderopengl.h:99
MYTH_PAINTER_VULKAN
#define MYTH_PAINTER_VULKAN
Definition: mythpainterwindowvulkan.h:10
MythPainterWindowVulkan
Definition: mythpainterwindowvulkan.h:12
mythcorecontext.h
MythRender
Definition: mythrender_base.h:23
MythPainter
Definition: mythpainter.h:32
MythPainterWindow::GetPainters
static MUI_PUBLIC QStringList GetPainters()
Definition: mythpainterwindow.cpp:41
MythRender::IsShared
bool IsShared(void) const
Warning: The reference count can be decremented between the call to this function and the use of it's...
Definition: mythrender.cpp:12
MythPainterWindow::MythPainterWindow
MythPainterWindow(MythMainWindow *MainWin)
Definition: mythpainterwindow.cpp:140
MythRenderVulkan
Definition: mythrendervulkan.h:54
MythPainterWindow::RenderIsShared
bool RenderIsShared()
Definition: mythpainterwindow.cpp:165
MYTH_PAINTER_OPENGL
#define MYTH_PAINTER_OPENGL
Definition: mythpainterwindowopengl.h:10
mythmainwindow.h
MythPainterWindow::resizeEvent
void resizeEvent(QResizeEvent *) override
Definition: mythpainterwindow.cpp:178
MythMainWindow
Definition: mythmainwindow.h:35
mythpainterwindowvulkan.h
mythpainterwindowopengl.h