hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * DrmBuffer.h - DRM Buffer Implementation
 *
 *  Copyright (c) 2021 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#ifndef _DRM_BUFFER_H_
#define _DRM_BUFFER_H_
 
#include <drm/drm_fourcc.h>
#include <sys/types.h>
 
#include <memory>
#include <vector>
 
#include "buffer_pool.h"
 
extern "C" {
struct DrmDumbObject;
};
 
namespace XCam {
 
class DmaBuffer;
class DrmDevice;
class DrmBufferProxy;
class DrmBufferPool;
 
class DrmBuffer : public BufferData {
 public:
    DrmBuffer()                 = delete;
    DrmBuffer(const DrmBuffer&) = delete;
    DrmBuffer& operator=(const DrmBuffer&) = delete;
    DrmBuffer(const std::shared_ptr<DrmDevice>& dev, std::unique_ptr<DrmDumbObject> dumb_object);
    virtual ~DrmBuffer();
 
    virtual uint8_t* map();
    virtual bool unmap();
    virtual int get_fd();
    size_t getSize();
    // default single plane
    uint8_t* map(unsigned int plane);
    bool unmap(unsigned int plane);
    int getFd(unsigned int plane);
    size_t getSize(unsigned int plane);
    int numPlanes();
    DrmDumbObject* get_bo();
 
 private:
    std::weak_ptr<DrmDevice> drm_device_;
    std::unique_ptr<DrmDumbObject> dumb_object_;
    std::vector<std::unique_ptr<DmaBuffer>> dma_bufs_;
};
 
class DrmBufferPool : public BufferPool {
    friend class DrmBuffer;
 
 public:
    explicit DrmBufferPool(std::shared_ptr<DrmDevice> device);
    virtual ~DrmBufferPool() = default;
    DrmBufferPool(const DrmBufferPool&) = delete;
    DrmBufferPool& operator=(const DrmBufferPool&) = delete;
 
 protected:
    virtual bool fixate_video_info (VideoBufferInfo &info);
    virtual SmartPtr<BufferData> allocate_data(const VideoBufferInfo& buffer_info);
    virtual SmartPtr<BufferProxy> create_buffer_from_data(SmartPtr<BufferData>& data);
 
 private:
    std::shared_ptr<DrmDevice> drm_device_;
};
 
class DrmBufferProxy : public virtual BufferProxy {
    friend class DrmBufferPool;
    friend class DrmDevice;
 
 public:
    explicit DrmBufferProxy(const VideoBufferInfo& info, const SmartPtr<DrmBuffer>& data);
    virtual ~DrmBufferProxy() = default;
    DrmDumbObject* get_bo();
 
    const int GetFd();
};
 
};  // namespace XCam
 
#endif  // _DRM_BUFFER_H_