| 1 |
/* |
| 2 |
* Copyright (C) 2017-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 "WinSystemWaylandEGLContextGL.h" |
| 10 |
|
| 11 |
#include "OptionalsReg.h" |
| 12 |
#include "cores/RetroPlayer/process/RPProcessInfo.h" |
| 13 |
#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererDMA.h" |
| 14 |
#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.h" |
| 15 |
#include "cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h" |
| 16 |
#include "rendering/gl/ScreenshotSurfaceGL.h" |
| 17 |
#include "utils/BufferObjectFactory.h" |
| 18 |
#include "utils/DMAHeapBufferObject.h" |
| 19 |
#include "utils/UDMABufferObject.h" |
| 20 |
#include "utils/log.h" |
| 21 |
#include "windowing/WindowSystemFactory.h" |
| 22 |
|
| 23 |
#include <EGL/eglext.h> |
| 24 |
|
| 25 |
using namespace KODI::WINDOWING::WAYLAND; |
| 26 |
|
| 27 |
void CWinSystemWaylandEGLContextGL::Register() |
| 28 |
{ |
| 29 |
CWindowSystemFactory::RegisterWindowSystem(CreateWinSystem, "wayland"); |
| 30 |
} |
| 31 |
|
| 32 |
std::unique_ptr<CWinSystemBase> CWinSystemWaylandEGLContextGL::CreateWinSystem() |
| 33 |
{ |
| 34 |
return std::make_unique<CWinSystemWaylandEGLContextGL>(); |
| 35 |
} |
| 36 |
|
| 37 |
bool CWinSystemWaylandEGLContextGL::InitWindowSystem() |
| 38 |
{ |
| 39 |
if (!CWinSystemWaylandEGLContext::InitWindowSystemEGL(EGL_OPENGL_BIT, EGL_OPENGL_API)) |
| 40 |
{ |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
CLinuxRendererGL::Register(); |
| 45 |
RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryDMA); |
| 46 |
RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGL); |
| 47 |
|
| 48 |
bool general, deepColor; |
| 49 |
m_vaapiProxy.reset(WAYLAND::VaapiProxyCreate()); |
| 50 |
WAYLAND::VaapiProxyConfig(m_vaapiProxy.get(), GetConnection()->GetDisplay(), |
| 51 |
m_eglContext.GetEGLDisplay()); |
| 52 |
WAYLAND::VAAPIRegisterRenderGL(m_vaapiProxy.get(), general, deepColor); |
| 53 |
if (general) |
| 54 |
{ |
| 55 |
WAYLAND::VAAPIRegister(m_vaapiProxy.get(), deepColor); |
| 56 |
} |
| 57 |
|
| 58 |
CBufferObjectFactory::ClearBufferObjects(); |
| 59 |
#if defined(HAVE_LINUX_MEMFD) && defined(HAVE_LINUX_UDMABUF) |
| 60 |
CUDMABufferObject::Register(); |
| 61 |
#endif |
| 62 |
#if defined(HAVE_LINUX_DMA_HEAP) |
| 63 |
CDMAHeapBufferObject::Register(); |
| 64 |
#endif |
| 65 |
|
| 66 |
CScreenshotSurfaceGL::Register(); |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
bool CWinSystemWaylandEGLContextGL::CreateContext() |
| 72 |
{ |
| 73 |
const EGLint glMajor = 3; |
| 74 |
const EGLint glMinor = 2; |
| 75 |
|
| 76 |
CEGLAttributesVec contextAttribs; |
| 77 |
contextAttribs.Add({{EGL_CONTEXT_MAJOR_VERSION_KHR, glMajor}, |
| 78 |
{EGL_CONTEXT_MINOR_VERSION_KHR, glMinor}, |
| 79 |
{EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR}}); |
| 80 |
|
| 81 |
if (!m_eglContext.CreateContext(contextAttribs)) |
| 82 |
{ |
| 83 |
CEGLAttributesVec fallbackContextAttribs; |
| 84 |
fallbackContextAttribs.Add({{EGL_CONTEXT_CLIENT_VERSION, 2}}); |
| 85 |
|
| 86 |
if (!m_eglContext.CreateContext(fallbackContextAttribs)) |
| 87 |
{ |
| 88 |
CLog::Log(LOGERROR, "EGL context creation failed"); |
| 89 |
return false; |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
CLog::Log(LOGWARNING, "Your OpenGL drivers do not support OpenGL {}.{} core profile. Kodi will run in compatibility mode, but performance may suffer.", glMajor, glMinor); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
void CWinSystemWaylandEGLContextGL::SetContextSize(CSizeInt size) |
| 101 |
{ |
| 102 |
CWinSystemWaylandEGLContext::SetContextSize(size); |
| 103 |
|
| 104 |
// Propagate changed dimensions to render system if necessary |
| 105 |
if (CRenderSystemGL::m_width != size.Width() || CRenderSystemGL::m_height != size.Height()) |
| 106 |
{ |
| 107 |
CLog::LogF(LOGDEBUG, "Resetting render system to {}x{}", size.Width(), size.Height()); |
| 108 |
CRenderSystemGL::ResetRenderSystem(size.Width(), size.Height()); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
void CWinSystemWaylandEGLContextGL::SetVSyncImpl(bool enable) |
| 113 |
{ |
| 114 |
// Unsupported |
| 115 |
} |
| 116 |
|
| 117 |
void CWinSystemWaylandEGLContextGL::PresentRenderImpl(bool rendered) |
| 118 |
{ |
| 119 |
PresentFrame(rendered); |
| 120 |
} |
| 121 |
|
| 122 |
void CWinSystemWaylandEGLContextGL::delete_CVaapiProxy::operator()(CVaapiProxy *p) const |
| 123 |
{ |
| 124 |
WAYLAND::VaapiProxyDelete(p); |
| 125 |
} |