From 3f9c5aa5eca3d6cbf13aecdb4810e66ab53ed2a6 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 15 Aug 2024 17:26:05 +0200 Subject: [PATCH] (!1654) Xnest: use new lookup table for visuals and cmaps mappings Use the visuals lookup table introduced by previous commit for looking up local vs upstream visuals and their colormaps. Replacing the the old Xlib visuals table. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xnest/Color.c | 9 ++---- hw/xnest/Cursor.c | 1 - hw/xnest/GCOps.c | 1 - hw/xnest/Screen.c | 5 ++-- hw/xnest/Visual.c | 69 -------------------------------------------- hw/xnest/Visual.h | 27 ----------------- hw/xnest/Window.c | 12 ++++---- hw/xnest/meson.build | 1 - hw/xnest/xcb.c | 31 +++++++++++++++++++- hw/xnest/xnest-xcb.h | 4 +++ 10 files changed, 44 insertions(+), 116 deletions(-) delete mode 100644 hw/xnest/Visual.c delete mode 100644 hw/xnest/Visual.h diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c index 6b6c47d1d..2eba4eca1 100644 --- a/hw/xnest/Color.c +++ b/hw/xnest/Color.c @@ -26,13 +26,11 @@ is" without express or implied warranty. #include "colormapst.h" #include "resource.h" -#include "Xnest.h" #include "xnest-xcb.h" #include "Display.h" #include "Screen.h" #include "Color.h" -#include "Visual.h" #include "XNWindow.h" #include "Args.h" @@ -98,7 +96,7 @@ xnestCreateColormap(ColormapPtr pCmap) (pVisual->class & DynamicClass) ? XCB_COLORMAP_ALLOC_ALL : XCB_COLORMAP_ALLOC_NONE, cmap, xnestDefaultWindows[pCmap->pScreen->myNum], - xnestVisual(pVisual)->visualid); + xnest_visual_map_to_upstream(pVisual->vid)); switch (pVisual->class) { case StaticGray: /* read only */ @@ -250,13 +248,12 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) */ if (icws.numWindows) { WindowPtr pWin; - Visual *visual; ColormapPtr pCmap; pWin = xnestWindowPtr(icws.windows[0]); - visual = xnestVisualFromID(pScreen, wVisual(pWin)); - if (visual == xnestDefaultVisual(pScreen)) + if (xnest_visual_map_to_upstream(wVisual(pWin)) == + xnest_visual_map_to_upstream(pScreen->rootVisual)) dixLookupResourceByType((void **) &pCmap, wColormap(pWin), X11_RESTYPE_COLORMAP, serverClient, DixUseAccess); diff --git a/hw/xnest/Cursor.c b/hw/xnest/Cursor.c index 06a3282f3..600068392 100644 --- a/hw/xnest/Cursor.c +++ b/hw/xnest/Cursor.c @@ -39,7 +39,6 @@ is" without express or implied warranty. #include "Display.h" #include "Screen.h" #include "XNCursor.h" -#include "Visual.h" #include "Keyboard.h" #include "Args.h" diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c index d3977dd37..c4462175e 100644 --- a/hw/xnest/GCOps.c +++ b/hw/xnest/GCOps.c @@ -43,7 +43,6 @@ is" without express or implied warranty. #include "XNFont.h" #include "GCOps.h" #include "Drawable.h" -#include "Visual.h" void xnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint * pPoints, diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index 8d5ae9c6b..a48e79dc2 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -45,7 +45,6 @@ is" without express or implied warranty. #include "XNFont.h" #include "Color.h" #include "XNCursor.h" -#include "Visual.h" #include "Events.h" #include "Init.h" #include "mipointer.h" @@ -415,7 +414,7 @@ breakout: xcb_params_cw_t attributes = { .back_pixel = xnestUpstreamInfo.screenInfo->white_pixel, .event_mask = xnestEventMask, - .colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen)), + .colormap = xnest_visual_to_upstream_cmap(pScreen->rootVisual), }; valuemask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; @@ -439,7 +438,7 @@ breakout: xnestGeometry.height, xnestBorderWidth, XCB_WINDOW_CLASS_INPUT_OUTPUT, - xnestDefaultVisual(pScreen)->visualid, + xnest_visual_map_to_upstream(pScreen->rootVisual), valuemask, &attributes); } diff --git a/hw/xnest/Visual.c b/hw/xnest/Visual.c deleted file mode 100644 index 21949f261..000000000 --- a/hw/xnest/Visual.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifdef HAVE_XNEST_CONFIG_H -#include -#endif - -#include -#include -#include "scrnintstr.h" -#include "dix.h" -#include "mi.h" -#include "Xnest.h" - -#include "Display.h" -#include "Visual.h" - -Visual * -xnestVisual(VisualPtr pVisual) -{ - int i; - - for (i = 0; i < xnestNumVisuals; i++) - if (pVisual->class == xnestVisuals[i].class && - pVisual->bitsPerRGBValue == xnestVisuals[i].bits_per_rgb && - pVisual->ColormapEntries == xnestVisuals[i].colormap_size && - pVisual->nplanes == xnestVisuals[i].depth && - pVisual->redMask == xnestVisuals[i].red_mask && - pVisual->greenMask == xnestVisuals[i].green_mask && - pVisual->blueMask == xnestVisuals[i].blue_mask) - return xnestVisuals[i].visual; - - return NULL; -} - -Visual * -xnestVisualFromID(ScreenPtr pScreen, VisualID visual) -{ - int i; - - for (i = 0; i < pScreen->numVisuals; i++) - if (pScreen->visuals[i].vid == visual) - return xnestVisual(&pScreen->visuals[i]); - - return NULL; -} - -Colormap -xnestDefaultVisualColormap(Visual * visual) -{ - int i; - - for (i = 0; i < xnestNumVisuals; i++) - if (xnestVisuals[i].visual == visual) - return xnestDefaultColormaps[i]; - - return XCB_WINDOW_NONE; -} diff --git a/hw/xnest/Visual.h b/hw/xnest/Visual.h deleted file mode 100644 index 12f19d9ab..000000000 --- a/hw/xnest/Visual.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - -Copyright 1993 by Davor Matic - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. Davor Matic makes no representations about -the suitability of this software for any purpose. It is provided "as -is" without express or implied warranty. - -*/ - -#ifndef XNESTVISUAL_H -#define XNESTVISUAL_H - -#include - -Visual *xnestVisual(VisualPtr pVisual); -Visual *xnestVisualFromID(ScreenPtr pScreen, VisualID visual); -Colormap xnestDefaultVisualColormap(Visual * visual); - -#define xnestDefaultVisual(pScreen) \ - xnestVisualFromID((pScreen), (pScreen)->rootVisual) - -#endif /* XNESTVISUAL_H */ diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c index bc603a0c8..59774b625 100644 --- a/hw/xnest/Window.c +++ b/hw/xnest/Window.c @@ -42,7 +42,6 @@ is" without express or implied warranty. #include "XNGC.h" #include "Drawable.h" #include "Color.h" -#include "Visual.h" #include "Events.h" #include "Args.h" @@ -84,7 +83,7 @@ xnestCreateWindow(WindowPtr pWin) { unsigned long mask; xcb_params_cw_t attributes = { 0 }; - Visual *visual; + uint32_t visual = CopyFromParent; /* 0L */ ColormapPtr pCmap; if (pWin->drawable.class == InputOnly) { @@ -99,8 +98,7 @@ xnestCreateWindow(WindowPtr pWin) if (pWin->parent) { if (pWin->optional && pWin->optional->visual != wVisual(pWin->parent)) { - visual = - xnestVisualFromID(pWin->drawable.pScreen, wVisual(pWin)); + visual = xnest_visual_map_to_upstream(wVisual(pWin)); mask |= XCB_CW_COLORMAP; if (pWin->optional->colormap) { dixLookupResourceByType((void **) &pCmap, wColormap(pWin), @@ -109,13 +107,13 @@ xnestCreateWindow(WindowPtr pWin) attributes.colormap = xnestColormap(pCmap); } else - attributes.colormap = xnestDefaultVisualColormap(visual); + attributes.colormap = xnest_upstream_visual_to_cmap(visual); } else visual = CopyFromParent; } else { /* root windows have their own colormaps at creation time */ - visual = xnestVisualFromID(pWin->drawable.pScreen, wVisual(pWin)); + visual = xnest_visual_map_to_upstream(wVisual(pWin)); dixLookupResourceByType((void **) &pCmap, wColormap(pWin), X11_RESTYPE_COLORMAP, serverClient, DixUseAccess); mask |= XCB_CW_COLORMAP; @@ -134,7 +132,7 @@ xnestCreateWindow(WindowPtr pWin) pWin->drawable.height, pWin->borderWidth, pWin->drawable.class, - (visual ? visual->visualid : 0), + visual, mask, &attributes); diff --git a/hw/xnest/meson.build b/hw/xnest/meson.build index a94a1cbfc..d0224e919 100644 --- a/hw/xnest/meson.build +++ b/hw/xnest/meson.build @@ -13,7 +13,6 @@ srcs = [ 'Pixmap.c', 'Pointer.c', 'Screen.c', - 'Visual.c', 'Window.c', '../../mi/miinitext.c', '../../mi/miinitext.h', diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c index 55578b742..741054811 100644 --- a/hw/xnest/xcb.c +++ b/hw/xnest/xcb.c @@ -20,7 +20,6 @@ #include "xnest-xcb.h" #include "xnest-xkb.h" #include "XNGC.h" - #include "Display.h" struct xnest_upstream_info xnestUpstreamInfo = { 0 }; @@ -417,3 +416,33 @@ int xnest_parse_geometry(const char *string, xRectangle *geometry) return mask; } + +uint32_t xnest_visual_map_to_upstream(VisualID visual) +{ + for (int i = 0; i < xnestNumVisualMap; i++) { + if (xnestVisualMap[i].ourXID == visual) { + return xnestVisualMap[i].upstreamVisual->visual_id; + } + } + return XCB_NONE; +} + +uint32_t xnest_upstream_visual_to_cmap(uint32_t upstreamVisual) +{ + for (int i = 0; i < xnestNumVisualMap; i++) { + if (xnestVisualMap[i].upstreamVisual->visual_id == upstreamVisual) { + return xnestVisualMap[i].upstreamCMap; + } + } + return XCB_COLORMAP_NONE; +} + +uint32_t xnest_visual_to_upstream_cmap(uint32_t visual) +{ + for (int i = 0; i < xnestNumVisualMap; i++) { + if (xnestVisualMap[i].ourXID == visual) { + return xnestVisualMap[i].upstreamCMap; + } + } + return XCB_COLORMAP_NONE; +} diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h index 9ec05c787..b64c50370 100644 --- a/hw/xnest/xnest-xcb.h +++ b/hw/xnest/xnest-xcb.h @@ -58,4 +58,8 @@ xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window); int xnest_parse_geometry(const char *string, xRectangle *geometry); +uint32_t xnest_visual_map_to_upstream(VisualID visual); +uint32_t xnest_upstream_visual_to_cmap(uint32_t visual); +uint32_t xnest_visual_to_upstream_cmap(uint32_t visual); + #endif /* __XNEST__XCB_H */