📄 i830_accel.c
字号:
/* * XXX So far, for GXxor this is about 40% of the speed of SW, but CPU * utilisation falls from 95% to < 5%. */#ifndef DO_SCANLINE_IMAGE_WRITE#define DO_SCANLINE_IMAGE_WRITE 0#endif/**************************************************************************Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sub license, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantial portionsof the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FORANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830_accel.c,v 1.8 2003/04/24 18:00:24 eich Exp $ *//* * Reformatted with GNU indent (2.2.8), using the following options: * * -bad -bap -c41 -cd0 -ncdb -ci6 -cli0 -cp0 -ncs -d0 -di3 -i3 -ip3 -l78 * -lp -npcs -psl -sob -ss -br -ce -sc -hnl * * This provides a good match with the original i810 code and preferred * XFree86 formatting conventions. * * When editing this driver, please follow the existing formatting, and edit * with <TAB> characters expanded at 8-column intervals. *//* * Authors: * Keith Whitwell <keith@tungstengraphics.com> * */#include "xf86_ansic.h"#include "xf86.h"#include "xaarop.h"#include "i830.h"#include "i810_reg.h"intI830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis){ I830Ptr pI830 = I830PTR(pScrn); I830RingBuffer *ring = pI830->LpRing; int iters = 0; int start = 0; int now = 0; int last_head = 0; int first = 0; /* If your system hasn't moved the head pointer in 2 seconds, I'm going to * call it crashed. */ if (timeout_millis == 0) timeout_millis = 2000; if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) { ErrorF("I830WaitLpRing %d\n", n); first = GetTimeInMillis(); } while (ring->space < n) { ring->head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK; ring->space = ring->head - (ring->tail + 8); if (ring->space < 0) ring->space += ring->mem.Size; iters++; now = GetTimeInMillis(); if (start == 0 || now < start || ring->head != last_head) { if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) if (now > start) ErrorF("space: %d wanted %d\n", ring->space, n); start = now; last_head = ring->head; } else if (now - start > timeout_millis) { ErrorF("Error in I830WaitLpRing(), now is %d, start is %d\n", now, start); I830PrintErrorState(pScrn); ErrorF("space: %d wanted %d\n", ring->space, n);#ifdef XF86DRI if (pI830->directRenderingEnabled) { DRIUnlock(screenInfo.screens[pScrn->scrnIndex]); DRICloseScreen(screenInfo.screens[pScrn->scrnIndex]); }#endif pI830->AccelInfoRec = NULL; /* Stops recursive behavior */ FatalError("lockup\n"); } DELAY(10); } if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) { now = GetTimeInMillis(); if (now - first) { ErrorF("Elapsed %d ms\n", now - first); ErrorF("space: %d wanted %d\n", ring->space, n); } } return iters;}voidI830Sync(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); if (I810_DEBUG & (DEBUG_VERBOSE_ACCEL | DEBUG_VERBOSE_SYNC)) ErrorF("I830Sync\n");#ifdef XF86DRI /* VT switching tries to do this. */ if (!pI830->LockHeld && pI830->directRenderingEnabled) { return; }#endif if (pI830->entityPrivate && !pI830->entityPrivate->RingRunning) return; /* Send a flush instruction and then wait till the ring is empty. * This is stronger than waiting for the blitter to finish as it also * flushes the internal graphics caches. */ { BEGIN_LP_RING(2); OUT_RING(MI_FLUSH | MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE); OUT_RING(MI_NOOP); /* pad to quadword */ ADVANCE_LP_RING(); } I830WaitLpRing(pScrn, pI830->LpRing->mem.Size - 8, 0); pI830->LpRing->space = pI830->LpRing->mem.Size - 8; pI830->nextColorExpandBuf = 0;}voidI830EmitFlush(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); BEGIN_LP_RING(2); OUT_RING(MI_FLUSH | MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE); OUT_RING(MI_NOOP); /* pad to quadword */ ADVANCE_LP_RING();}voidI830SelectBuffer(ScrnInfoPtr pScrn, int buffer){ I830Ptr pI830 = I830PTR(pScrn); switch (buffer) {#ifdef XF86DRI case I830_SELECT_BACK: pI830->bufferOffset = pI830->BackBuffer.Start; break; case I830_SELECT_DEPTH: pI830->bufferOffset = pI830->DepthBuffer.Start; break;#endif default: case I830_SELECT_FRONT: pI830->bufferOffset = pScrn->fbOffset; break; } if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) ErrorF("I830SelectBuffer %d --> offset %x\n", buffer, pI830->bufferOffset);}voidI830RefreshRing(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); pI830->LpRing->head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK; pI830->LpRing->tail = INREG(LP_RING + RING_TAIL); pI830->LpRing->space = pI830->LpRing->head - (pI830->LpRing->tail + 8); if (pI830->LpRing->space < 0) pI830->LpRing->space += pI830->LpRing->mem.Size; if (pI830->AccelInfoRec) pI830->AccelInfoRec->NeedToSync = TRUE;}/* I830 Accel Functions */static void I830SetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int pattx, int patty, int fg, int bg, int rop, unsigned int planemask);static void I830SubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int pattx, int patty, int x, int y, int w, int h);static void I830SetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int fg, int bg, int rop, unsigned int mask);static void I830SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int x, int y, int w, int h, int skipleft);static void I830SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno);#if DO_SCANLINE_IMAGE_WRITEstatic void I830SetupForScanlineImageWrite(ScrnInfoPtr pScrn, int rop, unsigned int planemask, int trans_color, int bpp, int depth);static void I830SubsequentScanlineImageWriteRect(ScrnInfoPtr pScrn, int x, int y, int w, int h, int skipleft);static void I830SubsequentImageWriteScanline(ScrnInfoPtr pScrn, int bufno);#endifstatic void I830RestoreAccelState(ScrnInfoPtr pScrn);/* The following function sets up the supported acceleration. Call it * from the FbInit() function in the SVGA driver, or before ScreenInit * in a monolithic server. */BoolI830AccelInit(ScreenPtr pScreen){ XAAInfoRecPtr infoPtr; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; I830Ptr pI830 = I830PTR(pScrn); int i; int width = 0; int nr_buffers = 0; unsigned char *ptr = NULL; if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) ErrorF("I830AccelInit\n"); pI830->AccelInfoRec = infoPtr = XAACreateInfoRec(); if (!infoPtr) return FALSE; pI830->bufferOffset = 0; infoPtr->Flags = LINEAR_FRAMEBUFFER | OFFSCREEN_PIXMAPS | PIXMAP_CACHE; /* Use the same sync function as the I830. */ infoPtr->Sync = I830Sync; /* Everything else is different enough to justify different functions */ { infoPtr->SolidFillFlags = NO_PLANEMASK; infoPtr->SetupForSolidFill = I830SetupForSolidFill; infoPtr->SubsequentSolidFillRect = I830SubsequentSolidFillRect; } { infoPtr->ScreenToScreenCopyFlags = (NO_PLANEMASK | NO_TRANSPARENCY); infoPtr->SetupForScreenToScreenCopy = I830SetupForScreenToScreenCopy; infoPtr->SubsequentScreenToScreenCopy = I830SubsequentScreenToScreenCopy; } { infoPtr->SetupForMono8x8PatternFill = I830SetupForMono8x8PatternFill; infoPtr->SubsequentMono8x8PatternFillRect = I830SubsequentMono8x8PatternFillRect; infoPtr->Mono8x8PatternFillFlags = (HARDWARE_PATTERN_PROGRAMMED_BITS | HARDWARE_PATTERN_SCREEN_ORIGIN | HARDWARE_PATTERN_PROGRAMMED_ORIGIN | BIT_ORDER_IN_BYTE_MSBFIRST | NO_PLANEMASK); } /* On the primary screen */ if (pI830->init == 0) { if (pI830->Scratch.Size != 0) { width = ((pScrn->displayWidth + 31) & ~31) / 8; nr_buffers = pI830->Scratch.Size / width; ptr = pI830->FbBase + pI830->Scratch.Start; } } else { /* On the secondary screen */ I830Ptr pI8301 = I830PTR(pI830->entityPrivate->pScrn_1); if (pI8301->Scratch2.Size != 0) { width = ((pScrn->displayWidth + 31) & ~31) / 8; nr_buffers = pI8301->Scratch2.Size / width; /* We have to use the primary screen's FbBase, as that's where * we allocated Scratch2, so we get the correct pointer */ ptr = pI8301->FbBase + pI8301->Scratch2.Start; } } if (nr_buffers) { pI830->NumScanlineColorExpandBuffers = nr_buffers; pI830->ScanlineColorExpandBuffers = (unsigned char **) xnfcalloc(nr_buffers, sizeof(unsigned char *)); for (i = 0; i < nr_buffers; i++, ptr += width) pI830->ScanlineColorExpandBuffers[i] = ptr; infoPtr->ScanlineCPUToScreenColorExpandFillFlags = (NO_PLANEMASK | ROP_NEEDS_SOURCE | BIT_ORDER_IN_BYTE_MSBFIRST); infoPtr->ScanlineColorExpandBuffers = (unsigned char **) xnfcalloc(1, sizeof(unsigned char *)); infoPtr->NumScanlineColorExpandBuffers = 1; infoPtr->ScanlineColorExpandBuffers[0] = pI830->ScanlineColorExpandBuffers[0]; pI830->nextColorExpandBuf = 0; infoPtr->SetupForScanlineCPUToScreenColorExpandFill = I830SetupForScanlineCPUToScreenColorExpandFill; infoPtr->SubsequentScanlineCPUToScreenColorExpandFill = I830SubsequentScanlineCPUToScreenColorExpandFill; infoPtr->SubsequentColorExpandScanline = I830SubsequentColorExpandScanline;#if DO_SCANLINE_IMAGE_WRITE infoPtr->NumScanlineImageWriteBuffers = 1; infoPtr->ScanlineImageWriteBuffers = infoPtr->ScanlineColorExpandBuffers; infoPtr->SetupForScanlineImageWrite = I830SetupForScanlineImageWrite; infoPtr->SubsequentScanlineImageWriteRect = I830SubsequentScanlineImageWriteRect; infoPtr->SubsequentImageWriteScanline = I830SubsequentImageWriteScanline; infoPtr->ScanlineImageWriteFlags = NO_GXCOPY | NO_PLANEMASK | ROP_NEEDS_SOURCE | SCANLINE_PAD_DWORD;#endif } { Bool shared_accel = FALSE; int i; for(i = 0; i < pScrn->numEntities; i++) { if(xf86IsEntityShared(pScrn->entityList[i])) shared_accel = TRUE; } if(shared_accel == TRUE) infoPtr->RestoreAccelState = I830RestoreAccelState; } I830SelectBuffer(pScrn, I830_SELECT_FRONT); return XAAInit(pScreen, infoPtr);}voidI830SetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop, unsigned int planemask){ I830Ptr pI830 = I830PTR(pScrn); if (I810_DEBUG & DEBUG_VERBOSE_ACCEL) ErrorF("I830SetupForFillRectSolid color: %x rop: %x mask: %x\n", color, rop, planemask); pI830->BR[13] = ((XAAGetPatternROP(rop) << 16) | (pScrn->displayWidth * pI830->cpp));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -