Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 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 | #ifndef ANDROID_DRM_CONNECTOR_H_ |
| 18 | #define ANDROID_DRM_CONNECTOR_H_ |
| 19 | |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 20 | #include <xf86drmMode.h> |
| 21 | |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 22 | #include <cstdint> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 26 | #include "DrmEncoder.h" |
| 27 | #include "DrmMode.h" |
| 28 | #include "DrmProperty.h" |
Roman Stratiienko | 3e8ce57 | 2021-09-29 12:46:28 +0300 | [diff] [blame] | 29 | #include "DrmUnique.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 30 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 31 | namespace android { |
| 32 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 33 | class DrmDevice; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 34 | |
Roman Stratiienko | cad8e0c | 2022-01-31 16:40:16 +0200 | [diff] [blame] | 35 | class DrmConnector : public PipelineBindable<DrmConnector> { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 36 | public: |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 37 | static auto CreateInstance(DrmDevice &dev, uint32_t connector_id, |
| 38 | uint32_t index) -> std::unique_ptr<DrmConnector>; |
| 39 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 40 | DrmConnector(const DrmProperty &) = delete; |
| 41 | DrmConnector &operator=(const DrmProperty &) = delete; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 42 | |
Andrii Chepurnyi | adc5d82 | 2020-07-10 16:07:03 +0300 | [diff] [blame] | 43 | int UpdateEdidProperty(); |
Roman Stratiienko | 3e8ce57 | 2021-09-29 12:46:28 +0300 | [diff] [blame] | 44 | auto GetEdidBlob() -> DrmModePropertyBlobUnique; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 45 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 46 | auto GetDev() const -> DrmDevice & { |
| 47 | return *drm_; |
| 48 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 49 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 50 | auto GetId() const { |
| 51 | return connector_->connector_id; |
| 52 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 53 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 54 | auto GetIndexInResArray() const { |
| 55 | return index_in_res_array_; |
| 56 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 57 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 58 | auto GetCurrentEncoderId() const { |
| 59 | return connector_->encoder_id; |
| 60 | } |
| 61 | |
| 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; |
Roman Kovalivskyi | df88299 | 2019-11-04 17:43:40 +0200 | [diff] [blame] | 79 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 80 | int UpdateModes(); |
| 81 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 82 | auto &GetModes() const { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 83 | return modes_; |
| 84 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 85 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 86 | auto &GetActiveMode() const { |
| 87 | return active_mode_; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 88 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 89 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 90 | void SetActiveMode(DrmMode &mode); |
Sean Paul | 0921649 | 2015-10-26 15:36:37 -0400 | [diff] [blame] | 91 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 92 | auto &GetDpmsProperty() const { |
| 93 | return dpms_property_; |
| 94 | } |
| 95 | |
| 96 | auto &GetCrtcIdProperty() const { |
| 97 | return crtc_id_property_; |
| 98 | } |
| 99 | |
| 100 | auto &GetEdidProperty() const { |
| 101 | return edid_property_; |
| 102 | } |
| 103 | |
| 104 | auto IsConnected() const { |
| 105 | return connector_->connection == DRM_MODE_CONNECTED; |
| 106 | } |
| 107 | |
| 108 | auto GetMmWidth() const { |
| 109 | return connector_->mmWidth; |
| 110 | } |
| 111 | |
| 112 | auto GetMmHeight() const { |
| 113 | return connector_->mmHeight; |
| 114 | }; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 115 | |
| 116 | private: |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 117 | DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index) |
| 118 | : connector_(std::move(connector)), |
| 119 | drm_(drm), |
| 120 | index_in_res_array_(index){}; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 121 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 122 | DrmModeConnectorUnique connector_; |
| 123 | DrmDevice *const drm_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 124 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 125 | const uint32_t index_in_res_array_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 126 | |
| 127 | DrmMode active_mode_; |
| 128 | std::vector<DrmMode> modes_; |
| 129 | |
| 130 | DrmProperty dpms_property_; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 131 | DrmProperty crtc_id_property_; |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 132 | DrmProperty edid_property_; |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 133 | DrmProperty writeback_pixel_formats_; |
| 134 | DrmProperty writeback_fb_id_; |
| 135 | DrmProperty writeback_out_fence_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 136 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 137 | } // namespace android |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 138 | |
| 139 | #endif // ANDROID_DRM_PLANE_H_ |