From 0294539bf0db220fee13698fb580c9d8003d32df Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 24 Dec 2020 01:52:37 +0100 Subject: [PATCH] Test process. (WIP) --- CMakeLists.txt | 5 +++ main.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d79249c..f151e83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,3 +16,8 @@ target_link_libraries(fbcp bcm_host) set (CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") + + +set (CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") + +set (CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") \ No newline at end of file diff --git a/main.c b/main.c index 2ec68c7..ce45de1 100644 --- a/main.c +++ b/main.c @@ -360,6 +360,7 @@ int process_skip_rows() { vc_dispmanx_display_close(display); } + int process() { DISPMANX_DISPLAY_HANDLE_T display; DISPMANX_MODEINFO_T display_info; @@ -508,13 +509,130 @@ int process() { vc_dispmanx_display_close(display); } + +int process_test() { + DISPMANX_DISPLAY_HANDLE_T display; + DISPMANX_MODEINFO_T display_info; + DISPMANX_RESOURCE_HANDLE_T screen_resource; + VC_IMAGE_TRANSFORM_T transform; + uint32_t image_prt; + VC_RECT_T rect1; + int ret; + int fbfd = 0; + char *fbp = 0; + + struct fb_var_screeninfo vinfo; + struct fb_fix_screeninfo finfo; + + uint16_t *screenbuf[3]; + uint8_t bufNum = 0; + + bcm_host_init(); + + display = vc_dispmanx_display_open(0); + if (!display) { + syslog(LOG_ERR, "Unable to open primary display"); + return -1; + } + ret = vc_dispmanx_display_get_info(display, &display_info); + if (ret) { + syslog(LOG_ERR, "Unable to get primary display information"); + return -1; + } + syslog(LOG_INFO, "Primary display is %d x %d", display_info.width, display_info.height); + + + fbfd = open("/dev/fb1", O_RDWR); + if (fbfd == -1) { + syslog(LOG_ERR, "Unable to open secondary display"); + return -1; + } + if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { + syslog(LOG_ERR, "Unable to get secondary display information"); + return -1; + } + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { + syslog(LOG_ERR, "Unable to get secondary display information"); + return -1; + } + + syslog(LOG_INFO, "Second display is %d x %d %dbps\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); + + screen_resource = vc_dispmanx_resource_create(VC_IMAGE_RGB565, vinfo.xres, vinfo.yres, &image_prt); + if (!screen_resource) { + syslog(LOG_ERR, "Unable to create screen buffer"); + close(fbfd); + vc_dispmanx_display_close(display); + return -1; + } + + // Allocate 3 screen buffers (current, prior, delta) + screenbuf[0] = (uint16_t *)malloc(vinfo.xres * vinfo.yres * 2 * 3); + if(!screenbuf[0]) { + printf("malloc fail"); + return -1; + } + memset(screenbuf[0], 0, vinfo.xres * vinfo.yres * 2 * 2); + screenbuf[1] = &screenbuf[0][vinfo.xres * vinfo.yres]; + screenbuf[2] = &screenbuf[1][vinfo.xres * vinfo.yres]; + + fbp = (char*) mmap(0, finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); + if (fbp <= 0) { + syslog(LOG_ERR, "Unable to create mamory mapping"); + close(fbfd); + ret = vc_dispmanx_resource_delete(screen_resource); + vc_dispmanx_display_close(display); + return -1; + } + + vc_dispmanx_rect_set(&rect1, 0, 0, vinfo.xres, vinfo.yres); + + while (1) { + ret = vc_dispmanx_snapshot(display, screen_resource, 0); + // Transfer snamshot to screenbuf + vc_dispmanx_resource_read_data(screen_resource, &rect1, + (char *)screenbuf[bufNum], vinfo.xres * vinfo.bits_per_pixel / 8); + + +#if 0 + // Let's try a full-width copy (single memcpy operation) + memcpy( + (uint16_t *)&fbp[firstRow * vinfo.xres * 2], + &screenbuf[bufNum][firstRow * vinfo.xres], + vinfo.xres * (lastRow - firstRow + 1) * 2); +#else + + int bytes = (100) * 2; + uint16_t + *src = &screenbuf[bufNum][0], + *dst = (uint16_t *)&fbp[0]; + + for(int row=0; row < 100; row++) { + memcpy(dst, src, bytes); + src += vinfo.xres; + dst += vinfo.xres; + } +#endif + bufNum = 1 - bufNum; + } + usleep(1000000 / 30); // 30 fps max + } + + munmap(fbp, finfo.smem_len); + close(fbfd); + ret = vc_dispmanx_resource_delete(screen_resource); + vc_dispmanx_display_close(display); +} + int main(int argc, char **argv) { setlogmask(LOG_UPTO(LOG_DEBUG)); openlog("fbcp", LOG_NDELAY | LOG_PID, LOG_USER); //return process(); - return process_skip_rows(); +// return process_skip_rows(); //return process_interlaced(); + + return process_test(); }