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() const34                 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)
51                 {
52                 }
53                 ~HdiDrmLayer() override
54                 {
55                 }
56                 // Return value optimization
57                 DrmGemBuffer *GetGemBuffer();
58 
59             private:
60                 std::unique_ptr<DrmGemBuffer> mCurrentBuffer;
61                 std::unique_ptr<DrmGemBuffer> mLastBuffer;
62             };
63         } // namespace OHOS
64     }     // namespace HDI
65 } // namespace DISPLAY
66 
67 #endif // HDI_DRM_LAYER_H
68