Merge lp:~jibel/phablet-tools/lp1238839_phablet-screenshot into lp:phablet-tools

Proposed by Jean-Baptiste Lallement
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 227
Merged at revision: 230
Proposed branch: lp:~jibel/phablet-tools/lp1238839_phablet-screenshot
Merge into: lp:phablet-tools
Diff against target: 247 lines (+222/-0)
3 files modified
debian/control (+1/-0)
phablet-screenshot (+220/-0)
setup.py (+1/-0)
To merge this branch: bzr merge lp:~jibel/phablet-tools/lp1238839_phablet-screenshot
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Sergio Schvezov Approve
Ricardo Salveti (community) Approve
Alan Pope 🍺🐧🐱 πŸ¦„ test Pending
Review via email: mp+196823@code.launchpad.net

This proposal supersedes a proposal from 2013-11-09.

Commit message

Add script phablet-screenshot to take screenshots on devices running Mir.

Description of the change

Add script phablet-screenshot to take screenshot of devices running Mir as Mir doesn't have a screencap equivalent.
Screenshot is taken by dumping first frame of /dev/fb.

Known issues:
- Doesn't work on maguro (device freezes), this device is blacklisted
- On dual boot devices, the dump shows the boot screen not the active buffer.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote : Posted in a previous version of this proposal

imagemagick should be in debian/control

I can't really test this, as I have a maguro. So I've only tested the odd condition of unsupported.
The error message could be nicer though ./phablet-screenshot: 171: ./phablet-screenshot: SUPPORTED: parameter not set

SUPPORTED is not defined anywhere, which explains the wrong error message.

review: Needs Fixing
Revision history for this message
Ricardo Salveti (rsalveti) wrote : Posted in a previous version of this proposal

Jean, any news on this MR? Would be nice to get it merged soon, as it's quite useful for bug reporting.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
226. By Jean-Baptiste Lallement

* phablet-screenshot: Add support for screencap if surfaceflinger is running instead of Mir

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

40 +# TODO:
41 +# - detect that it is running Mir and fallback to screencap if it is SF
42 +

This TODO should be removed.

Tested on maguro and manta, does the right thing.

review: Needs Fixing
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Tested with mako (mir), works fine.

review: Approve
227. By Jean-Baptiste Lallement

