Skip to content

Commit

Permalink
all: Refactor to much nicer fb abstraction that is less absolutely te…
Browse files Browse the repository at this point in the history
…rrifying
  • Loading branch information
misyltoad committed Apr 3, 2024
1 parent 11533d3 commit 62ef16e
Show file tree
Hide file tree
Showing 11 changed files with 466 additions and 332 deletions.
43 changes: 43 additions & 0 deletions src/backend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "backend.h"
#include "vblankmanager.hpp"
#include "convar.h"
#include "wlserver.hpp"

#include "wlr_begin.hpp"
#include <wlr/types/wlr_buffer.h>
#include "wlr_end.hpp"

extern void sleep_until_nanos(uint64_t nanos);
extern bool env_to_bool(const char *env);
Expand Down Expand Up @@ -37,6 +42,44 @@ namespace gamescope
return true;
}

/////////////////
// CBaseBackendFb
/////////////////

CBaseBackendFb::CBaseBackendFb( wlr_buffer *pClientBuffer )
: m_pClientBuffer{ pClientBuffer }
{
}

CBaseBackendFb::~CBaseBackendFb()
{
// I do not own the client buffer, but I released that in DecRef.
m_pClientBuffer = nullptr;
}

uint32_t CBaseBackendFb::IncRef()
{
uint32_t uRefCount = IBackendFb::IncRef();
if ( m_pClientBuffer && uRefCount == 1 )
{
wlserver_lock();
wlr_buffer_lock( m_pClientBuffer );
wlserver_unlock( false );
}
return uRefCount;
}
uint32_t CBaseBackendFb::DecRef()
{
uint32_t uRefCount = IBackendFb::DecRef();
if ( m_pClientBuffer && uRefCount == 0 )
{
wlserver_lock();
wlr_buffer_unlock( m_pClientBuffer );
wlserver_unlock();
}
return uRefCount;
}

/////////////////
// CBaseBackend
/////////////////
Expand Down
27 changes: 23 additions & 4 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "gamescope_shared.h"
#include "vulkan_include.h"
#include "convar.h"
#include "rc.h"

#include <cassert>
#include <span>
Expand Down Expand Up @@ -141,6 +142,24 @@ namespace gamescope
std::atomic<uint64_t> m_uCompletedPresents = { 0u };
};

class IBackendFb : public IRcObject<false /* Reference does NOT own. The wlr_buffer import + notarizer owns the object*/ >
{
// Dummy
};

class CBaseBackendFb : public IBackendFb
{
public:
CBaseBackendFb( wlr_buffer *pClientBuffer );
virtual ~CBaseBackendFb();

uint32_t IncRef() override;
uint32_t DecRef() override;

private:
wlr_buffer *m_pClientBuffer = nullptr;
};

class IBackend
{
public:
Expand Down Expand Up @@ -169,10 +188,10 @@ namespace gamescope

// For DRM, this is
// dmabuf -> fb_id.
virtual uint32_t ImportDmabufToBackend( wlr_buffer *pBuffer, wlr_dmabuf_attributes *pDmaBuf ) = 0;
virtual void LockBackendFb( uint32_t uFbId ) = 0;
virtual void UnlockBackendFb( uint32_t uFbId ) = 0;
virtual void DropBackendFb( uint32_t uFbId ) = 0;
//
// shared_ptr owns the structure.
// Rc manages acquire/release of buffer to/from client while imported.
virtual std::shared_ptr<IBackendFb> ImportDmabufToBackend( wlr_buffer *pBuffer, wlr_dmabuf_attributes *pDmaBuf ) = 0;

virtual bool UsesModifiers() const = 0;
virtual std::span<const uint64_t> GetSupportedModifiers( uint32_t uDrmFormat ) const = 0;
Expand Down
Loading

0 comments on commit 62ef16e

Please sign in to comment.