• 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_COMPOSITION_H
17 #define HDI_DRM_COMPOSITION_H
18 #include <vector>
19 #include <memory>
20 #include <xf86drm.h>
21 #include <xf86drmMode.h>
22 #include "drm_device.h"
23 #include "hdi_composer.h"
24 #include "hdi_device_common.h"
25 #include "hdi_drm_layer.h"
26 
27 namespace OHOS {
28     namespace HDI {
29         namespace DISPLAY {
30             class AtomicReqPtr {
31             public:
AtomicReqPtr(drmModeAtomicReqPtr ptr)32                 explicit AtomicReqPtr(drmModeAtomicReqPtr ptr) : mPtr(ptr)
33                 {
34                 }
~AtomicReqPtr()35                 virtual ~AtomicReqPtr()
36                 {
37                     if (mPtr != nullptr) {
38                         drmModeAtomicFree(mPtr);
39                     }
40                 }
Get()41                 drmModeAtomicReqPtr Get() const
42                 {
43                     return mPtr;
44                 }
45 
46             private:
47                 drmModeAtomicReqPtr mPtr;
48             };
49 
50             class HdiDrmComposition : public HdiComposition {
51             public:
52                 HdiDrmComposition(const std::shared_ptr<DrmConnector> &connector, const std::shared_ptr<DrmCrtc> &crtc,
53                                   const std::shared_ptr<DrmDevice> &drmDevice);
~HdiDrmComposition()54                 ~HdiDrmComposition() override
55                 {
56                 }
57                 int32_t Init() override;
58                 int32_t SetLayers(std::vector<HdiLayer *> &layers, HdiLayer &clientLayer) override;
59                 int32_t Apply(bool modeSet) override;
60                 int32_t UpdateMode(std::unique_ptr<DrmModeBlock> &modeBlock);
61 
62             private:
63                 int32_t ApplyPlane(HdiDrmLayer &layer, HdiLayer &hlayer, DrmPlane &drmPlane, drmModeAtomicReqPtr pset);
64                 int32_t SetSrcProperty(DrmPlane &drmPlane, drmModeAtomicReqPtr pset, int32_t bufferW, int32_t bufferH);
65                 int32_t SetCrtcProperty(DrmPlane &drmPlane, drmModeAtomicReqPtr pset, int32_t bufferW, int32_t bufferH);
66                 int32_t RemoveUnusePlane(drmModeAtomicReqPtr pset);
67                 int32_t FindPlaneAndApply(drmModeAtomicReqPtr pset);
68                 std::shared_ptr<DrmDevice> mDrmDevice;
69                 std::shared_ptr<DrmConnector> mConnector;
70                 std::shared_ptr<DrmCrtc> mCrtc;
71                 std::vector<std::shared_ptr<DrmPlane>> mPrimPlanes;
72                 std::vector<std::shared_ptr<DrmPlane>> mOverlayPlanes;
73                 std::vector<std::shared_ptr<DrmPlane>> mPlanes;
74             };
75         } // OHOS
76     }     // HDI
77 } // DISPLAY
78 
79 #endif // HDI_DRM_COMPOSITION_H
80