* phablet-screenshot: Mir support is added, removed TODO

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2013-09-07 11:39:27 +0000
+++ debian/control 2013-11-28 06:00:08 +0000
@@ -40,6 +40,7 @@
40 ${misc:Depends},40 ${misc:Depends},
41 ${python:Depends},41 ${python:Depends},
42Recommends:42Recommends:
43 imagemagick,
43 ubuntu-dev-tools,44 ubuntu-dev-tools,
44Description: Scripts to work with Phablet.45Description: Scripts to work with Phablet.
45 Installs Touch Developer Preview on Nexus devices, specifically the following:46 Installs Touch Developer Preview on Nexus devices, specifically the following:
4647
=== added file 'phablet-screenshot'
--- phablet-screenshot 1970-01-01 00:00:00 +0000
+++ phablet-screenshot 2013-11-28 06:00:08 +0000
@@ -0,0 +1,220 @@
1#!/bin/sh
2
3#
4# Screen capture of Mir devices
5#
6
7# Copyright (C) 2013 Canonical
8#
9# Authors: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
10#
11# This program is free software; you can redistribute it and/or modify it #
12# under the terms of the GNU General Public License as published by the Free #
13# Software Foundation; version 3.
14#
15# This program is distributed in the hope that it will be useful, but WITHOUT
16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18# # details.
19#
20# You should have received a copy of the GNU General Public License along with
21# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22# Street, Fifth Floor, Boston, MA 02110-1301 USA
23set -eu
24
25PICDIR=$(mktemp -d /tmp/$(basename $0).XXXXXX)
26FBDEV=fb0
27ADBOPTS=""
28CONVERTOPTS="-alpha off"
29UNSUPPORTED="maguro"
30REQUIREDPKGS="android-tools-adb imagemagick"
31
32size=""
33
34cleanup() {
35 #
36 # Cleanup temporary files
37 #
38 [ -d "$PICDIR" ] && rm -Rf "$PICDIR"
39}
40trap cleanup EXIT INT QUIT ABRT PIPE TERM
41
42usage() {
43 #
44 # Print usage and exit
45 #
46 cat <<EOF
47Usage: $(basename $0) [OPTIONS...] <FILENAME>
48Dump /dev/$FBDEV from a touch device and write it to FILENAME
49
50Arguments:
51 FILENAME Name of the output image, the output format must be supported by
52 convert from the package imagemagick.
53Options
54 -d,--debug Enable debug
55 -h,--help This help
56 -s,--serial SERIAL
57 Serial number of the device
58 -r,--resolution GEOMETRY
59 Width and height of the image instead of default for device
60 (e.g 720x1280)
61 -z,--resize FACTOR
62 Resize the image
63
64EOF
65 exit 1
66}
67
68check_prerequisites() {
69 # Check list of required packages
70 okay=1
71 pkgs="$REQUIREDPKGS"
72 for pkg in $pkgs; do
73 if ! dpkg-query -W -f '${Status}\t${Package}\n' $pkg 2>/dev/null| grep "ok installed" >/dev/null 2>&1; then
74 okay=0
75 echo "E: Package '$pkg' is required and is not installed."
76 fi
77 done
78
79 if [ $okay -ne 1 ]; then
80 echo "E: pre-requisites are not met. Exiting!"
81 exit 1
82 fi
83}
84
85get_device() {
86 # Get device name
87 device=$(adb $ADBOPTS shell getprop ro.cm.device)
88 echo "$device"|tr -d '\r'
89}
90
91is_supported() {
92 # Returns 0 is a device is supported
93 if echo "$UNSUPPORTED"|grep -qw $1 >/dev/null 2>&1; then
94 return 1
95 else
96 return 0
97 fi
98}
99
100get_mode() {
101 # Find graphics mode
102 size=$(adb $ADBOPTS shell head -1 /sys/devices/virtual/graphics/$FBDEV/modes| cut -d: -f2|cut -d 'p' -f1)
103
104 # Fallback to hardcoded values
105 #if ! echo "$size"|grep -qE '^\[0-9\]+x\[0-9\]+$' >/dev/null 2>&1; then
106 if ! echo "$size"|grep -qE '^[0-9]+x[0-9]+$' >/dev/null 2>&1; then
107 device="$(get_device)"
108 case "$device" in
109 maguro)
110 size=720x1280
111 ;;
112 mako)
113 size=768x1280
114 ;;
115 manta)
116 size=1600x2560
117 ;;
118 grouper)
119 size=800x1280
120 ;;
121 *)
122 size=""
123 ;;
124 esac
125 fi
126 echo $size
127}
128
129sf_is_running() {
130 # Return 0 if surface flinger is running then we'll use screencap
131 # instead
132 sf=$(adb $ADBOPTS shell pidof surfaceflinger)
133 if [ -z "$sf" ]; then
134 return 1
135 else
136 echo "I: surfaceflinger detected"
137 return 0
138 fi
139}
140
141screenshot_mir() {
142 # Dump framebuffer to capture Mir screenshot
143 #
144 # Arguments:
145 # $1: Size
146 # $2: Depth
147 size=$1
148 depth=$2
149
150 CONVERTOPTS="$CONVERTOPTS -depth $depth -size $size"
151
152 echo "I: Dumping $FBDEV ..."
153 adb $ADBOPTS shell "kill -SIGSTOP \$(pidof unity8)"
154 adb $ADBOPTS pull /dev/$FBDEV ${PICDIR}/fb
155 adb $ADBOPTS shell "kill -SIGCONT \$(pidof unity8)"
156
157 [ ! -e "${PICDIR}/fb" ] && echo "E: Capture failed!" && return
158 convert $CONVERTOPTS rgba:${PICDIR}/fb[0] $DST
159}
160
161screenshot_sf() {
162 # Use screencap if surfaceflinger is running
163 echo "I: Capturing screenshot with screencap ..."
164 capfile=screencap.png
165 adb $ADBOPTS shell /system/bin/screencap /tmp/$capfile
166 adb $ADBOPTS pull /tmp/$capfile ${PICDIR}/$capfile
167
168 [ ! -e "${PICDIR}/${capfile}" ] && echo "E: Capture failed!" && return
169 convert $CONVERTOPTS ${PICDIR}/$capfile $DST
170}
171
172SHORTOPTS="hdr:s:z:"
173LONGOPTS="help,debug,resolution:,serial:,resize:"
174
175TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
176eval set -- "$TEMP"
177
178while true ; do
179 case "$1" in
180 -h|--help)
181 usage;;
182 -d|--debug)
183 set -x
184 shift;;
185 -r|--resolution)
186 size=$2
187 shift 2;;
188 -s|--serial)
189 ADBOPTS="$ADBOPTS -s $2"
190 shift 2;;
191 -z|--resize)
192 CONVERTOPTS="$CONVERTOPTS -resize $2"
193 shift 2;;
194 --) shift;
195 break;;
196 *) usage;;
197 esac
198done
199
200[ $# -eq 0 ] && usage
201DST=$1
202
203check_prerequisites
204
205if sf_is_running; then
206 # Use screencap for surfaceflinger
207 screenshot_sf
208else
209 # Otherwise just dump the framebuffer
210 # Set resolution and depth for device
211 depth=8
212 [ -z "$size" ] && size="$(get_mode)"
213 device="$(get_device)"
214 if [ -z "$size" ] || ! is_supported "$device"; then
215 echo "E: Device '$device' is not supported."
216 exit 1
217 fi
218 screenshot_mir "$size" "$depth"
219fi
220echo "I: Done"
0221
=== modified file 'setup.py'
--- setup.py 2013-09-23 01:43:32 +0000
+++ setup.py 2013-11-28 06:00:08 +0000
@@ -14,6 +14,7 @@
1414
15SH_SCRIPTS = [15SH_SCRIPTS = [
16 'phablet-network',16 'phablet-network',
17 'phablet-screenshot',
17 'phablet-test-run',18 'phablet-test-run',
18 ]19 ]
1920

Subscribers

People subscribed via source and target branches