libcamera: include/libcamera/internal/dma_buf_allocator.h Source File

libcamera v0.3.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
dma_buf_allocator.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2020, Raspberry Pi Ltd
4 *
5 * Helper class for dma-buf allocations.
6 */
7
8#pragma once
9
10#include <libcamera/base/flags.h>
11#include <libcamera/base/unique_fd.h>
12
13namespace libcamera {
14
15 class DmaBufAllocator
16{
17public:
18 enum class DmaBufAllocatorFlag {
19 CmaHeap = 1 << 0,
20 SystemHeap = 1 << 1,
21 UDmaBuf = 1 << 2,
22 };
23
24 using DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>;
25
26 DmaBufAllocator(DmaBufAllocatorFlags flags = DmaBufAllocatorFlag::CmaHeap);
27 ~DmaBufAllocator();
28 bool isValid() const { return providerHandle_.isValid(); }
29 UniqueFD alloc(const char *name, std::size_t size);
30
31private:
32 UniqueFD allocFromHeap(const char *name, std::size_t size);
33 UniqueFD allocFromUDmaBuf(const char *name, std::size_t size);
34 UniqueFD providerHandle_;
35 DmaBufAllocatorFlag type_;
36};
37
38 LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaBufAllocator::DmaBufAllocatorFlag)
39
40} /* namespace libcamera */
libcamera::DmaBufAllocator
Helper class for dma-buf allocations.
Definition dma_buf_allocator.h:16
libcamera::DmaBufAllocator::isValid
bool isValid() const
Check if the DmaBufAllocator instance is valid.
Definition dma_buf_allocator.h:28
libcamera::DmaBufAllocator::DmaBufAllocator
DmaBufAllocator(DmaBufAllocatorFlags flags=DmaBufAllocatorFlag::CmaHeap)
Construct a DmaBufAllocator of a given type.
Definition dma_buf_allocator.cpp:94
libcamera::DmaBufAllocator::DmaBufAllocatorFlag
DmaBufAllocatorFlag
Type of the dma-buf provider.
Definition dma_buf_allocator.h:18
libcamera::DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap
@ CmaHeap
Allocate from a CMA dma-heap, providing physically-contiguous memory.
libcamera::DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap
@ SystemHeap
Allocate from the system dma-heap, using the page allocator.
libcamera::DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf
@ UDmaBuf
Allocate using a memfd + /dev/udmabuf.
libcamera::DmaBufAllocator::~DmaBufAllocator
~DmaBufAllocator()
Destroy the DmaBufAllocator instance.
libcamera::DmaBufAllocator::alloc
UniqueFD alloc(const char *name, std::size_t size)
Allocate a dma-buf from the DmaBufAllocator.
Definition dma_buf_allocator.cpp:197
libcamera::Flags
Type-safe container for enum-based bitfields.
Definition flags.h:16
libcamera::UniqueFD
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:18
libcamera::UniqueFD::isValid
bool isValid() const
Check if the UniqueFD owns a valid file descriptor.
Definition unique_fd.h:61
flags.h
Enum-based bit fields.
LIBCAMERA_FLAGS_ENABLE_OPERATORS
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Enable bitwise operations on the enum enumeration.
Definition flags.h:189
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
unique_fd.h
File descriptor wrapper that owns a file descriptor.