summaryrefslogtreecommitdiffstats
path: root/src/gbm/backends/dri
diff options
context:
space:
mode:
authorBen Widawsky <[email protected]>2016-10-26 13:36:42 -0700
committerBen Widawsky <[email protected]>2017-03-09 15:35:44 -0800
commit7f6209e46f8de409f182931e0ca23bb64f1a8e39 (patch)
treec947ec4f9a4cdffa9d7add21992ecc413c7ef686 /src/gbm/backends/dri
parented4cf2440d87b512f9dcf7cfc3f408c151854af9 (diff)
gbm: Export a per plane getter for stride
v2: Preserve legacy behavior when plane is 0 (Jason Ekstrand) EINVAL when input plane is greater than total planes (Jason Ekstrand) Don't leak the image after fromPlanar (Daniel) Move bo->image check below plane count preventing bad index succeeding (Daniel) v3: Fix DRIimage leak (using Jason's recommended change) Make plane 0 return planar stride. This might break legacy behavior (Jason) v4: Move bogus hunk for get_handle_for_plane to the right patch (Jason) Fix error handling path to be cleaner (Jason) v5: Add assert for dumb BOs to make sure plane == 0 (Jason) Signed-off-by: Ben Widawsky <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> (v1) Reviewed-by: Jason Ekstrand <[email protected]> Acked-by: Daniel Stone <[email protected]>
Diffstat (limited to 'src/gbm/backends/dri')
-rw-r--r--src/gbm/backends/dri/gbm_dri.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 6a834182b5b..5a98b6aba68 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -665,7 +665,40 @@ gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int plane)
static uint32_t
gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
{
- return _bo->stride;
+ struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+ struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+ __DRIimage *image;
+ int stride = 0;
+
+ if (!dri->image || dri->image->base.version < 11 || !dri->image->fromPlanar) {
+ /* Preserve legacy behavior if plane is 0 */
+ if (plane == 0)
+ return _bo->stride;
+
+ errno = ENOSYS;
+ return 0;
+ }
+
+ if (plane >= get_number_planes(dri, bo->image)) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ if (bo->image == NULL) {
+ assert(plane == 0);
+ return _bo->stride;
+ }
+
+ image = dri->image->fromPlanar(bo->image, plane, NULL);
+ if (image) {
+ dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+ dri->image->destroyImage(image);
+ } else {
+ assert(plane == 0);
+ dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+ }
+
+ return (uint32_t)stride;
}
static void