Repository: hyprwm/Hyprland
File: src/protocols/DRMSyncobj.hpp (C++)

Code before:
#include <hyprutils/os/FileDescriptor.hpp>
#include <list>

class CWLSurfaceResource;
class CDRMSyncobjTimelineResource;
class CSyncTimeline;
struct SSurfaceState;

class CDRMSyncPointState {
  public:
    CDRMSyncPointState() = default;
    CDRMSyncPointState(SP<CDRMSyncobjTimelineResource> resource_, uint64_t point_);
    ~CDRMSyncPointState() = default;

    const uint64_t&                                  point();
    WP<CDRMSyncobjTimelineResource>                  resource();
    WP<CSyncTimeline>                                timeline();
    bool                                             expired();
    Hyprutils::Memory::CUniquePointer<CSyncReleaser> createSyncRelease();
    bool                                             addWaiter(const std::function<void()>& waiter);
    bool                                             comitted();
    Hyprutils::OS::CFileDescriptor                   exportAsFD();
    void                                             signal();

  private:
    SP<CDRMSyncobjTimelineResource> m_resource         = {};
    uint64_t                        m_point            = 0;
    bool                            m_acquireCommitted = false;
    bool                            m_releaseTaken     = false;
};

class CDRMSyncobjSurfaceResource {
  public:
    CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurfaceV1>&& resource_, SP<CWLSurfaceResource> surface_);
    ~CDRMSyncobjSurfaceResource();

    bool protocolError();
    bool good();

  private:
    void                            removeAllWaiters();
    WP<CWLSurfaceResource>          surface;
    UP<CWpLinuxDrmSyncobjSurfaceV1> resource;

    CDRMSyncPointState              pendingAcquire;
    CDRMSyncPointState              pendingRelease;
    std::vector<SP<SSurfaceState>>  pendingStates;

    struct {
        CHyprSignalListener surfacePrecommit;
    } listeners;

Review comment (suggestion):
I think we should just store an `SP<CSyncTimeline>` here instead of storing the resource. The only times we use the resource are to get the timeline.

Code after:
#include <hyprutils/os/FileDescriptor.hpp>
#include <list>

class CWLSurfaceResource;
class CDRMSyncobjTimelineResource;
class CSyncTimeline;
struct SSurfaceState;

class CDRMSyncPointState {
  public:
    CDRMSyncPointState() = default;
    CDRMSyncPointState(SP<CSyncTimeline> timeline_, uint64_t point_);
    ~CDRMSyncPointState() = default;

    const uint64_t&                                  point();
    WP<CSyncTimeline>                                timeline();
    Hyprutils::Memory::CUniquePointer<CSyncReleaser> createSyncRelease();
    bool                                             addWaiter(const std::function<void()>& waiter);
    bool                                             comitted();
    Hyprutils::OS::CFileDescriptor                   exportAsFD();
    void                                             signal();

  private:
    SP<CSyncTimeline> m_timeline         = {};
    uint64_t          m_point            = 0;
    bool              m_acquireCommitted = false;
    bool              m_releaseTaken     = false;
};

class CDRMSyncobjSurfaceResource {
  public:
    CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurfaceV1>&& resource_, SP<CWLSurfaceResource> surface_);
    ~CDRMSyncobjSurfaceResource();

    bool protocolError();
    bool good();

  private:
    void                            removeAllWaiters();
    WP<CWLSurfaceResource>          surface;
    UP<CWpLinuxDrmSyncobjSurfaceV1> resource;

    CDRMSyncPointState              pendingAcquire;
    CDRMSyncPointState              pendingRelease;
    std::vector<SP<SSurfaceState>>  pendingStates;

    struct {
        CHyprSignalListener surfacePrecommit;
    } listeners;
};