fix: use new render scheduling like hl

fixes #48
This commit is contained in:
Virt 2024-12-26 19:24:35 +01:00
commit 38c1d00f3c
8 changed files with 127 additions and 20 deletions

View file

@ -1,8 +1,3 @@
#include "config/config.hpp"
#include "mode/Mode.hpp"
#include "src/debug/Log.hpp"
#include "src/helpers/math/Math.hpp"
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -10,19 +5,28 @@
#include <hyprlang.hpp>
#include <gbm.h>
#include <hyprland/src/managers/eventLoop/EventLoopTimer.hpp> // required so we don't "unprivate" chrono
#define private public
#include <hyprland/src/managers/CursorManager.hpp>
#include <hyprland/src/managers/PointerManager.hpp>
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/Compositor.hpp>
#undef private
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/protocols/core/Compositor.hpp>
#include <hyprland/src/protocols/core/Seat.hpp>
#include <hyprland/src/debug/Log.hpp>
#include <hyprland/src/helpers/math/Math.hpp>
#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<CEventLoopTimer> self, void* data) {
if (isEnabled())
@ -120,8 +124,20 @@ void CDynamicCursors::renderSoftware(CPointerManager* pointers, SP<CMonitor> 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<CCursorPassElement>(data));
pointers->currentCursorImage.waitTimeline.reset();
pointers->currentCursorImage.waitPoint = 0;
if (pointers->currentCursorImage.surface)
pointers->currentCursorImage.surface->resource()->frame(now);
@ -298,7 +314,7 @@ SP<Aquamarine::IBuffer> 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();

View file

@ -0,0 +1,47 @@
#include "CursorPassElement.hpp"
#include "renderer.hpp"
#include <hyprland/src/render/pass/TexPassElement.hpp>
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprutils/utils/ScopeGuard.hpp>
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<CBox> CCursorPassElement::boundingBox() {
return data.box.copy().scale(1.F / g_pHyprOpenGL->m_RenderData.pMonitor->scale).round();
}
CRegion CCursorPassElement::opaqueRegion() {
return {}; // TODO:
}
void CCursorPassElement::discard() {
;
}

View file

@ -0,0 +1,41 @@
#pragma once
#include <hyprland/src/render/pass/PassElement.hpp>
#include <optional>
class CWLSurfaceResource;
class CTexture;
class CSyncTimeline;
class CCursorPassElement : public IPassElement {
public:
struct SRenderData {
SP<CTexture> tex;
CBox box;
CRegion damage;
SP<CSyncTimeline> 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<CBox> boundingBox();
virtual CRegion opaqueRegion();
virtual void discard();
virtual const char* passName() {
return "CCursorPassElement";
}
private:
SRenderData data;
};

View file

@ -1,5 +1,4 @@
#include "globals.hpp"
#include "src/debug/Log.hpp"
#include "../globals.hpp"
#include <GLES2/gl2.h>
#define private public
@ -9,6 +8,7 @@
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/debug/Log.hpp>
#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<CTexture> tex, CBox* pBox, CRegion* damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch) {
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, const CRegion& damage, float alpha, SP<CSyncTimeline> 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<CTexture> 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<CTexture> 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<CTexture> 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);
}

4
src/render/renderer.hpp Normal file
View file

@ -0,0 +1,4 @@
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/helpers/math/Math.hpp>
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, const CRegion& damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch);

View file

@ -1,4 +0,0 @@
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/helpers/math/Math.hpp>
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion* damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch);