blob: 88ba87892ebda17fae1ac753b9295567897adbb9 [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
17#ifndef RESOURCEMANAGER_H
18#define RESOURCEMANAGER_H
19
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020020#include <cstring>
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 Stratiienko3dacd472022-01-11 19:18:34 +020029class PipelineToFrontendBindingInterface {
30 public:
31 virtual ~PipelineToFrontendBindingInterface() = default;
32 virtual bool BindDisplay(DrmDisplayPipeline *);
33 virtual bool UnbindDisplay(DrmDisplayPipeline *);
34 virtual void FinalizeDisplayBinding();
35};
36
Alexandru Gheorghec5463582018-03-27 15:52:02 +010037class ResourceManager {
38 public:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020039 explicit ResourceManager(
40 PipelineToFrontendBindingInterface *p2f_bind_interface);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010041 ResourceManager(const ResourceManager &) = delete;
42 ResourceManager &operator=(const ResourceManager &) = delete;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020043 ResourceManager(const ResourceManager &&) = delete;
44 ResourceManager &&operator=(const ResourceManager &&) = delete;
Roman Stratiienko24a7fc42021-12-23 16:25:20 +020045 ~ResourceManager();
Roman Stratiienko1e053b42021-10-25 22:54:20 +030046
Roman Stratiienko3dacd472022-01-11 19:18:34 +020047 void Init();
48
49 void DeInit();
50
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020051 bool ForcedScalingWithGpu() const {
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020052 return scale_with_gpu_;
53 }
Alexandru Gheorghec5463582018-03-27 15:52:02 +010054
Roman Stratiienko74923582022-01-17 11:24:21 +020055 auto &GetMainLock() {
56 return main_lock_;
57 }
58
Roman Stratiienkod0c035b2022-01-21 15:12:56 +020059 static auto GetTimeMonotonicNs() -> int64_t;
60
Alexandru Gheorghec5463582018-03-27 15:52:02 +010061 private:
Roman Stratiienko3dacd472022-01-11 19:18:34 +020062 auto AddDrmDevice(std::string const &path) -> int;
63 auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
64 void UpdateFrontendDisplays();
65 void DetachAllFrontendDisplays();
Alexandru Gheorghec5463582018-03-27 15:52:02 +010066
Alexandru Gheorghec5463582018-03-27 15:52:02 +010067 std::vector<std::unique_ptr<DrmDevice>> drms_;
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020068
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020069 bool scale_with_gpu_{};
Roman Stratiienko1e053b42021-10-25 22:54:20 +030070
71 UEventListener uevent_listener_;
Roman Stratiienko74923582022-01-17 11:24:21 +020072
73 std::mutex main_lock_;
Roman Stratiienko3dacd472022-01-11 19:18:34 +020074
75 std::map<DrmConnector *, std::unique_ptr<DrmDisplayPipeline>>
76 attached_pipelines_;
77
78 PipelineToFrontendBindingInterface *const frontend_interface_;
79
80 bool initialized_{};
Alexandru Gheorghec5463582018-03-27 15:52:02 +010081};
Sean Paulf72cccd2018-08-27 13:59:08 -040082} // namespace android
Alexandru Gheorghec5463582018-03-27 15:52:02 +010083
84#endif // RESOURCEMANAGER_H