1#!/usr/bin/python3 2 3import pykms 4import time 5import sys 6import argparse 7 8tests = { 9 1: "test_am5_trans_dest", 10 2: "test_am5_trans_src", 11 3: "test_am4_normal_trans_dst", 12 4: "test_am4_normal_trans_src", 13 5: "test_am4_alpha_trans_src", 14} 15 16parser = argparse.ArgumentParser() 17parser.add_argument("-c", "--connector", default="") 18parser.add_argument("test", type=int, help="test number 1-" + str(len(tests))) 19args = parser.parse_args() 20 21#if len(sys.argv) != 2: 22# print("Usage: {} <test-number>".format(sys.argv[0])) 23# print(" 1 - test_am5_trans_dest()") 24# print(" 2 - test_am5_trans_src()") 25# print(" 3 - test_am4_normal_trans_dst()") 26# print(" 4 - test_am4_normal_trans_src()") 27# print(" 5 - test_am4_alpha_trans_src()") 28# exit(0) 29 30TEST = args.test 31 32card = pykms.Card() 33res = pykms.ResourceManager(card) 34conn = res.reserve_connector(args.connector) 35crtc = res.reserve_crtc(conn) 36mode = conn.get_default_mode() 37 38planes = [] 39for p in card.planes: 40 if p.supports_crtc(crtc) == False: 41 continue 42 planes.append(p) 43 44card.disable_planes() 45 46w = mode.hdisplay 47h = mode.vdisplay 48 49fbs=[] 50 51# See Figure 11-78. DISPC Destination Transparency Color Key Example 52def test_am5_trans_dest(): 53 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 54 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 55 56 fb = fbs[0] 57 stepX = fb.width // 7 58 stepY = fb.height // 5; 59 60 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.purple) 61 pykms.draw_rect(fb, stepX, stepY, 62 stepX, fb.height - (stepY * 2), 63 pykms.green) 64 pykms.draw_rect(fb, stepX * 3, stepY, 65 stepX, fb.height - (stepY * 2), 66 pykms.red) 67 pykms.draw_rect(fb, stepX * 5, stepY, 68 stepX, fb.height - (stepY * 2), 69 pykms.white) 70 71 fb = fbs[1] 72 pykms.draw_rect(fb, 0, 0, 73 fb.width, fb.height, 74 pykms.cyan) 75 pykms.draw_circle(fb, (stepX * 3) + (stepX // 2), fb.height // 2, 76 (fb.height // 2) - stepY, 77 pykms.yellow) 78 79 crtc.set_props({ 80 "trans-key-mode": 1, 81 "trans-key": pykms.purple.rgb888, 82 "background": 0, 83 "alpha_blender": 0, 84 }) 85 86 print("Purple bg. Green, red, white boxes.") 87 88 plane = planes[0] 89 fb = fbs[0] 90 z = 0 91 92 plane.set_props({ 93 "FB_ID": fb.id, 94 "CRTC_ID": crtc.id, 95 "SRC_W": fb.width << 16, 96 "SRC_H": fb.height << 16, 97 "CRTC_W": fb.width, 98 "CRTC_H": fb.height, 99 "zpos": z, 100 }) 101 102 input("press enter\n") 103 104 print("Cyan bg. Green, red, white boxes. Yellow circle behind the red box.") 105 106 plane = planes[1] 107 fb = fbs[1] 108 z = 1 109 110 plane.set_props({ 111 "FB_ID": fb.id, 112 "CRTC_ID": crtc.id, 113 "SRC_W": fb.width << 16, 114 "SRC_H": fb.height << 16, 115 "CRTC_W": fb.width, 116 "CRTC_H": fb.height, 117 "zpos": z, 118 }) 119 120 input("press enter\n") 121 122# See Figure 11-77. DISPC Source Transparency Color Key Example 123def test_am5_trans_src(): 124 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 125 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 126 127 fb = fbs[0] 128 halfX = fb.width // 2 129 stepX = (fb.width // 2) // 5; 130 stepY = fb.height // 5; 131 132 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.white) 133 pykms.draw_rect(fb, stepX * 2, stepY * 2, 134 halfX - (stepX * 4), fb.height - (stepY * 4), 135 pykms.red) 136 pykms.draw_rect(fb, halfX + stepX * 2, stepY * 2, 137 halfX - (stepX * 4), fb.height - (stepY * 4), 138 pykms.green) 139 140 fb = fbs[1] 141 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.cyan) 142 pykms.draw_rect(fb, stepX, stepY, 143 fb.width - (stepX * 2), fb.height - (stepY * 2), 144 pykms.purple) 145 146 crtc.set_props({ 147 "trans-key-mode": 2, 148 "trans-key": pykms.purple.rgb888, 149 "background": 0, 150 "alpha_blender": 0, 151 }) 152 153 print("White bg. Red and green boxes.") 154 155 plane = planes[0] 156 fb = fbs[0] 157 z = 0 158 159 plane.set_props({ 160 "FB_ID": fb.id, 161 "CRTC_ID": crtc.id, 162 "SRC_W": fb.width << 16, 163 "SRC_H": fb.height << 16, 164 "CRTC_W": fb.width, 165 "CRTC_H": fb.height, 166 "zpos": z, 167 }) 168 169 input("press enter\n") 170 171 print("Cyan bg. Big white box, containing red and green boxes.") 172 173 plane = planes[1] 174 fb = fbs[1] 175 z = 3 176 177 plane.set_props({ 178 "FB_ID": fb.id, 179 "CRTC_ID": crtc.id, 180 "SRC_W": fb.width << 16, 181 "SRC_H": fb.height << 16, 182 "CRTC_W": fb.width, 183 "CRTC_H": fb.height, 184 "zpos": z, 185 }) 186 187 input("press enter\n") 188 189def test_am4_normal_trans_dst(): 190 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 191 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 192 193 fb = fbs[0] 194 stepX = fb.width // 7 195 stepY = fb.height // 5; 196 197 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.purple) 198 pykms.draw_rect(fb, stepX, stepY, 199 stepX, fb.height - (stepY * 2), 200 pykms.green) 201 pykms.draw_rect(fb, stepX * 3, stepY, 202 stepX, fb.height - (stepY * 2), 203 pykms.red) 204 pykms.draw_rect(fb, stepX * 5, stepY, 205 stepX, fb.height - (stepY * 2), 206 pykms.white) 207 208 fb = fbs[1] 209 pykms.draw_rect(fb, 0, 0, 210 fb.width, fb.height, 211 pykms.cyan) 212 pykms.draw_circle(fb, (stepX * 3) + (stepX // 2), fb.height // 2, 213 (fb.height // 2) - stepY, 214 pykms.yellow) 215 216 crtc.set_props({ 217 "trans-key-mode": 1, 218 "trans-key": pykms.purple.rgb888, 219 "background": 0, 220 "alpha_blender": 0, 221 }) 222 223 print("Purple bg. Green, red, white boxes.") 224 225 plane = planes[0] 226 fb = fbs[0] 227 z = 0 228 229 plane.set_props({ 230 "FB_ID": fb.id, 231 "CRTC_ID": crtc.id, 232 "SRC_W": fb.width << 16, 233 "SRC_H": fb.height << 16, 234 "CRTC_W": fb.width, 235 "CRTC_H": fb.height, 236 "zpos": z, 237 }) 238 239 input("press enter\n") 240 241 print("Cyan bg. Green, red, white boxes. Yellow circle behind the red box.") 242 243 plane = planes[1] 244 fb = fbs[1] 245 z = 1 246 247 plane.set_props({ 248 "FB_ID": fb.id, 249 "CRTC_ID": crtc.id, 250 "SRC_W": fb.width << 16, 251 "SRC_H": fb.height << 16, 252 "CRTC_W": fb.width, 253 "CRTC_H": fb.height, 254 "zpos": z, 255 }) 256 257 input("press enter\n") 258 259def test_am4_normal_trans_src(): 260 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 261 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 262 263 fb = fbs[0] 264 halfX = fb.width // 2 265 stepX = (fb.width // 2) // 5; 266 stepY = fb.height // 5; 267 268 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.white) 269 pykms.draw_rect(fb, stepX * 2, stepY * 2, 270 halfX - (stepX * 4), fb.height - (stepY * 4), 271 pykms.red) 272 pykms.draw_rect(fb, halfX + stepX * 2, stepY * 2, 273 halfX - (stepX * 4), fb.height - (stepY * 4), 274 pykms.green) 275 276 fb = fbs[1] 277 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.cyan) 278 pykms.draw_rect(fb, stepX, stepY, 279 fb.width - (stepX * 2), fb.height - (stepY * 2), 280 pykms.purple) 281 282 crtc.set_props({ 283 "trans-key-mode": 2, 284 "trans-key": pykms.purple.rgb888, 285 "background": 0, 286 "alpha_blender": 0, 287 }) 288 289 print("White bg. Red and green boxes.") 290 291 plane = planes[0] 292 fb = fbs[0] 293 z = 0 294 295 plane.set_props({ 296 "FB_ID": fb.id, 297 "CRTC_ID": crtc.id, 298 "SRC_W": fb.width << 16, 299 "SRC_H": fb.height << 16, 300 "CRTC_W": fb.width, 301 "CRTC_H": fb.height, 302 "zpos": z, 303 }) 304 305 input("press enter\n") 306 307 print("Cyan bg. Big white box, containing red and green boxes.") 308 309 plane = planes[1] 310 fb = fbs[1] 311 z = 2 312 313 plane.set_props({ 314 "FB_ID": fb.id, 315 "CRTC_ID": crtc.id, 316 "SRC_W": fb.width << 16, 317 "SRC_H": fb.height << 16, 318 "CRTC_W": fb.width, 319 "CRTC_H": fb.height, 320 "zpos": z, 321 }) 322 323 input("press enter\n") 324 325def test_am4_alpha_trans_src(): 326 fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24")) 327 fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24")) 328 fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24")) 329 330 fb = fbs[0] 331 halfX = fb.width // 2 332 stepX = (fb.width // 2) // 5; 333 stepY = fb.height // 5; 334 335 pykms.draw_rect(fb, 0, 0, w, h, pykms.purple) 336 pykms.draw_rect(fb, stepX * 2, stepY * 2, 337 halfX - (stepX * 4), fb.height - (stepY * 4), 338 pykms.red) 339 pykms.draw_rect(fb, halfX + stepX * 2, stepY * 2, 340 halfX - (stepX * 4), fb.height - (stepY * 4), 341 pykms.green) 342 343 fb = fbs[1] 344 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.blue) 345 pykms.draw_rect(fb, stepX, stepY, 346 fb.width - (stepX * 2), fb.height - (stepY * 2), 347 pykms.purple) 348 349 fb = fbs[2] 350 pykms.draw_rect(fb, 0, 0, fb.width, fb.height, pykms.cyan) 351 pykms.draw_rect(fb, stepX, stepY, 352 fb.width - (stepX * 2), fb.height - (stepY * 2), 353 pykms.purple) 354 355 crtc.set_props({ 356 "trans-key-mode": 1, 357 "trans-key": pykms.purple.rgb888, 358 "background": 0x666666, 359 "alpha_blender": 1, 360 }) 361 362 print("grey background") 363 input("press enter\n") 364 365 plane = planes[0] 366 fb = fbs[0] 367 plane.set_props({ 368 "FB_ID": fb.id, 369 "CRTC_ID": crtc.id, 370 "SRC_W": fb.width << 16, 371 "SRC_H": fb.height << 16, 372 "CRTC_W": w, 373 "CRTC_H": h, 374 }) 375 376 print("grey background, red and green boxes") 377 input("press enter\n") 378 379 plane = planes[1] 380 fb = fbs[1] 381 plane.set_props({ 382 "FB_ID": fb.id, 383 "CRTC_ID": crtc.id, 384 "SRC_X": 0 << 16, 385 "SRC_Y": 0 << 16, 386 "SRC_W": fb.width << 16, 387 "SRC_H": fb.height << 16, 388 "CRTC_X": 0, 389 "CRTC_Y": 0, 390 "CRTC_W": fb.width, 391 "CRTC_H": fb.height, 392 }) 393 394 print("left side: blue bg, purple box, red box inside purple. right side: unchanged") 395 input("press enter\n") 396 397 plane = planes[2] 398 fb = fbs[2] 399 plane.set_props({ 400 "FB_ID": fb.id, 401 "CRTC_ID": crtc.id, 402 "SRC_X": 0 << 16, 403 "SRC_Y": 0 << 16, 404 "SRC_W": fb.width << 16, 405 "SRC_H": fb.height << 16, 406 "CRTC_X": w - fb.width, 407 "CRTC_Y": 0, 408 "CRTC_W": fb.width, 409 "CRTC_H": fb.height, 410 }) 411 412 print("left side: unchanged. right side: cyan bg, purple box, green box inside purple.") 413 input("press enter\n") 414 415print(tests[args.test]) 416locals()[tests[args.test]]() 417