Skip to content

Commit

Permalink
Merge pull request xbmc#17641 from lrusak/bufferobject-create-by-size
Browse files Browse the repository at this point in the history
IBufferObject: allow creating by size
  • Loading branch information
lrusak authored and Maven85 committed Apr 17, 2020
1 parent b71412f commit 87f76e8
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion xbmc/cores/RetroPlayer/buffers/RenderBufferDMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace RETRO;
CRenderBufferDMA::CRenderBufferDMA(CRenderContext& context, int fourcc)
: m_context(context),
m_fourcc(fourcc),
m_bo(CBufferObject::GetBufferObject())
m_bo(CBufferObject::GetBufferObject(false))
{
auto winSystemEGL =
dynamic_cast<KODI::WINDOWING::LINUX::CWinSystemEGL*>(CServiceBroker::GetWinSystem());
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/RetroPlayer/buffers/RenderBufferDMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "system_gl.h"

class CEGLImage;
class CBufferObject;
class IBufferObject;

namespace KODI
{
Expand Down Expand Up @@ -60,7 +60,7 @@ namespace RETRO
void DeleteTexture();

std::unique_ptr<CEGLImage> m_egl;
std::unique_ptr<CBufferObject> m_bo;
std::unique_ptr<IBufferObject> m_bo;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CRPBaseRenderer* CRendererFactoryDMA::CreateRenderer(const CRenderSettings& sett

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

return {std::make_shared<CRenderBufferPoolDMA>(context)};
Expand Down
4 changes: 2 additions & 2 deletions xbmc/utils/BufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <sys/ioctl.h>
#endif

std::unique_ptr<CBufferObject> CBufferObject::GetBufferObject()
std::unique_ptr<CBufferObject> CBufferObject::GetBufferObject(bool needsCreateBySize)
{
return CBufferObjectFactory::CreateBufferObject();
return CBufferObjectFactory::CreateBufferObject(needsCreateBySize);
}

int CBufferObject::GetFd()
Expand Down
4 changes: 3 additions & 1 deletion xbmc/utils/BufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class CBufferObject : public IBufferObject
*
* @return std::unique_ptr<CBufferObject>
*/
static std::unique_ptr<CBufferObject> GetBufferObject();
static std::unique_ptr<CBufferObject> GetBufferObject(bool needsCreateBySize);

virtual bool CreateBufferObject(uint64_t size) override { return false; }

virtual int GetFd() override;
virtual uint32_t GetStride() override;
Expand Down
14 changes: 12 additions & 2 deletions xbmc/utils/BufferObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@

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

std::unique_ptr<CBufferObject> CBufferObjectFactory::CreateBufferObject()
std::unique_ptr<CBufferObject> CBufferObjectFactory::CreateBufferObject(bool needsCreateBySize)
{
for (const auto bufferObject : m_bufferObjects)
{
return bufferObject();
auto bo = bufferObject();

if (needsCreateBySize)
{
if (!bo->CreateBufferObject(1))
continue;

bo->DestroyBufferObject();
}

return bo;
}

return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/utils/BufferObjectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CBufferObjectFactory
*
* @return std::unique_ptr<CBufferObject>
*/
static std::unique_ptr<CBufferObject> CreateBufferObject();
static std::unique_ptr<CBufferObject> CreateBufferObject(bool needsCreateBySize);

/**
* @brief Registers a CBufferObject class to class to the factory.
Expand Down
8 changes: 7 additions & 1 deletion xbmc/utils/DMAHeapBufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ bool CDMAHeapBufferObject::CreateBufferObject(uint32_t format, uint32_t width, u
throw std::runtime_error("CDMAHeapBufferObject: pixel format not implemented");
}

m_size = width * height * bpp;
m_stride = width * bpp;

return CreateBufferObject(width * height * bpp);
}

bool CDMAHeapBufferObject::CreateBufferObject(uint64_t size)
{
m_size = size;

if (m_dmaheapfd < 0)
{
m_dmaheapfd = open(DMA_HEAP_PATH, O_RDWR);
Expand Down
1 change: 1 addition & 0 deletions xbmc/utils/DMAHeapBufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CDMAHeapBufferObject : public CBufferObject

// IBufferObject overrides via CBufferObject
bool CreateBufferObject(uint32_t format, uint32_t width, uint32_t height) override;
bool CreateBufferObject(uint64_t size) override;
void DestroyBufferObject() override;
uint8_t* GetMemory() override;
void ReleaseMemory() override;
Expand Down
17 changes: 14 additions & 3 deletions xbmc/utils/IBufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,28 @@ class IBufferObject
virtual ~IBufferObject() = default;

/**
* @brief Create a BufferObject.
* @brief Create a BufferObject based on the format, width, and height of the desired buffer
*
* @param format framebuffer pixel formats are described using the fourcc codes defined in
* https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_fourcc.h
* @param width width of the requested buffer object.
* @param height height of the requested buffer object.
* @param width width of the requested buffer.
* @param height height of the requested buffer.
* @return true BufferObject creation was successful.
* @return false BufferObject creation was unsuccessful.
*/
virtual bool CreateBufferObject(uint32_t format, uint32_t width, uint32_t height) = 0;

/**
* @brief Create a BufferObject based only on the size of the desired buffer. Not all
* CBufferObject implementations may support this. This method is required for
* use with the CAddonVideoCodec as it only knows the decoded buffer size.
*
* @param size of the requested buffer.
* @return true BufferObject creation was successful.
* @return false BufferObject creation was unsuccessful.
*/
virtual bool CreateBufferObject(uint64_t size) = 0;

/**
* @brief Destroy a BufferObject.
*
Expand Down
10 changes: 8 additions & 2 deletions xbmc/utils/UDMABufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ bool CUDMABufferObject::CreateBufferObject(uint32_t format, uint32_t width, uint
throw std::runtime_error("CUDMABufferObject: pixel format not implemented");
}

// Must be rounded to the system page size
m_size = RoundUp(width * height * bpp, PAGESIZE);
m_stride = width * bpp;

return CreateBufferObject(width * height * bpp);
}

bool CUDMABufferObject::CreateBufferObject(uint64_t size)
{
// Must be rounded to the system page size
m_size = RoundUp(size, PAGESIZE);

m_memfd = memfd_create("kodi", MFD_CLOEXEC | MFD_ALLOW_SEALING);
if (m_memfd < 0)
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/utils/UDMABufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CUDMABufferObject : public CBufferObject

// IBufferObject overrides via CBufferObject
bool CreateBufferObject(uint32_t format, uint32_t width, uint32_t height) override;
bool CreateBufferObject(uint64_t size) override;
void DestroyBufferObject() override;
uint8_t* GetMemory() override;
void ReleaseMemory() override;
Expand Down

0 comments on commit 87f76e8

Please sign in to comment.