2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "WinSystemGbmEGLContext.h"
11 #include "OptionalsReg.h"
12 #include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h"
13 #include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
14 #include "utils/log.h"
16 using namespace KODI::WINDOWING::GBM
;
17 using namespace KODI::WINDOWING::LINUX
;
19 bool CWinSystemGbmEGLContext::InitWindowSystemEGL(EGLint renderableType
, EGLint apiType
)
21 if (!CWinSystemGbm::InitWindowSystem())
26 if (!m_eglContext
.CreatePlatformDisplay(m_GBM
->GetDevice().Get(), m_GBM
->GetDevice().Get()))
31 if (!m_eglContext
.InitializeDisplay(apiType
))
36 auto plane
= m_DRM
->GetGuiPlane();
37 uint32_t visualId
= plane
!= nullptr ? plane
->GetFormat() : DRM_FORMAT_XRGB2101010
;
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
)))
43 // fallback to 8bit format if no EGL config was found for 10bit
45 plane
->SetFormat(DRM_FORMAT_XRGB8888
);
47 visualId
= plane
!= nullptr ? plane
->GetFormat() : DRM_FORMAT_XRGB8888
;
49 if (!m_eglContext
.ChooseConfig(renderableType
, CDRMUtils::FourCCWithAlpha(visualId
)) &&
50 !m_eglContext
.ChooseConfig(renderableType
, CDRMUtils::FourCCWithoutAlpha(visualId
)))
61 if (CEGLUtils::HasExtension(m_eglContext
.GetEGLDisplay(), "EGL_ANDROID_native_fence_sync") &&
62 CEGLUtils::HasExtension(m_eglContext
.GetEGLDisplay(), "EGL_KHR_fence_sync"))
64 m_eglFence
= std::make_unique
<KODI::UTILS::EGL::CEGLFence
>(m_eglContext
.GetEGLDisplay());
68 CLog::Log(LOGWARNING
, "[GBM] missing support for EGL_KHR_fence_sync and "
69 "EGL_ANDROID_native_fence_sync - performance may be impacted");
75 bool CWinSystemGbmEGLContext::CreateNewWindow(const std::string
& name
,
79 //Notify other subsystems that we change resolution
87 if (!m_DRM
->SetMode(res
))
89 CLog::Log(LOGERROR
, "CWinSystemGbmEGLContext::{} - failed to set DRM mode", __FUNCTION__
);
93 uint32_t format
= m_eglContext
.GetConfigAttrib(EGL_NATIVE_VISUAL_ID
);
95 std::vector
<uint64_t> modifiers
;
97 auto plane
= m_DRM
->GetGuiPlane();
99 modifiers
= plane
->GetModifiersForFormat(format
);
101 if (!m_GBM
->GetDevice().CreateSurface(res
.iWidth
, res
.iHeight
, format
, modifiers
.data(),
104 CLog::Log(LOGERROR
, "CWinSystemGbmEGLContext::{} - failed to initialize GBM", __FUNCTION__
);
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");
111 if (!m_eglContext
.CreatePlatformSurface(
112 m_GBM
->GetDevice().GetSurface().Get(),
113 reinterpret_cast<khronos_uintptr_t
>(m_GBM
->GetDevice().GetSurface().Get())))
118 if (!m_eglContext
.BindContext())
123 m_bFullScreen
= fullScreen
;
124 m_nWidth
= res
.iWidth
;
125 m_nHeight
= res
.iHeight
;
126 m_fRefreshRate
= res
.fRefreshRate
;
128 CLog::Log(LOGDEBUG
, "CWinSystemGbmEGLContext::{} - initialized GBM", __FUNCTION__
);
132 bool CWinSystemGbmEGLContext::DestroyWindow()
134 m_eglContext
.DestroySurface();
136 CLog::Log(LOGDEBUG
, "CWinSystemGbmEGLContext::{} - deinitialized GBM", __FUNCTION__
);
140 bool CWinSystemGbmEGLContext::DestroyWindowSystem()
142 CDVDFactoryCodec::ClearHWAccels();
143 VIDEOPLAYER::CRendererFactory::ClearRenderer();
144 m_eglContext
.Destroy();
146 return CWinSystemGbm::DestroyWindowSystem();
149 void CWinSystemGbmEGLContext::delete_CVaapiProxy::operator()(CVaapiProxy
*p
) const
154 bool CWinSystemGbmEGLContext::BindTextureUploadContext()
156 return m_eglContext
.BindTextureUploadContext();
159 bool CWinSystemGbmEGLContext::UnbindTextureUploadContext()
161 return m_eglContext
.UnbindTextureUploadContext();
164 bool CWinSystemGbmEGLContext::HasContext()
166 return m_eglContext
.HasContext();