minigbm: flush buffer instead of unmapping

As an optimization, let's call:
	- drv_bo_flush when calling (*unlock).
	- drv_bo_flush during gbm_bo_unmap()

CL:441916 makes sure that the buffer is unmapped before the
buffer destroy ioctl is called, so we will not be leaking
mappings in any case.

BUG=chromium:764871
TEST=Android boots, 8 CTS tests, and Youtube app works on Eve
     gbmtest, mmap_test -g

Change-Id: I429739a8c6435a434dac41ad125761364a3775d0
Reviewed-on: https://chromium-review.googlesource.com/668220
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/cros_gralloc_buffer.cc b/cros_gralloc/cros_gralloc_buffer.cc
index cec68a5..710b78f 100644
--- a/cros_gralloc/cros_gralloc_buffer.cc
+++ b/cros_gralloc/cros_gralloc_buffer.cc
@@ -87,12 +87,9 @@
 		return -EINVAL;
 	}
 
-	if (!--lockcount_) {
-		if (lock_data_[0]) {
-			drv_bo_unmap(bo_, lock_data_[0]);
-			lock_data_[0] = nullptr;
-		}
-	}
+	--lockcount_;
+	if (lock_data_[0])
+		return drv_bo_flush(bo_, lock_data_[0]);
 
 	return 0;
 }
diff --git a/gbm.c b/gbm.c
index 58173ea..831dfbf 100644
--- a/gbm.c
+++ b/gbm.c
@@ -242,7 +242,7 @@
 PUBLIC void gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
 {
 	assert(bo);
-	drv_bo_unmap(bo->bo, map_data);
+	drv_bo_flush(bo->bo, map_data);
 }
 
 PUBLIC uint32_t gbm_bo_get_width(struct gbm_bo *bo)