Debian Codegraph @

xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "WinSystemGbmEGLContext.h"
10
11 #include "OptionalsReg.h"
12 #include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h"
13 #include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
14 #include "utils/log.h"
15
16 using namespace KODI::WINDOWING::GBM;
17 using namespace KODI::WINDOWING::LINUX;
18
19 bool CWinSystemGbmEGLContext::InitWindowSystemEGL(EGLint renderableType, EGLint apiType)
20 {
21 if (!CWinSystemGbm::InitWindowSystem())
22 {
23 return false;
24 }
25
26 if (!m_eglContext.CreatePlatformDisplay(m_GBM->GetDevice().Get(), m_GBM->GetDevice().Get()))
27 {
28 return false;
29 }
30
31 if (!m_eglContext.InitializeDisplay(apiType))
32 {
33 return false;
34 }
35
36 auto plane = m_DRM->GetGuiPlane();
37 uint32_t visualId = plane != nullptr ? plane->GetFormat() : DRM_FORMAT_XRGB2101010;
38
39 // prefer alpha visual id, fallback to non-alpha visual id
40 if (!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithAlpha(visualId)) &&
41 !m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithoutAlpha(visualId)))
42 {
43 // fallback to 8bit format if no EGL config was found for 10bit
44 if (plane)
45 plane->SetFormat(DRM_FORMAT_XRGB8888);
46
47 visualId = plane != nullptr ? plane->GetFormat() : DRM_FORMAT_XRGB8888;
48
49 if (!m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithAlpha(visualId)) &&
50 !m_eglContext.ChooseConfig(renderableType, CDRMUtils::FourCCWithoutAlpha(visualId)))
51 {
52 return false;
53 }
54 }
55
56 if (!CreateContext())
57 {
58 return false;
59 }
60
61 if (CEGLUtils::HasExtension(m_eglContext.GetEGLDisplay(), "EGL_ANDROID_native_fence_sync") &&
62 CEGLUtils::HasExtension(m_eglContext.GetEGLDisplay(), "EGL_KHR_fence_sync"))
63 {
64 m_eglFence = std::make_unique<KODI::UTILS::EGL::CEGLFence>(m_eglContext.GetEGLDisplay());
65 }
66 else
67 {
68 CLog::Log(LOGWARNING, "[GBM] missing support for EGL_KHR_fence_sync and "
69 "EGL_ANDROID_native_fence_sync - performance may be impacted");
70 }
71
72 return true;
73 }
74
75 bool CWinSystemGbmEGLContext::CreateNewWindow(const std::string& name,
76 bool fullScreen,
77 RESOLUTION_INFO& res)
78 {
79 //Notify other subsystems that we change resolution
80 OnLostDevice();
81
82 if (!DestroyWindow())
83 {
84 return false;
85 }
86
87 if (!m_DRM->SetMode(res))
88 {
89 CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to set DRM mode", __FUNCTION__);
90 return false;
91 }
92
93 uint32_t format = m_eglContext.GetConfigAttrib(EGL_NATIVE_VISUAL_ID);
94
95 std::vector<uint64_t> modifiers;
96
97 auto plane = m_DRM->GetGuiPlane();
98 if (plane)
99 modifiers = plane->GetModifiersForFormat(format);
100
101 if (!m_GBM->GetDevice().CreateSurface(res.iWidth, res.iHeight, format, modifiers.data(),
102 modifiers.size()))
103 {
104 CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to initialize GBM", __FUNCTION__);
105 return false;
106 }
107
108 // This check + the reinterpret cast is for security reason, if the user has outdated platform header files which often is the case
109 static_assert(sizeof(EGLNativeWindowType) == sizeof(gbm_surface*), "Declaration specifier differs in size");
110
111 if (!m_eglContext.CreatePlatformSurface(
112 m_GBM->GetDevice().GetSurface().Get(),
113 reinterpret_cast<khronos_uintptr_t>(m_GBM->GetDevice().GetSurface().Get())))
114 {
115 return false;
116 }
117
118 if (!m_eglContext.BindContext())
119 {
120 return false;
121 }
122
123 m_bFullScreen = fullScreen;
124 m_nWidth = res.iWidth;
125 m_nHeight = res.iHeight;
126 m_fRefreshRate = res.fRefreshRate;
127
128 CLog::Log(LOGDEBUG, "CWinSystemGbmEGLContext::{} - initialized GBM", __FUNCTION__);
129 return true;
130 }
131
132 bool CWinSystemGbmEGLContext::DestroyWindow()
133 {
134 m_eglContext.DestroySurface();
135
136 CLog::Log(LOGDEBUG, "CWinSystemGbmEGLContext::{} - deinitialized GBM", __FUNCTION__);
137 return true;
138 }
139
140 bool CWinSystemGbmEGLContext::DestroyWindowSystem()
141 {
142 CDVDFactoryCodec::ClearHWAccels();
143 VIDEOPLAYER::CRendererFactory::ClearRenderer();
144 m_eglContext.Destroy();
145
146 return CWinSystemGbm::DestroyWindowSystem();
147 }
148
149 void CWinSystemGbmEGLContext::delete_CVaapiProxy::operator()(CVaapiProxy *p) const
150 {
151 VaapiProxyDelete(p);
152 }