main.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <sys/shm.h>
  8. #include <sys/ipc.h>
  9. #include <linux/ioctl.h>
  10. #include <sys/ioctl.h>
  11. #include <errno.h>
  12. #include <signal.h>
  13. #include <semaphore.h>
  14. #include <linux/fb.h>
  15. #include <string.h>
  16. #include "include/ark_api.h"
  17. #define TEST_ARK1668 1
  18. #define TEST_ARKN141 2
  19. #define TEST_ARK1668E 3
  20. //#define FILE_FORMAT_RGB 1
  21. //#define FILE_FORMAT_YUV 2
  22. //#define FILE_FORMAT_NV12 3
  23. #define DISP_WIDTH 1024
  24. #define DISP_HEIGHE 600
  25. struct display_info{
  26. disp_handle *display_handle;
  27. int lay_id;
  28. unsigned int disp_posx;
  29. unsigned int disp_posy;
  30. unsigned int disp_width;
  31. unsigned int disp_height;
  32. struct ark_reqbuf reqbuf;
  33. };
  34. struct test_info{
  35. int platform;
  36. int pic_format;
  37. char filepath[64];
  38. };
  39. static struct display_info *overlay = NULL;
  40. static struct display_info *overlay2 = NULL;
  41. static memalloc_handle * mem_handle = NULL;
  42. static struct test_info test;
  43. extern void carback_work_start(void);
  44. extern void carback_work_exit(void);
  45. static void generate_argb_pic(void *dst, int width, int height, unsigned int argb)
  46. {
  47. unsigned int *p = dst;
  48. int i,j;
  49. for(i = 0; i < height; i++){
  50. for(j = 0; j < width; j++){
  51. *p++ = argb;
  52. }
  53. }
  54. }
  55. static int get_file_argb_picture(void *dst, int width, int height)
  56. {
  57. int fd;
  58. //static int init = 0;
  59. //if(init)
  60. // return 0;
  61. //1. read file data
  62. fd = open(test.filepath, O_RDWR);
  63. if (fd < 0) {
  64. printf("open %s fail.\n",test.filepath);
  65. return 0;
  66. } else {
  67. read(fd,dst,width*height*4);
  68. close(fd);
  69. //init = 1;
  70. printf("open %s success.\n",test.filepath);
  71. }
  72. return 0;
  73. }
  74. static int disp_color_init_test(void){
  75. struct ark_disp_color color;
  76. int i, layer_max;
  77. if(test.platform == TEST_ARKN141)
  78. layer_max = 2;
  79. else
  80. layer_max = 5;
  81. for(i = PRIMARY_LAYER; i < layer_max; i++){
  82. color.contrast = 0x80;
  83. color.brightness = 0x80;
  84. color.saturation = 0x40;
  85. color.hue = 0;
  86. arkapi_display_layer_set_color(i, &color);
  87. arkapi_display_layer_get_color(i, &color);
  88. printf("%s-->layer=%d, %d %d %d %d.\n", __func__, i,color.contrast,color.brightness,color.saturation,color.hue);
  89. }
  90. }
  91. static struct display_info * disp_layer_init(enum ark_disp_layer layer, int format, int width, int height, int buf_cnt)
  92. {
  93. struct display_info *pinfo = NULL;
  94. struct ark_reqbuf reqbuf;
  95. unsigned int addr, ret;
  96. disp_handle *display_handle;
  97. pinfo = (struct display_info *)malloc(sizeof(struct display_info));
  98. if (pinfo == NULL) {
  99. printf("no enough memory be alloc");
  100. return NULL;
  101. }
  102. if(buf_cnt >= FRAME_MAX){
  103. printf("buf_cnt max=%d, error.",FRAME_MAX);
  104. }
  105. memset(pinfo, 0, sizeof(struct display_info));
  106. pinfo->disp_posx = 0;
  107. pinfo->disp_posy = 0;
  108. pinfo->disp_width = width;
  109. pinfo->disp_height = height;
  110. pinfo->lay_id = layer;
  111. display_handle = arkapi_display_open_layer(pinfo->lay_id);
  112. if(!display_handle){
  113. printf("open fb%d error.",pinfo->lay_id);
  114. free(pinfo);
  115. return NULL;
  116. }
  117. pinfo->display_handle = display_handle;
  118. arkapi_display_hide_layer(display_handle);
  119. reqbuf.count= buf_cnt;
  120. reqbuf.size= pinfo->disp_width * pinfo->disp_height * 4;
  121. ret = arkapi_memalloc_reqbuf(mem_handle, &reqbuf);
  122. if(ret != 0){
  123. printf("buffer request error ,ret=%d.\n",ret);
  124. return NULL;
  125. }
  126. memcpy(&pinfo->reqbuf, &reqbuf, sizeof(struct ark_reqbuf));
  127. #if 1
  128. arkapi_display_set_layer_pos_atomic(display_handle, pinfo->disp_posx, pinfo->disp_posy);
  129. arkapi_display_set_layer_size_atomic(display_handle, pinfo->disp_width, pinfo->disp_height);
  130. arkapi_display_set_layer_format_atomic(display_handle, format);
  131. arkapi_display_layer_update_commit(display_handle);
  132. #else
  133. arkapi_display_set_layer_pos(display_handle, pinfo->disp_posx, pinfo->disp_posy);
  134. arkapi_display_set_layer_size(display_handle, pinfo->disp_width, pinfo->disp_height);
  135. arkapi_display_set_layer_format(display_handle, format);
  136. #endif
  137. return pinfo;
  138. }
  139. static void disp_layer_deinit(struct display_info *pinfo)
  140. {
  141. if(pinfo){
  142. arkapi_display_close_layer(pinfo->display_handle);
  143. free(pinfo);
  144. }
  145. }
  146. static int overlay_update(struct display_info *pinfo)
  147. {
  148. static int id = 0;
  149. static int pos_x = 0;
  150. static int pos_y = 0;
  151. static int width;
  152. static int height;
  153. static unsigned int rgb = 0;
  154. int value;
  155. if(!pinfo)
  156. return -EINVAL;
  157. if(pos_x == 0 && pos_y == 0){
  158. width = pinfo->disp_width;
  159. height = pinfo->disp_height;
  160. }
  161. if(id >= pinfo->reqbuf.count)
  162. id = 0;
  163. if(rgb%3 == 0) {
  164. //value = 0xa0800080;//a r g b
  165. value = 0xa0ff0000;
  166. } else if(rgb%3 == 1){
  167. //value = 0xa0ffff00;//a r g b
  168. value = 0xa000ff00;
  169. //} else if(rgb++%3 == 2) {
  170. } else {
  171. //value = 0xa0ffff00;//a r g b
  172. value = 0xa00000ff;
  173. }
  174. rgb++;
  175. printf("generate-->0x%08x.\n", value);
  176. generate_argb_pic(pinfo->reqbuf.virt_addr[id], pinfo->disp_width, pinfo->disp_height, value);
  177. //arkapi_display_set_layer_format(pinfo->fd, format);
  178. arkapi_display_set_layer_pos(pinfo->display_handle, pos_x, pos_y);
  179. arkapi_display_set_layer_size(pinfo->display_handle, width, height);
  180. if(pinfo->reqbuf.count > 1) {
  181. int count = 3;
  182. while(count--) {
  183. int yaddr, uaddr, vaddr;
  184. arkapi_display_get_layer_addr(pinfo->display_handle, &yaddr, &uaddr, &vaddr);
  185. if(yaddr != pinfo->reqbuf.phy_addr[id])
  186. break;
  187. arkapi_display_wait_for_vsync(pinfo->display_handle);
  188. }
  189. }
  190. arkapi_display_set_layer_addr(pinfo->display_handle, pinfo->reqbuf.phy_addr[id], 0, 0);
  191. //change test
  192. pos_x += 10*pinfo->disp_width/pinfo->disp_height;
  193. pos_y += 10;
  194. width -= 20*pinfo->disp_width/pinfo->disp_height;
  195. height -= 20;
  196. if((width <= 0) || (height <= 30)){
  197. pos_x = 0;
  198. pos_y = 0;
  199. width = pinfo->disp_width;
  200. height = pinfo->disp_height;
  201. }
  202. id++;
  203. return 0;
  204. }
  205. static int overlay2_update(struct display_info *pinfo)
  206. {
  207. int value;
  208. int yaddr, uaddr, vaddr;
  209. static int id = 0;
  210. if(!pinfo)
  211. return -EINVAL;
  212. if(id >= pinfo->reqbuf.count)
  213. id = 0;
  214. yaddr = pinfo->reqbuf.phy_addr[id];
  215. uaddr = yaddr + pinfo->disp_width * pinfo->disp_height;
  216. //value = 0xa0005050;//a r g b
  217. //printf("generate-->0x%08x.\n",value);
  218. //generate_argb_pic((void*)pinfo->buf[0].yaddr, pinfo->disp_width, pinfo->disp_height, value);
  219. get_file_argb_picture(pinfo->reqbuf.virt_addr[id], pinfo->disp_width, pinfo->disp_height);
  220. if(test.pic_format == ARK_LCDC_FORMAT_Y_UV420) {
  221. vaddr = 0;
  222. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV420){
  223. vaddr = uaddr+ pinfo->disp_width * pinfo->disp_height / 4;
  224. } else if(test.pic_format == ARK_LCDC_FORMAT_Y_UV422) {
  225. vaddr = 0;
  226. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV422) {
  227. vaddr = uaddr+ pinfo->disp_width * pinfo->disp_height / 2;
  228. } else {
  229. uaddr = vaddr = 0;
  230. }
  231. if(pinfo->reqbuf.count > 1) {
  232. int count = 3;
  233. while(count--) {
  234. int y, u, v;
  235. arkapi_display_get_layer_addr(pinfo->display_handle, &y, &u, &v);
  236. if(yaddr != y)
  237. break;
  238. arkapi_display_wait_for_vsync(pinfo->display_handle);
  239. }
  240. }
  241. arkapi_display_set_layer_addr(pinfo->display_handle, yaddr, uaddr, vaddr);
  242. //ui 显存默认地址 已经设置,如果没有切换需要,可以不用重新设置
  243. id++;
  244. return 0;
  245. }
  246. static int parser_command_set_para(char* pcmd0,char* pcmd1)
  247. {
  248. char* p;
  249. int i;
  250. char *format_tail = NULL;
  251. /* Parse platform. */
  252. printf("pcmd0 parser==>%s\n",pcmd0);
  253. if(strstr(pcmd0,"n141")){
  254. test.platform = TEST_ARKN141;
  255. } else if(strncmp(pcmd0, "ark1668e", 8) == 0){
  256. test.platform = TEST_ARK1668E;
  257. printf("platform is ark1668e\n");
  258. } else if(strncmp(pcmd0, "ark1668", 7) == 0){
  259. test.platform = TEST_ARK1668;
  260. printf("platform is ark1668\n");
  261. } else{
  262. printf("cmd0 parser error.\n");
  263. return -1;
  264. }
  265. /* Parse format. */
  266. printf("pcmd1 parser==>%s\n",pcmd1);
  267. //new add as follows:
  268. if(strstr(pcmd1,".vyuy")) {
  269. test.pic_format = ARK_LCDC_FORMAT_VYUY;
  270. format_tail = ".vyuy";
  271. } else if(strstr(pcmd1,".y_uv420")) {
  272. test.pic_format = ARK_LCDC_FORMAT_Y_UV420;
  273. format_tail = ".y_uv420";
  274. } else if(strstr(pcmd1,".yuv420")) {
  275. test.pic_format = ARK_LCDC_FORMAT_YUV420;
  276. format_tail = ".yuv420";
  277. } else if(strstr(pcmd1,".y_uv422")) {
  278. test.pic_format = ARK_LCDC_FORMAT_Y_UV422;
  279. format_tail = ".y_uv422";
  280. } else if(strstr(pcmd1,".yuv422")) {
  281. test.pic_format = ARK_LCDC_FORMAT_YUV422;
  282. format_tail = ".yuv422";
  283. //Old format supported as follows.
  284. } else if(strstr(pcmd1,".rgb")) {
  285. test.pic_format = ARK_LCDC_FORMAT_RGBA888 | ARK_LCDC_ORDER_RGB;
  286. format_tail = ".rgb";
  287. } else if(strstr(pcmd1,".yuv")) {
  288. if (test.pic_format == TEST_ARKN141) {
  289. test.pic_format = ARK_LCDC_FORMAT_Y_UV420;
  290. format_tail = ".y_uv420";
  291. } else {
  292. test.pic_format = ARK_LCDC_FORMAT_VYUY;
  293. format_tail = ".vyuy";
  294. }
  295. } else {
  296. printf("cmd1 parser error.\n");
  297. return -1;
  298. }
  299. if(strlen(format_tail) == 0) {
  300. printf("Not recognize picture format\n");
  301. return -1;
  302. }
  303. printf("platform=%d, pic_format=%d.\n",test.platform, test.pic_format);
  304. //get file name format: 123.rgb
  305. p = strtok(pcmd1,".");
  306. i = 0;
  307. while(*p != '\0'){
  308. test.filepath[i++] = *p++;
  309. }
  310. sprintf(&test.filepath[i], "%s", format_tail);
  311. return 0;
  312. }
  313. static int display_layer_scale_test(struct display_info *pinfo)
  314. {
  315. static int id = 0;
  316. static int pos_x = 0;
  317. static int pos_y = 0;
  318. static int width;
  319. static int height;
  320. int yaddr, uaddr, vaddr;
  321. if(!pinfo) {
  322. printf("pinfo == NULL\n");
  323. return -EINVAL;
  324. }
  325. if(test.platform == TEST_ARK1668E) {
  326. if(pos_x == 0 && pos_y == 0){
  327. width = pinfo->disp_width;
  328. height = pinfo->disp_height;
  329. }
  330. if(id >= pinfo->reqbuf.count)
  331. id = 0;
  332. printf("generate-->id[%d]: 0x%08x.\n", id, pinfo->reqbuf.virt_addr[id]);
  333. get_file_argb_picture(pinfo->reqbuf.virt_addr[id], pinfo->disp_width, pinfo->disp_height);
  334. yaddr = pinfo->reqbuf.phy_addr[id];
  335. uaddr = yaddr + pinfo->disp_width * pinfo->disp_height;
  336. if(test.pic_format == ARK_LCDC_FORMAT_Y_UV420) {
  337. vaddr = 0;
  338. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV420){
  339. vaddr = uaddr+ pinfo->disp_width * pinfo->disp_height / 4;
  340. } else if(test.pic_format == ARK_LCDC_FORMAT_Y_UV422) {
  341. vaddr = 0;
  342. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV422) {
  343. vaddr = uaddr+ pinfo->disp_width * pinfo->disp_height / 2;
  344. } else {
  345. uaddr = vaddr = 0;
  346. }
  347. arkapi_display_set_layer_pos(pinfo->display_handle, pos_x, pos_y);
  348. if(pinfo->reqbuf.count > 1) {
  349. int count = 3;
  350. while(count--) {
  351. int y, u, v;
  352. arkapi_display_get_layer_addr(pinfo->display_handle, &y, &u, &v);
  353. if(yaddr != y)
  354. break;
  355. arkapi_display_wait_for_vsync(pinfo->display_handle);
  356. }
  357. }
  358. arkapi_display_set_layer_addr(pinfo->display_handle, yaddr, uaddr, vaddr);
  359. disp_scaler scale;
  360. scale.src_w = pinfo->disp_width;
  361. scale.src_h = pinfo->disp_height;
  362. scale.win_x = 0;
  363. scale.win_y = 0;
  364. scale.win_w = pinfo->disp_width;
  365. scale.win_h = pinfo->disp_height;
  366. scale.out_x = pos_x;
  367. scale.out_y = pos_y;
  368. scale.out_w = width;
  369. scale.out_h = height;
  370. scale.cut_top = 0;
  371. scale.cut_bottom = 0;
  372. scale.cut_left = 0;
  373. scale.cut_right = 0;
  374. arkapi_display_set_layer_scaler(pinfo->display_handle, &scale);
  375. //change test
  376. pos_x += 8*(pinfo->disp_width/pinfo->disp_height);
  377. pos_y += 8;
  378. width -= 16*(pinfo->disp_width/pinfo->disp_height);
  379. height -= 16;
  380. if((width <= 0) || (height <= 30)) {
  381. pos_x = 0;
  382. pos_y = 0;
  383. width = pinfo->disp_width;
  384. height = pinfo->disp_height;
  385. }
  386. id++;
  387. } else {
  388. printf("%s, Do not support platform:%d\n", __func__, test.platform);
  389. }
  390. return 0;
  391. }
  392. static int axi_scale_test(struct display_info *pinfo)
  393. {
  394. int format, oformat;
  395. int iyaddr, iuaddr, ivaddr;
  396. int oyaddr, ouaddr, ovaddr;
  397. int iwidth = 1920;
  398. int iheight = 720;
  399. static int owidth;
  400. static int oheight;
  401. static int pos_x = 0;
  402. static int pos_y = 0;
  403. static unsigned int id = 0;
  404. static int rotate = 0;
  405. int disp_width, disp_height;
  406. int ret;
  407. if((pos_x ==0) && (pos_y == 0)) {
  408. owidth = pinfo->disp_width;
  409. oheight = pinfo->disp_height;
  410. }
  411. #if 0
  412. pos_x = 0;
  413. pos_y = 0;
  414. owidth = 1920;
  415. oheight = 720;
  416. #endif
  417. if(test.pic_format == ARK_LCDC_FORMAT_VYUY) {
  418. format = ARK_SCALE_FORMAT_YUYV;
  419. oformat = ARK_SCALE_OUT_FORMAT_YUYV;
  420. } else if(test.pic_format == ARK_LCDC_FORMAT_Y_UV420) {
  421. format = ARK_SCALE_FORMAT_Y_UV420;
  422. oformat = ARK_SCALE_OUT_FORMAT_Y_UV420;
  423. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV420) {
  424. format = ARK_SCALE_FORMAT_Y_U_V420;
  425. oformat = ARK_SCALE_OUT_FORMAT_Y_UV420;
  426. } else if(test.pic_format == ARK_LCDC_FORMAT_Y_UV422) {
  427. format = ARK_SCALE_FORMAT_Y_UV422;
  428. oformat = ARK_SCALE_OUT_FORMAT_Y_UV422;
  429. } else if(test.pic_format == ARK_LCDC_FORMAT_YUV422) {
  430. format = ARK_SCALE_FORMAT_YUV422;
  431. oformat = ARK_SCALE_OUT_FORMAT_Y_UV422;
  432. } else {
  433. printf("axi scalar not support format:%d\n", test.pic_format);
  434. return -1;
  435. }
  436. if(test.platform == TEST_ARK1668E) {
  437. printf("format:0x%x\n", format);
  438. printf("iwidth:%d, iheight:%d\n", iwidth, iheight);
  439. printf("owidth:%d, oheight:%d\n", owidth, oheight);
  440. get_file_argb_picture(pinfo->reqbuf.virt_addr[0], iwidth, iheight);
  441. iyaddr = (unsigned int)pinfo->reqbuf.phy_addr[0];
  442. if(id++%2) {
  443. oyaddr = (unsigned int)pinfo->reqbuf.phy_addr[1];
  444. } else {
  445. oyaddr = (unsigned int)pinfo->reqbuf.phy_addr[2];
  446. }
  447. iuaddr = iyaddr + iwidth * iheight;
  448. ouaddr = oyaddr + owidth * oheight;
  449. if(format == ARK_SCALE_FORMAT_Y_UV420) {
  450. ivaddr = 0;
  451. ovaddr = 0;
  452. printf("### axi-scale mode y_uv420\n");
  453. } else if(format == ARK_SCALE_FORMAT_Y_U_V420){
  454. ivaddr = iuaddr+ iwidth * iheight / 4;
  455. ovaddr = ouaddr+ owidth * oheight / 4;
  456. printf("### axi-scale mode yuv420\n");
  457. } else if(format == ARK_SCALE_FORMAT_Y_UV422) {
  458. ivaddr = 0;
  459. ovaddr = 0;
  460. printf("### axi-scale mode y_uv422\n");
  461. } else if(format == ARK_SCALE_FORMAT_YUV422) {
  462. ivaddr = iuaddr+ iwidth * iheight / 2;
  463. ovaddr = ouaddr+ owidth * oheight / 2;
  464. printf("### axi-scale mode yuv422\n");
  465. } else {
  466. printf("### axi-scale mode other:%d\n", format);
  467. ivaddr = 0;
  468. ovaddr = 0;
  469. }
  470. //printf("%s, iyaddr:0x%x, iuaddr:0x%x, ivaddr:0x%x,\n", __func__, iyaddr, iuaddr, ivaddr);
  471. //printf("%s, oyaddr:0x%x, ouaddr:0x%x, ovaddr:0x%x,\n", __func__, oyaddr, ouaddr, ovaddr);
  472. printf("### rotate:%d\n", rotate);
  473. ret = arkapi_scalar(iyaddr, iuaddr, ivaddr, format,
  474. iwidth,
  475. iheight,
  476. 0, 0,
  477. iwidth,
  478. iheight,
  479. 0, 0, 0, 0,
  480. owidth,
  481. oheight,
  482. oyaddr,
  483. ouaddr,
  484. ovaddr,
  485. oformat,
  486. //SCALE_ROTATE_0);
  487. SCALE_ROTATE_0 + rotate);
  488. if(ret)
  489. printf("arkapi_scalar failed, ret:%d\n", ret);
  490. if((rotate == SCALE_ROTATE_90) || (rotate == SCALE_ROTATE_270) ||
  491. (rotate == SCALE_ROTATE_90_MIRROR) || (rotate == SCALE_ROTATE_270_MIRROR)) {
  492. disp_width = oheight;
  493. disp_height = owidth;
  494. } else {
  495. disp_width = owidth;
  496. disp_height = oheight;
  497. }
  498. ovaddr = 0;
  499. if(oformat == ARK_SCALE_OUT_FORMAT_Y_UV420) {
  500. format = ARK_LCDC_FORMAT_Y_UV420;
  501. arkapi_display_set_layer_format(pinfo->display_handle, format);
  502. } else if(oformat == ARK_SCALE_OUT_FORMAT_Y_UV422) {
  503. format = ARK_LCDC_FORMAT_Y_UV422;
  504. arkapi_display_set_layer_format(pinfo->display_handle, format);
  505. } else if(oformat == ARK_SCALE_OUT_FORMAT_YUYV) {
  506. //format = ARK_LCDC_FORMAT_VYUY;
  507. //arkapi_display_set_layer_format(pinfo->display_handle, format);
  508. }
  509. arkapi_display_set_layer_pos(pinfo->display_handle, pos_x, pos_y);
  510. arkapi_display_set_layer_size(pinfo->display_handle, disp_width, disp_height);
  511. if(pinfo->reqbuf.count > 1) {
  512. int count = 3;
  513. while(count--) {
  514. int yaddr, uaddr, vaddr;
  515. arkapi_display_get_layer_addr(pinfo->display_handle, &yaddr, &uaddr, &vaddr);
  516. if(yaddr != oyaddr)
  517. break;
  518. arkapi_display_wait_for_vsync(pinfo->display_handle);
  519. }
  520. }
  521. arkapi_display_set_layer_addr(pinfo->display_handle, oyaddr, ouaddr, ovaddr);
  522. #if 1
  523. pos_x += 8*(pinfo->disp_width/pinfo->disp_height);
  524. pos_y += 8;
  525. owidth -= 16*(pinfo->disp_width/pinfo->disp_height);
  526. oheight -= 16;
  527. if((owidth <= 0) || (oheight <= 30)) {
  528. pos_x = 0;
  529. pos_y = 0;
  530. owidth = pinfo->disp_width;
  531. oheight = pinfo->disp_height;
  532. }
  533. #else
  534. if(++rotate >= SCALE_ROTATE_END)
  535. rotate = SCALE_ROTATE_0;
  536. #endif
  537. } else {
  538. printf("%s, Do not support platform:%d\n", __func__, test.platform);
  539. }
  540. return 0;
  541. }
  542. static int vp_test(int layer, int brightness, int contrast, int saturation, int hue)
  543. {
  544. disp_color color;
  545. color.contrast = contrast;
  546. color.brightness = brightness;
  547. color.saturation = saturation;
  548. color.hue = hue;
  549. printf("%s, write:-->layer=%d, %d %d %d %d.\n", __func__,
  550. layer, color.contrast,color.brightness,color.saturation,color.hue);
  551. arkapi_display_layer_set_color(layer, &color);
  552. arkapi_display_layer_get_color(layer, &color);
  553. printf("%s, read: -->layer=%d, %d %d %d %d.\n", __func__,
  554. layer, color.contrast,color.brightness,color.saturation,color.hue);
  555. return 0;
  556. }
  557. static void printf_command_help(void)
  558. {
  559. printf("\n");
  560. printf("***********************command help*****************************\n");
  561. printf("* *\n");
  562. printf("*run cmd: demo-display [cmd1] [cmd2] *\n");
  563. printf("* *\n");
  564. printf("*cmd1 option: 1.ark1668 2.n141 3.ark1668e *\n");
  565. printf("* *\n");
  566. printf("*cmd2 option: filename.type *\n");
  567. printf("* type: y_uv420/yuv420/y_uv422/yuv422/vyuy/yuv/rgb *\n");
  568. printf("* *\n");
  569. printf("*example: *\n");
  570. printf("* demo-display ark1668 /usr/share/pic_1024x600.rgb *\n");
  571. printf("* demo-display n141 /media/123.yuv *\n");
  572. printf("* *\n");
  573. printf("****************************************************************\n");
  574. printf("\n");
  575. }
  576. int main(int argc, char *argv[])
  577. {
  578. int ret, screen_width, screen_height;
  579. char filepath[32] = "/usr/share/pic_1024x600.rgb";
  580. screen_info screen;
  581. int format;
  582. printf_command_help();
  583. if(argc == 1){
  584. test.platform = TEST_ARK1668;
  585. test.pic_format = ARK_LCDC_FORMAT_RGBA888;
  586. memcpy(&test.filepath, filepath, 32);
  587. }else if(argc == 3){
  588. printf("==>get run cmd: %s %s %s \n",argv[0],argv[1],argv[2]);
  589. ret = parser_command_set_para(argv[1],argv[2]);
  590. if(ret < 0){
  591. printf("run para error, exit1.\n");
  592. return 0;
  593. }
  594. } else if(argc == 8) { //vp test.
  595. printf("\n### cmd: %s %s %s %s %s %s %s %s\n\n",argv[0],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],argv[6]);
  596. parser_command_set_para(argv[1],argv[2]);
  597. }else{
  598. printf("run para error, exit2.\n");
  599. return 0;
  600. }
  601. if (test.platform == TEST_ARK1668)
  602. carback_work_start();
  603. mem_handle = arkapi_memalloc_init();
  604. ret = arkapi_display_get_screen_info(&screen);
  605. if(ret == 0){
  606. screen_width = screen.width;
  607. screen_height = screen.height;
  608. }else{
  609. screen_width = DISP_WIDTH;
  610. screen_height = DISP_HEIGHE;
  611. }
  612. printf("screen_width=%d, screen_height=%d \n",screen_width, screen_height);
  613. #if 0
  614. /* display video/osd layer vp test */
  615. if(strncmp(argv[2], "vp_test", 7) == 0) {
  616. if(test.platform == TEST_ARK1668E) {
  617. int layer = atoi(argv[3]);
  618. int brightness = atoi(argv[4]);
  619. int contrast = atoi(argv[5]);
  620. int saturation = atoi(argv[6]);
  621. int hue = atoi(argv[7]);
  622. vp_test(layer, brightness, contrast, saturation, hue);
  623. }
  624. return 0;
  625. }
  626. #endif
  627. #if 0
  628. /* video layer scale test. */
  629. format = test.pic_format | ARK_LCDC_ORDER_VYUY;
  630. struct display_info *pinfo = disp_layer_init(TVOUT_LAYER, format, screen_width, screen_height, 2);
  631. arkapi_display_show_layer(pinfo->display_handle);
  632. while(1) {
  633. display_layer_scale_test(pinfo);
  634. sleep(1);
  635. }
  636. #endif
  637. #if 0
  638. /* axi scale test. */
  639. format = test.pic_format;
  640. if(format == ARK_LCDC_FORMAT_YUV420)
  641. format = ARK_LCDC_FORMAT_Y_UV420;
  642. else if(format == ARK_LCDC_FORMAT_YUV422)
  643. format = ARK_LCDC_FORMAT_Y_UV422;
  644. else
  645. format = ARK_LCDC_FORMAT_VYUY;
  646. //scale output format only support: Y_UV420, YUV422, VYUY.
  647. struct display_info *pinfo = disp_layer_init(VIDEO_LAYER, format, screen_width, screen_height, 3);
  648. arkapi_display_show_layer(pinfo->display_handle);
  649. do {
  650. axi_scale_test(pinfo);
  651. sleep(2);
  652. //goto exit;
  653. } while(1);
  654. #endif
  655. /* display test. */
  656. #if 1
  657. if(test.platform == TEST_ARKN141){
  658. format = ARK_LCDC_FORMAT_RGBA888 | ARK_LCDC_ORDER_RGB;
  659. overlay = disp_layer_init(VIDEO_LAYER,format, screen_width, screen_height, 3);
  660. format = test.pic_format | ARK_LCDC_ORDER_VYUY;
  661. overlay2 = disp_layer_init(PRIMARY_LAYER, format, screen_width, screen_height, 1);
  662. }else if(test.platform == TEST_ARK1668){
  663. format = ARK_LCDC_FORMAT_RGBA888 | ARK_LCDC_ORDER_RGB;
  664. overlay = disp_layer_init(OVER_LAYER,format, screen_width, screen_height, 3);
  665. format = test.pic_format | ARK_LCDC_ORDER_VYUY;
  666. overlay2 = disp_layer_init(VIDEO_LAYER, format, screen_width, screen_height, 1);
  667. } else if(test.platform == TEST_ARK1668E){
  668. format = ARK_LCDC_FORMAT_RGBA888 | ARK_LCDC_ORDER_RGB;
  669. overlay = disp_layer_init(OVER_LAYER,format, screen_width, screen_height, 3);
  670. format = test.pic_format | ARK_LCDC_ORDER_VYUY;
  671. overlay2 = disp_layer_init(VIDEO_LAYER, format, screen_width, screen_height, 1);
  672. } else {
  673. printf("Invalid platfrom:%d, exit.\n", test.platform);
  674. return 0;
  675. }
  676. //disp_color_init_test(); //Call after set format.
  677. arkapi_display_show_layer(overlay->display_handle);
  678. arkapi_display_show_layer(overlay2->display_handle);
  679. while(1){
  680. overlay_update(overlay);
  681. overlay2_update(overlay2);
  682. sleep(1);
  683. }
  684. #endif
  685. exit:
  686. if(overlay)
  687. disp_layer_deinit(overlay);
  688. if(overlay2)
  689. disp_layer_deinit(overlay2);
  690. if (test.platform == TEST_ARK1668)
  691. carback_work_exit();
  692. if(mem_handle)
  693. arkapi_memalloc_release(mem_handle);
  694. return 0;
  695. }