📄 xm_api.c
字号:
* We'll use an alpha renderbuffer wrapper. */ b->swAlpha = GL_TRUE; } else { b->swAlpha = GL_FALSE; } /* * Other renderbuffer (depth, stencil, etc) */ _mesa_add_soft_renderbuffers(&b->mesa_buffer, GL_FALSE, /* color */ vis->mesa_visual.haveDepthBuffer, vis->mesa_visual.haveStencilBuffer, vis->mesa_visual.haveAccumBuffer, b->swAlpha, vis->mesa_visual.numAuxBuffers > 0 ); /* GLX_EXT_texture_from_pixmap */ b->TextureTarget = 0; b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT; b->TextureMipmap = 0; /* insert buffer into linked list */ b->Next = XMesaBufferList; XMesaBufferList = b; return b;}/** * Find an XMesaBuffer by matching X display and colormap but NOT matching * the notThis buffer. */XMesaBufferxmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis){ XMesaBuffer b; for (b=XMesaBufferList; b; b=b->Next) { if (b->display==dpy && b->cmap==cmap && b!=notThis) { return b; } } return NULL;}/** * Remove buffer from linked list, delete if no longer referenced. */static voidxmesa_free_buffer(XMesaBuffer buffer){ XMesaBuffer prev = NULL, b; for (b = XMesaBufferList; b; b = b->Next) { if (b == buffer) { struct gl_framebuffer *fb = &buffer->mesa_buffer; /* unlink buffer from list */ if (prev) prev->Next = buffer->Next; else XMesaBufferList = buffer->Next; /* mark as delete pending */ fb->DeletePending = GL_TRUE; /* Since the X window for the XMesaBuffer is going away, we don't * want to dereference this pointer in the future. */ b->frontxrb->drawable = 0; /* Unreference. If count = zero we'll really delete the buffer */ _mesa_unreference_framebuffer(&fb); return; } /* continue search */ prev = b; } /* buffer not found in XMesaBufferList */ _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n");}/** * Copy X color table stuff from one XMesaBuffer to another. */static voidcopy_colortable_info(XMesaBuffer dst, const XMesaBuffer src){ MEMCPY(dst->color_table, src->color_table, sizeof(src->color_table)); MEMCPY(dst->pixel_to_r, src->pixel_to_r, sizeof(src->pixel_to_r)); MEMCPY(dst->pixel_to_g, src->pixel_to_g, sizeof(src->pixel_to_g)); MEMCPY(dst->pixel_to_b, src->pixel_to_b, sizeof(src->pixel_to_b)); dst->num_alloced = src->num_alloced; MEMCPY(dst->alloced_colors, src->alloced_colors, sizeof(src->alloced_colors));}/**********************************************************************//***** Misc Private Functions *****//**********************************************************************//** * A replacement for XAllocColor. This function should never * fail to allocate a color. When XAllocColor fails, we return * the nearest matching color. If we have to allocate many colors * this function isn't too efficient; the XQueryColors() could be * done just once. * Written by Michael Pichler, Brian Paul, Mark Kilgard * Input: dpy - X display * cmap - X colormap * cmapSize - size of colormap * In/Out: color - the XColor struct * Output: exact - 1=exact color match, 0=closest match * alloced - 1=XAlloc worked, 0=XAlloc failed */static voidnoFaultXAllocColor( int client, XMesaDisplay *dpy, XMesaColormap cmap, int cmapSize, XMesaColor *color, int *exact, int *alloced ){#ifdef XFree86Server Pixel *ppixIn; xrgb *ctable;#else /* we'll try to cache ctable for better remote display performance */ static Display *prevDisplay = NULL; static XMesaColormap prevCmap = 0; static int prevCmapSize = 0; static XMesaColor *ctable = NULL;#endif XMesaColor subColor; int i, bestmatch; double mindist; /* 3*2^16^2 exceeds long int precision. */ (void) client; /* First try just using XAllocColor. */#ifdef XFree86Server if (AllocColor(cmap, &color->red, &color->green, &color->blue, &color->pixel, client) == Success)#else if (XAllocColor(dpy, cmap, color))#endif { *exact = 1; *alloced = 1; return; } /* Alloc failed, search for closest match */ /* Retrieve color table entries. */ /* XXX alloca candidate. */#ifdef XFree86Server ppixIn = (Pixel *) MALLOC(cmapSize * sizeof(Pixel)); ctable = (xrgb *) MALLOC(cmapSize * sizeof(xrgb)); for (i = 0; i < cmapSize; i++) { ppixIn[i] = i; } QueryColors(cmap, cmapSize, ppixIn, ctable);#else if (prevDisplay != dpy || prevCmap != cmap || prevCmapSize != cmapSize || !ctable) { /* free previously cached color table */ if (ctable) _mesa_free(ctable); /* Get the color table from X */ ctable = (XMesaColor *) MALLOC(cmapSize * sizeof(XMesaColor)); assert(ctable); for (i = 0; i < cmapSize; i++) { ctable[i].pixel = i; } XQueryColors(dpy, cmap, ctable, cmapSize); prevDisplay = dpy; prevCmap = cmap; prevCmapSize = cmapSize; }#endif /* Find best match. */ bestmatch = -1; mindist = 0.0; for (i = 0; i < cmapSize; i++) { double dr = 0.30 * ((double) color->red - (double) ctable[i].red); double dg = 0.59 * ((double) color->green - (double) ctable[i].green); double db = 0.11 * ((double) color->blue - (double) ctable[i].blue); double dist = dr * dr + dg * dg + db * db; if (bestmatch < 0 || dist < mindist) { bestmatch = i; mindist = dist; } } /* Return result. */ subColor.red = ctable[bestmatch].red; subColor.green = ctable[bestmatch].green; subColor.blue = ctable[bestmatch].blue; /* Try to allocate the closest match color. This should only * fail if the cell is read/write. Otherwise, we're incrementing * the cell's reference count. */#ifdef XFree86Server if (AllocColor(cmap, &subColor.red, &subColor.green, &subColor.blue, &subColor.pixel, client) == Success) {#else if (XAllocColor(dpy, cmap, &subColor)) {#endif *alloced = 1; } else { /* do this to work around a problem reported by Frank Ortega */ subColor.pixel = (unsigned long) bestmatch; subColor.red = ctable[bestmatch].red; subColor.green = ctable[bestmatch].green; subColor.blue = ctable[bestmatch].blue; subColor.flags = DoRed | DoGreen | DoBlue; *alloced = 0; }#ifdef XFree86Server _mesa_free(ppixIn); _mesa_free(ctable);#else /* don't free table, save it for next time */#endif *color = subColor; *exact = 0;}/** * Do setup for PF_GRAYSCALE pixel format. * Note that buffer may be NULL. */static GLbooleansetup_grayscale(int client, XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap){ if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { return GL_FALSE; } if (buffer) { XMesaBuffer prevBuffer; if (!cmap) { return GL_FALSE; } prevBuffer = xmesa_find_buffer(v->display, cmap, buffer); if (prevBuffer && (buffer->xm_visual->mesa_visual.rgbMode == prevBuffer->xm_visual->mesa_visual.rgbMode)) { /* Copy colormap stuff from previous XMesaBuffer which uses same * X colormap. Do this to avoid time spent in noFaultXAllocColor. */ copy_colortable_info(buffer, prevBuffer); } else { /* Allocate 256 shades of gray */ int gray; int colorsfailed = 0; for (gray=0;gray<256;gray++) { GLint r = gamma_adjust( v->RedGamma, gray, 255 ); GLint g = gamma_adjust( v->GreenGamma, gray, 255 ); GLint b = gamma_adjust( v->BlueGamma, gray, 255 ); int exact, alloced; XMesaColor xcol; xcol.red = (r << 8) | r; xcol.green = (g << 8) | g; xcol.blue = (b << 8) | b; noFaultXAllocColor( client, v->display, cmap, GET_COLORMAP_SIZE(v), &xcol, &exact, &alloced ); if (!exact) { colorsfailed++; } if (alloced) { assert(buffer->num_alloced<256); buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; buffer->num_alloced++; } /*OLD assert(gray < 576); buffer->color_table[gray*3+0] = xcol.pixel; buffer->color_table[gray*3+1] = xcol.pixel; buffer->color_table[gray*3+2] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = gray * 30 / 100; buffer->pixel_to_g[xcol.pixel] = gray * 59 / 100; buffer->pixel_to_b[xcol.pixel] = gray * 11 / 100; */ buffer->color_table[gray] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = gray; buffer->pixel_to_g[xcol.pixel] = gray; buffer->pixel_to_b[xcol.pixel] = gray; } if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Note: %d out of 256 needed colors do not match exactly.\n", colorsfailed ); } } } v->dithered_pf = PF_Grayscale; v->undithered_pf = PF_Grayscale; return GL_TRUE;}/** * Setup RGB rendering for a window with a PseudoColor, StaticColor, * or 8-bit TrueColor visual visual. We try to allocate a palette of 225 * colors (5 red, 9 green, 5 blue) and dither to approximate a 24-bit RGB * color. While this function was originally designed just for 8-bit * visuals, it has also proven to work from 4-bit up to 16-bit visuals. * Dithering code contributed by Bob Mercier. */static GLbooleansetup_dithered_color(int client, XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap){ if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { return GL_FALSE; } if (buffer) { XMesaBuffer prevBuffer; if (!cmap) { return GL_FALSE; } prevBuffer = xmesa_find_buffer(v->display, cmap, buffer); if (prevBuffer && (buffer->xm_visual->mesa_visual.rgbMode == prevBuffer->xm_visual->mesa_visual.rgbMode)) { /* Copy colormap stuff from previous, matching XMesaBuffer. * Do this to avoid time spent in noFaultXAllocColor. */ copy_colortable_info(buffer, prevBuffer); } else { /* Allocate X colors and initialize color_table[], red_table[], etc */ int r, g, b, i; int colorsfailed = 0; for (r = 0; r < DITH_R; r++) { for (g = 0; g < DITH_G; g++) { for (b = 0; b < DITH_B; b++) { XMesaColor xcol; int exact, alloced; xcol.red =gamma_adjust(v->RedGamma, r*65535/(DITH_R-1),65535); xcol.green=gamma_adjust(v->GreenGamma, g*65535/(DITH_G-1),65535); xcol.blue =gamma_adjust(v->BlueGamma, b*65535/(DITH_B-1),65535); noFaultXAllocColor( client, v->display, cmap, GET_COLORMAP_SIZE(v), &xcol, &exact, &alloced ); if (!exact) { colorsfailed++; } if (alloced) { assert(buffer->num_alloced<256); buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; buffer->num_alloced++; } i = DITH_MIX( r, g, b ); assert(i < 576); buffer->color_table[i] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = r * 255 / (DITH_R-1); buffer->pixel_to_g[xcol.pixel] = g * 255 / (DITH_G-1); buffer->pixel_to_b[xcol.pixel] = b * 255 / (DITH_B-1); } } } if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Note: %d out of %d needed colors do not match exactly.\n", colorsfailed, DITH_R * DITH_G * DITH_B ); } } } v->dithered_pf = PF_Dither; v->undithered_pf = PF_Lookup; return GL_TRUE;}/** * Setup for Hewlett Packard Color Recovery 8-bit TrueColor mode. * HPCR simulates 24-bit color fidelity with an 8-bit frame buffer. * Special dithering tables have to be initialized. */static voidsetup_8bit_hpcr(XMesaVisual v)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -