Snap for 13017112 from 799e7c29d9b5b1ef438f6e787ab2f7a3f827a95a to 25Q2-release
Change-Id: I687708a690cb6301c1898232594a1b119a0db85f
diff --git a/common/sensor_listener/Android.bp b/common/sensor_listener/Android.bp
index 1fdefb8..b02abf5 100644
--- a/common/sensor_listener/Android.bp
+++ b/common/sensor_listener/Android.bp
@@ -7,7 +7,6 @@
name: "lib_sensor_listener",
vendor: true,
owner: "google",
- host_supported: true,
srcs: [
"goog_gyro_direct.cc",
@@ -23,7 +22,6 @@
cflags: [
"-Werror",
- "-Wall",
"-Wthread-safety",
"-Wno-unused-parameter",
"-Wno-unused-function",
@@ -31,22 +29,20 @@
],
header_libs: [
"libhardware_headers",
+ "//hardware/google/graphics/common/gralloc-headers:pixel-gralloc-headers",
],
shared_libs: [
"android.frameworks.sensorservice@1.0",
- "android.hardware.graphics.allocator@3.0",
- "android.hardware.graphics.mapper@3.0",
"android.hardware.sensors@1.0",
- "android.hidl.allocator@1.0",
"libbase",
"libcutils",
"libhidlbase",
"liblog",
+ "libui",
"libutils",
],
export_shared_lib_headers: [
"android.frameworks.sensorservice@1.0",
- "android.hardware.graphics.allocator@3.0",
],
}
@@ -67,6 +63,7 @@
shared_libs: [
"libbinder",
"liblog",
+ "libui",
"libutils",
"lib_sensor_listener",
],
diff --git a/common/sensor_listener/goog_gralloc_wrapper.cc b/common/sensor_listener/goog_gralloc_wrapper.cc
index df30bf7..948ef4e 100644
--- a/common/sensor_listener/goog_gralloc_wrapper.cc
+++ b/common/sensor_listener/goog_gralloc_wrapper.cc
@@ -23,25 +23,9 @@
namespace android {
namespace camera_sensor_listener {
-using ::android::hardware::hidl_handle;
-using ::android::hardware::graphics::allocator::V3_0::IAllocator;
-using ::android::hardware::graphics::mapper::V3_0::BufferDescriptor;
-using ::android::hardware::graphics::mapper::V3_0::Error;
-using ::android::hardware::graphics::mapper::V3_0::IMapper;
-
-GoogGrallocWrapper::GoogGrallocWrapper() {
- allocator_ = IAllocator::getService();
- if (allocator_ == nullptr) {
- ALOGE("%s %d Failed to get allocator service", __func__, __LINE__);
- }
-
- mapper_ = IMapper::getService();
- if (mapper_ == nullptr) {
- ALOGE("%s %d Failed to get mapper service", __func__, __LINE__);
- }
- if (mapper_->isRemote()) {
- ALOGE("%s %d Mapper is not in passthrough mode", __func__, __LINE__);
- }
+GoogGrallocWrapper::GoogGrallocWrapper()
+ : allocator_(GraphicBufferAllocator::get()),
+ mapper_(GraphicBufferMapper::get()) {
}
GoogGrallocWrapper::~GoogGrallocWrapper() {
@@ -54,198 +38,121 @@
for (auto buffer_handle : imported_buffers_) {
auto buffer = const_cast<native_handle_t*>(buffer_handle);
- if (mapper_->freeBuffer(buffer) != Error::NONE) {
- ALOGE("%s %d Failed to free buffer %p", __func__, __LINE__, buffer);
+ if (status_t status = mapper_.freeBuffer(buffer); status != OK) {
+ ALOGE("%s: Failed to free buffer %p: %s", __FUNCTION__, buffer,
+ statusToString(status).c_str());
}
}
imported_buffers_.clear();
}
-sp<IAllocator> GoogGrallocWrapper::GetAllocator() const {
+GraphicBufferAllocator& GoogGrallocWrapper::GetAllocator() const {
return allocator_;
}
std::string GoogGrallocWrapper::DumpDebugInfo() const {
std::string debug_info;
- allocator_->dumpDebugInfo([&debug_info](const auto& tmp_debug_info) {
- debug_info = tmp_debug_info.c_str();
- });
-
+ allocator_.dump(debug_info);
return debug_info;
}
-const native_handle_t* GoogGrallocWrapper::CloneBuffer(
- const hidl_handle& raw_handle) {
- const native_handle_t* buffer_handle =
- native_handle_clone(raw_handle.getNativeHandle());
-
- if (buffer_handle) {
- cloned_buffers_.insert(buffer_handle);
- }
- return buffer_handle;
-}
-
// When import is false, this simply calls IAllocator::allocate. When import
// is true, the returned buffers are also imported into the mapper.
// Either case, the returned buffers must be freed with freeBuffer.
std::vector<const native_handle_t*> GoogGrallocWrapper::Allocate(
- const BufferDescriptor& descriptor, uint32_t count, bool import,
- uint32_t* out_stride) {
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layer_count,
+ uint64_t usage, uint32_t buffer_count, bool import, uint32_t* out_stride) {
std::vector<const native_handle_t*> buffer_handles;
- buffer_handles.reserve(count);
- allocator_->allocate(
- descriptor, count,
- [&](const auto& tmp_error, const auto& tmp_stride,
- const auto& tmp_buffers) {
- if (tmp_error != Error::NONE) {
- ALOGE("%s %d Failed to allocate buffers", __func__, __LINE__);
- }
- if (count != tmp_buffers.size()) {
- ALOGE("%s %d Invalid buffer array", __func__, __LINE__);
- }
-
- for (uint32_t i = 0; i < count; i++) {
- if (import) {
- buffer_handles.push_back(ImportBuffer(tmp_buffers[i]));
- } else {
- buffer_handles.push_back(CloneBuffer(tmp_buffers[i]));
- }
- }
-
- if (out_stride) {
- *out_stride = tmp_stride;
- }
- });
+ buffer_handles.reserve(buffer_count);
+ for (int i = 0; i < buffer_count; ++i) {
+ buffer_handle_t handle = nullptr;
+ if (import) {
+ allocator_.allocate(width, height, format, layer_count, usage, &handle,
+ out_stride, "SensorListener");
+ if (handle != nullptr) {
+ imported_buffers_.insert(handle);
+ }
+ } else {
+ allocator_.allocateRawHandle(width, height, format, layer_count, usage,
+ &handle, out_stride, "SensorListener");
+ if (handle != nullptr) {
+ cloned_buffers_.insert(handle);
+ }
+ }
+ buffer_handles.push_back(handle);
+ }
return buffer_handles;
}
const native_handle_t* GoogGrallocWrapper::AllocateOneBuffer(
- const IMapper::BufferDescriptorInfo& descriptor_info, bool import,
- uint32_t* out_stride) {
- BufferDescriptor descriptor = CreateDescriptor(descriptor_info);
- auto buffers = Allocate(descriptor, 1, import, out_stride);
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layer_count,
+ uint64_t usage, bool import, uint32_t* out_stride) {
+ auto buffers = Allocate(width, height, format, layer_count, usage,
+ /*buffer_count=*/1, import, out_stride);
return buffers[0];
}
-sp<IMapper> GoogGrallocWrapper::GetMapper() const {
+GraphicBufferMapper& GoogGrallocWrapper::GetMapper() const {
return mapper_;
}
-BufferDescriptor GoogGrallocWrapper::CreateDescriptor(
- const IMapper::BufferDescriptorInfo& descriptor_info) {
- BufferDescriptor descriptor;
- mapper_->createDescriptor(
- descriptor_info,
- [&descriptor](const auto& tmp_error, const auto& tmp_descriptor) {
- if (tmp_error != Error::NONE) {
- ALOGE("Failed to create descriptor");
- }
- descriptor = tmp_descriptor;
- });
-
- return descriptor;
-}
-
-const native_handle_t* GoogGrallocWrapper::ImportBuffer(
- const hidl_handle& raw_handle) {
- const native_handle_t* buffer_handle = nullptr;
- mapper_->importBuffer(
- raw_handle, [&buffer_handle, &raw_handle](const auto& tmp_error,
- const auto& tmp_buffer) {
- if (tmp_error != Error::NONE) {
- ALOGE("%s %d Failed to import buffer %p", __func__, __LINE__,
- raw_handle.getNativeHandle());
- }
- buffer_handle = static_cast<const native_handle_t*>(tmp_buffer);
- });
-
- if (buffer_handle) {
- imported_buffers_.insert(buffer_handle);
- }
-
- return buffer_handle;
-}
-
void GoogGrallocWrapper::FreeBuffer(const native_handle_t* buffer_handle) {
auto buffer = const_cast<native_handle_t*>(buffer_handle);
if (imported_buffers_.erase(buffer_handle)) {
- Error error = mapper_->freeBuffer(buffer);
- if (error != Error::NONE) {
- ALOGE("%s %d Failed to free %p", __func__, __LINE__, buffer);
+ if (status_t status = mapper_.freeBuffer(buffer); status != OK) {
+ ALOGE("%s: Failed to free %p: %s", __FUNCTION__, buffer,
+ statusToString(status).c_str());
}
- } else {
- cloned_buffers_.erase(buffer_handle);
+ } else if (cloned_buffers_.erase(buffer_handle)) {
native_handle_close(buffer);
native_handle_delete(buffer);
+ } else {
+ ALOGE("%s: buffer %p is not in cloned_buffers_ or imported_buffers_",
+ __FUNCTION__, buffer);
}
}
-// We use fd instead of ::android::hardware::hidl_handle in these functions to
-// pass fences in and out of the mapper. The ownership of the fd is always
-// transferred with each of these functions.
+// We use fd to pass fences in and out of the mapper. The ownership of the fd
+// is always transferred with each of these functions.
void* GoogGrallocWrapper::Lock(const native_handle_t* buffer_handle,
- uint64_t cpu_usage,
- const IMapper::Rect& access_region,
+ uint64_t cpu_usage, const Rect& access_region,
int acquire_fence) {
auto buffer = const_cast<native_handle_t*>(buffer_handle);
-
- NATIVE_HANDLE_DECLARE_STORAGE(acquire_fence_storage, 1, 0);
- hidl_handle acquire_fence_handle;
- if (acquire_fence >= 0) {
- auto h = native_handle_init(acquire_fence_storage, 1, 0);
- h->data[0] = acquire_fence;
- acquire_fence_handle = h;
+ if (!imported_buffers_.contains(buffer)) {
+ ALOGE("%s: buffer %p is not imported", __FUNCTION__, buffer);
+ return nullptr;
}
- void* data = nullptr;
- mapper_->lock(buffer, cpu_usage, access_region, acquire_fence_handle,
- [&buffer, &data](const auto& tmp_error, const auto& tmp_data,
- const auto& /*bytesPerPixel*/,
- const auto& /*bytesPerStride*/) {
- if (tmp_error != Error::NONE) {
- ALOGE("Failed to lock buffer %p", buffer);
- } else {
- data = tmp_data;
- }
- });
+ void* locked_buffer = nullptr;
+ status_t status = mapper_.lockAsync(buffer, cpu_usage, access_region,
+ &locked_buffer, acquire_fence);
+ if (status != OK) {
+ ALOGE("%s: Failed to lock buffer %p: %s", __FUNCTION__, buffer,
+ statusToString(status).c_str());
+ }
if (acquire_fence >= 0) {
close(acquire_fence);
}
- return data;
+ return locked_buffer;
}
int GoogGrallocWrapper::Unlock(const native_handle_t* buffer_handle) {
auto buffer = const_cast<native_handle_t*>(buffer_handle);
+ if (!imported_buffers_.contains(buffer)) {
+ ALOGE("%s: buffer %p is not imported", __FUNCTION__, buffer);
+ return -1;
+ }
int release_fence = -1;
- mapper_->unlock(buffer,
- [&buffer, &release_fence](const auto& tmp_error,
- const auto& tmp_release_fence) {
- if (tmp_error != Error::NONE) {
- ALOGE("Failed to unlock buffer %p", buffer);
- }
-
- auto fence_handle = tmp_release_fence.getNativeHandle();
- if (fence_handle) {
- if (fence_handle->numInts != 0) {
- ALOGE("Invalid fence handle %p", fence_handle);
- }
- if (fence_handle->numFds == 1) {
- release_fence = dup(fence_handle->data[0]);
- if (release_fence < 0) {
- ALOGE("Failed to dup fence fd");
- }
- } else {
- if (fence_handle->numFds != 0) {
- ALOGE("Invalid fence handle %p", fence_handle);
- }
- }
- }
- });
+ status_t status = mapper_.unlockAsync(buffer, &release_fence);
+ if (status != OK) {
+ ALOGE("%s: Failed to unlock buffer %p: %s", __FUNCTION__, buffer,
+ statusToString(status).c_str());
+ }
return release_fence;
}
diff --git a/common/sensor_listener/goog_gralloc_wrapper.h b/common/sensor_listener/goog_gralloc_wrapper.h
index 02755e4..82affd5 100644
--- a/common/sensor_listener/goog_gralloc_wrapper.h
+++ b/common/sensor_listener/goog_gralloc_wrapper.h
@@ -17,23 +17,21 @@
#ifndef VENDOR_GOOGLE_CAMERA_SENSOR_LISTENER_GOOG_GRALLOC_WRAPPER_H_
#define VENDOR_GOOGLE_CAMERA_SENSOR_LISTENER_GOOG_GRALLOC_WRAPPER_H_
-#include <unordered_set>
-
#include <android/frameworks/sensorservice/1.0/ISensorManager.h>
-#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
-#include <android/hardware/graphics/mapper/3.0/IMapper.h>
#include <sys/mman.h>
+#include <ui/GraphicBufferAllocator.h>
+#include <ui/GraphicBufferMapper.h>
#include <utils/StrongPointer.h>
+#include <unordered_set>
+
namespace android {
namespace camera_sensor_listener {
// GoogGrallocWrapper is a wrapper class to
-// ::android::hardware::graphics::allocator::V3_0::IAllocator and
-// ::android::hardware::graphics::mapper::V3_0::IMapper.
+// ::android::GraphicBufferAllocator and
+// ::android::GraphicBufferMapper.
// It can used by direct channel based sensor listener class.
-// Modified from //hardware/interfaces/graphics/mapper/2.0/utils/vts
-// /include/mapper-vts/2.0/MapperVts.h.
class GoogGrallocWrapper {
public:
// Constructor.
@@ -42,60 +40,44 @@
// Destructor.
~GoogGrallocWrapper();
- // Get StrongPointer to IAllocator.
- sp<::android::hardware::graphics::allocator::V3_0::IAllocator> GetAllocator()
- const;
+ // Get the reference of GraphicBufferAllocator.
+ GraphicBufferAllocator& GetAllocator() const;
// Wrapper of IAllocator dumpDebugInfo method.
std::string DumpDebugInfo() const;
- // Wrapper of IAllocator allocate method.
+ // Wrapper of GraphicBufferAllocator::allocate and
+ // GraphicBufferAllocator::allocateRawHandle.
std::vector<const native_handle_t*> Allocate(
- const ::android::hardware::graphics::mapper::V3_0::BufferDescriptor&
- descriptor,
- uint32_t count, bool import = true, uint32_t* out_stride = nullptr);
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layer_count,
+ uint64_t usage, uint32_t buffer_count, bool import = true,
+ uint32_t* out_stride = nullptr);
// Special case of Allocate, where allocated buffer count is 1.
- const native_handle_t* AllocateOneBuffer(
- const ::android::hardware::graphics::mapper::V3_0::IMapper::
- BufferDescriptorInfo& descriptor_info,
- bool import = true, uint32_t* out_stride = nullptr);
+ const native_handle_t* AllocateOneBuffer(uint32_t width, uint32_t height,
+ PixelFormat format,
+ uint32_t layer_count, uint64_t usage,
+ bool import = true,
+ uint32_t* out_stride = nullptr);
- // Get StrongPointer to IMapper.
- sp<::android::hardware::graphics::mapper::V3_0::IMapper> GetMapper() const;
+ // Get the reference of GraphicBufferMapper.
+ GraphicBufferMapper& GetMapper() const;
- // Wrapper of IMapper createDescriptor method.
- ::android::hardware::graphics::mapper::V3_0::BufferDescriptor CreateDescriptor(
- const ::android::hardware::graphics::mapper::V3_0::IMapper::
- BufferDescriptorInfo& descriptor_info);
-
- // Wrapper of IMapper importBuffer method.
- const native_handle_t* ImportBuffer(
- const ::android::hardware::hidl_handle& raw_handle);
-
- // Wrapper of IMapper freeBuffer method.
+ // Wrapper of GraphicBufferMapper::freeBuffer.
void FreeBuffer(const native_handle_t* buffer_handle);
- // Wrapper of Imapper lock method.
- // We use fd instead of hardware::hidl_handle in these functions to pass
- // fences in and out of the mapper. The ownership of the fd is always
- // transferred with each of these functions.
+ // Wrapper of GraphicBufferMapper::lockAsync.
+ // We use fd to pass fences in and out of the mapper. The ownership of the fd
+ // is always transferred with each of these functions.
void* Lock(const native_handle_t* buffer_handle, uint64_t cpu_usage,
- const ::android::hardware::graphics::mapper::V3_0::IMapper::Rect&
- access_region,
- int acquire_fence);
+ const Rect& access_region, int acquire_fence);
- // Wrapper of Imapper unlock method.
+ // Wrapper of GraphicBufferMapper::unlockAsync.
int Unlock(const native_handle_t* buffer_handle);
private:
- const native_handle_t* CloneBuffer(const hardware::hidl_handle& raw_handle);
-
- // StrongPointer to IAllocator.
- sp<::android::hardware::graphics::allocator::V3_0::IAllocator> allocator_;
-
- // StrongPointer to IMapper.
- sp<::android::hardware::graphics::mapper::V3_0::IMapper> mapper_;
+ GraphicBufferAllocator& allocator_;
+ GraphicBufferMapper& mapper_;
// Set of cloned buffer handles.
// Keep track of all cloned and imported handles. When a test fails with
diff --git a/common/sensor_listener/goog_gyro_direct.cc b/common/sensor_listener/goog_gyro_direct.cc
index f19290f..30b0e9d 100644
--- a/common/sensor_listener/goog_gyro_direct.cc
+++ b/common/sensor_listener/goog_gyro_direct.cc
@@ -16,23 +16,23 @@
#define LOG_TAG "goog_gyro_direct"
+#include "goog_gyro_direct.h"
+
#include <android/frameworks/sensorservice/1.0/ISensorManager.h>
#include <android/frameworks/sensorservice/1.0/types.h>
#include <android/hardware/sensors/1.0/types.h>
#include <hardware/sensors.h>
+#include <pixel-gralloc/usage.h>
#include <utils/Log.h>
#include <utils/SystemClock.h>
#include "goog_gralloc_wrapper.h"
-#include "goog_gyro_direct.h"
-
namespace android {
namespace camera_sensor_listener {
using ::android::frameworks::sensorservice::V1_0::ISensorManager;
using ::android::frameworks::sensorservice::V1_0::Result;
-using ::android::hardware::graphics::mapper::V3_0::IMapper;
using ::android::hardware::sensors::V1_0::RateLevel;
using ::android::hardware::sensors::V1_0::SensorFlagBits;
using ::android::hardware::sensors::V1_0::SensorsEventFormatOffset;
@@ -137,30 +137,22 @@
size_t buffer_size =
static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH) *
gyro_direct_buf_length_;
-
- using android::hardware::graphics::common::V1_0::BufferUsage;
- using android::hardware::graphics::common::V1_2::PixelFormat;
- IMapper::BufferDescriptorInfo buf_desc_info = {
- .width = static_cast<uint32_t>(buffer_size),
- .height = 1,
- .layerCount = 1,
- .format = PixelFormat::BLOB,
- .usage = static_cast<uint64_t>(BufferUsage::SENSOR_DIRECT_DATA |
- BufferUsage::CPU_READ_OFTEN),
- };
-
+ uint32_t width = buffer_size;
+ uint32_t height = 1;
+ uint64_t usage =
+ pixel::graphics::SENSOR_DIRECT_DATA | pixel::graphics::CPU_READ_OFTEN;
gyro_direct_channel_native_buf_handle_ =
- goog_gralloc_wrapper_ptr_->AllocateOneBuffer(buf_desc_info);
+ goog_gralloc_wrapper_ptr_->AllocateOneBuffer(
+ width, height, HAL_PIXEL_FORMAT_BLOB, /*layer_count=*/1, usage);
if (gyro_direct_channel_native_buf_handle_ == nullptr) {
ALOGE("%s %d Failed at allocating the channel native buffer", __func__,
__LINE__);
return NO_MEMORY;
}
- IMapper::Rect region{0, 0, static_cast<int32_t>(buf_desc_info.width),
- static_cast<int32_t>(buf_desc_info.height)};
+ Rect region(/*l=*/0, /*t=*/0, /*r=*/width, /*b=*/height);
gyro_direct_channel_addr_ = goog_gralloc_wrapper_ptr_->Lock(
- gyro_direct_channel_native_buf_handle_, buf_desc_info.usage, region,
+ gyro_direct_channel_native_buf_handle_, usage, region,
/*fence=*/-1);
if (gyro_direct_channel_addr_ == nullptr) {
goog_gralloc_wrapper_ptr_->FreeBuffer(