blob: 9a2652c0e1101f847ed8217cb0a3d7f11a0bb7a7 [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"
Roman Stratiienko24a7fc42021-12-23 16:25:20 +020025#include "UEventListener.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030026
Alexandru Gheorghec5463582018-03-27 15:52:02 +010027namespace android {
28
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020029enum class CtmHandling {
30 kDrmOrGpu, /* Handled by DRM is possible, otherwise by GPU */
31 kDrmOrIgnore, /* Handled by DRM is possible, otherwise displayed as is */
32};
33
Roman Stratiienko3dacd472022-01-11 19:18:34 +020034class PipelineToFrontendBindingInterface {
35 public:
36 virtual ~PipelineToFrontendBindingInterface() = default;
Drew Davenport5951b112024-08-05 09:44:27 -060037 virtual bool BindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
38 virtual bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
39 virtual void FinalizeDisplayBinding() = 0;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020040};
41
Alexandru Gheorghec5463582018-03-27 15:52:02 +010042class ResourceManager {
43 public:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020044 explicit ResourceManager(
45 PipelineToFrontendBindingInterface *p2f_bind_interface);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010046 ResourceManager(const ResourceManager &) = delete;
47 ResourceManager &operator=(const ResourceManager &) = delete;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020048 ResourceManager(const ResourceManager &&) = delete;
49 ResourceManager &&operator=(const ResourceManager &&) = delete;
Drew Davenportb8526052024-08-28 10:24:33 -060050 ~ResourceManager();
Roman Stratiienko1e053b42021-10-25 22:54:20 +030051
Roman Stratiienko3dacd472022-01-11 19:18:34 +020052 void Init();
53
54 void DeInit();
55
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020056 bool ForcedScalingWithGpu() const {
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020057 return scale_with_gpu_;
58 }
Alexandru Gheorghec5463582018-03-27 15:52:02 +010059
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020060 auto &GetCtmHandling() const {
61 return ctm_handling_;
62 }
63
Roman Stratiienko74923582022-01-17 11:24:21 +020064 auto &GetMainLock() {
65 return main_lock_;
66 }
67
Roman Stratiienkof2c060f2023-09-18 22:46:08 +030068 auto GetVirtualDisplayPipeline() -> std::shared_ptr<DrmDisplayPipeline>;
69 auto GetWritebackConnectorsCount() -> uint32_t;
70
Roman Stratiienkod0c035b2022-01-21 15:12:56 +020071 static auto GetTimeMonotonicNs() -> int64_t;
72
Alexandru Gheorghec5463582018-03-27 15:52:02 +010073 private:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020074 auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
75 void UpdateFrontendDisplays();
76 void DetachAllFrontendDisplays();
Alexandru Gheorghec5463582018-03-27 15:52:02 +010077
Alexandru Gheorghec5463582018-03-27 15:52:02 +010078 std::vector<std::unique_ptr<DrmDevice>> drms_;
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020079
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020080 // Android properties:
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020081 bool scale_with_gpu_{};
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020082 CtmHandling ctm_handling_{};
Roman Stratiienko1e053b42021-10-25 22:54:20 +030083
Roman Stratiienko4719abb2022-12-28 18:51:37 +020084 std::shared_ptr<UEventListener> uevent_listener_;
Roman Stratiienko74923582022-01-17 11:24:21 +020085
Roman Stratiienko9e2a2cd2022-12-28 20:47:29 +020086 std::recursive_mutex main_lock_;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020087
Roman Stratiienko63762a92023-09-18 22:33:45 +030088 std::map<DrmConnector *, std::shared_ptr<DrmDisplayPipeline>>
Roman Stratiienko3dacd472022-01-11 19:18:34 +020089 attached_pipelines_;
90
91 PipelineToFrontendBindingInterface *const frontend_interface_;
92
93 bool initialized_{};
Alexandru Gheorghec5463582018-03-27 15:52:02 +010094};
Sean Paulf72cccd2018-08-27 13:59:08 -040095} // namespace android