2022-03-17 16:56:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
2022-03-17 18:25:16 +01:00
|
|
|
#include <deque>
|
|
|
|
#include "WLClasses.hpp"
|
2022-07-23 15:48:08 +02:00
|
|
|
#include <vector>
|
2022-03-19 13:54:24 +01:00
|
|
|
#include <array>
|
2022-07-23 15:48:08 +02:00
|
|
|
#include <memory>
|
2023-05-09 15:01:45 +02:00
|
|
|
#include <xf86drmMode.h>
|
2023-03-24 20:23:16 +01:00
|
|
|
#include "Timer.hpp"
|
2024-06-19 16:20:06 +02:00
|
|
|
#include "math/Math.hpp"
|
2023-08-11 17:37:52 +02:00
|
|
|
#include <optional>
|
2024-04-22 19:21:03 +02:00
|
|
|
#include "signal/Signal.hpp"
|
2024-06-19 18:25:20 +02:00
|
|
|
#include "DamageRing.hpp"
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <aquamarine/output/Output.hpp>
|
|
|
|
#include <aquamarine/allocator/Swapchain.hpp>
|
2024-04-22 19:21:03 +02:00
|
|
|
|
2024-04-23 02:40:03 +02:00
|
|
|
// Enum for the different types of auto directions, e.g. auto-left, auto-up.
|
2024-05-24 20:56:42 +02:00
|
|
|
enum eAutoDirs {
|
|
|
|
DIR_AUTO_NONE = 0, /* None will be treated as right. */
|
2024-04-23 02:40:03 +02:00
|
|
|
DIR_AUTO_UP,
|
|
|
|
DIR_AUTO_DOWN,
|
|
|
|
DIR_AUTO_LEFT,
|
|
|
|
DIR_AUTO_RIGHT
|
|
|
|
};
|
|
|
|
|
2023-08-11 17:37:52 +02:00
|
|
|
struct SMonitorRule {
|
2024-05-24 20:56:42 +02:00
|
|
|
eAutoDirs autoDir = DIR_AUTO_NONE;
|
2023-08-11 17:37:52 +02:00
|
|
|
std::string name = "";
|
|
|
|
Vector2D resolution = Vector2D(1280, 720);
|
|
|
|
Vector2D offset = Vector2D(0, 0);
|
|
|
|
float scale = 1;
|
|
|
|
float refreshRate = 60;
|
|
|
|
bool disabled = false;
|
|
|
|
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
|
|
|
std::string mirrorOf = "";
|
|
|
|
bool enable10bit = false;
|
|
|
|
drmModeModeInfo drmMode = {};
|
|
|
|
std::optional<int> vrr;
|
|
|
|
};
|
2022-09-13 15:25:42 +02:00
|
|
|
|
2024-01-28 02:57:13 +01:00
|
|
|
class CMonitor;
|
2024-07-21 13:09:54 +02:00
|
|
|
class CSyncTimeline;
|
2024-01-28 02:57:13 +01:00
|
|
|
|
|
|
|
class CMonitorState {
|
|
|
|
public:
|
|
|
|
CMonitorState(CMonitor* owner);
|
|
|
|
~CMonitorState();
|
|
|
|
|
|
|
|
bool commit();
|
|
|
|
bool test();
|
2024-07-21 13:09:54 +02:00
|
|
|
bool updateSwapchain();
|
2024-01-28 02:57:13 +01:00
|
|
|
|
|
|
|
private:
|
2024-07-21 13:09:54 +02:00
|
|
|
void ensureBufferPresent();
|
|
|
|
|
|
|
|
CMonitor* m_pOwner;
|
2024-01-28 02:57:13 +01:00
|
|
|
};
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
class CMonitor {
|
2022-12-16 18:17:31 +01:00
|
|
|
public:
|
2024-08-19 18:44:22 +02:00
|
|
|
CMonitor(SP<Aquamarine::IOutput> output);
|
2023-04-07 13:18:40 +02:00
|
|
|
~CMonitor();
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
Vector2D vecPosition = Vector2D(-1, -1); // means unset
|
|
|
|
Vector2D vecXWaylandPosition = Vector2D(-1, -1); // means unset
|
|
|
|
Vector2D vecSize = Vector2D(0, 0);
|
|
|
|
Vector2D vecPixelSize = Vector2D(0, 0);
|
|
|
|
Vector2D vecTransformedSize = Vector2D(0, 0);
|
|
|
|
|
|
|
|
bool primary = false;
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2024-08-08 21:01:50 +02:00
|
|
|
MONITORID ID = MONITOR_INVALID;
|
2024-07-21 13:09:54 +02:00
|
|
|
PHLWORKSPACE activeWorkspace = nullptr;
|
|
|
|
PHLWORKSPACE activeSpecialWorkspace = nullptr;
|
|
|
|
float setScale = 1; // scale set by cfg
|
|
|
|
float scale = 1; // real scale
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
std::string szName = "";
|
|
|
|
std::string szDescription = "";
|
|
|
|
std::string szShortDescription = "";
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
Vector2D vecReservedTopLeft = Vector2D(0, 0);
|
|
|
|
Vector2D vecReservedBottomRight = Vector2D(0, 0);
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
drmModeModeInfo customDrmMode = {};
|
2023-05-09 15:01:45 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
CMonitorState state;
|
|
|
|
CDamageRing damage;
|
2022-03-17 18:25:16 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SP<Aquamarine::IOutput> output;
|
|
|
|
float refreshRate = 60;
|
|
|
|
int framesToSkip = 0;
|
|
|
|
int forceFullFrames = 0;
|
|
|
|
bool noFrameSchedule = false;
|
|
|
|
bool scheduledRecalc = false;
|
|
|
|
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
|
|
|
float xwaylandScale = 1.f;
|
2024-09-25 11:01:13 +02:00
|
|
|
Mat3x3 projMatrix;
|
2024-07-21 13:09:54 +02:00
|
|
|
std::optional<Vector2D> forceSize;
|
|
|
|
SP<Aquamarine::SOutputMode> currentMode;
|
|
|
|
SP<Aquamarine::CSwapchain> cursorSwapchain;
|
2024-08-31 15:07:52 +02:00
|
|
|
uint32_t drmFormat = DRM_FORMAT_INVALID;
|
|
|
|
uint32_t prevDrmFormat = DRM_FORMAT_INVALID;
|
2024-01-28 02:57:13 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool dpmsStatus = true;
|
|
|
|
bool vrrActive = false; // this can be TRUE even if VRR is not active in the case that this display does not support it.
|
|
|
|
bool enabled10bit = false; // as above, this can be TRUE even if 10 bit failed.
|
|
|
|
bool createdByUser = false;
|
|
|
|
bool isUnsafeFallback = false;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool pendingFrame = false; // if we schedule a frame during rendering, reschedule it after
|
|
|
|
bool renderingActive = false;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
wl_event_source* renderTimer = nullptr; // for RAT
|
|
|
|
bool RATScheduled = false;
|
|
|
|
CTimer lastPresentationTimer;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool isBeingLeased = false;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SMonitorRule activeMonitorRule;
|
2023-08-11 17:37:52 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
// explicit sync
|
|
|
|
SP<CSyncTimeline> inTimeline;
|
|
|
|
SP<CSyncTimeline> outTimeline;
|
2024-08-06 15:52:19 +02:00
|
|
|
uint64_t commitSeq = 0;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
WP<CMonitor> self;
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2022-09-13 15:25:42 +02:00
|
|
|
// mirroring
|
2022-12-16 18:17:31 +01:00
|
|
|
CMonitor* pMirrorOf = nullptr;
|
2022-09-13 15:25:42 +02:00
|
|
|
std::vector<CMonitor*> mirrors;
|
|
|
|
|
2024-10-08 17:59:15 +02:00
|
|
|
// ctm
|
|
|
|
Mat3x3 ctm = Mat3x3::identity();
|
|
|
|
bool ctmUpdated = false;
|
|
|
|
|
2023-09-28 22:48:33 +02:00
|
|
|
// for tearing
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOWREF solitaryClient;
|
2023-09-30 18:07:50 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
// for direct scanout
|
|
|
|
PHLWINDOWREF lastScanout;
|
|
|
|
|
2023-09-30 18:07:50 +02:00
|
|
|
struct {
|
|
|
|
bool canTear = false;
|
|
|
|
bool nextRenderTorn = false;
|
|
|
|
bool activelyTearing = false;
|
|
|
|
|
|
|
|
bool busy = false;
|
|
|
|
bool frameScheduledWhileBusy = false;
|
|
|
|
} tearingState;
|
2023-09-28 22:48:33 +02:00
|
|
|
|
2024-04-22 19:21:03 +02:00
|
|
|
struct {
|
|
|
|
CSignal destroy;
|
|
|
|
CSignal connect;
|
|
|
|
CSignal disconnect;
|
2024-04-29 02:28:26 +02:00
|
|
|
CSignal dpmsChanged;
|
|
|
|
CSignal modeChanged;
|
2024-04-22 19:21:03 +02:00
|
|
|
} events;
|
|
|
|
|
2024-05-09 22:47:21 +02:00
|
|
|
std::array<std::vector<PHLLSREF>, 4> m_aLayerSurfaceLayers;
|
2022-03-17 18:25:16 +01:00
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
// methods
|
2024-08-08 21:01:50 +02:00
|
|
|
void onConnect(bool noRule);
|
|
|
|
void onDisconnect(bool destroy = false);
|
|
|
|
void addDamage(const pixman_region32_t* rg);
|
|
|
|
void addDamage(const CRegion* rg);
|
|
|
|
void addDamage(const CBox* box);
|
|
|
|
bool shouldSkipScheduleFrameOnMouseEvent();
|
|
|
|
void setMirror(const std::string&);
|
|
|
|
bool isMirror();
|
|
|
|
bool matchesStaticSelector(const std::string& selector) const;
|
|
|
|
float getDefaultScale();
|
|
|
|
void changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false);
|
|
|
|
void changeWorkspace(const WORKSPACEID& id, bool internal = false, bool noMouseMove = false, bool noFocus = false);
|
|
|
|
void setSpecialWorkspace(const PHLWORKSPACE& pWorkspace);
|
|
|
|
void setSpecialWorkspace(const WORKSPACEID& id);
|
|
|
|
void moveTo(const Vector2D& pos);
|
|
|
|
Vector2D middle();
|
|
|
|
void updateMatrix();
|
|
|
|
WORKSPACEID activeWorkspaceID();
|
|
|
|
WORKSPACEID activeSpecialWorkspaceID();
|
|
|
|
CBox logicalBox();
|
|
|
|
void scheduleDone();
|
|
|
|
bool attemptDirectScanout();
|
2024-10-08 17:59:15 +02:00
|
|
|
void setCTM(const Mat3x3& ctm);
|
2024-08-08 21:01:50 +02:00
|
|
|
|
|
|
|
bool m_bEnabled = false;
|
|
|
|
bool m_bRenderingInitPassed = false;
|
2022-07-27 12:32:00 +02:00
|
|
|
|
2022-03-18 22:35:51 +01:00
|
|
|
// For the list lookup
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
bool operator==(const CMonitor& rhs) {
|
2022-03-18 22:35:51 +01:00
|
|
|
return vecPosition == rhs.vecPosition && vecSize == rhs.vecSize && szName == rhs.szName;
|
|
|
|
}
|
2022-09-13 15:25:42 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
private:
|
2024-10-05 01:44:30 +02:00
|
|
|
void setupDefaultWS(const SMonitorRule&);
|
|
|
|
WORKSPACEID findAvailableDefaultWS();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2024-10-05 01:44:30 +02:00
|
|
|
bool doneScheduled = false;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
CHyprSignalListener frame;
|
|
|
|
CHyprSignalListener destroy;
|
|
|
|
CHyprSignalListener state;
|
|
|
|
CHyprSignalListener needsFrame;
|
|
|
|
CHyprSignalListener presented;
|
|
|
|
CHyprSignalListener commit;
|
|
|
|
} listeners;
|
2022-09-25 20:07:48 +02:00
|
|
|
};
|