1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HDI_DRM_LAYER_H 17 #define HDI_DRM_LAYER_H 18 #include <xf86drm.h> 19 #include <xf86drmMode.h> 20 #include "buffer_handle.h" 21 #include "drm_fourcc.h" 22 #include "hdi_layer.h" 23 #include "hdi_device_common.h" 24 25 namespace OHOS { 26 namespace HDI { 27 namespace DISPLAY { 28 const int INVALID_DRM_ID = 0; 29 class DrmGemBuffer { 30 public: 31 DrmGemBuffer(int drmFd, HdiLayerBuffer &hdl); 32 virtual ~DrmGemBuffer(); GetFbId()33 uint32_t GetFbId() const 34 { 35 return mFdId; 36 } 37 bool IsValid(); 38 39 private: 40 void Init(int drmFd, HdiLayerBuffer &hdl); 41 uint32_t mGemHandle = 0; 42 uint32_t mFdId = 0; 43 int mDrmFd = -1; // the fd can not close. the other module will close it. 44 uint32_t mDrmFormat = DRM_FORMAT_INVALID; 45 }; 46 47 class HdiDrmLayer : public HdiLayer { 48 public: HdiDrmLayer(LayerType type)49 explicit HdiDrmLayer(LayerType type) : HdiLayer(type) {} ~HdiDrmLayer()50 ~HdiDrmLayer() override {} 51 // Return value optimization 52 DrmGemBuffer *GetGemBuffer(); 53 54 private: 55 std::unique_ptr<DrmGemBuffer> mCurrentBuffer; 56 std::unique_ptr<DrmGemBuffer> mLastBuffer; 57 }; 58 } // namespace OHOS 59 } // namespace HDI 60 } // namespace DISPLAY 61 62 #endif // HDI_DRM_LAYER_H 63