gralloc: Implement IMapper::2.1

Implements the new IMapper v2.1 APIs
Passes VTS for IMapper v2.1

Change-Id: I9762cd056a296c522ab3446408c3c4c5434b3dc4
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 42ac8ed..504e18d 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -92,6 +92,17 @@
   return Error::NONE;
 }
 
+Error BufferManager::ValidateBufferSize(private_handle_t const *hnd, BufferInfo info) {
+  unsigned int size, alignedw, alignedh;
+  info.format = allocator_->GetImplDefinedFormat(info.usage, info.format);
+  GetBufferSizeAndDimensions(info, &size, &alignedw, &alignedh);
+  auto ion_fd_size = static_cast<unsigned int>(lseek(hnd->fd, 0, SEEK_END));
+  if (size != ion_fd_size) {
+    return Error::BAD_VALUE;
+  }
+  return Error::NONE;
+}
+
 void BufferManager::RegisterHandleLocked(const private_handle_t *hnd, int ion_handle,
                                          int ion_handle_meta) {
   auto buffer = std::make_shared<Buffer>(hnd, ion_handle, ion_handle_meta);
@@ -111,9 +122,13 @@
           hnd->id);
     return Error::BAD_BUFFER;
   }
-  // Set base pointers to NULL since the data here was received over binder
+  // Initialize members that aren't transported
+  hnd->size = static_cast<unsigned int>(lseek(hnd->fd, 0, SEEK_END));
+  hnd->offset = 0;
+  hnd->offset_metadata = 0;
   hnd->base = 0;
   hnd->base_metadata = 0;
+  hnd->gpuaddr = 0;
   RegisterHandleLocked(hnd, ion_handle, ion_handle_meta);
   return Error::NONE;
 }
@@ -140,6 +155,15 @@
   return Error::NONE;
 }
 
+Error BufferManager::IsBufferImported(const private_handle_t *hnd) {
+  std::lock_guard<std::mutex> lock(buffer_lock_);
+  auto buf = GetBufferFromHandleLocked(hnd);
+  if (buf != nullptr) {
+    return Error::NONE;
+  }
+  return Error::BAD_BUFFER;
+}
+
 Error BufferManager::RetainBuffer(private_handle_t const *hnd) {
   ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id);
   auto err = Error::NONE;