trace_creator.py revision 834003e756cd6dffcae70648067b8fccc648e5af
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 ("8. Override Scaling Mode Change") 73 print ("9. Transparent Region Hint Change") 74 print ("10. Layer Stack Change") 75 print ("11. Hidden Flag Change") 76 print ("12. Opaque Flag Change") 77 print ("13. Secure Flag Change") 78 print ("14. Deferred Transaction Change") 79 print ("15. Display - Surface Change") 80 print ("16. Display - Layer Stack Change") 81 print ("17. Display - Size Change") 82 print ("18. Display - Projection Change") 83 print ("0. Finished adding Changes to this transaction") 84 print ("") 85 86 return int(input("> ")) 87 88def transaction(increment): 89 global trace 90 91 increment.transaction.synchronous \ 92 = bool(input("Is transaction synchronous (True/False): ")) 93 increment.transaction.animation \ 94 = bool(input("Is transaction animated (True/False): ")) 95 96 while(1): 97 option = transaction_menu() 98 99 if option == 0: 100 break 101 102 change = None 103 if option <= 14: 104 change = increment.transaction.surface_change.add() 105 elif option >= 15 and option <= 18: 106 change = increment.transaction.display_change.add() 107 108 change.id = int(input("ID of layer/display to undergo a change: ")) 109 110 if option == 1: 111 change.position.x, change.position.y = position() 112 elif option == 2: 113 change.size.w, change.size.h = size() 114 elif option == 3: 115 change.alpha.alpha = alpha() 116 elif option == 4: 117 change.layer.layer = layer() 118 elif option == 5: 119 change.crop.rectangle.left, change.crop.rectangle.top, \ 120 change.crop.rectangle.right, change.crop.rectangle.bottom = crop() 121 elif option == 6: 122 change.final_crop.rectangle.left, \ 123 change.final_crop.rectangle.top, \ 124 change.final_crop.rectangle.right,\ 125 change.final_crop.rectangle.bottom = final_crop() 126 elif option == 7: 127 change.matrix.dsdx,\ 128 change.matrix.dtdx,\ 129 change.matrix.dsdy,\ 130 change.matrix.dtdy = layer() 131 elif option == 8: 132 change.override_scaling_mode.override_scaling_mode \ 133 = override_scaling_mode() 134 elif option == 9: 135 for rect in transparent_region_hint(): 136 new = increment.transparent_region_hint.region.add() 137 new.left = rect[0] 138 new.top = rect[1] 139 new.right = rect[2] 140 new.bottom = rect[3] 141 elif option == 10: 142 change.layer_stack.layer_stack = layer_stack() 143 elif option == 11: 144 change.hidden_flag.hidden_flag = hidden_flag() 145 elif option == 12: 146 change.opaque_flag.opaque_flag = opaque_flag() 147 elif option == 13: 148 change.secure_flag.secure_flag = secure_flag() 149 elif option == 14: 150 change.deferred_transaction.layer_id, \ 151 change.deferred_transaction.frame_number = deferred_transaction() 152 elif option == 15: 153 change.surface.buffer_queue_id, \ 154 change.surface.buffer_queue_name = surface() 155 elif option == 16: 156 change.layer_stack.layer_stack = layer_stack() 157 elif option == 17: 158 change.size.w, change.size.h = size() 159 elif option == 18: 160 projection(change) 161 162def surface_create(increment): 163 increment.surface_creation.id = int(input("Enter id: ")) 164 n = str(raw_input("Enter name: ")) 165 increment.surface_creation.name = n 166 increment.surface_creation.w = input("Enter w: ") 167 increment.surface_creation.h = input("Enter h: ") 168 169def surface_delete(increment): 170 increment.surface_deletion.id = int(input("Enter id: ")) 171 172def display_create(increment): 173 increment.display_creation.id = int(input("Enter id: ")) 174 increment.display_creation.name = str(raw_input("Enter name: ")) 175 increment.display_creation.type = int(input("Enter type: ")) 176 increment.display_creation.is_secure = bool(input("Enter if secure: ")) 177 178def display_delete(increment): 179 increment.surface_deletion.id = int(input("Enter id: ")) 180 181def buffer_update(increment): 182 increment.buffer_update.id = int(input("Enter id: ")) 183 increment.buffer_update.w = int(input("Enter w: ")) 184 increment.buffer_update.h = int(input("Enter h: ")) 185 increment.buffer_update.frame_number = int(input("Enter frame_number: ")) 186 187def vsync_event(increment): 188 increment.vsync_event.when = int(input("Enter when: ")) 189 190def power_mode_update(increment): 191 increment.power_mode_update.id = int(input("Enter id: ")) 192 increment.power_mode_update.mode = int(input("Enter mode: ")) 193 194def position(): 195 x = input("Enter x: ") 196 y = input("Enter y: ") 197 198 return float(x), float(y) 199 200def size(): 201 w = input("Enter w: ") 202 h = input("Enter h: ") 203 204 return int(w), int(h) 205 206def alpha(): 207 alpha = input("Enter alpha: ") 208 209 return float(alpha) 210 211def layer(): 212 layer = input("Enter layer: ") 213 214 return int(layer) 215 216def crop(): 217 return rectangle() 218 219def final_crop(): 220 return rectangle() 221 222def matrix(): 223 dsdx = input("Enter dsdx: ") 224 dtdx = input("Enter dtdx: ") 225 dsdy = input("Enter dsdy: ") 226 dtdy = input("Enter dtdy: ") 227 228 return float(dsdx) 229 230def override_scaling_mode(): 231 mode = input("Enter override scaling mode: ") 232 233 return int(mode) 234 235def transparent_region_hint(): 236 num = input("Enter number of rectangles in region: ") 237 238 return [rectangle() in range(x)] 239 240def layer_stack(): 241 layer_stack = input("Enter layer stack: ") 242 243 return int(layer_stack) 244 245def hidden_flag(): 246 flag = input("Enter hidden flag state (True/False): ") 247 248 return bool(flag) 249 250def opaque_flag(): 251 flag = input("Enter opaque flag state (True/False): ") 252 253 return bool(flag) 254 255def secure_flag(): 256 flag = input("Enter secure flag state (True/False): ") 257 258 return bool(flag) 259 260def deferred_transaction(): 261 layer_id = input("Enter layer_id: ") 262 frame_number = input("Enter frame_number: ") 263 264 return int(layer_id), int(frame_number) 265 266def surface(): 267 id = input("Enter id: ") 268 name = raw_input("Enter name: ") 269 270 return int(id), str(name) 271 272def projection(change): 273 change.projection.orientation = input("Enter orientation: ") 274 print("Enter rectangle for viewport") 275 change.projection.viewport.left, \ 276 change.projection.viewport.top, \ 277 change.projection.viewport.right,\ 278 change.projection.viewport.bottom = rectangle() 279 print("Enter rectangle for frame") 280 change.projection.frame.left, \ 281 change.projection.frame.top, \ 282 change.projection.frame.right,\ 283 change.projection.frame.bottom = rectangle() 284 285def rectangle(): 286 left = input("Enter left: ") 287 top = input("Enter top: ") 288 right = input("Enter right: ") 289 bottom = input("Enter bottom: ") 290 291 return int(left), int(top), int(right), int(bottom) 292 293if __name__ == "__main__": 294 main() 295