From 7e3a9b6c5d82102a83cd6a11f3601424cfd721b0 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: utils/EGLUtils: add CEGLContextUtils class --- xbmc/utils/EGLUtils.cpp | 224 ++++++++++++++++++++++++++++++++++++++++++++++++ xbmc/utils/EGLUtils.h | 27 +++++- 2 files changed, 250 insertions(+), 1 deletion(-) diff --git a/xbmc/utils/EGLUtils.cpp b/xbmc/utils/EGLUtils.cpp index 9e93dbb8fe..23ff11233c 100644 --- a/xbmc/utils/EGLUtils.cpp +++ b/xbmc/utils/EGLUtils.cpp @@ -21,6 +21,12 @@ #include "EGLUtils.h" #include "log.h" +#include "guilib/IDirtyRegionSolver.h" +#include "settings/AdvancedSettings.h" + +#include +#include + std::set CEGLUtils::GetClientExtensions() { const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); @@ -55,3 +61,221 @@ void CEGLUtils::LogError(const std::string& what) { CLog::Log(LOGERROR, "%s (EGL error %d)", what.c_str(), eglGetError()); } + +CEGLContextUtils::CEGLContextUtils() : + m_eglDisplay(EGL_NO_DISPLAY), + m_eglSurface(EGL_NO_SURFACE), + m_eglContext(EGL_NO_CONTEXT), + m_eglConfig(0) +{ +} + +CEGLContextUtils::~CEGLContextUtils() +{ + Destroy(); +} + +bool CEGLContextUtils::CreateDisplay(EGLDisplay display, + EGLint renderable_type, + EGLint rendering_api) +{ + EGLint neglconfigs = 0; + int major, minor; + + EGLint surface_type = EGL_WINDOW_BIT; + // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates + if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || + g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) + surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; + + EGLint attribs[] = + { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 16, + EGL_STENCIL_SIZE, 0, + EGL_SAMPLE_BUFFERS, 0, + EGL_SAMPLES, 0, + EGL_SURFACE_TYPE, surface_type, + EGL_RENDERABLE_TYPE, renderable_type, + EGL_NONE + }; + +#if defined(EGL_EXT_platform_base) && defined(EGL_KHR_platform_gbm) && defined(HAVE_GBM) + if (m_eglDisplay == EGL_NO_DISPLAY && + CEGLUtils::HasExtension(EGL_NO_DISPLAY, "EGL_EXT_platform_base") && + CEGLUtils::HasExtension(EGL_NO_DISPLAY, "EGL_KHR_platform_gbm")) + { + PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT"); + if (getPlatformDisplayEXT) + { + m_eglDisplay = getPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, (EGLNativeDisplayType)display, NULL); + } + } +#endif + + if (m_eglDisplay == EGL_NO_DISPLAY) + { + m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display); + } + + if (m_eglDisplay == EGL_NO_DISPLAY) + { + CLog::Log(LOGERROR, "failed to get EGL display"); + return false; + } + + if (!eglInitialize(m_eglDisplay, &major, &minor)) + { + CLog::Log(LOGERROR, "failed to initialize EGL display"); + return false; + } + + eglBindAPI(rendering_api); + + if (!eglChooseConfig(m_eglDisplay, attribs, + &m_eglConfig, 1, &neglconfigs)) + { + CLog::Log(LOGERROR, "Failed to query number of EGL configs"); + return false; + } + + if (neglconfigs <= 0) + { + CLog::Log(LOGERROR, "No suitable EGL configs found"); + return false; + } + + return true; +} + +bool CEGLContextUtils::CreateContext() +{ + int client_version = 2; + + const EGLint context_attribs[] = + { + EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE + }; + + if (m_eglContext == EGL_NO_CONTEXT) + { + m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, + EGL_NO_CONTEXT, context_attribs); + } + + if (m_eglContext == EGL_NO_CONTEXT) + { + CLog::Log(LOGERROR, "failed to create EGL context"); + return false; + } + + return true; +} + +bool CEGLContextUtils::BindContext() +{ + if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, + m_eglSurface, m_eglContext)) + { + CLog::Log(LOGERROR, "Failed to make context current %p %p %p", + m_eglDisplay, m_eglSurface, m_eglContext); + return false; + } + + return true; +} + +bool CEGLContextUtils::SurfaceAttrib() +{ + // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates + if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || + g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) + { + if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE)) + { + return false; + } + + if (!eglSurfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) + { + CLog::Log(LOGDEBUG, "%s: Could not set EGL_SWAP_BEHAVIOR",__FUNCTION__); + } + } + + return true; +} + +bool CEGLContextUtils::CreateSurface(EGLNativeWindowType surface) +{ + m_eglSurface = eglCreateWindowSurface(m_eglDisplay, + m_eglConfig, + surface, + nullptr); + + if (m_eglSurface == EGL_NO_SURFACE) + { + CLog::Log(LOGERROR, "failed to create EGL window surface %d", eglGetError()); + return false; + } + + return true; +} + +void CEGLContextUtils::Destroy() +{ + if (m_eglContext != EGL_NO_CONTEXT) + { + eglDestroyContext(m_eglDisplay, m_eglContext); + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + m_eglContext = EGL_NO_CONTEXT; + } + + if (m_eglSurface != EGL_NO_SURFACE) + { + eglDestroySurface(m_eglDisplay, m_eglSurface); + m_eglSurface = EGL_NO_SURFACE; + } + + if (m_eglDisplay != EGL_NO_DISPLAY) + { + eglTerminate(m_eglDisplay); + m_eglDisplay = EGL_NO_DISPLAY; + } +} + +void CEGLContextUtils::Detach() +{ + if (m_eglContext != EGL_NO_CONTEXT) + { + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + } + + if (m_eglSurface != EGL_NO_SURFACE) + { + eglDestroySurface(m_eglDisplay, m_eglSurface); + m_eglSurface = EGL_NO_SURFACE; + } +} + +bool CEGLContextUtils::SetVSync(bool enable) +{ + if (!eglSwapInterval(m_eglDisplay, enable)) + { + return false; + } + + return true; +} + +void CEGLContextUtils::SwapBuffers() +{ + if (m_eglDisplay == EGL_NO_DISPLAY || m_eglSurface == EGL_NO_SURFACE) + { + return; + } + + eglSwapBuffers(m_eglDisplay, m_eglSurface); +} diff --git a/xbmc/utils/EGLUtils.h b/xbmc/utils/EGLUtils.h index 3879d5a91f..665fbae826 100644 --- a/xbmc/utils/EGLUtils.h +++ b/xbmc/utils/EGLUtils.h @@ -118,4 +118,29 @@ public: private: std::array m_attributes; int m_writePosition{}; -}; \ No newline at end of file +}; + +class CEGLContextUtils +{ +public: + CEGLContextUtils(); + virtual ~CEGLContextUtils(); + + bool CreateDisplay(EGLDisplay display, + EGLint renderable_type, + EGLint rendering_api); + + bool CreateSurface(EGLNativeWindowType surface); + bool CreateContext(); + bool BindContext(); + bool SurfaceAttrib(); + void Destroy(); + void Detach(); + bool SetVSync(bool enable); + void SwapBuffers(); + + EGLDisplay m_eglDisplay; + EGLSurface m_eglSurface; + EGLContext m_eglContext; + EGLConfig m_eglConfig; +}; -- cgit v1.2.3 From d84278d8e4db0cde90f0a3b83f1bbc672b94f871 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: windowing/gbm: use EGLUtils --- xbmc/windowing/gbm/CMakeLists.txt | 2 - xbmc/windowing/gbm/GLContextEGL.cpp | 252 --------------------------- xbmc/windowing/gbm/GLContextEGL.h | 48 ----- xbmc/windowing/gbm/WinSystemGbmGLESContext.h | 4 +- 4 files changed, 2 insertions(+), 304 deletions(-) delete mode 100644 xbmc/windowing/gbm/GLContextEGL.cpp delete mode 100644 xbmc/windowing/gbm/GLContextEGL.h diff --git a/xbmc/windowing/gbm/CMakeLists.txt b/xbmc/windowing/gbm/CMakeLists.txt index 53de4bac91..692561382e 100644 --- a/xbmc/windowing/gbm/CMakeLists.txt +++ b/xbmc/windowing/gbm/CMakeLists.txt @@ -1,5 +1,4 @@ set(SOURCES OptionalsReg.cpp - GLContextEGL.cpp WinSystemGbm.cpp GBMUtils.cpp DRMUtils.cpp @@ -7,7 +6,6 @@ set(SOURCES OptionalsReg.cpp DRMAtomic.cpp) set(HEADERS OptionalsReg.h - GLContextEGL.h WinSystemGbm.h GBMUtils.h DRMUtils.h diff --git a/xbmc/windowing/gbm/GLContextEGL.cpp b/xbmc/windowing/gbm/GLContextEGL.cpp deleted file mode 100644 index 52b58082ab..0000000000 --- a/xbmc/windowing/gbm/GLContextEGL.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "GLContextEGL.h" - -#include "guilib/IDirtyRegionSolver.h" -#include "settings/AdvancedSettings.h" -#include "utils/log.h" - -#include -#include - -CGLContextEGL::CGLContextEGL() : - m_eglDisplay(EGL_NO_DISPLAY), - m_eglSurface(EGL_NO_SURFACE), - m_eglContext(EGL_NO_CONTEXT), - m_eglConfig(0) -{ -} - -CGLContextEGL::~CGLContextEGL() -{ - Destroy(); -} - -bool CGLContextEGL::CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api) -{ - EGLint neglconfigs = 0; - int major, minor; - - EGLint surface_type = EGL_WINDOW_BIT; - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; - - EGLint attribs[] = - { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 0, - EGL_SAMPLE_BUFFERS, 0, - EGL_SAMPLES, 0, - EGL_SURFACE_TYPE, surface_type, - EGL_RENDERABLE_TYPE, renderable_type, - EGL_NONE - }; - - const char *client_extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); - CLog::Log(LOGNOTICE, "EGL_EXTENSIONS = %s", client_extensions); - -#if defined(EGL_EXT_platform_base) && defined(EGL_KHR_platform_gbm) - if (m_eglDisplay == EGL_NO_DISPLAY && - client_extensions != NULL && - strstr(client_extensions, "EGL_EXT_platform_base") && - strstr(client_extensions, "EGL_KHR_platform_gbm")) - { - PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT"); - if (getPlatformDisplayEXT) - { - m_eglDisplay = getPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, (EGLNativeDisplayType)display, NULL); - } - } -#endif - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display); - } - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - CLog::Log(LOGERROR, "failed to get EGL display"); - return false; - } - - if (!eglInitialize(m_eglDisplay, &major, &minor)) - { - CLog::Log(LOGERROR, "failed to initialize EGL display"); - return false; - } - - eglBindAPI(rendering_api); - - if (!eglChooseConfig(m_eglDisplay, attribs, - &m_eglConfig, 1, &neglconfigs)) - { - CLog::Log(LOGERROR, "Failed to query number of EGL configs"); - return false; - } - - if (neglconfigs <= 0) - { - CLog::Log(LOGERROR, "No suitable EGL configs found"); - return false; - } - - const char *display_extensions = eglQueryString(m_eglDisplay, EGL_EXTENSIONS); - CLog::Log(LOGNOTICE, "EGL_EXTENSIONS = %s", display_extensions); - - return true; -} - -bool CGLContextEGL::CreateContext() -{ - int client_version = 2; - - const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE - }; - - if (m_eglContext == EGL_NO_CONTEXT) - { - m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, - EGL_NO_CONTEXT, context_attribs); - } - - if (m_eglContext == EGL_NO_CONTEXT) - { - CLog::Log(LOGERROR, "failed to create EGL context"); - return false; - } - - return true; -} - -bool CGLContextEGL::BindContext() -{ - if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, - m_eglSurface, m_eglContext)) - { - CLog::Log(LOGERROR, "Failed to make context current %p %p %p", - m_eglDisplay, m_eglSurface, m_eglContext); - return false; - } - - return true; -} - -bool CGLContextEGL::SurfaceAttrib() -{ - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - { - if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE)) - { - return false; - } - - if (!eglSurfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) - { - CLog::Log(LOGDEBUG, "%s: Could not set EGL_SWAP_BEHAVIOR",__FUNCTION__); - } - } - - return true; -} - -bool CGLContextEGL::CreateSurface(EGLNativeWindowType surface) -{ - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, - m_eglConfig, - surface, - nullptr); - - if (m_eglSurface == EGL_NO_SURFACE) - { - CLog::Log(LOGERROR, "failed to create EGL window surface %d", eglGetError()); - return false; - } - - return true; -} - -void CGLContextEGL::Destroy() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(m_eglDisplay, m_eglContext); - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - m_eglContext = EGL_NO_CONTEXT; - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } - - if (m_eglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(m_eglDisplay); - m_eglDisplay = EGL_NO_DISPLAY; - } -} - -void CGLContextEGL::Detach() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } -} - -bool CGLContextEGL::SetVSync(bool enable) -{ - if (!eglSwapInterval(m_eglDisplay, enable)) - { - return false; - } - - return true; -} - -void CGLContextEGL::SwapBuffers() -{ - if (m_eglDisplay == EGL_NO_DISPLAY || m_eglSurface == EGL_NO_SURFACE) - { - return; - } - - eglSwapBuffers(m_eglDisplay, m_eglSurface); -} diff --git a/xbmc/windowing/gbm/GLContextEGL.h b/xbmc/windowing/gbm/GLContextEGL.h deleted file mode 100644 index 9370684d57..0000000000 --- a/xbmc/windowing/gbm/GLContextEGL.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#pragma once - -#include "EGL/egl.h" - -class CGLContextEGL -{ -public: - CGLContextEGL(); - virtual ~CGLContextEGL(); - - bool CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api); - - bool CreateSurface(EGLNativeWindowType surface); - bool CreateContext(); - bool BindContext(); - bool SurfaceAttrib(); - void Destroy(); - void Detach(); - bool SetVSync(bool enable); - void SwapBuffers(); - - EGLDisplay m_eglDisplay; - EGLSurface m_eglSurface; - EGLContext m_eglContext; - EGLConfig m_eglConfig; -}; diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h index 19866a3740..056f3cbaab 100644 --- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h @@ -20,7 +20,7 @@ #pragma once -#include "GLContextEGL.h" +#include "utils/EGLUtils.h" #include "rendering/gles/RenderSystemGLES.h" #include "WinSystemGbm.h" #include @@ -50,7 +50,7 @@ protected: void PresentRenderImpl(bool rendered) override {}; private: - CGLContextEGL m_pGLContext; + CEGLContextUtils m_pGLContext; struct delete_CVaapiProxy { void operator()(CVaapiProxy *p) const; -- cgit v1.2.3 From 360a7d21815beae2b9635fbb78f86b064a80a71a Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: windowing/gbm: remove uneeded pointers --- xbmc/windowing/gbm/WinSystemGbm.cpp | 10 ---------- xbmc/windowing/gbm/WinSystemGbm.h | 4 ---- xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp | 4 ++-- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/xbmc/windowing/gbm/WinSystemGbm.cpp b/xbmc/windowing/gbm/WinSystemGbm.cpp index 561e61f12e..906b53783d 100644 --- a/xbmc/windowing/gbm/WinSystemGbm.cpp +++ b/xbmc/windowing/gbm/WinSystemGbm.cpp @@ -40,8 +40,6 @@ CWinSystemGbm::CWinSystemGbm() : m_DRM(nullptr), m_GBM(new CGBMUtils), - m_nativeDisplay(nullptr), - m_nativeWindow(nullptr), m_delayDispReset(false) { std::string envSink; @@ -99,8 +97,6 @@ bool CWinSystemGbm::InitWindowSystem() return false; } - m_nativeDisplay = m_GBM->m_device; - CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - initialized DRM", __FUNCTION__); return CWinSystemBase::InitWindowSystem(); } @@ -108,10 +104,7 @@ bool CWinSystemGbm::InitWindowSystem() bool CWinSystemGbm::DestroyWindowSystem() { m_GBM->DestroySurface(); - m_nativeWindow = nullptr; - m_GBM->DestroyDevice(); - m_nativeDisplay = nullptr; CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - deinitialized DRM", __FUNCTION__); return true; @@ -136,8 +129,6 @@ bool CWinSystemGbm::CreateNewWindow(const std::string& name, return false; } - m_nativeWindow = reinterpret_cast(m_GBM->m_surface); - CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - initialized GBM", __FUNCTION__); return true; } @@ -145,7 +136,6 @@ bool CWinSystemGbm::CreateNewWindow(const std::string& name, bool CWinSystemGbm::DestroyWindow() { m_GBM->DestroySurface(); - m_nativeWindow = nullptr; CLog::Log(LOGDEBUG, "CWinSystemGbm::%s - deinitialized GBM", __FUNCTION__); return true; diff --git a/xbmc/windowing/gbm/WinSystemGbm.h b/xbmc/windowing/gbm/WinSystemGbm.h index 5ad76c273e..87a5afcbae 100644 --- a/xbmc/windowing/gbm/WinSystemGbm.h +++ b/xbmc/windowing/gbm/WinSystemGbm.h @@ -26,7 +26,6 @@ #include "threads/CriticalSection.h" #include "windowing/WinSystem.h" #include "DRMUtils.h" -#include "GLContextEGL.h" class IDispResource; @@ -65,9 +64,6 @@ protected: std::unique_ptr m_GBM; - EGLDisplay m_nativeDisplay; - EGLNativeWindowType m_nativeWindow; - CCriticalSection m_resourceSection; std::vector m_resources; diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp index 8a3f2432df..b06ae324e5 100644 --- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp @@ -50,7 +50,7 @@ bool CWinSystemGbmGLESContext::InitWindowSystem() return false; } - if (!m_pGLContext.CreateDisplay(m_nativeDisplay, + if (!m_pGLContext.CreateDisplay(m_GBM->m_device, EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES_API)) { @@ -99,7 +99,7 @@ bool CWinSystemGbmGLESContext::CreateNewWindow(const std::string& name, return false; } - if (!m_pGLContext.CreateSurface(m_nativeWindow)) + if (!m_pGLContext.CreateSurface(reinterpret_cast(m_GBM->m_surface))) { return false; } -- cgit v1.2.3 From 2f81b0fe2116d1f2959d33eeeb6eb84e5e00e659 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: windowing/amlogic: use EGLUtils --- xbmc/windowing/amlogic/CMakeLists.txt | 6 +- xbmc/windowing/amlogic/GLContextEGL.cpp | 229 --------------------- xbmc/windowing/amlogic/GLContextEGL.h | 48 ----- .../amlogic/WinSystemAmlogicGLESContext.h | 4 +- 4 files changed, 4 insertions(+), 283 deletions(-) delete mode 100644 xbmc/windowing/amlogic/GLContextEGL.cpp delete mode 100644 xbmc/windowing/amlogic/GLContextEGL.h diff --git a/xbmc/windowing/amlogic/CMakeLists.txt b/xbmc/windowing/amlogic/CMakeLists.txt index 2ad0319615..5df7176c70 100644 --- a/xbmc/windowing/amlogic/CMakeLists.txt +++ b/xbmc/windowing/amlogic/CMakeLists.txt @@ -1,9 +1,7 @@ -set(SOURCES GLContextEGL.cpp - WinSystemAmlogic.cpp +set(SOURCES WinSystemAmlogic.cpp VideoSyncAML.cpp) -set(HEADERS GLContextEGL.h - WinSystemAmlogic.h +set(HEADERS WinSystemAmlogic.h VideoSyncAML.h) if(OPENGLES_FOUND) diff --git a/xbmc/windowing/amlogic/GLContextEGL.cpp b/xbmc/windowing/amlogic/GLContextEGL.cpp deleted file mode 100644 index 91d19465d0..0000000000 --- a/xbmc/windowing/amlogic/GLContextEGL.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "GLContextEGL.h" - -#include "guilib/IDirtyRegionSolver.h" -#include "settings/AdvancedSettings.h" -#include "utils/log.h" - -CGLContextEGL::CGLContextEGL() : - m_eglDisplay(EGL_NO_DISPLAY), - m_eglSurface(EGL_NO_SURFACE), - m_eglContext(EGL_NO_CONTEXT), - m_eglConfig(0) -{ -} - -CGLContextEGL::~CGLContextEGL() -{ - Destroy(); -} - -bool CGLContextEGL::CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api) -{ - EGLint neglconfigs = 0; - int major, minor; - - EGLint surface_type = EGL_WINDOW_BIT; - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; - - EGLint attribs[] = - { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 0, - EGL_SAMPLE_BUFFERS, 0, - EGL_SAMPLES, 0, - EGL_SURFACE_TYPE, surface_type, - EGL_RENDERABLE_TYPE, renderable_type, - EGL_NONE - }; - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display); - } - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - CLog::Log(LOGERROR, "failed to get EGL display"); - return false; - } - - if (!eglInitialize(m_eglDisplay, &major, &minor)) - { - CLog::Log(LOGERROR, "failed to initialize EGL display"); - return false; - } - - eglBindAPI(rendering_api); - - if (!eglChooseConfig(m_eglDisplay, attribs, - &m_eglConfig, 1, &neglconfigs)) - { - CLog::Log(LOGERROR, "Failed to query number of EGL configs"); - return false; - } - - if (neglconfigs <= 0) - { - CLog::Log(LOGERROR, "No suitable EGL configs found"); - return false; - } - - return true; -} - -bool CGLContextEGL::CreateContext() -{ - int client_version = 2; - - const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE - }; - - if (m_eglContext == EGL_NO_CONTEXT) - { - m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, - EGL_NO_CONTEXT, context_attribs); - } - - if (m_eglContext == EGL_NO_CONTEXT) - { - CLog::Log(LOGERROR, "failed to create EGL context"); - return false; - } - - return true; -} - -bool CGLContextEGL::BindContext() -{ - if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, - m_eglSurface, m_eglContext)) - { - CLog::Log(LOGERROR, "Failed to make context current %p %p %p", - m_eglDisplay, m_eglSurface, m_eglContext); - return false; - } - - return true; -} - -bool CGLContextEGL::SurfaceAttrib() -{ - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - { - if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE)) - { - return false; - } - - if (!eglSurfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) - { - CLog::Log(LOGDEBUG, "%s: Could not set EGL_SWAP_BEHAVIOR",__FUNCTION__); - } - } - - return true; -} - -bool CGLContextEGL::CreateSurface(EGLNativeWindowType surface) -{ - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, - m_eglConfig, - surface, - nullptr); - - if (m_eglSurface == EGL_NO_SURFACE) - { - CLog::Log(LOGERROR, "failed to create EGL window surface %d", eglGetError()); - return false; - } - - return true; -} - -void CGLContextEGL::Destroy() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(m_eglDisplay, m_eglContext); - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - m_eglContext = EGL_NO_CONTEXT; - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } - - if (m_eglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(m_eglDisplay); - m_eglDisplay = EGL_NO_DISPLAY; - } -} - -void CGLContextEGL::Detach() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } -} - -bool CGLContextEGL::SetVSync(bool enable) -{ - if (!eglSwapInterval(m_eglDisplay, enable)) - { - return false; - } - - return true; -} - -void CGLContextEGL::SwapBuffers() -{ - if (m_eglDisplay == EGL_NO_DISPLAY || m_eglSurface == EGL_NO_SURFACE) - { - return; - } - - eglSwapBuffers(m_eglDisplay, m_eglSurface); -} diff --git a/xbmc/windowing/amlogic/GLContextEGL.h b/xbmc/windowing/amlogic/GLContextEGL.h deleted file mode 100644 index 9370684d57..0000000000 --- a/xbmc/windowing/amlogic/GLContextEGL.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#pragma once - -#include "EGL/egl.h" - -class CGLContextEGL -{ -public: - CGLContextEGL(); - virtual ~CGLContextEGL(); - - bool CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api); - - bool CreateSurface(EGLNativeWindowType surface); - bool CreateContext(); - bool BindContext(); - bool SurfaceAttrib(); - void Destroy(); - void Detach(); - bool SetVSync(bool enable); - void SwapBuffers(); - - EGLDisplay m_eglDisplay; - EGLSurface m_eglSurface; - EGLContext m_eglContext; - EGLConfig m_eglConfig; -}; diff --git a/xbmc/windowing/amlogic/WinSystemAmlogicGLESContext.h b/xbmc/windowing/amlogic/WinSystemAmlogicGLESContext.h index 3647c71af0..99dbf035a5 100644 --- a/xbmc/windowing/amlogic/WinSystemAmlogicGLESContext.h +++ b/xbmc/windowing/amlogic/WinSystemAmlogicGLESContext.h @@ -20,7 +20,7 @@ #pragma once -#include "GLContextEGL.h" +#include "utils/EGLUtils.h" #include "rendering/gles/RenderSystemGLES.h" #include "utils/GlobalsHandling.h" #include "WinSystemAmlogic.h" @@ -50,7 +50,7 @@ protected: void PresentRenderImpl(bool rendered) override; private: - CGLContextEGL m_pGLContext; + CEGLContextUtils m_pGLContext; }; -- cgit v1.2.3 From 772f5b2b37441a2e1d6ef46667074e84d607e4ed Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: windowing/android: use EGLUtils --- xbmc/windowing/android/CMakeLists.txt | 6 +- xbmc/windowing/android/GLContextEGL.cpp | 229 --------------------- xbmc/windowing/android/GLContextEGL.h | 48 ----- .../android/WinSystemAndroidGLESContext.h | 4 +- 4 files changed, 4 insertions(+), 283 deletions(-) delete mode 100644 xbmc/windowing/android/GLContextEGL.cpp delete mode 100644 xbmc/windowing/android/GLContextEGL.h diff --git a/xbmc/windowing/android/CMakeLists.txt b/xbmc/windowing/android/CMakeLists.txt index 5d248630a3..a10c9e4980 100644 --- a/xbmc/windowing/android/CMakeLists.txt +++ b/xbmc/windowing/android/CMakeLists.txt @@ -1,11 +1,9 @@ -set(SOURCES GLContextEGL.cpp - WinEventsAndroid.cpp +set(SOURCES WinEventsAndroid.cpp WinSystemAndroid.cpp AndroidUtils.cpp VideoSyncAndroid.cpp) -set(HEADERS GLContextEGL.h - WinEventsAndroid.h +set(HEADERS WinEventsAndroid.h WinSystemAndroid.h AndroidUtils.h VideoSyncAndroid.h) diff --git a/xbmc/windowing/android/GLContextEGL.cpp b/xbmc/windowing/android/GLContextEGL.cpp deleted file mode 100644 index 91d19465d0..0000000000 --- a/xbmc/windowing/android/GLContextEGL.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "GLContextEGL.h" - -#include "guilib/IDirtyRegionSolver.h" -#include "settings/AdvancedSettings.h" -#include "utils/log.h" - -CGLContextEGL::CGLContextEGL() : - m_eglDisplay(EGL_NO_DISPLAY), - m_eglSurface(EGL_NO_SURFACE), - m_eglContext(EGL_NO_CONTEXT), - m_eglConfig(0) -{ -} - -CGLContextEGL::~CGLContextEGL() -{ - Destroy(); -} - -bool CGLContextEGL::CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api) -{ - EGLint neglconfigs = 0; - int major, minor; - - EGLint surface_type = EGL_WINDOW_BIT; - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; - - EGLint attribs[] = - { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 0, - EGL_SAMPLE_BUFFERS, 0, - EGL_SAMPLES, 0, - EGL_SURFACE_TYPE, surface_type, - EGL_RENDERABLE_TYPE, renderable_type, - EGL_NONE - }; - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display); - } - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - CLog::Log(LOGERROR, "failed to get EGL display"); - return false; - } - - if (!eglInitialize(m_eglDisplay, &major, &minor)) - { - CLog::Log(LOGERROR, "failed to initialize EGL display"); - return false; - } - - eglBindAPI(rendering_api); - - if (!eglChooseConfig(m_eglDisplay, attribs, - &m_eglConfig, 1, &neglconfigs)) - { - CLog::Log(LOGERROR, "Failed to query number of EGL configs"); - return false; - } - - if (neglconfigs <= 0) - { - CLog::Log(LOGERROR, "No suitable EGL configs found"); - return false; - } - - return true; -} - -bool CGLContextEGL::CreateContext() -{ - int client_version = 2; - - const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE - }; - - if (m_eglContext == EGL_NO_CONTEXT) - { - m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, - EGL_NO_CONTEXT, context_attribs); - } - - if (m_eglContext == EGL_NO_CONTEXT) - { - CLog::Log(LOGERROR, "failed to create EGL context"); - return false; - } - - return true; -} - -bool CGLContextEGL::BindContext() -{ - if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, - m_eglSurface, m_eglContext)) - { - CLog::Log(LOGERROR, "Failed to make context current %p %p %p", - m_eglDisplay, m_eglSurface, m_eglContext); - return false; - } - - return true; -} - -bool CGLContextEGL::SurfaceAttrib() -{ - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - { - if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE)) - { - return false; - } - - if (!eglSurfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) - { - CLog::Log(LOGDEBUG, "%s: Could not set EGL_SWAP_BEHAVIOR",__FUNCTION__); - } - } - - return true; -} - -bool CGLContextEGL::CreateSurface(EGLNativeWindowType surface) -{ - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, - m_eglConfig, - surface, - nullptr); - - if (m_eglSurface == EGL_NO_SURFACE) - { - CLog::Log(LOGERROR, "failed to create EGL window surface %d", eglGetError()); - return false; - } - - return true; -} - -void CGLContextEGL::Destroy() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(m_eglDisplay, m_eglContext); - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - m_eglContext = EGL_NO_CONTEXT; - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } - - if (m_eglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(m_eglDisplay); - m_eglDisplay = EGL_NO_DISPLAY; - } -} - -void CGLContextEGL::Detach() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } -} - -bool CGLContextEGL::SetVSync(bool enable) -{ - if (!eglSwapInterval(m_eglDisplay, enable)) - { - return false; - } - - return true; -} - -void CGLContextEGL::SwapBuffers() -{ - if (m_eglDisplay == EGL_NO_DISPLAY || m_eglSurface == EGL_NO_SURFACE) - { - return; - } - - eglSwapBuffers(m_eglDisplay, m_eglSurface); -} diff --git a/xbmc/windowing/android/GLContextEGL.h b/xbmc/windowing/android/GLContextEGL.h deleted file mode 100644 index 9370684d57..0000000000 --- a/xbmc/windowing/android/GLContextEGL.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#pragma once - -#include "EGL/egl.h" - -class CGLContextEGL -{ -public: - CGLContextEGL(); - virtual ~CGLContextEGL(); - - bool CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api); - - bool CreateSurface(EGLNativeWindowType surface); - bool CreateContext(); - bool BindContext(); - bool SurfaceAttrib(); - void Destroy(); - void Detach(); - bool SetVSync(bool enable); - void SwapBuffers(); - - EGLDisplay m_eglDisplay; - EGLSurface m_eglSurface; - EGLContext m_eglContext; - EGLConfig m_eglConfig; -}; diff --git a/xbmc/windowing/android/WinSystemAndroidGLESContext.h b/xbmc/windowing/android/WinSystemAndroidGLESContext.h index ad38b584be..629b675097 100644 --- a/xbmc/windowing/android/WinSystemAndroidGLESContext.h +++ b/xbmc/windowing/android/WinSystemAndroidGLESContext.h @@ -20,7 +20,7 @@ #pragma once -#include "GLContextEGL.h" +#include "utils/EGLUtils.h" #include "rendering/gles/RenderSystemGLES.h" #include "utils/GlobalsHandling.h" #include "WinSystemAndroid.h" @@ -50,7 +50,7 @@ protected: void PresentRenderImpl(bool rendered) override; private: - CGLContextEGL m_pGLContext; + CEGLContextUtils m_pGLContext; }; -- cgit v1.2.3 From 32cc8ac18a71fa7decf2fad9eca6cef687d91553 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: windowing/rpi: use EGLUtils --- xbmc/windowing/rpi/CMakeLists.txt | 6 +- xbmc/windowing/rpi/GLContextEGL.cpp | 229 --------------------------- xbmc/windowing/rpi/GLContextEGL.h | 48 ------ xbmc/windowing/rpi/WinSystemRpiGLESContext.h | 4 +- 4 files changed, 4 insertions(+), 283 deletions(-) delete mode 100644 xbmc/windowing/rpi/GLContextEGL.cpp delete mode 100644 xbmc/windowing/rpi/GLContextEGL.h diff --git a/xbmc/windowing/rpi/CMakeLists.txt b/xbmc/windowing/rpi/CMakeLists.txt index f19dd6c0e4..f42c6419fc 100644 --- a/xbmc/windowing/rpi/CMakeLists.txt +++ b/xbmc/windowing/rpi/CMakeLists.txt @@ -1,10 +1,8 @@ -set(SOURCES GLContextEGL.cpp - WinSystemRpi.cpp +set(SOURCES WinSystemRpi.cpp RPIUtils.cpp VideoSyncPi.cpp) -set(HEADERS GLContextEGL.h - WinSystemRpi.h +set(HEADERS WinSystemRpi.h RPIUtils.h VideoSyncPi.h) diff --git a/xbmc/windowing/rpi/GLContextEGL.cpp b/xbmc/windowing/rpi/GLContextEGL.cpp deleted file mode 100644 index 91d19465d0..0000000000 --- a/xbmc/windowing/rpi/GLContextEGL.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "GLContextEGL.h" - -#include "guilib/IDirtyRegionSolver.h" -#include "settings/AdvancedSettings.h" -#include "utils/log.h" - -CGLContextEGL::CGLContextEGL() : - m_eglDisplay(EGL_NO_DISPLAY), - m_eglSurface(EGL_NO_SURFACE), - m_eglContext(EGL_NO_CONTEXT), - m_eglConfig(0) -{ -} - -CGLContextEGL::~CGLContextEGL() -{ - Destroy(); -} - -bool CGLContextEGL::CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api) -{ - EGLint neglconfigs = 0; - int major, minor; - - EGLint surface_type = EGL_WINDOW_BIT; - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; - - EGLint attribs[] = - { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 0, - EGL_SAMPLE_BUFFERS, 0, - EGL_SAMPLES, 0, - EGL_SURFACE_TYPE, surface_type, - EGL_RENDERABLE_TYPE, renderable_type, - EGL_NONE - }; - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display); - } - - if (m_eglDisplay == EGL_NO_DISPLAY) - { - CLog::Log(LOGERROR, "failed to get EGL display"); - return false; - } - - if (!eglInitialize(m_eglDisplay, &major, &minor)) - { - CLog::Log(LOGERROR, "failed to initialize EGL display"); - return false; - } - - eglBindAPI(rendering_api); - - if (!eglChooseConfig(m_eglDisplay, attribs, - &m_eglConfig, 1, &neglconfigs)) - { - CLog::Log(LOGERROR, "Failed to query number of EGL configs"); - return false; - } - - if (neglconfigs <= 0) - { - CLog::Log(LOGERROR, "No suitable EGL configs found"); - return false; - } - - return true; -} - -bool CGLContextEGL::CreateContext() -{ - int client_version = 2; - - const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE - }; - - if (m_eglContext == EGL_NO_CONTEXT) - { - m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, - EGL_NO_CONTEXT, context_attribs); - } - - if (m_eglContext == EGL_NO_CONTEXT) - { - CLog::Log(LOGERROR, "failed to create EGL context"); - return false; - } - - return true; -} - -bool CGLContextEGL::BindContext() -{ - if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, - m_eglSurface, m_eglContext)) - { - CLog::Log(LOGERROR, "Failed to make context current %p %p %p", - m_eglDisplay, m_eglSurface, m_eglContext); - return false; - } - - return true; -} - -bool CGLContextEGL::SurfaceAttrib() -{ - // for the non-trivial dirty region modes, we need the EGL buffer to be preserved across updates - if (g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_COST_REDUCTION || - g_advancedSettings.m_guiAlgorithmDirtyRegions == DIRTYREGION_SOLVER_UNION) - { - if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE)) - { - return false; - } - - if (!eglSurfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) - { - CLog::Log(LOGDEBUG, "%s: Could not set EGL_SWAP_BEHAVIOR",__FUNCTION__); - } - } - - return true; -} - -bool CGLContextEGL::CreateSurface(EGLNativeWindowType surface) -{ - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, - m_eglConfig, - surface, - nullptr); - - if (m_eglSurface == EGL_NO_SURFACE) - { - CLog::Log(LOGERROR, "failed to create EGL window surface %d", eglGetError()); - return false; - } - - return true; -} - -void CGLContextEGL::Destroy() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(m_eglDisplay, m_eglContext); - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - m_eglContext = EGL_NO_CONTEXT; - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } - - if (m_eglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(m_eglDisplay); - m_eglDisplay = EGL_NO_DISPLAY; - } -} - -void CGLContextEGL::Detach() -{ - if (m_eglContext != EGL_NO_CONTEXT) - { - eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - } - - if (m_eglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(m_eglDisplay, m_eglSurface); - m_eglSurface = EGL_NO_SURFACE; - } -} - -bool CGLContextEGL::SetVSync(bool enable) -{ - if (!eglSwapInterval(m_eglDisplay, enable)) - { - return false; - } - - return true; -} - -void CGLContextEGL::SwapBuffers() -{ - if (m_eglDisplay == EGL_NO_DISPLAY || m_eglSurface == EGL_NO_SURFACE) - { - return; - } - - eglSwapBuffers(m_eglDisplay, m_eglSurface); -} diff --git a/xbmc/windowing/rpi/GLContextEGL.h b/xbmc/windowing/rpi/GLContextEGL.h deleted file mode 100644 index 9370684d57..0000000000 --- a/xbmc/windowing/rpi/GLContextEGL.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#pragma once - -#include "EGL/egl.h" - -class CGLContextEGL -{ -public: - CGLContextEGL(); - virtual ~CGLContextEGL(); - - bool CreateDisplay(EGLDisplay display, - EGLint renderable_type, - EGLint rendering_api); - - bool CreateSurface(EGLNativeWindowType surface); - bool CreateContext(); - bool BindContext(); - bool SurfaceAttrib(); - void Destroy(); - void Detach(); - bool SetVSync(bool enable); - void SwapBuffers(); - - EGLDisplay m_eglDisplay; - EGLSurface m_eglSurface; - EGLContext m_eglContext; - EGLConfig m_eglConfig; -}; diff --git a/xbmc/windowing/rpi/WinSystemRpiGLESContext.h b/xbmc/windowing/rpi/WinSystemRpiGLESContext.h index df66c024c1..a06b89281e 100644 --- a/xbmc/windowing/rpi/WinSystemRpiGLESContext.h +++ b/xbmc/windowing/rpi/WinSystemRpiGLESContext.h @@ -20,7 +20,7 @@ #pragma once -#include "GLContextEGL.h" +#include "utils/EGLUtils.h" #include "rendering/gles/RenderSystemGLES.h" #include "WinSystemRpi.h" @@ -49,6 +49,6 @@ protected: void PresentRenderImpl(bool rendered) override; private: - CGLContextEGL m_pGLContext; + CEGLContextUtils m_pGLContext; }; -- cgit v1.2.3 From d5f4f3760bb7926c36fbc0941ab27b6930794e3e Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 22 Mar 2018 13:58:56 -0700 Subject: EGLUtils: return nothing if eglQueryString returns null --- xbmc/utils/EGLUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xbmc/utils/EGLUtils.cpp b/xbmc/utils/EGLUtils.cpp index 23ff11233c..f1785c05fd 100644 --- a/xbmc/utils/EGLUtils.cpp +++ b/xbmc/utils/EGLUtils.cpp @@ -32,7 +32,7 @@ std::set CEGLUtils::GetClientExtensions() const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); if (!extensions) { - throw std::runtime_error("Could not query EGL for client extensions, maybe EGL_EXT_client_extensions is not supported?"); + return {}; } std::set result; StringUtils::SplitTo(std::inserter(result, result.begin()), extensions, " "); -- cgit v1.2.3