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"
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
37#elif CONFIG_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#ifdef DEBUG_PAINTERWIN_EVENTS
171bool MythPainterWindow::event(QEvent *Event)
172{
173 qInfo() << Event;
174 return QWidget::event(Event);
175}
176#endif
177
178void MythPainterWindow::resizeEvent(QResizeEvent* /*ResizeEvent*/)
179{
180#if CONFIG_WAYLANDEXTRAS
181 if (m_waylandDev)
182 m_waylandDev->SetOpaqueRegion(rect());
183#endif
184}
Event details.
Definition: zmdefines.h:28
void resizeEvent(QResizeEvent *) override
static void DestroyPainters(MythPainterWindow *&PaintWin, MythPainter *&Painter)
static QString CreatePainters(MythMainWindow *MainWin, MythPainterWindow *&PaintWin, MythPainter *&Paint)
MythRender * GetRenderDevice()
MythPainterWindow(MythMainWindow *MainWin)
static MUI_PUBLIC QStringList GetPainters()
MythRender * m_render
static MUI_PUBLIC QString GetDefaultPainter()
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
A simple wrapper to retrieve the major Wayland objects from the Qt Wayland native interface.
static constexpr const char * MYTH_APPNAME_MYTHFRONTEND
Definition: mythappname.h:6
MythDB * GetMythDB(void)
Definition: mythdb.cpp:51
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
bool(*)(MythMainWindow *, MythPainterWindow *&, MythPainter *&, bool &) TryPainter
#define MYTH_PAINTER_QT
#define MYTH_PAINTER_OPENGL
#define MYTH_PAINTER_VULKAN
bool
Definition: pxsup2dast.c:31