blob: 7fa3fc69a988b3e7e6e54723db6aac33f686d1f6 [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;
37 virtual bool BindDisplay(DrmDisplayPipeline *);
38 virtual bool UnbindDisplay(DrmDisplayPipeline *);
39 virtual void FinalizeDisplayBinding();
40};
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;
Roman Stratiienko4719abb2022-12-28 18:51:37 +020050 ~ResourceManager() = default;
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 Stratiienkod0c035b2022-01-21 15:12:56 +020068 static auto GetTimeMonotonicNs() -> int64_t;
69
Alexandru Gheorghec5463582018-03-27 15:52:02 +010070 private:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020071 auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
72 void UpdateFrontendDisplays();
73 void DetachAllFrontendDisplays();
Alexandru Gheorghec5463582018-03-27 15:52:02 +010074
Alexandru Gheorghec5463582018-03-27 15:52:02 +010075 std::vector<std::unique_ptr<DrmDevice>> drms_;
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020076
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020077 // Android properties:
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020078 bool scale_with_gpu_{};
Roman Stratiienko0da91bf2023-01-17 18:06:04 +020079 CtmHandling ctm_handling_{};
Roman Stratiienko1e053b42021-10-25 22:54:20 +030080
Roman Stratiienko4719abb2022-12-28 18:51:37 +020081 std::shared_ptr<UEventListener> uevent_listener_;
Roman Stratiienko74923582022-01-17 11:24:21 +020082
Roman Stratiienko9e2a2cd2022-12-28 20:47:29 +020083 std::recursive_mutex main_lock_;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020084
85 std::map<DrmConnector *, std::unique_ptr<DrmDisplayPipeline>>
86 attached_pipelines_;
87
88 PipelineToFrontendBindingInterface *const frontend_interface_;
89
90 bool initialized_{};
Alexandru Gheorghec5463582018-03-27 15:52:02 +010091};
Sean Paulf72cccd2018-08-27 13:59:08 -040092} // namespace android