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 30 namespace android { 31 32 class DrmDevice; 33 34 class DrmConnector : public PipelineBindable<DrmConnector> { 35 public: 36 static auto CreateInstance(DrmDevice &dev, uint32_t connector_id, 37 uint32_t index) -> std::unique_ptr<DrmConnector>; 38 39 DrmConnector(const DrmProperty &) = delete; 40 DrmConnector &operator=(const DrmProperty &) = delete; 41 42 int UpdateEdidProperty(); 43 auto GetEdidBlob() -> DrmModePropertyBlobUnique; 44 45 auto GetDev() const -> DrmDevice & { 46 return *drm_; 47 } 48 GetId()49 auto GetId() const { 50 return connector_->connector_id; 51 } 52 GetIndexInResArray()53 auto GetIndexInResArray() const { 54 return index_in_res_array_; 55 } 56 GetCurrentEncoderId()57 auto GetCurrentEncoderId() const { 58 return connector_->encoder_id; 59 } 60 SupportsEncoder(DrmEncoder & enc)61 auto SupportsEncoder(DrmEncoder &enc) const { 62 for (int i = 0; i < connector_->count_encoders; i++) { 63 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 64 if (connector_->encoders[i] == enc.GetId()) { 65 return true; 66 } 67 } 68 69 return false; 70 } 71 72 bool IsInternal() const; 73 bool IsExternal() const; 74 bool IsWriteback() const; 75 bool IsValid() const; 76 77 std::string GetName() const; 78 79 int UpdateModes(); 80 GetModes()81 auto &GetModes() const { 82 return modes_; 83 } 84 GetDpmsProperty()85 auto &GetDpmsProperty() const { 86 return dpms_property_; 87 } 88 GetCrtcIdProperty()89 auto &GetCrtcIdProperty() const { 90 return crtc_id_property_; 91 } 92 GetEdidProperty()93 auto &GetEdidProperty() const { 94 return edid_property_; 95 } 96 GetWritebackFbIdProperty()97 auto &GetWritebackFbIdProperty() const { 98 return writeback_fb_id_; 99 } 100 GetWritebackOutFenceProperty()101 auto &GetWritebackOutFenceProperty() const { 102 return writeback_out_fence_; 103 } 104 IsConnected()105 auto IsConnected() const { 106 return connector_->connection == DRM_MODE_CONNECTED; 107 } 108 GetMmWidth()109 auto GetMmWidth() const { 110 return connector_->mmWidth; 111 } 112 GetMmHeight()113 auto GetMmHeight() const { 114 return connector_->mmHeight; 115 }; 116 117 private: DrmConnector(DrmModeConnectorUnique connector,DrmDevice * drm,uint32_t index)118 DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index) 119 : connector_(std::move(connector)), 120 drm_(drm), 121 index_in_res_array_(index){}; 122 123 DrmModeConnectorUnique connector_; 124 DrmDevice *const drm_; 125 126 const uint32_t index_in_res_array_; 127 128 std::vector<DrmMode> modes_; 129 130 DrmProperty dpms_property_; 131 DrmProperty crtc_id_property_; 132 DrmProperty edid_property_; 133 DrmProperty writeback_pixel_formats_; 134 DrmProperty writeback_fb_id_; 135 DrmProperty writeback_out_fence_; 136 }; 137 } // namespace android 138