blob: cbaa5360b4da03c57261a6b49fad9395ddd7d251 [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 Stratiienko76892782023-01-16 17:15:53 +020026#include "utils/fd.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 Stratiienko76892782023-01-16 17:15:53 +020041 auto &GetFd() const {
42 return fd_;
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>> &;
Roman Stratiienkof2c060f2023-09-18 22:46:08 +030050 auto GetWritebackConnectors()
51 -> const std::vector<std::unique_ptr<DrmConnector>> &;
Roman Stratiienko7d899112022-01-31 11:30:27 +020052 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
53 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
54 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &;
Zach Reiznerff30b522015-10-28 19:08:45 -070055
Roman Stratiienko7d899112022-01-31 11:30:27 +020056 auto GetMinResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080057 return min_resolution_;
58 }
59
Roman Stratiienko7d899112022-01-31 11:30:27 +020060 auto GetMaxResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080061 return max_resolution_;
62 }
63
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020064 std::string GetName() const;
Matvii Zorinef3c7972020-08-11 15:15:44 +030065
Roman Stratiienko6ede4662021-09-30 10:18:28 +030066 auto RegisterUserPropertyBlob(void *data, size_t length) const
67 -> DrmModeUserPropertyBlobUnique;
68
Roman Stratiienko3dacd472022-01-11 19:18:34 +020069 auto HasAddFb2ModifiersSupport() const {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020070 return HasAddFb2ModifiersSupport_;
71 }
72
Roman Stratiienko7d899112022-01-31 11:30:27 +020073 auto &GetDrmFbImporter() {
74 return *drm_fb_importer_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020075 }
76
Roman Stratiienko027987b2022-01-30 21:06:35 +020077 auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
78 for (const auto &crtc : crtcs_) {
79 if (crtc->GetId() == id) {
80 return crtc.get();
81 }
82 };
83
84 return nullptr;
85 }
86
Roman Stratiienko650299a2022-01-30 23:46:10 +020087 auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
88 for (const auto &enc : encoders_) {
89 if (enc->GetId() == id) {
90 return enc.get();
91 }
92 };
93
94 return nullptr;
95 }
96
Sean Paul6a55e9f2015-04-30 15:31:06 -040097 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020098 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040099
Roman Stratiienko0b063882021-09-30 10:15:05 +0300100 private:
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +0300101 explicit DrmDevice(ResourceManager *res_man);
102 auto Init(const char *path) -> int;
103
104 static auto IsKMSDev(const char *path) -> bool;
105
Roman Stratiienko76892782023-01-16 17:15:53 +0200106 SharedFd fd_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400107
Zach Reiznerff30b522015-10-28 19:08:45 -0700108 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000109 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700110 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
111 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
112 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800113
114 std::pair<uint32_t, uint32_t> min_resolution_;
115 std::pair<uint32_t, uint32_t> max_resolution_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200116
117 bool HasAddFb2ModifiersSupport_{};
118
Roman Stratiienko7d899112022-01-31 11:30:27 +0200119 std::unique_ptr<DrmFbImporter> drm_fb_importer_;
Roman Stratiienko5f21dbc2022-05-03 18:31:13 +0300120
121 ResourceManager *const res_man_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400122};
Sean Paulf72cccd2018-08-27 13:59:08 -0400123} // namespace android