blob: 3c4d7aeec095ca17f864295fc531aa9eae56cfb7 [file] [log] [blame]
Alexandru Gheorghec5463582018-03-27 15:52:02 +01001/*
2 * Copyright (C) 2018 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
Alexandru Gheorghec5463582018-03-27 15:52:02 +010018
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020019#include <cstring>
Roman Stratiienko4719abb2022-12-28 18:51:37 +020020#include <mutex>
Alexandru Gheorghec5463582018-03-27 15:52:02 +010021
Roman Stratiienko13cc3662020-08-29 21:35:39 +030022#include "DrmDevice.h"
Roman Stratiienko3dacd472022-01-11 19:18:34 +020023#include "DrmDisplayPipeline.h"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020024#include "DrmFbImporter.h"
Manasi Navare3f0c01a2024-10-04 18:01:55 +000025#include "DrmProperty.h"
Roman Stratiienko24a7fc42021-12-23 16:25:20 +020026#include "UEventListener.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030027
Alexandru Gheorghec5463582018-03-27 15:52:02 +010028namespace android {
29
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020030enum class CtmHandling {
31 kDrmOrGpu, /* Handled by DRM is possible, otherwise by GPU */
32 kDrmOrIgnore, /* Handled by DRM is possible, otherwise displayed as is */
33};
34
Roman Stratiienko3dacd472022-01-11 19:18:34 +020035class PipelineToFrontendBindingInterface {
36 public:
37 virtual ~PipelineToFrontendBindingInterface() = default;
Drew Davenport5951b112024-08-05 09:44:27 -060038 virtual bool BindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
39 virtual bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
40 virtual void FinalizeDisplayBinding() = 0;
Manasi Navare3f0c01a2024-10-04 18:01:55 +000041 virtual void NotifyDisplayLinkStatus(
42 std::shared_ptr<DrmDisplayPipeline> pipeline) = 0;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020043};
44
Alexandru Gheorghec5463582018-03-27 15:52:02 +010045class ResourceManager {
46 public:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020047 explicit ResourceManager(
48 PipelineToFrontendBindingInterface *p2f_bind_interface);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010049 ResourceManager(const ResourceManager &) = delete;
50 ResourceManager &operator=(const ResourceManager &) = delete;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020051 ResourceManager(const ResourceManager &&) = delete;
52 ResourceManager &&operator=(const ResourceManager &&) = delete;
Drew Davenportb8526052024-08-28 10:24:33 -060053 ~ResourceManager();
Roman Stratiienko1e053b42021-10-25 22:54:20 +030054
Roman Stratiienko3dacd472022-01-11 19:18:34 +020055 void Init();
56
57 void DeInit();
58
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020059 bool ForcedScalingWithGpu() const {
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020060 return scale_with_gpu_;
61 }
Alexandru Gheorghec5463582018-03-27 15:52:02 +010062
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020063 auto &GetCtmHandling() const {
64 return ctm_handling_;
65 }
66
Roman Stratiienko74923582022-01-17 11:24:21 +020067 auto &GetMainLock() {
68 return main_lock_;
69 }
70
Roman Stratiienkof2c060f2023-09-18 22:46:08 +030071 auto GetVirtualDisplayPipeline() -> std::shared_ptr<DrmDisplayPipeline>;
72 auto GetWritebackConnectorsCount() -> uint32_t;
73
Roman Stratiienkod0c035b2022-01-21 15:12:56 +020074 static auto GetTimeMonotonicNs() -> int64_t;
75
Alexandru Gheorghec5463582018-03-27 15:52:02 +010076 private:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020077 auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
78 void UpdateFrontendDisplays();
79 void DetachAllFrontendDisplays();
Alexandru Gheorghec5463582018-03-27 15:52:02 +010080
Alexandru Gheorghec5463582018-03-27 15:52:02 +010081 std::vector<std::unique_ptr<DrmDevice>> drms_;
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020082
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020083 // Android properties:
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020084 bool scale_with_gpu_{};
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020085 CtmHandling ctm_handling_{};
Roman Stratiienko1e053b42021-10-25 22:54:20 +030086
Roman Stratiienko4719abb2022-12-28 18:51:37 +020087 std::shared_ptr<UEventListener> uevent_listener_;
Roman Stratiienko74923582022-01-17 11:24:21 +020088
Roman Stratiienko9e2a2cd2022-12-28 20:47:29 +020089 std::recursive_mutex main_lock_;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020090
Roman Stratiienko63762a92023-09-18 22:33:45 +030091 std::map<DrmConnector *, std::shared_ptr<DrmDisplayPipeline>>
Roman Stratiienko3dacd472022-01-11 19:18:34 +020092 attached_pipelines_;
93
94 PipelineToFrontendBindingInterface *const frontend_interface_;
95
96 bool initialized_{};
Alexandru Gheorghec5463582018-03-27 15:52:02 +010097};
Sean Paulf72cccd2018-08-27 13:59:08 -040098} // namespace android