blob: d7ea35967db2c22a9d39e5f8c85ac5b1af76d035 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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 Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <stdint.h>
21
22#include <tuple>
23
Roman Stratiienko13cc3662020-08-29 21:35:39 +030024#include "DrmConnector.h"
25#include "DrmCrtc.h"
26#include "DrmEncoder.h"
27#include "DrmEventListener.h"
28#include "DrmPlane.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030029#include "platform/platform.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040030
31namespace android {
32
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010033class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040034 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010035 DrmDevice();
36 ~DrmDevice();
Sean Paul6a55e9f2015-04-30 15:31:06 -040037
Alexandru Gheorghec5463582018-03-27 15:52:02 +010038 std::tuple<int, int> Init(const char *path, int num_displays);
Sean Paul6a55e9f2015-04-30 15:31:06 -040039
Zach Reiznerff30b522015-10-28 19:08:45 -070040 int fd() const {
41 return fd_.get();
42 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040043
Zach Reiznerff30b522015-10-28 19:08:45 -070044 const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
45 return connectors_;
46 }
47
48 const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
49 return planes_;
50 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040051
Sean Paul406dbfc2016-02-10 15:35:17 -080052 std::pair<uint32_t, uint32_t> min_resolution() const {
53 return min_resolution_;
54 }
55
56 std::pair<uint32_t, uint32_t> max_resolution() const {
57 return max_resolution_;
58 }
59
Sean Paul6a55e9f2015-04-30 15:31:06 -040060 DrmConnector *GetConnectorForDisplay(int display) const;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000061 DrmConnector *GetWritebackConnectorForDisplay(int display) const;
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010062 DrmConnector *AvailableWritebackConnector(int display) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040063 DrmCrtc *GetCrtcForDisplay(int display) const;
64 DrmPlane *GetPlane(uint32_t id) const;
Sean Paul047b9b22015-07-28 14:15:42 -040065 DrmEventListener *event_listener();
Sean Paul6a55e9f2015-04-30 15:31:06 -040066
67 int GetPlaneProperty(const DrmPlane &plane, const char *prop_name,
68 DrmProperty *property);
Sean Paul877be972015-06-03 14:08:27 -040069 int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
70 DrmProperty *property);
Sean Paul6a55e9f2015-04-30 15:31:06 -040071 int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
72 DrmProperty *property);
73
Matvii Zorinef3c7972020-08-11 15:15:44 +030074 const std::string GetName() const;
75
Robert Foss0690c1c2016-10-20 11:07:57 -040076 const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040077 uint32_t next_mode_id();
Sean Paul6a55e9f2015-04-30 15:31:06 -040078
Sean Paul57355412015-09-19 09:14:34 -040079 int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id);
80 int DestroyPropertyBlob(uint32_t blob_id);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010081 bool HandlesDisplay(int display) const;
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030082 void RegisterHotplugHandler(DrmEventHandler *handler) {
83 event_listener_.RegisterHotplugHandler(handler);
84 }
Sean Paul57355412015-09-19 09:14:34 -040085
Sean Paul6a55e9f2015-04-30 15:31:06 -040086 private:
87 int TryEncoderForDisplay(int display, DrmEncoder *enc);
88 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
89 DrmProperty *property);
90
Sean Paul877be972015-06-03 14:08:27 -040091 int CreateDisplayPipe(DrmConnector *connector);
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000092 int AttachWriteback(DrmConnector *display_conn);
Sean Paul877be972015-06-03 14:08:27 -040093
Zach Reiznerff30b522015-10-28 19:08:45 -070094 UniqueFd fd_;
95 uint32_t mode_id_ = 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -040096
Zach Reiznerff30b522015-10-28 19:08:45 -070097 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000098 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -070099 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
100 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
101 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul047b9b22015-07-28 14:15:42 -0400102 DrmEventListener event_listener_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800103
104 std::pair<uint32_t, uint32_t> min_resolution_;
105 std::pair<uint32_t, uint32_t> max_resolution_;
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100106 std::map<int, int> displays_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400107};
Sean Paulf72cccd2018-08-27 13:59:08 -0400108} // namespace android
Sean Paul6a55e9f2015-04-30 15:31:06 -0400109
110#endif // ANDROID_DRM_H_