via_screen.c

来自「mesa-6.5-minigui源码」· C语言 代码 · 共 503 行 · 第 1/2 页

C
503
字号
/* * 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 "utils.h"#include "dri_util.h"#include "glheader.h"#include "context.h"#include "framebuffer.h"#include "renderbuffer.h"#include "matrix.h"#include "simple_list.h"#include "vblank.h"#include "via_state.h"#include "via_tex.h"#include "via_span.h"#include "via_tris.h"#include "via_ioctl.h"#include "via_screen.h"#include "via_fb.h"#include "via_dri.h"#include "GL/internal/dri_interface.h"#include "drirenderbuffer.h"/* Radeon configuration */#include "xmlpool.h"const char __driConfigOptions[] =DRI_CONF_BEGIN    DRI_CONF_SECTION_PERFORMANCE        DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)        DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)    DRI_CONF_SECTION_END    DRI_CONF_SECTION_DEBUG        DRI_CONF_NO_RAST(false)    DRI_CONF_SECTION_ENDDRI_CONF_END;static const GLuint __driNConfigOptions = 3;extern const struct dri_extension card_extensions[];static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );static drmBufMapPtr via_create_empty_buffers(void){    drmBufMapPtr retval;    retval = (drmBufMapPtr)MALLOC(sizeof(drmBufMap));    if (retval == NULL) return NULL;    memset(retval, 0, sizeof(drmBufMap));    retval->list = (drmBufPtr)MALLOC(sizeof(drmBuf) * VIA_DMA_BUF_NR);    if (retval->list == NULL) {       FREE(retval);       return NULL;    }    memset(retval->list, 0, sizeof(drmBuf) * VIA_DMA_BUF_NR);    return retval;}static void via_free_empty_buffers( drmBufMapPtr bufs ){   if (bufs && bufs->list)      FREE(bufs->list);   if (bufs)      FREE(bufs);}static GLbooleanviaInitDriver(__DRIscreenPrivate *sPriv){    viaScreenPrivate *viaScreen;    VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv;    PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =      (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));    void * const psc = sPriv->psc->screenConfigs;    if (sPriv->devPrivSize != sizeof(VIADRIRec)) {      fprintf(stderr,"\nERROR!  sizeof(VIADRIRec) does not match passed size from device driver\n");      return GL_FALSE;    }    /* Allocate the private area */    viaScreen = (viaScreenPrivate *) CALLOC(sizeof(viaScreenPrivate));    if (!viaScreen) {        __driUtilMessage("viaInitDriver: alloc viaScreenPrivate struct failed");        return GL_FALSE;    }    /* parse information in __driConfigOptions */    driParseOptionInfo (&viaScreen->optionCache,			__driConfigOptions, __driNConfigOptions);    viaScreen->driScrnPriv = sPriv;    sPriv->private = (void *)viaScreen;    viaScreen->deviceID = gDRIPriv->deviceID;    viaScreen->width = gDRIPriv->width;    viaScreen->height = gDRIPriv->height;    viaScreen->mem = gDRIPriv->mem;    viaScreen->bitsPerPixel = gDRIPriv->bytesPerPixel * 8;    viaScreen->bytesPerPixel = gDRIPriv->bytesPerPixel;    viaScreen->fbOffset = 0;    viaScreen->fbSize = gDRIPriv->fbSize;    viaScreen->irqEnabled = gDRIPriv->irqEnabled;    viaScreen->irqEnabled = 1;    if (VIA_DEBUG & DEBUG_DRI) {	fprintf(stderr, "deviceID = %08x\n", viaScreen->deviceID);	fprintf(stderr, "width = %08x\n", viaScreen->width);		fprintf(stderr, "height = %08x\n", viaScreen->height);		fprintf(stderr, "cpp = %08x\n", viaScreen->cpp);		fprintf(stderr, "fbOffset = %08x\n", viaScreen->fbOffset);	    }    viaScreen->bufs = via_create_empty_buffers();    if (viaScreen->bufs == NULL) {        __driUtilMessage("viaInitDriver: via_create_empty_buffers() failed");        FREE(viaScreen);        return GL_FALSE;    }    if (drmMap(sPriv->fd,               gDRIPriv->regs.handle,               gDRIPriv->regs.size,               &viaScreen->reg) != 0) {        FREE(viaScreen);        sPriv->private = NULL;        __driUtilMessage("viaInitDriver: drmMap regs failed");        return GL_FALSE;    }    if (gDRIPriv->agp.size) {        if (drmMap(sPriv->fd,                   gDRIPriv->agp.handle,                   gDRIPriv->agp.size,	           (drmAddress *)&viaScreen->agpLinearStart) != 0) {	    drmUnmap(viaScreen->reg, gDRIPriv->regs.size);	    FREE(viaScreen);	    sPriv->private = NULL;	    __driUtilMessage("viaInitDriver: drmMap agp failed");	    return GL_FALSE;	}	    	/*	 * FIXME: This is an invalid assumption that works until handle is	 * changed to mean something else than the 32-bit physical AGP address.	 */	viaScreen->agpBase = gDRIPriv->agp.handle;    } else	viaScreen->agpLinearStart = 0;    viaScreen->sareaPrivOffset = gDRIPriv->sarea_priv_offset;    if ( glx_enable_extension != NULL ) {       if ( viaScreen->irqEnabled ) {	  (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );	  (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );	  (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );       }       (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );    }    return GL_TRUE;}static voidviaDestroyScreen(__DRIscreenPrivate *sPriv){    viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;    VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv;    drmUnmap(viaScreen->reg, gDRIPriv->regs.size);    if (gDRIPriv->agp.size)        drmUnmap(viaScreen->agpLinearStart, gDRIPriv->agp.size);    via_free_empty_buffers(viaScreen->bufs);    FREE(viaScreen);    sPriv->private = NULL;}static GLbooleanviaCreateBuffer(__DRIscreenPrivate *driScrnPriv,                __DRIdrawablePrivate *driDrawPriv,                const __GLcontextModes *mesaVis,                GLboolean isPixmap){    viaScreenPrivate *screen = (viaScreenPrivate *) driScrnPriv->private;    GLboolean swStencil = (mesaVis->stencilBits > 0 && 			   mesaVis->depthBits != 24);    GLboolean swAccum = mesaVis->accumRedBits > 0;    if (isPixmap) {       /* KW: This needs work, disabled for now:	*/#if 0	driDrawPriv->driverPrivate = (void *)            _mesa_create_framebuffer(mesaVis,                                     GL_FALSE,	/* software depth buffer? */                                     swStencil,                                     mesaVis->accumRedBits > 0,                                     GL_FALSE 	/* s/w alpha planes */);        return (driDrawPriv->driverPrivate != NULL);#endif	return GL_FALSE;    }    else {      struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);      /* The front color, back color and depth renderbuffers are       * set up later in calculate_buffer_parameters().       * Only create/connect software-based buffers here.       */#if 000      /* This code _should_ be put to use.  We have to move the       * viaRenderbuffer members out of the via_context structure.       * Those members should just be the renderbuffers hanging off the

⌨️ 快捷键说明

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