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 | |
| 20 | #include "drmconnector.h" |
| 21 | #include "drmcrtc.h" |
| 22 | #include "drmencoder.h" |
Sean Paul | 047b9b2 | 2015-07-28 14:15:42 -0400 | [diff] [blame] | 23 | #include "drmeventlistener.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 24 | #include "drmplane.h" |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 25 | #include "platform.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 26 | |
| 27 | #include <stdint.h> |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 28 | #include <tuple> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 32 | class DrmDevice { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 33 | public: |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 34 | DrmDevice(); |
| 35 | ~DrmDevice(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 36 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 37 | std::tuple<int, int> Init(const char *path, int num_displays); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 38 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 39 | int fd() const { |
| 40 | return fd_.get(); |
| 41 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 42 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 43 | const std::vector<std::unique_ptr<DrmConnector>> &connectors() const { |
| 44 | return connectors_; |
| 45 | } |
| 46 | |
| 47 | const std::vector<std::unique_ptr<DrmPlane>> &planes() const { |
| 48 | return planes_; |
| 49 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 50 | |
Sean Paul | 406dbfc | 2016-02-10 15:35:17 -0800 | [diff] [blame] | 51 | std::pair<uint32_t, uint32_t> min_resolution() const { |
| 52 | return min_resolution_; |
| 53 | } |
| 54 | |
| 55 | std::pair<uint32_t, uint32_t> max_resolution() const { |
| 56 | return max_resolution_; |
| 57 | } |
| 58 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 59 | DrmConnector *GetConnectorForDisplay(int display) const; |
Alexandru Gheorghe | b46b930 | 2018-03-21 14:19:58 +0000 | [diff] [blame] | 60 | DrmConnector *GetWritebackConnectorForDisplay(int display) const; |
Alexandru Gheorghe | b6a675e | 2018-03-27 16:10:55 +0100 | [diff] [blame] | 61 | DrmConnector *AvailableWritebackConnector(int display) const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 62 | DrmCrtc *GetCrtcForDisplay(int display) const; |
| 63 | DrmPlane *GetPlane(uint32_t id) const; |
Sean Paul | 047b9b2 | 2015-07-28 14:15:42 -0400 | [diff] [blame] | 64 | DrmEventListener *event_listener(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 65 | |
| 66 | int GetPlaneProperty(const DrmPlane &plane, const char *prop_name, |
| 67 | DrmProperty *property); |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 68 | int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name, |
| 69 | DrmProperty *property); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 70 | int GetConnectorProperty(const DrmConnector &connector, const char *prop_name, |
| 71 | DrmProperty *property); |
| 72 | |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame^] | 73 | const std::string GetName() const; |
| 74 | |
Robert Foss | 0690c1c | 2016-10-20 11:07:57 -0400 | [diff] [blame] | 75 | const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 76 | uint32_t next_mode_id(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 77 | |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 78 | int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id); |
| 79 | int DestroyPropertyBlob(uint32_t blob_id); |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 80 | bool HandlesDisplay(int display) const; |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 81 | void RegisterHotplugHandler(DrmEventHandler *handler) { |
| 82 | event_listener_.RegisterHotplugHandler(handler); |
| 83 | } |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 84 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 85 | private: |
| 86 | int TryEncoderForDisplay(int display, DrmEncoder *enc); |
| 87 | int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, |
| 88 | DrmProperty *property); |
| 89 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 90 | int CreateDisplayPipe(DrmConnector *connector); |
Alexandru Gheorghe | b46b930 | 2018-03-21 14:19:58 +0000 | [diff] [blame] | 91 | int AttachWriteback(DrmConnector *display_conn); |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 92 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 93 | UniqueFd fd_; |
| 94 | uint32_t mode_id_ = 0; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 95 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 96 | std::vector<std::unique_ptr<DrmConnector>> connectors_; |
Alexandru Gheorghe | b46b930 | 2018-03-21 14:19:58 +0000 | [diff] [blame] | 97 | std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 98 | std::vector<std::unique_ptr<DrmEncoder>> encoders_; |
| 99 | std::vector<std::unique_ptr<DrmCrtc>> crtcs_; |
| 100 | std::vector<std::unique_ptr<DrmPlane>> planes_; |
Sean Paul | 047b9b2 | 2015-07-28 14:15:42 -0400 | [diff] [blame] | 101 | DrmEventListener event_listener_; |
Sean Paul | 406dbfc | 2016-02-10 15:35:17 -0800 | [diff] [blame] | 102 | |
| 103 | std::pair<uint32_t, uint32_t> min_resolution_; |
| 104 | std::pair<uint32_t, uint32_t> max_resolution_; |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 105 | std::map<int, int> displays_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 106 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 107 | } // namespace android |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 108 | |
| 109 | #endif // ANDROID_DRM_H_ |