blob: 52207604264e7c336b424afea665d611c26b6c62 [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
Roman Stratiienko7d899112022-01-31 11:30:27 +020042 auto GetFd() 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
Roman Stratiienko7d899112022-01-31 11:30:27 +020046 auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &;
47 auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
48 auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
49 auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &;
Zach Reiznerff30b522015-10-28 19:08:45 -070050
Roman Stratiienko7d899112022-01-31 11:30:27 +020051 auto GetMinResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080052 return min_resolution_;
53 }
54
Roman Stratiienko7d899112022-01-31 11:30:27 +020055 auto GetMaxResolution() const {
Sean Paul406dbfc2016-02-10 15:35:17 -080056 return max_resolution_;
57 }
58
Roman Stratiienko19c162f2022-02-01 09:35:08 +020059 auto *GetPipelineForDisplay(int display) {
60 return pipelines_.count(display) != 0 ? pipelines_.at(display).get()
61 : nullptr;
62 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040063
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
Alexandru Gheorghec5463582018-03-27 15:52:02 +010069 bool HandlesDisplay(int display) const;
Sean Paul57355412015-09-19 09:14:34 -040070
Roman Stratiienko8666dc92021-02-09 17:49:55 +020071 bool HasAddFb2ModifiersSupport() const {
72 return HasAddFb2ModifiersSupport_;
73 }
74
Roman Stratiienko7d899112022-01-31 11:30:27 +020075 auto &GetDrmFbImporter() {
76 return *drm_fb_importer_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020077 }
78
Roman Stratiienko56f4adc2021-09-29 12:47:12 +030079 static auto IsKMSDev(const char *path) -> bool;
80
Roman Stratiienko027987b2022-01-30 21:06:35 +020081 auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
82 for (const auto &crtc : crtcs_) {
83 if (crtc->GetId() == id) {
84 return crtc.get();
85 }
86 };
87
88 return nullptr;
89 }
90
Roman Stratiienko650299a2022-01-30 23:46:10 +020091 auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
92 for (const auto &enc : encoders_) {
93 if (enc->GetId() == id) {
94 return enc.get();
95 }
96 };
97
98 return nullptr;
99 }
100
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +0200101 auto GetDisplayId(DrmConnector *conn) -> int;
Roman Stratiienko650299a2022-01-30 23:46:10 +0200102
Sean Paul6a55e9f2015-04-30 15:31:06 -0400103 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200104 DrmProperty *property) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400105
Roman Stratiienko0b063882021-09-30 10:15:05 +0300106 private:
Zach Reiznerff30b522015-10-28 19:08:45 -0700107 UniqueFd fd_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400108
Zach Reiznerff30b522015-10-28 19:08:45 -0700109 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000110 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -0700111 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
112 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
113 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul406dbfc2016-02-10 15:35:17 -0800114
115 std::pair<uint32_t, uint32_t> min_resolution_;
116 std::pair<uint32_t, uint32_t> max_resolution_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200117
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +0200118 std::map<int /*display*/, std::unique_ptr<DrmDisplayPipeline>> pipelines_;
Roman Stratiienko10be8752022-01-30 20:28:46 +0200119
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200120 bool HasAddFb2ModifiersSupport_{};
121
Roman Stratiienko7d899112022-01-31 11:30:27 +0200122 std::unique_ptr<DrmFbImporter> drm_fb_importer_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400123};
Sean Paulf72cccd2018-08-27 13:59:08 -0400124} // namespace android
Sean Paul6a55e9f2015-04-30 15:31:06 -0400125
126#endif // ANDROID_DRM_H_