/
WinSystemGbm.cpp
293 lines (245 loc) · 7.13 KB
/
WinSystemGbm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "WinSystemGbm.h"
#include "ServiceBroker.h"
#include "settings/DisplaySettings.h"
#include "settings/Settings.h"
#include "settings/lib/Setting.h"
#include <string.h>
#include "OptionalsReg.h"
#include "platform/linux/OptionalsReg.h"
#include "windowing/GraphicContext.h"
#include "platform/linux/powermanagement/LinuxPowerSyscall.h"
#include "settings/DisplaySettings.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "DRMAtomic.h"
#include "DRMLegacy.h"
#include "OffScreenModeSetting.h"
#include "messaging/ApplicationMessenger.h"
CWinSystemGbm::CWinSystemGbm() :
m_DRM(nullptr),
m_GBM(new CGBMUtils),
m_libinput(new CLibInputHandler)
{
std::string envSink;
if (getenv("KODI_AE_SINK"))
envSink = getenv("KODI_AE_SINK");
if (StringUtils::EqualsNoCase(envSink, "ALSA"))
{
OPTIONALS::ALSARegister();
}
else if (StringUtils::EqualsNoCase(envSink, "PULSE"))
{
OPTIONALS::PulseAudioRegister();
}
else if (StringUtils::EqualsNoCase(envSink, "OSS"))
{
OPTIONALS::OSSRegister();
}
else if (StringUtils::EqualsNoCase(envSink, "SNDIO"))
{
OPTIONALS::SndioRegister();
}
else
{
if (!OPTIONALS::PulseAudioRegister())
{
if (!OPTIONALS::ALSARegister())
{
if (!OPTIONALS::SndioRegister())
{
OPTIONALS::OSSRegister();
}
}
}
}
CLinuxPowerSyscall::Register();
m_lirc.reset(OPTIONALS::LircRegister());
m_libinput->Start();
}
bool CWinSystemGbm::InitWindowSystem()
{
m_DRM = std::make_shared<CDRMAtomic>();
if (!m_DRM->InitDrm())
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize Atomic DRM", __FUNCTION__);
m_DRM.reset();
m_DRM = std::make_shared<CDRMLegacy>();
if (!m_DRM->InitDrm())
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize Legacy DRM", __FUNCTION__);
m_DRM.reset();
m_DRM = std::make_shared<COffScreenModeSetting>();
if (!m_DRM->InitDrm())
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize off screen DRM", __FUNCTION__);
m_DRM.reset();
return false;
}
}
}
if (!m_GBM->CreateDevice(m_DRM->GetFileDescriptor()))
{
m_GBM.reset();
return false;
}
CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - initialized DRM", __FUNCTION__);
return CWinSystemBase::InitWindowSystem();
}
bool CWinSystemGbm::DestroyWindowSystem()
{
m_GBM->DestroySurface();
m_GBM->DestroyDevice();
CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - deinitialized DRM", __FUNCTION__);
return true;
}
bool CWinSystemGbm::CreateNewWindow(const std::string& name,
bool fullScreen,
RESOLUTION_INFO& res)
{
//Notify other subsystems that we change resolution
OnLostDevice();
if(!m_DRM->SetMode(res))
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to set DRM mode", __FUNCTION__);
return false;
}
std::vector<uint64_t> *modifiers = m_DRM->GetOverlayPlaneModifiersForFormat(m_DRM->GetOverlayPlane()->format);
if (!m_GBM->CreateSurface(res.iWidth, res.iHeight, modifiers->data(), modifiers->size()))
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize GBM", __FUNCTION__);
return false;
}
m_bFullScreen = fullScreen;
m_nWidth = res.iWidth;
m_nHeight = res.iHeight;
m_fRefreshRate = res.fRefreshRate;
CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - initialized GBM", __FUNCTION__);
return true;
}
bool CWinSystemGbm::DestroyWindow()
{
m_GBM->DestroySurface();
CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - deinitialized GBM", __FUNCTION__);
return true;
}
void CWinSystemGbm::UpdateResolutions()
{
RESOLUTION_INFO current = m_DRM->GetCurrentMode();
auto resolutions = m_DRM->GetModes();
if (resolutions.empty())
{
CLog::Log(LOGWARNING, "CWinSystemGbm::%s - Failed to get resolutions", __FUNCTION__);
}
else
{
CDisplaySettings::GetInstance().ClearCustomResolutions();
for (auto &res : resolutions)
{
CServiceBroker::GetWinSystem()->GetGfxContext().ResetOverscan(res);
CDisplaySettings::GetInstance().AddResolutionInfo(res);
if (current.iScreenWidth == res.iScreenWidth &&
current.iScreenHeight == res.iScreenHeight &&
current.iWidth == res.iWidth &&
current.iHeight == res.iHeight &&
current.fRefreshRate == res.fRefreshRate &&
current.dwFlags == res.dwFlags)
{
CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP) = res;
}
CLog::Log(LOGNOTICE, "Found resolution %dx%d with %dx%d%s @ %f Hz",
res.iWidth,
res.iHeight,
res.iScreenWidth,
res.iScreenHeight,
res.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "",
res.fRefreshRate);
}
}
CDisplaySettings::GetInstance().ApplyCalibrations();
}
bool CWinSystemGbm::ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop)
{
return true;
}
bool CWinSystemGbm::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
// Notify other subsystems that we will change resolution
OnLostDevice();
if(!m_DRM->SetMode(res))
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to set DRM mode", __FUNCTION__);
return false;
}
struct gbm_bo *bo = nullptr;
if (!std::dynamic_pointer_cast<CDRMAtomic>(m_DRM))
{
bo = m_GBM->LockFrontBuffer();
}
auto result = m_DRM->SetVideoMode(res, bo);
if (!std::dynamic_pointer_cast<CDRMAtomic>(m_DRM))
{
m_GBM->ReleaseBuffer();
}
int delay = CServiceBroker::GetSettings().GetInt("videoscreen.delayrefreshchange");
if (delay > 0)
{
m_delayDispReset = true;
m_dispResetTimer.Set(delay * 100);
}
return result;
}
void CWinSystemGbm::FlipPage(bool rendered, bool videoLayer)
{
struct gbm_bo *bo = m_GBM->LockFrontBuffer();
m_DRM->FlipPage(bo, rendered, videoLayer);
m_GBM->ReleaseBuffer();
}
void CWinSystemGbm::WaitVBlank()
{
m_DRM->WaitVBlank();
}
bool CWinSystemGbm::UseLimitedColor()
{
return CServiceBroker::GetSettings().GetBool(CSettings::SETTING_VIDEOSCREEN_LIMITEDRANGE);
}
bool CWinSystemGbm::Hide()
{
bool ret = m_DRM->SetActive(false);
FlipPage(false, false);
return ret;
}
bool CWinSystemGbm::Show(bool raise)
{
bool ret = m_DRM->SetActive(true);
FlipPage(false, false);
return ret;
}
void CWinSystemGbm::Register(IDispResource *resource)
{
CSingleLock lock(m_resourceSection);
m_resources.push_back(resource);
}
void CWinSystemGbm::Unregister(IDispResource *resource)
{
CSingleLock lock(m_resourceSection);
std::vector<IDispResource*>::iterator i = find(m_resources.begin(), m_resources.end(), resource);
if (i != m_resources.end())
{
m_resources.erase(i);
}
}
void CWinSystemGbm::OnLostDevice()
{
CLog::Log(LOGDEBUG, "%s - notify display change event", __FUNCTION__);
{ CSingleLock lock(m_resourceSection);
for (std::vector<IDispResource *>::iterator i = m_resources.begin(); i != m_resources.end(); ++i)
(*i)->OnLostDisplay();
}
}