PageRenderTime 2364ms CodeModel.GetById 984ms app.highlight 638ms RepoModel.GetById 642ms app.codeStats 0ms

/src/backend/sigma/ftk_backend_sigma.c

http://ftk.googlecode.com/
C | 214 lines | 180 code | 30 blank | 4 comment | 23 complexity | d5b5f991f0b8fdaaf2b85eb2a8b2bf48 MD5 | raw file
  1#include "ftk_log.h"
  2#include "ftk_globals.h"
  3#include "ftk_wnd_manager.h"
  4#include "ftk_display_sigma.h"
  5
  6#define ALLOW_OS_CODE 1
  7#include "dcc/include/dcc.h"
  8#include "common.h"
  9#include "osdlib.h"
 10#include "rmcore/include/rmcore.h"
 11
 12#define DEB(f) (f)
 13
 14#define DEFAULT_OSD_WIDTH 640
 15#define DEFAULT_OSD_HEIGHT 480
 16#define DEFAULT_OSD_BPP 32
 17#define DEFAULT_DRAM 0
 18#define DEFAULT_OSD_FORMAT OSD_FORMAT_TC
 19#define DEFAULT_OSD_SUBFORMAT OSD_SUBFORMAT_32BPP
 20#define DEFAULT_CHIP 0
 21
 22/* Global */
 23static char create_osd = 0;
 24static char bg_R = 0xff, bg_G, bg_B, bg_A=0xff;
 25static char fg_R, fg_G, fg_B, fg_A;
 26
 27static RMuint8 *osd_base_addr;          //Base address where OSD is mapped
 28static struct osd_descriptor p_osd;
 29
 30static void init_tc(struct osd_descriptor *m_osd, RMuint8 *base_addr)
 31{
 32	RMuint32 bg_color = 0 , fg_color = 0;
 33
 34	bg_color = 0;
 35	fg_color = 0;
 36	switch(m_osd->profile.ColorFormat){
 37		case EMhwlibColorFormat_24BPP_565 :
 38		case EMhwlibColorFormat_24BPP :
 39		case EMhwlibColorFormat_32BPP_4444:
 40		case EMhwlibColorFormat_32BPP :
 41			/* for 24BPP, alpha will not be taken */
 42			RMinsShiftBits(&bg_color, bg_A, 8, 24);
 43			RMinsShiftBits(&bg_color, bg_R, 8, 16);
 44			RMinsShiftBits(&bg_color, bg_G, 8,  8);
 45			RMinsShiftBits(&bg_color, bg_B, 8,  0);
 46			RMinsShiftBits(&fg_color, fg_A, 8, 24);
 47			RMinsShiftBits(&fg_color, fg_R, 8, 16);
 48			RMinsShiftBits(&fg_color, fg_G, 8,  8);
 49			RMinsShiftBits(&fg_color, fg_B, 8,  0);
 50			break;
 51		case EMhwlibColorFormat_16BPP_565:
 52			RMinsShiftBits(&bg_color, bg_R, 5, 11);
 53			RMinsShiftBits(&bg_color, bg_G, 6,  5);
 54			RMinsShiftBits(&bg_color, bg_B, 5,  0);
 55			RMinsShiftBits(&fg_color, fg_R, 5, 11);
 56			RMinsShiftBits(&fg_color, fg_G, 6,  5);
 57			RMinsShiftBits(&fg_color, fg_B, 5,  0);
 58			break;
 59		case EMhwlibColorFormat_16BPP_1555:
 60			RMinsShiftBits(&bg_color, bg_A, 1, 15);
 61			RMinsShiftBits(&bg_color, bg_R, 5, 10);
 62			RMinsShiftBits(&bg_color, bg_G, 5,  5);
 63			RMinsShiftBits(&bg_color, bg_B, 5,  0);
 64			RMinsShiftBits(&fg_color, fg_A, 1, 15);
 65			RMinsShiftBits(&fg_color, fg_R, 5, 10);
 66			RMinsShiftBits(&fg_color, fg_G, 5,  5);
 67			RMinsShiftBits(&fg_color, fg_B, 5,  0);
 68			break;
 69		case EMhwlibColorFormat_16BPP_4444:
 70			RMinsShiftBits(&bg_color, bg_A, 4, 12);
 71			RMinsShiftBits(&bg_color, bg_R, 4,  8);
 72			RMinsShiftBits(&bg_color, bg_G, 4,  4);
 73			RMinsShiftBits(&bg_color, bg_B, 4,  0);
 74			RMinsShiftBits(&fg_color, fg_A, 4, 12);
 75			RMinsShiftBits(&fg_color, fg_R, 4,  8);
 76			RMinsShiftBits(&fg_color, fg_G, 4,  4);
 77			RMinsShiftBits(&fg_color, fg_B, 4,  0);
 78			break;
 79	}
 80
 81	DEB(fprintf(stderr,"bg color = 0x%08lx, fg color = 0x%08lx\n", bg_color, fg_color));
 82	{ 
 83		int x,y;
 84		int width = m_osd->profile.Width;
 85		int height = m_osd->profile.Height;
 86
 87		RMuint32 *addr= (RMuint32 *)base_addr;
 88		for (x=0;x<(int)m_osd->profile.Width;x++)
 89		{
 90			for (y=0;y<(int)m_osd->profile.Height;y++)
 91			{
 92		        *addr = bg_color;
 93		        addr++;
 94			}
 95		}
 96	}
 97}
 98
 99/** Cleanup
100 */
101static void sigma_deinit(void *param)
102{
103	RMstatus err;
104	struct osd_descriptor *my_osd=(struct osd_descriptor *)param;
105	
106	DEB(fprintf(stderr,"begin sigma_deinit\n"));
107	
108	if (my_osd == NULL)
109		return;
110	
111	if(my_osd->dcc_info.pRUA) {
112		(void)RUAUnMap(my_osd->dcc_info.pRUA, osd_base_addr, p_osd.LumaSize);
113		(void)RUAUnLock(my_osd->dcc_info.pRUA, p_osd.LumaAddr, p_osd.LumaSize);
114	}
115	
116	if (my_osd->dcc_info.pDCC){
117		err = DCCClose(my_osd->dcc_info.pDCC);
118		if (RMFAILED(err))
119			fprintf(stderr, "Cannot close DCC %d\n", err); 
120	}
121
122	if (my_osd->dcc_info.pRUA){
123		err = RUADestroyInstance(my_osd->dcc_info.pRUA);
124		if (RMFAILED(err))
125			fprintf(stderr, "Cannot destroy RUA instance %d\n", err);
126	}
127        DEB(fprintf(stderr,"end sigma_deinit\n"));
128}
129
130static Ret sigma_init(int argc, char* argv[])
131{
132	RMstatus status;
133	struct display_context disp_info;
134	p_osd.dcc_info.disp_info = &disp_info;
135
136	RMSignalInit(sigma_deinit, &p_osd);
137	
138	p_osd.chip_num = 0;
139	status = RUACreateInstance(&(p_osd.dcc_info.pRUA),p_osd.chip_num);
140	if(RMFAILED(status)) {
141		printf("Error creating intance : %d\n",status);
142		goto wayout;
143	}
144
145	DEB(fprintf(stderr,"  DCCOpen\n"));
146	status = DCCOpen(p_osd.dcc_info.pRUA, &(p_osd.dcc_info.pDCC));
147	if(RMFAILED(status)) {
148		printf("Error opening DCC : %d\n",status);
149		goto wayout;
150	}
151	
152	status = get_osd_infos(&p_osd); 
153	if (RMFAILED(status)) {
154		fprintf(stderr,"Error getting OSD infos : %s\n", RMstatusToString(status)); 
155		goto wayout;
156	}
157
158	if ( p_osd.LumaAddr == 0 || p_osd.LumaSize == 0){
159		fprintf(stderr,"No OSD buffer currently opened, you should create one with osdbuf_control.\n");
160		goto wayout;
161	}
162
163	DEB(fprintf(stderr,"Locking %d bytes of RUA memory ...\n", (int)p_osd.LumaSize));
164	status = RUALock(p_osd.dcc_info.pRUA, p_osd.LumaAddr, p_osd.LumaSize);
165	if (RMFAILED(status)){
166		fprintf(stderr,"Error locking OSD buffer at 0x%08lx (%ld bytes): %s\n",
167		        p_osd.LumaAddr, p_osd.LumaSize, RMstatusToString(status));
168		goto wayout;
169	}
170
171	osd_base_addr = RUAMap(p_osd.dcc_info.pRUA, p_osd.LumaAddr, p_osd.LumaSize);
172	if (osd_base_addr == NULL){
173		status= RM_ERROR;
174		fprintf(stderr,"Error mapping OSD buffer.\n");
175		goto wayout;
176	}
177
178	if (p_osd.profile.ColorMode <= EMhwlibColorMode_LUT_8BPP)
179	{
180		assert("not supported");
181	} else {
182		DEB(fprintf(stderr,"test_display_tc\n"));
183		init_tc(&p_osd, osd_base_addr);
184	}
185
186	DEB(fprintf(stderr, "osd_base_addr=%p width=%d height=%d bpp=%d\n", 
187		osd_base_addr,
188		(int)p_osd.profile.Width, (int)p_osd.profile.Height, (int)p_osd.bpp));
189	ftk_set_display(ftk_display_sigma_create(osd_base_addr, 
190		p_osd.profile.Width, p_osd.profile.Height, p_osd.bpp, &p_osd));
191	
192	DEB(fprintf(stderr,"ftk_set_display %p\n", ftk_default_display()));
193	return RET_OK;
194
195wayout:
196	sigma_deinit(&p_osd);
197	return RET_OK;
198}
199
200Ret ftk_backend_init(int argc, char* argv[])
201{
202	sigma_init(argc, argv);
203	fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
204	if(ftk_default_display() == NULL)
205	{
206		ftk_loge("open display failed.\n");
207		sigma_deinit(&p_osd);
208		exit(0);
209	}
210	fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
211
212	return RET_OK;
213}
214