blob: 9983d61ea8dcb0132a373378b95e8db6f4e6292e [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 Stratiienkoe78235c2021-12-23 17:36:12 +020020#include <cstdint>
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030021#include <map>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022#include <tuple>
23
Roman Stratiienko13cc3662020-08-29 21:35:39 +030024#include "DrmConnector.h"
25#include "DrmCrtc.h"
26#include "DrmEncoder.h"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020027#include "DrmFbImporter.h"
Roman Stratiienko0fade372021-02-20 13:59:55 +020028#include "utils/UniqueFd.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040029
30namespace android {
31
Roman Stratiienko8666dc92021-02-09 17:49:55 +020032class DrmFbImporter;
33class DrmPlane;
34
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010035class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040036 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010037 DrmDevice();
Roman Stratiienko1e053b42021-10-25 22:54:20 +030038 ~DrmDevice() = default;
Sean Paul6a55e9f2015-04-30 15:31:06 -040039
Alexandru Gheorghec5463582018-03-27 15:52:02 +010040 std::tuple<int, int> Init(const char *path, int num_displays);
Sean Paul6a55e9f2015-04-30 15:31:06 -040041
Zach Reiznerff30b522015-10-28 19:08:45 -070042 int fd() const {
Roman Stratiienko0fade372021-02-20 13:59:55 +020043 return fd_.Get();
Zach Reiznerff30b522015-10-28 19:08:45 -070044 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040045
Zach Reiznerff30b522015-10-28 19:08:45 -070046 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 Paul6a55e9f2015-04-30 15:31:06 -040053
Sean Paul406dbfc2016-02-10 15:35:17 -080054 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 Paul6a55e9f2015-04-30 15:31:06 -040062 DrmConnector *GetConnectorForDisplay(int display) const;
63 DrmCrtc *GetCrtcForDisplay(int display) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040064
Sean Paul877be972015-06-03 14:08:27 -040065 int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
Roman Stratiienko0b063882021-09-30 10:15:05 +030066 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040067 int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
Roman Stratiienko0b063882021-09-30 10:15:05 +030068 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040069
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020070 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030071
Robert Foss0690c1c2016-10-20 11:07:57 -040072 const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040073 uint32_t next_mode_id();
Sean Paul6a55e9f2015-04-30 15:31:06 -040074
Roman Stratiienko6ede4662021-09-30 10:18:28 +030075 auto RegisterUserPropertyBlob(void *data, size_t length) const
76 -> DrmModeUserPropertyBlobUnique;
77
Alexandru Gheorghec5463582018-03-27 15:52:02 +010078 bool HandlesDisplay(int display) const;
Sean Paul57355412015-09-19 09:14:34 -040079
Roman Stratiienko8666dc92021-02-09 17:49:55 +020080 bool HasAddFb2ModifiersSupport() const {
81 return HasAddFb2ModifiersSupport_;
82 }
83
84 DrmFbImporter &GetDrmFbImporter() {
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020085 return *mDrmFbImporter;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020086 }
87
Roman Stratiienko56f4adc2021-09-29 12:47:12 +030088 static auto IsKMSDev(const char *path) -> bool;
89
Sean Paul6a55e9f2015-04-30 15:31:06 -040090 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020091 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040092
Roman Stratiienko0b063882021-09-30 10:15:05 +030093 private:
94 int TryEncoderForDisplay(int display, DrmEncoder *enc);
95
Sean Paul877be972015-06-03 14:08:27 -040096 int CreateDisplayPipe(DrmConnector *connector);
97
Zach Reiznerff30b522015-10-28 19:08:45 -070098 UniqueFd fd_;
99 uint32_t mode_id_ = 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400100
Zach Reiznerff30b522015-10-28 19:08:45 -0700101 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000102 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700103 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
104 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
105 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800106
107 std::pair<uint32_t, uint32_t> min_resolution_;
108 std::pair<uint32_t, uint32_t> max_resolution_;
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100109 std::map<int, int> displays_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200110
111 bool HasAddFb2ModifiersSupport_{};
112
113 std::shared_ptr<DrmDevice> self;
114
115 std::unique_ptr<DrmFbImporter> mDrmFbImporter;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400116};
Sean Paulf72cccd2018-08-27 13:59:08 -0400117} // namespace android
Sean Paul6a55e9f2015-04-30 15:31:06 -0400118
119#endif // ANDROID_DRM_H_