Merge "gralloc: Upgrade mapper and allocator to 3.0" into qt-qpr1-dev am: f5761db525

Change-Id: I598f1409d677e38dadf662e9d8ed52cd6a3f0e36
diff --git a/config/display-product.mk b/config/display-product.mk
index 7ffa961..f27e6b1 100644
--- a/config/display-product.mk
+++ b/config/display-product.mk
@@ -2,7 +2,7 @@
 PRODUCT_PACKAGES += \
     android.hardware.graphics.composer@2.3-impl \
     android.hardware.graphics.composer@2.3-service-sm7150 \
-    android.hardware.graphics.mapper@2.0-impl-qti-display \
+    android.hardware.graphics.mapper@3.0-impl-qti-display \
     vendor.qti.hardware.display.allocator-service \
     android.hardware.memtrack@1.0-impl \
     android.hardware.memtrack@1.0-service \
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index 3a800ad..5bd97cd 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -13,7 +13,8 @@
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libqdMetaData libsync libgrallocutils \
                                  libgralloccore \
                                  android.hardware.graphics.mapper@2.0 \
-                                 android.hardware.graphics.mapper@2.1
+                                 android.hardware.graphics.mapper@2.1 \
+                                 android.hardware.graphics.mapper@3.0
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -Werror
 LOCAL_CLANG                   := true
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
@@ -29,7 +30,8 @@
 LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libqdMetaData libdl  \
                                   android.hardware.graphics.mapper@2.0 \
-                                  android.hardware.graphics.mapper@2.1
+                                  android.hardware.graphics.mapper@2.1 \
+                                  android.hardware.graphics.mapper@3.0
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_SRC_FILES               := gr_utils.cpp gr_adreno_info.cpp
@@ -47,7 +49,8 @@
 
 LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libqdMetaData libdl libgrallocutils libion \
-                                  android.hardware.graphics.mapper@2.1
+                                  android.hardware.graphics.mapper@2.1 \
+                                  android.hardware.graphics.mapper@3.0
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_SRC_FILES               := gr_allocator.cpp gr_buf_mgr.cpp gr_ion_alloc.cpp
@@ -55,7 +58,7 @@
 
 #mapper
 include $(CLEAR_VARS)
-LOCAL_MODULE                  := android.hardware.graphics.mapper@2.0-impl-qti-display
+LOCAL_MODULE                  := android.hardware.graphics.mapper@3.0-impl-qti-display
 LOCAL_VENDOR_MODULE           := true
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
@@ -68,11 +71,12 @@
                                   libgrallocutils \
                                   libgralloccore \
                                   libsync \
-                                  vendor.qti.hardware.display.mapper@2.0 \
+                                  vendor.qti.hardware.display.mapper@3.0 \
                                   vendor.qti.hardware.display.mapperextensions@1.0 \
                                   android.hardware.graphics.mapper@2.0 \
                                   android.hardware.graphics.mapper@2.1 \
-                                  vendor.qti.hardware.display.mapperextensions@1.1
+                                  vendor.qti.hardware.display.mapperextensions@1.1 \
+                                  android.hardware.graphics.mapper@3.0
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_SRC_FILES               := QtiMapper.cpp QtiMapperExtensions.cpp
@@ -91,9 +95,10 @@
                                  libqdMetaData \
                                  libgrallocutils \
                                  libgralloccore \
-                                 vendor.qti.hardware.display.allocator@1.0 \
+                                 vendor.qti.hardware.display.allocator@3.0 \
+                                 android.hardware.graphics.mapper@3.0 \
                                  android.hardware.graphics.mapper@2.1 \
-                                 android.hardware.graphics.allocator@2.0
+                                 android.hardware.graphics.allocator@3.0
 LOCAL_CFLAGS                  := -DLOG_TAG=\"qdgralloc\" $(common_flags)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
