1 /* 2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd 3 * This file contains confidential and proprietary information of 4 * OSWare Technology Co., Ltd 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 HDI_DRM_LAYER_H 20 #define HDI_DRM_LAYER_H 21 #include <xf86drm.h> 22 #include <xf86drmMode.h> 23 #include "buffer_handle.h" 24 #include "display_common.h" 25 #include "drm_fourcc.h" 26 #include "hdi_layer.h" 27 #include "hdi_device_common.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace DISPLAY { 32 constexpr int INVALID_DRM_ID = 0; 33 class DrmGemBuffer { 34 public: 35 DrmGemBuffer(int drmFd, HdiLayerBuffer &hdl); 36 virtual ~DrmGemBuffer(); GetFbId()37 uint32_t GetFbId() const 38 { 39 return mFdId; 40 } 41 bool IsValid(); 42 43 private: 44 void Init(int drmFd, HdiLayerBuffer &hdl); 45 uint32_t mGemHandle = 0; 46 uint32_t mFdId = 0; 47 int mDrmFd = -1; // the fd can not close. the other module will close it. 48 uint32_t mDrmFormat = DRM_FORMAT_INVALID; 49 }; 50 51 class HdiDrmLayer : public HdiLayer { 52 public: HdiDrmLayer(LayerType type)53 explicit HdiDrmLayer(LayerType type) : HdiLayer(type) {} ~HdiDrmLayer()54 virtual ~HdiDrmLayer() {} 55 // Return value optimization 56 DrmGemBuffer *GetGemBuffer(); 57 58 private: 59 std::unique_ptr<DrmGemBuffer> mCurrentBuffer; 60 std::unique_ptr<DrmGemBuffer> lastBuffer_; 61 }; 62 } // namespace OHOS 63 } // namespace HDI 64 } // namespace DISPLAY 65 66 #endif // HDI_DRM_LAYER_H 67