aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-01-28 23:42:39 +0000
committerVaxry <[email protected]>2024-01-28 23:42:49 +0000
commit4b4bd90b1450cbfc01d9ac429363cc7cecd6be8b (patch)
tree2bd9ed05ec3de181e9bb5194605b583762ae167e
parent7009dc9184317b7c68032fd733dfed268bc6c543 (diff)
downloadHyprland-4b4bd90b1450cbfc01d9ac429363cc7cecd6be8b.tar.gz
Hyprland-4b4bd90b1450cbfc01d9ac429363cc7cecd6be8b.zip
renderer: fixup misaligned fsv1 surfaces with uv
fixes #4548
-rw-r--r--src/render/Renderer.cpp28
-rw-r--r--src/render/Renderer.hpp2
2 files changed, 21 insertions, 9 deletions
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 15dac3cc..38b5d151 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -105,19 +105,22 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data)
if (windowBox.width <= 1 || windowBox.height <= 1)
return; // invisible
- g_pHyprRenderer->calculateUVForSurface(RDATA->pWindow, surface, RDATA->surface == surface);
-
windowBox.scale(RDATA->pMonitor->scale);
windowBox.round();
+ const bool MISALIGNEDFSV1 = std::floor(RDATA->pMonitor->scale) != RDATA->pMonitor->scale /* Fractional */ && surface->current.scale == 1 /* fs protocol */ &&
+ windowBox.size() != Vector2D{surface->current.buffer_width, surface->current.buffer_height} /* misaligned */ &&
+ DELTALESSTHAN(windowBox.width, surface->current.buffer_width, 3) && DELTALESSTHAN(windowBox.height, surface->current.buffer_height, 3) /* off by one-or-two */ &&
+ (!RDATA->pWindow || (!RDATA->pWindow->m_vRealSize.isBeingAnimated() && !INTERACTIVERESIZEINPROGRESS)) /* not window or not animated/resizing */;
+
+ g_pHyprRenderer->calculateUVForSurface(RDATA->pWindow, surface, RDATA->surface == surface, windowBox.size(), MISALIGNEDFSV1);
+
// check for fractional scale surfaces misaligning the buffer size
// in those cases it's better to just force nearest neighbor
- // as long as the window is not animated. During those it'd look weird
+ // as long as the window is not animated. During those it'd look weird.
+ // UV will fixup it as well
const auto NEARESTNEIGHBORSET = g_pHyprOpenGL->m_RenderData.useNearestNeighbor;
- if (std::floor(RDATA->pMonitor->scale) != RDATA->pMonitor->scale /* Fractional */ && surface->current.scale == 1 /* fs protocol */ &&
- windowBox.size() != Vector2D{surface->current.buffer_width, surface->current.buffer_height} /* misaligned */ &&
- DELTALESSTHAN(windowBox.width, surface->current.buffer_width, 3) && DELTALESSTHAN(windowBox.height, surface->current.buffer_height, 3) /* off by one-or-two */ &&
- (!RDATA->pWindow || (!RDATA->pWindow->m_vRealSize.isBeingAnimated() && !INTERACTIVERESIZEINPROGRESS)) /* not window or not animated/resizing */)
+ if (MISALIGNEDFSV1)
g_pHyprOpenGL->m_RenderData.useNearestNeighbor = true;
float rounding = RDATA->rounding;
@@ -806,7 +809,7 @@ void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now) {
}
}
-void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurface, bool main) {
+void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurface, bool main, const Vector2D& projSize, bool fixMisalignedFSV1) {
if (!pWindow || !pWindow->m_bIsX11) {
Vector2D uvTL;
Vector2D uvBR = Vector2D(1, 1);
@@ -828,6 +831,15 @@ void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurfac
}
}
+ if (projSize != Vector2D{} && fixMisalignedFSV1) {
+ // instead of nearest_neighbor (we will repeat / skip)
+ // just cut off / expand surface
+ const Vector2D PIXELASUV = Vector2D{1, 1} / Vector2D{pSurface->buffer->texture->width, pSurface->buffer->texture->height};
+ const Vector2D MISALIGNMENT = Vector2D{pSurface->buffer->texture->width, pSurface->buffer->texture->height} - projSize;
+ if (MISALIGNMENT != Vector2D{})
+ uvBR -= MISALIGNMENT * PIXELASUV;
+ }
+
g_pHyprOpenGL->m_RenderData.primarySurfaceUVTopLeft = uvTL;
g_pHyprOpenGL->m_RenderData.primarySurfaceUVBottomRight = uvBR;
diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp
index d83e772b..f77bf36e 100644
--- a/src/render/Renderer.hpp
+++ b/src/render/Renderer.hpp
@@ -57,7 +57,7 @@ class CHyprRenderer {
void ensureCursorRenderingMode();
bool shouldRenderCursor();
void setCursorHidden(bool hide);
- void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false);
+ void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false);
std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min
void renderLockscreen(CMonitor* pMonitor, timespec* now);
void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace);