summaryrefslogtreecommitdiff
path: root/src/android/mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/mm')
-rw-r--r--src/android/mm/cros_camera_buffer.cpp2
-rw-r--r--src/android/mm/cros_frame_buffer_allocator.cpp18
-rw-r--r--src/android/mm/generic_camera_buffer.cpp2
-rw-r--r--src/android/mm/generic_frame_buffer_allocator.cpp27
-rw-r--r--src/android/mm/libhardware_stub.c17
-rw-r--r--src/android/mm/meson.build8
6 files changed, 53 insertions, 21 deletions
diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
index 2ac3dc4a..e2a44a2a 100644
--- a/src/android/mm/cros_camera_buffer.cpp
+++ b/src/android/mm/cros_camera_buffer.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2021, Google Inc.
*
- * cros_camera_buffer.cpp - Chromium OS buffer backend using CameraBufferManager
+ * Chromium OS buffer backend using CameraBufferManager
*/
#include "../camera_buffer.h"
diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp
index 52e8c180..264c0d48 100644
--- a/src/android/mm/cros_frame_buffer_allocator.cpp
+++ b/src/android/mm/cros_frame_buffer_allocator.cpp
@@ -2,8 +2,7 @@
/*
* Copyright (C) 2021, Google Inc.
*
- * cros_frame_buffer.cpp - Allocate FrameBuffer for Chromium OS using
- * CameraBufferManager
+ * Allocate FrameBuffer for Chromium OS using CameraBufferManager
*/
#include <memory>
@@ -16,6 +15,7 @@
#include "../camera_device.h"
#include "../frame_buffer_allocator.h"
+#include "../hal_framebuffer.h"
#include "cros-camera/camera_buffer_manager.h"
using namespace libcamera;
@@ -28,8 +28,9 @@ class CrosFrameBufferData : public FrameBuffer::Private
LIBCAMERA_DECLARE_PUBLIC(FrameBuffer)
public:
- CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle)
- : FrameBuffer::Private(), scopedHandle_(std::move(scopedHandle))
+ CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle,
+ const std::vector<FrameBuffer::Plane> &planes)
+ : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle))
{
}
@@ -47,11 +48,11 @@ public:
{
}
- std::unique_ptr<libcamera::FrameBuffer>
+ std::unique_ptr<HALFrameBuffer>
allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);
};
-std::unique_ptr<libcamera::FrameBuffer>
+std::unique_ptr<HALFrameBuffer>
PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
const libcamera::Size &size,
uint32_t usage)
@@ -80,9 +81,8 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i);
}
- return std::make_unique<FrameBuffer>(
- std::make_unique<CrosFrameBufferData>(std::move(scopedHandle)),
- planes);
+ return std::make_unique<HALFrameBuffer>(
+ std::make_unique<CrosFrameBufferData>(std::move(scopedHandle), planes), handle);
}
PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION
diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp
index 1bd7090d..0ffcb445 100644
--- a/src/android/mm/generic_camera_buffer.cpp
+++ b/src/android/mm/generic_camera_buffer.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2021, Google Inc.
*
- * generic_camera_buffer.cpp - Generic Android frame buffer backend
+ * Generic Android frame buffer backend
*/
#include "../camera_buffer.h"
diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp
index acb2fa2b..79625a9a 100644
--- a/src/android/mm/generic_frame_buffer_allocator.cpp
+++ b/src/android/mm/generic_frame_buffer_allocator.cpp
@@ -2,9 +2,10 @@
/*
* Copyright (C) 2021, Google Inc.
*
- * generic_camera_buffer.cpp - Allocate FrameBuffer using gralloc API
+ * Allocate FrameBuffer using gralloc API
*/
+#include <dlfcn.h>
#include <memory>
#include <vector>
@@ -20,6 +21,7 @@
#include "../camera_device.h"
#include "../frame_buffer_allocator.h"
+#include "../hal_framebuffer.h"
using namespace libcamera;
@@ -32,8 +34,10 @@ class GenericFrameBufferData : public FrameBuffer::Private
public:
GenericFrameBufferData(struct alloc_device_t *allocDevice,
- buffer_handle_t handle)
- : allocDevice_(allocDevice), handle_(handle)
+ buffer_handle_t handle,
+ const std::vector<FrameBuffer::Plane> &planes)
+ : FrameBuffer::Private(planes), allocDevice_(allocDevice),
+ handle_(handle)
{
ASSERT(allocDevice_);
ASSERT(handle_);
@@ -69,20 +73,21 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private
public:
Private(CameraDevice *const cameraDevice)
: cameraDevice_(cameraDevice),
- hardwareModule_(cameraDevice->camera3Device()->common.module),
+ hardwareModule_(nullptr),
allocDevice_(nullptr)
{
+ hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hardwareModule_);
ASSERT(hardwareModule_);
}
~Private() override;
- std::unique_ptr<libcamera::FrameBuffer>
+ std::unique_ptr<HALFrameBuffer>
allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);
private:
const CameraDevice *const cameraDevice_;
- struct hw_module_t *const hardwareModule_;
+ const struct hw_module_t *hardwareModule_;
struct alloc_device_t *allocDevice_;
};
@@ -90,9 +95,10 @@ PlatformFrameBufferAllocator::Private::~Private()
{
if (allocDevice_)
gralloc_close(allocDevice_);
+ dlclose(hardwareModule_->dso);
}
-std::unique_ptr<libcamera::FrameBuffer>
+std::unique_ptr<HALFrameBuffer>
PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
const libcamera::Size &size,
uint32_t usage)
@@ -135,9 +141,10 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
offset += planeSize;
}
- return std::make_unique<FrameBuffer>(
- std::make_unique<GenericFrameBufferData>(allocDevice_, handle),
- planes);
+ return std::make_unique<HALFrameBuffer>(
+ std::make_unique<GenericFrameBufferData>(
+ allocDevice_, handle, planes),
+ handle);
}
PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION
diff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c
new file mode 100644
index 00000000..28faa638
--- /dev/null
+++ b/src/android/mm/libhardware_stub.c
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright (C) 2023, Ideas on Board
+ *
+ * Android libhardware stub for test compilation
+ */
+
+#include <errno.h>
+
+#include <hardware/hardware.h>
+
+int hw_get_module(const char *id __attribute__((__unused__)),
+ const struct hw_module_t **module)
+{
+ *module = NULL;
+ return -ENOTSUP;
+}
diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build
index d40a3b0b..e3e0484c 100644
--- a/src/android/mm/meson.build
+++ b/src/android/mm/meson.build
@@ -4,6 +4,14 @@ platform = get_option('android_platform')
if platform == 'generic'
android_hal_sources += files(['generic_camera_buffer.cpp',
'generic_frame_buffer_allocator.cpp'])
+ android_deps += [libdl]
+
+ libhardware = dependency('libhardware', required : false)
+ if libhardware.found()
+ android_deps += [libhardware]
+ else
+ android_hal_sources += files(['libhardware_stub.c'])
+ endif
elif platform == 'cros'
android_hal_sources += files(['cros_camera_buffer.cpp',
'cros_frame_buffer_allocator.cpp'])