summaryrefslogtreecommitdiff
path: root/cros_gralloc
diff options
context:
space:
mode:
authorYiwei Zhang <zzyiwei@chromium.org>2021-09-13 20:35:34 +0000
committerCommit Bot <commit-bot@chromium.org>2021-09-14 07:15:32 +0000
commitcaf13f185bd95956a8ea49b27eaa3ee841dd0fb1 (patch)
treed6f16baa046eb937dbd2ca4dc33978050e158b73 /cros_gralloc
parent94a69bd0bf2726feaaa4a07fbdaa696c411226fc (diff)
downloadminigbm-caf13f185bd95956a8ea49b27eaa3ee841dd0fb1.tar.gz
minigbm: deprecate Gralloc3 frontend
Gralloc3 was only temporarily used by CF before Gralloc4 came to the public. Let's deprecate Gralloc3 frontend so to avoid the maintaining cost for an inactive frontend. BUG=b:199524294 TEST=none Change-Id: I410aad56e0cd9bb1fd3589c0da3009c91c6774fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3158899 Reviewed-by: Jason Macnak <natsu@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org> Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Diffstat (limited to 'cros_gralloc')
-rw-r--r--cros_gralloc/gralloc3/.clang-format19
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Allocator.cc126
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Allocator.h31
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3AllocatorService.cc34
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Mapper.cc483
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Mapper.h64
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Utils.cc416
-rw-r--r--cros_gralloc/gralloc3/CrosGralloc3Utils.h39
-rw-r--r--cros_gralloc/gralloc3/android.hardware.graphics.allocator@3.0-service.minigbm.rc14
9 files changed, 0 insertions, 1226 deletions
diff --git a/cros_gralloc/gralloc3/.clang-format b/cros_gralloc/gralloc3/.clang-format
deleted file mode 100644
index 534cd32..0000000
--- a/cros_gralloc/gralloc3/.clang-format
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# This directory is formatted to match the format of the interfaces implemented.
-
-BasedOnStyle: Google
-Standard: Cpp11
-AccessModifierOffset: -2
-AllowShortFunctionsOnASingleLine: Inline
-ColumnLimit: 100
-CommentPragmas: NOLINT:.*
-DerivePointerAlignment: false
-IncludeBlocks: Preserve
-IndentWidth: 4
-ContinuationIndentWidth: 8
-PointerAlignment: Left
-TabWidth: 4
-UseTab: Never \ No newline at end of file
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Allocator.cc b/cros_gralloc/gralloc3/CrosGralloc3Allocator.cc
deleted file mode 100644
index 65637bc..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Allocator.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "cros_gralloc/gralloc3/CrosGralloc3Allocator.h"
-
-#include <optional>
-
-#include <android/hardware/graphics/mapper/3.0/IMapper.h>
-
-#include "cros_gralloc/cros_gralloc_helpers.h"
-#include "cros_gralloc/gralloc3/CrosGralloc3Utils.h"
-
-using android::hardware::hidl_handle;
-using android::hardware::hidl_vec;
-using android::hardware::Return;
-using android::hardware::Void;
-using android::hardware::graphics::common::V1_2::BufferUsage;
-using android::hardware::graphics::common::V1_2::PixelFormat;
-using android::hardware::graphics::mapper::V3_0::Error;
-
-using BufferDescriptorInfo =
- android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo;
-
-Error CrosGralloc3Allocator::init() {
- mDriver = cros_gralloc_driver::get_instance();
- return mDriver ? Error::NONE : Error::NO_RESOURCES;
-}
-
-Error CrosGralloc3Allocator::allocate(const BufferDescriptorInfo& descriptor, uint32_t* outStride,
- hidl_handle* outHandle) {
- if (!mDriver) {
- drv_log("Failed to allocate. Driver is uninitialized.\n");
- return Error::NO_RESOURCES;
- }
-
- if (!outStride || !outHandle) {
- return Error::NO_RESOURCES;
- }
-
- struct cros_gralloc_buffer_descriptor crosDescriptor;
- if (convertToCrosDescriptor(descriptor, &crosDescriptor)) {
- return Error::UNSUPPORTED;
- }
-
- bool supported = mDriver->is_supported(&crosDescriptor);
- if (!supported && (descriptor.usage & BufferUsage::COMPOSER_OVERLAY)) {
- crosDescriptor.use_flags &= ~BO_USE_SCANOUT;
- supported = mDriver->is_supported(&crosDescriptor);
- }
-
- if (!supported) {
- std::string drmFormatString = get_drm_format_string(crosDescriptor.drm_format);
- std::string pixelFormatString = getPixelFormatString(descriptor.format);
- std::string usageString = getUsageString(descriptor.usage);
- drv_log("Unsupported combination -- pixel format: %s, drm format:%s, usage: %s\n",
- pixelFormatString.c_str(), drmFormatString.c_str(), usageString.c_str());
- return Error::UNSUPPORTED;
- }
-
- buffer_handle_t handle;
- int ret = mDriver->allocate(&crosDescriptor, &handle);
- if (ret) {
- return Error::NO_RESOURCES;
- }
-
- cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(handle);
- if (!crosHandle) {
- return Error::NO_RESOURCES;
- }
-
- *outHandle = handle;
- *outStride = crosHandle->pixel_stride;
-
- return Error::NONE;
-}
-
-Return<void> CrosGralloc3Allocator::allocate(const hidl_vec<uint32_t>& encoded, uint32_t count,
- allocate_cb hidlCb) {
- hidl_vec<hidl_handle> handles;
-
- if (!mDriver) {
- drv_log("Failed to allocate. Driver is uninitialized.\n");
- hidlCb(Error::NO_RESOURCES, 0, handles);
- return Void();
- }
-
- auto descriptor_opt = decodeBufferDescriptorInfo(encoded);
- if (!descriptor_opt) {
- drv_log("Failed to allocate. Failed to decode buffer descriptor.\n");
- hidlCb(Error::BAD_DESCRIPTOR, 0, handles);
- return Void();
- }
-
- BufferDescriptorInfo descriptor = *descriptor_opt;
-
- handles.resize(count);
-
- uint32_t stride = 0;
- for (int i = 0; i < handles.size(); i++) {
- Error err = allocate(descriptor, &stride, &(handles[i]));
- if (err != Error::NONE) {
- for (int j = 0; j < i; j++) {
- mDriver->release(handles[j].getNativeHandle());
- }
- handles.resize(0);
- hidlCb(err, 0, handles);
- return Void();
- }
- }
-
- hidlCb(Error::NONE, stride, handles);
-
- for (const hidl_handle& handle : handles) {
- mDriver->release(handle.getNativeHandle());
- }
-
- return Void();
-}
-
-Return<void> CrosGralloc3Allocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
- hidl_cb("CrosGralloc3Allocator::dumpDebugInfo unimplemented.");
- return Void();
-}
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Allocator.h b/cros_gralloc/gralloc3/CrosGralloc3Allocator.h
deleted file mode 100644
index be5b5b9..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Allocator.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
-#include <android/hardware/graphics/mapper/3.0/IMapper.h>
-
-#include "cros_gralloc/cros_gralloc_driver.h"
-
-class CrosGralloc3Allocator : public android::hardware::graphics::allocator::V3_0::IAllocator {
- public:
- CrosGralloc3Allocator() = default;
-
- android::hardware::Return<void> allocate(
- const android::hardware::hidl_vec<uint32_t>& descriptor, uint32_t count,
- allocate_cb hidl_cb) override;
-
- android::hardware::graphics::mapper::V3_0::Error init();
-
- android::hardware::Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
-
- private:
- android::hardware::graphics::mapper::V3_0::Error allocate(
- const android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo&
- description,
- uint32_t* outStride, android::hardware::hidl_handle* outHandle);
-
- cros_gralloc_driver* mDriver = nullptr;
-};
diff --git a/cros_gralloc/gralloc3/CrosGralloc3AllocatorService.cc b/cros_gralloc/gralloc3/CrosGralloc3AllocatorService.cc
deleted file mode 100644
index 6bde1d6..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3AllocatorService.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#define LOG_TAG "AllocatorService"
-
-#include <hidl/LegacySupport.h>
-
-#include "cros_gralloc/gralloc3/CrosGralloc3Allocator.h"
-
-using android::sp;
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-using android::hardware::graphics::mapper::V3_0::Error;
-
-int main(int, char**) {
- sp<CrosGralloc3Allocator> allocator = new CrosGralloc3Allocator();
- if (allocator->init() != Error::NONE) {
- ALOGE("Failed to initialize IAllocator 3.0 service.");
- return -EINVAL;
- }
- configureRpcThreadpool(4, true /* callerWillJoin */);
- if (allocator->registerAsService() != android::NO_ERROR) {
- ALOGE("Failed to register graphics IAllocator 3.0 service.");
- return -EINVAL;
- }
-
- ALOGI("IAllocator 3.0 service is initialized.");
- android::hardware::joinRpcThreadpool();
- ALOGI("IAllocator 3.0 service is terminating.");
- return 0;
-}
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc b/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc
deleted file mode 100644
index a0b19f0..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Mapper.cc
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "cros_gralloc/gralloc3/CrosGralloc3Mapper.h"
-
-#include <cutils/native_handle.h>
-
-#include "cros_gralloc/cros_gralloc_helpers.h"
-#include "cros_gralloc/gralloc3/CrosGralloc3Utils.h"
-
-#include "helpers.h"
-
-using android::hardware::hidl_handle;
-using android::hardware::hidl_vec;
-using android::hardware::Return;
-using android::hardware::Void;
-using android::hardware::graphics::common::V1_2::BufferUsage;
-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;
-
-Return<void> CrosGralloc3Mapper::createDescriptor(const BufferDescriptorInfo& description,
- createDescriptor_cb hidlCb) {
- hidl_vec<uint32_t> descriptor;
-
- if (description.width == 0) {
- drv_log("Failed to createDescriptor. Bad width: %d.\n", description.width);
- hidlCb(Error::BAD_VALUE, descriptor);
- return Void();
- }
-
- if (description.height == 0) {
- drv_log("Failed to createDescriptor. Bad height: %d.\n", description.height);
- hidlCb(Error::BAD_VALUE, descriptor);
- return Void();
- }
-
- if (description.layerCount == 0) {
- drv_log("Failed to createDescriptor. Bad layer count: %d.\n", description.layerCount);
- hidlCb(Error::BAD_VALUE, descriptor);
- return Void();
- }
-
- auto descriptor_opt = encodeBufferDescriptorInfo(description);
- if (!descriptor_opt) {
- drv_log("Failed to createDescriptor. Failed to encodeBufferDescriptorInfo\n");
- hidlCb(Error::BAD_VALUE, descriptor);
- return Void();
- }
-
- descriptor = *descriptor_opt;
- hidlCb(Error::NONE, descriptor);
- return Void();
-}
-
-Return<void> CrosGralloc3Mapper::importBuffer(const hidl_handle& handle, importBuffer_cb hidlCb) {
- if (!mDriver) {
- drv_log("Failed to import buffer. Driver is uninitialized.\n");
- hidlCb(Error::NO_RESOURCES, nullptr);
- return Void();
- }
-
- const native_handle_t* bufferHandle = handle.getNativeHandle();
- if (!bufferHandle || bufferHandle->numFds == 0) {
- drv_log("Failed to importBuffer. Bad handle.\n");
- hidlCb(Error::BAD_BUFFER, nullptr);
- return Void();
- }
-
- native_handle_t* importedBufferHandle = native_handle_clone(bufferHandle);
- if (!importedBufferHandle) {
- drv_log("Failed to importBuffer. Handle clone failed.\n");
- hidlCb(Error::NO_RESOURCES, nullptr);
- return Void();
- }
-
- int ret = mDriver->retain(importedBufferHandle);
- if (ret) {
- native_handle_close(importedBufferHandle);
- native_handle_delete(importedBufferHandle);
- hidlCb(Error::NO_RESOURCES, nullptr);
- return Void();
- }
-
- hidlCb(Error::NONE, importedBufferHandle);
- return Void();
-}
-
-Return<Error> CrosGralloc3Mapper::freeBuffer(void* rawHandle) {
- if (!mDriver) {
- drv_log("Failed to freeBuffer. Driver is uninitialized.\n");
- return Error::NO_RESOURCES;
- }
-
- native_handle_t* bufferHandle = reinterpret_cast<native_handle_t*>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to freeBuffer. Empty handle.\n");
- return Error::BAD_BUFFER;
- }
-
- int ret = mDriver->release(bufferHandle);
- if (ret) {
- drv_log("Failed to freeBuffer.\n");
- return Error::BAD_BUFFER;
- }
-
- native_handle_close(bufferHandle);
- native_handle_delete(bufferHandle);
- return Error::NONE;
-}
-
-Return<Error> CrosGralloc3Mapper::validateBufferSize(void* rawHandle,
- const BufferDescriptorInfo& descriptor,
- uint32_t stride) {
- if (!mDriver) {
- drv_log("Failed to validateBufferSize. Driver is uninitialized.\n");
- return Error::NO_RESOURCES;
- }
-
- native_handle_t* bufferHandle = reinterpret_cast<native_handle_t*>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to validateBufferSize. Empty handle.\n");
- return Error::BAD_BUFFER;
- }
-
- cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(bufferHandle);
- if (!crosHandle) {
- drv_log("Failed to validateBufferSize. Invalid handle.\n");
- return Error::BAD_BUFFER;
- }
-
- PixelFormat crosHandleFormat = static_cast<PixelFormat>(crosHandle->droid_format);
- if (descriptor.format != crosHandleFormat) {
- drv_log("Failed to validateBufferSize. Format mismatch.\n");
- return Error::BAD_BUFFER;
- }
-
- if (descriptor.width != crosHandle->width) {
- drv_log("Failed to validateBufferSize. Width mismatch (%d vs %d).\n", descriptor.width,
- crosHandle->width);
- return Error::BAD_VALUE;
- }
-
- if (descriptor.height != crosHandle->height) {
- drv_log("Failed to validateBufferSize. Height mismatch (%d vs %d).\n", descriptor.height,
- crosHandle->height);
- return Error::BAD_VALUE;
- }
-
- if (stride != crosHandle->pixel_stride) {
- drv_log("Failed to validateBufferSize. Stride mismatch (%d vs %d).\n", stride,
- crosHandle->pixel_stride);
- return Error::BAD_VALUE;
- }
-
- return Error::NONE;
-}
-
-Return<void> CrosGralloc3Mapper::getTransportSize(void* rawHandle, getTransportSize_cb hidlCb) {
- if (!mDriver) {
- drv_log("Failed to getTransportSize. Driver is uninitialized.\n");
- hidlCb(Error::BAD_BUFFER, 0, 0);
- return Void();
- }
-
- native_handle_t* bufferHandle = reinterpret_cast<native_handle_t*>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to getTransportSize. Bad handle.\n");
- hidlCb(Error::BAD_BUFFER, 0, 0);
- return Void();
- }
-
- // No local process data is currently stored on the native handle.
- hidlCb(Error::NONE, bufferHandle->numFds, bufferHandle->numInts);
- return Void();
-}
-
-Return<void> CrosGralloc3Mapper::lock(void* rawHandle, uint64_t cpuUsage, const Rect& accessRegion,
- const hidl_handle& acquireFence, lock_cb hidlCb) {
- if (!mDriver) {
- drv_log("Failed to lock. Driver is uninitialized.\n");
- hidlCb(Error::NO_RESOURCES, nullptr, 0, 0);
- return Void();
- }
-
- buffer_handle_t bufferHandle = reinterpret_cast<buffer_handle_t>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to lock. Empty handle.\n");
- hidlCb(Error::BAD_BUFFER, nullptr, 0, 0);
- return Void();
- }
-
- cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(bufferHandle);
- if (crosHandle == nullptr) {
- drv_log("Failed to lock. Invalid handle.\n");
- hidlCb(Error::BAD_BUFFER, nullptr, 0, 0);
- return Void();
- }
-
- LockResult result = lockInternal(crosHandle, cpuUsage, accessRegion, acquireFence);
- if (result.error != Error::NONE) {
- drv_log("Failed to lock. Failed to lockInternal.\n");
- hidlCb(result.error, nullptr, 0, 0);
- return Void();
- }
-
- int32_t bytesPerPixel = drv_bytes_per_pixel_from_format(crosHandle->format, 0);
- int32_t bytesPerStride = static_cast<int32_t>(crosHandle->strides[0]);
-
- hidlCb(Error::NONE, result.mapped[0], bytesPerPixel, bytesPerStride);
- return Void();
-}
-
-Return<void> CrosGralloc3Mapper::lockYCbCr(void* rawHandle, uint64_t cpuUsage,
- const Rect& accessRegion,
- const android::hardware::hidl_handle& acquireFence,
- lockYCbCr_cb hidlCb) {
- YCbCrLayout ycbcr = {};
-
- if (!mDriver) {
- drv_log("Failed to lock. Driver is uninitialized.\n");
- hidlCb(Error::NO_RESOURCES, ycbcr);
- return Void();
- }
-
- buffer_handle_t bufferHandle = reinterpret_cast<buffer_handle_t>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to lockYCbCr. Empty handle.\n");
- hidlCb(Error::BAD_BUFFER, ycbcr);
- return Void();
- }
-
- cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(bufferHandle);
- if (crosHandle == nullptr) {
- drv_log("Failed to lockYCbCr. Invalid handle.\n");
- hidlCb(Error::BAD_BUFFER, ycbcr);
- return Void();
- }
-
- LockResult result = lockInternal(crosHandle, cpuUsage, accessRegion, acquireFence);
- if (result.error != Error::NONE) {
- drv_log("Failed to lockYCbCr. Failed to lockInternal.\n");
- hidlCb(result.error, ycbcr);
- return Void();
- }
-
- switch (crosHandle->format) {
- case DRM_FORMAT_NV12: {
- ycbcr.y = result.mapped[0] + crosHandle->offsets[0];
- ycbcr.cb = result.mapped[0] + crosHandle->offsets[1];
- ycbcr.cr = result.mapped[0] + crosHandle->offsets[1] + 1;
- ycbcr.yStride = crosHandle->strides[0];
- ycbcr.cStride = crosHandle->strides[1];
- ycbcr.chromaStep = 2;
- break;
- }
- case DRM_FORMAT_NV21: {
- ycbcr.y = result.mapped[0] + crosHandle->offsets[0];
- ycbcr.cb = result.mapped[0] + crosHandle->offsets[1] + 1;
- ycbcr.cr = result.mapped[0] + crosHandle->offsets[1];
- ycbcr.yStride = crosHandle->strides[0];
- ycbcr.cStride = crosHandle->strides[1];
- ycbcr.chromaStep = 2;
- break;
- }
- case DRM_FORMAT_YVU420: {
- ycbcr.y = result.mapped[0] + crosHandle->offsets[0];
- ycbcr.cb = result.mapped[0] + crosHandle->offsets[1];
- ycbcr.cr = result.mapped[0] + crosHandle->offsets[2];
- ycbcr.yStride = crosHandle->strides[0];
- ycbcr.cStride = crosHandle->strides[1];
- ycbcr.chromaStep = 1;
- break;
- }
- case DRM_FORMAT_YVU420_ANDROID: {
- ycbcr.y = result.mapped[0] + crosHandle->offsets[0];
- ycbcr.cb = result.mapped[0] + crosHandle->offsets[2];
- ycbcr.cr = result.mapped[0] + crosHandle->offsets[1];
- ycbcr.yStride = crosHandle->strides[0];
- ycbcr.cStride = crosHandle->strides[1];
- ycbcr.chromaStep = 1;
- break;
- }
- default: {
- std::string format = get_drm_format_string(crosHandle->format);
- drv_log("Failed to lockYCbCr. Unhandled format: %s\n", format.c_str());
- hidlCb(Error::BAD_BUFFER, ycbcr);
- return Void();
- }
- }
-
- hidlCb(Error::NONE, ycbcr);
- return Void();
-}
-
-CrosGralloc3Mapper::LockResult CrosGralloc3Mapper::lockInternal(
- cros_gralloc_handle_t crosHandle, uint64_t cpuUsage, const Rect& region,
- const android::hardware::hidl_handle& acquireFence) {
- LockResult result = {};
-
- if (!mDriver) {
- drv_log("Failed to lock. Driver is uninitialized.\n");
- result.error = Error::NO_RESOURCES;
- return result;
- }
-
- if (cpuUsage == 0) {
- drv_log("Failed to lock. Bad cpu usage: %" PRIu64 ".\n", cpuUsage);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- uint32_t mapUsage = 0;
- int ret = convertToMapUsage(cpuUsage, &mapUsage);
- if (ret) {
- drv_log("Failed to lock. Convert usage failed.\n");
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.left < 0) {
- drv_log("Failed to lock. Invalid region: negative left value %d.\n", region.left);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.top < 0) {
- drv_log("Failed to lock. Invalid region: negative top value %d.\n", region.top);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.width < 0) {
- drv_log("Failed to lock. Invalid region: negative width value %d.\n", region.width);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.height < 0) {
- drv_log("Failed to lock. Invalid region: negative height value %d.\n", region.height);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.width > crosHandle->width) {
- drv_log("Failed to lock. Invalid region: width greater than buffer width (%d vs %d).\n",
- region.width, crosHandle->width);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- if (region.height > crosHandle->height) {
- drv_log("Failed to lock. Invalid region: height greater than buffer height (%d vs %d).\n",
- region.height, crosHandle->height);
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- struct rectangle rect = {static_cast<uint32_t>(region.left), static_cast<uint32_t>(region.top),
- static_cast<uint32_t>(region.width),
- static_cast<uint32_t>(region.height)};
-
- // An access region of all zeros means the entire buffer.
- if (rect.x == 0 && rect.y == 0 && rect.width == 0 && rect.height == 0) {
- rect.width = crosHandle->width;
- rect.height = crosHandle->height;
- }
-
- int acquireFenceFd = -1;
- ret = convertToFenceFd(acquireFence, &acquireFenceFd);
- if (ret) {
- drv_log("Failed to lock. Bad acquire fence.\n");
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- buffer_handle_t bufferHandle = reinterpret_cast<buffer_handle_t>(crosHandle);
- ret = mDriver->lock(bufferHandle, acquireFenceFd, false, &rect, mapUsage, result.mapped);
- if (ret) {
- result.error = Error::BAD_VALUE;
- return result;
- }
-
- result.error = Error::NONE;
- return result;
-}
-
-Return<void> CrosGralloc3Mapper::unlock(void* rawHandle, unlock_cb hidlCb) {
- if (!mDriver) {
- drv_log("Failed to unlock. Driver is uninitialized.\n");
- hidlCb(Error::BAD_BUFFER, nullptr);
- return Void();
- }
-
- buffer_handle_t bufferHandle = reinterpret_cast<buffer_handle_t>(rawHandle);
- if (!bufferHandle) {
- drv_log("Failed to unlock. Empty handle.\n");
- hidlCb(Error::BAD_BUFFER, nullptr);
- return Void();
- }
-
- int releaseFenceFd = -1;
- int ret = mDriver->unlock(bufferHandle, &releaseFenceFd);
- if (ret) {
- drv_log("Failed to unlock.\n");
- hidlCb(Error::BAD_BUFFER, nullptr);
- return Void();
- }
-
- hidl_handle releaseFenceHandle;
- ret = convertToFenceHandle(releaseFenceFd, &releaseFenceHandle);
- if (ret) {
- drv_log("Failed to unlock. Failed to convert release fence to handle.\n");
- hidlCb(Error::BAD_BUFFER, nullptr);
- return Void();
- }
-
- hidlCb(Error::NONE, releaseFenceHandle);
- return Void();
-}
-
-Return<void> CrosGralloc3Mapper::isSupported(const BufferDescriptorInfo& descriptor,
- isSupported_cb hidlCb) {
- if (!mDriver) {
- drv_log("Failed to isSupported. Driver is uninitialized.\n");
- hidlCb(Error::BAD_VALUE, false);
- return Void();
- }
-
- struct cros_gralloc_buffer_descriptor crosDescriptor;
- if (convertToCrosDescriptor(descriptor, &crosDescriptor)) {
- hidlCb(Error::NONE, false);
- return Void();
- }
-
- bool supported = mDriver->is_supported(&crosDescriptor);
- if (!supported) {
- crosDescriptor.use_flags &= ~BO_USE_SCANOUT;
- supported = mDriver->is_supported(&crosDescriptor);
- }
-
- hidlCb(Error::NONE, supported);
- return Void();
-}
-
-int CrosGralloc3Mapper::getResolvedDrmFormat(PixelFormat pixelFormat, uint64_t bufferUsage,
- uint32_t* outDrmFormat) {
- uint32_t drmFormat;
- if (convertToDrmFormat(pixelFormat, &drmFormat)) {
- std::string pixelFormatString = getPixelFormatString(pixelFormat);
- drv_log("Failed to getResolvedDrmFormat. Failed to convert format %s\n",
- pixelFormatString.c_str());
- return -EINVAL;
- }
-
- uint64_t usage;
- if (convertToBufferUsage(bufferUsage, &usage)) {
- std::string usageString = getUsageString(bufferUsage);
- drv_log("Failed to getResolvedDrmFormat. Failed to convert usage %s\n",
- usageString.c_str());
- return -EINVAL;
- }
-
- uint32_t resolvedDrmFormat = mDriver->get_resolved_drm_format(drmFormat, usage);
- if (resolvedDrmFormat == DRM_FORMAT_INVALID) {
- std::string drmFormatString = get_drm_format_string(drmFormat);
- drv_log("Failed to getResolvedDrmFormat. Failed to resolve drm format %s\n",
- drmFormatString.c_str());
- return -EINVAL;
- }
-
- *outDrmFormat = resolvedDrmFormat;
-
- return 0;
-}
-
-android::hardware::graphics::mapper::V3_0::IMapper* HIDL_FETCH_IMapper(const char* /*name*/) {
- return static_cast<android::hardware::graphics::mapper::V3_0::IMapper*>(new CrosGralloc3Mapper);
-}
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Mapper.h b/cros_gralloc/gralloc3/CrosGralloc3Mapper.h
deleted file mode 100644
index 54db61e..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Mapper.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <android/hardware/graphics/mapper/3.0/IMapper.h>
-
-#include <optional>
-
-#include "cros_gralloc/cros_gralloc_driver.h"
-#include "cros_gralloc/cros_gralloc_handle.h"
-
-class CrosGralloc3Mapper : public android::hardware::graphics::mapper::V3_0::IMapper {
- public:
- CrosGralloc3Mapper() = default;
-
- android::hardware::Return<void> createDescriptor(const BufferDescriptorInfo& description,
- createDescriptor_cb hidlCb) override;
-
- android::hardware::Return<void> importBuffer(const android::hardware::hidl_handle& rawHandle,
- importBuffer_cb hidlCb) override;
-
- android::hardware::Return<android::hardware::graphics::mapper::V3_0::Error> freeBuffer(
- void* rawHandle) override;
-
- android::hardware::Return<android::hardware::graphics::mapper::V3_0::Error> validateBufferSize(
- void* rawHandle, const BufferDescriptorInfo& descriptor, uint32_t stride) override;
-
- android::hardware::Return<void> getTransportSize(void* rawHandle,
- getTransportSize_cb hidlCb) override;
-
- android::hardware::Return<void> lock(void* rawHandle, uint64_t cpuUsage,
- const Rect& accessRegion,
- const android::hardware::hidl_handle& acquireFence,
- lock_cb hidlCb) override;
-
- android::hardware::Return<void> lockYCbCr(void* rawHandle, uint64_t cpuUsage,
- const Rect& accessRegion,
- const android::hardware::hidl_handle& acquireFence,
- lockYCbCr_cb _hidl_cb) override;
-
- android::hardware::Return<void> unlock(void* rawHandle, unlock_cb hidlCb) override;
-
- android::hardware::Return<void> isSupported(const BufferDescriptorInfo& descriptor,
- isSupported_cb hidlCb) override;
-
- private:
- int getResolvedDrmFormat(android::hardware::graphics::common::V1_2::PixelFormat pixelFormat,
- uint64_t bufferUsage, uint32_t* outDrmFormat);
-
- struct LockResult {
- android::hardware::graphics::mapper::V3_0::Error error;
-
- uint8_t* mapped[DRV_MAX_PLANES];
- };
- LockResult lockInternal(cros_gralloc_handle_t crosHandle, uint64_t cpuUsage,
- const Rect& accessRegion,
- const android::hardware::hidl_handle& acquireFence);
-
- cros_gralloc_driver* mDriver = cros_gralloc_driver::get_instance();
-};
-
-extern "C" android::hardware::graphics::mapper::V3_0::IMapper* HIDL_FETCH_IMapper(const char* name);
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Utils.cc b/cros_gralloc/gralloc3/CrosGralloc3Utils.cc
deleted file mode 100644
index d15c431..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Utils.cc
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "cros_gralloc/gralloc3/CrosGralloc3Utils.h"
-
-#include <array>
-#include <limits>
-#include <unordered_map>
-
-#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
-#include <cutils/native_handle.h>
-
-#include "cros_gralloc/cros_gralloc_helpers.h"
-
-using android::hardware::hidl_bitfield;
-using android::hardware::hidl_handle;
-using android::hardware::hidl_vec;
-using android::hardware::graphics::common::V1_2::BufferUsage;
-using android::hardware::graphics::common::V1_2::PixelFormat;
-
-using BufferDescriptorInfo =
- android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo;
-
-std::string getPixelFormatString(PixelFormat format) {
- switch (format) {
- case PixelFormat::BGRA_8888:
- return "PixelFormat::BGRA_8888";
- case PixelFormat::BLOB:
- return "PixelFormat::BLOB";
- case PixelFormat::DEPTH_16:
- return "PixelFormat::DEPTH_16";
- case PixelFormat::DEPTH_24:
- return "PixelFormat::DEPTH_24";
- case PixelFormat::DEPTH_24_STENCIL_8:
- return "PixelFormat::DEPTH_24_STENCIL_8";
- case PixelFormat::DEPTH_32F:
- return "PixelFormat::DEPTH_24";
- case PixelFormat::DEPTH_32F_STENCIL_8:
- return "PixelFormat::DEPTH_24_STENCIL_8";
- case PixelFormat::HSV_888:
- return "PixelFormat::HSV_888";
- case PixelFormat::IMPLEMENTATION_DEFINED:
- return "PixelFormat::IMPLEMENTATION_DEFINED";
- case PixelFormat::RAW10:
- return "PixelFormat::RAW10";
- case PixelFormat::RAW12:
- return "PixelFormat::RAW12";
- case PixelFormat::RAW16:
- return "PixelFormat::RAW16";
- case PixelFormat::RAW_OPAQUE:
- return "PixelFormat::RAW_OPAQUE";
- case PixelFormat::RGBA_1010102:
- return "PixelFormat::RGBA_1010102";
- case PixelFormat::RGBA_8888:
- return "PixelFormat::RGBA_8888";
- case PixelFormat::RGBA_FP16:
- return "PixelFormat::RGBA_FP16";
- case PixelFormat::RGBX_8888:
- return "PixelFormat::RGBX_8888";
- case PixelFormat::RGB_565:
- return "PixelFormat::RGB_565";
- case PixelFormat::RGB_888:
- return "PixelFormat::RGB_888";
- case PixelFormat::STENCIL_8:
- return "PixelFormat::STENCIL_8";
- case PixelFormat::Y16:
- return "PixelFormat::Y16";
- case PixelFormat::Y8:
- return "PixelFormat::Y8";
- case PixelFormat::YCBCR_420_888:
- return "PixelFormat::YCBCR_420_888";
- case PixelFormat::YCBCR_422_I:
- return "PixelFormat::YCBCR_422_I";
- case PixelFormat::YCBCR_422_SP:
- return "PixelFormat::YCBCR_422_SP";
- case PixelFormat::YCBCR_P010:
- return "PixelFormat::YCBCR_P010";
- case PixelFormat::YCRCB_420_SP:
- return "PixelFormat::YCRCB_420_SP";
- case PixelFormat::YV12:
- return "PixelFormat::YV12";
- }
- return android::base::StringPrintf("PixelFormat::Unknown(%d)", static_cast<uint32_t>(format));
-}
-
-std::string getUsageString(hidl_bitfield<BufferUsage> bufferUsage) {
- using Underlying = typename std::underlying_type<BufferUsage>::type;
-
- Underlying usage = static_cast<Underlying>(bufferUsage);
-
- std::vector<std::string> usages;
- if (usage & BufferUsage::CAMERA_INPUT) {
- usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_INPUT);
- usages.push_back("BufferUsage::CAMERA_INPUT");
- }
- if (usage & BufferUsage::CAMERA_OUTPUT) {
- usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_OUTPUT);
- usages.push_back("BufferUsage::CAMERA_OUTPUT");
- }
- if (usage & BufferUsage::COMPOSER_CURSOR) {
- usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_CURSOR);
- usages.push_back("BufferUsage::COMPOSER_CURSOR");
- }
- if (usage & BufferUsage::COMPOSER_OVERLAY) {
- usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_OVERLAY);
- usages.push_back("BufferUsage::COMPOSER_OVERLAY");
- }
- if (usage & BufferUsage::CPU_READ_OFTEN) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_OFTEN);
- usages.push_back("BufferUsage::CPU_READ_OFTEN");
- }
- if (usage & BufferUsage::CPU_READ_NEVER) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_NEVER);
- usages.push_back("BufferUsage::CPU_READ_NEVER");
- }
- if (usage & BufferUsage::CPU_READ_RARELY) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_RARELY);
- usages.push_back("BufferUsage::CPU_READ_RARELY");
- }
- if (usage & BufferUsage::CPU_WRITE_NEVER) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_NEVER);
- usages.push_back("BufferUsage::CPU_WRITE_NEVER");
- }
- if (usage & BufferUsage::CPU_WRITE_OFTEN) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_OFTEN);
- usages.push_back("BufferUsage::CPU_WRITE_OFTEN");
- }
- if (usage & BufferUsage::CPU_WRITE_RARELY) {
- usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_RARELY);
- usages.push_back("BufferUsage::CPU_WRITE_RARELY");
- }
- if (usage & BufferUsage::GPU_RENDER_TARGET) {
- usage &= ~static_cast<Underlying>(BufferUsage::GPU_RENDER_TARGET);
- usages.push_back("BufferUsage::GPU_RENDER_TARGET");
- }
- if (usage & BufferUsage::GPU_TEXTURE) {
- usage &= ~static_cast<Underlying>(BufferUsage::GPU_TEXTURE);
- usages.push_back("BufferUsage::GPU_TEXTURE");
- }
- if (usage & BufferUsage::PROTECTED) {
- usage &= ~static_cast<Underlying>(BufferUsage::PROTECTED);
- usages.push_back("BufferUsage::PROTECTED");
- }
- if (usage & BufferUsage::RENDERSCRIPT) {
- usage &= ~static_cast<Underlying>(BufferUsage::RENDERSCRIPT);
- usages.push_back("BufferUsage::RENDERSCRIPT");
- }
- if (usage & BufferUsage::VIDEO_DECODER) {
- usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_DECODER);
- usages.push_back("BufferUsage::VIDEO_DECODER");
- }
- if (usage & BufferUsage::VIDEO_ENCODER) {
- usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_ENCODER);
- usages.push_back("BufferUsage::VIDEO_ENCODER");
- }
- if (usage & BufferUsage::GPU_DATA_BUFFER) {
- usage &= ~static_cast<Underlying>(BufferUsage::GPU_DATA_BUFFER);
- usages.push_back("BufferUsage::GPU_DATA_BUFFER");
- }
- if (usage & BUFFER_USAGE_FRONT_RENDERING) {
- usage &= ~static_cast<Underlying>(BUFFER_USAGE_FRONT_RENDERING);
- usages.push_back("BUFFER_USAGE_FRONT_RENDERING");
- }
-
- if (usage) {
- usages.push_back(android::base::StringPrintf("UnknownUsageBits-%" PRIu64, usage));
- }
-
- return android::base::Join(usages, '|');
-}
-
-int convertToDrmFormat(PixelFormat format, uint32_t* outDrmFormat) {
- switch (format) {
- case PixelFormat::BGRA_8888:
- *outDrmFormat = DRM_FORMAT_ARGB8888;
- return 0;
- /**
- * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
- * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
- * equal to their size in bytes.
- */
- case PixelFormat::BLOB:
- *outDrmFormat = DRM_FORMAT_R8;
- return 0;
- case PixelFormat::DEPTH_16:
- return -EINVAL;
- case PixelFormat::DEPTH_24:
- return -EINVAL;
- case PixelFormat::DEPTH_24_STENCIL_8:
- return -EINVAL;
- case PixelFormat::DEPTH_32F:
- return -EINVAL;
- case PixelFormat::DEPTH_32F_STENCIL_8:
- return -EINVAL;
- case PixelFormat::HSV_888:
- return -EINVAL;
- case PixelFormat::IMPLEMENTATION_DEFINED:
- *outDrmFormat = DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
- return 0;
- case PixelFormat::RAW10:
- return -EINVAL;
- case PixelFormat::RAW12:
- return -EINVAL;
- case PixelFormat::RAW16:
- *outDrmFormat = DRM_FORMAT_R16;
- return 0;
- /* TODO use blob */
- case PixelFormat::RAW_OPAQUE:
- return -EINVAL;
- case PixelFormat::RGBA_1010102:
- *outDrmFormat = DRM_FORMAT_ABGR2101010;
- return 0;
- case PixelFormat::RGBA_8888:
- *outDrmFormat = DRM_FORMAT_ABGR8888;
- return 0;
- case PixelFormat::RGBA_FP16:
- *outDrmFormat = DRM_FORMAT_ABGR16161616F;
- return 0;
- case PixelFormat::RGBX_8888:
- *outDrmFormat = DRM_FORMAT_XBGR8888;
- return 0;
- case PixelFormat::RGB_565:
- *outDrmFormat = DRM_FORMAT_RGB565;
- return 0;
- case PixelFormat::RGB_888:
- *outDrmFormat = DRM_FORMAT_RGB888;
- return 0;
- case PixelFormat::STENCIL_8:
- return -EINVAL;
- case PixelFormat::Y16:
- *outDrmFormat = DRM_FORMAT_R16;
- return 0;
- case PixelFormat::Y8:
- *outDrmFormat = DRM_FORMAT_R8;
- return 0;
- case PixelFormat::YCBCR_420_888:
- *outDrmFormat = DRM_FORMAT_FLEX_YCbCr_420_888;
- return 0;
- case PixelFormat::YCBCR_422_SP:
- return -EINVAL;
- case PixelFormat::YCBCR_422_I:
- return -EINVAL;
- case PixelFormat::YCBCR_P010:
- *outDrmFormat = DRM_FORMAT_P010;
- return 0;
- case PixelFormat::YCRCB_420_SP:
- *outDrmFormat = DRM_FORMAT_NV21;
- return 0;
- case PixelFormat::YV12:
- *outDrmFormat = DRM_FORMAT_YVU420_ANDROID;
- return 0;
- };
- return -EINVAL;
-}
-
-int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage) {
- uint64_t bufferUsage = BO_USE_NONE;
-
- if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
- static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY)) {
- bufferUsage |= BO_USE_SW_READ_RARELY;
- }
- if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
- static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN)) {
- bufferUsage |= BO_USE_SW_READ_OFTEN;
- }
- if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
- static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY)) {
- bufferUsage |= BO_USE_SW_WRITE_RARELY;
- }
- if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
- static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN)) {
- bufferUsage |= BO_USE_SW_WRITE_OFTEN;
- }
- if (grallocUsage & BufferUsage::GPU_TEXTURE) {
- bufferUsage |= BO_USE_TEXTURE;
- }
- if (grallocUsage & BufferUsage::GPU_RENDER_TARGET) {
- bufferUsage |= BO_USE_RENDERING;
- }
- if (grallocUsage & BufferUsage::COMPOSER_OVERLAY) {
- /* HWC wants to use display hardware, but can defer to OpenGL. */
- bufferUsage |= BO_USE_SCANOUT | BO_USE_TEXTURE;
- }
- /* Map this flag to linear until real HW protection is available on Android. */
- if (grallocUsage & BufferUsage::PROTECTED) {
- bufferUsage |= BO_USE_LINEAR;
- }
- if (grallocUsage & BufferUsage::COMPOSER_CURSOR) {
- bufferUsage |= BO_USE_NONE;
- }
- if (grallocUsage & BufferUsage::VIDEO_ENCODER) {
- /*HACK: See b/30054495 */
- bufferUsage |= BO_USE_SW_READ_OFTEN;
- }
- if (grallocUsage & BufferUsage::CAMERA_OUTPUT) {
- bufferUsage |= BO_USE_CAMERA_WRITE;
- }
- if (grallocUsage & BufferUsage::CAMERA_INPUT) {
- bufferUsage |= BO_USE_CAMERA_READ;
- }
- if (grallocUsage & BufferUsage::RENDERSCRIPT) {
- bufferUsage |= BO_USE_RENDERSCRIPT;
- }
- if (grallocUsage & BufferUsage::VIDEO_DECODER) {
- bufferUsage |= BO_USE_HW_VIDEO_DECODER;
- }
- if (grallocUsage & BufferUsage::GPU_DATA_BUFFER) {
- bufferUsage |= BO_USE_GPU_DATA_BUFFER;
- }
- if (grallocUsage & BUFFER_USAGE_FRONT_RENDERING) {
- bufferUsage |= BO_USE_FRONT_RENDERING;
- }
-
- *outBufferUsage = bufferUsage;
- return 0;
-}
-
-int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage) {
- uint32_t mapUsage = BO_MAP_NONE;
-
- if (grallocUsage & BufferUsage::CPU_READ_MASK) {
- mapUsage |= BO_MAP_READ;
- }
- if (grallocUsage & BufferUsage::CPU_WRITE_MASK) {
- mapUsage |= BO_MAP_WRITE;
- }
-
- *outMapUsage = mapUsage;
- return 0;
-}
-
-int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor,
- struct cros_gralloc_buffer_descriptor* outCrosDescriptor) {
- outCrosDescriptor->width = descriptor.width;
- outCrosDescriptor->height = descriptor.height;
- outCrosDescriptor->droid_format = static_cast<int32_t>(descriptor.format);
- outCrosDescriptor->droid_usage = descriptor.usage;
- outCrosDescriptor->reserved_region_size = 0;
- if (descriptor.layerCount > 1) {
- drv_log("Failed to convert descriptor. Unsupported layerCount: %d\n",
- descriptor.layerCount);
- return -EINVAL;
- }
- if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
- std::string pixelFormatString = getPixelFormatString(descriptor.format);
- drv_log("Failed to convert descriptor. Unsupported format %s\n", pixelFormatString.c_str());
- return -EINVAL;
- }
- if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
- std::string usageString = getUsageString(descriptor.usage);
- drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
- return -EINVAL;
- }
- return 0;
-}
-
-int convertToFenceFd(const hidl_handle& fenceHandle, int* outFenceFd) {
- if (!outFenceFd) {
- return -EINVAL;
- }
-
- const native_handle_t* nativeHandle = fenceHandle.getNativeHandle();
- if (nativeHandle && nativeHandle->numFds > 1) {
- return -EINVAL;
- }
-
- *outFenceFd = (nativeHandle && nativeHandle->numFds == 1) ? nativeHandle->data[0] : -1;
- return 0;
-}
-
-int convertToFenceHandle(int fenceFd, hidl_handle* outFenceHandle) {
- if (!outFenceHandle) {
- return -EINVAL;
- }
- if (fenceFd < 0) {
- return 0;
- }
-
- NATIVE_HANDLE_DECLARE_STORAGE(handleStorage, 1, 0);
- auto fenceHandle = native_handle_init(handleStorage, 1, 0);
- fenceHandle->data[0] = fenceFd;
-
- *outFenceHandle = fenceHandle;
- return 0;
-}
-
-std::optional<BufferDescriptorInfo> decodeBufferDescriptorInfo(const hidl_vec<uint32_t>& encoded) {
- if (encoded.size() != 5) {
- drv_log("Failed to decodeBufferDescriptorInfo. Invalid size: %zd.\n", encoded.size());
- return {};
- }
-
- BufferDescriptorInfo descriptor;
- descriptor.width = encoded[0];
- descriptor.height = encoded[1];
- descriptor.layerCount = encoded[2];
- descriptor.format = static_cast<PixelFormat>(encoded[3]);
- descriptor.usage = encoded[4];
- return std::move(descriptor);
-}
-
-std::optional<hidl_vec<uint32_t>> encodeBufferDescriptorInfo(const BufferDescriptorInfo& info) {
- hidl_vec<uint32_t> encoded;
- encoded.resize(5);
- encoded[0] = info.width;
- encoded[1] = info.height;
- encoded[2] = info.layerCount;
- encoded[3] = static_cast<uint32_t>(info.format);
- encoded[4] = info.usage & std::numeric_limits<uint32_t>::max();
- return std::move(encoded);
-}
diff --git a/cros_gralloc/gralloc3/CrosGralloc3Utils.h b/cros_gralloc/gralloc3/CrosGralloc3Utils.h
deleted file mode 100644
index 0492568..0000000
--- a/cros_gralloc/gralloc3/CrosGralloc3Utils.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <optional>
-#include <string>
-#include <vector>
-
-#include <android/hardware/graphics/common/1.2/types.h>
-#include <android/hardware/graphics/mapper/3.0/IMapper.h>
-
-std::string getPixelFormatString(android::hardware::graphics::common::V1_2::PixelFormat format);
-
-std::string getUsageString(
- android::hardware::hidl_bitfield<android::hardware::graphics::common::V1_2::BufferUsage>
- usage);
-
-int convertToDrmFormat(android::hardware::graphics::common::V1_2::PixelFormat format,
- uint32_t* outDrmFormat);
-
-int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage);
-
-int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage);
-
-int convertToCrosDescriptor(
- const android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo& descriptor,
- struct cros_gralloc_buffer_descriptor* outCrosDescriptor);
-
-int convertToFenceFd(const android::hardware::hidl_handle& fence_handle, int* out_fence_fd);
-
-int convertToFenceHandle(int fence_fd, android::hardware::hidl_handle* out_fence_handle);
-
-std::optional<android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo>
-decodeBufferDescriptorInfo(const android::hardware::hidl_vec<uint32_t>& encoded);
-
-std::optional<android::hardware::hidl_vec<uint32_t>> encodeBufferDescriptorInfo(
- const android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo& info);
diff --git a/cros_gralloc/gralloc3/android.hardware.graphics.allocator@3.0-service.minigbm.rc b/cros_gralloc/gralloc3/android.hardware.graphics.allocator@3.0-service.minigbm.rc
deleted file mode 100644
index 7377cee..0000000
--- a/cros_gralloc/gralloc3/android.hardware.graphics.allocator@3.0-service.minigbm.rc
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# Copyright 2020 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-
-service vendor.graphics.allocator-3-0 /vendor/bin/hw/android.hardware.graphics.allocator@3.0-service.minigbm
- interface android.hardware.graphics.allocator@3.0::IAllocator default
- class hal animation
- user system
- group graphics drmrpc
- capabilities SYS_NICE
- onrestart restart surfaceflinger
- writepid /dev/cpuset/system-background/tasks