summaryrefslogtreecommitdiffstats
path: root/cmds/screencap
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2013-03-20 15:38:07 -0700
committerMathias Agopian <mathias@google.com>2013-03-20 15:40:45 -0700
commit0137fb8937e69ed41cff3bf8cb0c1fea43daa3b5 (patch)
treef891875e2b13707ea34b925414a75c25f34a0e79 /cmds/screencap
parent3be79f328a9b8817859679d6c39a509e897db845 (diff)
downloadframeworks_base-0137fb8937e69ed41cff3bf8cb0c1fea43daa3b5.zip
frameworks_base-0137fb8937e69ed41cff3bf8cb0c1fea43daa3b5.tar.gz
frameworks_base-0137fb8937e69ed41cff3bf8cb0c1fea43daa3b5.tar.bz2
make sure screencap's data stream matches what adb expects
adb assumes the stride is always equal to the width, so we make sure it's actually the case (screenshot don't always have this guarantee). Change-Id: I643b909f6542b7493a611afc6e3c86955b984352
Diffstat (limited to 'cmds/screencap')
-rw-r--r--cmds/screencap/screencap.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index d196392..e1270af 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -28,6 +28,8 @@
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
+#include <ui/PixelFormat.h>
+
#include <SkImageEncoder.h>
#include <SkBitmap.h>
#include <SkData.h>
@@ -138,7 +140,7 @@ int main(int argc, char** argv)
ssize_t mapsize = -1;
void const* base = 0;
- uint32_t w, h, f;
+ uint32_t w, s, h, f;
size_t size = 0;
ScreenshotClient screenshot;
@@ -147,6 +149,7 @@ int main(int argc, char** argv)
base = screenshot.getPixels();
w = screenshot.getWidth();
h = screenshot.getHeight();
+ s = screenshot.getStride();
f = screenshot.getFormat();
size = screenshot.getSize();
} else {
@@ -160,6 +163,7 @@ int main(int argc, char** argv)
size_t offset = (vinfo.xoffset + vinfo.yoffset*vinfo.xres) * bytespp;
w = vinfo.xres;
h = vinfo.yres;
+ s = vinfo.xres;
size = w*h*bytespp;
mapsize = offset + size;
mapbase = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, fb, 0);
@@ -187,7 +191,11 @@ int main(int argc, char** argv)
write(fd, &w, 4);
write(fd, &h, 4);
write(fd, &f, 4);
- write(fd, base, size);
+ size_t Bpp = bytesPerPixel(f);
+ for (size_t y=0 ; y<h ; y++) {
+ write(fd, base, w*Bpp);
+ base = (void *)((char *)base + s*Bpp);
+ }
}
}
close(fd);