MythTV
master
mythtv
libs
libmythui
mythpainterwindow.cpp
Go to the documentation of this file.
1
// Qt
2
#include <QWindow>
3
#include <QGuiApplication>
4
5
// MythTV
6
#include "
libmythbase/mythcorecontext.h
"
7
#include "
mythmainwindow.h
"
8
#include "
mythpainter_qt.h
"
9
#include "
mythpainterwindowqt.h
"
10
#include "
mythpainterwindow.h
"
11
12
#ifdef USING_OPENGL
13
#include "
opengl/mythpainterwindowopengl.h
"
14
#include "
opengl/mythpainteropengl.h
"
15
#endif
16
17
#ifdef USING_VULKAN
18
#include "
vulkan/mythpainterwindowvulkan.h
"
19
#include "
vulkan/mythpaintervulkan.h
"
20
#endif
21
22
#ifdef USING_WAYLANDEXTRAS
23
#include "
platforms/mythwaylandextras.h
"
24
#endif
25
26
#define MYTH_PAINTER_QT QString("Qt")
27
28
using
TryPainter
=
bool
(*)(
MythMainWindow
*,
MythPainterWindow
*&,
MythPainter
*&,
bool
&);
29
30
QString
MythPainterWindow::GetDefaultPainter
()
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
41
QStringList
MythPainterWindow::GetPainters
()
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
53
QString
MythPainterWindow::CreatePainters
(
MythMainWindow
*MainWin,
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
132
void
MythPainterWindow::DestroyPainters
(
MythPainterWindow
*&PaintWin,
MythPainter
*&Painter)
133
{
134
delete
Painter;
135
delete
PaintWin;
136
Painter =
nullptr
;
137
PaintWin =
nullptr
;
138
}
139
140
MythPainterWindow::MythPainterWindow
(
MythMainWindow
*MainWin)
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)
150
MythPainterWindow::~MythPainterWindow
()
151
{
152
#ifdef USING_WAYLANDEXTRAS
153
delete
m_waylandDev;
154
#endif
155
}
156
157
MythRender
*
MythPainterWindow::GetRenderDevice
()
158
{
159
return
m_render
;
160
}
161
162
bool
MythPainterWindow::RenderIsShared
()
163
{
164
return
m_render
&&
m_render
->
IsShared
();
165
}
166
167
#if defined(DEBUG_PAINTERWIN_EVENTS)
168
bool
MythPainterWindow::event(QEvent *
Event
)
169
{
170
qInfo() <<
Event
;
171
return
QWidget::event(
Event
);
172
}
173
#endif
174
175
void
MythPainterWindow::resizeEvent
(QResizeEvent*
/*ResizeEvent*/
)
176
{
177
#ifdef USING_WAYLANDEXTRAS
178
if
(m_waylandDev)
179
m_waylandDev->SetOpaqueRegion(rect());
180
#endif
181
}
mythwaylandextras.h
MythPainterWindow::DestroyPainters
static void DestroyPainters(MythPainterWindow *&PaintWin, MythPainter *&Painter)
Definition:
mythpainterwindow.cpp:132
MythOpenGLPainter
Definition:
mythpainteropengl.h:26
bool
bool
Definition:
pxsup2dast.c:30
mythpainter_qt.h
MythQtPainter
Definition:
mythpainter_qt.h:13
mythpainterwindowqt.h
MythPainterWindow::~MythPainterWindow
~MythPainterWindow() override
Definition:
mythpainterwindow.cpp:150
MythPainterWindow
Definition:
mythpainterwindow.h:34
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:39
MythPainterWindow::CreatePainters
static QString CreatePainters(MythMainWindow *MainWin, MythPainterWindow *&PaintWin, MythPainter *&Paint)
Definition:
mythpainterwindow.cpp:53
MythPainterWindow::GetDefaultPainter
static MUI_PUBLIC QString GetDefaultPainter()
Definition:
mythpainterwindow.cpp:30
GetMythDB
MythDB * GetMythDB(void)
Definition:
mythdb.cpp:50
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:27
MythPainterWindow::m_render
MythRender * m_render
Definition:
mythpainterwindow.h:58
MythPainterWindow::GetRenderDevice
MythRender * GetRenderDevice()
Definition:
mythpainterwindow.cpp:157
TryPainter
bool(*)(MythMainWindow *, MythPainterWindow *&, MythPainter *&, bool &) TryPainter
Definition:
mythpainterwindow.cpp:28
mythpainteropengl.h
MythRenderOpenGL
Definition:
mythrenderopengl.h:96
MYTH_PAINTER_VULKAN
#define MYTH_PAINTER_VULKAN
Definition:
mythpainterwindowvulkan.h:10
MYTH_APPNAME_MYTHFRONTEND
static constexpr const char * MYTH_APPNAME_MYTHFRONTEND
Definition:
mythcorecontext.h:21
MythPainterWindowVulkan
Definition:
mythpainterwindowvulkan.h:12
mythcorecontext.h
MythRender
Definition:
mythrender_base.h:23
MythPainter
Definition:
mythpainter.h:34
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:11
MythPainterWindow::MythPainterWindow
MythPainterWindow(MythMainWindow *MainWin)
Definition:
mythpainterwindow.cpp:140
MythRenderVulkan
Definition:
mythrendervulkan.h:57
MythPainterWindow::RenderIsShared
bool RenderIsShared()
Definition:
mythpainterwindow.cpp:162
MYTH_PAINTER_OPENGL
#define MYTH_PAINTER_OPENGL
Definition:
mythpainterwindowopengl.h:10
mythmainwindow.h
MythPainterWindow::resizeEvent
void resizeEvent(QResizeEvent *) override
Definition:
mythpainterwindow.cpp:175
MythMainWindow
Definition:
mythmainwindow.h:28
mythpainterwindowvulkan.h
mythpainterwindowopengl.h
Generated on Sun Jan 5 2025 03:16:25 for MythTV by
1.8.17