Skip to content

Commit

Permalink
add scheduleFrame reasons (#6799)
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 authored and vaxerski committed Jul 20, 2024
1 parent aa6ae13 commit 8ea0633
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "managers/PointerManager.hpp"
#include "managers/SeatManager.hpp"
#include "managers/eventLoop/EventLoopManager.hpp"
#include <aquamarine/output/Output.hpp>
#include <random>
#include <cstring>
#include <unordered_set>
Expand Down Expand Up @@ -2373,7 +2374,7 @@ void CCompositor::updateWorkspaceWindowData(const int& id) {
}
}

void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor) {
void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor, IOutput::scheduleFrameReason reason) {
if ((m_pAqBackend->hasSession() && !m_pAqBackend->session->active) || !m_bSessionActive)
return;

Expand All @@ -2383,7 +2384,7 @@ void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor) {
if (pMonitor->renderingActive)
pMonitor->pendingFrame = true;

pMonitor->output->scheduleFrame();
pMonitor->output->scheduleFrame(reason);
}

PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp) {
Expand Down Expand Up @@ -2966,7 +2967,7 @@ void CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) {
g_pCompositor->m_bReadyToProcess = true;

g_pConfigManager->m_bWantsMonitorReload = true;
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR.get());
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR.get(), IOutput::AQ_SCHEDULE_NEW_MONITOR);

checkDefaultCursorWarp(PNEWMONITOR, output->name);

Expand Down
2 changes: 1 addition & 1 deletion src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CCompositor {
void setWindowFullscreen(PHLWINDOW, bool, eFullscreenMode mode = FULLSCREEN_INVALID);
void updateFullscreenFadeOnWorkspace(PHLWORKSPACE);
PHLWINDOW getX11Parent(PHLWINDOW);
void scheduleFrameForMonitor(CMonitor*);
void scheduleFrameForMonitor(CMonitor*, Aquamarine::IOutput::scheduleFrameReason reason = Aquamarine::IOutput::AQ_SCHEDULE_CLIENT_UNKNOWN);
void addToFadingOutSafe(PHLLS);
void removeFromFadingOutSafe(PHLLS);
void addToFadingOutSafe(PHLWINDOW);
Expand Down
3 changes: 2 additions & 1 deletion src/events/Monitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Events.hpp"
#include "../debug/HyprCtl.hpp"
#include "../config/ConfigValue.hpp"
#include <aquamarine/output/Output.hpp>

// --------------------------------------------------------- //
// __ __ ____ _ _ _____ _______ ____ _____ _____ //
Expand Down Expand Up @@ -110,7 +111,7 @@ void Events::listener_monitorDestroy(void* owner, void* data) {
void Events::listener_monitorNeedsFrame(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;

g_pCompositor->scheduleFrameForMonitor(PMONITOR);
g_pCompositor->scheduleFrameForMonitor(PMONITOR, Aquamarine::IOutput::AQ_SCHEDULE_NEEDS_FRAME);
}

void Events::listener_monitorCommit(void* owner, void* data) {
Expand Down
22 changes: 12 additions & 10 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../protocols/core/Output.hpp"
#include "../managers/PointerManager.hpp"
#include "sync/SyncTimeline.hpp"
#include <aquamarine/output/Output.hpp>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;

Expand All @@ -35,11 +36,12 @@ void CMonitor::onConnect(bool noRule) {
outTimeline = CSyncTimeline::create(output->getBackend()->drmFD());
}

listeners.frame = output->events.frame.registerListener([this](std::any d) { Events::listener_monitorFrame(this, nullptr); });
listeners.destroy = output->events.destroy.registerListener([this](std::any d) { Events::listener_monitorDestroy(this, nullptr); });
listeners.commit = output->events.commit.registerListener([this](std::any d) { Events::listener_monitorCommit(this, nullptr); });
listeners.needsFrame = output->events.needsFrame.registerListener([this](std::any d) { g_pCompositor->scheduleFrameForMonitor(this); });
listeners.presented = output->events.present.registerListener([this](std::any d) {
listeners.frame = output->events.frame.registerListener([this](std::any d) { Events::listener_monitorFrame(this, nullptr); });
listeners.destroy = output->events.destroy.registerListener([this](std::any d) { Events::listener_monitorDestroy(this, nullptr); });
listeners.commit = output->events.commit.registerListener([this](std::any d) { Events::listener_monitorCommit(this, nullptr); });
listeners.needsFrame =
output->events.needsFrame.registerListener([this](std::any d) { g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_NEEDS_FRAME); });
listeners.presented = output->events.present.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IOutput::SPresentEvent>(d);
PROTO::presentation->onPresented(this, E.when, E.refresh, E.seq, E.flags);
});
Expand Down Expand Up @@ -197,7 +199,7 @@ void CMonitor::onConnect(bool noRule) {

renderTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ratHandler, this);

g_pCompositor->scheduleFrameForMonitor(this);
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_NEW_MONITOR);

PROTO::gamma->applyGammaToState(this);

Expand Down Expand Up @@ -325,9 +327,9 @@ void CMonitor::addDamage(const pixman_region32_t* rg) {
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) {
damage.damageEntire();
g_pCompositor->scheduleFrameForMonitor(this);
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);
} else if (damage.damage(rg))
g_pCompositor->scheduleFrameForMonitor(this);
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);
}

