Browse Source

wayland: Release the SHM pool after initial cursor buffer creation

The backing memory will be automatically unmapped when the buffer objects are destroyed, so no need to keep the pool around.
Frank Praznik 4 months ago
parent
commit
b3060956c3
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/video/wayland/SDL_waylandmouse.c

+ 6 - 7
src/video/wayland/SDL_waylandmouse.c

@@ -65,7 +65,6 @@ typedef struct
     int hot_x;
     int hot_x;
     int hot_y;
     int hot_y;
 
 
-    Wayland_SHMPool *shmPool;
     int images_per_frame;
     int images_per_frame;
     CustomCursorImage images[];
     CustomCursorImage images[];
 } Wayland_CustomCursor;
 } Wayland_CustomCursor;
@@ -736,6 +735,7 @@ static SDL_Cursor *Wayland_CreateAnimatedCursor(SDL_CursorFrameInfo *frames, int
     }
     }
 
 
     SDL_CursorData *data = NULL;
     SDL_CursorData *data = NULL;
+    Wayland_SHMPool *shm_pool = NULL;
     int pool_size = 0;
     int pool_size = 0;
     int max_images = 0;
     int max_images = 0;
     bool is_stack = false;
     bool is_stack = false;
@@ -773,8 +773,8 @@ static SDL_Cursor *Wayland_CreateAnimatedCursor(SDL_CursorFrameInfo *frames, int
         goto failed;
         goto failed;
     }
     }
 
 
-    data->cursor_data.custom.shmPool = Wayland_AllocSHMPool(pool_size);
-    if (!data->cursor_data.custom.shmPool) {
+    shm_pool = Wayland_AllocSHMPool(pool_size);
+    if (!shm_pool) {
         goto failed;
         goto failed;
     }
     }
 
 
@@ -812,7 +812,7 @@ static SDL_Cursor *Wayland_CreateAnimatedCursor(SDL_CursorFrameInfo *frames, int
             data->cursor_data.custom.images[offset + j].height = surface->h;
             data->cursor_data.custom.images[offset + j].height = surface->h;
 
 
             void *buf_data;
             void *buf_data;
-            data->cursor_data.custom.images[offset + j].buffer = Wayland_AllocBufferFromPool(data->cursor_data.custom.shmPool, surface->w, surface->h, &buf_data);
+            data->cursor_data.custom.images[offset + j].buffer = Wayland_AllocBufferFromPool(shm_pool, surface->w, surface->h, &buf_data);
             // Wayland requires premultiplied alpha for its surfaces.
             // Wayland requires premultiplied alpha for its surfaces.
             SDL_PremultiplyAlpha(surface->w, surface->h,
             SDL_PremultiplyAlpha(surface->w, surface->h,
                                  surface->format, surface->pixels, surface->pitch,
                                  surface->format, surface->pixels, surface->pitch,
@@ -828,12 +828,13 @@ static SDL_Cursor *Wayland_CreateAnimatedCursor(SDL_CursorFrameInfo *frames, int
     }
     }
 
 
     SDL_small_free(surfaces, is_stack);
     SDL_small_free(surfaces, is_stack);
+    Wayland_ReleaseSHMPool(shm_pool);
 
 
     return cursor;
     return cursor;
 
 
 failed:
 failed:
+    Wayland_ReleaseSHMPool(shm_pool);
     if (data) {
     if (data) {
-        Wayland_ReleaseSHMPool(data->cursor_data.custom.shmPool);
         SDL_free(data->frame_durations_ms);
         SDL_free(data->frame_durations_ms);
         for (int i = 0; i < data->cursor_data.custom.images_per_frame * frame_count; ++i) {
         for (int i = 0; i < data->cursor_data.custom.images_per_frame * frame_count; ++i) {
             if (data->cursor_data.custom.images[i].buffer) {
             if (data->cursor_data.custom.images[i].buffer) {
@@ -922,8 +923,6 @@ static void Wayland_FreeCursorData(SDL_CursorData *d)
                 wl_buffer_destroy(d->cursor_data.custom.images[i].buffer);
                 wl_buffer_destroy(d->cursor_data.custom.images[i].buffer);
             }
             }
         }
         }
-
-        Wayland_ReleaseSHMPool(d->cursor_data.custom.shmPool);
     }
     }
 
 
     SDL_free(d->frame_durations_ms);
     SDL_free(d->frame_durations_ms);