summaryrefslogtreecommitdiff
path: root/gbm.c
diff options
context:
space:
mode:
authorGurchetan Singh <gurchetansingh@chromium.org>2017-11-06 11:07:52 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-11-16 13:52:02 -0800
commit1ef809ecd434bfc0fd1d669ba925d58b1255d163 (patch)
tree2021d33b377ae8aec16d1eee63854ab24f24954b /gbm.c
parentee43c301c21976fb82538261c4e4288ffc754777 (diff)
minigbm: plumb buffer access region
This will allow drivers to tile or detile only the regions requested by the user. Note that the gralloc spec states that: "This address will represent the top-left corner of the entire buffer, even if accessRegion does not begin at the top-left corner." (see hardware/interfaces/graphics/mapper/2.0/IMapper.hal in AOSP) Also, the gralloc API makes it difficult to maintain two mappings of the same buffer. For example, say you have two access regions: module->lock(mod, handle1, 0, 0, 5, 5, &addr); module->lock(mod, handle1, 5, 5, 10, 10, &addr); module->unlock(mod, handle1); // which access region should be unlocked? In practice, this scenario never happens on Android. It's not exactly clear what gbm should return. Let's just return the top left of the access region because that's what we where doing before. BUG=chromium:764871 TEST=gbmtest, mmap_test -g, the following CTS tests: android.view.cts.SurfaceViewSyncTests android.media.cts.EncodeDecodeTest android.video.cts.VideoEncoderDecoderTest Change-Id: I7ca0713871e03928b1d4402aa161588990c7e775 Reviewed-on: https://chromium-review.googlesource.com/758147 Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Diffstat (limited to 'gbm.c')
-rw-r--r--gbm.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/gbm.c b/gbm.c
index 606b195..c67bdcd 100644
--- a/gbm.c
+++ b/gbm.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <xf86drm.h>
#include "drv.h"
@@ -225,15 +226,24 @@ PUBLIC struct gbm_bo *gbm_bo_import(struct gbm_device *gbm, uint32_t type, void
PUBLIC void *gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
uint32_t transfer_flags, uint32_t *stride, void **map_data, size_t plane)
{
+ void *addr;
+ off_t offset;
uint32_t map_flags;
+ struct rectangle rect = { .x = x, .y = y, .width = width, .height = height };
if (!bo || width == 0 || height == 0 || !stride || !map_data)
return NULL;
*stride = gbm_bo_get_plane_stride(bo, plane);
map_flags = (transfer_flags & GBM_BO_TRANSFER_READ) ? BO_MAP_READ : BO_MAP_NONE;
map_flags |= (transfer_flags & GBM_BO_TRANSFER_WRITE) ? BO_MAP_WRITE : BO_MAP_NONE;
- return drv_bo_map(bo->bo, x, y, width, height, map_flags, (struct mapping **)map_data,
- plane);
+
+ addr = drv_bo_map(bo->bo, &rect, map_flags, (struct mapping **)map_data, plane);
+ if (addr == MAP_FAILED)
+ return MAP_FAILED;
+
+ offset = gbm_bo_get_plane_stride(bo, plane) * rect.y;
+ offset += drv_stride_from_format(bo->gbm_format, rect.x, plane);
+ return (void *)((uint8_t *)addr + offset);
}
PUBLIC void gbm_bo_unmap(struct gbm_bo *bo, void *map_data)