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 #pragma once 18 19 #include <cstring> 20 #include <mutex> 21 22 #include "DrmDevice.h" 23 #include "DrmDisplayPipeline.h" 24 #include "DrmFbImporter.h" 25 #include "DrmProperty.h" 26 #include "UEventListener.h" 27 28 namespace android { 29 30 enum class CtmHandling { 31 kDrmOrGpu, /* Handled by DRM is possible, otherwise by GPU */ 32 kDrmOrIgnore, /* Handled by DRM is possible, otherwise displayed as is */ 33 }; 34 35 class PipelineToFrontendBindingInterface { 36 public: 37 virtual ~PipelineToFrontendBindingInterface() = default; 38 virtual bool BindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0; 39 virtual bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline>) = 0; 40 virtual void FinalizeDisplayBinding() = 0; 41 virtual void NotifyDisplayLinkStatus( 42 std::shared_ptr<DrmDisplayPipeline> pipeline) = 0; 43 }; 44 45 class ResourceManager { 46 public: 47 explicit ResourceManager( 48 PipelineToFrontendBindingInterface *p2f_bind_interface); 49 ResourceManager(const ResourceManager &) = delete; 50 ResourceManager &operator=(const ResourceManager &) = delete; 51 ResourceManager(const ResourceManager &&) = delete; 52 ResourceManager &&operator=(const ResourceManager &&) = delete; 53 ~ResourceManager(); 54 55 void Init(); 56 57 void DeInit(); 58 ForcedScalingWithGpu()59 bool ForcedScalingWithGpu() const { 60 return scale_with_gpu_; 61 } 62 GetCtmHandling()63 auto &GetCtmHandling() const { 64 return ctm_handling_; 65 } 66 GetMainLock()67 auto &GetMainLock() { 68 return main_lock_; 69 } 70 71 auto GetVirtualDisplayPipeline() -> std::shared_ptr<DrmDisplayPipeline>; 72 auto GetWritebackConnectorsCount() -> uint32_t; 73 74 static auto GetTimeMonotonicNs() -> int64_t; 75 76 private: 77 auto GetOrderedConnectors() -> std::vector<DrmConnector *>; 78 void UpdateFrontendDisplays(); 79 void DetachAllFrontendDisplays(); 80 81 std::vector<std::unique_ptr<DrmDevice>> drms_; 82 83 // Android properties: 84 bool scale_with_gpu_{}; 85 CtmHandling ctm_handling_{}; 86 87 std::shared_ptr<UEventListener> uevent_listener_; 88 89 std::recursive_mutex main_lock_; 90 91 std::map<DrmConnector *, std::shared_ptr<DrmDisplayPipeline>> 92 attached_pipelines_; 93 94 PipelineToFrontendBindingInterface *const frontend_interface_; 95 96 bool initialized_{}; 97 }; 98 } // namespace android 99