From fe405a4bbfe4e8bff2442e72406ed67d7ea17658 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 | 66 -------------------------------------------- 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(+), 113 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 da0c85696b..56e8cdf826 100644 --- a/hw/xnest/Color.c +++ b/hw/xnest/Color.c @@ -25,13 +25,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" @@ -97,7 +95,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 */ @@ -249,13 +247,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 ae209884f0..527cc92863 100644 --- a/hw/xnest/Cursor.c +++ b/hw/xnest/Cursor.c @@ -36,7 +36,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 3c12ebedf6..65a939a737 100644 --- a/hw/xnest/GCOps.c +++ b/hw/xnest/GCOps.c @@ -40,7 +40,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 23c8af5bc7..79b04d977b 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -42,7 +42,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" @@ -412,7 +411,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; @@ -436,7 +435,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 57e420a1c1..0000000000 --- a/hw/xnest/Visual.c +++ /dev/null @@ -1,66 +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. - -*/ -#include - -#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 12f19d9ab7..0000000000 --- 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 1339b2eed2..dbc53dd532 100644 --- a/hw/xnest/Window.c +++ b/hw/xnest/Window.c @@ -39,7 +39,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" @@ -81,7 +80,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) { @@ -96,8 +95,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), @@ -106,13 +104,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; @@ -131,7 +129,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 d3a3e6900b..a8931b0312 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 55578b7429..741054811b 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 9ec05c7871..b64c50370e 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 */