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_H_ |
| 18 | #define ANDROID_DRM_H_ |
| 19 | |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 20 | #include <cstdint> |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 21 | #include <map> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 22 | #include <tuple> |
| 23 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 24 | #include "DrmConnector.h" |
| 25 | #include "DrmCrtc.h" |
| 26 | #include "DrmEncoder.h" |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 27 | #include "DrmFbImporter.h" |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame] | 28 | #include "utils/UniqueFd.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 32 | class DrmFbImporter; |
| 33 | class DrmPlane; |
| 34 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 35 | class DrmDevice { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 36 | public: |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 37 | DrmDevice(); |
Roman Stratiienko | 1e053b4 | 2021-10-25 22:54:20 +0300 | [diff] [blame] | 38 | ~DrmDevice() = default; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 39 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 40 | std::tuple<int, int> Init(const char *path, int num_displays); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 41 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 42 | int fd() const { |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame] | 43 | return fd_.Get(); |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 44 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 45 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 46 | const std::vector<std::unique_ptr<DrmConnector>> &connectors() const { |
| 47 | return connectors_; |
| 48 | } |
| 49 | |
| 50 | const std::vector<std::unique_ptr<DrmPlane>> &planes() const { |
| 51 | return planes_; |
| 52 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 53 | |
Sean Paul | 406dbfc | 2016-02-10 15:35:17 -0800 | [diff] [blame] | 54 | std::pair<uint32_t, uint32_t> min_resolution() const { |
| 55 | return min_resolution_; |
| 56 | } |
| 57 | |
| 58 | std::pair<uint32_t, uint32_t> max_resolution() const { |
| 59 | return max_resolution_; |
| 60 | } |
| 61 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 62 | DrmConnector *GetConnectorForDisplay(int display) const; |
| 63 | DrmCrtc *GetCrtcForDisplay(int display) const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 64 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 65 | int GetConnectorProperty(const DrmConnector &connector, const char *prop_name, |
Roman Stratiienko | 0b06388 | 2021-09-30 10:15:05 +0300 | [diff] [blame] | 66 | DrmProperty *property) const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 67 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 68 | std::string GetName() const; |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 69 | |
Robert Foss | 0690c1c | 2016-10-20 11:07:57 -0400 | [diff] [blame] | 70 | const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 71 | uint32_t next_mode_id(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 72 | |
Roman Stratiienko | 6ede466 | 2021-09-30 10:18:28 +0300 | [diff] [blame] | 73 | auto RegisterUserPropertyBlob(void *data, size_t length) const |
| 74 | -> DrmModeUserPropertyBlobUnique; |
| 75 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 76 | bool HandlesDisplay(int display) const; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 77 | |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 78 | bool HasAddFb2ModifiersSupport() const { |
| 79 | return HasAddFb2ModifiersSupport_; |
| 80 | } |
| 81 | |
| 82 | DrmFbImporter &GetDrmFbImporter() { |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 83 | return *mDrmFbImporter; |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Roman Stratiienko | 56f4adc | 2021-09-29 12:47:12 +0300 | [diff] [blame] | 86 | static auto IsKMSDev(const char *path) -> bool; |
| 87 | |
Roman Stratiienko | 027987b | 2022-01-30 21:06:35 +0200 | [diff] [blame^] | 88 | auto FindCrtcById(uint32_t id) const -> DrmCrtc * { |
| 89 | for (const auto &crtc : crtcs_) { |
| 90 | if (crtc->GetId() == id) { |
| 91 | return crtc.get(); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | return nullptr; |
| 96 | } |
| 97 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 98 | int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 99 | DrmProperty *property) const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 100 | |
Roman Stratiienko | 0b06388 | 2021-09-30 10:15:05 +0300 | [diff] [blame] | 101 | private: |
| 102 | int TryEncoderForDisplay(int display, DrmEncoder *enc); |
| 103 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 104 | int CreateDisplayPipe(DrmConnector *connector); |
| 105 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 106 | UniqueFd fd_; |
| 107 | uint32_t mode_id_ = 0; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 108 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 109 | std::vector<std::unique_ptr<DrmConnector>> connectors_; |
Alexandru Gheorghe | b46b930 | 2018-03-21 14:19:58 +0000 | [diff] [blame] | 110 | std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 111 | std::vector<std::unique_ptr<DrmEncoder>> encoders_; |
| 112 | std::vector<std::unique_ptr<DrmCrtc>> crtcs_; |
| 113 | std::vector<std::unique_ptr<DrmPlane>> planes_; |
Sean Paul | 406dbfc | 2016-02-10 15:35:17 -0800 | [diff] [blame] | 114 | |
| 115 | std::pair<uint32_t, uint32_t> min_resolution_; |
| 116 | std::pair<uint32_t, uint32_t> max_resolution_; |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 117 | std::map<int, int> displays_; |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 118 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 119 | std::map<int /*display*/, DrmCrtc *> bound_crtcs_; |
Roman Stratiienko | 027987b | 2022-01-30 21:06:35 +0200 | [diff] [blame^] | 120 | std::map<DrmCrtc *, DrmEncoder *> bound_encoders_; |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 121 | |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 122 | bool HasAddFb2ModifiersSupport_{}; |
| 123 | |
| 124 | std::shared_ptr<DrmDevice> self; |
| 125 | |
| 126 | std::unique_ptr<DrmFbImporter> mDrmFbImporter; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 127 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 128 | } // namespace android |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 129 | |
| 130 | #endif // ANDROID_DRM_H_ |