• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef RESOURCEMANAGER_H
18 #define RESOURCEMANAGER_H
19 
20 #include <cstring>
21 
22 #include "DrmDevice.h"
23 #include "DrmDisplayPipeline.h"
24 #include "DrmFbImporter.h"
25 #include "UEventListener.h"
26 
27 namespace android {
28 
29 class PipelineToFrontendBindingInterface {
30  public:
31   virtual ~PipelineToFrontendBindingInterface() = default;
32   virtual bool BindDisplay(DrmDisplayPipeline *);
33   virtual bool UnbindDisplay(DrmDisplayPipeline *);
34   virtual void FinalizeDisplayBinding();
35 };
36 
37 class ResourceManager {
38  public:
39   explicit ResourceManager(
40       PipelineToFrontendBindingInterface *p2f_bind_interface);
41   ResourceManager(const ResourceManager &) = delete;
42   ResourceManager &operator=(const ResourceManager &) = delete;
43   ResourceManager(const ResourceManager &&) = delete;
44   ResourceManager &&operator=(const ResourceManager &&) = delete;
45   ~ResourceManager();
46 
47   void Init();
48 
49   void DeInit();
50 
ForcedScalingWithGpu()51   bool ForcedScalingWithGpu() const {
52     return scale_with_gpu_;
53   }
54 
GetMainLock()55   auto &GetMainLock() {
56     return main_lock_;
57   }
58 
59   static auto GetTimeMonotonicNs() -> int64_t;
60 
61  private:
62   auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
63   void UpdateFrontendDisplays();
64   void DetachAllFrontendDisplays();
65 
66   std::vector<std::unique_ptr<DrmDevice>> drms_;
67 
68   bool scale_with_gpu_{};
69 
70   UEventListener uevent_listener_;
71 
72   std::mutex main_lock_;
73 
74   std::map<DrmConnector *, std::unique_ptr<DrmDisplayPipeline>>
75       attached_pipelines_;
76 
77   PipelineToFrontendBindingInterface *const frontend_interface_;
78 
79   bool initialized_{};
80 };
81 }  // namespace android
82 
83 #endif  // RESOURCEMANAGER_H
84