• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_log.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 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> lastBuffer_;
57 };
58 } // namespace OHOS
59 } // namespace HDI
60 } // namespace DISPLAY
61 
62 #endif // HDI_DRM_LAYER_H
63