summaryrefslogtreecommitdiffstats
path: root/cmds/screencap
diff options
context:
space:
mode:
authorDan Stoza <stoza@google.com>2015-06-09 16:47:33 -0700
committerDan Stoza <stoza@google.com>2015-06-09 16:53:11 -0700
commitcf70d71781a40d197c3ecde89351976b27eb9a8a (patch)
tree612a6015634d2da200703a1547fb0a6c45e22a61 /cmds/screencap
parente1f3214e72b63ed7cbe368005622055f80da0e0d (diff)
downloadframeworks_base-cf70d71781a40d197c3ecde89351976b27eb9a8a.zip
frameworks_base-cf70d71781a40d197c3ecde89351976b27eb9a8a.tar.gz
frameworks_base-cf70d71781a40d197c3ecde89351976b27eb9a8a.tar.bz2
screencap: Rotate images when display is rotated
Changes screencap to read the display rotation and use it when capturing the screenshot so that the output image is oriented correctly. Bug: 8433742 Change-Id: I0f7db422399985a1ff17da3faa946ff0943e58f7
Diffstat (limited to 'cmds/screencap')
-rw-r--r--cmds/screencap/screencap.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index dbc35af..c469ae4 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -30,6 +30,7 @@
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
+#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
// TODO: Fix Skia.
@@ -159,9 +160,35 @@ int main(int argc, char** argv)
uint32_t w, s, h, f;
size_t size = 0;
+ // Maps orientations from DisplayInfo to ISurfaceComposer
+ static const uint32_t ORIENTATION_MAP[] = {
+ ISurfaceComposer::eRotateNone, // 0 == DISPLAY_ORIENTATION_0
+ ISurfaceComposer::eRotate270, // 1 == DISPLAY_ORIENTATION_90
+ ISurfaceComposer::eRotate180, // 2 == DISPLAY_ORIENTATION_180
+ ISurfaceComposer::eRotate90, // 3 == DISPLAY_ORIENTATION_270
+ };
+
ScreenshotClient screenshot;
sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(displayId);
- if (display != NULL && screenshot.update(display, Rect(), false) == NO_ERROR) {
+ if (display == NULL) {
+ fprintf(stderr, "Unable to get handle for display %d\n", displayId);
+ return 1;
+ }
+
+ Vector<DisplayInfo> configs;
+ SurfaceComposerClient::getDisplayConfigs(display, &configs);
+ int activeConfig = SurfaceComposerClient::getActiveConfig(display);
+ if (static_cast<size_t>(activeConfig) >= configs.size()) {
+ fprintf(stderr, "Active config %d not inside configs (size %zu)\n",
+ activeConfig, configs.size());
+ return 1;
+ }
+ uint8_t displayOrientation = configs[activeConfig].orientation;
+ uint32_t captureOrientation = ORIENTATION_MAP[displayOrientation];
+
+ status_t result = screenshot.update(display, Rect(), 0, 0, 0, -1U,
+ false, captureOrientation);
+ if (result == NO_ERROR) {
base = screenshot.getPixels();
w = screenshot.getWidth();
h = screenshot.getHeight();