pass: improve pass debugging

This commit is contained in:
Vaxry 2025-01-01 17:26:05 +01:00
parent 4e93b2def5
commit d64ac47202
5 changed files with 133 additions and 44 deletions

View file

@ -43,3 +43,7 @@ Hyprgraphics::CColor::SHSL CHyprColor::asHSL() const {
CHyprColor CHyprColor::stripA() const { CHyprColor CHyprColor::stripA() const {
return {r, g, b, 1.F}; return {r, g, b, 1.F};
} }
CHyprColor CHyprColor::modifyA(float newa) const {
return {r, g, b, newa};
}

View file

@ -18,6 +18,7 @@ class CHyprColor {
Hyprgraphics::CColor::SOkLab asOkLab() const; Hyprgraphics::CColor::SOkLab asOkLab() const;
Hyprgraphics::CColor::SHSL asHSL() const; Hyprgraphics::CColor::SHSL asHSL() const;
CHyprColor stripA() const; CHyprColor stripA() const;
CHyprColor modifyA(float newa) const;
// //
bool operator==(const CHyprColor& c2) const { bool operator==(const CHyprColor& c2) const {
@ -45,3 +46,18 @@ class CHyprColor {
private: private:
Hyprgraphics::CColor::SOkLab okLab; // cache for the OkLab representation Hyprgraphics::CColor::SOkLab okLab; // cache for the OkLab representation
}; };
//NOLINTNEXTLINE
namespace Colors {
static const CHyprColor WHITE = CHyprColor(1.F, 1.F, 1.F, 1.F);
static const CHyprColor GREEN = CHyprColor(0.F, 1.F, 0.F, 1.F);
static const CHyprColor BLUE = CHyprColor(0.F, 0.F, 1.F, 1.F);
static const CHyprColor RED = CHyprColor(1.F, 0.F, 0.F, 1.F);
static const CHyprColor ORANGE = CHyprColor(1.F, 0.5F, 0.F, 1.F);
static const CHyprColor YELLOW = CHyprColor(1.F, 1.F, 0.F, 1.F);
static const CHyprColor MAGENTA = CHyprColor(1.F, 0.F, 1.F, 1.F);
static const CHyprColor PURPLE = CHyprColor(0.5F, 0.F, 0.5F, 1.F);
static const CHyprColor LIME = CHyprColor(0.5F, 1.F, 0.1F, 1.F);
static const CHyprColor LIGHT_BLUE = CHyprColor(0.1F, 1.F, 1.F, 1.F);
static const CHyprColor BLACK = CHyprColor(0.F, 0.F, 0.F, 1.F);
};

View file

@ -166,59 +166,62 @@ class CHyprOpenGLImpl {
CHyprOpenGLImpl(); CHyprOpenGLImpl();
~CHyprOpenGLImpl(); ~CHyprOpenGLImpl();
void begin(PHLMONITOR, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {}); void begin(PHLMONITOR, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {});
void beginSimple(PHLMONITOR, const CRegion& damage, SP<CRenderbuffer> rb = nullptr, CFramebuffer* fb = nullptr); void beginSimple(PHLMONITOR, const CRegion& damage, SP<CRenderbuffer> rb = nullptr, CFramebuffer* fb = nullptr);
void end(); void end();
void renderRect(CBox*, const CHyprColor&, int round = 0); void renderRect(CBox*, const CHyprColor&, int round = 0);
void renderRectWithBlur(CBox*, const CHyprColor&, int round = 0, float blurA = 1.f, bool xray = false); void renderRectWithBlur(CBox*, const CHyprColor&, int round = 0, float blurA = 1.f, bool xray = false);
void renderRectWithDamage(CBox*, const CHyprColor&, const CRegion& damage, int round = 0); void renderRectWithDamage(CBox*, const CHyprColor&, const CRegion& damage, int round = 0);
void renderTexture(SP<CTexture>, CBox*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false); void renderTexture(SP<CTexture>, CBox*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false);
void renderTextureWithDamage(SP<CTexture>, CBox*, const CRegion& damage, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false, void renderTextureWithDamage(SP<CTexture>, CBox*, const CRegion& damage, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false,
SP<CSyncTimeline> waitTimeline = nullptr, uint64_t waitPoint = 0); SP<CSyncTimeline> waitTimeline = nullptr, uint64_t waitPoint = 0);
void renderTextureWithBlur(SP<CTexture>, CBox*, float a, SP<CWLSurfaceResource> pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f); void renderTextureWithBlur(SP<CTexture>, CBox*, float a, SP<CWLSurfaceResource> pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f);
void renderRoundedShadow(CBox*, int round, int range, const CHyprColor& color, float a = 1.0); void renderRoundedShadow(CBox*, int round, int range, const CHyprColor& color, float a = 1.0);
void renderBorder(CBox*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); void renderBorder(CBox*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */);
void renderBorder(CBox*, const CGradientValueData&, const CGradientValueData&, float lerp, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); void renderBorder(CBox*, const CGradientValueData&, const CGradientValueData&, float lerp, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */);
void renderTextureMatte(SP<CTexture> tex, CBox* pBox, CFramebuffer& matte); void renderTextureMatte(SP<CTexture> tex, CBox* pBox, CFramebuffer& matte);
void setMonitorTransformEnabled(bool enabled); void setMonitorTransformEnabled(bool enabled);
void setRenderModifEnabled(bool enabled); void setRenderModifEnabled(bool enabled);
void saveMatrix(); void saveMatrix();
void setMatrixScaleTranslate(const Vector2D& translate, const float& scale); void setMatrixScaleTranslate(const Vector2D& translate, const float& scale);
void restoreMatrix(); void restoreMatrix();
void blend(bool enabled); void blend(bool enabled);
bool shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow); bool shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow);
void clear(const CHyprColor&); void clear(const CHyprColor&);
void clearWithTex(); void clearWithTex();
void scissor(const CBox*, bool transform = true); void scissor(const CBox*, bool transform = true);
void scissor(const pixman_box32*, bool transform = true); void scissor(const pixman_box32*, bool transform = true);
void scissor(const int x, const int y, const int w, const int h, bool transform = true); void scissor(const int x, const int y, const int w, const int h, bool transform = true);
void destroyMonitorResources(PHLMONITOR); void destroyMonitorResources(PHLMONITOR);
void markBlurDirtyForMonitor(PHLMONITOR); void markBlurDirtyForMonitor(PHLMONITOR);
void preWindowPass(); void preWindowPass();
bool preBlurQueued(); bool preBlurQueued();
void preRender(PHLMONITOR); void preRender(PHLMONITOR);
void saveBufferForMirror(CBox*); void saveBufferForMirror(CBox*);
void renderMirrored(); void renderMirrored();
void applyScreenShader(const std::string& path); void applyScreenShader(const std::string& path);
void bindOffMain(); void bindOffMain();
void renderOffToMain(CFramebuffer* off); void renderOffToMain(CFramebuffer* off);
void bindBackOnMain(); void bindBackOnMain();
void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {}); SP<CTexture> loadAsset(const std::string& file);
SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false);
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor); void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {});
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
std::vector<SDRMFormat> getDRMFormats(); std::vector<SDRMFormat> getDRMFormats();
EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs);
SP<CEGLSync> createEGLSync(int fenceFD); SP<CEGLSync> createEGLSync(int fenceFD);
@ -298,8 +301,6 @@ class CHyprOpenGLImpl {
void initDRMFormats(); void initDRMFormats();
void initEGL(bool gbm); void initEGL(bool gbm);
EGLDeviceEXT eglDeviceFromDRMFD(int drmFD); EGLDeviceEXT eglDeviceFromDRMFD(int drmFD);
SP<CTexture> loadAsset(const std::string& file);
SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false);
void initAssets(); void initAssets();
void initMissingAssetTexture(); void initMissingAssetTexture();

View file

@ -3,6 +3,10 @@
#include <algorithm> #include <algorithm>
#include <ranges> #include <ranges>
#include "../../config/ConfigValue.hpp" #include "../../config/ConfigValue.hpp"
#include "../../desktop/WLSurface.hpp"
#include "../../managers/SeatManager.hpp"
#include "../../managers/eventLoop/EventLoopManager.hpp"
#include "../../Compositor.hpp"
bool CRenderPass::empty() const { bool CRenderPass::empty() const {
return false; return false;
@ -120,6 +124,15 @@ CRegion CRenderPass::render(const CRegion& damage_) {
return damage; return damage;
} }
if (!*PDEBUGPASS && debugData.present)
debugData = {false};
else if (*PDEBUGPASS && !debugData.present) {
debugData.present = true;
debugData.keyboardFocusText = g_pHyprOpenGL->renderText("keyboard", Colors::WHITE, 12);
debugData.pointerFocusText = g_pHyprOpenGL->renderText("pointer", Colors::WHITE, 12);
debugData.lastWindowText = g_pHyprOpenGL->renderText("lastWindow", Colors::WHITE, 12);
}
if (WILLBLUR && !*PDEBUGPASS) { if (WILLBLUR && !*PDEBUGPASS) {
// combine blur regions into one that will be expanded // combine blur regions into one that will be expanded
CRegion blurRegion; CRegion blurRegion;
@ -171,15 +184,63 @@ CRegion CRenderPass::render(const CRegion& damage_) {
} }
if (*PDEBUGPASS) { if (*PDEBUGPASS) {
CBox monbox = {{}, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize}; renderDebugData();
g_pHyprOpenGL->renderRectWithDamage(&monbox, CHyprColor{1.F, 0.1F, 0.1F, 0.5F}, occludedRegion); g_pEventLoopManager->doLater([] {
g_pHyprOpenGL->renderRectWithDamage(&monbox, CHyprColor{0.1F, 1.F, 0.1F, 0.5F}, totalLiveBlurRegion); for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m);
}
});
} }
g_pHyprOpenGL->m_RenderData.damage = damage; g_pHyprOpenGL->m_RenderData.damage = damage;
return damage; return damage;
} }
void CRenderPass::renderDebugData() {
CBox box = {{}, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize};
g_pHyprOpenGL->renderRectWithDamage(&box, Colors::RED.modifyA(0.1F), occludedRegion);
g_pHyprOpenGL->renderRectWithDamage(&box, Colors::GREEN.modifyA(0.1F), totalLiveBlurRegion);
std::unordered_map<CWLSurfaceResource*, float> offsets;
// render focus stuff
auto renderHLSurface = [&offsets](SP<CTexture> texture, SP<CWLSurfaceResource> surface, const CHyprColor& color) {
if (!surface || !texture)
return;
auto hlSurface = CWLSurface::fromResource(surface);
if (!hlSurface)
return;
auto bb = hlSurface->getSurfaceBoxGlobal();
if (!bb.has_value())
return;
CBox box = bb->copy().translate(-g_pHyprOpenGL->m_RenderData.pMonitor->vecPosition).scale(g_pHyprOpenGL->m_RenderData.pMonitor->scale);
if (box.intersection(CBox{{}, g_pHyprOpenGL->m_RenderData.pMonitor->vecSize}).empty())
return;
if (offsets.contains(surface.get()))
box.translate(Vector2D{0.F, offsets[surface.get()]});
else
offsets[surface.get()] = 0;
g_pHyprOpenGL->renderRectWithDamage(&box, Colors::PURPLE.modifyA(0.1F), CRegion{0, 0, INT32_MAX, INT32_MAX});
box = {box.pos(), texture->m_vSize};
g_pHyprOpenGL->renderRectWithDamage(&box, CHyprColor{0.F, 0.F, 0.F, 0.2F}, CRegion{0, 0, INT32_MAX, INT32_MAX}, std::min(5.0, box.size().y));
g_pHyprOpenGL->renderTexture(texture, &box, 1.F);
offsets[surface.get()] += texture->m_vSize.y;
};
renderHLSurface(debugData.keyboardFocusText, g_pSeatManager->state.keyboardFocus.lock(), Colors::PURPLE.modifyA(0.1F));
renderHLSurface(debugData.pointerFocusText, g_pSeatManager->state.pointerFocus.lock(), Colors::ORANGE.modifyA(0.1F));
if (g_pCompositor->m_pLastWindow)
renderHLSurface(debugData.lastWindowText, g_pCompositor->m_pLastWindow->m_pWLSurface->resource(), Colors::LIGHT_BLUE.modifyA(0.1F));
}
float CRenderPass::oneBlurRadius() { float CRenderPass::oneBlurRadius() {
// TODO: is this exact range correct? // TODO: is this exact range correct?
static auto PBLURSIZE = CConfigValue<Hyprlang::INT>("decoration:blur:size"); static auto PBLURSIZE = CConfigValue<Hyprlang::INT>("decoration:blur:size");

View file

@ -4,6 +4,7 @@
#include "PassElement.hpp" #include "PassElement.hpp"
class CGradientValueData; class CGradientValueData;
class CTexture;
class CRenderPass { class CRenderPass {
public: public:
@ -33,6 +34,12 @@ class CRenderPass {
void simplify(); void simplify();
float oneBlurRadius(); float oneBlurRadius();
void renderDebugData();
struct {
bool present = false;
SP<CTexture> keyboardFocusText, pointerFocusText, lastWindowText;
} debugData;
friend class CHyprOpenGLImpl; friend class CHyprOpenGLImpl;
}; };