Retire gralloc dependence from cbmanager
We are retiring gralloc. This change removes the
gralloc dependency and its types from
cbmanager's API.
Bug: 145244672
Test: boot, check if the virtual scene camera works
Change-Id: Ied2525ea7057fafe407e047576640452ed614376
Signed-off-by: Roman Kiryanov <rkir@google.com>
diff --git a/system/cbmanager/Android.mk b/system/cbmanager/Android.mk
index 418902f..a6cfeaa 100644
--- a/system/cbmanager/Android.mk
+++ b/system/cbmanager/Android.mk
@@ -29,22 +29,16 @@
LOCAL_SHARED_LIBRARIES += \
liblog \
libcutils \
- libutils
+ libutils \
+ libhidlbase \
+ android.hardware.graphics.mapper@2.0 \
+ android.hardware.graphics.allocator@2.0
LOCAL_CFLAGS += \
-DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 30; echo $$?), 0)
LOCAL_SRC_FILES := hidl.cpp
-LOCAL_SHARED_LIBRARIES += \
- libhidlbase \
- android.hardware.graphics.mapper@2.0 \
- android.hardware.graphics.allocator@2.0
-else
-LOCAL_SRC_FILES := gralloc.cpp
-LOCAL_SHARED_LIBRARIES += \
- libhardware
-endif
+
endif
LOCAL_C_INCLUDES += \
diff --git a/system/cbmanager/gralloc.cpp b/system/cbmanager/gralloc.cpp
deleted file mode 100644
index dab4e39..0000000
--- a/system/cbmanager/gralloc.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hardware/gralloc.h>
-#include "cbmanager.h"
-
-namespace android {
-namespace {
-
-class CbManagerGrallocImpl : public CbManager::CbManagerImpl {
-public:
- CbManagerGrallocImpl(const hw_module_t* hwModule, alloc_device_t* allocDev)
- : mHwModule(hwModule), mAllocDev(allocDev) {}
-
- ~CbManagerGrallocImpl() {
- gralloc_close(mAllocDev);
- }
-
- const cb_handle_t* allocateBuffer(int width, int height, int format) {
- int ret;
- int stride;
- buffer_handle_t handle;
-
- ret = mAllocDev->alloc(mAllocDev, width, height, format,
- GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER,
- &handle, &stride);
- return ret ? nullptr : cb_handle_t::from(handle);
- }
-
- void freeBuffer(const cb_handle_t* h) {
- mAllocDev->free(mAllocDev, h);
- }
-
-private:
- const hw_module_t* mHwModule;
- alloc_device_t* mAllocDev;
-};
-
-std::unique_ptr<CbManager::CbManagerImpl> buildGrallocImpl() {
- int ret;
- const hw_module_t* hwModule;
-
- ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hwModule);
- if (ret) {
- return nullptr;
- }
-
- alloc_device_t* allocDev;
- ret = gralloc_open(hwModule, &allocDev);
- if (ret) {
- return nullptr;
- }
-
- return std::make_unique<CbManagerGrallocImpl>(hwModule, allocDev);
-}
-} // namespace
-
-CbManager::CbManager() : mImpl(buildGrallocImpl()) {}
-
-} // namespace android
diff --git a/system/cbmanager/hidl.cpp b/system/cbmanager/hidl.cpp
index 782645d..4c4d399 100644
--- a/system/cbmanager/hidl.cpp
+++ b/system/cbmanager/hidl.cpp
@@ -24,19 +24,22 @@
namespace {
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_vec;
-using PixelFormat10 = ::android::hardware::graphics::common::V1_0::PixelFormat;
-using ::android::hardware::graphics::common::V1_0::BufferUsage;
-namespace IMapper2ns = ::android::hardware::graphics::mapper::V2_0;
-namespace IAllocator2ns = ::android::hardware::graphics::allocator::V2_0;
+namespace IMapper2ns = hardware::graphics::mapper::V2_0;
+namespace IAllocator2ns = hardware::graphics::allocator::V2_0;
class CbManagerHidlV2Impl : public CbManager::CbManagerImpl {
public:
+ typedef CbManager::BufferUsage BufferUsage;
+ typedef CbManager::PixelFormat PixelFormat;
+ typedef hardware::hidl_bitfield<BufferUsage> BufferUsageBits;
+
CbManagerHidlV2Impl(::android::sp<IMapper2ns::IMapper> mapper,
::android::sp<IAllocator2ns::IAllocator> allocator)
: mMapper(mapper), mAllocator(allocator) {}
- const cb_handle_t* allocateBuffer(int width, int height, int format) {
+ const cb_handle_t* allocateBuffer(int width, int height,
+ PixelFormat format, BufferUsageBits usage) {
using IMapper2ns::Error;
using IMapper2ns::BufferDescriptor;
@@ -44,9 +47,8 @@
descriptor_info.width = width;
descriptor_info.height = height;
descriptor_info.layerCount = 1;
- descriptor_info.format = static_cast<PixelFormat10>(format);
- descriptor_info.usage =
- BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_RENDER_TARGET;
+ descriptor_info.format = format;
+ descriptor_info.usage = usage;
Error hidl_err = Error::NONE;
BufferDescriptor descriptor;
diff --git a/system/hwc2/Android.mk b/system/hwc2/Android.mk
index 489a98e..698de73 100644
--- a/system/hwc2/Android.mk
+++ b/system/hwc2/Android.mk
@@ -27,6 +27,7 @@
libhardware \
libsync \
libui \
+ android.hardware.graphics.mapper@2.0 \
emulator_hwcomposer_cflags += \
-DLOG_TAG=\"hwc2\" \
diff --git a/system/hwc2/EmuHWC2.cpp b/system/hwc2/EmuHWC2.cpp
index 2d9430f..d81d88a 100644
--- a/system/hwc2/EmuHWC2.cpp
+++ b/system/hwc2/EmuHWC2.cpp
@@ -390,8 +390,13 @@
}
const cb_handle_t* EmuHWC2::allocateDisplayColorBuffer() {
- return mCbManager.allocateBuffer(mDisplayWidth, mDisplayHeight,
- HAL_PIXEL_FORMAT_RGBA_8888);
+ typedef CbManager::BufferUsage BufferUsage;
+
+ return mCbManager.allocateBuffer(
+ mDisplayWidth,
+ mDisplayHeight,
+ CbManager::PixelFormat::RGBA_8888,
+ (BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_RENDER_TARGET));
}
void EmuHWC2::freeDisplayColorBuffer(const cb_handle_t* h) {
diff --git a/system/include/cbmanager.h b/system/include/cbmanager.h
index 4d98641..29eeab7 100644
--- a/system/include/cbmanager.h
+++ b/system/include/cbmanager.h
@@ -18,12 +18,17 @@
#define ANDROID_GOLDFISH_OPENGL_SYSTEM_CBMANAGER_CBMANAGER_H
#include <memory>
+#include <android/hardware/graphics/common/1.0/types.h>
#include "gralloc_cb.h"
namespace android {
class CbManager {
public:
+ typedef hardware::graphics::common::V1_0::BufferUsage BufferUsage;
+ typedef hardware::graphics::common::V1_0::PixelFormat PixelFormat;
+ typedef hardware::hidl_bitfield<BufferUsage> BufferUsageBits;
+
CbManager();
class CbManagerImpl {
@@ -31,12 +36,13 @@
virtual ~CbManagerImpl() {}
virtual const cb_handle_t* allocateBuffer(int width,
int height,
- int format) = 0;
+ PixelFormat format,
+ BufferUsageBits usage) = 0;
virtual void freeBuffer(const cb_handle_t* h) = 0;
};
- const cb_handle_t* allocateBuffer(int width, int height, int format) {
- return mImpl->allocateBuffer(width, height, format);
+ const cb_handle_t* allocateBuffer(int width, int height, PixelFormat format, BufferUsageBits usage) {
+ return mImpl->allocateBuffer(width, height, format, usage);
}
void freeBuffer(const cb_handle_t* h) {