📄 gfx_osi.c
字号:
//vulcan/drv/gfx/gfx_osi.c/*----------------------------------------------------------------------------+|| This source code has been made available to you by IBM on an AS-IS| basis. Anyone receiving this source is licensed under IBM| copyrights to use it in any way he or she deems fit, including| copying it, modifying it, compiling it, and redistributing it either| with or without modifications. No license under IBM patents or| patent applications is to be implied by the copyright license.|| Any user of this software should understand that IBM cannot provide| technical support for this software and will not be responsible for| any consequences resulting from the use of this software.|| Any person who transfers this source code or any derivative work| must include the IBM copyright notice, this paragraph, and the| preceding two paragraphs in the transferred software.|| COPYRIGHT I B M CORPORATION 1998| LICENSED MATERIAL - PROGRAM PROPERTY OF I B M+----------------------------------------------------------------------------*/////Comment: // OSI function of GFX controls //Revision Log: // Oct/29/2001 Created by YYD// Jun/05/2002 Implemented basic gfx routines using software by YYD#include "os/os-types.h"#include "os/os-generic.h"#include "gfx_surface.h"#include "gfx_osi.h"#include "gfx_osi_engine.h"#include "hw/physical-mem.h"#include "gfx_osi_local.h"#include "os/pm-alloc.h"#include <asm/io.h>#include <linux/ioport.h>//#define __G2D_FAST_RESIZE//#define __GFX_OSI_DEBUG #ifdef __GFX_OSI_DEBUG #define __DRV_DEBUG#endif#include "os/drv_debug.h"#ifndef NULL // My local NULL definition #define NULL ((void *)0)#endifINT gfx_osi_init(void){ PDEBUG("gfx_osi_init: __STB_GRAPHICS_MEM_SIZE = 0x%0x \n",__STB_GRAPHICS_MEM_SIZE); if(__STB_GRAPHICS_MEM_SIZE>0) { void *pmapped; if (gpGraphicsPMRoot) // it should have been initialized, so error { return PM_ALLOC_ERROR; } PDEBUG("\nGraphics physical mem at 0x%8.8x , size 0x%8.8x\n", __STB_GRAPHICS_MEM_BASE_ADDR, __STB_GRAPHICS_MEM_SIZE); if ((__STB_GRAPHICS_MEM_BASE_ADDR + __STB_GRAPHICS_MEM_SIZE) < __STB_GRAPHICS_MEM_BASE_ADDR) // how can we wrap around ?! return PM_ALLOC_INVALID_PARM; if (!request_region(__STB_GRAPHICS_MEM_BASE_ADDR, __STB_GRAPHICS_MEM_SIZE, __PM_MODULE_NAME)) { printk("ERROR: failed to lock graphics memory\n"); return PM_ALLOC_ERROR; // hi, I cann't do this } pmapped = (void *)ioremap(__STB_GRAPHICS_MEM_BASE_ADDR, __STB_GRAPHICS_MEM_SIZE); if (NULL == pmapped) { release_region(__STB_GRAPHICS_MEM_BASE_ADDR, __STB_GRAPHICS_MEM_SIZE); return PM_ALLOC_ERROR; // hi, I cann't do this } guGraphicsPhysicalAddr = __STB_GRAPHICS_MEM_BASE_ADDR; guGraphicsPhysicalSize = __STB_GRAPHICS_MEM_SIZE; guGraphicsLogicalAddr = pmapped; guGraphicsPhysicalBase = __STB_GRAPHICS_MEM_BASE_ADDR; gpGraphicsPMRoot = __pm_alloc_physical_init(guGraphicsPhysicalAddr, pmapped, guGraphicsPhysicalSize,4096); PDEBUG("gfx_osi_init gpGraphicsPMRoot = %0x\n", gpGraphicsPMRoot); if(!gpGraphicsPMRoot) { // failed iounmap(guGraphicsLogicalAddr); release_region(guGraphicsPhysicalAddr, guGraphicsPhysicalSize); return PM_ALLOC_ERROR; } else { return PM_ALLOC_SUCCESS; } } return 0;}INT gfx_osi_deinit(void){ if(__STB_GRAPHICS_MEM_SIZE>0) { if (!gpGraphicsPMRoot) { PDEBUG("DEINIT: Tries to deinit before successful init !\n"); return -1; // you are going to deallocate an non existing one } __pm_alloc_physical_deinit(gpGraphicsPMRoot); gpGraphicsPMRoot = NULL; iounmap(guGraphicsLogicalAddr); release_region(guGraphicsPhysicalAddr, guGraphicsPhysicalSize); guGraphicsPhysicalAddr = 0; guGraphicsPhysicalSize = 0; guGraphicsLogicalAddr = NULL; } return 0;}INT gfx_osi_wait_for_engine(INT nTimeout){ return 0;}INT gfx_osi_run_engine(INT nWait){ return 0;}INT gfx_osi_reset_engine(void){ return 0; }// rect clip of BLT routines// return 0 if clip result is not zero// -1 if clip result is zeroINT gfx_osi_ClipBLTRect(UINT uSrcWidth, UINT uSrcHeight, UINT uDesWidth, UINT uDesHeight, UINT uSrcX, UINT uSrcY, UINT uDesX, UINT uDesY, UINT *uWidth, UINT *uHeight ){ if( !*uWidth || !*uHeight || uSrcX >= uSrcWidth || uSrcY >= uSrcHeight || uDesX >= uDesWidth || uDesY >= uDesWidth ) { return -1; // empty clip } if(uSrcX + *uWidth > uSrcWidth) { *uWidth = uSrcWidth - uSrcX; } if(uDesX + *uWidth > uDesWidth) { *uWidth = uDesWidth - uDesX; } if(uSrcY + *uHeight > uSrcHeight) { *uHeight = uSrcHeight - uSrcY; } if(uDesY + *uHeight > uDesHeight) { *uHeight = uDesHeight - uDesY; } return (*uHeight)&&(*uWidth) ? 0 : -1;}// rect clip of BLT routines// return 0 if clip result is not zero// -1 if clip result is zeroINT gfx_osi_ClipRect(UINT uDesWidth, UINT uDesHeight, UINT uDesX, UINT uDesY, UINT *uWidth, UINT *uHeight ){ if( !*uWidth || !*uHeight || uDesX >= uDesWidth || uDesY >= uDesWidth ) { return -1; // empty clip } if(uDesX + *uWidth > uDesWidth) { *uWidth = uDesWidth - uDesX; } if(uDesY + *uHeight > uDesHeight) { *uHeight = uDesHeight - uDesY; } return (*uHeight)&&(*uWidth) ? 0 : -1;}INT gfx_osi_ClipExtRect(GFX_RECT_T *pDesClip, INT *nDesX, INT *nDesY, UINT *uWidth, UINT *uHeight ){ register INT v1, v2; if(!*uWidth || !*uHeight) { return -1; // empty clip } v1 = *nDesX; v2 = v1 + (INT)*uWidth-1; if(pDesClip->x1 > v1) v1 = pDesClip->x1; if(pDesClip->x2 < v2) v2 = pDesClip->x2; if(v1 > v2) // no overlap { return -1; } *nDesX = v1; *uWidth = v2-v1+1; v1 = *nDesY; v2 = v1 + (INT)*uHeight-1; if(pDesClip->y1 > v1) v1 = pDesClip->y1; if(pDesClip->y2 < v2) v2 = pDesClip->y2; if(v1 > v2) // no overlap { return -1; } *nDesY = v1; *uHeight = v2-v1+1; return 0;}INT gfx_osi_ClipExtBLTRect(GFX_RECT_T *pSrcClip, GFX_RECT_T *pDesClip, INT *nSrcX, INT *nSrcY, INT *nDesX, INT *nDesY, UINT *uWidth, UINT *uHeight, UINT *uAdjustX, UINT *uAdjustY ){ INT x1, y1, xadj, yadj; // forward clip x1 = *nSrcX; // save for checking coordination move y1 = *nSrcY; if(gfx_osi_ClipExtRect(pSrcClip, nSrcX, nSrcY, uWidth, uHeight)) return -1; // no overlap xadj = *nSrcX - x1; yadj = *nSrcY - y1; *nDesX += xadj; // we need to move dest coordination too *nDesY += yadj; // backward clip x1 = *nDesX; // save for checking coordination move y1 = *nDesY; if(gfx_osi_ClipExtRect(pDesClip, nDesX, nDesY, uWidth, uHeight)) return -1; // no overlap *nSrcX += *nDesX - x1; // we need to move src coordination too *nSrcY += *nDesY - y1; if(uAdjustX) *uAdjustX = xadj + *nDesX - x1; if(uAdjustY) *uAdjustY = yadj + *nDesY - y1; return 0;}void gfx_osi_pixelJustify(UINT uJustify, UINT *uX, UINT *uWidth){ if(uJustify < 2) return; if(*uX % uJustify) *uX += uJustify - *uX % uJustify; if(*uWidth % uJustify) *uWidth += uJustify - *uWidth % uJustify;}INT gfx_osi_set_surface_clip_region(GFX_SURFACE_T *pSurface, GFX_RECT_T *pClip){ if(!gfx_osi_pSurface_valid(pSurface)) { PDEBUG("invalid surface!\n"); return -1; } if(!pClip) // reset to default { pSurface->clip.x1 = pSurface->clip.y1 = 0; pSurface->clip.x2 = pSurface->plane[0].uAllocWidth - 1; pSurface->clip.y2 = pSurface->plane[0].uAllocHeight - 1; } else { GFX_RECT_T clip = *pClip; *pClip = pSurface->clip; if(clip.x1 > clip.x2 || clip.x1 >= (INT)pSurface->plane[0].uAllocWidth) return -1; if(clip.y1 > clip.y2 || clip.y1 >= (INT)pSurface->plane[0].uAllocHeight) return -1; if(clip.x2 < 0 || clip.y2 < 0) return -1; if(clip.x1 < 0) clip.x1 = 0; if(clip.y1 < 0) clip.y1 = 0; if(clip.x2 >= (INT)pSurface->plane[0].uAllocWidth) clip.x2 = (INT)pSurface->plane[0].uAllocWidth-1; if(clip.y2 >= (INT)pSurface->plane[0].uAllocHeight) clip.y2 = (INT)pSurface->plane[0].uAllocHeight-1; gfx_osi_pixelJustify(pSurface->plane[0].uPixelJustify, (UINT *)&clip.x1, &clip.x2); pSurface->clip = clip; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -