xref: /aosp_15_r20/external/drm_hwcomposer/drm/ResourceManager.h (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker  * Copyright (C) 2018 The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker  *
4*0a9764feSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker  *
8*0a9764feSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker  *
10*0a9764feSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker  * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker  */
16*0a9764feSAndroid Build Coastguard Worker 
17*0a9764feSAndroid Build Coastguard Worker #pragma once
18*0a9764feSAndroid Build Coastguard Worker 
19*0a9764feSAndroid Build Coastguard Worker #include <cstring>
20*0a9764feSAndroid Build Coastguard Worker #include <mutex>
21*0a9764feSAndroid Build Coastguard Worker 
22*0a9764feSAndroid Build Coastguard Worker #include "DrmDevice.h"
23*0a9764feSAndroid Build Coastguard Worker #include "DrmDisplayPipeline.h"
24*0a9764feSAndroid Build Coastguard Worker #include "DrmFbImporter.h"
25*0a9764feSAndroid Build Coastguard Worker #include "DrmProperty.h"
26*0a9764feSAndroid Build Coastguard Worker #include "UEventListener.h"
27*0a9764feSAndroid Build Coastguard Worker 
28*0a9764feSAndroid Build Coastguard Worker namespace android {
29*0a9764feSAndroid Build Coastguard Worker 
30*0a9764feSAndroid Build Coastguard Worker enum class CtmHandling {
31*0a9764feSAndroid Build Coastguard Worker   kDrmOrGpu,    /* Handled by DRM is possible, otherwise by GPU */
32*0a9764feSAndroid Build Coastguard Worker   kDrmOrIgnore, /* Handled by DRM is possible, otherwise displayed as is */
33*0a9764feSAndroid Build Coastguard Worker };
34*0a9764feSAndroid Build Coastguard Worker 
35*0a9764feSAndroid Build Coastguard Worker class PipelineToFrontendBindingInterface {
36*0a9764feSAndroid Build Coastguard Worker  public:
37*0a9764feSAndroid Build Coastguard Worker   virtual ~PipelineToFrontendBindingInterface() = default;
38*0a9764feSAndroid Build Coastguard Worker   virtual bool BindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
39*0a9764feSAndroid Build Coastguard Worker   virtual bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0;
40*0a9764feSAndroid Build Coastguard Worker   virtual void FinalizeDisplayBinding() = 0;
41*0a9764feSAndroid Build Coastguard Worker   virtual void NotifyDisplayLinkStatus(
42*0a9764feSAndroid Build Coastguard Worker       std::shared_ptr<DrmDisplayPipeline> pipeline) = 0;
43*0a9764feSAndroid Build Coastguard Worker };
44*0a9764feSAndroid Build Coastguard Worker 
45*0a9764feSAndroid Build Coastguard Worker class ResourceManager {
46*0a9764feSAndroid Build Coastguard Worker  public:
47*0a9764feSAndroid Build Coastguard Worker   explicit ResourceManager(
48*0a9764feSAndroid Build Coastguard Worker       PipelineToFrontendBindingInterface *p2f_bind_interface);
49*0a9764feSAndroid Build Coastguard Worker   ResourceManager(const ResourceManager &) = delete;
50*0a9764feSAndroid Build Coastguard Worker   ResourceManager &operator=(const ResourceManager &) = delete;
51*0a9764feSAndroid Build Coastguard Worker   ResourceManager(const ResourceManager &&) = delete;
52*0a9764feSAndroid Build Coastguard Worker   ResourceManager &&operator=(const ResourceManager &&) = delete;
53*0a9764feSAndroid Build Coastguard Worker   ~ResourceManager();
54*0a9764feSAndroid Build Coastguard Worker 
55*0a9764feSAndroid Build Coastguard Worker   void Init();
56*0a9764feSAndroid Build Coastguard Worker 
57*0a9764feSAndroid Build Coastguard Worker   void DeInit();
58*0a9764feSAndroid Build Coastguard Worker 
ForcedScalingWithGpu()59*0a9764feSAndroid Build Coastguard Worker   bool ForcedScalingWithGpu() const {
60*0a9764feSAndroid Build Coastguard Worker     return scale_with_gpu_;
61*0a9764feSAndroid Build Coastguard Worker   }
62*0a9764feSAndroid Build Coastguard Worker 
GetCtmHandling()63*0a9764feSAndroid Build Coastguard Worker   auto &GetCtmHandling() const {
64*0a9764feSAndroid Build Coastguard Worker     return ctm_handling_;
65*0a9764feSAndroid Build Coastguard Worker   }
66*0a9764feSAndroid Build Coastguard Worker 
GetMainLock()67*0a9764feSAndroid Build Coastguard Worker   auto &GetMainLock() {
68*0a9764feSAndroid Build Coastguard Worker     return main_lock_;
69*0a9764feSAndroid Build Coastguard Worker   }
70*0a9764feSAndroid Build Coastguard Worker 
71*0a9764feSAndroid Build Coastguard Worker   auto GetVirtualDisplayPipeline() -> std::shared_ptr<DrmDisplayPipeline>;
72*0a9764feSAndroid Build Coastguard Worker   auto GetWritebackConnectorsCount() -> uint32_t;
73*0a9764feSAndroid Build Coastguard Worker 
74*0a9764feSAndroid Build Coastguard Worker   static auto GetTimeMonotonicNs() -> int64_t;
75*0a9764feSAndroid Build Coastguard Worker 
76*0a9764feSAndroid Build Coastguard Worker  private:
77*0a9764feSAndroid Build Coastguard Worker   auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
78*0a9764feSAndroid Build Coastguard Worker   void UpdateFrontendDisplays();
79*0a9764feSAndroid Build Coastguard Worker   void DetachAllFrontendDisplays();
80*0a9764feSAndroid Build Coastguard Worker 
81*0a9764feSAndroid Build Coastguard Worker   std::vector<std::unique_ptr<DrmDevice>> drms_;
82*0a9764feSAndroid Build Coastguard Worker 
83*0a9764feSAndroid Build Coastguard Worker   // Android properties:
84*0a9764feSAndroid Build Coastguard Worker   bool scale_with_gpu_{};
85*0a9764feSAndroid Build Coastguard Worker   CtmHandling ctm_handling_{};
86*0a9764feSAndroid Build Coastguard Worker 
87*0a9764feSAndroid Build Coastguard Worker   std::shared_ptr<UEventListener> uevent_listener_;
88*0a9764feSAndroid Build Coastguard Worker 
89*0a9764feSAndroid Build Coastguard Worker   std::recursive_mutex main_lock_;
90*0a9764feSAndroid Build Coastguard Worker 
91*0a9764feSAndroid Build Coastguard Worker   std::map<DrmConnector *, std::shared_ptr<DrmDisplayPipeline>>
92*0a9764feSAndroid Build Coastguard Worker       attached_pipelines_;
93*0a9764feSAndroid Build Coastguard Worker 
94*0a9764feSAndroid Build Coastguard Worker   PipelineToFrontendBindingInterface *const frontend_interface_;
95*0a9764feSAndroid Build Coastguard Worker 
96*0a9764feSAndroid Build Coastguard Worker   bool initialized_{};
97*0a9764feSAndroid Build Coastguard Worker };
98*0a9764feSAndroid Build Coastguard Worker }  // namespace android
99