(!1654) Xnest: replace XQueryColors() by xcb_query_colors()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
		
							parent
							
								
									b6a40db227
								
							
						
					
					
						commit
						b23f4a462e
					
				| 
						 | 
					@ -47,17 +47,49 @@ static DevPrivateKeyRec cmapScrPrivateKeyRec;
 | 
				
			||||||
#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 | 
					#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 | 
				
			||||||
#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
 | 
					#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static Bool load_colormap(ColormapPtr pCmap, int ncolors, uint32_t *colors)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    xcb_generic_error_t *err = NULL;
 | 
				
			||||||
 | 
					    xcb_query_colors_reply_t *reply = xcb_query_colors_reply(
 | 
				
			||||||
 | 
					        xnestUpstreamInfo.conn,
 | 
				
			||||||
 | 
					        xcb_query_colors(
 | 
				
			||||||
 | 
					            xnestUpstreamInfo.conn,
 | 
				
			||||||
 | 
					            xnestColormap(pCmap),
 | 
				
			||||||
 | 
					            ncolors,
 | 
				
			||||||
 | 
					            colors),
 | 
				
			||||||
 | 
					        &err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!reply) {
 | 
				
			||||||
 | 
					        LogMessage(X_WARNING, "load_colormap(): missing reply for QueryColors request\n");
 | 
				
			||||||
 | 
					        free(colors);
 | 
				
			||||||
 | 
					        return FALSE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (xcb_query_colors_colors_length(reply) != ncolors) {
 | 
				
			||||||
 | 
					        LogMessage(X_WARNING, "load_colormap(): received wrong number of entries: %d - expected %d\n",
 | 
				
			||||||
 | 
					            xcb_query_colors_colors_length(reply), ncolors);
 | 
				
			||||||
 | 
					        free(reply);
 | 
				
			||||||
 | 
					        free(colors);
 | 
				
			||||||
 | 
					        return FALSE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    xcb_rgb_t *rgb = xcb_query_colors_colors(reply);
 | 
				
			||||||
 | 
					    for (int i = 0; i < ncolors; i++) {
 | 
				
			||||||
 | 
					        pCmap->red[i].co.local.red = rgb[i].red;
 | 
				
			||||||
 | 
					        pCmap->green[i].co.local.green = rgb[i].green;
 | 
				
			||||||
 | 
					        pCmap->blue[i].co.local.blue = rgb[i].blue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(colors);
 | 
				
			||||||
 | 
					    free(reply);
 | 
				
			||||||
 | 
					    return TRUE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bool
 | 
					Bool
 | 
				
			||||||
xnestCreateColormap(ColormapPtr pCmap)
 | 
					xnestCreateColormap(ColormapPtr pCmap)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    VisualPtr pVisual;
 | 
					    VisualPtr pVisual = pCmap->pVisual;
 | 
				
			||||||
    XColor *colors;
 | 
					    int ncolors = pVisual->ColormapEntries;
 | 
				
			||||||
    int i, ncolors;
 | 
					 | 
				
			||||||
    Pixel red, green, blue;
 | 
					 | 
				
			||||||
    Pixel redInc, greenInc, blueInc;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pVisual = pCmap->pVisual;
 | 
					 | 
				
			||||||
    ncolors = pVisual->ColormapEntries;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint32_t const cmap = xcb_generate_id(xnestUpstreamInfo.conn);
 | 
					    uint32_t const cmap = xcb_generate_id(xnestUpstreamInfo.conn);
 | 
				
			||||||
    xnestColormapPriv(pCmap)->colormap = cmap;
 | 
					    xnestColormapPriv(pCmap)->colormap = cmap;
 | 
				
			||||||
| 
						 | 
					@ -70,39 +102,24 @@ xnestCreateColormap(ColormapPtr pCmap)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (pVisual->class) {
 | 
					    switch (pVisual->class) {
 | 
				
			||||||
    case StaticGray:           /* read only */
 | 
					    case StaticGray:           /* read only */
 | 
				
			||||||
        colors = xallocarray(ncolors, sizeof(XColor));
 | 
					 | 
				
			||||||
        for (i = 0; i < ncolors; i++)
 | 
					 | 
				
			||||||
            colors[i].pixel = i;
 | 
					 | 
				
			||||||
        XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
 | 
					 | 
				
			||||||
        for (i = 0; i < ncolors; i++) {
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.red = colors[i].red;
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.green = colors[i].red;
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.blue = colors[i].red;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        free(colors);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    case StaticColor:          /* read only */
 | 
					    case StaticColor:          /* read only */
 | 
				
			||||||
        colors = xallocarray(ncolors, sizeof(XColor));
 | 
					    {
 | 
				
			||||||
        for (i = 0; i < ncolors; i++)
 | 
					        uint32_t *colors = malloc(ncolors * sizeof(uint32_t));
 | 
				
			||||||
            colors[i].pixel = i;
 | 
					        for (int i = 0; i < ncolors; i++)
 | 
				
			||||||
        XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
 | 
					            colors[i] = i;
 | 
				
			||||||
        for (i = 0; i < ncolors; i++) {
 | 
					        return load_colormap(pCmap, ncolors, colors);
 | 
				
			||||||
            pCmap->red[i].co.local.red = colors[i].red;
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.green = colors[i].green;
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.blue = colors[i].blue;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
        free(colors);
 | 
					 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case TrueColor:            /* read only */
 | 
					    case TrueColor:            /* read only */
 | 
				
			||||||
        colors = xallocarray(ncolors, sizeof(XColor));
 | 
					    {
 | 
				
			||||||
        red = green = blue = 0L;
 | 
					        uint32_t *colors = malloc(ncolors * sizeof(uint32_t));
 | 
				
			||||||
        redInc = lowbit(pVisual->redMask);
 | 
					        Pixel red = 0, redInc = lowbit(pVisual->redMask);
 | 
				
			||||||
        greenInc = lowbit(pVisual->greenMask);
 | 
					        Pixel green = 0, greenInc = lowbit(pVisual->greenMask);
 | 
				
			||||||
        blueInc = lowbit(pVisual->blueMask);
 | 
					        Pixel blue = 0, blueInc = lowbit(pVisual->blueMask);
 | 
				
			||||||
        for (i = 0; i < ncolors; i++) {
 | 
					
 | 
				
			||||||
            colors[i].pixel = red | green | blue;
 | 
					        for (int i = 0; i < ncolors; i++) {
 | 
				
			||||||
 | 
					            colors[i] = red | green | blue;
 | 
				
			||||||
            red += redInc;
 | 
					            red += redInc;
 | 
				
			||||||
            if (red > pVisual->redMask)
 | 
					            if (red > pVisual->redMask)
 | 
				
			||||||
                red = 0L;
 | 
					                red = 0L;
 | 
				
			||||||
| 
						 | 
					@ -113,13 +130,8 @@ xnestCreateColormap(ColormapPtr pCmap)
 | 
				
			||||||
            if (blue > pVisual->blueMask)
 | 
					            if (blue > pVisual->blueMask)
 | 
				
			||||||
                blue = 0L;
 | 
					                blue = 0L;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
 | 
					        return load_colormap(pCmap, ncolors, colors);
 | 
				
			||||||
        for (i = 0; i < ncolors; i++) {
 | 
					 | 
				
			||||||
            pCmap->red[i].co.local.red = colors[i].red;
 | 
					 | 
				
			||||||
            pCmap->green[i].co.local.green = colors[i].green;
 | 
					 | 
				
			||||||
            pCmap->blue[i].co.local.blue = colors[i].blue;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
        free(colors);
 | 
					 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case GrayScale:            /* read and write */
 | 
					    case GrayScale:            /* read and write */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue