/src/backend/sigma/ftk_backend_sigma.c

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