Find valid crtc for screenshot.
This change completes some of the drm structures and searches
for a valid crtc to take the screenshot from.
BUG=chromium:476791
TEST=Ran on alex.
Change-Id: I84a2c85061c2e2e897051d6cfad3211247518c03
Reviewed-on: https://chromium-review.googlesource.com/272546
Commit-Queue: Ilja Friedel <ihf@chromium.org>
Trybot-Ready: Ilja Friedel <ihf@chromium.org>
Tested-by: Ilja Friedel <ihf@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/client/cros/graphics/drm.py b/client/cros/graphics/drm.py
index 10d42f4..c11397e 100644
--- a/client/cros/graphics/drm.py
+++ b/client/cros/graphics/drm.py
@@ -62,7 +62,14 @@
("fbs", POINTER(c_uint)),
("count_crtcs", c_int),
("crtcs", POINTER(c_uint)),
- # XXX incomplete struct!
+ ("count_connectors", c_int),
+ ("connectors", POINTER(c_uint)),
+ ("count_encoders", c_int),
+ ("encoders", POINTER(c_uint)),
+ ("min_width", c_int),
+ ("max_width", c_int),
+ ("min_height", c_int),
+ ("max_height", c_int),
]
_fd = None
@@ -75,17 +82,25 @@
if self._l:
self._l.drmModeFreeResources(self)
+ def getValidCrtc(self):
+ for i in xrange(0, self.count_crtcs):
+ crtc_id = self.crtcs[i]
+ crtc = self._l.drmModeGetCrtc(self._fd, crtc_id).contents
+ if crtc.mode_valid:
+ return crtc
+ return None
+
def getCrtc(self, crtc_id=None):
"""
Obtain the CRTC at a given index.
@param index: The CRTC to get.
"""
-
- if not crtc_id:
- crtc_id = self.crtcs[0]
-
- crtc = self._l.drmModeGetCrtc(self._fd, crtc_id).contents
+ crtc = None
+ if crtc_id:
+ crtc = self._l.drmModeGetCrtc(self._fd, crtc_id).contents
+ else:
+ crtc = self.getValidCrtc()
crtc._fd = self._fd
crtc._l = self._l
return crtc
@@ -99,6 +114,11 @@
_fields_ = [
("crtc_id", c_uint),
("buffer_id", c_uint),
+ ("x", c_uint),
+ ("y", c_uint),
+ ("width", c_uint),
+ ("height", c_uint),
+ ("mode_valid", c_int),
# XXX incomplete struct!
]