Honor bufferpool stride alignment when rendering overlays
Buffer pool may be allocated by hardware specific routines
that specify specific stride alignment. When rendering
overlays we must honor the specified constraints or risk
garbage being rendered downstream.
In the current specific use case the downstream element
is glupload, which NXP has modified to require a stride
that's 16*bpp aligned for their Vivante specific fastpath
to work. They also disabled all the standard fallback paths
for dmabufs assumed present, so unless upstream adheres
to the HW constrains garbage is rendered.
Change-Id: I2710446ddd4a9e23da5888c5a04f40833e28cbb5
diff --git a/edgetpuvision/gst_native.py b/edgetpuvision/gst_native.py
index d761dd4..eb79089 100644
--- a/edgetpuvision/gst_native.py
+++ b/edgetpuvision/gst_native.py
@@ -151,6 +151,7 @@
self.cond = threading.Condition()
self.width = 0
self.height = 0
+ self.min_stride = 0
self.flushing = False
self.eos = False
self.svg = None
@@ -200,6 +201,8 @@
structure = caps.get_structure(0)
self.width = structure.get_value('width')
self.height = structure.get_value('height')
+ self.min_stride = libcairo.cairo_format_stride_for_width(
+ int(cairo.FORMAT_ARGB32), self.width)
return True
def do_unlock(self):
@@ -251,9 +254,17 @@
return self.get_flow_return_locked(Gst.FlowReturn.OK)
def render_svg(self, svg, buf):
+ meta = GstVideo.buffer_get_video_meta(buf)
+ if meta:
+ assert meta.n_planes == 1
+ assert meta.width == self.width
+ assert meta.height == self.height
+ assert meta.stride[0] >= self.min_stride
+ stride = meta.stride[0]
+ else:
+ stride = self.min_stride
+
with _gst_buffer_map(buf, Gst.MapFlags.WRITE) as mapped:
- stride = libcairo.cairo_format_stride_for_width(
- int(cairo.FORMAT_ARGB32), self.width)
assert len(mapped) >= stride * self.height
# Fill with transparency.