summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevika Krishnadas <kdevika@google.com>2023-09-19 23:26:28 +0000
committerDevika Krishnadas <kdevika@google.com>2023-11-08 01:57:34 +0000
commit8e6973cbaabd9c038e69082699d330462492463d (patch)
tree50f056e35b969ab52fb8cd8e54981f4c30f2eca4
parent1b0e72747646b4443dc62046d01cfe45d525228e (diff)
downloadgchips-8e6973cbaabd9c038e69082699d330462492463d.tar.gz
Revert^2 "gralloc4: Upgrade Allocator to AIDL2"
b04e88e3f68b9d6f42bbde910756380386663a68 Bug: 287353739 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: I11acdf0240f7429c41697745201438fd17c403f5
-rw-r--r--gralloc4/service/aidl/Android.bp4
-rw-r--r--gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc2
-rw-r--r--gralloc4/service/aidl/manifest_gralloc_aidl.xml1
-rw-r--r--gralloc4/src/aidl/Android.bp2
-rw-r--r--gralloc4/src/aidl/GrallocAllocator.cpp89
-rw-r--r--gralloc4/src/aidl/GrallocAllocator.h11
-rw-r--r--gralloc4/src/hidl_common/Allocator.cpp5
-rw-r--r--gralloc4/src/hidl_common/Allocator.h2
8 files changed, 111 insertions, 5 deletions
diff --git a/gralloc4/service/aidl/Android.bp b/gralloc4/service/aidl/Android.bp
index a3d7a87..ea6e461 100644
--- a/gralloc4/service/aidl/Android.bp
+++ b/gralloc4/service/aidl/Android.bp
@@ -3,7 +3,7 @@ package {
}
cc_binary {
- name: "android.hardware.graphics.allocator-V1-service",
+ name: "android.hardware.graphics.allocator-V2-service",
proprietary: true,
relative_install_path: "hw",
srcs: [
@@ -17,7 +17,7 @@ cc_binary {
"libgralloc_headers",
],
shared_libs: [
- "android.hardware.graphics.allocator-V1-ndk",
+ "android.hardware.graphics.allocator-V2-ndk",
"android.hardware.graphics.allocator-aidl-impl",
"libbinder_ndk",
"liblog",
diff --git a/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc b/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
index e86b68d..723fab6 100644
--- a/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
+++ b/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
@@ -1,4 +1,4 @@
-service vendor.graphics.allocator-default /vendor/bin/hw/android.hardware.graphics.allocator-V1-service
+service vendor.graphics.allocator-default /vendor/bin/hw/android.hardware.graphics.allocator-V2-service
class hal animation
user system
group graphics drmrpc
diff --git a/gralloc4/service/aidl/manifest_gralloc_aidl.xml b/gralloc4/service/aidl/manifest_gralloc_aidl.xml
index 6848a99..c29d370 100644
--- a/gralloc4/service/aidl/manifest_gralloc_aidl.xml
+++ b/gralloc4/service/aidl/manifest_gralloc_aidl.xml
@@ -1,6 +1,7 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.graphics.allocator</name>
+ <version>2</version>
<fqname>IAllocator/default</fqname>
</hal>
</manifest>
diff --git a/gralloc4/src/aidl/Android.bp b/gralloc4/src/aidl/Android.bp
index e2d9d04..3c0fc26 100644
--- a/gralloc4/src/aidl/Android.bp
+++ b/gralloc4/src/aidl/Android.bp
@@ -10,7 +10,7 @@ cc_library_shared {
"arm_gralloc_api_4x_defaults",
],
shared_libs: [
- "android.hardware.graphics.allocator-V1-ndk",
+ "android.hardware.graphics.allocator-V2-ndk",
"android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.mapper@4.0",
"libbinder_ndk",
diff --git a/gralloc4/src/aidl/GrallocAllocator.cpp b/gralloc4/src/aidl/GrallocAllocator.cpp
index fb1d5b7..8e82036 100644
--- a/gralloc4/src/aidl/GrallocAllocator.cpp
+++ b/gralloc4/src/aidl/GrallocAllocator.cpp
@@ -7,7 +7,6 @@
#include <cutils/android_filesystem_config.h>
#include <hidl/HidlSupport.h>
-#include "allocator/mali_gralloc_ion.h"
#include "hidl_common/Allocator.h"
namespace pixel::allocator {
@@ -88,6 +87,94 @@ ndk::ScopedAStatus GrallocAllocator::allocate(const std::vector<uint8_t>& descri
return ndk::ScopedAStatus::ok();
}
+buffer_descriptor_t decodeBufferDescriptorInfo(
+ const AidlAllocator::BufferDescriptorInfo& descriptor) {
+ buffer_descriptor_t bufferDescriptor;
+ bufferDescriptor.width = descriptor.width;
+ bufferDescriptor.height = descriptor.height;
+ bufferDescriptor.layer_count = descriptor.layerCount;
+ bufferDescriptor.hal_format = static_cast<uint64_t>(descriptor.format);
+ bufferDescriptor.producer_usage = static_cast<uint64_t>(descriptor.usage);
+ bufferDescriptor.consumer_usage = bufferDescriptor.producer_usage;
+ bufferDescriptor.format_type = MALI_GRALLOC_FORMAT_TYPE_USAGE;
+ bufferDescriptor.signature = sizeof(buffer_descriptor_t);
+ bufferDescriptor.reserved_size = descriptor.reservedSize;
+ const char *str = (const char*) descriptor.name.data();
+ bufferDescriptor.name = std::string(str);
+ return bufferDescriptor;
+}
+
+ndk::ScopedAStatus GrallocAllocator::allocate2(
+ const AidlAllocator::BufferDescriptorInfo& descriptor, int32_t count,
+ AidlAllocator::AllocationResult* result) {
+ MALI_GRALLOC_LOGV("Allocation request from process: %lu", callingPid());
+
+ buffer_descriptor_t bufferDescriptor = decodeBufferDescriptorInfo(descriptor);
+
+ HidlError error = HidlError::NONE;
+ auto hidl_cb = [&](HidlError _error, int _stride, hidl_vec<hidl_handle> _buffers) {
+ if (_error != HidlError::NONE) {
+ error = _error;
+ return;
+ }
+
+ const uint32_t size = _buffers.size();
+
+ result->stride = _stride;
+ result->buffers.resize(size);
+ for (uint32_t i = 0; i < size; i++) {
+ // Dup here is necessary. After this callback returns common::allocate
+ // will free the buffer which will destroy the older fd.
+ result->buffers[i] = android::dupToAidl(static_cast<const native_handle*>(_buffers[i]));
+ }
+ };
+
+ arm::allocator::common::allocate(bufferDescriptor, count, hidl_cb);
+
+ switch (error) {
+ case HidlError::NONE:
+ break;
+
+ case HidlError::BAD_DESCRIPTOR:
+ return ndk::ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(AidlAllocator::AllocationError::BAD_DESCRIPTOR));
+
+ case HidlError::NO_RESOURCES:
+ return ndk::ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(AidlAllocator::AllocationError::NO_RESOURCES));
+
+ case HidlError::UNSUPPORTED:
+ return ndk::ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(AidlAllocator::AllocationError::UNSUPPORTED));
+
+ default:
+ return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
+ }
+
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus GrallocAllocator::isSupported(
+ const AidlAllocator::BufferDescriptorInfo& descriptor, bool* result) {
+ buffer_descriptor_t bufferDescriptor = decodeBufferDescriptorInfo(descriptor);
+
+ int isBufferDescriptorSupported = arm::allocator::common::isSupported(&bufferDescriptor);
+ *result = isBufferDescriptorSupported;
+
+ if (isBufferDescriptorSupported) {
+ MALI_GRALLOC_LOGV("Allocation for the given description will not succeed. error %d",
+ isBufferDescriptorSupported);
+ return ndk::ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(AidlAllocator::AllocationError::UNSUPPORTED));
+ }
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus GrallocAllocator::getIMapperLibrarySuffix(std::string* result) {
+ *result = "";
+ return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
+}
+
binder_status_t GrallocAllocator::dump(int fd, const char** /* args */, uint32_t numArgs) {
if (callingUid() != AID_ROOT) {
const std::string permission_denied = "Permission Denied\n";
diff --git a/gralloc4/src/aidl/GrallocAllocator.h b/gralloc4/src/aidl/GrallocAllocator.h
index dadd4b9..91655a7 100644
--- a/gralloc4/src/aidl/GrallocAllocator.h
+++ b/gralloc4/src/aidl/GrallocAllocator.h
@@ -2,9 +2,11 @@
#include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
#include <aidl/android/hardware/graphics/allocator/BnAllocator.h>
+#include <aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.h>
#include <aidlcommonsupport/NativeHandle.h>
#include <cstdint>
+#include <string>
#include <vector>
namespace pixel {
@@ -21,6 +23,15 @@ public:
virtual ndk::ScopedAStatus allocate(const std::vector<uint8_t>& descriptor, int32_t count,
AidlAllocator::AllocationResult* result) override;
+ virtual ndk::ScopedAStatus allocate2(const AidlAllocator::BufferDescriptorInfo& descriptor,
+ int32_t count,
+ AidlAllocator::AllocationResult* result) override;
+
+ virtual ndk::ScopedAStatus isSupported(const AidlAllocator::BufferDescriptorInfo& descriptor,
+ bool* result) override;
+
+ virtual ndk::ScopedAStatus getIMapperLibrarySuffix(std::string* result) override;
+
virtual binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
};
diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp
index d854255..08f2e8e 100644
--- a/gralloc4/src/hidl_common/Allocator.cpp
+++ b/gralloc4/src/hidl_common/Allocator.cpp
@@ -245,6 +245,11 @@ const std::string dump() {
return ss.str();
}
+int isSupported(buffer_descriptor_t *const bufDescriptor) {
+ // this is used as the criteria to determine which allocations succeed.
+ return mali_gralloc_derive_format_and_size(bufDescriptor);
+}
+
} // namespace common
} // namespace allocator
} // namespace arm
diff --git a/gralloc4/src/hidl_common/Allocator.h b/gralloc4/src/hidl_common/Allocator.h
index 079457c..e5ce174 100644
--- a/gralloc4/src/hidl_common/Allocator.h
+++ b/gralloc4/src/hidl_common/Allocator.h
@@ -56,6 +56,8 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
const std::string dump();
+int isSupported(buffer_descriptor_t *const bufDescriptor);
+
} // namespace common
} // namespace allocator
} // namespace arm