diff --git a/gralloc/QtiAllocator.cpp b/gralloc/QtiAllocator.cpp
index bdb8ebe..e623e81 100644
--- a/gralloc/QtiAllocator.cpp
+++ b/gralloc/QtiAllocator.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -40,7 +40,7 @@
 namespace hardware {
 namespace display {
 namespace allocator {
-namespace V1_0 {
+namespace V3_0 {
 namespace implementation {
 
 using android::hardware::hidl_handle;
@@ -105,7 +105,7 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_0
+}  // namespace V3_0
 }  // namespace allocator
 }  // namespace display
 }  // namespace hardware
diff --git a/gralloc/QtiAllocator.h b/gralloc/QtiAllocator.h
index 2f3add8..76ee392 100644
--- a/gralloc/QtiAllocator.h
+++ b/gralloc/QtiAllocator.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -32,7 +32,7 @@
 
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
-#include <vendor/qti/hardware/display/allocator/1.0/IQtiAllocator.h>
+#include <vendor/qti/hardware/display/allocator/3.0/IQtiAllocator.h>
 
 #include "gr_buf_mgr.h"
 
@@ -41,22 +41,22 @@
 namespace hardware {
 namespace display {
 namespace allocator {
-namespace V1_0 {
+namespace V3_0 {
 namespace implementation {
 
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::hardware::graphics::allocator::V2_0::IAllocator;
-using ::android::hardware::graphics::mapper::V2_0::Error;
+using ::android::sp;
 using ::android::hardware::hidl_array;
 using ::android::hardware::hidl_memory;
 using ::android::hardware::hidl_string;
 using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::graphics::allocator::V3_0::IAllocator;
+using ::android::hardware::graphics::mapper::V3_0::Error;
 using ::android::hidl::base::V1_0::DebugInfo;
 using ::android::hidl::base::V1_0::IBase;
-using ::android::sp;
-using ::vendor::qti::hardware::display::allocator::V1_0::IQtiAllocator;
 using gralloc::BufferManager;
+using ::vendor::qti::hardware::display::allocator::V3_0::IQtiAllocator;
 
 class QtiAllocator : public IQtiAllocator {
  public:
@@ -74,7 +74,7 @@
 extern "C" IQtiAllocator *HIDL_FETCH_IQtiAllocator(const char *name);
 
 }  // namespace implementation
-}  // namespace V1_0
+}  // namespace V3_0
 }  // namespace allocator
 }  // namespace display
 }  // namespace hardware
diff --git a/gralloc/QtiMapper.cpp b/gralloc/QtiMapper.cpp
index c9790c2..27f91c1 100644
--- a/gralloc/QtiMapper.cpp
+++ b/gralloc/QtiMapper.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -50,7 +50,7 @@
   ALOGD_IF(DEBUG, "Created QtiMapper instance");
 }
 
-bool QtiMapper::ValidDescriptor(const BufferDescriptorInfo_2_1 &bd) {
+bool QtiMapper::ValidDescriptor(const BufferDescriptorInfo_3_0 &bd) {
   if (bd.width == 0 || bd.height == 0 || (static_cast<int32_t>(bd.format) <= 0) ||
       bd.layerCount <= 0) {
     return false;
@@ -59,7 +59,7 @@
   return true;
 }
 
-Error QtiMapper::CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
+Error QtiMapper::CreateDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info,
                                   IMapperBufferDescriptor *descriptor) {
   ALOGD_IF(DEBUG,
            "BufferDescriptorInfo: wxh: %dx%d usage: 0x%" PRIu64 " format: %d layer_count: %d",
@@ -76,17 +76,17 @@
 }
 
 // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
-Return<void> QtiMapper::createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
+Return<void> QtiMapper::createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info,
                                          createDescriptor_cb hidl_cb) {
   IMapperBufferDescriptor descriptor;
-  auto info_2_1 = BufferDescriptorInfo_2_1 {
+  auto info_3_0 = BufferDescriptorInfo_3_0{
       descriptor_info.width,
       descriptor_info.height,
       descriptor_info.layerCount,
       static_cast<PixelFormat>(descriptor_info.format),
       descriptor_info.usage,
   };
-  auto err = CreateDescriptor(info_2_1, &descriptor);
+  auto err = CreateDescriptor(info_3_0, &descriptor);
   hidl_cb(err, descriptor);
   return Void();
 }
@@ -177,13 +177,13 @@
                              const hidl_handle &acquire_fence, lock_cb hidl_cb) {
   auto err = LockBuffer(buffer, cpu_usage, acquire_fence);
   if (err != Error::NONE) {
-    hidl_cb(err, nullptr);
+    hidl_cb(err, nullptr, -1, -1);
     return Void();
   }
 
   auto hnd = PRIV_HANDLE_CONST(buffer);
   auto *out_data = reinterpret_cast<void *>(hnd->base);
-  hidl_cb(Error::NONE, out_data);
+  hidl_cb(err, out_data, gralloc::GetBpp(hnd->format), hnd->width);
   return Void();
 }
 
@@ -222,8 +222,8 @@
   return Void();
 }
 
-Return<Error> QtiMapper::validateBufferSize(void* buffer,
-                                            const BufferDescriptorInfo_2_1& descriptor_info,
+Return<Error> QtiMapper::validateBufferSize(void *buffer,
+                                            const BufferDescriptorInfo_3_0 &descriptor_info,
                                             uint32_t /*stride*/) {
   auto err = Error::BAD_BUFFER;
   auto hnd = static_cast<private_handle_t *>(buffer);
@@ -240,8 +240,7 @@
   return err;
 }
 
-Return<void> QtiMapper::getTransportSize(void *buffer,
-                                         IMapper_2_1::getTransportSize_cb hidl_cb) {
+Return<void> QtiMapper::getTransportSize(void *buffer, IMapper_3_0::getTransportSize_cb hidl_cb) {
   auto err = Error::BAD_BUFFER;
   auto hnd = static_cast<private_handle_t *>(buffer);
   uint32_t num_fds = 0, num_ints = 0;
@@ -260,11 +259,30 @@
   return Void();
 }
 
-Return<void> QtiMapper::createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptor_info,
-                                             IMapper_2_1::createDescriptor_2_1_cb hidl_cb) {
+Return<void> QtiMapper::isSupported(const BufferDescriptorInfo_3_0 &descriptor_info,
+                                    IMapper_3_0::isSupported_cb hidl_cb) {
   IMapperBufferDescriptor descriptor;
   auto err = CreateDescriptor(descriptor_info, &descriptor);
-  hidl_cb(err, descriptor);
+  if (err != Error::NONE) {
+    hidl_cb(err, false);
+    return Void();
+  }
+
+  gralloc::BufferDescriptor desc;
+  err = desc.Decode(descriptor);
+  if (err != Error::NONE) {
+    hidl_cb(err, false);
+    return Void();
+  }
+
+  buffer_handle_t buffer;
+  err = buf_mgr_->AllocateBuffer(desc, &buffer, 0, true);
+  if (err != Error::NONE) {
+    hidl_cb(err, false);
+  } else {
+    hidl_cb(err, true);
+  }
+
   return Void();
 }
 
@@ -281,10 +299,10 @@
 
 // When we are in passthrough mode, this method is used
 // by hidl to obtain the SP HAL object
-IMapper_2_1 *HIDL_FETCH_IMapper(const char * /* name */) {
+IMapper_3_0 *HIDL_FETCH_IMapper(const char * /* name */) {
   ALOGD_IF(DEBUG, "Fetching IMapper from QtiMapper");
   auto mapper = new QtiMapper();
-  return static_cast<IMapper_2_1 *>(mapper);
+  return static_cast<IMapper_3_0 *>(mapper);
 }
 
 IQtiMapper *HIDL_FETCH_IQtiMapper(const char * /* name */) {
diff --git a/gralloc/QtiMapper.h b/gralloc/QtiMapper.h
index 7302e5e..09e29c0 100644
--- a/gralloc/QtiMapper.h
+++ b/gralloc/QtiMapper.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -32,7 +32,7 @@
 
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
-#include <vendor/qti/hardware/display/mapper/2.0/IQtiMapper.h>
+#include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h>
 
 #include "QtiMapperExtensions.h"
 #include "gr_buf_mgr.h"
@@ -51,29 +51,27 @@
 using ::android::hardware::hidl_vec;
 using ::android::hardware::Return;
 using ::android::hardware::Void;
-using ::android::hardware::graphics::common::V1_1::PixelFormat;
-using ::android::hardware::graphics::mapper::V2_0::Error;
-using ::android::hardware::graphics::mapper::V2_0::IMapper;
-using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
+using ::android::hardware::graphics::common::V1_2::PixelFormat;
+using ::android::hardware::graphics::mapper::V3_0::Error;
+using ::android::hardware::graphics::mapper::V3_0::IMapper;
+using ::android::hardware::graphics::mapper::V3_0::YCbCrLayout;
 using ::android::hidl::base::V1_0::DebugInfo;
 using ::android::hidl::base::V1_0::IBase;
 using gralloc::BufferManager;
-using ::vendor::qti::hardware::display::mapper::V2_0::IQtiMapper;
+using ::vendor::qti::hardware::display::mapper::V3_0::IQtiMapper;
 using ::vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions;
 using ::vendor::qti::hardware::display::mapperextensions::V1_1::implementation::QtiMapperExtensions;
 
-using IMapper_2_1 = android::hardware::graphics::mapper::V2_1::IMapper;
-using BufferDescriptorInfo_2_0 =
-android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo;
-using BufferDescriptorInfo_2_1 =
-android::hardware::graphics::mapper::V2_1::IMapper::BufferDescriptorInfo;
-using IMapperBufferDescriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor;
+using IMapper_3_0 = android::hardware::graphics::mapper::V3_0::IMapper;
+using BufferDescriptorInfo_3_0 =
+    android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo;
+using IMapperBufferDescriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor;
 
 class QtiMapper : public IQtiMapper {
  public:
   QtiMapper();
   // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
-  Return<void> createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
+  Return<void> createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info,
                                 createDescriptor_cb hidl_cb) override;
   Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override;
   Return<Error> freeBuffer(void *buffer) override;
@@ -84,27 +82,27 @@
   Return<void> unlock(void *buffer, unlock_cb hidl_cb) override;
 
   // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow.
-  Return<Error> validateBufferSize(void* buffer,
-                                   const BufferDescriptorInfo_2_1& descriptorInfo,
+  Return<Error> validateBufferSize(void *buffer, const BufferDescriptorInfo_3_0 &descriptorInfo,
                                    uint32_t stride) override;
-  Return<void> getTransportSize(void* buffer, IMapper_2_1::getTransportSize_cb hidl_cb) override;
-  Return<void> createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptorInfo,
-                                    createDescriptor_2_1_cb _hidl_cb) override;
+  Return<void> getTransportSize(void *buffer, IMapper_3_0::getTransportSize_cb hidl_cb) override;
+
+  Return<void> isSupported(const BufferDescriptorInfo_3_0 &descriptor_info,
+                           IMapper_3_0::isSupported_cb hidl_cb) override;
 
   Return<void> getMapperExtensions(getMapperExtensions_cb hidl_cb);
   sp<mapperextensions::V1_1::IQtiMapperExtensions> extensions_ = nullptr;
 
  private:
   BufferManager *buf_mgr_ = nullptr;
-  Error CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
-                         IMapperBufferDescriptor * descriptor);
+  Error CreateDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info,
+                         IMapperBufferDescriptor *descriptor);
   bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd);
   bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd);
   void WaitFenceFd(int fence_fd);
   Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence);
 };
 
