summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-09-26 18:44:28 -0700
committerMathias Agopian <mathias@google.com>2010-09-26 18:44:28 -0700
commit0715f91223b2f7a91ea08bfa95998d846e7977cf (patch)
treeca2694380560f86400097836c28a6d76845ea391
parentb32007c54b9a8b6670e78a42eb9f8b0a21ed9559 (diff)
downloadsystem_core-0715f91223b2f7a91ea08bfa95998d846e7977cf.zip
system_core-0715f91223b2f7a91ea08bfa95998d846e7977cf.tar.gz
system_core-0715f91223b2f7a91ea08bfa95998d846e7977cf.tar.bz2
update adbd to use the new screencap command for taking screenshots.
Change-Id: I02c49240f9db9258824020f3f5f04463e17a537a
-rw-r--r--adb/framebuffer_service.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c
index 2f45694..434eb1c 100644
--- a/adb/framebuffer_service.c
+++ b/adb/framebuffer_service.c
@@ -51,56 +51,63 @@ 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;
+ /* for now always assume RGBX_8888 format */
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;
-
+ 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;
+
+ /* 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);
}