1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android-base/logging.h>
20 #include <android-base/unique_fd.h>
21 #include <xf86drm.h>
22 #include <xf86drmMode.h>
23 
24 #include <cstdint>
25 #include <memory>
26 #include <string>
27 #include <unordered_map>
28 
29 #include "Common.h"
30 #include "DrmCrtc.h"
31 #include "DrmProperty.h"
32 
33 namespace aidl::android::hardware::graphics::composer3::impl {
34 
35 class DrmPlane {
36    public:
37     static std::unique_ptr<DrmPlane> create(::android::base::borrowed_fd drmFd, uint32_t planeId);
~DrmPlane()38     ~DrmPlane(){};
39 
getId()40     uint32_t getId() const { return mId; }
41 
42     bool isPrimary() const;
43     bool isOverlay() const;
44 
45     bool isCompatibleWith(const DrmCrtc& crtc);
46 
getCrtcProperty()47     const DrmProperty& getCrtcProperty() const { return mCrtc; }
getInFenceProperty()48     const DrmProperty& getInFenceProperty() const { return mInFenceFd; }
getFbProperty()49     const DrmProperty& getFbProperty() const { return mFb; }
getCrtcXProperty()50     const DrmProperty& getCrtcXProperty() const { return mCrtcX; }
getCrtcYProperty()51     const DrmProperty& getCrtcYProperty() const { return mCrtcY; }
getCrtcWProperty()52     const DrmProperty& getCrtcWProperty() const { return mCrtcW; }
getCrtcHProperty()53     const DrmProperty& getCrtcHProperty() const { return mCrtcH; }
getSrcXProperty()54     const DrmProperty& getSrcXProperty() const { return mSrcX; }
getSrcYProperty()55     const DrmProperty& getSrcYProperty() const { return mSrcY; }
getSrcWProperty()56     const DrmProperty& getSrcWProperty() const { return mSrcW; }
getSrcHProperty()57     const DrmProperty& getSrcHProperty() const { return mSrcH; }
58 
59    private:
DrmPlane(uint32_t id)60     DrmPlane(uint32_t id) : mId(id){};
61 
62     const uint32_t mId;
63 
64     uint32_t mPossibleCrtcsMask = 0;
65 
66     DrmProperty mCrtc;
67     DrmProperty mInFenceFd;
68     DrmProperty mFb;
69     DrmProperty mCrtcX;
70     DrmProperty mCrtcY;
71     DrmProperty mCrtcW;
72     DrmProperty mCrtcH;
73     DrmProperty mSrcX;
74     DrmProperty mSrcY;
75     DrmProperty mSrcW;
76     DrmProperty mSrcH;
77     DrmProperty mType;
78 
GetPropertiesMap()79     static const auto& GetPropertiesMap() {
80         static const auto* sMap = []() {
81             return new DrmPropertyMemberMap<DrmPlane>{
82                 {"CRTC_ID", &DrmPlane::mCrtc},
83                 {"CRTC_X", &DrmPlane::mCrtcX},
84                 {"CRTC_Y", &DrmPlane::mCrtcY},
85                 {"CRTC_W", &DrmPlane::mCrtcW},
86                 {"CRTC_H", &DrmPlane::mCrtcH},
87                 {"FB_ID", &DrmPlane::mFb},
88                 {"IN_FENCE_FD", &DrmPlane::mInFenceFd},
89                 {"SRC_X", &DrmPlane::mSrcX},
90                 {"SRC_Y", &DrmPlane::mSrcY},
91                 {"SRC_W", &DrmPlane::mSrcW},
92                 {"SRC_H", &DrmPlane::mSrcH},
93                 {"type", &DrmPlane::mType},
94             };
95         }();
96         return *sMap;
97     }
98 };
99 
100 }  // namespace aidl::android::hardware::graphics::composer3::impl
101