📄 r128_dri.c
字号:
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ati/r128_dri.c,v 1.31 2003/09/28 20:15:53 alanh Exp $ *//* * Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario, * Precision Insight, Inc., Cedar Park, Texas, and * VA Linux Systems Inc., Fremont, California. * * 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, 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 (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 ATI, PRECISION INSIGHT, VA LINUX * SYSTEMS AND/OR THEIR 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. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <string.h>#include <stdio.h>/* * Authors: * Kevin E. Martin <martin@valinux.com> * Rickard E. Faith <faith@valinux.com> * Daryll Strauss <daryll@valinux.com> * Gareth Hughes <gareth@valinux.com> * */ /* Driver data structures */#include "r128.h"#include "r128_dri.h"#include "r128_common.h"#include "r128_reg.h"#include "r128_sarea.h"#include "r128_version.h" /* X and server generic header files */#include "xf86.h"#include "windowstr.h"#include "atipciids.h"#include "shadowfb.h" /* GLX/DRI/DRM definitions */#define _XF86DRI_SERVER_#include "GL/glxtokens.h"#include "sarea.h"static size_t r128_drm_page_size;static void R128DRITransitionTo2d(ScreenPtr pScreen);static void R128DRITransitionTo3d(ScreenPtr pScreen);static void R128DRITransitionMultiToSingle3d(ScreenPtr pScreen);static void R128DRITransitionSingleToMulti3d(ScreenPtr pScreen);static void R128DRIRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);/* Initialize the visual configs that are supported by the hardware. These are combined with the visual configs that the indirect rendering core supports, and the intersection is exported to the client. */static Bool R128InitVisualConfigs(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; R128InfoPtr info = R128PTR(pScrn); int numConfigs = 0; __GLXvisualConfig *pConfigs = 0; R128ConfigPrivPtr pR128Configs = 0; R128ConfigPrivPtr *pR128ConfigPtrs = 0; int i, accum, stencil, db; switch (info->CurrentLayout.pixel_code) { case 8: /* 8bpp mode is not support */ case 15: /* FIXME */ case 24: /* FIXME */ xf86DrvMsg(pScreen->myNum, X_ERROR, "[dri] R128DRIScreenInit failed (depth %d not supported). " "Disabling DRI.\n", info->CurrentLayout.pixel_code); return FALSE;#define R128_USE_ACCUM 1#define R128_USE_STENCIL 1#define R128_USE_DB 1 case 16: numConfigs = 1; if (R128_USE_ACCUM) numConfigs *= 2; if (R128_USE_STENCIL) numConfigs *= 2; if (R128_USE_DB) numConfigs *= 2; if (!(pConfigs = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pR128Configs = (R128ConfigPrivPtr)xcalloc(sizeof(R128ConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pR128ConfigPtrs = (R128ConfigPrivPtr*)xcalloc(sizeof(R128ConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pR128Configs); return FALSE; } i = 0; for (db = 0; db <= R128_USE_DB; db++) { for (accum = 0; accum <= R128_USE_ACCUM; accum++) { for (stencil = 0; stencil <= R128_USE_STENCIL; stencil++) { pR128ConfigPtrs[i] = &pR128Configs[i]; pConfigs[i].vid = (VisualID)(-1); pConfigs[i].class = -1; pConfigs[i].rgba = TRUE; pConfigs[i].redSize = 5; pConfigs[i].greenSize = 6; pConfigs[i].blueSize = 5; pConfigs[i].alphaSize = 0; pConfigs[i].redMask = 0x0000F800; pConfigs[i].greenMask = 0x000007E0; pConfigs[i].blueMask = 0x0000001F; pConfigs[i].alphaMask = 0x00000000; if (accum) { /* Simulated in software */ pConfigs[i].accumRedSize = 16; pConfigs[i].accumGreenSize = 16; pConfigs[i].accumBlueSize = 16; pConfigs[i].accumAlphaSize = 0; } else { pConfigs[i].accumRedSize = 0; pConfigs[i].accumGreenSize = 0; pConfigs[i].accumBlueSize = 0; pConfigs[i].accumAlphaSize = 0; } if (db) pConfigs[i].doubleBuffer = TRUE; else pConfigs[i].doubleBuffer = FALSE; pConfigs[i].stereo = FALSE; pConfigs[i].bufferSize = 16; pConfigs[i].depthSize = 16; if (stencil) pConfigs[i].stencilSize = 8; /* Simulated in software */ else pConfigs[i].stencilSize = 0; pConfigs[i].auxBuffers = 0; pConfigs[i].level = 0; if (accum || stencil) { pConfigs[i].visualRating = GLX_SLOW_CONFIG; } else { pConfigs[i].visualRating = GLX_NONE; } pConfigs[i].transparentPixel = GLX_NONE; pConfigs[i].transparentRed = 0; pConfigs[i].transparentGreen = 0; pConfigs[i].transparentBlue = 0; pConfigs[i].transparentAlpha = 0; pConfigs[i].transparentIndex = 0; i++; } } } break; case 32: numConfigs = 1; if (R128_USE_ACCUM) numConfigs *= 2; if (R128_USE_STENCIL) numConfigs *= 2; if (R128_USE_DB) numConfigs *= 2; if (!(pConfigs = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pR128Configs = (R128ConfigPrivPtr)xcalloc(sizeof(R128ConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pR128ConfigPtrs = (R128ConfigPrivPtr*)xcalloc(sizeof(R128ConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pR128Configs); return FALSE; } i = 0; for (db = 0; db <= R128_USE_DB; db++) { for (accum = 0; accum <= R128_USE_ACCUM; accum++) { for (stencil = 0; stencil <= R128_USE_STENCIL; stencil++) { pR128ConfigPtrs[i] = &pR128Configs[i]; pConfigs[i].vid = (VisualID)(-1); pConfigs[i].class = -1; pConfigs[i].rgba = TRUE; pConfigs[i].redSize = 8; pConfigs[i].greenSize = 8; pConfigs[i].blueSize = 8; pConfigs[i].alphaSize = 0; pConfigs[i].redMask = 0x00FF0000; pConfigs[i].greenMask = 0x0000FF00; pConfigs[i].blueMask = 0x000000FF; pConfigs[i].alphaMask = 0x00000000; if (accum) { /* Simulated in software */ pConfigs[i].accumRedSize = 16; pConfigs[i].accumGreenSize = 16; pConfigs[i].accumBlueSize = 16; pConfigs[i].accumAlphaSize = 0; } else { pConfigs[i].accumRedSize = 0; pConfigs[i].accumGreenSize = 0; pConfigs[i].accumBlueSize = 0; pConfigs[i].accumAlphaSize = 0; } if (db) pConfigs[i].doubleBuffer = TRUE; else pConfigs[i].doubleBuffer = FALSE; pConfigs[i].stereo = FALSE; pConfigs[i].bufferSize = 24; if (stencil) { pConfigs[i].depthSize = 24; pConfigs[i].stencilSize = 8; } else { pConfigs[i].depthSize = 24; pConfigs[i].stencilSize = 0; } pConfigs[i].auxBuffers = 0; pConfigs[i].level = 0; if (accum) { pConfigs[i].visualRating = GLX_SLOW_CONFIG; } else { pConfigs[i].visualRating = GLX_NONE; } pConfigs[i].transparentPixel = GLX_NONE; pConfigs[i].transparentRed = 0; pConfigs[i].transparentGreen = 0; pConfigs[i].transparentBlue = 0; pConfigs[i].transparentAlpha = 0; pConfigs[i].transparentIndex = 0; i++; } } } break; } info->numVisualConfigs = numConfigs; info->pVisualConfigs = pConfigs; info->pVisualConfigsPriv = pR128Configs; GlxSetVisualConfigs(numConfigs, pConfigs, (void**)pR128ConfigPtrs); return TRUE;}/* Create the Rage 128-specific context information */static Bool R128CreateContext(ScreenPtr pScreen, VisualPtr visual, drm_context_t hwContext, void *pVisualConfigPriv, DRIContextType contextStore){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; R128InfoPtr info = R128PTR(pScrn); info->drmCtx = hwContext; return TRUE;}/* Destroy the Rage 128-specific context information */static void R128DestroyContext(ScreenPtr pScreen, drm_context_t hwContext, DRIContextType contextStore){ /* Nothing yet */}/* Called when the X server is woken up to allow the last client's context to be saved and the X server's context to be loaded. This is not necessary for the Rage 128 since the client detects when it's context is not currently loaded and then load's it itself. Since the registers to start and stop the CCE are privileged, only the X server can start/stop the engine. */static void R128EnterServer(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; R128InfoPtr info = R128PTR(pScrn); if (info->accel) info->accel->NeedToSync = TRUE;}/* Called when the X server goes to sleep to allow the X server's context to be saved and the last client's context to be loaded. This is not necessary for the Rage 128 since the client detects when it's context is not currently loaded and then load's it itself. Since the registers to start and stop the CCE are privileged, only the X server can start/stop the engine. */static void R128LeaveServer(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; R128InfoPtr info = R128PTR(pScrn); unsigned char *R128MMIO = info->MMIO; if (!info->directRenderingEnabled) { /* Save all hardware scissors */ info->sc_left = INREG(R128_SC_LEFT); info->sc_right = INREG(R128_SC_RIGHT); info->sc_top = INREG(R128_SC_TOP); info->sc_bottom = INREG(R128_SC_BOTTOM); info->aux_sc_cntl = INREG(R128_SC_BOTTOM); } else if (info->CCEInUse) { R128CCEReleaseIndirect(pScrn); info->CCEInUse = FALSE; }}/* Contexts can be swapped by the X server if necessary. This callback is currently only used to perform any functions necessary when entering or leaving the X server, and in the future might not be necessary. */static void R128DRISwapContext(ScreenPtr pScreen, DRISyncType syncType, DRIContextType oldContextType, void *oldContext, DRIContextType newContextType, void *newContext){ if ((syncType==DRI_3D_SYNC) && (oldContextType==DRI_2D_CONTEXT) && (newContextType==DRI_2D_CONTEXT)) { /* Entering from Wakeup */ R128EnterServer(pScreen); } if ((syncType==DRI_2D_SYNC) && (oldContextType==DRI_NO_CONTEXT) && (newContextType==DRI_2D_CONTEXT)) { /* Exiting from Block Handler */ R128LeaveServer(pScreen); }}/* Initialize the state of the back and depth buffers. */static void R128DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 indx){ /* FIXME: This routine needs to have acceleration turned on */ ScreenPtr pScreen = pWin->drawable.pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; R128InfoPtr info = R128PTR(pScrn); BoxPtr pbox, pboxSave; int nbox, nboxSave; int depth; /* FIXME: Use accel when CCE 2D code is written * EA: What is this code kept for? Radeon doesn't have it and * has a comment: "There's no need for the 2d driver to be clearing * buffers for the 3d client. It knows how to do that on its own." */ if (info->directRenderingEnabled) return; /* FIXME: This should be based on the __GLXvisualConfig info */ switch (pScrn->bitsPerPixel) { case 8: depth = 0x000000ff; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -