[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / windowing / gbm / WinSystemGbmEGLContext.cpp
blobb7e02d58b7bea91aa8df156d9a13b3eb99c8b8f3
1 /*
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.
7 */
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())
23 return false;
26 if (!m_eglContext.CreatePlatformDisplay(m_GBM->GetDevice().Get(), m_GBM->GetDevice().Get()))
28 return false;
31 if (!m_eglContext.InitializeDisplay(apiType))
33 return false;
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
44 if (plane)
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)))
52 return false;
56 if (!CreateContext())
58 return false;
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());
66 else
68 CLog::Log(LOGWARNING, "[GBM] missing support for EGL_KHR_fence_sync and "
69 "EGL_ANDROID_native_fence_sync - performance may be impacted");
72 return true;
75 bool CWinSystemGbmEGLContext::CreateNewWindow(const std::string& name,
76 bool fullScreen,
77 RESOLUTION_INFO& res)
79 //Notify other subsystems that we change resolution
80 OnLostDevice();
82 if (!DestroyWindow())
84 return false;
87 if (!m_DRM->SetMode(res))
89 CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to set DRM mode", __FUNCTION__);
90 return false;
93 uint32_t format = m_eglContext.GetConfigAttrib(EGL_NATIVE_VISUAL_ID);
95 std::vector<uint64_t> modifiers;
97 auto plane = m_DRM->GetGuiPlane();
98 if (plane)
99 modifiers = plane->GetModifiersForFormat(format);
101 if (!m_GBM->GetDevice().CreateSurface(res.iWidth, res.iHeight, format, modifiers.data(),
102 modifiers.size()))
104 CLog::Log(LOGERROR, "CWinSystemGbmEGLContext::{} - failed to initialize GBM", __FUNCTION__);
105 return false;
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())))
115 return false;
118 if (!m_eglContext.BindContext())
120 return false;
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__);
129 return true;
132 bool CWinSystemGbmEGLContext::DestroyWindow()
134 m_eglContext.DestroySurface();
136 CLog::Log(LOGDEBUG, "CWinSystemGbmEGLContext::{} - deinitialized GBM", __FUNCTION__);
137 return true;
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
151 VaapiProxyDelete(p);
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();