MythTV  master
mythpainterwindow.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QWindow>
3 #include <QGuiApplication>
4 
5 // MythTV
6 #include "libmythbase/mythconfig.h"
8 #include "libmythbase/mythdb.h"
10 #include "mythmainwindow.h"
11 #include "mythpainter_qt.h"
12 #include "mythpainterwindowqt.h"
13 #include "mythpainterwindow.h"
14 
15 #if CONFIG_OPENGL
18 #endif
19 
20 #if CONFIG_VULKAN
23 #endif
24 
25 #if CONFIG_WAYLANDEXTRAS
27 #endif
28 
29 #define MYTH_PAINTER_QT QString("Qt")
30 
32 
34 {
35 #if CONFIG_OPENGL
36  return MYTH_PAINTER_OPENGL;
37 #elif CONFIG_VULKAN
38  return MYTH_PAINTER_VULKAN;
39 #else
40  return MYTH_PAINTER_QT;
41 #endif
42 }
43 
45 {
46  QStringList result;
47 #if CONFIG_OPENGL
48  result.append(MYTH_PAINTER_OPENGL);
49 #endif
50 #if CONFIG_VULKAN
51  result.append(MYTH_PAINTER_VULKAN);
52 #endif
53  return result;
54 }
55 
57  MythPainterWindow *&PaintWin,
58  MythPainter *&Paint)
59 {
60  bool warn = false;
61  QString painter = GetMythDB()->GetSetting("PaintEngine", GetDefaultPainter());
62 
63  // build a prioritised list of painters to try
64  QVector<TryPainter> painterstotry;
65 
66 #if CONFIG_OPENGL
67  auto TryOpenGL = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
68  MythPainter *&Painter, bool& /*unused*/)
69  {
70  auto* glwindow = new MythPainterWindowOpenGL(MainWindow);
71  if (glwindow && glwindow->IsValid())
72  {
73  PaintWindow = glwindow;
74  auto *render = dynamic_cast<MythRenderOpenGL*>(glwindow->GetRenderDevice());
75  Painter = new MythOpenGLPainter(render, MainWindow);
76  return true;
77  }
78  delete glwindow;
79  return false;
80  };
81 
82  if (painter.contains(MYTH_PAINTER_OPENGL, Qt::CaseInsensitive))
83  painterstotry.prepend(TryOpenGL);
84  else
85  painterstotry.append(TryOpenGL);
86 #endif
87 
88 #if CONFIG_VULKAN
89  auto TryVulkan = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
90  MythPainter *&Painter, bool& /*unused*/)
91  {
92  auto *vulkan = new MythPainterWindowVulkan(MainWindow);
93  if (vulkan && vulkan->IsValid())
94  {
95  PaintWindow = vulkan;
96  auto *render = dynamic_cast<MythRenderVulkan*>(vulkan->GetRenderDevice());
97  Painter = new MythPainterVulkan(render, MainWindow);
98  return true;
99  }
100  delete vulkan;
101  return false;
102  };
103 
104  if (painter.contains(MYTH_PAINTER_VULKAN, Qt::CaseInsensitive))
105  painterstotry.prepend(TryVulkan);
106  else
107  painterstotry.append(TryVulkan);
108 #endif
109 
110  // Fallback to Qt painter as the last resort.
111  auto TryQt = [](MythMainWindow *MainWindow, MythPainterWindow *&PaintWindow,
112  MythPainter *&Painter, bool& Warn)
113  {
114  LOG(VB_GENERAL, LOG_INFO, "Using the Qt painter. Video playback will not work!");
115  Painter = new MythQtPainter();
116  PaintWindow = new MythPainterWindowQt(MainWindow);
117  Warn = QCoreApplication::applicationName() == MYTH_APPNAME_MYTHFRONTEND;
118  return true;
119  };
120 
121  // N.B. this won't be selectable as a painter in the UI but can be forced
122  // from the command line again (-O PaintEngine=Qt)
123  if (painter.contains(MYTH_PAINTER_QT, Qt::CaseInsensitive))
124  painterstotry.prepend(TryQt);
125  else
126  painterstotry.append(TryQt);
127 
128  for (auto & trypainter : painterstotry)
129  if (trypainter(MainWin, PaintWin, Paint, warn))
130  break;
131 
132  return warn ? tr("Warning: No GPU acceleration") : QString();
133 }
134 
136 {
137  delete Painter;
138  delete PaintWin;
139  Painter = nullptr;
140  PaintWin = nullptr;
141 }
142 
144  : QWidget(MainWin)
145 {
146 #if CONFIG_WAYLANDEXTRAS
147  if (QGuiApplication::platformName().toLower().contains("wayland"))
148  m_waylandDev = new MythWaylandDevice(MainWin);
149 #endif
150 }
151 
152 // NOLINTNEXTLINE(modernize-use-equals-default)
154 {
155 #if CONFIG_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 #if CONFIG_WAYLANDEXTRAS
181  if (m_waylandDev)
182  m_waylandDev->SetOpaqueRegion(rect());
183 #endif
184 }
mythwaylandextras.h
MythPainterWindow::DestroyPainters
static void DestroyPainters(MythPainterWindow *&PaintWin, MythPainter *&Painter)
Definition: mythpainterwindow.cpp:135
MythOpenGLPainter
Definition: mythpainteropengl.h:26
bool
bool
Definition: pxsup2dast.c:31
MYTH_APPNAME_MYTHFRONTEND
static constexpr const char * MYTH_APPNAME_MYTHFRONTEND
Definition: mythappname.h:6
mythdb.h
mythpainter_qt.h
MythQtPainter
Definition: mythpainter_qt.h:13
mythpainterwindowqt.h
MythPainterWindow::~MythPainterWindow
~MythPainterWindow() override
Definition: mythpainterwindow.cpp:153
MythPainterWindow
Definition: mythpainterwindow.h:35
MythPainterWindowOpenGL
Definition: mythpainterwindowopengl.h:12
MYTH_PAINTER_QT
#define MYTH_PAINTER_QT
Definition: mythpainterwindow.cpp:29
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythPainterWindow::CreatePainters
static QString CreatePainters(MythMainWindow *MainWin, MythPainterWindow *&PaintWin, MythPainter *&Paint)
Definition: mythpainterwindow.cpp:56
MythPainterWindow::GetDefaultPainter
static MUI_PUBLIC QString GetDefaultPainter()
Definition: mythpainterwindow.cpp:33
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:51
mythpaintervulkan.h
MythPainterWindowQt
Definition: mythpainterwindowqt.h:7
mythpainterwindow.h
mythlogging.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:27
MythPainterWindow::m_render
MythRender * m_render
Definition: mythpainterwindow.h:59
MythPainterWindow::GetRenderDevice
MythRender * GetRenderDevice()
Definition: mythpainterwindow.cpp:160
TryPainter
bool(*)(MythMainWindow *, MythPainterWindow *&, MythPainter *&, bool &) TryPainter
Definition: mythpainterwindow.cpp:31
mythappname.h
mythpainteropengl.h
MythRenderOpenGL
Definition: mythrenderopengl.h:95
MYTH_PAINTER_VULKAN
#define MYTH_PAINTER_VULKAN
Definition: mythpainterwindowvulkan.h:10
MythPainterWindowVulkan
Definition: mythpainterwindowvulkan.h:12
MythRender
Definition: mythrender_base.h:23
MythPainter
Definition: mythpainter.h:34
MythPainterWindow::GetPainters
static MUI_PUBLIC QStringList GetPainters()
Definition: mythpainterwindow.cpp:44
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:11
MythPainterWindow::MythPainterWindow
MythPainterWindow(MythMainWindow *MainWin)
Definition: mythpainterwindow.cpp:143
MythRenderVulkan
Definition: mythrendervulkan.h:57
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:28
mythpainterwindowvulkan.h
mythpainterwindowopengl.h