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>
diff --git a/drv.h b/drv.h
index bfde327..18653e5 100644
--- a/drv.h
+++ b/drv.h
@@ -87,8 +87,17 @@
 	void *priv;
 };
 
+struct rectangle {
+	uint32_t x;
+	uint32_t y;
+	uint32_t width;
+	uint32_t height;
+};
+
 struct mapping {
 	struct vma *vma;
+	struct rectangle rect;
+	uint32_t refcount;
 };
 
 struct driver *drv_create(int fd);
@@ -114,8 +123,8 @@
 
 struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
 
-void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-		 uint32_t map_flags, struct mapping **map_data, size_t plane);
+void *drv_bo_map(struct bo *bo, const struct rectangle *rect, uint32_t map_flags,
+		 struct mapping **map_data, size_t plane);
 
 int drv_bo_unmap(struct bo *bo, struct mapping *mapping);
 
@@ -147,6 +156,8 @@
 
 uint32_t drv_bo_get_stride_in_pixels(struct bo *bo);
 
+uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
+
 uint32_t drv_resolve_format(struct driver *drv, uint32_t format, uint64_t use_flags);
 
 size_t drv_num_planes_from_format(uint32_t format);