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/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc
index ab05376..b055f65 100644
--- a/cros_gralloc/gralloc0/gralloc0.cc
+++ b/cros_gralloc/gralloc0/gralloc0.cc
@@ -297,6 +297,10 @@
 	uint32_t map_flags;
 	uint8_t *addr[DRV_MAX_PLANES];
 	auto mod = (struct gralloc0_module *)module;
+	struct rectangle rect = { .x = static_cast<uint32_t>(l),
+				  .y = static_cast<uint32_t>(t),
+				  .width = static_cast<uint32_t>(w),
+				  .height = static_cast<uint32_t>(h) };
 
 	auto hnd = cros_gralloc_convert_handle(handle);
 	if (!hnd) {
@@ -309,8 +313,13 @@
 		return -EINVAL;
 	}
 
+	assert(l >= 0);
+	assert(t >= 0);
+	assert(w >= 0);
+	assert(h >= 0);
+
 	map_flags = gralloc0_convert_map_usage(usage);
-	ret = mod->driver->lock(handle, fence_fd, map_flags, addr);
+	ret = mod->driver->lock(handle, fence_fd, &rect, map_flags, addr);
 	*vaddr = addr[0];
 	return ret;
 }
@@ -330,6 +339,10 @@
 	uint32_t map_flags;
 	uint8_t *addr[DRV_MAX_PLANES] = { nullptr, nullptr, nullptr, nullptr };
 	auto mod = (struct gralloc0_module *)module;
+	struct rectangle rect = { .x = static_cast<uint32_t>(l),
+				  .y = static_cast<uint32_t>(t),
+				  .width = static_cast<uint32_t>(w),
+				  .height = static_cast<uint32_t>(h) };
 
 	auto hnd = cros_gralloc_convert_handle(handle);
 	if (!hnd) {
@@ -344,8 +357,13 @@
 		return -EINVAL;
 	}
 
+	assert(l >= 0);
+	assert(t >= 0);
+	assert(w >= 0);
+	assert(h >= 0);
+
 	map_flags = gralloc0_convert_map_usage(usage);
-	ret = mod->driver->lock(handle, fence_fd, map_flags, addr);
+	ret = mod->driver->lock(handle, fence_fd, &rect, map_flags, addr);
 	if (ret)
 		return ret;