Skip to content

Commit

Permalink
Merge pull request xbmc#17544 from lrusak/wayland-dma
Browse files Browse the repository at this point in the history
[RetroPlayer] allow using wayland with CRPRendererDMA
  • Loading branch information
lrusak authored and Maven85 committed Aug 5, 2020
1 parent 6ba927b commit 4b37099
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion xbmc/cores/RetroPlayer/buffers/CMakeLists.txt
Expand Up @@ -24,7 +24,7 @@ if(OPENGL_FOUND)
RenderBufferPoolOpenGL.cpp)
endif()

if(CORE_PLATFORM_NAME_LC STREQUAL gbm AND OPENGLES_FOUND)
if(CORE_PLATFORM_NAME_LC STREQUAL gbm OR CORE_PLATFORM_NAME_LC STREQUAL wayland)
list(APPEND SOURCES RenderBufferDMA.cpp
RenderBufferPoolDMA.cpp)
list(APPEND HEADERS RenderBufferDMA.h
Expand Down
15 changes: 11 additions & 4 deletions xbmc/cores/RetroPlayer/buffers/RenderBufferDMA.cpp
Expand Up @@ -11,19 +11,26 @@
#include "ServiceBroker.h"
#include "utils/BufferObject.h"
#include "utils/EGLImage.h"
#include "windowing/gbm/WinSystemGbmEGLContext.h"
#include "windowing/WinSystem.h"
#include "windowing/linux/WinSystemEGL.h"

using namespace KODI::WINDOWING::GBM;
using namespace KODI;
using namespace RETRO;

CRenderBufferDMA::CRenderBufferDMA(CRenderContext& context, int fourcc)
: m_context(context),
m_fourcc(fourcc),
m_egl(new CEGLImage(
static_cast<CWinSystemGbmEGLContext*>(CServiceBroker::GetWinSystem())->GetEGLDisplay())),
m_bo(CBufferObject::GetBufferObject())
{
auto winSystemEGL =
dynamic_cast<KODI::WINDOWING::LINUX::CWinSystemEGL*>(CServiceBroker::GetWinSystem());

if (winSystemEGL == nullptr)
throw std::runtime_error("dynamic_cast failed to cast to CWinSystemEGL. This is likely due to "
"a build misconfiguration as DMA can only be used with EGL and "
"specifically platforms that implement CWinSystemEGL");

m_egl = std::make_unique<CEGLImage>(winSystemEGL->GetEGLDisplay());
}

CRenderBufferDMA::~CRenderBufferDMA()
Expand Down
Expand Up @@ -18,7 +18,7 @@ if(OPENGL_FOUND)
list(APPEND HEADERS RPRendererOpenGL.h)
endif()

if(CORE_PLATFORM_NAME_LC STREQUAL gbm AND OPENGLES_FOUND)
if(CORE_PLATFORM_NAME_LC STREQUAL gbm OR CORE_PLATFORM_NAME_LC STREQUAL wayland)
list(APPEND SOURCES RPRendererDMA.cpp)
list(APPEND HEADERS RPRendererDMA.h)
endif()
Expand Down
Expand Up @@ -12,6 +12,7 @@
#include "cores/RetroPlayer/buffers/RenderBufferPoolDMA.h"
#include "cores/RetroPlayer/rendering/RenderContext.h"
#include "cores/RetroPlayer/rendering/RenderVideoSettings.h"
#include "utils/BufferObjectFactory.h"
#include "utils/GLUtils.h"

#include <cassert>
Expand All @@ -34,6 +35,9 @@ CRPBaseRenderer* CRendererFactoryDMA::CreateRenderer(const CRenderSettings& sett

RenderBufferPoolVector CRendererFactoryDMA::CreateBufferPools(CRenderContext& context)
{
if (!CBufferObjectFactory::CreateBufferObject())
return {};

return {std::make_shared<CRenderBufferPoolDMA>(context)};
}

Expand Down
Expand Up @@ -19,6 +19,8 @@ namespace RETRO
class CRendererFactoryDMA : public IRendererFactory
{
public:
~CRendererFactoryDMA() override = default;

// implementation of IRendererFactory
std::string RenderSystemName() const override;
CRPBaseRenderer* CreateRenderer(const CRenderSettings& settings,
Expand Down
11 changes: 8 additions & 3 deletions xbmc/utils/BufferObjectFactory.cpp
Expand Up @@ -8,17 +8,22 @@

#include "BufferObjectFactory.h"

std::vector<std::function<std::unique_ptr<CBufferObject>()>> CBufferObjectFactory::m_bufferObjects;
std::list<std::function<std::unique_ptr<CBufferObject>()>> CBufferObjectFactory::m_bufferObjects;

std::unique_ptr<CBufferObject> CBufferObjectFactory::CreateBufferObject()
{
return m_bufferObjects.back()();
for (const auto bufferObject : m_bufferObjects)
{
return bufferObject();
}

return nullptr;
}

void CBufferObjectFactory::RegisterBufferObject(
std::function<std::unique_ptr<CBufferObject>()> createFunc)
{
m_bufferObjects.emplace_back(createFunc);
m_bufferObjects.emplace_front(createFunc);
}

void CBufferObjectFactory::ClearBufferObjects()
Expand Down
4 changes: 2 additions & 2 deletions xbmc/utils/BufferObjectFactory.h
Expand Up @@ -11,8 +11,8 @@
#include "BufferObject.h"

#include <functional>
#include <list>
#include <memory>
#include <vector>

/**
* @brief Factory that provides CBufferObject registration and creation
Expand Down Expand Up @@ -44,5 +44,5 @@ class CBufferObjectFactory
static void ClearBufferObjects();

protected:
static std::vector<std::function<std::unique_ptr<CBufferObject>()>> m_bufferObjects;
static std::list<std::function<std::unique_ptr<CBufferObject>()>> m_bufferObjects;
};
14 changes: 8 additions & 6 deletions xbmc/utils/CMakeLists.txt
Expand Up @@ -185,16 +185,18 @@ if(NOT CORE_SYSTEM_NAME STREQUAL windows AND NOT CORE_SYSTEM_NAME STREQUAL windo
list(APPEND HEADERS GLUtils.h)
endif()

if(CORE_PLATFORM_NAME_LC STREQUAL gbm)
list(APPEND SOURCES EGLImage.cpp)
list(APPEND HEADERS EGLImage.h)

if(CORE_PLATFORM_NAME_LC STREQUAL gbm OR CORE_PLATFORM_NAME_LC STREQUAL wayland)
list(APPEND SOURCES BufferObject.cpp
BufferObjectFactory.cpp
DumbBufferObject.cpp)
EGLImage.cpp)
list(APPEND HEADERS BufferObject.h
BufferObjectFactory.h
DumbBufferObject.h)
EGLImage.h)

if(CORE_PLATFORM_NAME_LC STREQUAL gbm)
list(APPEND SOURCES DumbBufferObject.cpp)
list(APPEND SOURCES DumbBufferObject.h)
endif()

if(HAVE_LINUX_MEMFD AND HAVE_LINUX_UDMABUF)
list(APPEND SOURCES UDMABufferObject.cpp)
Expand Down
14 changes: 14 additions & 0 deletions xbmc/windowing/wayland/WinSystemWaylandEGLContextGLES.cpp
Expand Up @@ -10,10 +10,14 @@

#include "OptionalsReg.h"
#include "cores/RetroPlayer/process/RPProcessInfo.h"
#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererDMA.h"
#include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGLES.h"
#include "cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
#include "rendering/gles/ScreenshotSurfaceGLES.h"
#include "utils/BufferObjectFactory.h"
#include "utils/DMAHeapBufferObject.h"
#include "utils/UDMABufferObject.h"
#include "utils/log.h"

#include <EGL/egl.h>
Expand All @@ -34,6 +38,8 @@ bool CWinSystemWaylandEGLContextGLES::InitWindowSystem()
}

CLinuxRendererGLES::Register();

RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryDMA);
RETRO::CRPProcessInfo::RegisterRendererFactory(new RETRO::CRendererFactoryOpenGLES);

bool general, deepColor;
Expand All @@ -46,6 +52,14 @@ bool CWinSystemWaylandEGLContextGLES::InitWindowSystem()
::WAYLAND::VAAPIRegister(m_vaapiProxy.get(), deepColor);
}

CBufferObjectFactory::ClearBufferObjects();
#if defined(HAVE_LINUX_MEMFD) && defined(HAVE_LINUX_UDMABUF)
CUDMABufferObject::Register();
#endif
#if defined(HAVE_LINUX_DMA_HEAP)
CDMAHeapBufferObject::Register();
#endif

CScreenshotSurfaceGLES::Register();

return true;
Expand Down

0 comments on commit 4b37099

Please sign in to comment.