blob: c92004bacfc4868fe6fa56259e1c14a01f96d7cb [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
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030022#include <map>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030023#include <tuple>
24
Roman Stratiienko13cc3662020-08-29 21:35:39 +030025#include "DrmConnector.h"
26#include "DrmCrtc.h"
27#include "DrmEncoder.h"
28#include "DrmEventListener.h"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020029#include "DrmFbImporter.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030030#include "DrmPlane.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040031
32namespace android {
33
Roman Stratiienko8666dc92021-02-09 17:49:55 +020034class DrmFbImporter;
35class DrmPlane;
36
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010037class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040038 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010039 DrmDevice();
40 ~DrmDevice();
Sean Paul6a55e9f2015-04-30 15:31:06 -040041
Alexandru Gheorghec5463582018-03-27 15:52:02 +010042 std::tuple<int, int> Init(const char *path, int num_displays);
Sean Paul6a55e9f2015-04-30 15:31:06 -040043
Zach Reiznerff30b522015-10-28 19:08:45 -070044 int fd() const {
45 return fd_.get();
46 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040047
Zach Reiznerff30b522015-10-28 19:08:45 -070048 const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
49 return connectors_;
50 }
51
52 const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
53 return planes_;
54 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040055
Sean Paul406dbfc2016-02-10 15:35:17 -080056 std::pair<uint32_t, uint32_t> min_resolution() const {
57 return min_resolution_;
58 }
59
60 std::pair<uint32_t, uint32_t> max_resolution() const {
61 return max_resolution_;
62 }
63
Sean Paul6a55e9f2015-04-30 15:31:06 -040064 DrmConnector *GetConnectorForDisplay(int display) const;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000065 DrmConnector *GetWritebackConnectorForDisplay(int display) const;
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010066 DrmConnector *AvailableWritebackConnector(int display) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040067 DrmCrtc *GetCrtcForDisplay(int display) const;
68 DrmPlane *GetPlane(uint32_t id) const;
Sean Paul047b9b22015-07-28 14:15:42 -040069 DrmEventListener *event_listener();
Sean Paul6a55e9f2015-04-30 15:31:06 -040070
71 int GetPlaneProperty(const DrmPlane &plane, const char *prop_name,
72 DrmProperty *property);
Sean Paul877be972015-06-03 14:08:27 -040073 int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
74 DrmProperty *property);
Sean Paul6a55e9f2015-04-30 15:31:06 -040075 int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
76 DrmProperty *property);
77
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020078 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030079
Robert Foss0690c1c2016-10-20 11:07:57 -040080 const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040081 uint32_t next_mode_id();
Sean Paul6a55e9f2015-04-30 15:31:06 -040082
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020083 int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id) const;
84 int DestroyPropertyBlob(uint32_t blob_id) const;
Alexandru Gheorghec5463582018-03-27 15:52:02 +010085 bool HandlesDisplay(int display) const;
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030086 void RegisterHotplugHandler(DrmEventHandler *handler) {
87 event_listener_.RegisterHotplugHandler(handler);
88 }
Sean Paul57355412015-09-19 09:14:34 -040089
Roman Stratiienko8666dc92021-02-09 17:49:55 +020090 bool HasAddFb2ModifiersSupport() const {
91 return HasAddFb2ModifiersSupport_;
92 }
93
94 DrmFbImporter &GetDrmFbImporter() {
95 return *mDrmFbImporter.get();
96 }
97
Sean Paul6a55e9f2015-04-30 15:31:06 -040098 private:
99 int TryEncoderForDisplay(int display, DrmEncoder *enc);
100 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200101 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400102
Sean Paul877be972015-06-03 14:08:27 -0400103 int CreateDisplayPipe(DrmConnector *connector);
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000104 int AttachWriteback(DrmConnector *display_conn);
Sean Paul877be972015-06-03 14:08:27 -0400105
Zach Reiznerff30b522015-10-28 19:08:45 -0700106 UniqueFd fd_;
107 uint32_t mode_id_ = 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400108
Zach Reiznerff30b522015-10-28 19:08:45 -0700109 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000110 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700111 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
112 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
113 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul047b9b22015-07-28 14:15:42 -0400114 DrmEventListener event_listener_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800115
116 std::pair<uint32_t, uint32_t> min_resolution_;
117 std::pair<uint32_t, uint32_t> max_resolution_;
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100118 std::map<int, int> displays_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200119
120 bool HasAddFb2ModifiersSupport_{};
121
122 std::shared_ptr<DrmDevice> self;
123
124 std::unique_ptr<DrmFbImporter> mDrmFbImporter;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400125};
Sean Paulf72cccd2018-08-27 13:59:08 -0400126} // namespace android
Sean Paul6a55e9f2015-04-30 15:31:06 -0400127
128#endif // ANDROID_DRM_H_