add cursor fallback swapchain

This commit is contained in:
UjinT34 2024-07-24 23:13:15 +03:00
parent a0be3de0e8
commit 5115f1993c
3 changed files with 49 additions and 22 deletions

View file

@ -396,6 +396,30 @@ int CMonitor::findAvailableDefaultWS() {
return INT32_MAX; // shouldn't be reachable
}
SP<Aquamarine::CSwapchain> CMonitor::resizeSwapchain(SP<Aquamarine::CSwapchain> swapchain, Vector2D size, bool isCursor) {
if (!swapchain || size != swapchain->currentOptions().size) {
if (!swapchain)
swapchain = Aquamarine::CSwapchain::create(output->getBackend()->preferredAllocator(), output->getBackend());
auto options = swapchain->currentOptions();
options.size = size;
options.length = 2;
options.scanout = true;
options.cursor = isCursor;
options.multigpu = output->getBackend()->preferredAllocator()->drmFD() != g_pCompositor->m_iDRMFD;
// We do not set the format. If it's unset (DRM_FORMAT_INVALID) then the swapchain will pick for us,
// but if it's set, we don't wanna change it.
if (!swapchain->reconfigure(options)) {
Debug::log(TRACE, "Failed to reconfigure {} swapchain", isCursor ? "cursor" : "cursor fallback");
return nullptr;
}
}
return swapchain;
}
void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
// Workspace
std::string newDefaultWorkspaceName = "";
@ -835,6 +859,22 @@ bool CMonitor::attemptDirectScanout() {
return true;
}
bool CMonitor::resizeCursorSwapchain(Vector2D size) {
auto swapchain = resizeSwapchain(cursorSwapchain, size, true);
if (!cursorSwapchain)
cursorSwapchain = swapchain;
return !!swapchain;
}
bool CMonitor::resizeCursorFallbackSwapchain(Vector2D size) {
auto swapchain = resizeSwapchain(cursorFallbackSwapchain, size, false);
if (!cursorFallbackSwapchain)
cursorFallbackSwapchain = swapchain;
return !!swapchain;
}
CMonitorState::CMonitorState(CMonitor* owner) {
m_pOwner = owner;
}

View file

@ -100,6 +100,7 @@ class CMonitor {
std::optional<Vector2D> forceSize;
SP<Aquamarine::SOutputMode> currentMode;
SP<Aquamarine::CSwapchain> cursorSwapchain;
SP<Aquamarine::CSwapchain> cursorFallbackSwapchain;
bool dpmsStatus = true;
bool vrrActive = false; // this can be TRUE even if VRR is not active in the case that this display does not support it.
@ -178,6 +179,8 @@ class CMonitor {
CBox logicalBox();
void scheduleDone();
bool attemptDirectScanout();
bool resizeCursorSwapchain(Vector2D size);
bool resizeCursorFallbackSwapchain(Vector2D size);
bool m_bEnabled = false;
bool m_bRenderingInitPassed = false;
@ -189,10 +192,11 @@ class CMonitor {
}
private:
void setupDefaultWS(const SMonitorRule&);
int findAvailableDefaultWS();
void setupDefaultWS(const SMonitorRule&);
int findAvailableDefaultWS();
SP<Aquamarine::CSwapchain> resizeSwapchain(SP<Aquamarine::CSwapchain> swapchain, Vector2D size, bool isCursor);
wl_event_source* doneSource = nullptr;
wl_event_source* doneSource = nullptr;
struct {
CHyprSignalListener frame;

View file

@ -374,25 +374,8 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
} else
maxSize = cursorSize;
if (!state->monitor->cursorSwapchain || maxSize != state->monitor->cursorSwapchain->currentOptions().size) {
if (!state->monitor->cursorSwapchain)
state->monitor->cursorSwapchain = Aquamarine::CSwapchain::create(state->monitor->output->getBackend()->preferredAllocator(), state->monitor->output->getBackend());
auto options = state->monitor->cursorSwapchain->currentOptions();
options.size = maxSize;
options.length = 2;
options.scanout = true;
options.cursor = true;
options.multigpu = state->monitor->output->getBackend()->preferredAllocator()->drmFD() != g_pCompositor->m_iDRMFD;
// We do not set the format. If it's unset (DRM_FORMAT_INVALID) then the swapchain will pick for us,
// but if it's set, we don't wanna change it.
if (!state->monitor->cursorSwapchain->reconfigure(options)) {
Debug::log(TRACE, "Failed to reconfigure cursor swapchain");
return nullptr;
}
}
if (!state->monitor->resizeCursorSwapchain(maxSize))
return nullptr;
// if we already rendered the cursor, revert the swapchain to avoid rendering the cursor over
// the current front buffer