commit f88eecf79b766761374b5ad9b2ade3d32069f457 Author: Tasanakorn Phaipool Date: Tue Jul 16 19:54:36 2013 +0700 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4be3295 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build/ +/nbproject/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2b0ec30 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +SET(COMPILE_DEFINITIONS -Werror) + +include_directories(/opt/vc/include) + +link_directories(/opt/vc/lib) + +add_executable(fbcp main.c) + +target_link_libraries(fbcp bcm_host) diff --git a/main.c b/main.c new file mode 100644 index 0000000..3b3c65a --- /dev/null +++ b/main.c @@ -0,0 +1,95 @@ + +#include +#include +#include +#include +#include + +#include + +int process() { + 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; + + + 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) { + 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; + } + + 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); + vc_dispmanx_resource_read_data(screen_resource, &rect1, fbp, vinfo.xres * vinfo.bits_per_pixel / 8); + usleep(50 * 1000); + } + + 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(); +} + + +