Hyprland/src/render/Renderer.hpp

160 lines
7.1 KiB
C++
Raw Normal View History

2022-03-17 20:22:29 +01:00
#pragma once
#include "../defines.hpp"
2022-03-19 14:37:40 +01:00
#include <list>
#include "../helpers/Monitor.hpp"
2022-04-05 20:49:15 +02:00
#include "OpenGL.hpp"
#include "Renderbuffer.hpp"
2023-05-01 03:49:41 +02:00
#include "../helpers/Timer.hpp"
#include "../helpers/math/Math.hpp"
2022-03-17 20:22:29 +01:00
2022-04-19 19:01:23 +02:00
struct SMonitorRule;
class CWorkspace;
2024-03-20 02:44:51 +01:00
class CWindow;
class CInputPopup;
class IHLBuffer;
class CEventLoopTimer;
2022-04-19 19:01:23 +02:00
2022-04-14 16:43:29 +02:00
// TODO: add fuller damage tracking for updating only parts of a window
enum DAMAGETRACKINGMODES {
2022-04-14 16:43:29 +02:00
DAMAGE_TRACKING_INVALID = -1,
DAMAGE_TRACKING_NONE = 0,
2022-04-14 16:43:29 +02:00
DAMAGE_TRACKING_MONITOR,
DAMAGE_TRACKING_FULL
};
enum eRenderPassMode {
RENDER_PASS_ALL = 0,
RENDER_PASS_MAIN,
RENDER_PASS_POPUP
};
enum eRenderMode {
RENDER_MODE_NORMAL = 0,
RENDER_MODE_FULL_FAKE = 1,
RENDER_MODE_TO_BUFFER = 2,
RENDER_MODE_TO_BUFFER_READ_ONLY = 3,
};
class CToplevelExportProtocolManager;
2023-01-26 11:39:06 +01:00
class CInputManager;
2023-02-03 12:58:55 +01:00
struct SSessionLockSurface;
struct SExplicitSyncSettings {
bool explicitEnabled = false, explicitKMSEnabled = false;
};
2022-03-17 20:22:29 +01:00
class CHyprRenderer {
public:
CHyprRenderer();
~CHyprRenderer();
void renderMonitor(PHLMONITOR pMonitor);
void arrangeLayersForMonitor(const MONITORID&);
void damageSurface(SP<CWLSurfaceResource>, double, double, double scale = 1.0);
void damageWindow(PHLWINDOW, bool forceFull = false);
void damageBox(CBox*, bool skipFrameSchedule = false);
void damageBox(const int& x, const int& y, const int& w, const int& h);
void damageRegion(const CRegion&);
void damageMonitor(PHLMONITOR);
void damageMirrorsWith(PHLMONITOR, const CRegion&);
bool applyMonitorRule(PHLMONITOR, SMonitorRule*, bool force = false);
bool shouldRenderWindow(PHLWINDOW, PHLMONITOR);
bool shouldRenderWindow(PHLWINDOW);
void ensureCursorRenderingMode();
bool shouldRenderCursor();
void setCursorHidden(bool hide);
void calculateUVForSurface(PHLWINDOW, SP<CWLSurfaceResource>, SP<CMonitor> pMonitor, bool main = false, const Vector2D& projSize = {}, const Vector2D& projSizeUnscaled = {},
bool fixMisalignedFSV1 = false);
std::tuple<float, float, float> getRenderTimes(PHLMONITOR pMonitor); // avg max min
void renderLockscreen(PHLMONITOR pMonitor, timespec* now, const CBox& geometry);
void setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace);
void setOccludedForMainWorkspace(CRegion& region, PHLWORKSPACE pWorkspace); // TODO: merge occlusion methods
bool canSkipBackBufferClear(PHLMONITOR pMonitor);
void recheckSolitaryForMonitor(PHLMONITOR pMonitor);
void setCursorSurface(SP<CWLSurface> surf, int hotspotX, int hotspotY, bool force = false);
void setCursorFromName(const std::string& name, bool force = false);
void onRenderbufferDestroy(CRenderbuffer* rb);
SP<CRenderbuffer> getCurrentRBO();
bool isNvidia();
2023-11-30 02:18:55 +01:00
void makeEGLCurrent();
void unsetEGL();
SExplicitSyncSettings getExplicitSyncSettings();
void addWindowToRenderUnfocused(PHLWINDOW window);
2024-02-19 19:17:32 +01:00
// if RENDER_MODE_NORMAL, provided damage will be written to.
// otherwise, it will be the one used.
bool beginRender(PHLMONITOR pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, SP<IHLBuffer> buffer = {}, CFramebuffer* fb = nullptr, bool simple = false);
void endRender();
2022-06-26 13:43:32 +02:00
bool m_bBlockSurfaceFeedback = false;
bool m_bRenderingSnapshot = false;
PHLMONITORREF m_pMostHzMonitor;
bool m_bDirectScanoutBlocked = false;
2022-04-14 16:43:29 +02:00
2023-04-16 15:48:38 +02:00
DAMAGETRACKINGMODES
damageTrackingModeFromStr(const std::string&);
2022-03-17 20:22:29 +01:00
void setSurfaceScanoutMode(SP<CWLSurfaceResource> surface, SP<CMonitor> monitor); // nullptr monitor resets
void initiateManualCrash();
bool m_bCrashingInProgress = false;
float m_fCrashingDistort = 0.5f;
wl_event_source* m_pCrashingLoop = nullptr;
wl_event_source* m_pCursorTicker = nullptr;
2023-04-04 15:49:58 +02:00
CTimer m_tRenderTimer;
std::vector<SP<CWLSurfaceResource>> explicitPresented;
2023-05-01 03:49:41 +02:00
struct {
int hotspotX;
int hotspotY;
std::optional<SP<CWLSurface>> surf;
std::string name;
} m_sLastCursorData;
private:
void arrangeLayerArray(PHLMONITOR, const std::vector<PHLLSREF>&, bool, CBox*);
void renderWorkspaceWindowsFullscreen(PHLMONITOR, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows(PHLMONITOR, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow(PHLWINDOW, PHLMONITOR, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderLayer(PHLLS, PHLMONITOR, timespec*, bool popups = false);
void renderSessionLockSurface(SSessionLockSurface*, PHLMONITOR, timespec*);
void renderDragIcon(PHLMONITOR, timespec*);
void renderIMEPopup(CInputPopup*, PHLMONITOR, timespec*);
void renderWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry);
void sendFrameEventsToWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now); // sends frame displayed events but doesn't actually render anything
void renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f);
void renderSessionLockMissing(PHLMONITOR pMonitor);
bool commitPendingAndDoExplicitSync(PHLMONITOR pMonitor);
bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false;
SP<CRenderbuffer> m_pCurrentRenderbuffer = nullptr;
SP<Aquamarine::IBuffer> m_pCurrentBuffer;
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL;
bool m_bNvidia = false;
struct {
bool hiddenOnTouch = false;
bool hiddenOnTimeout = false;
bool hiddenOnKeyboard = false;
} m_sCursorHiddenConditions;
SP<CRenderbuffer> getOrCreateRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t fmt);
std::vector<SP<CRenderbuffer>> m_vRenderbuffers;
std::vector<PHLWINDOWREF> m_vRenderUnfocused;
SP<CEventLoopTimer> m_tRenderUnfocusedTimer;
2022-04-05 20:49:15 +02:00
friend class CHyprOpenGLImpl;
friend class CToplevelExportFrame;
2023-01-26 11:39:06 +01:00
friend class CInputManager;
friend class CPointerManager;
friend class CMonitor;
2022-03-17 20:22:29 +01:00
};
inline std::unique_ptr<CHyprRenderer> g_pHyprRenderer;