| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 1 | /* | 
|  | 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 Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 18 |  | 
| Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 19 | #include <cstring> | 
| Roman Stratiienko | 4719abb | 2022-12-28 18:51:37 +0200 | [diff] [blame] | 20 | #include <mutex> | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 21 |  | 
| Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 22 | #include "DrmDevice.h" | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 23 | #include "DrmDisplayPipeline.h" | 
| Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 24 | #include "DrmFbImporter.h" | 
| Roman Stratiienko | 24a7fc4 | 2021-12-23 16:25:20 +0200 | [diff] [blame] | 25 | #include "UEventListener.h" | 
| Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 26 |  | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 27 | namespace android { | 
|  | 28 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 29 | enum 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 Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 34 | class PipelineToFrontendBindingInterface { | 
|  | 35 | public: | 
|  | 36 | virtual ~PipelineToFrontendBindingInterface() = default; | 
|  | 37 | virtual bool BindDisplay(DrmDisplayPipeline *); | 
|  | 38 | virtual bool UnbindDisplay(DrmDisplayPipeline *); | 
|  | 39 | virtual void FinalizeDisplayBinding(); | 
|  | 40 | }; | 
|  | 41 |  | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 42 | class ResourceManager { | 
|  | 43 | public: | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 44 | explicit ResourceManager( | 
|  | 45 | PipelineToFrontendBindingInterface *p2f_bind_interface); | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 46 | ResourceManager(const ResourceManager &) = delete; | 
|  | 47 | ResourceManager &operator=(const ResourceManager &) = delete; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 48 | ResourceManager(const ResourceManager &&) = delete; | 
|  | 49 | ResourceManager &&operator=(const ResourceManager &&) = delete; | 
| Roman Stratiienko | 4719abb | 2022-12-28 18:51:37 +0200 | [diff] [blame] | 50 | ~ResourceManager() = default; | 
| Roman Stratiienko | 1e053b4 | 2021-10-25 22:54:20 +0300 | [diff] [blame] | 51 |  | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 52 | void Init(); | 
|  | 53 |  | 
|  | 54 | void DeInit(); | 
|  | 55 |  | 
| Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 56 | bool ForcedScalingWithGpu() const { | 
| Roman Stratiienko | 65f2ba8 | 2019-12-20 17:04:01 +0200 | [diff] [blame] | 57 | return scale_with_gpu_; | 
|  | 58 | } | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 59 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 60 | auto &GetCtmHandling() const { | 
|  | 61 | return ctm_handling_; | 
|  | 62 | } | 
|  | 63 |  | 
| Roman Stratiienko | 7492358 | 2022-01-17 11:24:21 +0200 | [diff] [blame] | 64 | auto &GetMainLock() { | 
|  | 65 | return main_lock_; | 
|  | 66 | } | 
|  | 67 |  | 
| Roman Stratiienko | d0c035b | 2022-01-21 15:12:56 +0200 | [diff] [blame] | 68 | static auto GetTimeMonotonicNs() -> int64_t; | 
|  | 69 |  | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 70 | private: | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 71 | auto GetOrderedConnectors() -> std::vector<DrmConnector *>; | 
|  | 72 | void UpdateFrontendDisplays(); | 
|  | 73 | void DetachAllFrontendDisplays(); | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 74 |  | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 75 | std::vector<std::unique_ptr<DrmDevice>> drms_; | 
| Roman Stratiienko | 65f2ba8 | 2019-12-20 17:04:01 +0200 | [diff] [blame] | 76 |  | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 77 | // Android properties: | 
| Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 78 | bool scale_with_gpu_{}; | 
| Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 79 | CtmHandling ctm_handling_{}; | 
| Roman Stratiienko | 1e053b4 | 2021-10-25 22:54:20 +0300 | [diff] [blame] | 80 |  | 
| Roman Stratiienko | 4719abb | 2022-12-28 18:51:37 +0200 | [diff] [blame] | 81 | std::shared_ptr<UEventListener> uevent_listener_; | 
| Roman Stratiienko | 7492358 | 2022-01-17 11:24:21 +0200 | [diff] [blame] | 82 |  | 
| Roman Stratiienko | 9e2a2cd | 2022-12-28 20:47:29 +0200 | [diff] [blame] | 83 | std::recursive_mutex main_lock_; | 
| Roman Stratiienko | 3dacd47 | 2022-01-11 19:18:34 +0200 | [diff] [blame] | 84 |  | 
|  | 85 | std::map<DrmConnector *, std::unique_ptr<DrmDisplayPipeline>> | 
|  | 86 | attached_pipelines_; | 
|  | 87 |  | 
|  | 88 | PipelineToFrontendBindingInterface *const frontend_interface_; | 
|  | 89 |  | 
|  | 90 | bool initialized_{}; | 
| Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 91 | }; | 
| Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 92 | }  // namespace android |