summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b11baff)
raw | patch | inline | side by side (parent: b11baff)
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | |
Mon, 2 Jan 2017 14:42:09 +0000 (16:42 +0200) | ||
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | |
Tue, 3 Jan 2017 08:46:42 +0000 (10:46 +0200) |
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 <laurent.pinchart@ideasonboard.com>
them to pykms by turning it into a python module.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
py/pykms/CMakeLists.txt | patch | blob | history | |
py/pykms/__init__.py | [new file with mode: 0644] | patch | blob |
py/tests/alpha-test.py | patch | blob | history | |
py/tests/cam.py | patch | blob | history | |
py/tests/db.py | patch | blob | history | |
py/tests/functest.py | patch | blob | history | |
py/tests/gamma.py | patch | blob | history | |
py/tests/helpers.py | [deleted file] | patch | blob | history |
py/tests/iact.py | patch | blob | history | |
py/tests/test.py | patch | blob | history | |
py/tests/trans-test.py | patch | blob | history |
index 3e6e0e1f6cea8358bcfc4b9958b2b878e9c7eb42..a671b7a5fafe5625bd1ba4d12fc5e1d96d22306b 100644 (file)
--- a/py/pykms/CMakeLists.txt
+++ b/py/pykms/CMakeLists.txt
# 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
--- /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 c6ec8ee0eae8f4e5476992bf62e44d650b97ac44..5873612cc31006e209b100ca50ee9a1e66df6347 100755 (executable)
--- a/py/tests/alpha-test.py
+++ b/py/tests/alpha-test.py
#!/usr/bin/python3
import pykms
-from helpers import *
import time
# This hack makes drm initialize the fbcon, setting up the default connector
print("Need 3 planes!")
exit(1)
-disable_planes(card)
+card.disable_planes()
w = mode.hdisplay
h = mode.vdisplay
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,
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 b44f8f9cece674dc038ad5c8f184c4a2ee845288..57d0c1a502a0f801cc6e866e5db979c7a01fa42a 100755 (executable)
--- a/py/tests/cam.py
+++ b/py/tests/cam.py
import sys
import selectors
import pykms
-from helpers import *
-
w = 640
h = 480
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 3ffb716b02792270fdfadef3d3138629afdc9d16..772b4fc18e37bed321c763fddeee88a8d88c7dc8 100755 (executable)
--- a/py/tests/db.py
+++ b/py/tests/db.py
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 44c29fb9a18ce778317bf55688ee2bb1371583e8..836b880e6c59d9a1546818f50d6aa0232caa6d53 100755 (executable)
--- a/py/tests/functest.py
+++ b/py/tests/functest.py
#!/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 a6b68cccd2af82b45ad560407f1cb0b938a7706e..5969b82ad78a9c52d5841120658a2be6097cf662 100755 (executable)
--- a/py/tests/gamma.py
+++ b/py/tests/gamma.py
#!/usr/bin/python3
import pykms
-from helpers import *
# This hack makes drm initialize the fbcon, setting up the default connector
card = pykms.Card()
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
--- 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 fecd899f056e58ac8b53dad5bc7c497c8b719efd..721e55820de89d2a322f97767349b95717c8141e 100755 (executable)
--- a/py/tests/iact.py
+++ b/py/tests/iact.py
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 9c23b5b4b92950667ba69456549ed199ca0231c2..de00a4371ed63da10d675fb3f519bb063e4c8237 100755 (executable)
--- a/py/tests/test.py
+++ b/py/tests/test.py
#!/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 8c1f9640ff7766ebf16b3016349d220bd5f7cbf6..c2d08c1de993c318820a4ed7d76d93919e7939c6 100755 (executable)
--- a/py/tests/trans-test.py
+++ b/py/tests/trans-test.py
#!/usr/bin/python3
import pykms
-from helpers import *
import time
# This hack makes drm initialize the fbcon, setting up the default connector
continue
planes.append(p)
-disable_planes(card)
+card.disable_planes()
w = mode.hdisplay
h = mode.vdisplay
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,
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,
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,
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,
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,
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,
plane = planes[1]
fb = fbs[1]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,
plane = planes[2]
fb = fbs[2]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,
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,
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,
plane = planes[1]
fb = fbs[1]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,
plane = planes[2]
fb = fbs[2]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,
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,
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,
plane = planes[1]
fb = fbs[1]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,
plane = planes[2]
fb = fbs[2]
- set_props(plane, {
+ plane.set_props({
"FB_ID": fb.id,
"CRTC_ID": crtc.id,
"SRC_X": 0 << 16,