📄 ffb_xmesa.c
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_xmesa.c,v 1.4 2002/02/22 21:32:59 dawes Exp $ * * GLX Hardware Device Driver for Sun Creator/Creator3D * Copyright (C) 2000, 2001 David S. Miller * * 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 * DAVID MILLER, OR ANY OTHER CONTRIBUTORS 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. * * * David S. Miller <davem@redhat.com> */#include "ffb_xmesa.h"#include "context.h"#include "framebuffer.h"#include "matrix.h"#include "renderbuffer.h"#include "simple_list.h"#include "imports.h"#include "utils.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "tnl/t_pipeline.h"#include "vbo/vbo.h"#include "drivers/common/driverfuncs.h"#include "ffb_context.h"#include "ffb_dd.h"#include "ffb_span.h"#include "ffb_depth.h"#include "ffb_stencil.h"#include "ffb_clear.h"#include "ffb_vb.h"#include "ffb_tris.h"#include "ffb_lines.h"#include "ffb_points.h"#include "ffb_state.h"#include "ffb_tex.h"#include "ffb_lock.h"#include "ffb_vtxfmt.h"#include "ffb_bitmap.h"#include "drm_sarea.h"#include "drirenderbuffer.h"static GLbooleanffbInitDriver(__DRIscreenPrivate *sPriv){ ffbScreenPrivate *ffbScreen; FFBDRIPtr gDRIPriv = (FFBDRIPtr) sPriv->pDevPriv; drmAddress map; if (getenv("LIBGL_FORCE_XSERVER")) return GL_FALSE; if (sPriv->devPrivSize != sizeof(FFBDRIRec)) { fprintf(stderr,"\nERROR! sizeof(FFBDRIRec) does not match passed size from device driver\n"); return GL_FALSE; } /* Allocate the private area. */ ffbScreen = (ffbScreenPrivate *) MALLOC(sizeof(ffbScreenPrivate)); if (!ffbScreen) return GL_FALSE; /* Map FBC registers. */ if (drmMap(sPriv->fd, gDRIPriv->hFbcRegs, gDRIPriv->sFbcRegs, &map)) { FREE(ffbScreen); return GL_FALSE; } ffbScreen->regs = (ffb_fbcPtr) map; /* Map ramdac registers. */ if (drmMap(sPriv->fd, gDRIPriv->hDacRegs, gDRIPriv->sDacRegs, &map)) { drmUnmap((drmAddress)ffbScreen->regs, gDRIPriv->sFbcRegs); FREE(ffbScreen); return GL_FALSE; } ffbScreen->dac = (ffb_dacPtr) map; /* Map "Smart" framebuffer views. */ if (drmMap(sPriv->fd, gDRIPriv->hSfb8r, gDRIPriv->sSfb8r, &map)) { drmUnmap((drmAddress)ffbScreen->regs, gDRIPriv->sFbcRegs); drmUnmap((drmAddress)ffbScreen->dac, gDRIPriv->sDacRegs); FREE(ffbScreen); return GL_FALSE; } ffbScreen->sfb8r = (volatile char *) map; if (drmMap(sPriv->fd, gDRIPriv->hSfb32, gDRIPriv->sSfb32, &map)) { drmUnmap((drmAddress)ffbScreen->regs, gDRIPriv->sFbcRegs); drmUnmap((drmAddress)ffbScreen->dac, gDRIPriv->sDacRegs); drmUnmap((drmAddress)ffbScreen->sfb8r, gDRIPriv->sSfb8r); FREE(ffbScreen); return GL_FALSE; } ffbScreen->sfb32 = (volatile char *) map; if (drmMap(sPriv->fd, gDRIPriv->hSfb64, gDRIPriv->sSfb64, &map)) { drmUnmap((drmAddress)ffbScreen->regs, gDRIPriv->sFbcRegs); drmUnmap((drmAddress)ffbScreen->dac, gDRIPriv->sDacRegs); drmUnmap((drmAddress)ffbScreen->sfb8r, gDRIPriv->sSfb8r); drmUnmap((drmAddress)ffbScreen->sfb32, gDRIPriv->sSfb32); FREE(ffbScreen); return GL_FALSE; } ffbScreen->sfb64 = (volatile char *) map; ffbScreen->fifo_cache = 0; ffbScreen->rp_active = 0; ffbScreen->sPriv = sPriv; sPriv->private = (void *) ffbScreen; ffbDDLinefuncInit(); ffbDDPointfuncInit(); return GL_TRUE;}static voidffbDestroyScreen(__DRIscreenPrivate *sPriv){ ffbScreenPrivate *ffbScreen = sPriv->private; FFBDRIPtr gDRIPriv = (FFBDRIPtr) sPriv->pDevPriv; drmUnmap((drmAddress)ffbScreen->regs, gDRIPriv->sFbcRegs); drmUnmap((drmAddress)ffbScreen->dac, gDRIPriv->sDacRegs); drmUnmap((drmAddress)ffbScreen->sfb8r, gDRIPriv->sSfb8r); drmUnmap((drmAddress)ffbScreen->sfb32, gDRIPriv->sSfb32); drmUnmap((drmAddress)ffbScreen->sfb64, gDRIPriv->sSfb64); FREE(ffbScreen);}static const struct tnl_pipeline_stage *ffb_pipeline[] = { &_tnl_vertex_transform_stage, &_tnl_normal_transform_stage, &_tnl_lighting_stage, /* REMOVE: fog coord stage */ &_tnl_texgen_stage, &_tnl_texture_transform_stage, /* REMOVE: point attenuation stage */ &_tnl_render_stage, 0,};/* Create and initialize the Mesa and driver specific context data */static GLbooleanffbCreateContext(const __GLcontextModes *mesaVis, __DRIcontextPrivate *driContextPriv, void *sharedContextPrivate){ ffbContextPtr fmesa; GLcontext *ctx, *shareCtx; __DRIscreenPrivate *sPriv; ffbScreenPrivate *ffbScreen; char *debug; struct dd_function_table functions; /* Allocate ffb context */ fmesa = (ffbContextPtr) CALLOC(sizeof(ffbContextRec)); if (!fmesa) return GL_FALSE; _mesa_init_driver_functions(&functions); /* Allocate Mesa context */ if (sharedContextPrivate) shareCtx = ((ffbContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; fmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, &functions, fmesa); if (!fmesa->glCtx) { FREE(fmesa); return GL_FALSE; } driContextPriv->driverPrivate = fmesa; ctx = fmesa->glCtx; sPriv = driContextPriv->driScreenPriv; ffbScreen = (ffbScreenPrivate *) sPriv->private; /* Dri stuff. */ fmesa->hHWContext = driContextPriv->hHWContext; fmesa->driFd = sPriv->fd; fmesa->driHwLock = &sPriv->pSAREA->lock; fmesa->ffbScreen = ffbScreen; fmesa->driScreen = sPriv; fmesa->ffb_sarea = FFB_DRISHARE(sPriv->pSAREA); /* Register and framebuffer hw pointers. */ fmesa->regs = ffbScreen->regs; fmesa->sfb32 = ffbScreen->sfb32; ffbDDInitContextHwState(ctx); /* Default clear and depth colors. */ { GLubyte r = (GLint) (ctx->Color.ClearColor[0] * 255.0F); GLubyte g = (GLint) (ctx->Color.ClearColor[1] * 255.0F); GLubyte b = (GLint) (ctx->Color.ClearColor[2] * 255.0F); fmesa->clear_pixel = ((r << 0) | (g << 8) | (b << 16)); } fmesa->clear_depth = Z_FROM_MESA(ctx->Depth.Clear * 4294967295.0f); fmesa->clear_stencil = ctx->Stencil.Clear & 0xf; /* No wide points. */ ctx->Const.MinPointSize = 1.0; ctx->Const.MinPointSizeAA = 1.0; ctx->Const.MaxPointSize = 1.0; ctx->Const.MaxPointSizeAA = 1.0; /* Disable wide lines as we can't antialias them correctly in * hardware. */ ctx->Const.MinLineWidth = 1.0; ctx->Const.MinLineWidthAA = 1.0; ctx->Const.MaxLineWidth = 1.0; ctx->Const.MaxLineWidthAA = 1.0; ctx->Const.LineWidthGranularity = 1.0; /* Instead of having GCC emit these constants a zillion times * everywhere in the driver, put them here. */ fmesa->ffb_2_30_fixed_scale = __FFB_2_30_FIXED_SCALE; fmesa->ffb_one_over_2_30_fixed_scale = (1.0 / __FFB_2_30_FIXED_SCALE); fmesa->ffb_16_16_fixed_scale = __FFB_16_16_FIXED_SCALE; fmesa->ffb_one_over_16_16_fixed_scale = (1.0 / __FFB_16_16_FIXED_SCALE); fmesa->ffb_ubyte_color_scale = 255.0f; fmesa->ffb_zero = 0.0f; fmesa->debugFallbacks = GL_FALSE; debug = getenv("LIBGL_DEBUG"); if (debug && strstr(debug, "fallbacks")) fmesa->debugFallbacks = GL_TRUE; /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); /* All of this need only be done once for a new context. */ /* XXX these should be moved right after the * _mesa_init_driver_functions() call above. */ ffbDDExtensionsInit(ctx); ffbDDInitDriverFuncs(ctx); ffbDDInitStateFuncs(ctx); ffbDDInitRenderFuncs(ctx); /*ffbDDInitTexFuncs(ctx); not needed */ ffbDDInitBitmapFuncs(ctx); ffbInitVB(ctx);#if 0 ffbInitTnlModule(ctx);#endif _tnl_destroy_pipeline(ctx); _tnl_install_pipeline(ctx, ffb_pipeline); return GL_TRUE;}static voidffbDestroyContext(__DRIcontextPrivate *driContextPriv){ ffbContextPtr fmesa = (ffbContextPtr) driContextPriv->driverPrivate; if (fmesa) { ffbFreeVB(fmesa->glCtx); _swsetup_DestroyContext( fmesa->glCtx ); _tnl_DestroyContext( fmesa->glCtx ); _vbo_DestroyContext( fmesa->glCtx ); _swrast_DestroyContext( fmesa->glCtx ); /* free the Mesa context */ fmesa->glCtx->DriverCtx = NULL; _mesa_destroy_context(fmesa->glCtx); FREE(fmesa); }}/* Create and initialize the Mesa and driver specific pixmap buffer data */static GLbooleanffbCreateBuffer(__DRIscreenPrivate *driScrnPriv, __DRIdrawablePrivate *driDrawPriv, const __GLcontextModes *mesaVis, GLboolean isPixmap ){ /* Mesa checks for pitch > 0, but ffb doesn't use pitches */ int bogusPitch = 1; int bpp = 4; /* we've always got a 32bpp framebuffer */ int offset = 0; /* always at 0 for offset */ if (isPixmap) { return GL_FALSE; /* not implemented */ } else { GLboolean swStencil = (mesaVis->stencilBits > 0 && mesaVis->depthBits != 24); struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis); { driRenderbuffer *frontRb = driNewRenderbuffer(GL_RGBA, NULL, bpp, offset, bogusPitch, driDrawPriv); ffbSetSpanFunctions(frontRb, mesaVis); _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base); } if (mesaVis->doubleBufferMode) { driRenderbuffer *backRb = driNewRenderbuffer(GL_RGBA, NULL, bpp, offset, bogusPitch, driDrawPriv); ffbSetSpanFunctions(backRb, mesaVis); _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -