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 AddDrmDevice(std::string const &path) -> int; 63 auto GetOrderedConnectors() -> std::vector<DrmConnector *>; 64 void UpdateFrontendDisplays(); 65 void DetachAllFrontendDisplays(); 66 67 std::vector<std::unique_ptr<DrmDevice>> drms_; 68 69 bool scale_with_gpu_{}; 70 71 UEventListener uevent_listener_; 72 73 std::mutex main_lock_; 74 75 std::map<DrmConnector *, std::unique_ptr<DrmDisplayPipeline>> 76 attached_pipelines_; 77 78 PipelineToFrontendBindingInterface *const frontend_interface_; 79 80 bool initialized_{}; 81 }; 82 } // namespace android 83 84 #endif // RESOURCEMANAGER_H 85