android: framebuffer: Add HALFrameBuffer and replace FrameBuffer

HALFrameBuffer is derived from FrameBuffer with access to
buffer_handle_t, which is needed for JEA usage.

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Harvey Yang 2023-02-08 03:33:16 +00:00 committed by Laurent Pinchart
parent 4843bfa66d
commit b64fa1363c
9 changed files with 72 additions and 15 deletions

View file

@ -30,6 +30,7 @@
#include "camera_hal_config.h" #include "camera_hal_config.h"
#include "camera_ops.h" #include "camera_ops.h"
#include "camera_request.h" #include "camera_request.h"
#include "hal_framebuffer.h"
using namespace libcamera; using namespace libcamera;
@ -771,7 +772,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
return 0; return 0;
} }
std::unique_ptr<FrameBuffer> std::unique_ptr<HALFrameBuffer>
CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,
PixelFormat pixelFormat, const Size &size) PixelFormat pixelFormat, const Size &size)
{ {
@ -794,7 +795,7 @@ CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,
planes[i].length = buf.size(i); planes[i].length = buf.size(i);
} }
return std::make_unique<FrameBuffer>(planes); return std::make_unique<HALFrameBuffer>(planes, camera3buffer);
} }
int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) int CameraDevice::processControls(Camera3RequestDescriptor *descriptor)

View file

@ -29,6 +29,7 @@
#include "camera_capabilities.h" #include "camera_capabilities.h"
#include "camera_metadata.h" #include "camera_metadata.h"
#include "camera_stream.h" #include "camera_stream.h"
#include "hal_framebuffer.h"
#include "jpeg/encoder.h" #include "jpeg/encoder.h"
class Camera3RequestDescriptor; class Camera3RequestDescriptor;
@ -83,7 +84,7 @@ private:
void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_);
std::unique_ptr<libcamera::FrameBuffer> std::unique_ptr<HALFrameBuffer>
createFrameBuffer(const buffer_handle_t camera3buffer, createFrameBuffer(const buffer_handle_t camera3buffer,
libcamera::PixelFormat pixelFormat, libcamera::PixelFormat pixelFormat,
const libcamera::Size &size); const libcamera::Size &size);

View file

@ -21,6 +21,7 @@
#include <hardware/camera3.h> #include <hardware/camera3.h>
#include "camera_metadata.h" #include "camera_metadata.h"
#include "hal_framebuffer.h"
class CameraBuffer; class CameraBuffer;
class CameraStream; class CameraStream;
@ -44,7 +45,7 @@ public:
CameraStream *stream; CameraStream *stream;
buffer_handle_t *camera3Buffer; buffer_handle_t *camera3Buffer;
std::unique_ptr<libcamera::FrameBuffer> frameBuffer; std::unique_ptr<HALFrameBuffer> frameBuffer;
libcamera::UniqueFD fence; libcamera::UniqueFD fence;
Status status = Status::Success; Status status = Status::Success;
libcamera::FrameBuffer *internalBuffer = nullptr; libcamera::FrameBuffer *internalBuffer = nullptr;

View file

@ -13,9 +13,10 @@
#include <libcamera/base/class.h> #include <libcamera/base/class.h>
#include <libcamera/camera.h> #include <libcamera/camera.h>
#include <libcamera/framebuffer.h>
#include <libcamera/geometry.h> #include <libcamera/geometry.h>
#include "hal_framebuffer.h"
class CameraDevice; class CameraDevice;
class PlatformFrameBufferAllocator : libcamera::Extensible class PlatformFrameBufferAllocator : libcamera::Extensible
@ -31,7 +32,7 @@ public:
* Note: The returned FrameBuffer needs to be destroyed before * Note: The returned FrameBuffer needs to be destroyed before
* PlatformFrameBufferAllocator is destroyed. * PlatformFrameBufferAllocator is destroyed.
*/ */
std::unique_ptr<libcamera::FrameBuffer> allocate( std::unique_ptr<HALFrameBuffer> allocate(
int halPixelFormat, const libcamera::Size &size, uint32_t usage); int halPixelFormat, const libcamera::Size &size, uint32_t usage);
}; };
@ -44,7 +45,7 @@ PlatformFrameBufferAllocator::PlatformFrameBufferAllocator( \
PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator() \ PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator() \
{ \ { \
} \ } \
std::unique_ptr<libcamera::FrameBuffer> \ std::unique_ptr<HALFrameBuffer> \
PlatformFrameBufferAllocator::allocate(int halPixelFormat, \ PlatformFrameBufferAllocator::allocate(int halPixelFormat, \
const libcamera::Size &size, \ const libcamera::Size &size, \
uint32_t usage) \ uint32_t usage) \

View file

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Google Inc.
*
* hal_framebuffer.cpp - HAL Frame Buffer Handling
*/
#include "hal_framebuffer.h"
#include <hardware/camera3.h>
HALFrameBuffer::HALFrameBuffer(std::unique_ptr<Private> d,
buffer_handle_t handle)
: FrameBuffer(std::move(d)), handle_(handle)
{
}
HALFrameBuffer::HALFrameBuffer(const std::vector<Plane> &planes,
buffer_handle_t handle)
: FrameBuffer(planes), handle_(handle)
{
}

View file

@ -0,0 +1,26 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Google Inc.
*
* hal_framebuffer.h - HAL 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,
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_;
};

View file

@ -46,6 +46,7 @@ android_hal_sources = files([
'camera_ops.cpp', 'camera_ops.cpp',
'camera_request.cpp', 'camera_request.cpp',
'camera_stream.cpp', 'camera_stream.cpp',
'hal_framebuffer.cpp',
'jpeg/encoder_libjpeg.cpp', 'jpeg/encoder_libjpeg.cpp',
'jpeg/exif.cpp', 'jpeg/exif.cpp',
'jpeg/post_processor_jpeg.cpp', 'jpeg/post_processor_jpeg.cpp',

View file

@ -16,6 +16,7 @@
#include "../camera_device.h" #include "../camera_device.h"
#include "../frame_buffer_allocator.h" #include "../frame_buffer_allocator.h"
#include "../hal_framebuffer.h"
#include "cros-camera/camera_buffer_manager.h" #include "cros-camera/camera_buffer_manager.h"
using namespace libcamera; using namespace libcamera;
@ -48,11 +49,11 @@ public:
{ {
} }
std::unique_ptr<libcamera::FrameBuffer> std::unique_ptr<HALFrameBuffer>
allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);
}; };
std::unique_ptr<libcamera::FrameBuffer> std::unique_ptr<HALFrameBuffer>
PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
const libcamera::Size &size, const libcamera::Size &size,
uint32_t usage) uint32_t usage)
@ -81,8 +82,8 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i); plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i);
} }
return std::make_unique<FrameBuffer>( return std::make_unique<HALFrameBuffer>(
std::make_unique<CrosFrameBufferData>(std::move(scopedHandle), planes)); std::make_unique<CrosFrameBufferData>(std::move(scopedHandle), planes), handle);
} }
PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION

View file

@ -20,6 +20,7 @@
#include "../camera_device.h" #include "../camera_device.h"
#include "../frame_buffer_allocator.h" #include "../frame_buffer_allocator.h"
#include "../hal_framebuffer.h"
using namespace libcamera; using namespace libcamera;
@ -79,7 +80,7 @@ public:
~Private() override; ~Private() override;
std::unique_ptr<libcamera::FrameBuffer> std::unique_ptr<HALFrameBuffer>
allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);
private: private:
@ -94,7 +95,7 @@ PlatformFrameBufferAllocator::Private::~Private()
gralloc_close(allocDevice_); gralloc_close(allocDevice_);
} }
std::unique_ptr<libcamera::FrameBuffer> std::unique_ptr<HALFrameBuffer>
PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
const libcamera::Size &size, const libcamera::Size &size,
uint32_t usage) uint32_t usage)
@ -137,8 +138,10 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,
offset += planeSize; offset += planeSize;
} }
return std::make_unique<FrameBuffer>( return std::make_unique<HALFrameBuffer>(
std::make_unique<GenericFrameBufferData>(allocDevice_, handle, planes)); std::make_unique<GenericFrameBufferData>(
allocDevice_, handle, planes),
handle);
} }
PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION