• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2from subprocess import call
3import os
4proto_path = os.environ['ANDROID_BUILD_TOP'] + "/frameworks/native/cmds/surfacereplayer/proto/src/"
5call(["aprotoc", "-I=" + proto_path, "--python_out=.", proto_path + "trace.proto"])
6
7from trace_pb2 import *
8
9trace = Trace()
10
11def main():
12    global trace
13    while(1):
14        option = main_menu()
15
16        if option == 0:
17            break
18
19        increment = trace.increment.add()
20        increment.time_stamp  = int(input("Time stamp of action: "))
21
22        if option == 1:
23           transaction(increment)
24        elif option == 2:
25            surface_create(increment)
26        elif option == 3:
27            surface_delete(increment)
28        elif option == 4:
29            display_create(increment)
30        elif option == 5:
31            display_delete(increment)
32        elif option == 6:
33            buffer_update(increment)
34        elif option == 7:
35            vsync_event(increment)
36        elif option == 8:
37            power_mode_update(increment)
38
39    seralizeTrace()
40
41def seralizeTrace():
42    with open("trace.dat", 'wb') as f:
43        f.write(trace.SerializeToString())
44
45
46def main_menu():
47    print ("")
48    print ("What would you like to do?")
49    print ("1. Add transaction")
50    print ("2. Add surface creation")
51    print ("3. Add surface deletion")
52    print ("4. Add display creation")
53    print ("5. Add display deletion")
54    print ("6. Add buffer update")
55    print ("7. Add VSync event")
56    print ("8. Add power mode update")
57    print ("0. Finish and serialize")
58    print ("")
59
60    return int(input("> "))
61
62def transaction_menu():
63    print ("")
64    print ("What kind of transaction?")
65    print ("1. Position Change")
66    print ("2. Size Change")
67    print ("3. Alpha Change")
68    print ("4. Layer Change")
69    print ("5. Crop Change")
70    print ("6. Final Crop Change")
71    print ("7. Matrix Change")
72    print ("9. Transparent Region Hint Change")
73    print ("10. Layer Stack Change")
74    print ("11. Hidden Flag Change")
75    print ("12. Opaque Flag Change")
76    print ("13. Secure Flag Change")
77    print ("14. Deferred Transaction Change")
78    print ("15. Display - Surface Change")
79    print ("16. Display - Layer Stack Change")
80    print ("17. Display - Size Change")
81    print ("18. Display - Projection Change")
82    print ("0. Finished adding Changes to this transaction")
83    print ("")
84
85    return int(input("> "))
86
87def transaction(increment):
88    global trace
89
90    increment.transaction.synchronous \
91            = bool(input("Is transaction synchronous (True/False): "))
92    increment.transaction.animation \
93            = bool(input("Is transaction animated (True/False): "))
94
95    while(1):
96        option = transaction_menu()
97
98        if option == 0:
99            break
100
101        change = None
102        if option <= 14:
103            change = increment.transaction.surface_change.add()
104        elif option >= 15 and option <= 18:
105            change = increment.transaction.display_change.add()
106
107        change.id = int(input("ID of layer/display to undergo a change: "))
108
109        if option == 1:
110            change.position.x, change.position.y = position()
111        elif option == 2:
112            change.size.w, change.size.h = size()
113        elif option == 3:
114            change.alpha.alpha = alpha()
115        elif option == 4:
116            change.layer.layer = layer()
117        elif option == 5:
118            change.crop.rectangle.left,  change.crop.rectangle.top, \
119            change.crop.rectangle.right, change.crop.rectangle.bottom = crop()
120        elif option == 6:
121            change.final_crop.rectangle.left, \
122            change.final_crop.rectangle.top,  \
123            change.final_crop.rectangle.right,\
124            change.final_crop.rectangle.bottom = final_crop()
125        elif option == 7:
126            change.matrix.dsdx,\
127            change.matrix.dtdx,\
128            change.matrix.dsdy,\
129            change.matrix.dtdy = layer()
130        elif option == 9:
131            for rect in transparent_region_hint():
132                new = increment.transparent_region_hint.region.add()
133                new.left = rect[0]
134                new.top = rect[1]
135                new.right = rect[2]
136                new.bottom = rect[3]
137        elif option == 10:
138            change.layer_stack.layer_stack = layer_stack()
139        elif option == 11:
140            change.hidden_flag.hidden_flag = hidden_flag()
141        elif option == 12:
142            change.opaque_flag.opaque_flag = opaque_flag()
143        elif option == 13:
144            change.secure_flag.secure_flag = secure_flag()
145        elif option == 14:
146            change.deferred_transaction.layer_id, \
147            change.deferred_transaction.frame_number = deferred_transaction()
148        elif option == 15:
149            change.surface.buffer_queue_id, \
150            change.surface.buffer_queue_name = surface()
151        elif option == 16:
152            change.layer_stack.layer_stack = layer_stack()
153        elif option == 17:
154            change.size.w, change.size.h = size()
155        elif option == 18:
156            projection(change)
157
158def surface_create(increment):
159    increment.surface_creation.id = int(input("Enter id: "))
160    n = str(raw_input("Enter name: "))
161    increment.surface_creation.name = n
162    increment.surface_creation.w = input("Enter w: ")
163    increment.surface_creation.h = input("Enter h: ")
164
165def surface_delete(increment):
166    increment.surface_deletion.id = int(input("Enter id: "))
167
168def display_create(increment):
169    increment.display_creation.id = int(input("Enter id: "))
170    increment.display_creation.name = str(raw_input("Enter name: "))
171    increment.display_creation.display_id = int(input("Enter display ID: "))
172    increment.display_creation.is_secure = bool(input("Enter if secure: "))
173
174def display_delete(increment):
175    increment.surface_deletion.id = int(input("Enter id: "))
176
177def buffer_update(increment):
178    increment.buffer_update.id = int(input("Enter id: "))
179    increment.buffer_update.w = int(input("Enter w: "))
180    increment.buffer_update.h = int(input("Enter h: "))
181    increment.buffer_update.frame_number = int(input("Enter frame_number: "))
182
183def vsync_event(increment):
184    increment.vsync_event.when = int(input("Enter when: "))
185
186def power_mode_update(increment):
187    increment.power_mode_update.id = int(input("Enter id: "))
188    increment.power_mode_update.mode = int(input("Enter mode: "))
189
190def position():
191    x = input("Enter x: ")
192    y = input("Enter y: ")
193
194    return float(x), float(y)
195
196def size():
197    w = input("Enter w: ")
198    h = input("Enter h: ")
199
200    return int(w), int(h)
201
202def alpha():
203    alpha = input("Enter alpha: ")
204
205    return float(alpha)
206
207def layer():
208    layer = input("Enter layer: ")
209
210    return int(layer)
211
212def crop():
213    return rectangle()
214
215def final_crop():
216    return rectangle()
217
218def matrix():
219    dsdx = input("Enter dsdx: ")
220    dtdx = input("Enter dtdx: ")
221    dsdy = input("Enter dsdy: ")
222    dtdy = input("Enter dtdy: ")
223
224    return float(dsdx)
225
226def transparent_region_hint():
227    num = input("Enter number of rectangles in region: ")
228
229    return [rectangle() in range(x)]
230
231def layer_stack():
232    layer_stack = input("Enter layer stack: ")
233
234    return int(layer_stack)
235
236def hidden_flag():
237    flag = input("Enter hidden flag state (True/False): ")
238
239    return bool(flag)
240
241def opaque_flag():
242    flag = input("Enter opaque flag state (True/False): ")
243
244    return bool(flag)
245
246def secure_flag():
247    flag = input("Enter secure flag state (True/False): ")
248
249    return bool(flag)
250
251def deferred_transaction():
252    layer_id = input("Enter layer_id: ")
253    frame_number = input("Enter frame_number: ")
254
255    return int(layer_id), int(frame_number)
256
257def surface():
258    id = input("Enter id: ")
259    name = raw_input("Enter name: ")
260
261    return int(id), str(name)
262
263def projection(change):
264    change.projection.orientation = input("Enter orientation: ")
265    print("Enter rectangle for viewport")
266    change.projection.viewport.left, \
267    change.projection.viewport.top,  \
268    change.projection.viewport.right,\
269    change.projection.viewport.bottom = rectangle()
270    print("Enter rectangle for frame")
271    change.projection.frame.left, \
272    change.projection.frame.top,  \
273    change.projection.frame.right,\
274    change.projection.frame.bottom = rectangle()
275
276def rectangle():
277    left = input("Enter left: ")
278    top = input("Enter top: ")
279    right = input("Enter right: ")
280    bottom = input("Enter bottom: ")
281
282    return int(left), int(top), int(right), int(bottom)
283
284if __name__ == "__main__":
285    main()
286