@@ -29,6 +29,7 @@
#include "camera_hal_config.h"
#include "camera_ops.h"
#include "camera_request.h"
+#include "hal_framebuffer.h"
using namespace libcamera;
@@ -754,7 +755,7 @@ CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,
planes[i].length = buf.size(i);
}
- return std::make_unique<FrameBuffer>(planes);
+ return std::make_unique<HALFrameBuffer>(planes, camera3buffer);
}
int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)
@@ -13,9 +13,10 @@
#include <libcamera/base/class.h>
#include <libcamera/camera.h>
-#include <libcamera/framebuffer.h>
#include <libcamera/geometry.h>
+#include "hal_framebuffer.h"
+
class CameraDevice;
class PlatformFrameBufferAllocator : libcamera::Extensible
@@ -31,7 +32,7 @@ public:
* Note: The returned FrameBuffer needs to be destroyed before
* PlatformFrameBufferAllocator is destroyed.
*/
- std::unique_ptr<libcamera::FrameBuffer> allocate(
+ std::unique_ptr<HALFrameBuffer> allocate(
int halPixelFormat, const libcamera::Size &size, uint32_t usage);
};
@@ -44,7 +45,7 @@ PlatformFrameBufferAllocator::PlatformFrameBufferAllocator( \
PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator() \
{ \
} \
-std::unique_ptr<libcamera::FrameBuffer> \
+std::unique_ptr<HALFrameBuffer> \
PlatformFrameBufferAllocator::allocate(int halPixelFormat, \
const libcamera::Size &size, \
uint32_t usage) \
new file mode 100644
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * hal_framebuffer.cpp - Android Frame Buffer Handling
+ */
+
+#include "hal_framebuffer.h"
+
+#include <hardware/camera3.h>
+
+HALFrameBuffer::HALFrameBuffer(
+ std::unique_ptr<Private> d,
+ const std::vector<Plane> &planes,
+ buffer_handle_t handle)
+ : FrameBuffer(std::move(d), planes), handle_(handle)
+{
+}
+
+HALFrameBuffer::HALFrameBuffer(
+ const std::vector<Plane> &planes,
+ buffer_handle_t handle)
+ : FrameBuffer(planes), handle_(handle)
+{
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * hal_framebuffer.h - Android Frame Buffer Handling
+ */
+
+#pragma once
+
+#include "libcamera/internal/framebuffer.h"
+
+#include <hardware/camera3.h>
+
+class HALFrameBuffer final : public libcamera::FrameBuffer
+{
+public:
+ HALFrameBuffer(std::unique_ptr<Private> d,
+ const std::vector<Plane> &planes,
+ buffer_handle_t handle);
+ HALFrameBuffer(const std::vector<Plane> &planes,
+ buffer_handle_t handle);
+
+ buffer_handle_t handle() const { return handle_; }
+
+private:
+ buffer_handle_t handle_;
+};
@@ -38,6 +38,7 @@ endif
android_deps += [libyuv_dep]
android_hal_sources = files([
+ 'hal_framebuffer.cpp',
'camera3_hal.cpp',
'camera_capabilities.cpp',
'camera_device.cpp',
@@ -16,6 +16,7 @@
#include "../camera_device.h"
#include "../frame_buffer_allocator.h"
+#include "../hal_framebuffer.h"
#include "cros-camera/camera_buffer_manager.h"
using namespace libcamera;
@@ -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,12 @@ 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);
+ auto fb = std::make_unique<HALFrameBuffer>(
+ std::make_unique<CrosFrameBufferData>(
+ std::move(scopedHandle)),
+ planes, handle);
+
+ return fb;
}
PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION
@@ -20,6 +20,7 @@
#include "../camera_device.h"
#include "../frame_buffer_allocator.h"
+#include "../hal_framebuffer.h"
using namespace libcamera;
@@ -77,7 +78,7 @@ public:
~Private() override;
- std::unique_ptr<libcamera::FrameBuffer>
+ std::unique_ptr<HALFrameBuffer>
allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);
private:
@@ -92,7 +93,7 @@ PlatformFrameBufferAllocator::Private::~Private()
gralloc_close(allocDevice_);
}
-std::unique_ptr<libcamera::FrameBuffer>
+std::unique_ptr<HALFrameBuffer>
PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
const libcamera::Size &size,
uint32_t usage)
@@ -135,9 +136,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
AndroidFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang <chenghaoyang@chromium.org> --- src/android/camera_device.cpp | 3 ++- src/android/frame_buffer_allocator.h | 7 ++--- src/android/hal_framebuffer.cpp | 25 +++++++++++++++++ src/android/hal_framebuffer.h | 27 +++++++++++++++++++ src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 14 ++++++---- .../mm/generic_frame_buffer_allocator.cpp | 12 +++++---- 7 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 src/android/hal_framebuffer.cpp create mode 100644 src/android/hal_framebuffer.h