void CMonitor::addDamage(const CRegion* rg) {
Expand All @@ -338,11 +340,11 @@ void CMonitor::addDamage(const CBox* box) {
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) {
damage.damageEntire();
g_pCompositor->scheduleFrameForMonitor(this);
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);
}

if (damage.damage(*box))
g_pCompositor->scheduleFrameForMonitor(this);
g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);
}

bool CMonitor::shouldSkipScheduleFrameOnMouseEvent() {
Expand Down
2 changes: 1 addition & 1 deletion src/managers/AnimationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void CAnimationManager::tick() {

// manually schedule a frame
if (PMONITOR)
g_pCompositor->scheduleFrameForMonitor(PMONITOR);
g_pCompositor->scheduleFrameForMonitor(PMONITOR, Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);
}

// do it here, because if this alters the animation vars deque we would be in trouble above.
Expand Down
2 changes: 1 addition & 1 deletion src/managers/CursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void CCursorManager::updateTheme() {

for (auto& m : g_pCompositor->m_vMonitors) {
m->forceFullFrames = 5;
g_pCompositor->scheduleFrameForMonitor(m.get());
g_pCompositor->scheduleFrameForMonitor(m.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/managers/PointerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ bool CPointerManager::setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquam

state->cursorFrontBuffer = buf;

g_pCompositor->scheduleFrameForMonitor(state->monitor.get());
g_pCompositor->scheduleFrameForMonitor(state->monitor.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);

return true;
}
Expand Down
5 changes: 3 additions & 2 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "InputManager.hpp"
#include "../../Compositor.hpp"
#include <aquamarine/output/Output.hpp>
#include <cstdint>
#include <ranges>
#include "../../config/ConfigValue.hpp"
Expand Down Expand Up @@ -191,7 +192,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
bool skipFrameSchedule = PMONITOR->shouldSkipScheduleFrameOnMouseEvent();

if (!PMONITOR->solitaryClient.lock() && g_pHyprRenderer->shouldRenderCursor() && g_pPointerManager->softwareLockedFor(PMONITOR->self.lock()) && !skipFrameSchedule)
g_pCompositor->scheduleFrameForMonitor(PMONITOR);
g_pCompositor->scheduleFrameForMonitor(PMONITOR, Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_MOVE);

PHLWINDOW forcedFocus = m_pForcedFocus.lock();

Expand Down Expand Up @@ -374,7 +375,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords, &pFoundLayerSurface);

if (g_pPointerManager->softwareLockedFor(PMONITOR->self.lock()) > 0 && !skipFrameSchedule)
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.get());
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_MOVE);

// grabs
if (g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(foundSurface)) {
Expand Down
9 changes: 5 additions & 4 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../Compositor.hpp"
#include "../helpers/math/Math.hpp"
#include <algorithm>
#include <aquamarine/output/Output.hpp>
#include <cstring>
#include "../config/ConfigValue.hpp"
#include "../managers/CursorManager.hpp"
Expand Down Expand Up @@ -1187,7 +1188,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
pMonitor->framesToSkip -= 1;

if (!pMonitor->noFrameSchedule)
g_pCompositor->scheduleFrameForMonitor(pMonitor);
g_pCompositor->scheduleFrameForMonitor(pMonitor, Aquamarine::IOutput::AQ_SCHEDULE_RENDER_MONITOR);
else
Debug::log(LOG, "NoFrameSchedule hit for {}.", pMonitor->szName);

Expand Down Expand Up @@ -1432,7 +1433,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
pMonitor->tearingState.busy = true;

if (*PDAMAGEBLINK || *PVFR == 0 || pMonitor->pendingFrame)
g_pCompositor->scheduleFrameForMonitor(pMonitor);
g_pCompositor->scheduleFrameForMonitor(pMonitor, Aquamarine::IOutput::AQ_SCHEDULE_RENDER_MONITOR);

pMonitor->pendingFrame = false;

Expand Down Expand Up @@ -1750,7 +1751,7 @@ void CHyprRenderer::damageSurface(SP<CWLSurfaceResource> pSurface, double x, dou
damageBox.scale(scale);

// schedule frame events
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->getMonitorFromVector(Vector2D(x, y)));
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->getMonitorFromVector(Vector2D(x, y)), Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);

if (damageBox.empty())
return;
Expand Down Expand Up @@ -1868,7 +1869,7 @@ void CHyprRenderer::damageMirrorsWith(CMonitor* pMonitor, const CRegion& pRegion

mirror->addDamage(&transformed);

g_pCompositor->scheduleFrameForMonitor(mirror);
g_pCompositor->scheduleFrameForMonitor(mirror, Aquamarine::IOutput::AQ_SCHEDULE_DAMAGE);
}
}

Expand Down

0 comments on commit 8ea0633

Please sign in to comment.