diff --git a/src/compositor/wayland_wrapper/wlsurface.cpp b/src/compositor/wayland_wrapper/wlsurface.cpp
index 92acac0c2c7cb57f035e41f26e5f04622d2fc3b0..d516e1db5adb3d211c953e1f9c39172ecb4e7a3d 100644
--- a/src/compositor/wayland_wrapper/wlsurface.cpp
+++ b/src/compositor/wayland_wrapper/wlsurface.cpp
@@ -429,11 +429,11 @@ WaylandSurface::Type Surface::type() const
 bool Surface::isYInverted() const
 {
     bool ret = false;
+    static bool negateReturn = qgetenv("QT_COMPOSITOR_NEGATE_INVERTED_Y").toInt();
+
 #ifdef QT_COMPOSITOR_WAYLAND_GL
     Q_D(const Surface);
 
-    static bool negateReturn = qgetenv("QT_COMPOSITOR_NEGATE_INVERTED_Y").toInt();
-
     if (!d->surfaceBuffer) {
         ret = false;
     } else if (d->compositor->graphicsHWIntegration() && d->surfaceBuffer->handle() && type() != WaylandSurface::Shm) {