📄 gfx_inf_helper.c
字号:
//vulcan/drv/gfx/gfx_inf_helper.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: // Helper function for INF layer of GFX controls //Revision Log: // Nov/05/2001 Created by YYD// Nov/08/2001 Enabled surface locks by YYD// Nov/22/2001 Fixed a variable name typing bug in gfx_inf_h_init() by YYD// Oct/21/2002 Added dispatch handlers for GFX_DISP_CNTL_OSDIRQ and// GFX_DISP_CNTL_OSDHSR in gfx_inf_set/get_display_control()// Added gfx_inf_h_swap_surface() to detach one surface and// attach another, optionally synchronized with the OSD// animation interrupt for double-buffered operation. // Added gfx_inf_h_dmablt() to initiate a DMA "block transfer".// Added gfx_inf_h_dmablt_wait() to wait for an async DMABLT.// Added gfx_inf_h_pmalloc() to allocate phys contig memory. BJC#include "os/os-types.h"#include "os/os-sync.h"#include "os/os-generic.h"#include "os/pm-alloc.h"#include "gfx_surface.h"#include "gfx_osi.h"#include "osd_osi.h"#include "gfx_inf_helper.h"#include "gfx_atom.h" // BJC 102101//#define __GFX_INF_HELPER_DEBUG#ifdef __GFX_INF_HELPER_DEBUG #define __DRV_DEBUG#endif#include "os/drv_debug.h"#ifndef NULL // My local NULL definition #define NULL ((void *)0)#endif// local data structuretypedef struct __GFX_HANDLE_T_STRUCTURE__{ GFX_SURFACE_T surface; UINT uLocks; GFX_SURFACE_PHYSICAL_PARM_T phy;} GFX_HANDLE_T;static GFX_HANDLE_T *gpHandles;static UINT guMaxHandles;static UINT guFreeHandles;static UINT guLockedHandles;static GFX_SCREEN_INFO_T gScreenInfo;static int ghShared = -1; // a globally shared surface handle which can be get by other appsstatic MUTEX_T *gGFXMutex;static int gWait_for_finish;extern GFX_SWAP_SURFACE_T osdanim_swap; // setup by gfx_inf_h_swap_surface() -- BJC 102102int gfx_inf_h_init(unsigned int uNumSurface){ if(uNumSurface == 0) { uNumSurface = GFX_DEFAULT_SURFACES; } if(gGFXMutex) return 0; // already done gGFXMutex = os_create_mutex (); if(!gGFXMutex) { PDEBUG("Failed to create lock for resources!\n"); return -1; } ///////////////////////////// if(os_get_mutex(gGFXMutex)) { PDEBUG("Failed on mutex!\n"); return -1; } if(osd_osi_init() < 0) { PDEBUG("Failed to initlized display device!\n"); return -1; } if(gfx_osi_init() < 0) { PDEBUG("Failed to initlized graphics device!\n"); osd_osi_deinit(); return -1; } gScreenInfo.uUpper = OSD_DEFAULT_TV_UPPER_MARGIN; gScreenInfo.uLeft = OSD_DEFAULT_TV_LEFT_MARGIN; gScreenInfo.uWidth = OSD_DEFAULT_XRES; gScreenInfo.uHeight= OSD_DEFAULT_YRES; gpHandles = MALLOC(uNumSurface * sizeof(GFX_HANDLE_T)); if(NULL == gpHandles) { osd_osi_deinit(); gfx_osi_deinit(); os_release_mutex(gGFXMutex); os_delete_mutex(gGFXMutex); gGFXMutex = NULL; PDEBUG("Failed to allocate surface handle buffer!\n"); return -1; } _OS_MEMSET(gpHandles, 0, uNumSurface * sizeof(GFX_HANDLE_T)); guMaxHandles = uNumSurface; guFreeHandles = uNumSurface; guLockedHandles = 0; ghShared = -1; gWait_for_finish = 1; // compatible with old app os_release_mutex(gGFXMutex); ///////////////////////////// // set default af parms { GFX_DISPLAY_CONTROL_PARM_T parm; parm.parm = GFX_DISP_CNTL_EDAF; parm.uAttr = 1; gfx_inf_h_set_display_control(&parm); // set antiflicker detect threshold to afdt parm.parm = GFX_DISP_CNTL_AFDT; parm.uAttr = 2; gfx_inf_h_set_display_control(&parm); } return 0;}// nForce : 0 // safest mode// 1 // stop when surfaces are locked// 2 // continue anywayint gfx_inf_h_deinit(int nForce){ MUTEX_T *mutex; int rtn; if(!gGFXMutex) return 0; // already done ///////////////////////////// if(os_get_mutex(gGFXMutex)) { PDEBUG("Failed on mutex!\n"); return -1; } if(guFreeHandles < guMaxHandles) { if(1 == nForce) { UINT i; if(guLockedHandles > 0) { os_release_mutex(gGFXMutex); ////////////////////////////// PDEBUG("Some surface is locked, could not continue!\n"); return -1; } for(i=0; i<guMaxHandles; i++) { if(gpHandles[i].uLocks > 0) { // some thing wrong, should not happen os_release_mutex(gGFXMutex); ////////////////////////////// PFATAL("Some surface is locked but not recorded!\n"); return -1; } if(gfx_osi_pSurface_alloc(&gpHandles[i].surface)) { if(gpHandles[i].surface.attachedDev != GFX_VDEV_NULL) { osd_osi_detach_comp_gfx_surface(gpHandles[i].surface.attachedDev, &gpHandles[i].surface); } PDEBUG("Surface handle %d is not released!\n", i); gfx_osi_destroy_surface(&gpHandles[i].surface); guFreeHandles ++; } } // ok, lets do other stuffs } else if (2 == nForce) { UINT i; if(guLockedHandles > 0) { PFATAL("Some surface is locked, expecting unstability afterwards !\n"); } for(i=0; i<guMaxHandles; i++) { if(gfx_osi_pSurface_alloc(&gpHandles[i].surface)) { if(gpHandles[i].surface.attachedDev != GFX_VDEV_NULL) { osd_osi_detach_comp_gfx_surface(gpHandles[i].surface.attachedDev, &gpHandles[i].surface); } PDEBUG("Surface handle %d is not released!\n", i); gfx_osi_destroy_surface(&gpHandles[i].surface); } } // ok, lets do other stuffs } else if (0 == nForce) { os_release_mutex(gGFXMutex); ///////////////////////////// PDEBUG("Some surface is not freed, could not continue!\n"); return -1; } } mutex = gGFXMutex; // save first gGFXMutex = NULL; // no one can enter correctly now FREE(gpHandles); gpHandles = NULL; guMaxHandles = 0; guFreeHandles = 0; guLockedHandles = 0; ghShared = -1; rtn = gfx_osi_deinit(); rtn += osd_osi_deinit(); os_release_mutex(mutex); ///////////////////////////// os_delete_mutex(mutex); return rtn;}int gfx_inf_h_set_shared_surface(int hSurface){ int rtn = -1; if(hSurface < 0 || hSurface >= (int)guMaxHandles) { PDEBUG("Invalid surface\n"); return -1; } ///////////////////////////// if(os_get_mutex(gGFXMutex)) { PDEBUG("Failed on mutex!\n"); return -1; } if(gfx_osi_pSurface_alloc(&gpHandles[hSurface].surface)) { ghShared = hSurface; rtn = 0; PDEBUG("Shared surface set to %d\n", hSurface); } os_release_mutex(gGFXMutex); ///////////////////////////// return rtn;}int gfx_inf_h_get_shared_surface(void){ return ghShared;}int gfx_inf_h_create_surface(GFX_CREATE_SURFACE_PARM_T *pParm){ int rtn = -1; if(NULL == pParm || pParm->uHeight == 0 || pParm->uWidth == 0) { PDEBUG("Invalid parm\n"); return -1; } ///////////////////////////// if(os_get_mutex(gGFXMutex)) { PDEBUG("Failed on mutex!\n"); return -1; } if(guFreeHandles > 0) { // try to find a free handle int i; for(i=0; i<guMaxHandles; i++) { if(!gfx_osi_pSurface_alloc(&gpHandles[i].surface)) break; } if(i<guMaxHandles) { gfx_osi_init_surface_t(&gpHandles[i].surface); // clear everything if(gfx_osi_create_surface(&gpHandles[i].surface, pParm->graphDev, pParm->uPlaneConfig, pParm->uWidth, pParm->uHeight) >= 0) { rtn = 0; pParm->hSurface = i; gpHandles[i].uLocks = 0; PDEBUG("Clear the surface\n"); gfx_osi_fillBLT(&gpHandles[i].surface, 0,0, pParm->uWidth, pParm->uHeight, pParm->uFillColor); gfx_osi_run_engine(1); PDEBUG("After Clear\n"); guFreeHandles--; if(IS_SURFACE_OSD_COMP(gpHandles[i].surface.uPlaneConfig)) { if(!IS_SURFACE_CURSOR_COMP(gpHandles[i].surface.uPlaneConfig)) { osd_osi_set_comp_gfx_surface_parm(&gpHandles[i].surface, OSD_GRAPH_SURFACE_SCREEN_OFFSET, (ULONG)(gScreenInfo.uLeft ), (ULONG)(gScreenInfo.uUpper)); } else { osd_osi_set_comp_gfx_surface_parm(&gpHandles[i].surface, OSD_GRAPH_SURFACE_SCREEN_OFFSET, (ULONG)0, (ULONG)0); } } } else { PDEBUG("Failed on create surface!\n"); rtn = -1; } } else { PFATAL("invalid free handle count !\n"); guFreeHandles = 0; rtn = -1; } } os_release_mutex(gGFXMutex); ///////////////////////////// return rtn;}int gfx_inf_h_destroy_surface(int hSurface){ int rtn= -1; if(hSurface < 0 || hSurface >= (int)guMaxHandles) { PDEBUG("Bad parm\n"); return -1; } ///////////////////////////// if(os_get_mutex(gGFXMutex)) { PDEBUG("Failed on mutex!\n"); return -1; } if(gfx_osi_pSurface_alloc(&gpHandles[hSurface].surface)) { if(gpHandles[hSurface].uLocks > 0) { PDEBUG("Surface %d is locked by %d times, destroy might be dangerous!\n", hSurface, gpHandles[hSurface].uLocks); } if(gpHandles[hSurface].surface.attachedDev != GFX_VDEV_NULL) osd_osi_detach_comp_gfx_surface(gpHandles[hSurface].surface.attachedDev, &gpHandles[hSurface].surface); rtn = gfx_osi_destroy_surface(&gpHandles[hSurface].surface); if(!rtn) { guFreeHandles++; _OS_MEMSET(&gpHandles[hSurface], 0, sizeof(gpHandles[hSurface])); if(ghShared == hSurface) // make sure it is changed ghShared = -1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -