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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
/*
* 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 "WinSystemX11GLContext.h"
#include "GLContextEGL.h"
#include "OptionalsReg.h"
#include "VideoSyncOML.h"
#include "X11DPMSSupport.h"
#include "application/ApplicationComponents.h"
#include "application/ApplicationSkinHandling.h"
#include "cores/RetroPlayer/process/X11/RPProcessInfoX11.h"
#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.h"
#include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h"
#include "cores/VideoPlayer/Process/X11/ProcessInfoX11.h"
#include "cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
#include "guilib/DispResource.h"
#include "rendering/gl/ScreenshotSurfaceGL.h"
#include "windowing/GraphicContext.h"
#include "windowing/WindowSystemFactory.h"
#include <mutex>
#include <vector>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
using namespace KODI;
using namespace KODI::WINDOWING::X11;
void CWinSystemX11GLContext::Register()
{
KODI::WINDOWING::CWindowSystemFactory::RegisterWindowSystem(CreateWinSystem, "x11");
}
std::unique_ptr<CWinSystemBase> CWinSystemX11GLContext::CreateWinSystem()
{
return std::make_unique<CWinSystemX11GLContext>();
}
CWinSystemX11GLContext::~CWinSystemX11GLContext()
{
delete m_pGLContext;
}
void CWinSystemX11GLContext::PresentRenderImpl(bool rendered)
{
if (rendered)
m_pGLContext->SwapBuffers();
if (m_delayDispReset && m_dispResetTimer.IsTimePast())
{
m_delayDispReset = false;
std::unique_lock<CCriticalSection> lock(m_resourceSection);
// tell any shared resources
for (std::vector<IDispResource *>::iterator i = m_resources.begin(); i != m_resources.end(); ++i)
(*i)->OnResetDisplay();
}
}
void CWinSystemX11GLContext::SetVSyncImpl(bool enable)
{
m_pGLContext->SetVSync(enable);
}
bool CWinSystemX11GLContext::IsExtSupported(const char* extension) const
{
if(strncmp(extension, m_pGLContext->ExtPrefix().c_str(), 4) != 0)
return CRenderSystemGL::IsExtSupported(extension);
return m_pGLContext->IsExtSupported(extension);
}
XID CWinSystemX11GLContext::GetWindow() const
{
return GLXGetWindow(m_pGLContext);
}
void* CWinSystemX11GLContext::GetGlxContext() const
{
return GLXGetContext(m_pGLContext);
}
EGLDisplay CWinSystemX11GLContext::GetEGLDisplay() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglDisplay;
}
EGLSurface CWinSystemX11GLContext::GetEGLSurface() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglSurface;
}
EGLContext CWinSystemX11GLContext::GetEGLContext() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglContext;
}
EGLConfig CWinSystemX11GLContext::GetEGLConfig() const
{
return static_cast<CGLContextEGL*>(m_pGLContext)->m_eglConfig;
}
bool CWinSystemX11GLContext::SetWindow(int width, int height, bool fullscreen, const std::string &output, int *winstate)
{
int newwin = 0;
CWinSystemX11::SetWindow(width, height, fullscreen, output, &newwin);
if (newwin)
{
RefreshGLContext(m_currentOutput.compare(output) != 0);
XSync(m_dpy, False);
CServiceBroker::GetWinSystem()->GetGfxContext().Clear(0);
CServiceBroker::GetWinSystem()->GetGfxContext().Flip(true, false);
ResetVSync();
m_windowDirty = false;
m_bIsInternalXrr = false;
if (!m_delayDispReset)
{
std::unique_lock<CCriticalSection> lock(m_resourceSection);
// tell any shared resources
for (std::vector<IDispResource *>::iterator i = m_resources.begin(); i != m_resources.end(); ++i)
(*i)->OnResetDisplay();
}
}
return true;
}
bool CWinSystemX11GLContext::CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res)
{
if(!CWinSystemX11::CreateNewWindow(name, fullScreen, res))
return false;
m_pGLContext->QueryExtensions();
return true;
}
bool CWinSystemX11GLContext::ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop)
{
m_newGlContext = false;
CWinSystemX11::ResizeWindow(newWidth, newHeight, newLeft, newTop);
CRenderSystemGL::ResetRenderSystem(newWidth, newHeight);
if (m_newGlContext)
{
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->ReloadSkin();
}
return true;
}
void CWinSystemX11GLContext::FinishWindowResize(int newWidth, int newHeight)
{
m_newGlContext = false;
CWinSystemX11::FinishWindowResize(newWidth, newHeight);
CRenderSystemGL::ResetRenderSystem(newWidth, newHeight);
if (m_newGlContext)
{
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->ReloadSkin();
}
}
bool CWinSystemX11GLContext::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
m_newGlContext = false;
CWinSystemX11::SetFullScreen(fullScreen, res, blankOtherDisplays);
CRenderSystemGL::ResetRenderSystem(res.iWidth, res.iHeight);
if (m_newGlContext)
{
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->ReloadSkin();
}
return true;
}
bool CWinSystemX11GLContext::DestroyWindowSystem()
{
if (m_pGLContext)
m_pGLContext->Destroy();
return CWinSystemX11::DestroyWindowSystem();
}
bool CWinSystemX11GLContext::DestroyWindow()
{
if (m_pGLContext)
m_pGLContext->Detach();
return CWinSystemX11::DestroyWindow();
}
XVisualInfo* CWinSystemX11GLContext::GetVisual()
{
int count = 0;
XVisualInfo vTemplate;
XVisualInfo *visual = nullptr;
int vMask = VisualScreenMask | VisualDepthMask | VisualClassMask;
vTemplate.screen = m_screen;
vTemplate.depth = 24;
vTemplate.c_class = TrueColor;
visual = XGetVisualInfo(m_dpy, vMask, &vTemplate, &count);
if (!visual)
{
vTemplate.depth = 30;
visual = XGetVisualInfo(m_dpy, vMask, &vTemplate, &count);
}
return visual;
}
bool CWinSystemX11GLContext::RefreshGLContext(bool force)
{
bool success = false;
if (m_pGLContext)
{
if (force)
{
auto& components = CServiceBroker::GetAppComponents();
const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
appSkin->UnloadSkin();
CRenderSystemGL::DestroyRenderSystem();
}
success = m_pGLContext->Refresh(force, m_screen, m_glWindow, m_newGlContext);
if (!success)
{
success = m_pGLContext->CreatePB();
m_newGlContext = true;
}
if (force)
CRenderSystemGL::InitRenderSystem();
return success;
}
m_dpms = std::make_shared<CX11DPMSSupport>();
VIDEOPLAYER::CProcessInfoX11::Register();
RETRO::CRPProcessInfoX11::Register();
RETRO::CRPProcessInfoX11::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGL);
CDVDFactoryCodec::ClearHWAccels();
VIDEOPLAYER::CRendererFactory::ClearRenderer();
CLinuxRendererGL::Register();
CScreenshotSurfaceGL::Register();
std::string gpuvendor;
const char* vend = (const char*) glGetString(GL_VENDOR);
if (vend)
gpuvendor = vend;
std::transform(gpuvendor.begin(), gpuvendor.end(), gpuvendor.begin(), ::tolower);
bool isNvidia = (gpuvendor.compare(0, 6, "nvidia") == 0);
bool isIntel = (gpuvendor.compare(0, 5, "intel") == 0);
std::string gli = (getenv("KODI_GL_INTERFACE") != nullptr) ? getenv("KODI_GL_INTERFACE") : "";
if (gli != "GLX")
{
m_pGLContext = new CGLContextEGL(m_dpy, EGL_OPENGL_API);
success = m_pGLContext->Refresh(force, m_screen, m_glWindow, m_newGlContext);
if (success)
{
if (!isNvidia)
{
m_vaapiProxy.reset(VaapiProxyCreate());
VaapiProxyConfig(m_vaapiProxy.get(), GetDisplay(),
static_cast<CGLContextEGL*>(m_pGLContext)->m_eglDisplay);
bool general = false;
bool deepColor = false;
VAAPIRegisterRenderGL(m_vaapiProxy.get(), general, deepColor);
if (general)
{
VAAPIRegister(m_vaapiProxy.get(), deepColor);
return true;
}
if (isIntel || gli == "EGL")
return true;
}
}
else if (gli == "EGL_PB")
{
success = m_pGLContext->CreatePB();
if (success)
return true;
}
}
delete m_pGLContext;
// fallback for vdpau
m_pGLContext = GLXContextCreate(m_dpy);
success = m_pGLContext->Refresh(force, m_screen, m_glWindow, m_newGlContext);
if (success)
{
VDPAURegister();
VDPAURegisterRender();
}
return success;
}
std::unique_ptr<CVideoSync> CWinSystemX11GLContext::GetVideoSync(void *clock)
{
std::unique_ptr<CVideoSync> pVSync;
if (dynamic_cast<CGLContextEGL*>(m_pGLContext))
{
pVSync.reset(new CVideoSyncOML(clock, *this));
}
else
{
pVSync.reset(GLXVideoSyncCreate(clock, *this));
}
return pVSync;
}
float CWinSystemX11GLContext::GetFrameLatencyAdjustment()
{
if (m_pGLContext)
{
uint64_t msc, interval;
float micros = m_pGLContext->GetVblankTiming(msc, interval);
return micros / 1000;
}
return 0;
}
uint64_t CWinSystemX11GLContext::GetVblankTiming(uint64_t &msc, uint64_t &interval)
{
if (m_pGLContext)
{
float micros = m_pGLContext->GetVblankTiming(msc, interval);
return micros;
}
msc = 0;
interval = 0;
return 0;
}
void CWinSystemX11GLContext::delete_CVaapiProxy::operator()(CVaapiProxy *p) const
{
VaapiProxyDelete(p);
}
|