blob: 89c22ca33a11f79643958d65bf982a52d106d8a5 [file] [log] [blame]
Wind Yuan25aed2b2015-02-10 17:46:23 +08001/*
2 * drm_bo_buffer.h - drm bo buffer
3 *
4 * Copyright (c) 2015 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20#ifndef XCAM_DRM_BO_BUFFER_H
21#define XCAM_DRM_BO_BUFFER_H
22
23#include "xcam_utils.h"
24#include "smartptr.h"
25#include "safe_list.h"
26#include "xcam_mutex.h"
27#include "video_buffer.h"
28#include "drm_display.h"
29
30namespace XCam {
31
32class DrmBoBufferPool;
33
34class DrmBoWrapper {
35 friend class DrmDisplay;
36public:
37 ~DrmBoWrapper ();
38 drm_intel_bo *get_bo () {
39 return _bo;
40 }
Wind Yuan54c73242015-02-15 15:51:40 +080041
42 bool map (intptr_t &ptr);
43 bool unmap ();
Wind Yuan25aed2b2015-02-10 17:46:23 +080044private:
45 explicit DrmBoWrapper (SmartPtr<DrmDisplay> &display, drm_intel_bo *bo);
46 XCAM_DEAD_COPY (DrmBoWrapper);
47private:
48 SmartPtr<DrmDisplay> _display;
49 drm_intel_bo *_bo;
Wind Yuan54c73242015-02-15 15:51:40 +080050 intptr_t _buf;
Wind Yuan25aed2b2015-02-10 17:46:23 +080051};
52
53class DrmBoBuffer
54 : public VideoBuffer
55{
56 friend class DrmDisplay;
57 friend class DrmBoBufferPool;
58public:
59 virtual ~DrmBoBuffer ();
60
61 drm_intel_bo *get_bo () {
62 return _bo->get_bo ();
63 }
64
65 //abstract from VideoBuffer
66 virtual uint8_t *map ();
67 virtual bool unmap ();
68
69private:
70 explicit DrmBoBuffer (
71 SmartPtr<DrmDisplay> display,
72 const VideoBufferInfo &info,
73 SmartPtr<DrmBoWrapper> &bo);
74
75 void set_parent (SmartPtr<VideoBuffer> &parent);
76 void set_buf_pool (SmartPtr<DrmBoBufferPool> &buf_pool);
77
78 XCAM_DEAD_COPY (DrmBoBuffer);
79
80private:
81 SmartPtr<DrmDisplay> _display;
82 SmartPtr<DrmBoBufferPool> _pool;
83 SmartPtr<VideoBuffer> _parent;
84 SmartPtr<DrmBoWrapper> _bo;
85};
86
87class DrmBoBufferPool {
88 friend class DrmBoBuffer;
89
90public:
91 explicit DrmBoBufferPool (SmartPtr<DrmDisplay> &display);
92 ~DrmBoBufferPool ();
93 bool set_buffer_info (const VideoBufferInfo &info);
94 bool init (uint32_t buf_num = 6);
95 void deinit ();
96 SmartPtr<DrmBoBuffer> get_buffer (SmartPtr<DrmBoBufferPool> &self);
97
98private:
99 void release (SmartPtr<DrmBoWrapper> &bo);
100 XCAM_DEAD_COPY (DrmBoBufferPool);
101
102private:
103 SmartPtr<DrmDisplay> _display;
104 VideoBufferInfo _buf_info;
105 SafeList<DrmBoWrapper> _buf_list;
106 uint32_t _buf_count;
107};
108
109
110};
111
112#endif //XCAM_DRM_BO_BUFFER_H
113