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"
2023-11-24 11:54:21 +01:00
# include "Renderbuffer.hpp"
2023-05-01 03:49:41 +02:00
# include "../helpers/Timer.hpp"
2023-07-19 20:09:49 +02:00
# include "../helpers/Region.hpp"
2022-03-17 20:22:29 +01:00
2022-04-19 19:01:23 +02:00
struct SMonitorRule ;
2024-02-29 14:03:38 +01:00
class CWorkspace ;
2024-03-20 02:44:51 +01:00
class CWindow ;
2024-03-24 21:38:10 +01:00
class CInputPopup ;
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
2023-12-06 23:54:56 +01:00
enum DAMAGETRACKINGMODES {
2022-04-14 16:43:29 +02:00
DAMAGE_TRACKING_INVALID = - 1 ,
2022-12-16 18:17:31 +01:00
DAMAGE_TRACKING_NONE = 0 ,
2022-04-14 16:43:29 +02:00
DAMAGE_TRACKING_MONITOR ,
DAMAGE_TRACKING_FULL
} ;
2023-12-06 23:54:56 +01:00
enum eRenderPassMode {
2022-07-12 09:49:56 +02:00
RENDER_PASS_ALL = 0 ,
RENDER_PASS_MAIN ,
RENDER_PASS_POPUP
} ;
2023-12-06 23:54:56 +01:00
enum eRenderMode {
2023-11-30 11:14:35 +01:00
RENDER_MODE_NORMAL = 0 ,
RENDER_MODE_FULL_FAKE = 1 ,
RENDER_MODE_TO_BUFFER = 2 ,
RENDER_MODE_TO_BUFFER_READ_ONLY = 3 ,
2023-11-24 11:54:21 +01:00
} ;
2022-12-05 18:05:15 +01:00
class CToplevelExportProtocolManager ;
2023-01-26 11:39:06 +01:00
class CInputManager ;
2023-02-03 12:58:55 +01:00
struct SSessionLockSurface ;
2022-12-05 18:05:15 +01:00
2022-03-17 20:22:29 +01:00
class CHyprRenderer {
2022-12-16 18:17:31 +01:00
public :
2023-09-28 22:48:33 +02:00
CHyprRenderer ( ) ;
2023-03-24 20:23:16 +01:00
void renderMonitor ( CMonitor * pMonitor ) ;
void outputMgrApplyTest ( wlr_output_configuration_v1 * , bool ) ;
void arrangeLayersForMonitor ( const int & ) ;
2023-06-11 21:52:13 +02:00
void damageSurface ( wlr_surface * , double , double , double scale = 1.0 ) ;
2023-03-24 20:23:16 +01:00
void damageWindow ( CWindow * ) ;
2023-11-04 18:03:05 +01:00
void damageBox ( CBox * ) ;
2023-03-24 20:23:16 +01:00
void damageBox ( const int & x , const int & y , const int & w , const int & h ) ;
2023-07-19 20:09:49 +02:00
void damageRegion ( const CRegion & ) ;
2023-03-24 20:23:16 +01:00
void damageMonitor ( CMonitor * ) ;
2023-07-19 20:09:49 +02:00
void damageMirrorsWith ( CMonitor * , const CRegion & ) ;
2023-03-24 20:23:16 +01:00
bool applyMonitorRule ( CMonitor * , SMonitorRule * , bool force = false ) ;
2023-04-12 14:05:57 +02:00
bool shouldRenderWindow ( CWindow * , CMonitor * , CWorkspace * ) ;
2023-03-24 20:23:16 +01:00
bool shouldRenderWindow ( CWindow * ) ;
void ensureCursorRenderingMode ( ) ;
bool shouldRenderCursor ( ) ;
2023-12-20 21:40:44 +01:00
void setCursorHidden ( bool hide ) ;
2024-01-29 00:42:39 +01:00
void calculateUVForSurface ( CWindow * , wlr_surface * , bool main = false , const Vector2D & projSize = { } , bool fixMisalignedFSV1 = false ) ;
2023-03-24 20:23:16 +01:00
std : : tuple < float , float , float > getRenderTimes ( CMonitor * pMonitor ) ; // avg max min
2024-03-15 17:17:13 +01:00
void renderLockscreen ( CMonitor * pMonitor , timespec * now , const CBox & geometry ) ;
2023-07-19 20:09:49 +02:00
void setOccludedForBackLayers ( CRegion & region , CWorkspace * pWorkspace ) ;
2023-12-23 22:41:42 +01:00
void setOccludedForMainWorkspace ( CRegion & region , CWorkspace * pWorkspace ) ; // TODO: merge occlusion methods
2023-07-20 14:11:05 +02:00
bool canSkipBackBufferClear ( CMonitor * pMonitor ) ;
2023-09-28 22:48:33 +02:00
void recheckSolitaryForMonitor ( CMonitor * pMonitor ) ;
2023-12-20 21:40:44 +01:00
void setCursorSurface ( wlr_surface * surf , int hotspotX , int hotspotY , bool force = false ) ;
void setCursorFromName ( const std : : string & name , bool force = false ) ;
2023-11-24 11:54:21 +01:00
void renderSoftwareCursors ( CMonitor * pMonitor , const CRegion & damage , std : : optional < Vector2D > overridePos = { } ) ;
void onRenderbufferDestroy ( CRenderbuffer * rb ) ;
CRenderbuffer * getCurrentRBO ( ) ;
2023-11-25 18:45:08 +01:00
bool isNvidia ( ) ;
2023-11-30 02:18:55 +01:00
void makeEGLCurrent ( ) ;
void unsetEGL ( ) ;
2023-11-24 11:54:21 +01:00
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.
2023-11-30 02:18:55 +01:00
bool beginRender ( CMonitor * pMonitor , CRegion & damage , eRenderMode mode = RENDER_MODE_NORMAL , wlr_buffer * buffer = nullptr , CFramebuffer * fb = nullptr ) ;
void endRender ( ) ;
2022-06-26 13:43:32 +02:00
2023-12-29 10:24:56 +01:00
bool m_bBlockSurfaceFeedback = false ;
bool m_bRenderingSnapshot = false ;
CWindow * m_pLastScanout = nullptr ;
CMonitor * m_pMostHzMonitor = nullptr ;
bool m_bDirectScanoutBlocked = false ;
bool m_bSoftwareCursorsLocked = 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
2023-09-28 22:48:33 +02:00
bool attemptDirectScanout ( CMonitor * ) ;
void setWindowScanoutMode ( CWindow * ) ;
void initiateManualCrash ( ) ;
bool m_bCrashingInProgress = false ;
float m_fCrashingDistort = 0.5f ;
wl_event_source * m_pCrashingLoop = nullptr ;
2024-03-28 03:04:30 +01:00
wl_event_source * m_pCursorTicker = nullptr ;
2023-04-04 15:49:58 +02:00
2023-09-28 22:48:33 +02:00
std : : vector < std : : unique_ptr < STearingController > > m_vTearingControllers ;
2022-11-05 13:50:47 +01:00
2023-09-28 22:48:33 +02:00
CTimer m_tRenderTimer ;
2023-05-01 03:49:41 +02:00
2023-10-29 19:09:05 +01:00
struct {
2023-12-18 17:06:06 +01:00
int hotspotX ;
int hotspotY ;
2023-10-30 01:18:40 +01:00
std : : optional < wlr_surface * > surf = nullptr ;
std : : string name ;
2023-10-29 19:09:05 +01:00
} m_sLastCursorData ;
2022-12-16 18:17:31 +01:00
private :
2023-11-24 11:54:21 +01:00
void arrangeLayerArray ( CMonitor * , const std : : vector < std : : unique_ptr < SLayerSurface > > & , bool , CBox * ) ;
void renderWorkspaceWindowsFullscreen ( CMonitor * , CWorkspace * , timespec * ) ; // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows ( CMonitor * , CWorkspace * , timespec * ) ; // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow ( CWindow * , CMonitor * , timespec * , bool , eRenderPassMode , bool ignorePosition = false , bool ignoreAllGeometry = false ) ;
2024-03-25 17:20:30 +01:00
void renderLayer ( SLayerSurface * , CMonitor * , timespec * , bool popups = false ) ;
2023-11-24 11:54:21 +01:00
void renderSessionLockSurface ( SSessionLockSurface * , CMonitor * , timespec * ) ;
void renderDragIcon ( CMonitor * , timespec * ) ;
2024-03-24 17:08:25 +01:00
void renderIMEPopup ( CInputPopup * , CMonitor * , timespec * ) ;
2023-11-24 11:54:21 +01:00
void renderWorkspace ( CMonitor * pMonitor , CWorkspace * pWorkspace , timespec * now , const CBox & geometry ) ;
void renderAllClientsForWorkspace ( CMonitor * pMonitor , CWorkspace * pWorkspace , timespec * now , const Vector2D & translate = { 0 , 0 } , const float & scale = 1.f ) ;
2023-12-20 21:40:44 +01:00
bool m_bCursorHidden = false ;
bool m_bCursorHasSurface = false ;
CRenderbuffer * m_pCurrentRenderbuffer = nullptr ;
wlr_buffer * m_pCurrentWlrBuffer = nullptr ;
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL ;
2023-11-24 11:54:21 +01:00
2023-11-25 18:45:08 +01:00
bool m_bNvidia = false ;
2024-03-28 03:04:30 +01:00
struct {
bool hiddenOnTouch = false ;
bool hiddenOnTimeout = false ;
bool hiddenOnKeyboard = false ;
} m_sCursorHiddenConditions ;
CRenderbuffer * getOrCreateRenderbuffer ( wlr_buffer * buffer , uint32_t fmt ) ;
2023-11-24 11:54:21 +01:00
std : : vector < std : : unique_ptr < CRenderbuffer > > m_vRenderbuffers ;
2022-04-05 20:49:15 +02:00
friend class CHyprOpenGLImpl ;
2022-12-05 18:05:15 +01:00
friend class CToplevelExportProtocolManager ;
2023-01-26 11:39:06 +01:00
friend class CInputManager ;
2022-03-17 20:22:29 +01:00
} ;
inline std : : unique_ptr < CHyprRenderer > g_pHyprRenderer ;