From a473c5313de82604dc95c32fb2f7bfbc6c494ffe Mon Sep 17 00:00:00 2001 From: UjinT34 <41110182+UjinT34@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:05:05 +0300 Subject: [PATCH] output: add scheduleFrame reasons (#7) --- include/aquamarine/backend/DRM.hpp | 2 +- include/aquamarine/backend/Headless.hpp | 2 +- include/aquamarine/backend/Wayland.hpp | 2 +- include/aquamarine/output/Output.hpp | 15 ++++++++++++++- src/backend/Headless.cpp | 5 ++++- src/backend/Wayland.cpp | 4 +++- src/backend/drm/DRM.cpp | 12 ++++++++---- src/backend/drm/impl/Atomic.cpp | 3 ++- src/backend/drm/impl/Legacy.cpp | 3 ++- src/output/Output.cpp | 2 +- 10 files changed, 37 insertions(+), 13 deletions(-) diff --git a/include/aquamarine/backend/DRM.hpp b/include/aquamarine/backend/DRM.hpp index e4e7b00..3f34473 100644 --- a/include/aquamarine/backend/DRM.hpp +++ b/include/aquamarine/backend/DRM.hpp @@ -187,7 +187,7 @@ namespace Aquamarine { virtual Hyprutils::Memory::CSharedPointer getBackend(); virtual bool setCursor(Hyprutils::Memory::CSharedPointer buffer, const Hyprutils::Math::Vector2D& hotspot); virtual void moveCursor(const Hyprutils::Math::Vector2D& coord); - virtual void scheduleFrame(); + virtual void scheduleFrame(const scheduleFrameReason reason = AQ_SCHEDULE_UNKNOWN); virtual void setCursorVisible(bool visible); virtual Hyprutils::Math::Vector2D cursorPlaneSize(); virtual size_t getGammaSize(); diff --git a/include/aquamarine/backend/Headless.hpp b/include/aquamarine/backend/Headless.hpp index f95d3f2..24d4237 100644 --- a/include/aquamarine/backend/Headless.hpp +++ b/include/aquamarine/backend/Headless.hpp @@ -15,7 +15,7 @@ namespace Aquamarine { virtual bool commit(); virtual bool test(); virtual Hyprutils::Memory::CSharedPointer getBackend(); - virtual void scheduleFrame(); + virtual void scheduleFrame(const scheduleFrameReason reason = AQ_SCHEDULE_UNKNOWN); virtual bool destroy(); Hyprutils::Memory::CWeakPointer self; diff --git a/include/aquamarine/backend/Wayland.hpp b/include/aquamarine/backend/Wayland.hpp index 7cdd7ea..0758923 100644 --- a/include/aquamarine/backend/Wayland.hpp +++ b/include/aquamarine/backend/Wayland.hpp @@ -46,7 +46,7 @@ namespace Aquamarine { virtual Hyprutils::Memory::CSharedPointer getBackend(); virtual bool setCursor(Hyprutils::Memory::CSharedPointer buffer, const Hyprutils::Math::Vector2D& hotspot); virtual void moveCursor(const Hyprutils::Math::Vector2D& coord); - virtual void scheduleFrame(); + virtual void scheduleFrame(const scheduleFrameReason reason = AQ_SCHEDULE_UNKNOWN); virtual Hyprutils::Math::Vector2D cursorPlaneSize(); virtual bool destroy(); diff --git a/include/aquamarine/output/Output.hpp b/include/aquamarine/output/Output.hpp index c38127f..cfbdf81 100644 --- a/include/aquamarine/output/Output.hpp +++ b/include/aquamarine/output/Output.hpp @@ -100,6 +100,19 @@ namespace Aquamarine { ; } + enum scheduleFrameReason : uint32_t { + AQ_SCHEDULE_UNKNOWN = 0, + AQ_SCHEDULE_NEW_CONNECTOR, + AQ_SCHEDULE_CURSOR_VISIBLE, + AQ_SCHEDULE_CURSOR_SHAPE, + AQ_SCHEDULE_CURSOR_MOVE, + AQ_SCHEDULE_CLIENT_UNKNOWN, + AQ_SCHEDULE_DAMAGE, + AQ_SCHEDULE_NEW_MONITOR, + AQ_SCHEDULE_RENDER_MONITOR, + AQ_SCHEDULE_NEEDS_FRAME, + }; + virtual bool commit() = 0; virtual bool test() = 0; virtual Hyprutils::Memory::CSharedPointer getBackend() = 0; @@ -108,7 +121,7 @@ namespace Aquamarine { virtual void moveCursor(const Hyprutils::Math::Vector2D& coord); // includes the hotspot virtual void setCursorVisible(bool visible); // moving the cursor will make it visible again without this util virtual Hyprutils::Math::Vector2D cursorPlaneSize(); // -1, -1 means no set size, 0, 0 means error - virtual void scheduleFrame(); + virtual void scheduleFrame(const scheduleFrameReason reason = AQ_SCHEDULE_UNKNOWN); virtual size_t getGammaSize(); virtual bool destroy(); // not all backends allow this!!! diff --git a/src/backend/Headless.cpp b/src/backend/Headless.cpp index c66c245..bd6ba11 100644 --- a/src/backend/Headless.cpp +++ b/src/backend/Headless.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "Shared.hpp" using namespace Aquamarine; using namespace Hyprutils::Memory; @@ -53,7 +54,9 @@ Hyprutils::Memory::CSharedPointer Aquamarine::CHeadlessO return backend.lock(); } -void Aquamarine::CHeadlessOutput::scheduleFrame() { +void Aquamarine::CHeadlessOutput::scheduleFrame(const scheduleFrameReason reason) { + TRACE(backend->backend->log(AQ_LOG_TRACE, + std::format("CHeadlessOutput::scheduleFrame: reason {}, needsFrame {}, frameScheduled {}", (uint32_t)reason, needsFrame, frameScheduled))); // FIXME: limit fps to the committed framerate. needsFrame = true; diff --git a/src/backend/Wayland.cpp b/src/backend/Wayland.cpp index 537e12b..364b768 100644 --- a/src/backend/Wayland.cpp +++ b/src/backend/Wayland.cpp @@ -723,7 +723,9 @@ Hyprutils::Math::Vector2D Aquamarine::CWaylandOutput::cursorPlaneSize() { return {-1, -1}; // no limit } -void Aquamarine::CWaylandOutput::scheduleFrame() { +void Aquamarine::CWaylandOutput::scheduleFrame(const scheduleFrameReason reason) { + TRACE(backend->backend->log(AQ_LOG_TRACE, + std::format("CWaylandOutput::scheduleFrame: reason {}, needsFrame {}, frameScheduled {}", (uint32_t)reason, needsFrame, frameScheduled))); needsFrame = true; if (frameScheduled) diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 7b5e237..83d53a6 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1,3 +1,4 @@ +#include "aquamarine/output/Output.hpp" #include #include #include @@ -1065,7 +1066,7 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) { output->swapchain = CSwapchain::create(backend->backend->allocator, backend->self.lock()); backend->backend->events.newOutput.emit(output); - output->scheduleFrame(); + output->scheduleFrame(IOutput::AQ_SCHEDULE_NEW_CONNECTOR); } void Aquamarine::SDRMConnector::disconnect() { @@ -1136,7 +1137,7 @@ bool Aquamarine::CDRMOutput::test() { void Aquamarine::CDRMOutput::setCursorVisible(bool visible) { cursorVisible = visible; needsFrame = true; - scheduleFrame(); + scheduleFrame(AQ_SCHEDULE_CURSOR_VISIBLE); } bool Aquamarine::CDRMOutput::commitState(bool onlyTest) { @@ -1298,7 +1299,7 @@ bool Aquamarine::CDRMOutput::setCursor(SP buffer, const Vector2D& hotsp } needsFrame = true; - scheduleFrame(); + scheduleFrame(AQ_SCHEDULE_CURSOR_SHAPE); return true; } @@ -1308,7 +1309,10 @@ void Aquamarine::CDRMOutput::moveCursor(const Vector2D& coord) { backend->impl->moveCursor(connector); } -void Aquamarine::CDRMOutput::scheduleFrame() { +void Aquamarine::CDRMOutput::scheduleFrame(const scheduleFrameReason reason) { + TRACE(backend->backend->log(AQ_LOG_TRACE, + std::format("CDRMOutput::scheduleFrame: reason {}, needsFrame {}, isPageFlipPending {}, frameEventScheduled {}", (uint32_t)reason, needsFrame, + connector->isPageFlipPending, connector->frameEventScheduled))); needsFrame = true; if (connector->isPageFlipPending || connector->frameEventScheduled) diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index e6efec1..6869956 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -4,6 +4,7 @@ #include #include #include "Shared.hpp" +#include "aquamarine/output/Output.hpp" using namespace Aquamarine; using namespace Hyprutils::Memory; @@ -323,7 +324,7 @@ bool Aquamarine::CDRMAtomicImpl::moveCursor(SP connector) { return true; connector->output->needsFrame = true; - connector->output->scheduleFrame(); + connector->output->scheduleFrame(IOutput::AQ_SCHEDULE_CURSOR_MOVE); return true; } \ No newline at end of file diff --git a/src/backend/drm/impl/Legacy.cpp b/src/backend/drm/impl/Legacy.cpp index dac16e0..bb7f47e 100644 --- a/src/backend/drm/impl/Legacy.cpp +++ b/src/backend/drm/impl/Legacy.cpp @@ -1,3 +1,4 @@ +#include "aquamarine/output/Output.hpp" #include #include #include @@ -18,7 +19,7 @@ bool Aquamarine::CDRMLegacyImpl::moveCursor(Hyprutils::Memory::CSharedPointeroutput->needsFrame = true; - connector->output->scheduleFrame(); + connector->output->scheduleFrame(IOutput::AQ_SCHEDULE_CURSOR_MOVE); return true; } diff --git a/src/output/Output.cpp b/src/output/Output.cpp index a8a867c..bad45ea 100644 --- a/src/output/Output.cpp +++ b/src/output/Output.cpp @@ -23,7 +23,7 @@ void Aquamarine::IOutput::setCursorVisible(bool visible) { ; } -void Aquamarine::IOutput::scheduleFrame() { +void Aquamarine::IOutput::scheduleFrame(const scheduleFrameReason reason) { ; }