1 /* 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_std.h> 24 #include <safe_list.h> 25 #include <xcam_mutex.h> 26 #include <buffer_pool.h> 27 #include <drm_display.h> 28 #include <swapped_buffer.h> 29 30 namespace XCam { 31 32 class DrmBoBufferPool; 33 class X3aStats; 34 35 class DrmBoData 36 : public BufferData 37 { 38 friend class DrmDisplay; 39 40 public: 41 ~DrmBoData (); get_bo()42 drm_intel_bo *get_bo () { 43 return _bo; 44 } 45 46 //derived from BufferData 47 virtual uint8_t *map (); 48 virtual bool unmap (); 49 virtual int get_fd (); 50 51 protected: 52 explicit DrmBoData (SmartPtr<DrmDisplay> &display, drm_intel_bo *bo); 53 54 bool set_prime_fd (int fd, bool need_close); 55 56 private: 57 XCAM_DEAD_COPY (DrmBoData); 58 59 private: 60 SmartPtr<DrmDisplay> _display; 61 drm_intel_bo *_bo; 62 uint8_t *_buf; 63 int _prime_fd; 64 bool _need_close_fd; 65 }; 66 67 class DrmBoBuffer 68 : public virtual BufferProxy 69 , public SwappedBuffer 70 { 71 friend class DrmBoBufferPool; 72 friend class DrmDisplay; 73 74 public: ~DrmBoBuffer()75 virtual ~DrmBoBuffer () {} 76 drm_intel_bo *get_bo (); 77 78 SmartPtr<X3aStats> find_3a_stats (); 79 80 protected: 81 DrmBoBuffer (const VideoBufferInfo &info, const SmartPtr<DrmBoData> &data); 82 83 //derived from SwappedBuffer 84 virtual SmartPtr<SwappedBuffer> create_new_swap_buffer ( 85 const VideoBufferInfo &info, SmartPtr<BufferData> &data); 86 87 XCAM_DEAD_COPY (DrmBoBuffer); 88 }; 89 90 class DrmBoBufferPool 91 : public BufferPool 92 { 93 friend class DrmBoBuffer; 94 95 public: 96 explicit DrmBoBufferPool (SmartPtr<DrmDisplay> &display); 97 ~DrmBoBufferPool (); 98 99 // **** MUST be set before set_video_info **** set_swap_flags(uint32_t flags,uint32_t init_order)100 void set_swap_flags (uint32_t flags, uint32_t init_order) { 101 _swap_flags = flags; 102 _swap_init_order = init_order; 103 } get_swap_flags()104 uint32_t get_swap_flags () const { 105 return _swap_flags; 106 } 107 108 bool update_swap_init_order (uint32_t init_order); 109 get_drm_display()110 SmartPtr<DrmDisplay> &get_drm_display () { 111 return _display; 112 } 113 114 protected: 115 // derived from BufferPool 116 virtual bool fixate_video_info (VideoBufferInfo &info); 117 virtual SmartPtr<BufferData> allocate_data (const VideoBufferInfo &buffer_info); 118 virtual SmartPtr<BufferProxy> create_buffer_from_data (SmartPtr<BufferData> &data); 119 120 bool init_swap_order (VideoBufferInfo &info); 121 122 private: 123 XCAM_DEAD_COPY (DrmBoBufferPool); 124 125 protected: 126 uint32_t _swap_flags; 127 uint32_t _swap_init_order; 128 uint32_t _swap_offsets[XCAM_VIDEO_MAX_COMPONENTS * 2]; 129 130 private: 131 SmartPtr<DrmDisplay> _display; 132 }; 133 134 }; 135 136 #endif //XCAM_DRM_BO_BUFFER_H 137 138