mirror of
https://github.com/hyprwm/Hyprland
synced 2025-12-20 09:10:08 +01:00
* syncobj: cleanup and use uniqueptrs cleanup a bit missing removals if resource not good, erasing from containers etc. make use of unique ptrs instead. and add default destructors. * syncobj: rework syncobj entirerly remove early buffer release that was breaking explicit sync, the buffer needs to exist until the surface commit event has been emitted and draw calls added egl sync points, move to eventfd signaling instead of stalling sync point checks, and recommit pending commits if waiting on a signal. add a CDRMSyncPointState helper class. move a few weak pointers to shared pointers so they dont destruct before we need to use them. * syncobj: queue pending states for eventfd eventfd requires us to queue pending stats until ready and then apply to current, and also when no ready state exist commit the client commit on the current existing buffer, if there is one. * syncobj: clear current buffer damage clear current buffer damage on current buffer commits. * syncobj: cleanup code and fix hyprlock remove unused code, and ensure we dont commit a empty texture causing locksession protocol and gtk4-layer-shell misbehaving. * syncobj: ensure buffers are cleaned up ensure the containers having the various buffers actually gets cleaned up from their containers, incase the CSignal isnt signaled because of expired smart pointers or just wrong order destruction because mishaps. also move the acquire/point setting to buffer attaching. instead of on precommit. * syncobj: remove unused code, optimize remove unused code and merge sync fds if fence is valid, remove manual directscanout buffer dropping that signals release point on pageflip, it can cause us to signal the release point while still keeping the current buffer and rendering it yet again causing wrong things. * syncobj: delay buffer release on non syncobj delay buffer releases on non syncobj surfaces until next commit, and check on async buffers if syncobj and drop and signal the release point on backend buffer release. * syncobj: ensure we follow protocol ensure we follow protocol by replacing acquire/release points if they arrive late and replace already existing ones. also remove unneded brackets, and dont try to manual lock/release buffers when it comes to explicit protocol. it doesnt care about buffer releases only about acquire and release points and signaling them. * syncobj: lets not complicate things set points in precommit, before checking protocol errors and we catch any pending acquire/release points arriving late. * syncobj: move SSurfaceState to types remove destructor resource destroying, let resources destroys them on their events, and move SSurfaceStates to types/SurfaceState.hpp * syncobj: actually store the merged fd have to actually store the mergedfd to use it. * syncobj: cleanup a bit around fences ensure the current asynchronous buffer is actually released on pageflip not the previous. cleanup a bit FD handling in commitPendingAndDoExplicitSync, and reuse the in fence when syncing surfaces. * syncobjs: ensure fence FD doesnt leak calling resetexplicitfence without properly ensuring the FD is closed before will leak it, store it per monitor and let it close itself with the CFileDescriptor class. * syncobj: ensure buffers are actually released buffers were never being sent released properly. * types: Defer buffer sync releaser until unlock * syncobj: store directscanout fence in monitor ensure the infence fd survives the scope of attemptdirectscanout so it doesnt close before it should have. * syncobj: check if if acquire is expired we might hit a race to finish on exit where the timeline just has destructed but the buffer waiter is still pending. and such we removeAllWaiters null dereferences. * syncobj: code style changes remove quack comment, change to m_foo and use a std::vector and weakpointer in the waiter for removal instead of a std::list. * syncobj: remove unused async buffer drop remove unused async buffer drop, only related to directscanout and is handled elsewhere. --------- Co-authored-by: Lee Bousfield <ljbousfield@gmail.com>
168 lines
5.6 KiB
C++
168 lines
5.6 KiB
C++
#pragma once
|
|
|
|
/*
|
|
Implementations for:
|
|
- wl_compositor
|
|
- wl_surface
|
|
- wl_region
|
|
- wl_callback
|
|
*/
|
|
|
|
#include <vector>
|
|
#include <cstdint>
|
|
#include "../WaylandProtocol.hpp"
|
|
#include "wayland.hpp"
|
|
#include "../../helpers/signal/Signal.hpp"
|
|
#include "../../helpers/math/Math.hpp"
|
|
#include "../types/Buffer.hpp"
|
|
#include "../types/SurfaceRole.hpp"
|
|
#include "../types/SurfaceState.hpp"
|
|
|
|
class CWLOutputResource;
|
|
class CMonitor;
|
|
class CWLSurface;
|
|
class CWLSurfaceResource;
|
|
class CWLSubsurfaceResource;
|
|
class CViewportResource;
|
|
class CDRMSyncobjSurfaceResource;
|
|
class CColorManagementSurface;
|
|
class CFrogColorManagementSurface;
|
|
class CContentType;
|
|
|
|
class CWLCallbackResource {
|
|
public:
|
|
CWLCallbackResource(SP<CWlCallback> resource_);
|
|
|
|
bool good();
|
|
void send(timespec* now);
|
|
|
|
private:
|
|
SP<CWlCallback> resource;
|
|
};
|
|
|
|
class CWLRegionResource {
|
|
public:
|
|
CWLRegionResource(SP<CWlRegion> resource_);
|
|
static SP<CWLRegionResource> fromResource(wl_resource* res);
|
|
|
|
bool good();
|
|
|
|
CRegion region;
|
|
WP<CWLRegionResource> self;
|
|
|
|
private:
|
|
SP<CWlRegion> resource;
|
|
};
|
|
|
|
class CWLSurfaceResource {
|
|
public:
|
|
CWLSurfaceResource(SP<CWlSurface> resource_);
|
|
~CWLSurfaceResource();
|
|
|
|
static SP<CWLSurfaceResource> fromResource(wl_resource* res);
|
|
|
|
bool good();
|
|
wl_client* client();
|
|
void enter(PHLMONITOR monitor);
|
|
void leave(PHLMONITOR monitor);
|
|
void sendPreferredTransform(wl_output_transform t);
|
|
void sendPreferredScale(int32_t scale);
|
|
void frame(timespec* now);
|
|
uint32_t id();
|
|
void map();
|
|
void unmap();
|
|
void error(int code, const std::string& str);
|
|
SP<CWlSurface> getResource();
|
|
CBox extends();
|
|
void resetRole();
|
|
Vector2D sourceSize();
|
|
|
|
struct {
|
|
CSignal precommit; // before commit
|
|
CSignal commit; // after commit
|
|
CSignal map;
|
|
CSignal unmap;
|
|
CSignal newSubsurface;
|
|
CSignal destroy;
|
|
} events;
|
|
|
|
SSurfaceState current, pending;
|
|
|
|
std::vector<SP<CWLCallbackResource>> callbacks;
|
|
WP<CWLSurfaceResource> self;
|
|
WP<CWLSurface> hlSurface;
|
|
std::vector<PHLMONITORREF> enteredOutputs;
|
|
bool mapped = false;
|
|
std::vector<WP<CWLSubsurfaceResource>> subsurfaces;
|
|
SP<ISurfaceRole> role;
|
|
WP<CViewportResource> viewportResource;
|
|
WP<CDRMSyncobjSurfaceResource> syncobj; // may not be present
|
|
WP<CColorManagementSurface> colorManagement;
|
|
WP<CContentType> contentType;
|
|
|
|
void breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
|
|
SP<CWLSurfaceResource> findFirstPreorder(std::function<bool(SP<CWLSurfaceResource>)> fn);
|
|
CRegion accumulateCurrentBufferDamage();
|
|
void presentFeedback(timespec* when, PHLMONITOR pMonitor, bool discarded = false);
|
|
void commitPendingState(SSurfaceState& state);
|
|
|
|
// returns a pair: found surface (null if not found) and surface local coords.
|
|
// localCoords param is relative to 0,0 of this surface
|
|
std::pair<SP<CWLSurfaceResource>, Vector2D> at(const Vector2D& localCoords, bool allowsInput = false);
|
|
|
|
private:
|
|
SP<CWlSurface> resource;
|
|
wl_client* pClient = nullptr;
|
|
|
|
void destroy();
|
|
void releaseBuffers(bool onlyCurrent = true);
|
|
void dropPendingBuffer();
|
|
void dropCurrentBuffer();
|
|
void bfHelper(std::vector<SP<CWLSurfaceResource>> const& nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
|
|
SP<CWLSurfaceResource> findFirstPreorderHelper(SP<CWLSurfaceResource> root, std::function<bool(SP<CWLSurfaceResource>)> fn);
|
|
void updateCursorShm(CRegion damage = CBox{0, 0, INT16_MAX, INT16_MAX});
|
|
|
|
friend class CWLPointerResource;
|
|
};
|
|
|
|
class CWLCompositorResource {
|
|
public:
|
|
CWLCompositorResource(SP<CWlCompositor> resource_);
|
|
|
|
bool good();
|
|
|
|
private:
|
|
SP<CWlCompositor> resource;
|
|
};
|
|
|
|
class CWLCompositorProtocol : public IWaylandProtocol {
|
|
public:
|
|
CWLCompositorProtocol(const wl_interface* iface, const int& ver, const std::string& name);
|
|
|
|
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
|
|
|
|
void forEachSurface(std::function<void(SP<CWLSurfaceResource>)> fn);
|
|
|
|
struct {
|
|
CSignal newSurface; // SP<CWLSurfaceResource>
|
|
} events;
|
|
|
|
private:
|
|
void destroyResource(CWLCompositorResource* resource);
|
|
void destroyResource(CWLSurfaceResource* resource);
|
|
void destroyResource(CWLRegionResource* resource);
|
|
|
|
//
|
|
std::vector<SP<CWLCompositorResource>> m_vManagers;
|
|
std::vector<SP<CWLSurfaceResource>> m_vSurfaces;
|
|
std::vector<SP<CWLRegionResource>> m_vRegions;
|
|
|
|
friend class CWLSurfaceResource;
|
|
friend class CWLCompositorResource;
|
|
friend class CWLRegionResource;
|
|
friend class CWLCallbackResource;
|
|
};
|
|
|
|
namespace PROTO {
|
|
inline UP<CWLCompositorProtocol> compositor;
|
|
};
|