From 97e82afd4de3b81d08744352dc6a3eca8d9d7cb6 Mon Sep 17 00:00:00 2001 From: Oskari Alaranta Date: Sat, 30 May 2026 18:29:49 +0300 Subject: [PATCH] Optimize {,Shm}PutImage Don't calculate clipping when its not needed. This can still be improved by a ton, but it can wait :) --- xbanan/Image.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/xbanan/Image.cpp b/xbanan/Image.cpp index 0640c7d..b941fe7 100644 --- a/xbanan/Image.cpp +++ b/xbanan/Image.cpp @@ -60,8 +60,33 @@ void put_image(const PutImageInfo& info) } case ZPixmap: { + bool needs_clipping = true; + + if (info.gc.clip_mask == None) + { + needs_clipping = false; + } + else if (info.gc.clip_mask == UINT32_MAX) + { + const uint32_t clip_min_x = min_x - info.gc.clip_origin_x; + const uint32_t clip_min_y = min_y - info.gc.clip_origin_y; + + const uint32_t clip_max_x = max_x - info.gc.clip_origin_x; + const uint32_t clip_max_y = max_y - info.gc.clip_origin_y; + + for (const auto& rect : info.gc.clip_rects) + { + if (clip_min_x < rect.x || clip_max_x > rect.x + rect.width) + continue; + if (clip_min_y < rect.y || clip_max_y > rect.y + rect.height) + continue; + needs_clipping = false; + break; + } + } + ASSERT(info.left_pad == 0); - if (in_bpp == 32 && info.gc.clip_mask == None) + if (in_bpp == 32 && !needs_clipping) { const auto bytes_per_row = (max_x - min_x) * 4; for (int32_t y = min_y; y < max_y; y++)