From f1a098203be8c44a52ed5d2a72982a3f634d4df6 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 2 Jan 2017 16:42:09 +0200 Subject: py: Move helpers to the pykms module Instead of forcing applications to import the helpers manually, move them to pykms by turning it into a python module. Signed-off-by: Laurent Pinchart --- py/pykms/CMakeLists.txt | 8 +++++-- py/pykms/__init__.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ py/tests/alpha-test.py | 7 +++--- py/tests/cam.py | 4 +--- py/tests/db.py | 1 - py/tests/functest.py | 1 - py/tests/gamma.py | 5 ++--- py/tests/helpers.py | 54 -------------------------------------------- py/tests/iact.py | 1 - py/tests/test.py | 1 - py/tests/trans-test.py | 35 ++++++++++++++--------------- 11 files changed, 89 insertions(+), 88 deletions(-) create mode 100644 py/pykms/__init__.py delete mode 100644 py/tests/helpers.py (limited to 'py') diff --git a/py/pykms/CMakeLists.txt b/py/pykms/CMakeLists.txt index 3e6e0e1..a671b7a 100644 --- a/py/pykms/CMakeLists.txt +++ b/py/pykms/CMakeLists.txt @@ -21,6 +21,10 @@ target_link_libraries(pykms kms++ kms++util ${LIBDRM_LIBRARIES}) # Don't add a 'lib' prefix to the shared library set_target_properties(pykms PROPERTIES PREFIX "") +set_target_properties(pykms PROPERTIES LIBRARY_OUTPUT_DIRECTORY "") -# XXX Where should pykms.so be installed? -#install(TARGETS pykms DESTINATION lib) +configure_file(__init__.py __init__.py COPYONLY) + +set(PY_DESTDIR lib/python${PYTHON_VERSION}/site-packages/pykms) +install(FILES __init__.py DESTINATION ${PY_DESTDIR}) +install(TARGETS pykms DESTINATION ${PY_DESTDIR}) diff --git a/py/pykms/__init__.py b/py/pykms/__init__.py new file mode 100644 index 0000000..d4cdc43 --- /dev/null +++ b/py/pykms/__init__.py @@ -0,0 +1,60 @@ +from .pykms import * + +# +# Common RGB colours +# + +red = RGB(255, 0, 0) +green = RGB(0, 255, 0) +blue = RGB(0, 0, 255) +yellow = RGB(255, 255, 0) +purple = RGB(255, 0, 255) +white = RGB(255, 255, 255) +cyan = RGB(0, 255, 255) + +# +# DrmObject API extensions +# + +def __obj_set_prop(self, prop, value): + if self.card.has_atomic: + areq = AtomicReq(self.card) + areq.add(self, prop, value) + if areq.commit_sync() != 0: + print("commit failed") + else: + if self.set_prop_value(prop, value) != 0: + print("setting property failed") + +def __obj_set_props(self, map): + if self.card.has_atomic: + areq = AtomicReq(self.card) + + for key, value in map.items(): + areq.add(self, key, value) + + if areq.commit_sync() != 0: + print("commit failed") + else: + for propid,propval in map.items(): + if self.set_prop_value(propid, propval) != 0: + print("setting property failed") + +DrmObject.set_prop = __obj_set_prop +DrmObject.set_props = __obj_set_props + +# +# Card API extensions +# + +def __card_disable_planes(self): + areq = AtomicReq(self) + + for p in self.planes: + areq.add(p, "FB_ID", 0) + areq.add(p, "CRTC_ID", 0) + + if areq.commit_sync() != 0: + print("disabling planes failed") + +Card.disable_planes = __card_disable_planes diff --git a/py/tests/alpha-test.py b/py/tests/alpha-test.py index c6ec8ee..5873612 100755 --- a/py/tests/alpha-test.py +++ b/py/tests/alpha-test.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import pykms -from helpers import * import time # This hack makes drm initialize the fbcon, setting up the default connector @@ -24,7 +23,7 @@ if len(planes) != 3: print("Need 3 planes!") exit(1) -disable_planes(card) +card.disable_planes() w = mode.hdisplay h = mode.vdisplay @@ -39,7 +38,7 @@ pykms.draw_rect(fbs[1], 150, 50, 200, 200, pykms.RGB(128, 0, 255, 0)) pykms.draw_rect(fbs[2], 50, 150, 200, 200, pykms.RGB(128, 0, 0, 255)) -set_props(crtc, { +crtc.set_props({ "trans-key-mode": 0, "trans-key": 0, "background": 0, @@ -52,7 +51,7 @@ for i in range(len(planes)): print("set crtc {}, plane {}, fb {}".format(crtc.id, p.id, fbs[i].id)) - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, diff --git a/py/tests/cam.py b/py/tests/cam.py index b44f8f9..57d0c1a 100755 --- a/py/tests/cam.py +++ b/py/tests/cam.py @@ -3,8 +3,6 @@ import sys import selectors import pykms -from helpers import * - w = 640 h = 480 @@ -48,7 +46,7 @@ def readvid(conn, mask): fb = cap.dequeue() if card.has_atomic: - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, diff --git a/py/tests/db.py b/py/tests/db.py index 3ffb716..772b4fc 100755 --- a/py/tests/db.py +++ b/py/tests/db.py @@ -3,7 +3,6 @@ import sys import pykms import selectors -from helpers import * bar_width = 20 bar_speed = 8 diff --git a/py/tests/functest.py b/py/tests/functest.py index 44c29fb..836b880 100755 --- a/py/tests/functest.py +++ b/py/tests/functest.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import pykms -from helpers import * card = pykms.Card() res = pykms.ResourceManager(card) diff --git a/py/tests/gamma.py b/py/tests/gamma.py index a6b68cc..5969b82 100755 --- a/py/tests/gamma.py +++ b/py/tests/gamma.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import pykms -from helpers import * # This hack makes drm initialize the fbcon, setting up the default connector card = pykms.Card() @@ -32,10 +31,10 @@ for i in range(len): gamma = pykms.Blob(card, arr); -set_prop(crtc, "GAMMA_LUT", gamma.id) +crtc.set_prop("GAMMA_LUT", gamma.id) input("press enter to remove gamma\n") -set_prop(crtc, "GAMMA_LUT", 0) +crtc.set_prop("GAMMA_LUT", 0) input("press enter to exit\n") diff --git a/py/tests/helpers.py b/py/tests/helpers.py deleted file mode 100644 index fd67d41..0000000 --- a/py/tests/helpers.py +++ /dev/null @@ -1,54 +0,0 @@ -import pykms - -def add_props(areq, ob, map): - for key, value in map.items(): - areq.add(ob, key, value) - -def props(o): - o.refresh_props() - map = o.prop_map - for propid,propval in map.items(): - prop = o.card.get_prop(propid) - print("%-15s %d (%#x)" % (prop.name, propval, propval)) - -def set_prop(ob, prop, value): - if ob.card.has_atomic: - areq = pykms.AtomicReq(ob.card) - areq.add(ob, prop, value) - if areq.commit_sync() != 0: - print("commit failed") - else: - if ob.set_prop_value(prop, value) != 0: - print("setting property failed") - -def set_props(ob, map): - if ob.card.has_atomic: - areq = pykms.AtomicReq(ob.card) - - for key, value in map.items(): - areq.add(ob, key, value) - - if areq.commit_sync() != 0: - print("commit failed") - else: - for propid,propval in map.items(): - if ob.set_prop_value(propid, propval) != 0: - print("setting property failed") - -red = pykms.RGB(255, 0, 0) -green = pykms.RGB(0, 255, 0) -blue = pykms.RGB(0, 0, 255) -yellow = pykms.RGB(255, 255, 0) -purple = pykms.RGB(255, 0, 255) -white = pykms.RGB(255, 255, 255) -cyan = pykms.RGB(0, 255, 255) - -def disable_planes(card): - areq = pykms.AtomicReq(card) - - for p in card.planes: - areq.add(p, "FB_ID", 0) - areq.add(p, "CRTC_ID", 0) - - if areq.commit_sync() != 0: - print("disabling planes failed") diff --git a/py/tests/iact.py b/py/tests/iact.py index fecd899..721e558 100755 --- a/py/tests/iact.py +++ b/py/tests/iact.py @@ -6,7 +6,6 @@ import pykms from time import sleep from math import sin from math import cos -from helpers import * card = pykms.Card() res = pykms.ResourceManager(card) diff --git a/py/tests/test.py b/py/tests/test.py index 9c23b5b..de00a43 100755 --- a/py/tests/test.py +++ b/py/tests/test.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import pykms -from helpers import * card = pykms.Card() res = pykms.ResourceManager(card) diff --git a/py/tests/trans-test.py b/py/tests/trans-test.py index 8c1f964..c2d08c1 100755 --- a/py/tests/trans-test.py +++ b/py/tests/trans-test.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import pykms -from helpers import * import time # This hack makes drm initialize the fbcon, setting up the default connector @@ -20,7 +19,7 @@ for p in card.planes: continue planes.append(p) -disable_planes(card) +card.disable_planes() w = mode.hdisplay h = mode.vdisplay @@ -41,7 +40,7 @@ def test_am5_trans_dest(): pykms.draw_rect(fb, 0, 0, fb.width, fb.height, cyan) pykms.draw_rect(fb, 250, 100, 200, 200, yellow) - set_props(crtc, { + crtc.set_props({ "trans-key-mode": 1, "trans-key": purple.rgb888, "background": 0, @@ -55,7 +54,7 @@ def test_am5_trans_dest(): plane = planes[i] fb = fbs[i] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, @@ -80,7 +79,7 @@ def test_am5_trans_src(): pykms.draw_rect(fb, 0, 0, fb.width, fb.height, cyan) pykms.draw_rect(fb, 100, 100, 500, 500, purple) - set_props(crtc, { + crtc.set_props({ "trans-key-mode": 2, "trans-key": purple.rgb888, "background": 0, @@ -94,7 +93,7 @@ def test_am5_trans_src(): plane = planes[i] fb = fbs[i] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, @@ -123,7 +122,7 @@ def test_am4_normal_trans_dst(): fb = fbs[2] pykms.draw_rect(fb, 0, 0, fb.width, fb.height, cyan) - set_props(crtc, { + crtc.set_props({ "trans-key-mode": 1, "trans-key": purple.rgb888, "background": 0, @@ -134,7 +133,7 @@ def test_am4_normal_trans_dst(): plane = planes[0] fb = fbs[0] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, @@ -147,7 +146,7 @@ def test_am4_normal_trans_dst(): plane = planes[1] fb = fbs[1] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, @@ -164,7 +163,7 @@ def test_am4_normal_trans_dst(): plane = planes[2] fb = fbs[2] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, @@ -195,7 +194,7 @@ def test_am4_normal_trans_src(): pykms.draw_rect(fb, 0, 0, fb.width, fb.height, cyan) pykms.draw_rect(fb, 100, 100, fb.width - 200, fb.height - 200, purple) - set_props(crtc, { + crtc.set_props({ "trans-key-mode": 2, "trans-key": purple.rgb888, "background": 0, @@ -206,7 +205,7 @@ def test_am4_normal_trans_src(): plane = planes[0] fb = fbs[0] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, @@ -219,7 +218,7 @@ def test_am4_normal_trans_src(): plane = planes[1] fb = fbs[1] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, @@ -236,7 +235,7 @@ def test_am4_normal_trans_src(): plane = planes[2] fb = fbs[2] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, @@ -267,7 +266,7 @@ def test_am4_alpha_trans_src(): pykms.draw_rect(fb, 0, 0, fb.width, fb.height, cyan) pykms.draw_rect(fb, 100, 100, fb.width - 200, fb.height - 200, purple) - set_props(crtc, { + crtc.set_props({ "trans-key-mode": 1, "trans-key": purple.rgb888, "background": 0, @@ -278,7 +277,7 @@ def test_am4_alpha_trans_src(): plane = planes[0] fb = fbs[0] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_W": fb.width << 16, @@ -291,7 +290,7 @@ def test_am4_alpha_trans_src(): plane = planes[1] fb = fbs[1] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, @@ -308,7 +307,7 @@ def test_am4_alpha_trans_src(): plane = planes[2] fb = fbs[2] - set_props(plane, { + plane.set_props({ "FB_ID": fb.id, "CRTC_ID": crtc.id, "SRC_X": 0 << 16, -- cgit v1.2.3