1 /* 2 * Copyright (c) 2021 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 "display_common.h" 22 #include "drm_fourcc.h" 23 #include "hdi_layer.h" 24 #include "hdi_device_common.h" 25 26 namespace OHOS { 27 namespace HDI { 28 namespace DISPLAY { 29 const int INVALID_DRM_ID = 0; 30 class DrmGemBuffer { 31 public: 32 DrmGemBuffer(int drmfd, HdiLayerBuffer &hdl); 33 virtual ~DrmGemBuffer(); GetFbId()34 uint32_t GetFbId() const 35 { 36 return mFdId; 37 } 38 bool IsValid(); 39 40 private: 41 void Init(int drmFd, HdiLayerBuffer &hdl); 42 uint32_t mGemHandle = 0; 43 uint32_t mFdId = 0; 44 int mDrmFd = -1; // the fd can not close. the other module will close it. 45 uint32_t mDrmFormat = DRM_FORMAT_INVALID; 46 }; 47 48 class HdiDrmLayer : public HdiLayer { 49 public: HdiDrmLayer(LayerType type)50 explicit HdiDrmLayer(LayerType type) : HdiLayer(type) {} ~HdiDrmLayer()51 ~HdiDrmLayer() override {} 52 // Return value optimization 53 DrmGemBuffer *GetGemBuffer(); 54 55 private: 56 std::unique_ptr<DrmGemBuffer> mCurrentBuffer; 57 std::unique_ptr<DrmGemBuffer> LastBuffer; 58 }; 59 } // namespace OHOS 60 } // namespace HDI 61 } // namespace DISPLAY 62 63 #endif // HDI_DRM_LAYER_H 64