From 9996aa209b718f63d793ee79c23c5217ff841222 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 9 Aug 2024 13:01:57 +0200 Subject: [PATCH] (!1654) Xnest: fetch supported pixmap formats from xcb setup data There's even no need to keep our own copies, since we can ask XCB's copy any time. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xnest/Display.c | 16 ++++++---------- hw/xnest/Display.h | 1 - hw/xnest/Init.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/hw/xnest/Display.c b/hw/xnest/Display.c index ec70fe362..2fa678cf2 100644 --- a/hw/xnest/Display.c +++ b/hw/xnest/Display.c @@ -44,7 +44,6 @@ int xnestNumVisuals; int xnestDefaultVisualIndex; Colormap *xnestDefaultColormaps; static uint16_t xnestNumDefaultColormaps; -XPixmapFormatValues *xnestPixmapFormats; int xnestNumPixmapFormats; Drawable xnestDefaultDrawables[MAXDEPTH + 1]; Pixmap xnestIconBitmap; @@ -126,9 +125,6 @@ xnestOpenDisplay(int argc, char *argv[]) xnestVisuals[i].visual->visualid); } - xnestPixmapFormats = XListPixmapFormats(xnestDisplay, - &xnestNumPixmapFormats); - if (xnestParentWindow != (Window) 0) xnestEventMask = XCB_EVENT_MASK_STRUCTURE_NOTIFY; else @@ -137,21 +133,22 @@ xnestOpenDisplay(int argc, char *argv[]) for (i = 0; i <= MAXDEPTH; i++) xnestDefaultDrawables[i] = XCB_WINDOW_NONE; - for (i = 0; i < xnestNumPixmapFormats; i++) { + xcb_format_t *fmt = xcb_setup_pixmap_formats(xnestUpstreamInfo.setup); + const xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length(xnestUpstreamInfo.setup); + for(; fmt != fmtend; ++fmt) { xcb_depth_iterator_t depth_iter; for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo); depth_iter.rem; xcb_depth_next(&depth_iter)) { - if (xnestPixmapFormats[i].depth == 1 || - xnestPixmapFormats[i].depth == depth_iter.data->depth) { + if (fmt->depth == 1 || fmt->depth == depth_iter.data->depth) { uint32_t pixmap = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_pixmap(xnestUpstreamInfo.conn, - xnestPixmapFormats[i].depth, + fmt->depth, pixmap, xnestUpstreamInfo.screenInfo->root, 1, 1); - xnestDefaultDrawables[xnestPixmapFormats[i].depth] = pixmap; + xnestDefaultDrawables[fmt->depth] = pixmap; } } } @@ -210,6 +207,5 @@ xnestCloseDisplay(void) free(xnestDefaultColormaps); XFree(xnestVisuals); - XFree(xnestPixmapFormats); XCloseDisplay(xnestDisplay); } diff --git a/hw/xnest/Display.h b/hw/xnest/Display.h index ed72c71c2..38cbe221b 100644 --- a/hw/xnest/Display.h +++ b/hw/xnest/Display.h @@ -28,7 +28,6 @@ extern int xnestNumVisuals; extern int xnestDefaultVisualIndex; extern Colormap *xnestDefaultColormaps; extern int xnestNumDefaultClormaps; -extern XPixmapFormatValues *xnestPixmapFormats; extern int xnestNumPixmapFormats; extern Drawable xnestDefaultDrawables[MAXDEPTH + 1]; extern Pixmap xnestIconBitmap; diff --git a/hw/xnest/Init.c b/hw/xnest/Init.c index 54e6c9a14..cab90d6bc 100644 --- a/hw/xnest/Init.c +++ b/hw/xnest/Init.c @@ -74,20 +74,23 @@ InitOutput(ScreenInfo * screen_info, int argc, char *argv[]) screen_info->bitmapScanlinePad = xnestUpstreamInfo.setup->bitmap_format_scanline_pad; screen_info->bitmapBitOrder = xnestUpstreamInfo.setup->bitmap_format_bit_order; screen_info->numPixmapFormats = 0; - for (i = 0; i < xnestNumPixmapFormats; i++) { + + xcb_format_t *fmt = xcb_setup_pixmap_formats(xnestUpstreamInfo.setup); + const xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length(xnestUpstreamInfo.setup); + for(; fmt != fmtend; ++fmt) { xcb_depth_iterator_t depth_iter; for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo); depth_iter.rem; xcb_depth_next(&depth_iter)) { - if ((xnestPixmapFormats[i].depth == 1) || - (xnestPixmapFormats[i].depth == depth_iter.data->depth)) { + if ((fmt->depth == 1) || + (fmt->depth == depth_iter.data->depth)) { screen_info->formats[screen_info->numPixmapFormats].depth = - xnestPixmapFormats[i].depth; + fmt->depth; screen_info->formats[screen_info->numPixmapFormats].bitsPerPixel = - xnestPixmapFormats[i].bits_per_pixel; + fmt->bits_per_pixel; screen_info->formats[screen_info->numPixmapFormats].scanlinePad = - xnestPixmapFormats[i].scanline_pad; + fmt->scanline_pad; screen_info->numPixmapFormats++; break; }