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
This commit is contained in:
Mathias Agopian
2013-03-20 15:38:07 -07:00
parent 3be79f328a
commit 0137fb8937

View File

@@ -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);