blob: bb515e06afcb511c0c58efa8611fd0472e8b9f42 [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 Stratiienkoaa3cd542020-08-29 11:26:16 +030021#include <tuple>
22
Roman Stratiienko13cc3662020-08-29 21:35:39 +030023#include "DrmConnector.h"
24#include "DrmCrtc.h"
25#include "DrmEncoder.h"
Roman Stratiienko0fade372021-02-20 13:59:55 +020026#include "utils/UniqueFd.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040027
28namespace android {
29
Roman Stratiienko8666dc92021-02-09 17:49:55 +020030class DrmFbImporter;
31class DrmPlane;
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030032class ResourceManager;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020033
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010034class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040035 public:
Roman Stratiienko1e053b42021-10-25 22:54:20 +030036 ~DrmDevice() = default;
Sean Paul6a55e9f2015-04-30 15:31:06 -040037
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030038 static auto CreateInstance(std::string const &path, ResourceManager *res_man)
39 -> std::unique_ptr<DrmDevice>;
Sean Paul6a55e9f2015-04-30 15:31:06 -040040
Roman Stratiienko7d899112022-01-31 11:30:27 +020041 auto GetFd() const {
Roman Stratiienko0fade372021-02-20 13:59:55 +020042 return fd_.Get();
Zach Reiznerff30b522015-10-28 19:08:45 -070043 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040044
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030045 auto &GetResMan() {
46 return *res_man_;
47 }
48
Roman Stratiienko7d899112022-01-31 11:30:27 +020049 auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &;
50 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
51 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
52 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &;
Zach Reiznerff30b522015-10-28 19:08:45 -070053
Roman Stratiienko7d899112022-01-31 11:30:27 +020054 auto GetMinResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080055 return min_resolution_;
56 }
57
Roman Stratiienko7d899112022-01-31 11:30:27 +020058 auto GetMaxResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080059 return max_resolution_;
60 }
61
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020062 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030063
Roman Stratiienko6ede4662021-09-30 10:18:28 +030064 auto RegisterUserPropertyBlob(void *data, size_t length) const
65 -> DrmModeUserPropertyBlobUnique;
66
Roman Stratiienko3dacd472022-01-11 19:18:34 +020067 auto HasAddFb2ModifiersSupport() const {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020068 return HasAddFb2ModifiersSupport_;
69 }
70
Roman Stratiienko7d899112022-01-31 11:30:27 +020071 auto &GetDrmFbImporter() {
72 return *drm_fb_importer_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020073 }
74
Roman Stratiienko027987b2022-01-30 21:06:35 +020075 auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
76 for (const auto &crtc : crtcs_) {
77 if (crtc->GetId() == id) {
78 return crtc.get();
79 }
80 };
81
82 return nullptr;
83 }
84
Roman Stratiienko650299a2022-01-30 23:46:10 +020085 auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
86 for (const auto &enc : encoders_) {
87 if (enc->GetId() == id) {
88 return enc.get();
89 }
90 };
91
92 return nullptr;
93 }
94
Sean Paul6a55e9f2015-04-30 15:31:06 -040095 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020096 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040097
Roman Stratiienko0b063882021-09-30 10:15:05 +030098 private:
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +030099 explicit DrmDevice(ResourceManager *res_man);
100 auto Init(const char *path) -> int;
101
102 static auto IsKMSDev(const char *path) -> bool;
103
Zach Reiznerff30b522015-10-28 19:08:45 -0700104 UniqueFd fd_;
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_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200114
115 bool HasAddFb2ModifiersSupport_{};
116
Roman Stratiienko7d899112022-01-31 11:30:27 +0200117 std::unique_ptr<DrmFbImporter> drm_fb_importer_;
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +0300118
119 ResourceManager *const res_man_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400120};
Sean Paulf72cccd2018-08-27 13:59:08 -0400121} // namespace android