1*0a9764feSAndroid Build Coastguard Worker /* 2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*0a9764feSAndroid Build Coastguard Worker * 4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*0a9764feSAndroid Build Coastguard Worker * 8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*0a9764feSAndroid Build Coastguard Worker * 10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*0a9764feSAndroid Build Coastguard Worker * limitations under the License. 15*0a9764feSAndroid Build Coastguard Worker */ 16*0a9764feSAndroid Build Coastguard Worker 17*0a9764feSAndroid Build Coastguard Worker #pragma once 18*0a9764feSAndroid Build Coastguard Worker 19*0a9764feSAndroid Build Coastguard Worker #include <xf86drmMode.h> 20*0a9764feSAndroid Build Coastguard Worker 21*0a9764feSAndroid Build Coastguard Worker #include <cstdint> 22*0a9764feSAndroid Build Coastguard Worker #include <string> 23*0a9764feSAndroid Build Coastguard Worker #include <vector> 24*0a9764feSAndroid Build Coastguard Worker 25*0a9764feSAndroid Build Coastguard Worker #include "DrmEncoder.h" 26*0a9764feSAndroid Build Coastguard Worker #include "DrmMode.h" 27*0a9764feSAndroid Build Coastguard Worker #include "DrmProperty.h" 28*0a9764feSAndroid Build Coastguard Worker #include "DrmUnique.h" 29*0a9764feSAndroid Build Coastguard Worker #include "compositor/DisplayInfo.h" 30*0a9764feSAndroid Build Coastguard Worker 31*0a9764feSAndroid Build Coastguard Worker namespace android { 32*0a9764feSAndroid Build Coastguard Worker 33*0a9764feSAndroid Build Coastguard Worker class DrmDevice; 34*0a9764feSAndroid Build Coastguard Worker 35*0a9764feSAndroid Build Coastguard Worker class DrmConnector : public PipelineBindable<DrmConnector> { 36*0a9764feSAndroid Build Coastguard Worker public: 37*0a9764feSAndroid Build Coastguard Worker static auto CreateInstance(DrmDevice &dev, uint32_t connector_id, 38*0a9764feSAndroid Build Coastguard Worker uint32_t index) -> std::unique_ptr<DrmConnector>; 39*0a9764feSAndroid Build Coastguard Worker 40*0a9764feSAndroid Build Coastguard Worker DrmConnector(const DrmProperty &) = delete; 41*0a9764feSAndroid Build Coastguard Worker DrmConnector &operator=(const DrmProperty &) = delete; 42*0a9764feSAndroid Build Coastguard Worker 43*0a9764feSAndroid Build Coastguard Worker int UpdateEdidProperty(); 44*0a9764feSAndroid Build Coastguard Worker auto GetEdidBlob() -> DrmModePropertyBlobUnique; 45*0a9764feSAndroid Build Coastguard Worker 46*0a9764feSAndroid Build Coastguard Worker auto GetDev() const -> DrmDevice & { 47*0a9764feSAndroid Build Coastguard Worker return *drm_; 48*0a9764feSAndroid Build Coastguard Worker } 49*0a9764feSAndroid Build Coastguard Worker GetId()50*0a9764feSAndroid Build Coastguard Worker auto GetId() const { 51*0a9764feSAndroid Build Coastguard Worker return connector_->connector_id; 52*0a9764feSAndroid Build Coastguard Worker } 53*0a9764feSAndroid Build Coastguard Worker GetIndexInResArray()54*0a9764feSAndroid Build Coastguard Worker auto GetIndexInResArray() const { 55*0a9764feSAndroid Build Coastguard Worker return index_in_res_array_; 56*0a9764feSAndroid Build Coastguard Worker } 57*0a9764feSAndroid Build Coastguard Worker GetCurrentEncoderId()58*0a9764feSAndroid Build Coastguard Worker auto GetCurrentEncoderId() const { 59*0a9764feSAndroid Build Coastguard Worker return connector_->encoder_id; 60*0a9764feSAndroid Build Coastguard Worker } 61*0a9764feSAndroid Build Coastguard Worker SupportsEncoder(DrmEncoder & enc)62*0a9764feSAndroid Build Coastguard Worker auto SupportsEncoder(DrmEncoder &enc) const { 63*0a9764feSAndroid Build Coastguard Worker for (int i = 0; i < connector_->count_encoders; i++) { 64*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 65*0a9764feSAndroid Build Coastguard Worker if (connector_->encoders[i] == enc.GetId()) { 66*0a9764feSAndroid Build Coastguard Worker return true; 67*0a9764feSAndroid Build Coastguard Worker } 68*0a9764feSAndroid Build Coastguard Worker } 69*0a9764feSAndroid Build Coastguard Worker 70*0a9764feSAndroid Build Coastguard Worker return false; 71*0a9764feSAndroid Build Coastguard Worker } 72*0a9764feSAndroid Build Coastguard Worker 73*0a9764feSAndroid Build Coastguard Worker bool IsInternal() const; 74*0a9764feSAndroid Build Coastguard Worker bool IsExternal() const; 75*0a9764feSAndroid Build Coastguard Worker bool IsWriteback() const; 76*0a9764feSAndroid Build Coastguard Worker bool IsValid() const; 77*0a9764feSAndroid Build Coastguard Worker 78*0a9764feSAndroid Build Coastguard Worker std::string GetName() const; 79*0a9764feSAndroid Build Coastguard Worker 80*0a9764feSAndroid Build Coastguard Worker int UpdateModes(); 81*0a9764feSAndroid Build Coastguard Worker 82*0a9764feSAndroid Build Coastguard Worker bool IsLinkStatusGood(); 83*0a9764feSAndroid Build Coastguard Worker GetModes()84*0a9764feSAndroid Build Coastguard Worker auto &GetModes() const { 85*0a9764feSAndroid Build Coastguard Worker return modes_; 86*0a9764feSAndroid Build Coastguard Worker } 87*0a9764feSAndroid Build Coastguard Worker GetDpmsProperty()88*0a9764feSAndroid Build Coastguard Worker auto &GetDpmsProperty() const { 89*0a9764feSAndroid Build Coastguard Worker return dpms_property_; 90*0a9764feSAndroid Build Coastguard Worker } 91*0a9764feSAndroid Build Coastguard Worker GetCrtcIdProperty()92*0a9764feSAndroid Build Coastguard Worker auto &GetCrtcIdProperty() const { 93*0a9764feSAndroid Build Coastguard Worker return crtc_id_property_; 94*0a9764feSAndroid Build Coastguard Worker } 95*0a9764feSAndroid Build Coastguard Worker GetEdidProperty()96*0a9764feSAndroid Build Coastguard Worker auto &GetEdidProperty() const { 97*0a9764feSAndroid Build Coastguard Worker return edid_property_; 98*0a9764feSAndroid Build Coastguard Worker } 99*0a9764feSAndroid Build Coastguard Worker GetColorspaceProperty()100*0a9764feSAndroid Build Coastguard Worker auto &GetColorspaceProperty() const { 101*0a9764feSAndroid Build Coastguard Worker return colorspace_property_; 102*0a9764feSAndroid Build Coastguard Worker } 103*0a9764feSAndroid Build Coastguard Worker GetColorspacePropertyValue(Colorspace c)104*0a9764feSAndroid Build Coastguard Worker auto GetColorspacePropertyValue(Colorspace c) { 105*0a9764feSAndroid Build Coastguard Worker return colorspace_enum_map_[c]; 106*0a9764feSAndroid Build Coastguard Worker } 107*0a9764feSAndroid Build Coastguard Worker GetContentTypeProperty()108*0a9764feSAndroid Build Coastguard Worker auto &GetContentTypeProperty() const { 109*0a9764feSAndroid Build Coastguard Worker return content_type_property_; 110*0a9764feSAndroid Build Coastguard Worker } 111*0a9764feSAndroid Build Coastguard Worker GetWritebackFbIdProperty()112*0a9764feSAndroid Build Coastguard Worker auto &GetWritebackFbIdProperty() const { 113*0a9764feSAndroid Build Coastguard Worker return writeback_fb_id_; 114*0a9764feSAndroid Build Coastguard Worker } 115*0a9764feSAndroid Build Coastguard Worker GetWritebackOutFenceProperty()116*0a9764feSAndroid Build Coastguard Worker auto &GetWritebackOutFenceProperty() const { 117*0a9764feSAndroid Build Coastguard Worker return writeback_out_fence_; 118*0a9764feSAndroid Build Coastguard Worker } 119*0a9764feSAndroid Build Coastguard Worker GetPanelOrientationProperty()120*0a9764feSAndroid Build Coastguard Worker auto &GetPanelOrientationProperty() const { 121*0a9764feSAndroid Build Coastguard Worker return panel_orientation_; 122*0a9764feSAndroid Build Coastguard Worker } 123*0a9764feSAndroid Build Coastguard Worker IsConnected()124*0a9764feSAndroid Build Coastguard Worker auto IsConnected() const { 125*0a9764feSAndroid Build Coastguard Worker return connector_->connection == DRM_MODE_CONNECTED; 126*0a9764feSAndroid Build Coastguard Worker } 127*0a9764feSAndroid Build Coastguard Worker GetMmWidth()128*0a9764feSAndroid Build Coastguard Worker auto GetMmWidth() const { 129*0a9764feSAndroid Build Coastguard Worker return connector_->mmWidth; 130*0a9764feSAndroid Build Coastguard Worker } 131*0a9764feSAndroid Build Coastguard Worker GetMmHeight()132*0a9764feSAndroid Build Coastguard Worker auto GetMmHeight() const { 133*0a9764feSAndroid Build Coastguard Worker return connector_->mmHeight; 134*0a9764feSAndroid Build Coastguard Worker }; 135*0a9764feSAndroid Build Coastguard Worker 136*0a9764feSAndroid Build Coastguard Worker auto GetPanelOrientation() -> std::optional<PanelOrientation>; 137*0a9764feSAndroid Build Coastguard Worker 138*0a9764feSAndroid Build Coastguard Worker private: DrmConnector(DrmModeConnectorUnique connector,DrmDevice * drm,uint32_t index)139*0a9764feSAndroid Build Coastguard Worker DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index) 140*0a9764feSAndroid Build Coastguard Worker : connector_(std::move(connector)), 141*0a9764feSAndroid Build Coastguard Worker drm_(drm), 142*0a9764feSAndroid Build Coastguard Worker index_in_res_array_(index) {}; 143*0a9764feSAndroid Build Coastguard Worker 144*0a9764feSAndroid Build Coastguard Worker DrmModeConnectorUnique connector_; 145*0a9764feSAndroid Build Coastguard Worker DrmDevice *const drm_; 146*0a9764feSAndroid Build Coastguard Worker 147*0a9764feSAndroid Build Coastguard Worker auto Init() -> bool; 148*0a9764feSAndroid Build Coastguard Worker auto GetConnectorProperty(const char *prop_name, DrmProperty *property, 149*0a9764feSAndroid Build Coastguard Worker bool is_optional = false) -> bool; 150*0a9764feSAndroid Build Coastguard Worker 151*0a9764feSAndroid Build Coastguard Worker const uint32_t index_in_res_array_; 152*0a9764feSAndroid Build Coastguard Worker 153*0a9764feSAndroid Build Coastguard Worker std::vector<DrmMode> modes_; 154*0a9764feSAndroid Build Coastguard Worker 155*0a9764feSAndroid Build Coastguard Worker DrmProperty dpms_property_; 156*0a9764feSAndroid Build Coastguard Worker DrmProperty crtc_id_property_; 157*0a9764feSAndroid Build Coastguard Worker DrmProperty edid_property_; 158*0a9764feSAndroid Build Coastguard Worker DrmProperty colorspace_property_; 159*0a9764feSAndroid Build Coastguard Worker DrmProperty content_type_property_; 160*0a9764feSAndroid Build Coastguard Worker 161*0a9764feSAndroid Build Coastguard Worker DrmProperty link_status_property_; 162*0a9764feSAndroid Build Coastguard Worker DrmProperty writeback_pixel_formats_; 163*0a9764feSAndroid Build Coastguard Worker DrmProperty writeback_fb_id_; 164*0a9764feSAndroid Build Coastguard Worker DrmProperty writeback_out_fence_; 165*0a9764feSAndroid Build Coastguard Worker DrmProperty panel_orientation_; 166*0a9764feSAndroid Build Coastguard Worker 167*0a9764feSAndroid Build Coastguard Worker std::map<Colorspace, uint64_t> colorspace_enum_map_; 168*0a9764feSAndroid Build Coastguard Worker std::map<uint64_t, PanelOrientation> panel_orientation_enum_map_; 169*0a9764feSAndroid Build Coastguard Worker }; 170*0a9764feSAndroid Build Coastguard Worker } // namespace android 171