i810_video.c
来自「是由intel提供的针对intel显卡915以上系列的linux驱动」· C语言 代码 · 共 1,420 行 · 第 1/3 页
C
1,420 行
/*************************************************************************** Copyright 2000 Intel Corporation. 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 INTEL, 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.**************************************************************************//* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i810_video.c,v 1.26 2003/11/10 18:22:22 tsi Exp $ *//* * i810_video.c: i810 Xv driver. Based on the mga Xv driver by Mark Vojkovich. * * Authors: * Jonathan Bian <jonathan.bian@intel.com> * Offscreen Images: * Matt Sottek <matthew.j.sottek@intel.com> */#include "xf86.h"#include "xf86_OSproc.h"#include "xf86Resources.h"#include "xf86_ansic.h"#include "compiler.h"#include "xf86PciInfo.h"#include "xf86Pci.h"#include "xf86fbman.h"#include "regionstr.h"#include "i810.h"#include "xf86xv.h"#include <X11/extensions/Xv.h>#include "xaa.h"#include "xaalocal.h"#include "dixstruct.h"#include "fourcc.h"#define OFF_DELAY 250 /* milliseconds */#define FREE_DELAY 15000#define OFF_TIMER 0x01#define FREE_TIMER 0x02#define CLIENT_VIDEO_ON 0x04#define TIMER_MASK (OFF_TIMER | FREE_TIMER)static void I810InitOffscreenImages(ScreenPtr);static XF86VideoAdaptorPtr I810SetupImageVideo(ScreenPtr);static void I810StopVideo(ScrnInfoPtr, pointer, Bool);static int I810SetPortAttribute(ScrnInfoPtr, Atom, INT32, pointer);static int I810GetPortAttribute(ScrnInfoPtr, Atom ,INT32 *, pointer);static void I810QueryBestSize(ScrnInfoPtr, Bool, short, short, short, short, unsigned int *, unsigned int *, pointer);static int I810PutImage( ScrnInfoPtr, short, short, short, short, short, short, short, short, int, unsigned char*, short, short, Bool, RegionPtr, pointer);static int I810QueryImageAttributes(ScrnInfoPtr, int, unsigned short *, unsigned short *, int *, int *);static void I810BlockHandler(int, pointer, pointer, pointer);#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)static Atom xvBrightness, xvContrast, xvColorKey;#define IMAGE_MAX_WIDTH 1440#define IMAGE_FAST_WIDTH 720#define IMAGE_MAX_HEIGHT 1080#define Y_BUF_SIZE (IMAGE_MAX_WIDTH * IMAGE_MAX_HEIGHT)#define OVERLAY_UPDATE(p) OUTREG(0x30000, p | 0x80000000);/* * OV0CMD - Overlay Command Register */#define VERTICAL_CHROMINANCE_FILTER 0x70000000#define VC_SCALING_OFF 0x00000000#define VC_LINE_REPLICATION 0x10000000#define VC_UP_INTERPOLATION 0x20000000#define VC_PIXEL_DROPPING 0x50000000#define VC_DOWN_INTERPOLATION 0x60000000#define VERTICAL_LUMINANCE_FILTER 0x0E000000#define VL_SCALING_OFF 0x00000000#define VL_LINE_REPLICATION 0x02000000#define VL_UP_INTERPOLATION 0x04000000#define VL_PIXEL_DROPPING 0x0A000000#define VL_DOWN_INTERPOLATION 0x0C000000#define HORIZONTAL_CHROMINANCE_FILTER 0x01C00000#define HC_SCALING_OFF 0x00000000#define HC_LINE_REPLICATION 0x00400000#define HC_UP_INTERPOLATION 0x00800000#define HC_PIXEL_DROPPING 0x01400000#define HC_DOWN_INTERPOLATION 0x01800000#define HORIZONTAL_LUMINANCE_FILTER 0x00380000#define HL_SCALING_OFF 0x00000000#define HL_LINE_REPLICATION 0x00080000#define HL_UP_INTERPOLATION 0x00100000#define HL_PIXEL_DROPPING 0x00280000#define HL_DOWN_INTERPOLATION 0x00300000#define Y_ADJUST 0x00010000 #define OV_BYTE_ORDER 0x0000C000#define UV_SWAP 0x00004000#define Y_SWAP 0x00008000#define Y_AND_UV_SWAP 0x0000C000#define SOURCE_FORMAT 0x00003C00#define RGB_555 0x00000800#define RGB_565 0x00000C00#define YUV_422 0x00002000#define YUV_411 0x00002400#define YUV_420 0x00003000#define YUV_410 0x00003800#define BUFFER_AND_FIELD 0x00000006#define BUFFER0_FIELD0 0x00000000#define BUFFER1_FIELD0 0x00000004#define OVERLAY_ENABLE 0x00000001#define UV_VERT_BUF1 0x02#define UV_VERT_BUF0 0x04/* * DOV0STA - Display/Overlay 0 Status Register */#define DOV0STA 0x30008#define MINUV_SCALE 0x1#define RGB16ToColorKey(c) \ (((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3))#define RGB15ToColorKey(c) \ (((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3))void I810InitVideo(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL; XF86VideoAdaptorPtr newAdaptor = NULL; int num_adaptors; if (pScrn->bitsPerPixel != 8) { newAdaptor = I810SetupImageVideo(pScreen); I810InitOffscreenImages(pScreen); } num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors); if(newAdaptor) { if(!num_adaptors) { num_adaptors = 1; adaptors = &newAdaptor; } else { newAdaptors = /* need to free this someplace */ xalloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr*)); if(newAdaptors) { memcpy(newAdaptors, adaptors, num_adaptors * sizeof(XF86VideoAdaptorPtr)); newAdaptors[num_adaptors] = newAdaptor; adaptors = newAdaptors; num_adaptors++; } } } if(num_adaptors) xf86XVScreenInit(pScreen, adaptors, num_adaptors); if(newAdaptors) xfree(newAdaptors);}/* *INDENT-OFF* *//* client libraries expect an encoding */static XF86VideoEncodingRec DummyEncoding[1] ={ { 0, "XV_IMAGE", IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, {1, 1} }};#define NUM_FORMATS 3static XF86VideoFormatRec Formats[NUM_FORMATS] = { {15, TrueColor}, {16, TrueColor}, {24, TrueColor}};#define NUM_ATTRIBUTES 3static XF86AttributeRec Attributes[NUM_ATTRIBUTES] ={ {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"}, {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"}, {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}};#define NUM_IMAGES 6#define I810_RV15 0x35315652#define I810_RV16 0x36315652static XF86ImageRec Images[NUM_IMAGES] ={ { I810_RV15, XvRGB, LSBFirst, {'R','V','1','5', 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 16, XvPacked, 1, 15, 0x7C00, 0x03E0, 0x001F, 0, 0, 0, 0, 0, 0, 0, 0, 0, {'R','V','B',0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, XvTopToBottom }, { I810_RV16, XvRGB, LSBFirst, {'R','V','1','6', 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 16, XvPacked, 1, 16, 0xF800, 0x07E0, 0x001F, 0, 0, 0, 0, 0, 0, 0, 0, 0, {'R','V','B',0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, XvTopToBottom }, XVIMAGE_YUY2, XVIMAGE_YV12, XVIMAGE_I420, XVIMAGE_UYVY};/* *INDENT-ON* */typedef struct { CARD32 OBUF_0Y; CARD32 OBUF_1Y; CARD32 OBUF_0U; CARD32 OBUF_0V; CARD32 OBUF_1U; CARD32 OBUF_1V; CARD32 OV0STRIDE; CARD32 YRGB_VPH; CARD32 UV_VPH; CARD32 HORZ_PH; CARD32 INIT_PH; CARD32 DWINPOS; CARD32 DWINSZ; CARD32 SWID; CARD32 SWIDQW; CARD32 SHEIGHT; CARD32 YRGBSCALE; CARD32 UVSCALE; CARD32 OV0CLRC0; CARD32 OV0CLRC1; CARD32 DCLRKV; CARD32 DCLRKM; CARD32 SCLRKVH; CARD32 SCLRKVL; CARD32 SCLRKM; CARD32 OV0CONF; CARD32 OV0CMD;} I810OverlayRegRec, *I810OverlayRegPtr;typedef struct { CARD32 YBuf0offset; CARD32 UBuf0offset; CARD32 VBuf0offset; CARD32 YBuf1offset; CARD32 UBuf1offset; CARD32 VBuf1offset; unsigned char currentBuf; int brightness; int contrast; RegionRec clip; CARD32 colorKey; CARD32 videoStatus; Time offTime; Time freeTime; FBLinearPtr linear;} I810PortPrivRec, *I810PortPrivPtr; #define GET_PORT_PRIVATE(pScrn) \ (I810PortPrivPtr)((I810PTR(pScrn))->adaptor->pPortPrivates[0].ptr)static void I810ResetVideo(ScrnInfoPtr pScrn) { I810Ptr pI810 = I810PTR(pScrn); I810PortPrivPtr pPriv = pI810->adaptor->pPortPrivates[0].ptr; I810OverlayRegPtr overlay = (I810OverlayRegPtr) (pI810->FbBase + pI810->OverlayStart); /* * Default to maximum image size in YV12 */ overlay->YRGB_VPH = 0; overlay->UV_VPH = 0; overlay->HORZ_PH = 0; overlay->INIT_PH = 0; overlay->DWINPOS = 0; overlay->DWINSZ = (IMAGE_MAX_HEIGHT << 16) | IMAGE_MAX_WIDTH; overlay->SWID = IMAGE_MAX_WIDTH | (IMAGE_MAX_WIDTH << 15); overlay->SWIDQW = (IMAGE_MAX_WIDTH >> 3) | (IMAGE_MAX_WIDTH << 12); overlay->SHEIGHT = IMAGE_MAX_HEIGHT | (IMAGE_MAX_HEIGHT << 15); overlay->YRGBSCALE = 0x80004000; /* scale factor 1 */ overlay->UVSCALE = 0x80004000; /* scale factor 1 */ overlay->OV0CLRC0 = 0x4000; /* brightness: 0 contrast: 1.0 */ overlay->OV0CLRC1 = 0x80; /* saturation: bypass */ /* * Enable destination color keying */ switch(pScrn->depth) { case 16: overlay->DCLRKV = RGB16ToColorKey(pPriv->colorKey); overlay->DCLRKM = 0x80070307; break; case 15: overlay->DCLRKV = RGB15ToColorKey(pPriv->colorKey); overlay->DCLRKM = 0x80070707; break; default: overlay->DCLRKV = pPriv->colorKey; overlay->DCLRKM = 0x80000000; break; } overlay->SCLRKVH = 0; overlay->SCLRKVL = 0; overlay->SCLRKM = 0; /* source color key disable */ overlay->OV0CONF = 0; /* two 720 pixel line buffers */ overlay->OV0CMD = VC_UP_INTERPOLATION | HC_UP_INTERPOLATION | Y_ADJUST | YUV_420; OVERLAY_UPDATE(pI810->OverlayPhysical);}static XF86VideoAdaptorPtr I810SetupImageVideo(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; I810Ptr pI810 = I810PTR(pScrn); XF86VideoAdaptorPtr adapt; I810PortPrivPtr pPriv; if(!(adapt = xcalloc(1, sizeof(XF86VideoAdaptorRec) + sizeof(I810PortPrivRec) + sizeof(DevUnion)))) return NULL; adapt->type = XvWindowMask | XvInputMask | XvImageMask; adapt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; adapt->name = "I810 Video Overlay"; adapt->nEncodings = 1; adapt->pEncodings = DummyEncoding; adapt->nFormats = NUM_FORMATS; adapt->pFormats = Formats; adapt->nPorts = 1; adapt->pPortPrivates = (DevUnion*)(&adapt[1]); pPriv = (I810PortPrivPtr)(&adapt->pPortPrivates[1]); adapt->pPortPrivates[0].ptr = (pointer)(pPriv); adapt->pAttributes = Attributes; adapt->nImages = NUM_IMAGES; adapt->nAttributes = NUM_ATTRIBUTES; adapt->pImages = Images; adapt->PutVideo = NULL; adapt->PutStill = NULL; adapt->GetVideo = NULL; adapt->GetStill = NULL; adapt->StopVideo = I810StopVideo; adapt->SetPortAttribute = I810SetPortAttribute; adapt->GetPortAttribute = I810GetPortAttribute; adapt->QueryBestSize = I810QueryBestSize; adapt->PutImage = I810PutImage; adapt->QueryImageAttributes = I810QueryImageAttributes; pPriv->colorKey = pI810->colorKey & ((1 << pScrn->depth) - 1); pPriv->videoStatus = 0; pPriv->brightness = 0; pPriv->contrast = 64; pPriv->linear = NULL; pPriv->currentBuf = 0; /* gotta uninit this someplace */ REGION_NULL(pScreen, &pPriv->clip); pI810->adaptor = adapt; pI810->BlockHandler = pScreen->BlockHandler; pScreen->BlockHandler = I810BlockHandler; xvBrightness = MAKE_ATOM("XV_BRIGHTNESS"); xvContrast = MAKE_ATOM("XV_CONTRAST"); xvColorKey = MAKE_ATOM("XV_COLORKEY"); I810ResetVideo(pScrn); return adapt;}/* I810ClipVideo - Takes the dst box in standard X BoxRec form (top and left edges inclusive, bottom and right exclusive). The new dst box is returned. The source boundaries are given (x1, y1 inclusive, x2, y2 exclusive) and returned are the new source boundaries in 16.16 fixed point. */static voidI810ClipVideo( BoxPtr dst, INT32 *x1, INT32 *x2, INT32 *y1, INT32 *y2, BoxPtr extents, /* extents of the clip region */ INT32 width, INT32 height){ INT32 vscale, hscale, delta; int diff; hscale = ((*x2 - *x1) << 16) / (dst->x2 - dst->x1); vscale = ((*y2 - *y1) << 16) / (dst->y2 - dst->y1); *x1 <<= 16; *x2 <<= 16; *y1 <<= 16; *y2 <<= 16; diff = extents->x1 - dst->x1; if(diff > 0) { dst->x1 = extents->x1; *x1 += diff * hscale; } diff = dst->x2 - extents->x2;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?