From 38c1d00f3c1c65c6307dbc91be41fc2ce28ffeed Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Thu, 26 Dec 2024 19:24:35 +0100 Subject: [PATCH] fix: use new render scheduling like hl fixes #48 --- Makefile | 2 +- hyprpm.toml | 3 ++ src/cursor.cpp | 34 +++++++++++++++++------ src/render/CursorPassElement.cpp | 47 ++++++++++++++++++++++++++++++++ src/render/CursorPassElement.hpp | 41 ++++++++++++++++++++++++++++ src/{ => render}/renderer.cpp | 12 ++++---- src/render/renderer.hpp | 4 +++ src/renderer.hpp | 4 --- 8 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 src/render/CursorPassElement.cpp create mode 100644 src/render/CursorPassElement.hpp rename src/{ => render}/renderer.cpp (94%) create mode 100644 src/render/renderer.hpp delete mode 100644 src/renderer.hpp diff --git a/Makefile b/Makefile index 0a265c8..9e31db4 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: $(PLUGIN_NAME).so $(PLUGIN_NAME).so: $(SOURCE_FILES) mkdir -p out - g++ -shared -Wall --no-gnu-unique -fPIC $(SOURCE_FILES) -g `pkg-config --cflags hyprland | awk '{print $$NF "/src";}'` `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++23 -o out/$(PLUGIN_NAME).so + $(CXX) -shared -Wall --no-gnu-unique -fPIC $(SOURCE_FILES) -g `pkg-config --cflags hyprland | awk '{print $$NF "/src";}'` `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++26 -o out/$(PLUGIN_NAME).so clean: rm -f out/$(PLUGIN_NAME).so diff --git a/hyprpm.toml b/hyprpm.toml index b2a6fc8..8ae67c2 100644 --- a/hyprpm.toml +++ b/hyprpm.toml @@ -11,6 +11,9 @@ commit_pins = [ ["a425fbebe4cf4238e48a42f724ef2208959d66cf", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.0 ["500d2a3580388afc8b620b0a3624147faa34f98b", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.1 ["12f9a0d0b93f691d4d9923716557154d74777b0a", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.2 + ["788ae588979c2a1ff8a660f16e3c502ef5796755", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.0 + ["254fc2bc6000075f660b4b8ed818a6af544d1d64", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.1 + ["0bd541f2fd902dbfa04c3ea2ccf679395e316887", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.2 ] [dynamic-cursors] diff --git a/src/cursor.cpp b/src/cursor.cpp index 119e499..f5e6628 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -1,8 +1,3 @@ -#include "config/config.hpp" -#include "mode/Mode.hpp" -#include "src/debug/Log.hpp" -#include "src/helpers/math/Math.hpp" - #include #include #include @@ -10,19 +5,28 @@ #include #include +#include // required so we don't "unprivate" chrono + #define private public #include #include #include +#include #include #undef private #include #include #include +#include +#include #include "cursor.hpp" -#include "renderer.hpp" +#include "render/renderer.hpp" +#include "config/config.hpp" +#include "mode/Mode.hpp" +#include "render/CursorPassElement.hpp" +#include "render/Renderer.hpp" void tickRaw(SP self, void* data) { if (isEnabled()) @@ -120,8 +124,20 @@ void CDynamicCursors::renderSoftware(CPointerManager* pointers, SP pMo // we rotate the cursor by our calculated amount box.rot = resultShown.rotation; - // now pass the hotspot to rotate around - renderCursorTextureInternalWithDamage(texture, &box, &damage, 1.F, nullptr, 0, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, nearest, resultShown.stretch.angle, resultShown.stretch.magnitude); + CCursorPassElement::SRenderData data; + data.tex = texture; + data.box = box; + data.syncTimeline = pointers->currentCursorImage.waitTimeline; + data.syncPoint = pointers->currentCursorImage.waitPoint; + data.hotspot = pointers->currentCursorImage.hotspot * state->monitor->scale * zoom; + data.nearest = nearest; + data.stretchAngle = resultShown.stretch.angle; + data.stretchMagnitude = resultShown.stretch.magnitude; + + g_pHyprRenderer->m_sRenderPass.add(makeShared(data)); + + pointers->currentCursorImage.waitTimeline.reset(); + pointers->currentCursorImage.waitPoint = 0; if (pointers->currentCursorImage.surface) pointers->currentCursorImage.surface->resource()->frame(now); @@ -298,7 +314,7 @@ SP CDynamicCursors::renderHardware(CPointerManager* pointer xbox.rot = resultShown.rotation; // use our custom draw function - renderCursorTextureInternalWithDamage(texture, &xbox, &damage, 1.F, pointers->currentCursorImage.waitTimeline, pointers->currentCursorImage.waitPoint, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, zoom > 1 && **PNEAREST, resultShown.stretch.angle, resultShown.stretch.magnitude); + renderCursorTextureInternalWithDamage(texture, &xbox, damage, 1.F, pointers->currentCursorImage.waitTimeline, pointers->currentCursorImage.waitPoint, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, zoom > 1 && **PNEAREST, resultShown.stretch.angle, resultShown.stretch.magnitude); g_pHyprOpenGL->end(); glFlush(); diff --git a/src/render/CursorPassElement.cpp b/src/render/CursorPassElement.cpp new file mode 100644 index 0000000..e4292dc --- /dev/null +++ b/src/render/CursorPassElement.cpp @@ -0,0 +1,47 @@ +#include "CursorPassElement.hpp" +#include "renderer.hpp" + +#include +#include + +#include +using namespace Hyprutils::Utils; + +CCursorPassElement::CCursorPassElement(const CCursorPassElement::SRenderData& data_) : data(data_) { + ; +} + +void CCursorPassElement::draw(const CRegion& damage) { + renderCursorTextureInternalWithDamage( + data.tex, + &data.box, + data.damage.empty() ? damage : data.damage, + 1.F, + data.syncTimeline, + data.syncPoint, + data.hotspot, + data.nearest, + data.stretchAngle, + data.stretchMagnitude + ); +} + +bool CCursorPassElement::needsLiveBlur() { + return false; // TODO? +} + +bool CCursorPassElement::needsPrecomputeBlur() { + return false; // TODO? +} + +std::optional CCursorPassElement::boundingBox() { + return data.box.copy().scale(1.F / g_pHyprOpenGL->m_RenderData.pMonitor->scale).round(); +} + +CRegion CCursorPassElement::opaqueRegion() { + return {}; // TODO: +} + +void CCursorPassElement::discard() { + ; +} diff --git a/src/render/CursorPassElement.hpp b/src/render/CursorPassElement.hpp new file mode 100644 index 0000000..a5d50a2 --- /dev/null +++ b/src/render/CursorPassElement.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include + +class CWLSurfaceResource; +class CTexture; +class CSyncTimeline; + +class CCursorPassElement : public IPassElement { + public: + struct SRenderData { + SP tex; + CBox box; + CRegion damage; + SP syncTimeline; + int64_t syncPoint = 0; + + Vector2D hotspot; + bool nearest; + double stretchAngle; + Vector2D stretchMagnitude; + }; + + CCursorPassElement(const SRenderData& data); + virtual ~CCursorPassElement() = default; + + virtual void draw(const CRegion& damage); + virtual bool needsLiveBlur(); + virtual bool needsPrecomputeBlur(); + virtual std::optional boundingBox(); + virtual CRegion opaqueRegion(); + virtual void discard(); + + virtual const char* passName() { + return "CCursorPassElement"; + } + + private: + SRenderData data; +}; diff --git a/src/renderer.cpp b/src/render/renderer.cpp similarity index 94% rename from src/renderer.cpp rename to src/render/renderer.cpp index e7c8315..55982f3 100644 --- a/src/renderer.cpp +++ b/src/render/renderer.cpp @@ -1,5 +1,4 @@ -#include "globals.hpp" -#include "src/debug/Log.hpp" +#include "../globals.hpp" #include #define private public @@ -9,6 +8,7 @@ #include #include +#include #include "renderer.hpp" @@ -52,7 +52,7 @@ Mat3x3 projectCursorBox(CBox& box, eTransform transform, float rotation, const M /* This renders a texture with damage but rotates the texture around a given hotspot. */ -void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, CRegion* damage, float alpha, SP waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch) { +void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, const CRegion& damage, float alpha, SP waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch) { TRACY_GPU_ZONE("RenderDynamicCursor"); if (waitTimeline != nullptr) { @@ -64,7 +64,7 @@ void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, CRegion alpha = std::clamp(alpha, 0.f, 1.f); - if (damage->empty()) + if (damage.empty()) return; CBox newBox = *pBox; @@ -129,7 +129,7 @@ void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, CRegion if (g_pHyprOpenGL->m_RenderData.clipBox.width != 0 && g_pHyprOpenGL->m_RenderData.clipBox.height != 0) { CRegion damageClip{g_pHyprOpenGL->m_RenderData.clipBox.x, g_pHyprOpenGL->m_RenderData.clipBox.y, g_pHyprOpenGL->m_RenderData.clipBox.width, g_pHyprOpenGL->m_RenderData.clipBox.height}; - damageClip.intersect(*damage); + damageClip.intersect(damage); if (!damageClip.empty()) { for (auto& RECT : damageClip.getRects()) { @@ -138,7 +138,7 @@ void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, CRegion } } } else { - for (auto& RECT : damage->getRects()) { + for (auto& RECT : damage.getRects()) { g_pHyprOpenGL->scissor(&RECT); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } diff --git a/src/render/renderer.hpp b/src/render/renderer.hpp new file mode 100644 index 0000000..d265d15 --- /dev/null +++ b/src/render/renderer.hpp @@ -0,0 +1,4 @@ +#include +#include + +void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, const CRegion& damage, float alpha, SP waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch); diff --git a/src/renderer.hpp b/src/renderer.hpp deleted file mode 100644 index 81dc1ff..0000000 --- a/src/renderer.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#include -#include - -void renderCursorTextureInternalWithDamage(SP tex, CBox* pBox, CRegion* damage, float alpha, SP waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch);