From 2cc3f9cdeefd2a3df064f72df7d9fb4dbf5dcb9a Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 14 Aug 2024 11:46:36 +0300 Subject: [PATCH] Avoid issuing many glTexSubImage2D() calls when uploading shm contents Applications that use QtWidgets can have a lot of rectangles in the damage region. For example, when you navigate between directories in Dolphin, each individual file or folder item will be added to the damage region rather than the container view where they are. On the other hand, issuing multiple glTexSubImage2D() function calls is not great because it means stalling the cpu until the texture upload completes. This change attempts to improve that by simplifying the input damage. If the input damage isn't complex, use it as is; otherwise use its bounding rect. The gains are not impressive. On my machine, I see fewer 5ms texture upload time spikes when navigating in Dolphin, now I can observe 4ms spikes instead. Still, I believe the change is reasonable enough. --- .../scenes/opengl/basiceglsurfacetexture_wayland.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/platformsupport/scenes/opengl/basiceglsurfacetexture_wayland.cpp b/src/platformsupport/scenes/opengl/basiceglsurfacetexture_wayland.cpp index d22474702e..9f05c32724 100644 --- a/src/platformsupport/scenes/opengl/basiceglsurfacetexture_wayland.cpp +++ b/src/platformsupport/scenes/opengl/basiceglsurfacetexture_wayland.cpp @@ -86,6 +86,15 @@ bool BasicEGLSurfaceTextureWayland::loadShmTexture(GraphicsBuffer *buffer) return true; } +static QRegion simplifyDamage(const QRegion &damage) +{ + if (damage.rectCount() < 3) { + return damage; + } else { + return damage.boundingRect(); + } +} + void BasicEGLSurfaceTextureWayland::updateShmTexture(GraphicsBuffer *buffer, const QRegion ®ion) { if (Q_UNLIKELY(m_bufferType != BufferType::Shm)) { @@ -99,7 +108,8 @@ void BasicEGLSurfaceTextureWayland::updateShmTexture(GraphicsBuffer *buffer, con return; } - for (const QRect &rect : region) { + const QRegion simplifiedDamage = simplifyDamage(region); + for (const QRect &rect : simplifiedDamage) { m_texture.planes[0]->update(*view.image(), rect.topLeft(), rect); } }