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

Subscribers

People subscribed via source and target branches