-extern "C" IMapper_2_1 *HIDL_FETCH_IMapper(const char *name);
+extern "C" IMapper_3_0 *HIDL_FETCH_IMapper(const char *name);
 extern "C" IQtiMapper *HIDL_FETCH_IQtiMapper(const char *name);
 
 }  // namespace implementation
diff --git a/gralloc/QtiMapperExtensions.h b/gralloc/QtiMapperExtensions.h
index b333312..b3c0500 100644
--- a/gralloc/QtiMapperExtensions.h
+++ b/gralloc/QtiMapperExtensions.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -51,8 +51,8 @@
 using ::android::hardware::hidl_vec;
 using ::android::hardware::Return;
 using ::android::hardware::Void;
-using ::android::hardware::graphics::common::V1_1::PixelFormat;
-using ::android::hardware::graphics::mapper::V2_0::IMapper;
+using ::android::hardware::graphics::common::V1_2::PixelFormat;
+using ::android::hardware::graphics::mapper::V3_0::IMapper;
 using ::android::hidl::base::V1_0::DebugInfo;
 using ::android::hidl::base::V1_0::IBase;
 using gralloc::BufferManager;
diff --git a/gralloc/gr_buf_descriptor.h b/gralloc/gr_buf_descriptor.h
index 2d426da..f608d8a 100644
--- a/gralloc/gr_buf_descriptor.h
+++ b/gralloc/gr_buf_descriptor.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -30,13 +30,13 @@
 #ifndef __GR_BUF_DESCRIPTOR_H__
 #define __GR_BUF_DESCRIPTOR_H__
 
-#include <android/hardware/graphics/mapper/2.1/IMapper.h>
+#include <android/hardware/graphics/mapper/3.0/IMapper.h>
 #include <atomic>
 
 namespace gralloc {
-using android::hardware::graphics::mapper::V2_0::Error;
-using android::hardware::graphics::mapper::V2_1::IMapper;
 using android::hardware::hidl_vec;
+using android::hardware::graphics::mapper::V3_0::Error;
+using android::hardware::graphics::mapper::V3_0::IMapper;
 
 const uint32_t kBufferDescriptorSize = 7;
 const uint32_t kMagicVersion = 0x76312E30;  // v1.0
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index cd36c13..e053862 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, 2020 The Linux Foundation. All rights reserved.
  * Not a Contribution
  *
  * Copyright (C) 2010 The Android Open Source Project
@@ -262,7 +262,7 @@
 }
 
 Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
-                                    unsigned int bufferSize) {
+                                    unsigned int bufferSize, bool testAlloc) {
   if (!handle)
     return Error::BAD_BUFFER;
   std::lock_guard<std::mutex> buffer_lock(buffer_lock_);
@@ -286,6 +286,10 @@
     return Error::BAD_DESCRIPTOR;
   }
 
+  if (testAlloc) {
+    return Error::NONE;
+  }
+
   size = (bufferSize >= size) ? bufferSize : size;
   uint64_t flags = 0;
   auto page_size = UINT(getpagesize());
diff --git a/gralloc/gr_buf_mgr.h b/gralloc/gr_buf_mgr.h
index 6c5f365..5f0f896 100644
--- a/gralloc/gr_buf_mgr.h
+++ b/gralloc/gr_buf_mgr.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, 2020 The Linux Foundation. All rights reserved.
  * Not a Contribution
  *
  * Copyright (C) 2008 The Android Open Source Project
@@ -33,14 +33,14 @@
 
 namespace gralloc {
 
-using android::hardware::graphics::mapper::V2_0::Error;
+using android::hardware::graphics::mapper::V3_0::Error;
 
 class BufferManager {
  public:
   ~BufferManager();
 
   Error AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
-                       unsigned int bufferSize = 0);
+                       unsigned int bufferSize = 0, bool testAlloc = false);
   Error RetainBuffer(private_handle_t const *hnd);
   Error ReleaseBuffer(private_handle_t const *hnd);
   Error LockBuffer(const private_handle_t *hnd, uint64_t usage);
diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp
index 2f8f550..997c8b9 100644
--- a/gralloc/gr_utils.cpp
+++ b/gralloc/gr_utils.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -235,6 +235,32 @@
   return ret;
 }
 
+int GetBpp(int format) {
+  if (IsUncompressedRGBFormat(format)) {
+    return GetBppForUncompressedRGB(format);
+  }
+  switch (format) {
+    case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR:
+    case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+    case HAL_PIXEL_FORMAT_RAW8:
+    case HAL_PIXEL_FORMAT_Y8:
+      return 1;
+    case HAL_PIXEL_FORMAT_RAW16:
+    case HAL_PIXEL_FORMAT_Y16:
+    case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+    case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+    case HAL_PIXEL_FORMAT_YCbCr_422_I:
+    case HAL_PIXEL_FORMAT_YCrCb_422_I:
+    case HAL_PIXEL_FORMAT_CbYCrY_422_I:
+      return 2;
+    case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
+    case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+      return 3;
+    default:
+      return -1;
+  }
+}
+
 // Returns the final buffer size meant to be allocated with ion
 unsigned int GetSize(const BufferInfo &info, unsigned int alignedw, unsigned int alignedh) {
   unsigned int size = 0;
diff --git a/gralloc/gr_utils.h b/gralloc/gr_utils.h
index 39d7e9b..6b86ee6 100644
--- a/gralloc/gr_utils.h
+++ b/gralloc/gr_utils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2016,2018-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2016,2018-2020, The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -30,7 +30,7 @@
 #ifndef __GR_UTILS_H__
 #define __GR_UTILS_H__
 
-#include <android/hardware/graphics/common/1.1/types.h>
+#include <android/hardware/graphics/common/1.2/types.h>
 #include "gralloc_priv.h"
 #include "qdMetaData.h"
 
@@ -132,6 +132,7 @@
 bool CpuCanAccess(uint64_t usage);
 bool CpuCanRead(uint64_t usage);
 bool CpuCanWrite(uint64_t usage);
+int GetBpp(int format);
 unsigned int GetSize(const BufferInfo &d, unsigned int alignedw, unsigned int alignedh);
 int GetBufferSizeAndDimensions(const BufferInfo &d, unsigned int *size, unsigned int *alignedw,
                                unsigned int *alignedh);
diff --git a/gralloc/service.cpp b/gralloc/service.cpp
index ecc8680..3431a1d 100644
--- a/gralloc/service.cpp
+++ b/gralloc/service.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -31,8 +31,8 @@
 
 using android::hardware::configureRpcThreadpool;
 using android::hardware::joinRpcThreadpool;
-using vendor::qti::hardware::display::allocator::V1_0::IQtiAllocator;
-using vendor::qti::hardware::display::allocator::V1_0::implementation::QtiAllocator;
+using vendor::qti::hardware::display::allocator::V3_0::IQtiAllocator;
+using vendor::qti::hardware::display::allocator::V3_0::implementation::QtiAllocator;
 
 int main(int, char **) {
   android::sp<IQtiAllocator> service = new QtiAllocator();