1 /* 2 * drm_device.h - DRM Device Implementation 3 * 4 * Copyright (c) 2021 Rockchip 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 */ 19 #ifndef _DRM_DEVICE_H_ 20 #define _DRM_DEVICE_H_ 21 22 #include <stdint.h> 23 24 #include <memory> 25 26 #include "unique_fd.h" 27 #include "xcam_common.h" 28 29 extern "C" { 30 31 #define RKCAM_MAX_DRM_PLANES 4 32 33 struct DrmDumbObject { 34 uint32_t drm_format; 35 uint32_t width; 36 uint32_t height; 37 int num_planes; 38 int strides[RKCAM_MAX_DRM_PLANES]; 39 uint32_t offsets[RKCAM_MAX_DRM_PLANES]; 40 int fds[RKCAM_MAX_DRM_PLANES]; 41 uint32_t handles[RKCAM_MAX_DRM_PLANES]; 42 size_t sizes[RKCAM_MAX_DRM_PLANES]; 43 }; 44 } 45 46 namespace XCam { 47 48 class DrmDevice { 49 public: 50 DrmDevice(); 51 ~DrmDevice(); 52 DrmDevice(const DrmDevice&) = delete; 53 DrmDevice& operator=(const DrmDevice&) = delete; 54 55 static bool Available(); 56 57 std::unique_ptr<DrmDumbObject> CreateDumbObject(unsigned int width, unsigned int height, 58 unsigned int bpp = 8, 59 unsigned int num_planes = 1); 60 XCamReturn DestroyDumbObject(const std::unique_ptr<DrmDumbObject>& bo); 61 XCamReturn RequestMapDumbObject(const std::unique_ptr<DrmDumbObject>& bo, 62 unsigned int plane = 0); 63 64 private: 65 int Open(); 66 void Close(); 67 UniqueFd fd_; 68 }; 69 70 } // namespace XCam 71 72 #endif // _DRM_DEVICE_H_ 73