Skip to content

Commit

Permalink
output: add scheduleFrame reasons (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 authored Jul 7, 2024
1 parent 946c756 commit a473c53
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/aquamarine/backend/DRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace Aquamarine {
virtual Hyprutils::Memory::CSharedPointer<IBackendImplementation> getBackend();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> 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();
Expand Down
2 changes: 1 addition & 1 deletion include/aquamarine/backend/Headless.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Aquamarine {
virtual bool commit();
virtual bool test();
virtual Hyprutils::Memory::CSharedPointer<IBackendImplementation> getBackend();
virtual void scheduleFrame();
virtual void scheduleFrame(const scheduleFrameReason reason = AQ_SCHEDULE_UNKNOWN);
virtual bool destroy();

Hyprutils::Memory::CWeakPointer<CHeadlessOutput> self;
Expand Down
2 changes: 1 addition & 1 deletion include/aquamarine/backend/Wayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Aquamarine {
virtual Hyprutils::Memory::CSharedPointer<IBackendImplementation> getBackend();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> 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();

Expand Down
15 changes: 14 additions & 1 deletion include/aquamarine/output/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBackendImplementation> getBackend() = 0;
Expand All @@ -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!!!

Expand Down
5 changes: 4 additions & 1 deletion src/backend/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <time.h>
#include <sys/timerfd.h>
#include <string.h>
#include "Shared.hpp"

using namespace Aquamarine;
using namespace Hyprutils::Memory;
Expand Down Expand Up @@ -53,7 +54,9 @@ Hyprutils::Memory::CSharedPointer<IBackendImplementation> 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;

Expand Down
4 changes: 3 additions & 1 deletion src/backend/Wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "aquamarine/output/Output.hpp"
#include <aquamarine/backend/DRM.hpp>
#include <aquamarine/backend/drm/Legacy.hpp>
#include <aquamarine/backend/drm/Atomic.hpp>
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1298,7 +1299,7 @@ bool Aquamarine::CDRMOutput::setCursor(SP<IBuffer> buffer, const Vector2D& hotsp
}

needsFrame = true;
scheduleFrame();
scheduleFrame(AQ_SCHEDULE_CURSOR_SHAPE);
return true;
}

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/backend/drm/impl/Atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <xf86drmMode.h>
#include <sys/mman.h>
#include "Shared.hpp"
#include "aquamarine/output/Output.hpp"

using namespace Aquamarine;
using namespace Hyprutils::Memory;
Expand Down Expand Up @@ -323,7 +324,7 @@ bool Aquamarine::CDRMAtomicImpl::moveCursor(SP<SDRMConnector> connector) {
return true;

connector->output->needsFrame = true;
connector->output->scheduleFrame();
connector->output->scheduleFrame(IOutput::AQ_SCHEDULE_CURSOR_MOVE);

return true;
}
3 changes: 2 additions & 1 deletion src/backend/drm/impl/Legacy.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "aquamarine/output/Output.hpp"
#include <aquamarine/backend/drm/Legacy.hpp>
#include <cstring>
#include <xf86drm.h>
Expand All @@ -18,7 +19,7 @@ bool Aquamarine::CDRMLegacyImpl::moveCursor(Hyprutils::Memory::CSharedPointer<SD
return true;

connector->output->needsFrame = true;
connector->output->scheduleFrame();
connector->output->scheduleFrame(IOutput::AQ_SCHEDULE_CURSOR_MOVE);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/output/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void Aquamarine::IOutput::setCursorVisible(bool visible) {
;
}

void Aquamarine::IOutput::scheduleFrame() {
void Aquamarine::IOutput::scheduleFrame(const scheduleFrameReason reason) {
;
}

Expand Down

0 comments on commit a473c53

Please sign in to comment.