Skip to content

Commit 7c110cb

Browse files
committed
wayland: Convert alternate images to ARGB8888
The higher-level functions only convert the base image, so alternate scaled images for icons and cursors need to be converted when being copied to the buffers.
1 parent 5447721 commit 7c110cb

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/video/wayland/SDL_waylandmouse.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,18 @@ static Wayland_ScaledCustomCursor *Wayland_CacheScaledCustomCursor(SDL_CursorDat
552552
}
553553
}
554554

555+
if (surface->format != SDL_PIXELFORMAT_ARGB8888) {
556+
SDL_Surface *temp = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
557+
if (temp) {
558+
SDL_DestroySurface(surface);
559+
surface = temp;
560+
} else {
561+
Wayland_ReleaseSHMPool(cache->shmPool);
562+
SDL_free(cache);
563+
return NULL;
564+
}
565+
}
566+
555567
// Wayland requires premultiplied alpha for its surfaces.
556568
SDL_PremultiplyAlpha(surface->w, surface->h,
557569
surface->format, surface->pixels, surface->pitch,

src/video/wayland/SDL_waylandwindow.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,16 +2995,31 @@ bool Wayland_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfa
29952995

29962996
for (int i = 0; i < image_count; ++i) {
29972997
if (images[i]->w == images[i]->h) {
2998+
SDL_Surface *surface = images[i];
29982999
Wayland_SHMBuffer *buffer = &wind->icon_buffers[wind->icon_buffer_count];
29993000

3000-
if (!Wayland_AllocSHMBuffer(images[i]->w, images[i]->h, buffer)) {
3001+
if (!Wayland_AllocSHMBuffer(surface->w, surface->h, buffer)) {
30013002
SDL_SetError("wayland: failed to allocate SHM buffer for the icon");
30023003
goto failure_cleanup;
30033004
}
30043005

3005-
SDL_PremultiplyAlpha(images[i]->w, images[i]->h, images[i]->format, images[i]->pixels, images[i]->pitch, SDL_PIXELFORMAT_ARGB8888, buffer->shm_data, images[i]->w * 4, true);
3006-
const int scale = (int)SDL_ceil((double)images[i]->w / (double)icon->w);
3006+
if (surface->format != SDL_PIXELFORMAT_ARGB8888) {
3007+
surface = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
3008+
if (!surface) {
3009+
goto failure_cleanup;
3010+
}
3011+
}
3012+
3013+
SDL_PremultiplyAlpha(surface->w, surface->h, surface->format, surface->pixels, surface->pitch, SDL_PIXELFORMAT_ARGB8888, buffer->shm_data, surface->w * 4, true);
3014+
3015+
const int scale = (int)SDL_ceil((double)surface->w / (double)icon->w);
30073016
xdg_toplevel_icon_v1_add_buffer(wind->xdg_toplevel_icon_v1, buffer->wl_buffer, scale);
3017+
3018+
// Clean up the temporary conversion surface.
3019+
if (surface != images[i]) {
3020+
SDL_DestroySurface(surface);
3021+
}
3022+
30083023
wind->icon_buffer_count++;
30093024
} else {
30103025
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "wayland: icon width and height must be equal, got %ix%i for image level %i; skipping", images[i]->w, images[i]->h, i);

0 commit comments

Comments
 (0)