blob: 4cbbd60cbbc278e163220d4c623a3c211b7185be [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"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020028#include "DrmFbImporter.h"
Roman Stratiienko0fade372021-02-20 13:59:55 +020029#include "utils/UniqueFd.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040030
31namespace android {
32
Roman Stratiienko8666dc92021-02-09 17:49:55 +020033class DrmFbImporter;
34class DrmPlane;
35
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010036class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040037 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010038 DrmDevice();
Roman Stratiienko1e053b42021-10-25 22:54:20 +030039 ~DrmDevice() = default;
Sean Paul6a55e9f2015-04-30 15:31:06 -040040
Alexandru Gheorghec5463582018-03-27 15:52:02 +010041 std::tuple<int, int> Init(const char *path, int num_displays);
Sean Paul6a55e9f2015-04-30 15:31:06 -040042
Zach Reiznerff30b522015-10-28 19:08:45 -070043 int fd() const {
Roman Stratiienko0fade372021-02-20 13:59:55 +020044 return fd_.Get();
Zach Reiznerff30b522015-10-28 19:08:45 -070045 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040046
Zach Reiznerff30b522015-10-28 19:08:45 -070047 const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
48 return connectors_;
49 }
50
51 const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
52 return planes_;
53 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040054
Sean Paul406dbfc2016-02-10 15:35:17 -080055 std::pair<uint32_t, uint32_t> min_resolution() const {
56 return min_resolution_;
57 }
58
59 std::pair<uint32_t, uint32_t> max_resolution() const {
60 return max_resolution_;
61 }
62
Sean Paul6a55e9f2015-04-30 15:31:06 -040063 DrmConnector *GetConnectorForDisplay(int display) const;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000064 DrmConnector *GetWritebackConnectorForDisplay(int display) const;
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010065 DrmConnector *AvailableWritebackConnector(int display) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040066 DrmCrtc *GetCrtcForDisplay(int display) const;
67 DrmPlane *GetPlane(uint32_t id) const;
68
Sean Paul877be972015-06-03 14:08:27 -040069 int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
Roman Stratiienko0b063882021-09-30 10:15:05 +030070 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040071 int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
Roman Stratiienko0b063882021-09-30 10:15:05 +030072 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040073
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020074 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030075
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
Roman Stratiienko6ede4662021-09-30 10:18:28 +030079 auto RegisterUserPropertyBlob(void *data, size_t length) const
80 -> DrmModeUserPropertyBlobUnique;
81
Alexandru Gheorghec5463582018-03-27 15:52:02 +010082 bool HandlesDisplay(int display) const;
Sean Paul57355412015-09-19 09:14:34 -040083
Roman Stratiienko8666dc92021-02-09 17:49:55 +020084 bool HasAddFb2ModifiersSupport() const {
85 return HasAddFb2ModifiersSupport_;
86 }
87
88 DrmFbImporter &GetDrmFbImporter() {
89 return *mDrmFbImporter.get();
90 }
91
Roman Stratiienko56f4adc2021-09-29 12:47:12 +030092 static auto IsKMSDev(const char *path) -> bool;
93
Sean Paul6a55e9f2015-04-30 15:31:06 -040094 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020095 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040096
Roman Stratiienko0b063882021-09-30 10:15:05 +030097 private:
98 int TryEncoderForDisplay(int display, DrmEncoder *enc);
99
Sean Paul877be972015-06-03 14:08:27 -0400100 int CreateDisplayPipe(DrmConnector *connector);
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000101 int AttachWriteback(DrmConnector *display_conn);
Sean Paul877be972015-06-03 14:08:27 -0400102
Zach Reiznerff30b522015-10-28 19:08:45 -0700103 UniqueFd fd_;
104 uint32_t mode_id_ = 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400105
Zach Reiznerff30b522015-10-28 19:08:45 -0700106 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000107 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700108 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
109 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
110 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800111
112 std::pair<uint32_t, uint32_t> min_resolution_;
113 std::pair<uint32_t, uint32_t> max_resolution_;
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100114 std::map<int, int> displays_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200115
116 bool HasAddFb2ModifiersSupport_{};
117
118 std::shared_ptr<DrmDevice> self;
119
120 std::unique_ptr<DrmFbImporter> mDrmFbImporter;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400121};
Sean Paulf72cccd2018-08-27 13:59:08 -0400122} // namespace android
Sean Paul6a55e9f2015-04-30 15:31:06 -0400123
124#endif // ANDROID_DRM_H_