📄 mga_xmesa.c
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c,v 1.19 2003/03/26 20:43:49 tsi Exp $ *//* * Copyright 2000-2001 VA Linux Systems, 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 * on 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 * VA LINUX SYSTEMS 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. *//** * \file mga_xmesa.c * MGA screen and context initialization / creation code. * * \author Keith Whitwell <keith@tungstengraphics.com> */#include <stdlib.h>#include <stdint.h>#include "drm.h"#include "mga_drm.h"#include "mga_xmesa.h"#include "context.h"#include "matrix.h"#include "simple_list.h"#include "imports.h"#include "framebuffer.h"#include "renderbuffer.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "vbo/vbo.h"#include "tnl/t_pipeline.h"#include "drivers/common/driverfuncs.h"#include "mgadd.h"#include "mgastate.h"#include "mgatex.h"#include "mgaspan.h"#include "mgaioctl.h"#include "mgatris.h"#include "mgavb.h"#include "mgapixel.h"#include "mga_xmesa.h"#include "mga_dri.h"#include "utils.h"#include "vblank.h"#include "extensions.h"#include "drirenderbuffer.h"#include "GL/internal/dri_interface.h"#define need_GL_ARB_multisample#define need_GL_ARB_texture_compression#define need_GL_ARB_vertex_buffer_object#define need_GL_ARB_vertex_program#define need_GL_EXT_fog_coord#define need_GL_EXT_gpu_program_parameters#define need_GL_EXT_multi_draw_arrays#define need_GL_EXT_secondary_color#if 0#define need_GL_EXT_paletted_texture#endif#define need_GL_APPLE_vertex_array_object#define need_GL_NV_vertex_program#include "extension_helper.h"/* MGA configuration */#include "xmlpool.h"PUBLIC const char __driConfigOptions[] =DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB) DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER) DRI_CONF_SECTION_END DRI_CONF_SECTION_SOFTWARE DRI_CONF_ARB_VERTEX_PROGRAM(true) DRI_CONF_NV_VERTEX_PROGRAM(true) DRI_CONF_SECTION_END DRI_CONF_SECTION_DEBUG DRI_CONF_NO_RAST(false) DRI_CONF_SECTION_ENDDRI_CONF_END;static const GLuint __driNConfigOptions = 6;#ifndef MGA_DEBUGint MGA_DEBUG = 0;#endifstatic const __DRIconfig **mgaFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ){ __DRIconfig **configs; __GLcontextModes * m; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; int i; /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't * support pageflipping at all. */ static const GLenum back_buffer_modes[] = { GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML }; u_int8_t depth_bits_array[3]; u_int8_t stencil_bits_array[3]; depth_bits_array[0] = 0; depth_bits_array[1] = depth_bits; depth_bits_array[2] = depth_bits; /* Just like with the accumulation buffer, always provide some modes * with a stencil buffer. It will be a sw fallback, but some apps won't * care about that. */ stencil_bits_array[0] = 0; stencil_bits_array[1] = 0; stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits; depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; } else { fb_format = GL_BGR; fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } configs = driCreateConfigs(fb_format, fb_type, depth_bits_array, stencil_bits_array, depth_buffer_factor, back_buffer_modes, back_buffer_factor); if (configs == NULL) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__ ); return NULL; } /* Mark the visual as slow if there are "fake" stencil bits. */ for (i = 0; configs[i]; i++) { m = &configs[i]->modes; if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { m->visualRating = GLX_SLOW_CONFIG; } } return (const __DRIconfig **) configs;}const __DRIextension *mgaScreenExtensions[] = { &driReadDrawableExtension, &driSwapControlExtension.base, &driFrameTrackingExtension.base, &driMediaStreamCounterExtension.base, NULL};static GLbooleanmgaInitDriver(__DRIscreenPrivate *sPriv){ mgaScreenPrivate *mgaScreen; MGADRIPtr serverInfo = (MGADRIPtr)sPriv->pDevPriv; if (sPriv->devPrivSize != sizeof(MGADRIRec)) { fprintf(stderr,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n"); return GL_FALSE; } /* Allocate the private area */ mgaScreen = (mgaScreenPrivate *)MALLOC(sizeof(mgaScreenPrivate)); if (!mgaScreen) { __driUtilMessage("Couldn't malloc screen struct"); return GL_FALSE; } mgaScreen->sPriv = sPriv; sPriv->private = (void *)mgaScreen; if (sPriv->drm_version.minor >= 1) { int ret; drm_mga_getparam_t gp; gp.param = MGA_PARAM_IRQ_NR; gp.value = &mgaScreen->irq; mgaScreen->irq = 0; ret = drmCommandWriteRead( sPriv->fd, DRM_MGA_GETPARAM, &gp, sizeof(gp)); if (ret) { fprintf(stderr, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret); FREE(mgaScreen); sPriv->private = NULL; return GL_FALSE; } } sPriv->extensions = mgaScreenExtensions; if (serverInfo->chipset != MGA_CARD_TYPE_G200 && serverInfo->chipset != MGA_CARD_TYPE_G400) { FREE(mgaScreen); sPriv->private = NULL; __driUtilMessage("Unrecognized chipset"); return GL_FALSE; } mgaScreen->chipset = serverInfo->chipset; mgaScreen->cpp = serverInfo->cpp; mgaScreen->agpMode = serverInfo->agpMode; mgaScreen->frontPitch = serverInfo->frontPitch; mgaScreen->frontOffset = serverInfo->frontOffset; mgaScreen->backOffset = serverInfo->backOffset; mgaScreen->backPitch = serverInfo->backPitch; mgaScreen->depthOffset = serverInfo->depthOffset; mgaScreen->depthPitch = serverInfo->depthPitch; /* The only reason that the MMIO region needs to be accessable and the * primary DMA region base address needs to be known is so that the driver * can busy wait for certain DMA operations to complete (see * mgaWaitForFrameCompletion in mgaioctl.c). * * Starting with MGA DRM version 3.2, these are completely unneeded as * there is a new, in-kernel mechanism for handling the wait. */ if (mgaScreen->sPriv->drm_version.minor < 2) { mgaScreen->mmio.handle = serverInfo->registers.handle; mgaScreen->mmio.size = serverInfo->registers.size; if ( drmMap( sPriv->fd, mgaScreen->mmio.handle, mgaScreen->mmio.size, &mgaScreen->mmio.map ) < 0 ) { FREE( mgaScreen ); sPriv->private = NULL; __driUtilMessage( "Couldn't map MMIO registers" ); return GL_FALSE; } mgaScreen->primary.handle = serverInfo->primary.handle; mgaScreen->primary.size = serverInfo->primary.size; } else { (void) memset( & mgaScreen->primary, 0, sizeof( mgaScreen->primary ) ); (void) memset( & mgaScreen->mmio, 0, sizeof( mgaScreen->mmio ) ); } mgaScreen->textureOffset[MGA_CARD_HEAP] = serverInfo->textureOffset; mgaScreen->textureOffset[MGA_AGP_HEAP] = (serverInfo->agpTextureOffset | PDEA_pagpxfer_enable | 1); mgaScreen->textureSize[MGA_CARD_HEAP] = serverInfo->textureSize; mgaScreen->textureSize[MGA_AGP_HEAP] = serverInfo->agpTextureSize; /* The texVirtual array stores the base addresses in the CPU's address * space of the texture memory pools. The base address of the on-card * memory pool is calculated as an offset of the base of video memory. The * AGP texture pool has to be mapped into the processes address space by * the DRM. */ mgaScreen->texVirtual[MGA_CARD_HEAP] = (char *)(mgaScreen->sPriv->pFB + serverInfo->textureOffset); if ( serverInfo->agpTextureSize > 0 ) { if (drmMap(sPriv->fd, serverInfo->agpTextureOffset, serverInfo->agpTextureSize, (drmAddress *)&mgaScreen->texVirtual[MGA_AGP_HEAP]) != 0) { FREE(mgaScreen); sPriv->private = NULL; __driUtilMessage("Couldn't map agptexture region"); return GL_FALSE; } } /* For calculating setupdma addresses. */ mgaScreen->bufs = drmMapBufs(sPriv->fd); if (!mgaScreen->bufs) { FREE(mgaScreen); sPriv->private = NULL; __driUtilMessage("Couldn't map dma buffers"); return GL_FALSE; } mgaScreen->sarea_priv_offset = serverInfo->sarea_priv_offset; /* parse information in __driConfigOptions */ driParseOptionInfo (&mgaScreen->optionCache, __driConfigOptions, __driNConfigOptions); return GL_TRUE;}static voidmgaDestroyScreen(__DRIscreenPrivate *sPriv){ mgaScreenPrivate *mgaScreen = (mgaScreenPrivate *) sPriv->private; if (MGA_DEBUG&DEBUG_VERBOSE_DRI)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -