gralloc1: Add remaining functionality

* Use private_0 flag
* Add some legacy flags to be used during transition
* Fix gralloc module version
* Adjust makefiles for gralloc1
* Add support for dump, num flex planes and lock flex.
* Use a unique ID for buffer descriptors
* Do not delete buffer handle, fix after verifying framework fix.
* Current gralloc1 clients do not conform to the lock() requirement
in the gralloc1 header. Tracked in b/33588773
* Add perform APIs to get the buffer size  and allocate a buffer
for use by SDM
* Fix reference counting
* Add a unique buffer ID
* Some cleanup in private_handle
* Create a wrapper class of private_handle to do refcounting
* Resolve implementation defined formats At allocation time, update buffer
descriptors to replace implementation defined formats with the ones we mean
to allocate
* Defer ion handle release
* Remove unused drm code.
* Add legacy constructor for private_handle_t used by some
clients

CRs-Fixed: 2007391
Change-Id: Ia9e816cec35ba45483a5b75d99f256325a010138
diff --git a/libgralloc1/gr_device_impl.h b/libgralloc1/gr_device_impl.h
index 4fc8e3c..80c3182 100644
--- a/libgralloc1/gr_device_impl.h
+++ b/libgralloc1/gr_device_impl.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, 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
@@ -44,7 +44,6 @@
 
 class GrallocImpl : public gralloc1_device_t {
  public:
-  explicit GrallocImpl(const private_module_t *module);
   ~GrallocImpl();
   bool Init();
   static int CloseDevice(hw_device_t *device);
@@ -53,9 +52,14 @@
   static gralloc1_function_pointer_t GetFunction(
       struct gralloc1_device *device, int32_t /*gralloc1_function_descriptor_t*/ descriptor);
 
+  static GrallocImpl* GetInstance(const struct hw_module_t *module) {
+    static GrallocImpl *instance = new GrallocImpl(module);
+    return instance;
+  }
+
  private:
-  static inline gralloc1_error_t CheckDeviceAndDescriptor(gralloc1_device_t *device,
-                                                          gralloc1_buffer_descriptor_t descriptor);
+  static inline gralloc1_error_t Dump(gralloc1_device_t *device, uint32_t *out_size,
+                                      char *out_buffer);
   static inline gralloc1_error_t CheckDeviceAndHandle(gralloc1_device_t *device,
                                                       buffer_handle_t buffer);
   static gralloc1_error_t CreateBufferDescriptor(gralloc1_device_t *device,
@@ -90,29 +94,25 @@
                                           buffer_handle_t *out_buffers);
   static gralloc1_error_t RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
   static gralloc1_error_t ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
-  static gralloc1_error_t getNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
+  static gralloc1_error_t GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
                                            uint32_t *out_num_planes);
   static gralloc1_error_t LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
                                      gralloc1_producer_usage_t prod_usage,
                                      gralloc1_consumer_usage_t cons_usage,
-                                     const gralloc1_rect_t *access_region, void **out_data,
+                                     const gralloc1_rect_t *region, void **out_data,
                                      int32_t acquire_fence);
   static gralloc1_error_t LockFlex(gralloc1_device_t *device, buffer_handle_t buffer,
                                    gralloc1_producer_usage_t prod_usage,
                                    gralloc1_consumer_usage_t cons_usage,
-                                   const gralloc1_rect_t *access_region,
+                                   const gralloc1_rect_t *region,
                                    struct android_flex_layout *out_flex_layout,
-                                   int32_t acquireFence);
-  /*  TODO(user) : LOCK_YCBCR changed to LOCK_FLEX but structure is not known yet.
-   *  Need to implement after clarification from Google.
-  static gralloc1_error_t LockYCbCrBuffer(gralloc1_device_t* device, buffer_handle_t buffer,
-      gralloc1_producer_usage_t producerUsage, gralloc1_consumer_usage_t consumerUsage,
-      const gralloc1_rect_t* Region, struct android_ycbcr* outYCbCr, int32_t* outAcquireFence);
-   */
+                                   int32_t acquire_fence);
+
   static gralloc1_error_t UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
                                        int32_t *release_fence);
   static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...);
 
+  explicit GrallocImpl(const hw_module_t *module);
   BufferManager *buf_mgr_ = NULL;
 };