diff options
Diffstat (limited to 'adb/framebuffer_service.c')
-rw-r--r-- | adb/framebuffer_service.c | 149 |
1 files changed, 109 insertions, 40 deletions
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c index 2f45694..862dd91 100644 --- a/adb/framebuffer_service.c +++ b/adb/framebuffer_service.c @@ -51,56 +51,125 @@ struct fbinfo { void framebuffer_service(int fd, void *cookie) { - struct fb_var_screeninfo vinfo; - int fb, offset; - char x[256]; - struct fbinfo fbinfo; - unsigned i, bytespp; - - fb = open("/dev/graphics/fb0", O_RDONLY); - if(fb < 0) goto done; + unsigned int i; + char buf[640]; + int fd_screencap; + int w, h, f; + int fds[2]; + + if (pipe(fds) < 0) goto done; + + pid_t pid = fork(); + if (pid < 0) goto done; + + if (pid == 0) { + dup2(fds[1], STDOUT_FILENO); + close(fds[0]); + close(fds[1]); + const char* command = "screencap"; + const char *args[2] = {command, NULL}; + execvp(command, (char**)args); + exit(1); + } - if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done; - fcntl(fb, F_SETFD, FD_CLOEXEC); + fd_screencap = fds[0]; - bytespp = vinfo.bits_per_pixel / 8; + /* read w, h & format */ + if(readx(fd_screencap, &w, 4)) goto done; + if(readx(fd_screencap, &h, 4)) goto done; + if(readx(fd_screencap, &f, 4)) goto done; fbinfo.version = DDMS_RAWIMAGE_VERSION; - fbinfo.bpp = vinfo.bits_per_pixel; - fbinfo.size = vinfo.xres * vinfo.yres * bytespp; - fbinfo.width = vinfo.xres; - fbinfo.height = vinfo.yres; - fbinfo.red_offset = vinfo.red.offset; - fbinfo.red_length = vinfo.red.length; - fbinfo.green_offset = vinfo.green.offset; - fbinfo.green_length = vinfo.green.length; - fbinfo.blue_offset = vinfo.blue.offset; - fbinfo.blue_length = vinfo.blue.length; - fbinfo.alpha_offset = vinfo.transp.offset; - fbinfo.alpha_length = vinfo.transp.length; - - /* HACK: for several of our 3d cores a specific alignment - * is required so the start of the fb may not be an integer number of lines - * from the base. As a result we are storing the additional offset in - * xoffset. This is not the correct usage for xoffset, it should be added - * to each line, not just once at the beginning */ - offset = vinfo.xoffset * bytespp; - - offset += vinfo.xres * vinfo.yoffset * bytespp; + /* see hardware/hardware.h */ + switch (f) { + case 1: /* RGBA_8888 */ + fbinfo.bpp = 32; + fbinfo.size = w * h * 4; + fbinfo.width = w; + fbinfo.height = h; + fbinfo.red_offset = 0; + fbinfo.red_length = 8; + fbinfo.green_offset = 8; + fbinfo.green_length = 8; + fbinfo.blue_offset = 16; + fbinfo.blue_length = 8; + fbinfo.alpha_offset = 24; + fbinfo.alpha_length = 8; + break; + case 2: /* RGBX_8888 */ + fbinfo.bpp = 32; + fbinfo.size = w * h * 4; + fbinfo.width = w; + fbinfo.height = h; + fbinfo.red_offset = 0; + fbinfo.red_length = 8; + fbinfo.green_offset = 8; + fbinfo.green_length = 8; + fbinfo.blue_offset = 16; + fbinfo.blue_length = 8; + fbinfo.alpha_offset = 24; + fbinfo.alpha_length = 0; + break; + case 3: /* RGB_888 */ + fbinfo.bpp = 24; + fbinfo.size = w * h * 3; + fbinfo.width = w; + fbinfo.height = h; + fbinfo.red_offset = 0; + fbinfo.red_length = 8; + fbinfo.green_offset = 8; + fbinfo.green_length = 8; + fbinfo.blue_offset = 16; + fbinfo.blue_length = 8; + fbinfo.alpha_offset = 24; + fbinfo.alpha_length = 0; + break; + case 4: /* RGB_565 */ + fbinfo.bpp = 16; + fbinfo.size = w * h * 2; + fbinfo.width = w; + fbinfo.height = h; + fbinfo.red_offset = 11; + fbinfo.red_length = 5; + fbinfo.green_offset = 5; + fbinfo.green_length = 6; + fbinfo.blue_offset = 0; + fbinfo.blue_length = 5; + fbinfo.alpha_offset = 0; + fbinfo.alpha_length = 0; + break; + case 5: /* BGRA_8888 */ + fbinfo.bpp = 32; + fbinfo.size = w * h * 4; + fbinfo.width = w; + fbinfo.height = h; + fbinfo.red_offset = 16; + fbinfo.red_length = 8; + fbinfo.green_offset = 8; + fbinfo.green_length = 8; + fbinfo.blue_offset = 0; + fbinfo.blue_length = 8; + fbinfo.alpha_offset = 24; + fbinfo.alpha_length = 8; + break; + default: + goto done; + } + /* write header */ if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done; - lseek(fb, offset, SEEK_SET); - for(i = 0; i < fbinfo.size; i += 256) { - if(readx(fb, &x, 256)) goto done; - if(writex(fd, &x, 256)) goto done; + /* write data */ + for(i = 0; i < fbinfo.size; i += sizeof(buf)) { + if(readx(fd_screencap, buf, sizeof(buf))) goto done; + if(writex(fd, buf, sizeof(buf))) goto done; } - - if(readx(fb, &x, fbinfo.size % 256)) goto done; - if(writex(fd, &x, fbinfo.size % 256)) goto done; + if(readx(fd_screencap, buf, fbinfo.size % sizeof(buf))) goto done; + if(writex(fd, buf, fbinfo.size % sizeof(buf))) goto done; done: - if(fb >= 0) close(fb); + close(fds[0]); + close(fds[1]); close(fd); } |