xref: /aosp_15_r20/external/drm_hwcomposer/drm/DrmConnector.h (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
1 /*
2  * Copyright (C) 2015 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 <xf86drmMode.h>
20 
21 #include <cstdint>
22 #include <string>
23 #include <vector>
24 
25 #include "DrmEncoder.h"
26 #include "DrmMode.h"
27 #include "DrmProperty.h"
28 #include "DrmUnique.h"
29 #include "compositor/DisplayInfo.h"
30 
31 namespace android {
32 
33 class DrmDevice;
34 
35 class DrmConnector : public PipelineBindable<DrmConnector> {
36  public:
37   static auto CreateInstance(DrmDevice &dev, uint32_t connector_id,
38                              uint32_t index) -> std::unique_ptr<DrmConnector>;
39 
40   DrmConnector(const DrmProperty &) = delete;
41   DrmConnector &operator=(const DrmProperty &) = delete;
42 
43   int UpdateEdidProperty();
44   auto GetEdidBlob() -> DrmModePropertyBlobUnique;
45 
46   auto GetDev() const -> DrmDevice & {
47     return *drm_;
48   }
49 
GetId()50   auto GetId() const {
51     return connector_->connector_id;
52   }
53 
GetIndexInResArray()54   auto GetIndexInResArray() const {
55     return index_in_res_array_;
56   }
57 
GetCurrentEncoderId()58   auto GetCurrentEncoderId() const {
59     return connector_->encoder_id;
60   }
61 
SupportsEncoder(DrmEncoder & enc)62   auto SupportsEncoder(DrmEncoder &enc) const {
63     for (int i = 0; i < connector_->count_encoders; i++) {
64       // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
65       if (connector_->encoders[i] == enc.GetId()) {
66         return true;
67       }
68     }
69 
70     return false;
71   }
72 
73   bool IsInternal() const;
74   bool IsExternal() const;
75   bool IsWriteback() const;
76   bool IsValid() const;
77 
78   std::string GetName() const;
79 
80   int UpdateModes();
81 
82   bool IsLinkStatusGood();
83 
GetModes()84   auto &GetModes() const {
85     return modes_;
86   }
87 
GetDpmsProperty()88   auto &GetDpmsProperty() const {
89     return dpms_property_;
90   }
91 
GetCrtcIdProperty()92   auto &GetCrtcIdProperty() const {
93     return crtc_id_property_;
94   }
95 
GetEdidProperty()96   auto &GetEdidProperty() const {
97     return edid_property_;
98   }
99 
GetColorspaceProperty()100   auto &GetColorspaceProperty() const {
101     return colorspace_property_;
102   }
103 
GetColorspacePropertyValue(Colorspace c)104   auto GetColorspacePropertyValue(Colorspace c) {
105     return colorspace_enum_map_[c];
106   }
107 
GetContentTypeProperty()108   auto &GetContentTypeProperty() const {
109     return content_type_property_;
110   }
111 
GetWritebackFbIdProperty()112   auto &GetWritebackFbIdProperty() const {
113     return writeback_fb_id_;
114   }
115 
GetWritebackOutFenceProperty()116   auto &GetWritebackOutFenceProperty() const {
117     return writeback_out_fence_;
118   }
119 
GetPanelOrientationProperty()120   auto &GetPanelOrientationProperty() const {
121     return panel_orientation_;
122   }
123 
IsConnected()124   auto IsConnected() const {
125     return connector_->connection == DRM_MODE_CONNECTED;
126   }
127 
GetMmWidth()128   auto GetMmWidth() const {
129     return connector_->mmWidth;
130   }
131 
GetMmHeight()132   auto GetMmHeight() const {
133     return connector_->mmHeight;
134   };
135 
136   auto GetPanelOrientation() -> std::optional<PanelOrientation>;
137 
138  private:
DrmConnector(DrmModeConnectorUnique connector,DrmDevice * drm,uint32_t index)139   DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
140       : connector_(std::move(connector)),
141         drm_(drm),
142         index_in_res_array_(index) {};
143 
144   DrmModeConnectorUnique connector_;
145   DrmDevice *const drm_;
146 
147   auto Init() -> bool;
148   auto GetConnectorProperty(const char *prop_name, DrmProperty *property,
149                             bool is_optional = false) -> bool;
150 
151   const uint32_t index_in_res_array_;
152 
153   std::vector<DrmMode> modes_;
154 
155   DrmProperty dpms_property_;
156   DrmProperty crtc_id_property_;
157   DrmProperty edid_property_;
158   DrmProperty colorspace_property_;
159   DrmProperty content_type_property_;
160 
161   DrmProperty link_status_property_;
162   DrmProperty writeback_pixel_formats_;
163   DrmProperty writeback_fb_id_;
164   DrmProperty writeback_out_fence_;
165   DrmProperty panel_orientation_;
166 
167   std::map<Colorspace, uint64_t> colorspace_enum_map_;
168   std::map<uint64_t, PanelOrientation> panel_orientation_enum_map_;
169 };
170 }  // namespace android
171