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