Retire cbmananger from EmuHWC2

Replace it with GraphicBufferAllocator from fw.

Bug: 154346346
Test: boot
Signed-off-by: Roman Kiryanov <rkir@google.com>
Merged-In: Ibd1b559e9721ad229198ddda83ca45ffc6905642
Change-Id: Ia4668c2d047ca5918d690e7b43b002619f1a3ef9
diff --git a/system/hwc2/Android.mk b/system/hwc2/Android.mk
index ac74218..24a8a58 100644
--- a/system/hwc2/Android.mk
+++ b/system/hwc2/Android.mk
@@ -53,7 +53,7 @@
 LOCAL_VENDOR_MODULE := true
 LOCAL_SHARED_LIBRARIES := $(emulator_hwcomposer_shared_libraries)
 LOCAL_SHARED_LIBRARIES += libOpenglSystemCommon lib_renderControl_enc
-LOCAL_SHARED_LIBRARIES += libcbmanager
+LOCAL_SHARED_LIBRARIES += libui
 LOCAL_SRC_FILES := $(emulator_hwcomposer2_src_files)
 LOCAL_C_INCLUDES := $(emulator_hwcomposer_c_includes)
 LOCAL_MODULE_RELATIVE_PATH := $(emulator_hwcomposer_relative_path)
diff --git a/system/hwc2/EmuHWC2.cpp b/system/hwc2/EmuHWC2.cpp
index 14bb545..8df9f6d 100644
--- a/system/hwc2/EmuHWC2.cpp
+++ b/system/hwc2/EmuHWC2.cpp
@@ -27,6 +27,8 @@
 
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
+#include <ui/GraphicBuffer.h>
+#include <ui/GraphicBufferAllocator.h>
 
 #include "../egl/goldfish_sync.h"
 
@@ -390,17 +392,27 @@
 }
 
 const native_handle_t* EmuHWC2::allocateDisplayColorBuffer() {
-    typedef CbManager::BufferUsage BufferUsage;
+    const uint32_t layerCount = 1;
+    const uint64_t graphicBufferId = 0; // not used
 
-    return mCbManager.allocateBuffer(
-        mDisplayWidth,
-        mDisplayHeight,
-        CbManager::PixelFormat::RGBA_8888,
-        (BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_RENDER_TARGET));
+    buffer_handle_t h;
+    uint32_t stride;
+
+    if (GraphicBufferAllocator::get().allocate(
+        mDisplayWidth, mDisplayHeight,
+        PIXEL_FORMAT_RGBA_8888,
+        layerCount,
+        (GraphicBuffer::USAGE_HW_COMPOSER | GraphicBuffer::USAGE_HW_RENDER),
+        &h, &stride,
+        graphicBufferId, "EmuHWC2") == OK) {
+        return static_cast<const native_handle_t*>(h);
+    } else {
+        return nullptr;
+    }
 }
 
 void EmuHWC2::freeDisplayColorBuffer(const native_handle_t* h) {
-    mCbManager.freeBuffer(h);
+    GraphicBufferAllocator::get().free(h);
 }
 
 // Display functions
diff --git a/system/hwc2/EmuHWC2.h b/system/hwc2/EmuHWC2.h
index 1a8f275..1ff3394 100644
--- a/system/hwc2/EmuHWC2.h
+++ b/system/hwc2/EmuHWC2.h
@@ -38,7 +38,6 @@
 
 #include <cutils/native_handle.h>
 
-#include "cbmanager.h"
 #include "HostConnection.h"
 
 namespace android {
@@ -470,7 +469,6 @@
     const native_handle_t* allocateDisplayColorBuffer();
     void freeDisplayColorBuffer(const native_handle_t* h);
 
-    CbManager mCbManager;
     std::unordered_set<HWC2::Capability> mCapabilities;
 
     // These are potentially accessed from multiple threads, and are protected