Skip to content

Commit

Permalink
steamcompmgr, rc, commit: introduce make_rc() function + use it to cl…
Browse files Browse the repository at this point in the history
…eanup import_commit()
  • Loading branch information
sharkautarch committed Sep 4, 2024
1 parent 2d687e8 commit 6861af3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 40 deletions.
23 changes: 21 additions & 2 deletions src/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@

extern gamescope::CAsyncWaiter<gamescope::Rc<commit_t>> g_ImageWaiter;

uint64_t commit_t::getCommitID()
{
static uint64_t maxCommmitID = 1;
return maxCommmitID++;
}

commit_t::commit_t()
{
static uint64_t maxCommmitID = 0;
commitID = ++maxCommmitID;
commitID = getCommitID();;
}

commit_t::commit_t(std::in_place_t tag, uint64_t seq, ResListEntry_t& reslistentry, bool is_steam)
: RcObject(tag), buf(reslistentry.buf),
async(reslistentry.async), fifo(reslistentry.fifo),
is_steam(is_steam),
feedback(reslistentry.feedback ? std::optional<wlserver_vk_swapchain_feedback>(std::in_place_t{}, *reslistentry.feedback) : std::nullopt),
win_seq(seq), surf(reslistentry.surf),
presentation_feedbacks(std::move(reslistentry.presentation_feedbacks)),
present_id(reslistentry.present_id),
desired_present_time(reslistentry.desired_present_time)
{
commitID = getCommitID();
}

commit_t::~commit_t()
{
{
Expand Down
8 changes: 7 additions & 1 deletion src/commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ struct UpscaledTexture_t

struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable, public gamescope::NonCopyable
{
protected:
ENABLE_IN_PLACE_RC
commit_t(std::in_place_t tag, uint64_t seq, ResListEntry_t& reslistentry, bool is_stream);

uint64_t getCommitID();
public:
commit_t();
~commit_t();
~commit_t();

GamescopeAppTextureColorspace colorspace() const;

Expand Down
29 changes: 28 additions & 1 deletion src/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

#include <cstdint>
#include <atomic>
#include <utility>

namespace gamescope
{
template <typename T, bool Public>
class Rc;
#define ENABLE_IN_PLACE_RC using gamescope::RcObject::RcObject; \
template <class T, class... Args> \
friend gamescope::Rc<T, true> gamescope::make_rc(Args&&... args);
class RcObject
{
template <class T, class... Args>
friend gamescope::Rc<T, true> make_rc(Args&&... args);
protected:
constexpr RcObject(std::in_place_t) : m_uRefCount{1}, m_uRefPrivate{1} {}
public:
RcObject() = default;
virtual ~RcObject()
{
}
Expand Down Expand Up @@ -67,6 +78,7 @@ namespace gamescope

class IRcObject : public RcObject
{
using RcObject::RcObject;
public:
virtual uint32_t IncRef()
{
Expand All @@ -93,15 +105,30 @@ namespace gamescope
static void DecRef( T* pObject ) { pObject->DecRefPrivate(); }
};

template <class T, class... Args>
Rc<T, true> make_rc(Args&&... args) {
T* pObj = new T(std::in_place_t{}, std::forward<Args>(args)...);
return Rc<T, true>{std::in_place_t{}, pObj};
}

template <typename T, bool Public = true>
class Rc
{
template <typename Tx, bool Publicx>
friend class Rc;

template <class Tx, class... Args>
friend Rc<Tx, true> gamescope::make_rc(Args&&... args);

using RcRef = RcRef_<T, Public>;

protected:
constexpr Rc( std::in_place_t tag, T* pObject )
: m_pObject{ pObject } {} //no IncRef here, because this constructor is used w/ in-place RcObject construction via friend function make_rc()
//this is locked behind protected access, to avoid any unintended use

public:
Rc() { }
constexpr Rc() { }
Rc( std::nullptr_t ) { }

Rc( T* pObject )
Expand Down
43 changes: 7 additions & 36 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,33 +1169,11 @@ static steamcompmgr_win_t * find_win( xwayland_ctx_t *ctx, struct wlr_surface *s

static gamescope::CBufferMemoizer s_BufferMemos;

// This really needs cleanup, this function is so silly...
static gamescope::Rc<commit_t>
import_commit (
steamcompmgr_win_t *w,
struct wlr_surface *surf,
struct wlr_buffer *buf,
bool async,
std::shared_ptr<wlserver_vk_swapchain_feedback> swapchain_feedback,
std::vector<struct wl_resource*> presentation_feedbacks,
std::optional<uint32_t> present_id,
uint64_t desired_present_time,
bool fifo )
{
gamescope::Rc<commit_t> commit = new commit_t;

commit->win_seq = w->seq;
commit->surf = surf;
commit->buf = buf;
commit->async = async;
commit->fifo = fifo;
commit->is_steam = window_is_steam( w );
commit->presentation_feedbacks = std::move(presentation_feedbacks);
if (swapchain_feedback)
commit->feedback = *swapchain_feedback;
commit->present_id = present_id;
commit->desired_present_time = desired_present_time;
static gamescope::Rc<commit_t> import_commit(steamcompmgr_win_t *w, ResListEntry_t& reslistentry)
{
gamescope::Rc<commit_t> commit = gamescope::make_rc<commit_t>(w->seq, reslistentry, window_is_steam( w ));

auto*& buf = reslistentry.buf;
if ( gamescope::OwningRc<CVulkanTexture> pTexture = s_BufferMemos.LookupVulkanTexture( buf ) )
{
// Going from OwningRc -> Rc now.
Expand Down Expand Up @@ -5686,6 +5664,7 @@ handle_property_notify(xwayland_ctx_t *ctx, XPropertyEvent *ev)
win = nullptr;
};

#pragma GCC unroll 8
for (std::reference_wrapper<steamcompmgr_win_t *> win
: (std::reference_wrapper<steamcompmgr_win_t*>[])
{
Expand Down Expand Up @@ -6245,16 +6224,7 @@ void update_wayland_res(CommitDoneList_t *doneCommits, steamcompmgr_win_t *w, Re
return;
}

gamescope::Rc<commit_t> newCommit = import_commit(
w,
reslistentry.surf,
buf,
reslistentry.async,
std::move(reslistentry.feedback),
std::move(reslistentry.presentation_feedbacks),
reslistentry.present_id,
reslistentry.desired_present_time,
reslistentry.fifo );
gamescope::Rc<commit_t> newCommit = import_commit(w, reslistentry);

int fence = -1;
if ( newCommit != nullptr )
Expand Down Expand Up @@ -7047,6 +7017,7 @@ void steamcompmgr_check_xdg(bool vblank, uint64_t vblank_idx)
w = nullptr;
};

#pragma GCC unroll 6
for (std::reference_wrapper<steamcompmgr_win_t *> focusWin
: (std::reference_wrapper<steamcompmgr_win_t*>[])
{
Expand Down

0 comments on commit 6861af3

Please sign in to comment.