⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xm_dd.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Mesa 3-D graphics library * Version:  6.5 * * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "glxheader.h"#include "bufferobj.h"#include "buffers.h"#include "context.h"#include "colormac.h"#include "depth.h"#include "drawpix.h"#include "extensions.h"#include "framebuffer.h"#include "macros.h"#include "image.h"#include "imports.h"#include "mtypes.h"#include "state.h"#include "texobj.h"#include "teximage.h"#include "texstore.h"#include "texformat.h"#include "xmesaP.h"#include "array_cache/acache.h"#include "swrast/swrast.h"#include "swrast/s_context.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "tnl/t_context.h"#ifdef XFree86Server#include <GL/glxtokens.h>#endif/* * Dithering kernels and lookup tables. */const int xmesa_kernel8[DITH_DY * DITH_DX] = {    0 * MAXC,  8 * MAXC,  2 * MAXC, 10 * MAXC,   12 * MAXC,  4 * MAXC, 14 * MAXC,  6 * MAXC,    3 * MAXC, 11 * MAXC,  1 * MAXC,  9 * MAXC,   15 * MAXC,  7 * MAXC, 13 * MAXC,  5 * MAXC,};const short xmesa_HPCR_DRGB[3][2][16] = {   {      { 16, -4,  1,-11, 14, -6,  3, -9, 15, -5,  2,-10, 13, -7,  4, -8},      {-15,  5,  0, 12,-13,  7, -2, 10,-14,  6, -1, 11,-12,  8, -3,  9}   },   {      {-11, 15, -7,  3, -8, 14, -4,  2,-10, 16, -6,  4, -9, 13, -5,  1},      { 12,-14,  8, -2,  9,-13,  5, -1, 11,-15,  7, -3, 10,-12,  6,  0}   },   {      {  6,-18, 26,-14,  2,-22, 30,-10,  8,-16, 28,-12,  4,-20, 32, -8},      { -4, 20,-24, 16,  0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10}   }};const int xmesa_kernel1[16] = {   0*47,  9*47,  4*47, 12*47,     /* 47 = (255*3)/16 */   6*47,  2*47, 14*47,  8*47,  10*47,  1*47,  5*47, 11*47,   7*47, 13*47,  3*47, 15*47};/* * Return the size (width, height) of the X window for the given GLframebuffer. * Output:  width - width of buffer in pixels. *          height - height of buffer in pixels. */static voidget_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ){   /* We can do this cast because the first field in the XMesaBuffer    * struct is a GLframebuffer struct.  If this weren't true, we'd    * need a pointer from the GLframebuffer to the XMesaBuffer.    */   const XMesaBuffer xmBuffer = (XMesaBuffer) buffer;   unsigned int winwidth, winheight;#ifdef XFree86Server   /* XFree86 GLX renderer */   winwidth = MIN2(xmBuffer->frontxrb->drawable->width, MAX_WIDTH);   winheight = MIN2(xmBuffer->frontxrb->drawable->height, MAX_HEIGHT);#else   Window root;   Status stat;   int winx, winy;   unsigned int bw, d;   _glthread_LOCK_MUTEX(_xmesa_lock);   XSync(xmBuffer->xm_visual->display, 0); /* added for Chromium */   stat = XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontxrb->pixmap,                 &root, &winx, &winy, &winwidth, &winheight, &bw, &d );   _glthread_UNLOCK_MUTEX(_xmesa_lock);   if (!stat) {      /* probably querying a window that's recently been destroyed */      _mesa_warning(NULL, "XGetGeometry failed!\n");      *width = *height = 1;      return;   }#endif   *width = winwidth;   *height = winheight;}static voidfinish_or_flush( GLcontext *ctx ){#ifdef XFree86Server      /* NOT_NEEDED */#else   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   if (xmesa) {      _glthread_LOCK_MUTEX(_xmesa_lock);      XSync( xmesa->display, False );      _glthread_UNLOCK_MUTEX(_xmesa_lock);   }#endif}static voidclear_index( GLcontext *ctx, GLuint index ){   if (ctx->DrawBuffer->Name == 0) {      const XMesaContext xmesa = XMESA_CONTEXT(ctx);      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);      xmesa->clearpixel = (unsigned long) index;      XMesaSetForeground( xmesa->display, xmbuf->cleargc, (unsigned long) index );   }}static voidclear_color( GLcontext *ctx, const GLfloat color[4] ){   if (ctx->DrawBuffer->Name == 0) {      const XMesaContext xmesa = XMESA_CONTEXT(ctx);      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);      xmesa->clearpixel = xmesa_color_to_pixel( ctx,                                                xmesa->clearcolor[0],                                                xmesa->clearcolor[1],                                                xmesa->clearcolor[2],                                                xmesa->clearcolor[3],                                                xmesa->xm_visual->undithered_pf );      _glthread_LOCK_MUTEX(_xmesa_lock);      XMesaSetForeground( xmesa->display, xmbuf->cleargc,                          xmesa->clearpixel );      _glthread_UNLOCK_MUTEX(_xmesa_lock);   }}/* Set index mask ala glIndexMask */static voidindex_mask( GLcontext *ctx, GLuint mask ){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);   /* not sure this conditional is really needed */   if (xmbuf->backxrb && xmbuf->backxrb->pixmap) {      unsigned long m;      if (mask==0xffffffff) {	 m = ((unsigned long)~0L);      }      else {         m = (unsigned long) mask;      }      XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m );      XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m );   }}/* Implements glColorMask() */static voidcolor_mask(GLcontext *ctx,           GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   XMesaBuffer xmbuf;   const int xclass = xmesa->xm_visual->mesa_visual.visualType;   (void) amask;   if (ctx->DrawBuffer->Name != 0)      return;   xmbuf = XMESA_BUFFER(ctx->DrawBuffer);   if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {      unsigned long m;      if (rmask && gmask && bmask) {         m = ((unsigned long)~0L);      }      else {         m = 0;         if (rmask)   m |= GET_REDMASK(xmesa->xm_visual);         if (gmask)   m |= GET_GREENMASK(xmesa->xm_visual);         if (bmask)   m |= GET_BLUEMASK(xmesa->xm_visual);      }      XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m );      XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m );   }}/**********************************************************************//*** glClear implementations                                        ***//**********************************************************************//** * Clear the front or back color buffer, if it's implemented with a pixmap. */static voidclear_pixmap(GLcontext *ctx, struct xmesa_renderbuffer *xrb, GLboolean all,             GLint x, GLint y, GLint width, GLint height){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);   assert(xmbuf);   assert(xrb->pixmap);   assert(xmesa);   assert(xmesa->display);   assert(xrb->pixmap);   assert(xmbuf->cleargc);   if (all) {      XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,                          0, 0, xrb->Base.Width + 1, xrb->Base.Height + 1 );   }   else {      XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,                          x, xrb->Base.Height - y - height,                          width, height );   }}static voidclear_8bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,                   GLboolean all, GLint x, GLint y, GLint width, GLint height ){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   if (all) {      const size_t n = xrb->ximage->bytes_per_line * xrb->Base.Height;      MEMSET( xrb->ximage->data, xmesa->clearpixel, n );   }   else {      GLint i;      for (i=0;i<height;i++) {         GLubyte *ptr = PIXEL_ADDR1(xrb, x, y + i);         MEMSET( ptr, xmesa->clearpixel, width );      }   }}static voidclear_HPCR_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,                   GLboolean all, GLint x, GLint y, GLint width, GLint height ){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   if (all) {      GLint i, c16 = (xrb->ximage->bytes_per_line>>4)<<4;      GLubyte *ptr  = (GLubyte *) xrb->ximage->data;      for (i = 0; i < xrb->Base.Height; i++) {         GLint j;         GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];         if (i&1) {            sptr += 16;         }         for (j=0; j<c16; j+=16) {            ptr[0] = sptr[0];            ptr[1] = sptr[1];            ptr[2] = sptr[2];            ptr[3] = sptr[3];            ptr[4] = sptr[4];            ptr[5] = sptr[5];            ptr[6] = sptr[6];            ptr[7] = sptr[7];            ptr[8] = sptr[8];            ptr[9] = sptr[9];            ptr[10] = sptr[10];            ptr[11] = sptr[11];            ptr[12] = sptr[12];            ptr[13] = sptr[13];            ptr[14] = sptr[14];            ptr[15] = sptr[15];            ptr += 16;         }         for (; j < xrb->ximage->bytes_per_line; j++) {            *ptr = sptr[j&15];            ptr++;         }      }   }   else {      GLint i;      for (i=y; i<y+height; i++) {         GLubyte *ptr = PIXEL_ADDR1( xrb, x, i );         int j;         const GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];         if (i&1) {            sptr += 16;         }         for (j=x; j<x+width; j++) {            *ptr = sptr[j&15];            ptr++;         }      }   }}static voidclear_16bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,                    GLboolean all, GLint x, GLint y, GLint width, GLint height){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   register GLuint pixel = (GLuint) xmesa->clearpixel;   if (xmesa->swapbytes) {      pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00);   }   if (all) {      GLuint *ptr4 = (GLuint *) xrb->ximage->data;      if ((pixel & 0xff) == ((pixel >> 8) & 0xff)) {         /* low and high bytes are equal so use memset() */         const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height;         MEMSET( ptr4, pixel & 0xff, n );      }      else {         const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height / 4;         GLuint i;         pixel = pixel | (pixel<<16);         for (i = 0; i < n; i++) {            ptr4[i] = pixel;         }         ptr4 += n;         /* might be one last GLushort to set */         if ((xrb->ximage->bytes_per_line * xrb->Base.Height) & 0x2)            *(GLushort *)ptr4 = pixel & 0xffff;      }   }   else {      GLint i, j;      for (j=0;j<height;j++) {         GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y + j);         for (i=0;i<width;i++) {            *ptr2++ = pixel;         }      }   }}/* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */static voidclear_24bit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb,                   GLboolean all, GLint x, GLint y, GLint width, GLint height){   const XMesaContext xmesa = XMESA_CONTEXT(ctx);   const GLubyte r = xmesa->clearcolor[0];   const GLubyte g = xmesa->clearcolor[1];   const GLubyte b = xmesa->clearcolor[2];   if (all) {      if (r == g && g == b) {         /* same value for all three components (gray) */         const GLint w3 = xrb->Base.Width * 3;         const GLint h = xrb->Base.Height;         GLint i;         for (i = 0; i < h; i++) {            bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i);            MEMSET(ptr3, r, w3);         }      }      else {         /* the usual case */         const GLint w = xrb->Base.Width;         const GLint h = xrb->Base.Height;         GLint i, j;         for (i = 0; i < h; i++) {            bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i);            for (j = 0; j < w; j++) {               ptr3->r = r;               ptr3->g = g;               ptr3->b = b;               ptr3++;            }         }      }   }   else {      /* only clear subrect of color buffer */      if (r == g && g == b) {         /* same value for all three components (gray) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -