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
|
/*
* 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 "WinSystemGbmEGLContext.h"
#include "OptionalsReg.h"
#include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
#include "utils/log.h"
using namespace KODI::WINDOWING::GBM;
using namespace KODI::WINDOWING::LINUX;
bool CWinSystemGbmEGLContext::InitWindowSystemEGL(EGLint renderableType, EGLint apiType)
{
if (!CWinSystemGbm::InitWindowSystem())
{
return false;
}
if (!m_eglContext.CreatePlatformDisplay(m_GBM->GetDevice()->Get(), m_GBM->GetDevice()->Get()))
{
return false;
}
if (!m_eglContext.InitializeDisplay(apiType))
{
return false;
}
auto plane = m_DRM->GetGuiPlane();
uint32_t visualId = plane != nullptr ? plane->GetFormat() : DRM_FORMAT_XRGB2101010;
// prefer alpha visual id, fallback to non-alpha visual id
if (!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithAlpha(visualId)) &&
!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithoutAlpha(visualId)))
{
// fallback to 8bit format if no EGL config was found for 10bit
if (plane)
plane->SetFormat(DRM_FORMAT_XRGB8888);
visualId = plane != nullptr ? plane->GetFormat() : DRM_FORMAT_XRGB8888;
if (!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithAlpha(visualId)) &&
!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithoutAlpha(visualId)))
{
return false;
}
}
if (!CreateContext())
{
return false;
}
return true;
}
bool CWinSystemGbmEGLContext::CreateNewWindow(const std::string& name,
bool fullScreen,
RESOLUTION_INFO& res)
{
//Notify other subsystems that we change resolution
OnLostDevice();
if (!DestroyWindow())
{
return false;
}
if (!m_DRM->SetMode(res))
{
CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to set DRM mode", __FUNCTION__);
return false;
}
uint32_t format = m_eglContext.GetConfigAttrib(EGL_NATIVE_VISUAL_ID);
std::vector<uint64_t> modifiers;
auto plane = m_DRM->GetGuiPlane();
if (plane)
modifiers = plane->GetModifiersForFormat(format);
if (!m_GBM->GetDevice()->CreateSurface(res.iWidth, res.iHeight, format, modifiers.data(),
modifiers.size()))
{
CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to initialize GBM", __FUNCTION__);
return false;
}
// This check + the reinterpret cast is for security reason, if the user has outdated platform header files which often is the case
static_assert(sizeof(EGLNativeWindowType) == sizeof(gbm_surface*), "Declaration specifier differs in size");
if (!m_eglContext.CreatePlatformSurface(
m_GBM->GetDevice()->GetSurface()->Get(),
reinterpret_cast<khronos_uintptr_t>(m_GBM->GetDevice()->GetSurface()->Get())))
{
return false;
}
if (!m_eglContext.BindContext())
{
return false;
}
m_bFullScreen = fullScreen;
m_nWidth = res.iWidth;
m_nHeight = res.iHeight;
m_fRefreshRate = res.fRefreshRate;
CLog::Log(LOGDEBUG, "CWinSystemGbmEGLContext::{} - initialized GBM", __FUNCTION__);
return true;
}
bool CWinSystemGbmEGLContext::DestroyWindow()
{
m_eglContext.DestroySurface();
CLog::Log(LOGDEBUG, "CWinSystemGbmEGLContext::{} - deinitialized GBM", __FUNCTION__);
return true;
}
bool CWinSystemGbmEGLContext::DestroyWindowSystem()
{
CDVDFactoryCodec::ClearHWAccels();
VIDEOPLAYER::CRendererFactory::ClearRenderer();
m_eglContext.Destroy();
return CWinSystemGbm::DestroyWindowSystem();
}
void CWinSystemGbmEGLContext::delete_CVaapiProxy::operator()(CVaapiProxy *p) const
{
VaapiProxyDelete(p);
}
|