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