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

📄 savageioctl.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. * Copyright 2001-2003 S3 Graphics, Inc. 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, sub license, * 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 (including the * next paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS 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 <stdio.h>#include <unistd.h>#include <sys/mman.h>#include "mtypes.h"#include "macros.h"#include "dd.h"#include "context.h"#include "swrast/swrast.h"#include "colormac.h"#include "mm.h"#include "savagecontext.h"#include "savageioctl.h"#include "savage_bci.h"#include "savagestate.h"#include "savagespan.h"#include "drm.h"#include <sys/ioctl.h>#include <sys/timeb.h>#define DEPTH_SCALE_16 ((1<<16)-1)#define DEPTH_SCALE_24 ((1<<24)-1)void savageGetDMABuffer( savageContextPtr imesa ){   int idx = 0;   int size = 0;   drmDMAReq dma;   int retcode;   drmBufPtr buf;   assert (imesa->savageScreen->bufs);   if (SAVAGE_DEBUG & DEBUG_DMA)      fprintf(stderr,  "Getting dma buffer\n");   dma.context = imesa->hHWContext;   dma.send_count = 0;   dma.send_list = NULL;   dma.send_sizes = NULL;   dma.flags = 0;   dma.request_count = 1;   dma.request_size = imesa->bufferSize;   dma.request_list = &idx;   dma.request_sizes = &size;   dma.granted_count = 0;   if (SAVAGE_DEBUG & DEBUG_DMA)      fprintf(stderr, "drmDMA (get) ctx %d count %d size 0x%x\n",	   dma.context, dma.request_count,	   dma.request_size);   while (1) {      retcode = drmDMA(imesa->driFd, &dma);      if (SAVAGE_DEBUG & DEBUG_DMA)	 fprintf(stderr, "retcode %d sz %d idx %d count %d\n",		 retcode,		 dma.request_sizes[0],		 dma.request_list[0],		 dma.granted_count);      if (retcode == 0 &&	  dma.request_sizes[0] &&	  dma.granted_count)	 break;      if (SAVAGE_DEBUG & DEBUG_DMA)	 fprintf(stderr, "\n\nflush");   }   buf = &(imesa->savageScreen->bufs->list[idx]);   if (SAVAGE_DEBUG & DEBUG_DMA)      fprintf(stderr,	   "drmDMA (get) returns size[0] 0x%x idx[0] %d\n"	   "dma_buffer now: buf idx: %d size: %d used: %d addr %p\n",	   dma.request_sizes[0], dma.request_list[0],	   buf->idx, buf->total,	   buf->used, buf->address);   imesa->dmaVtxBuf.total = buf->total / 4;   imesa->dmaVtxBuf.used = 0;   imesa->dmaVtxBuf.flushed = 0;   imesa->dmaVtxBuf.idx = buf->idx;   imesa->dmaVtxBuf.buf = (u_int32_t *)buf->address;   if (SAVAGE_DEBUG & DEBUG_DMA)      fprintf(stderr, "finished getbuffer\n");}#if 0/* Still keeping this around because it demonstrates page flipping and * automatic z-clear. */static void savage_BCI_clear(GLcontext *ctx, drm_savage_clear_t *pclear){	savageContextPtr imesa = SAVAGE_CONTEXT(ctx);	int nbox = imesa->sarea->nbox;	drm_clip_rect_t *pbox = imesa->sarea->boxes;        int i;	      	if (nbox > SAVAGE_NR_SAREA_CLIPRECTS)     		nbox = SAVAGE_NR_SAREA_CLIPRECTS;	for (i = 0 ; i < nbox ; i++, pbox++) {		unsigned int x = pbox->x1;		unsigned int y = pbox->y1;		unsigned int width = pbox->x2 - x;		unsigned int height = pbox->y2 - y; 		u_int32_t *bciptr;		if (pbox->x1 > pbox->x2 ||		    pbox->y1 > pbox->y2 ||		    pbox->x2 > imesa->savageScreen->width ||		    pbox->y2 > imesa->savageScreen->height)			continue;	   	if ( pclear->flags & SAVAGE_FRONT ) {		        bciptr = savageDMAAlloc (imesa, 8);			WRITE_CMD((bciptr) , 0x4BCC8C00,u_int32_t);			WRITE_CMD((bciptr) , imesa->savageScreen->frontOffset,u_int32_t);			WRITE_CMD((bciptr) , imesa->savageScreen->frontBitmapDesc,u_int32_t);			WRITE_CMD((bciptr) , pclear->clear_color,u_int32_t);			WRITE_CMD((bciptr) , (y <<16) | x,u_int32_t);			WRITE_CMD((bciptr) , (height << 16) | width,u_int32_t);			savageDMACommit (imesa, bciptr);		}		if ( pclear->flags & SAVAGE_BACK ) {		        bciptr = savageDMAAlloc (imesa, 8);			WRITE_CMD((bciptr) , 0x4BCC8C00,u_int32_t);			WRITE_CMD((bciptr) , imesa->savageScreen->backOffset,u_int32_t);			WRITE_CMD((bciptr) , imesa->savageScreen->backBitmapDesc,u_int32_t);			WRITE_CMD((bciptr) , pclear->clear_color,u_int32_t);			WRITE_CMD((bciptr) , (y <<16) | x,u_int32_t);			WRITE_CMD((bciptr) , (height << 16) | width,u_int32_t);			savageDMACommit (imesa, bciptr);		}				if ( pclear->flags & (SAVAGE_DEPTH |SAVAGE_STENCIL) ) {		        u_int32_t writeMask = 0x0;		        if(imesa->hw_stencil)		        {        		            if(pclear->flags & SAVAGE_STENCIL)		            {		          		                 writeMask |= 0xFF000000;		            }		            if(pclear->flags & SAVAGE_DEPTH)		            {		                 writeMask |= 0x00FFFFFF;		            }                        }		        if(imesa->IsFullScreen && imesa->NotFirstFrame &&			   imesa->savageScreen->chipset >= S3_SAVAGE4)		        {		            imesa->regs.s4.zBufCtrl.ni.autoZEnable = GL_TRUE;                            imesa->regs.s4.zBufCtrl.ni.frameID =				~imesa->regs.s4.zBufCtrl.ni.frameID;                                                        imesa->dirty |= SAVAGE_UPLOAD_GLOBAL;		        }		        else		        {		            if(imesa->IsFullScreen)		                imesa->NotFirstFrame = GL_TRUE;		                			    if(imesa->hw_stencil)			    {				bciptr = savageDMAAlloc (imesa, 10);			        if(writeMask != 0xFFFFFFFF)			        {                                    WRITE_CMD((bciptr) , 0x960100D7,u_int32_t);                                    WRITE_CMD((bciptr) , writeMask,u_int32_t);                                }                            }			    else			    {				bciptr = savageDMAAlloc (imesa, 6);			    }			    WRITE_CMD((bciptr) , 0x4BCC8C00,u_int32_t);			    WRITE_CMD((bciptr) , imesa->savageScreen->depthOffset,u_int32_t);			    WRITE_CMD((bciptr) , imesa->savageScreen->depthBitmapDesc,u_int32_t);			    WRITE_CMD((bciptr) , pclear->clear_depth,u_int32_t);			    WRITE_CMD((bciptr) , (y <<16) | x,u_int32_t);			    WRITE_CMD((bciptr) , (height << 16) | width,u_int32_t);			    if(imesa->hw_stencil)			    {			        if(writeMask != 0xFFFFFFFF)			        {			           WRITE_CMD((bciptr) , 0x960100D7,u_int32_t);                                   WRITE_CMD((bciptr) , 0xFFFFFFFF,u_int32_t);  			        }			    }			    savageDMACommit (imesa, bciptr);			}		}	}	/* FK: Make sure that the clear stuff is emitted. Otherwise a	   software fallback may get overwritten by a delayed clear. */	savageDMAFlush (imesa);}static void savage_BCI_swap(savageContextPtr imesa){    int nbox = imesa->sarea->nbox;    drm_clip_rect_t *pbox = imesa->sarea->boxes;    int i;    volatile u_int32_t *bciptr;        if (nbox > SAVAGE_NR_SAREA_CLIPRECTS)        nbox = SAVAGE_NR_SAREA_CLIPRECTS;    savageDMAFlush (imesa);        if(imesa->IsFullScreen)    { /* full screen*/        unsigned int tmp0;        tmp0 = imesa->savageScreen->frontOffset;         imesa->savageScreen->frontOffset = imesa->savageScreen->backOffset;        imesa->savageScreen->backOffset = tmp0;                if(imesa->toggle == TARGET_BACK)            imesa->toggle = TARGET_FRONT;        else            imesa->toggle = TARGET_BACK;                 driFlipRenderbuffers(imesa->glCtx->DrawBuffer,                             imesa->toggle != TARGET_FRONT);        imesa->regs.s4.destCtrl.ni.offset = imesa->savageScreen->backOffset>>11;        imesa->dirty |= SAVAGE_UPLOAD_GLOBAL;        bciptr = SAVAGE_GET_BCI_POINTER(imesa,3);        *(bciptr) = 0x960100B0;        *(bciptr) = (imesa->savageScreen->frontOffset);         *(bciptr) = 0xA0000000;    }         else    {  /* Use bitblt copy from back to front buffer*/                for (i = 0 ; i < nbox; i++, pbox++)        {            unsigned int w = pbox->x2 - pbox->x1;            unsigned int h = pbox->y2 - pbox->y1;                        if (pbox->x1 > pbox->x2 ||                pbox->y1 > pbox->y2 ||                pbox->x2 > imesa->savageScreen->width ||                pbox->y2 > imesa->savageScreen->height)                continue;            bciptr = SAVAGE_GET_BCI_POINTER(imesa,6);                        *(bciptr) = 0x4BCC00C0;                        *(bciptr) = imesa->savageScreen->backOffset;            *(bciptr) = imesa->savageScreen->backBitmapDesc;            *(bciptr) = (pbox->y1 <<16) | pbox->x1;   /*x0, y0*/            *(bciptr) = (pbox->y1 <<16) | pbox->x1;            *(bciptr) = (h << 16) | w;        }            }}#endifstatic GLboolean intersect_rect( drm_clip_rect_t *out,				 const drm_clip_rect_t *a,				 const drm_clip_rect_t *b ){   *out = *a;   if (b->x1 > out->x1) out->x1 = b->x1;   if (b->y1 > out->y1) out->y1 = b->y1;   if (b->x2 < out->x2) out->x2 = b->x2;   if (b->y2 < out->y2) out->y2 = b->y2;   return ((out->x1 < out->x2) && (out->y1 < out->y2));}static GLuint savageIntersectClipRects(drm_clip_rect_t *dest,				       const drm_clip_rect_t *src,				       GLuint nsrc,				       const drm_clip_rect_t *clip){    GLuint i, ndest;    for (i = 0, ndest = 0; i < nsrc; ++i, ++src) {	if (intersect_rect(dest, src, clip)) {	    dest++;	    ndest++;	}    }    return ndest;}static void savageDDClear( GLcontext *ctx, GLbitfield mask ){   savageContextPtr imesa = SAVAGE_CONTEXT( ctx );

⌨️ 快捷键说明

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