📄 atimach64xv.c
字号:
OffsetV = OffsetU; OffsetU = tmp; } pDst += ((Top - SrcTop) * DstPitch) + ((Left - SrcLeft) << 1); xf86XVCopyYUV12ToPacked(Buffer + (Top * SrcPitch) + Left, Buffer + OffsetV, Buffer + OffsetU, pDst, SrcPitch, SrcPitchUV, DstPitch, nLine, nPixel); break; case FOURCC_UYVY: case FOURCC_YUY2: default: Left = (SrcX1 >> 16) & ~1; Right = ((SrcX2 + 0x1FFFF) >> 16) & ~1; Top = SrcY1 >> 16; Bottom = (SrcY2 + 0x0FFFF) >> 16; if ((Right < Width) && ((SrcX1 & 0x1FFFF) <= (SrcX2 & 0x1FFFF))) Right += 2; if ((Bottom < Height) && ((SrcY1 & 0x0FFFF) <= (SrcY2 & 0x0FFFF))) Bottom++; nPixel = Right - Left; nLine = Bottom - Top; SrcPitch = Width << 1; Buffer += (Top * SrcPitch) + (Left << 1); pDst += ((Top - SrcTop) * DstPitch) + ((Left - SrcLeft) << 1); xf86XVCopyPacked(Buffer, pDst, SrcPitch, DstPitch, nLine, nPixel); break; } if (!REGION_EQUAL(pScreen, &pATI->VideoClip, pClip)) { REGION_COPY(pScreen, &pATI->VideoClip, pClip); if (pATI->AutoPaint) xf86XVFillKeyHelper(pScreen, pATI->NewHW.overlay_graphics_key_clr, pClip); } ATIMach64DisplayVideo(pScreenInfo, pATI, &DstBox, ImageID, Offset, DstPitch / 2, SrcW, SrcH, DstW, DstH, DstWidth, DstHeight); return Success;}/* * ATIMach64AllocateSurface -- * * This function allocates an offscreen buffer (called a "surface") for use by * an external driver such as 'v4l'. */static intATIMach64AllocateSurface( ScrnInfoPtr pScreenInfo, int ImageID, unsigned short Width, unsigned short Height, XF86SurfacePtr pSurface){ ScreenPtr pScreen; ATIPtr pATI = ATIPTR(pScreenInfo); int XVOffset; if (pATI->ActiveSurface) return BadAlloc; if ((Height <= 0) || (Height > 2048) || (Width <= 0) || (Width > 720) || ((Width > 384) && (pATI->Chip < ATI_CHIP_264VTB))) return BadValue; Width = (Width + 1) & ~1; pATI->SurfacePitch = ((Width << 1) + 15) & ~15; pScreen = pScreenInfo->pScreen; pATI->pXVBuffer = ATIMach64XVMemAlloc(pScreen, pATI->pXVBuffer, Height * pATI->SurfacePitch, &XVOffset, pATI); if (!pATI->pXVBuffer) return BadAlloc; pATI->SurfaceOffset = XVOffset; pSurface->pScrn = pScreenInfo; pSurface->id = ImageID; pSurface->width = Width; pSurface->height = Height; pSurface->pitches = &pATI->SurfacePitch; pSurface->offsets = &pATI->SurfaceOffset; pSurface->devPrivate.ptr = pATI; /* Stop the video */ outf(OVERLAY_SCALE_CNTL, SCALE_EN); REGION_EMPTY(pScreen, &pATI->VideoClip); pATI->ActiveSurface = TRUE; return Success;}/* * ATIMach64FreeSurface -- * * This function called to free a surface's offscreen buffer. */static intATIMach64FreeSurface( XF86SurfacePtr pSurface){ ATIPtr pATI = pSurface->devPrivate.ptr; if (!pATI->ActiveSurface) return Success; outf(OVERLAY_SCALE_CNTL, SCALE_EN); ATIMach64XVMemFree(pSurface->pScrn->pScreen, pATI->pXVBuffer, pATI); pATI->pXVBuffer = NULL; pATI->ActiveSurface = FALSE; return Success;}/* * ATIMach64DisplaySurface -- * * This function is called to display a video surface. */static intATIMach64DisplaySurface( XF86SurfacePtr pSurface, short SrcX, short SrcY, short DstX, short DstY, short SrcW, short SrcH, short DstW, short DstH, RegionPtr pClip){ ATIPtr pATI = pSurface->devPrivate.ptr; ScrnInfoPtr pScreenInfo; int ImageID; short Width, Height; BoxRec DstBox; INT32 SrcX1, SrcX2, SrcY1, SrcY2; int SrcLeft, SrcTop, SrcPitch, Offset; if (!pATI->ActiveSurface) return Success; pScreenInfo = pSurface->pScrn; ImageID = pSurface->id; Width = pSurface->width; Height = pSurface->height; if (!ATIMach64ClipVideo(pScreenInfo, pATI, ImageID, SrcX, SrcY, SrcW, SrcH, DstX, DstY, &DstW, &DstH, Width, Height, pClip, &DstBox, &SrcX1, &SrcX2, &SrcY1, &SrcY2, &SrcLeft, &SrcTop)) return Success; xf86XVFillKeyHelper(pScreenInfo->pScreen, pATI->NewHW.overlay_graphics_key_clr, pClip); SrcPitch = pSurface->pitches[0]; Offset = pSurface->offsets[0] + (SrcTop * SrcPitch) + (SrcLeft << 1); ATIMach64DisplayVideo(pScreenInfo, pATI, &DstBox, ImageID, Offset, SrcPitch, SrcW, SrcH, DstW, DstH, Width, Height); return Success;}/* * ATIMach64StopSurface -- * * This function is called to stop the overlaid display of a video surface. */static intATIMach64StopSurface( XF86SurfacePtr pSurface){ ATIPtr pATI = pSurface->devPrivate.ptr; if (pATI->ActiveSurface) outf(OVERLAY_SCALE_CNTL, SCALE_EN); return Success;}/* * ATIMach64GetSurfaceAttribute -- * * Retrieve the value of an XVideo attribute. */static intATIMach64GetSurfaceAttribute( ScrnInfoPtr pScreenInfo, Atom AttributeID, INT32 *Value){ return ATIMach64GetPortAttribute(pScreenInfo, AttributeID, Value, ATIPTR(pScreenInfo));}/* * ATIMach64SetSurfaceAttribute * * Set the value of an XVideo attribute. */static intATIMach64SetSurfaceAttribute( ScrnInfoPtr pScreenInfo, Atom AttributeID, INT32 Value){ return ATIMach64SetPortAttribute(pScreenInfo, AttributeID, Value, ATIPTR(pScreenInfo));}/* XVideo surface registration data */static XF86OffscreenImageRec ATIMach64Surface_A[] ={ { &ATIMach64Image[0], /* YUY2 */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 384, 2048, nATIMach64Attribute - 5, /* No double-buffering */ ATIMach64Attribute + 4 /* No saturation nor brightness */ }, { &ATIMach64Image[1], /* UYVY */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 384, 2048, nATIMach64Attribute - 5, /* No double-buffering */ ATIMach64Attribute + 4 /* No saturation nor brightness */ }};#define nATIMach64Surface_A NumberOf(ATIMach64Surface_A)static XF86OffscreenImageRec ATIMach64Surface_B[] ={ { &ATIMach64Image[0], /* YUY2 */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 720, 2048, nATIMach64Attribute - 5, /* No double-buffering */ ATIMach64Attribute + 4 /* No saturation nor brightness */ }, { &ATIMach64Image[1], /* UYVY */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 720, 2048, nATIMach64Attribute - 5, /* No double-buffering */ ATIMach64Attribute + 4 /* No saturation nor brightness */ }};#define nATIMach64Surface_B NumberOf(ATIMach64Surface_B)static XF86OffscreenImageRec ATIMach64Surface_C[] ={ { &ATIMach64Image[0], /* YUY2 */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 720, 2048, nATIMach64Attribute - 1, /* No double-buffering */ ATIMach64Attribute }, { &ATIMach64Image[1], /* UYVY */ VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT, ATIMach64AllocateSurface, ATIMach64FreeSurface, ATIMach64DisplaySurface, ATIMach64StopSurface, ATIMach64GetSurfaceAttribute, ATIMach64SetSurfaceAttribute, 720, 2048, nATIMach64Attribute - 1, /* No double-buffering */ ATIMach64Attribute }};#define nATIMach64Surface_C NumberOf(ATIMach64Surface_C)/* * ATIMach64XVInitialiseAdaptor -- * * This function is called to make a Mach64's hardware overlay support * available as an XVideo adaptor. */intATIMach64XVInitialiseAdaptor( ScreenPtr pScreen, ScrnInfoPtr pScreenInfo, ATIPtr pATI, XF86VideoAdaptorPtr **pppAdaptor){ XF86VideoAdaptorPtr pAdaptor; int Index; if (!pATI->Block1Base) return 0; if (!(pAdaptor = xf86XVAllocateVideoAdaptorRec(pScreenInfo))) return 0; *pppAdaptor = xnfalloc(sizeof(pAdaptor)); **pppAdaptor = pAdaptor; pAdaptor->nPorts = 1; pAdaptor->pPortPrivates = pATI->XVPortPrivate; pATI->XVPortPrivate[0].ptr = pATI; pAdaptor->type = XvInputMask | XvImageMask | XvWindowMask; pAdaptor->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; pAdaptor->name = "ATI Mach64 Back-end Overlay Scaler"; if (pATI->Chip < ATI_CHIP_264VTB) { pAdaptor->nEncodings = nATIMach64VideoEncoding_A; pAdaptor->pEncodings = ATIMach64VideoEncoding_A; } else { pAdaptor->nEncodings = nATIMach64VideoEncoding_B; pAdaptor->pEncodings = ATIMach64VideoEncoding_B; } pAdaptor->nFormats = nATIMach64VideoFormat; pAdaptor->pFormats = ATIMach64VideoFormat; pAdaptor->nAttributes = nATIMach64Attribute; pAdaptor->pAttributes = ATIMach64Attribute; if (pATI->Chip < ATI_CHIP_264GTPRO) { /* Older controllers don't have brightness or saturation controls */ pAdaptor->nAttributes -= 4; pAdaptor->pAttributes += 4; } pAdaptor->nImages = nATIMach64Image; pAdaptor->pImages = ATIMach64Image; pAdaptor->StopVideo = ATIMach64StopVideo; pAdaptor->SetPortAttribute = ATIMach64SetPortAttribute; pAdaptor->GetPortAttribute = ATIMach64GetPortAttribute; pAdaptor->QueryBestSize = ATIMach64QueryBestSize; pAdaptor->PutImage = ATIMach64PutImage; pAdaptor->QueryImageAttributes = ATIMach64QueryImageAttributes; REGION_NULL(pScreen, &pATI->VideoClip); pATI->ActiveSurface = FALSE; if (ATIMach64XVAtomGeneration != serverGeneration) { /* Refresh static data */ ATIMach64XVAtomGeneration = serverGeneration; Index = nATIMach64Attribute - pAdaptor->nAttributes; for (; Index < nATIMach64Attribute; Index++) ATIMach64AttributeInfo[Index].AttributeID = MAKE_ATOM(ATIMach64Attribute[Index].name); } ATIMach64SetDefaultAttributes(pATI, 0); if (pATI->Chip < ATI_CHIP_264VTB) { xf86XVRegisterOffscreenImages(pScreen, ATIMach64Surface_A, nATIMach64Surface_A); } else if (pATI->Chip < ATI_CHIP_264GTPRO) { xf86XVRegisterOffscreenImages(pScreen, ATIMach64Surface_B, nATIMach64Surface_B); } else { xf86XVRegisterOffscreenImages(pScreen, ATIMach64Surface_C, nATIMach64Surface_C); } return 1;}/* * ATIMach64CloseXVideo -- * * This function is called during screen termination to clean up after * initialisation of Mach64 XVideo support. */voidATIMach64CloseXVideo( ScreenPtr pScreen, ScrnInfoPtr pScreenInfo, ATIPtr pATI){ ATIMach64StopVideo(pScreenInfo, pATI, TRUE); REGION_UNINIT(pScreen, &pATI->VideoClip);}static pointerATIMach64XVMemAlloc( ScreenPtr pScreen, pointer pVideo, int size, int *offset, ATIPtr pATI){#ifdef USE_EXA if (pATI->useEXA) { ExaOffscreenArea *area = (ExaOffscreenArea *)pVideo; if (area != NULL) { if (area->size >= size) { *offset = area->offset; return area; } exaOffscreenFree(pScreen, area); } area = exaOffscreenAlloc(pScreen, size, 64, TRUE, NULL, NULL); if (area != NULL) { *offset = area->offset; return area; } }#endif /* USE_EXA */#ifdef USE_XAA if (!pATI->useEXA) { FBLinearPtr linear = (FBLinearPtr)pVideo; int cpp = pATI->AdjustDepth; /* XAA allocates in units of pixels at the screen bpp, so adjust size * appropriately. */ size = (size + cpp - 1) / cpp; linear = ATIResizeOffscreenLinear(pScreen, linear, size); if (linear != NULL) { *offset = linear->offset * cpp; return linear; } }#endif /* USE_XAA */ *offset = 0; return NULL;}static voidATIMach64XVMemFree( ScreenPtr pScreen, pointer pVideo, ATIPtr pATI){#ifdef USE_EXA if (pATI->useEXA) { ExaOffscreenArea *area = (ExaOffscreenArea *)pVideo; if (area != NULL) exaOffscreenFree(pScreen, area); }#endif /* USE_EXA */#ifdef USE_XAA if (!pATI->useEXA) { FBLinearPtr linear = (FBLinearPtr)pVideo; if (linear != NULL) ATIResizeOffscreenLinear(pScreen, linear, 0); }#endif /* USE_XAA */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -