blob: ac20855bf27d7214115e00f4783c959d027ff34d [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
Roman Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Sean Paul6a55e9f2015-04-30 15:31:06 -040018
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020019#include <cstdint>
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030020#include <map>
Roman Stratiienko2290dc62025-02-09 12:53:35 +020021#include <optional>
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 Stratiienko2290dc62025-02-09 12:53:35 +020027#include "bufferinfo/BufferInfo.h"
Roman Stratiienko76892782023-01-16 17:15:53 +020028#include "utils/fd.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040029
30namespace android {
31
Roman Stratiienko8666dc92021-02-09 17:49:55 +020032class DrmFbImporter;
33class DrmPlane;
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030034class ResourceManager;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020035
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010036class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040037 public:
Roman Stratiienko1e053b42021-10-25 22:54:20 +030038 ~DrmDevice() = default;
Sean Paul6a55e9f2015-04-30 15:31:06 -040039
Gil Dekel907a51a2025-02-14 22:44:01 -050040 static auto CreateInstance(std::string const &path, ResourceManager *res_man,
41 uint32_t index) -> std::unique_ptr<DrmDevice>;
Sean Paul6a55e9f2015-04-30 15:31:06 -040042
Roman Stratiienko76892782023-01-16 17:15:53 +020043 auto &GetFd() const {
44 return fd_;
Zach Reiznerff30b522015-10-28 19:08:45 -070045 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040046
Gil Dekel907a51a2025-02-14 22:44:01 -050047 auto GetIndexInDevArray() const {
48 return index_in_dev_array_;
49 }
50
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030051 auto &GetResMan() {
52 return *res_man_;
53 }
54
Roman Stratiienko7d899112022-01-31 11:30:27 +020055 auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &;
Roman Stratiienkof2c060f2023-09-18 22:46:08 +030056 auto GetWritebackConnectors()
57 -> const std::vector<std::unique_ptr<DrmConnector>> &;
Roman Stratiienko7d899112022-01-31 11:30:27 +020058 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
59 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
60 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &;
Zach Reiznerff30b522015-10-28 19:08:45 -070061
Roman Stratiienko7d899112022-01-31 11:30:27 +020062 auto GetMinResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080063 return min_resolution_;
64 }
65
Roman Stratiienko7d899112022-01-31 11:30:27 +020066 auto GetMaxResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080067 return max_resolution_;
68 }
69
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020070 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030071
Roman Stratiienko6ede4662021-09-30 10:18:28 +030072 auto RegisterUserPropertyBlob(void *data, size_t length) const
73 -> DrmModeUserPropertyBlobUnique;
74
Roman Stratiienko3dacd472022-01-11 19:18:34 +020075 auto HasAddFb2ModifiersSupport() const {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020076 return HasAddFb2ModifiersSupport_;
77 }
78
Roman Stratiienko2290dc62025-02-09 12:53:35 +020079 auto CreateBufferForModeset(uint32_t width, uint32_t height)
80 -> std::optional<BufferInfo>;
81
Roman Stratiienko7d899112022-01-31 11:30:27 +020082 auto &GetDrmFbImporter() {
83 return *drm_fb_importer_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020084 }
85
Roman Stratiienko027987b2022-01-30 21:06:35 +020086 auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
87 for (const auto &crtc : crtcs_) {
88 if (crtc->GetId() == id) {
89 return crtc.get();
90 }
91 };
92
93 return nullptr;
94 }
95
Roman Stratiienko650299a2022-01-30 23:46:10 +020096 auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
97 for (const auto &enc : encoders_) {
98 if (enc->GetId() == id) {
99 return enc.get();
100 }
101 };
102
103 return nullptr;
104 }
105
Sean Paul6a55e9f2015-04-30 15:31:06 -0400106 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200107 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400108
Andrew Wolfers9777fba2024-12-12 17:51:43 +0000109 const std::optional<std::pair<uint64_t, uint64_t>> &GetCapCursorSize() const {
110 return cap_cursor_size_;
111 }
112
Roman Stratiienko0b063882021-09-30 10:15:05 +0300113 private:
Gil Dekel907a51a2025-02-14 22:44:01 -0500114 explicit DrmDevice(ResourceManager *res_man, uint32_t index);
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +0300115 auto Init(const char *path) -> int;
116
117 static auto IsKMSDev(const char *path) -> bool;
118
Roman Stratiienko76892782023-01-16 17:15:53 +0200119 SharedFd fd_;
Gil Dekel907a51a2025-02-14 22:44:01 -0500120 const uint32_t index_in_dev_array_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400121
Zach Reiznerff30b522015-10-28 19:08:45 -0700122 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000123 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700124 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
125 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
126 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800127
128 std::pair<uint32_t, uint32_t> min_resolution_;
129 std::pair<uint32_t, uint32_t> max_resolution_;
Andrew Wolfers9777fba2024-12-12 17:51:43 +0000130 std::optional<std::pair<uint64_t, uint64_t>> cap_cursor_size_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200131
132 bool HasAddFb2ModifiersSupport_{};
133
Roman Stratiienko7d899112022-01-31 11:30:27 +0200134 std::unique_ptr<DrmFbImporter> drm_fb_importer_;
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +0300135
136 ResourceManager *const res_man_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400137};
Andrew Wolfers9777fba2024-12-12 17:51:43 +0000138
Sean Paulf72cccd2018-08-27 13:59:08 -0400139} // namespace android