1 /* 2 * Copyright (C) 2022 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 ANDROID_DRMDISPLAYPIPELINE_H_ 18 #define ANDROID_DRMDISPLAYPIPELINE_H_ 19 20 #include <memory> 21 #include <vector> 22 23 namespace android { 24 25 class DrmConnector; 26 class DrmDevice; 27 class DrmPlane; 28 class DrmCrtc; 29 class DrmEncoder; 30 class DrmAtomicStateManager; 31 32 struct DrmDisplayPipeline; 33 34 template <class O> 35 class BindingOwner; 36 37 template <class O> 38 class PipelineBindable { 39 friend class BindingOwner<O>; 40 41 public: GetPipeline()42 auto *GetPipeline() { 43 return bound_pipeline_; 44 } 45 46 auto BindPipeline(DrmDisplayPipeline *pipeline, 47 bool return_object_if_bound = false) 48 -> std::shared_ptr<BindingOwner<O>>; 49 50 private: 51 DrmDisplayPipeline *bound_pipeline_; 52 std::weak_ptr<BindingOwner<O>> owner_object_; 53 }; 54 55 template <class B> 56 class BindingOwner { 57 public: BindingOwner(B * pb)58 explicit BindingOwner(B *pb) : bindable_(pb){}; ~BindingOwner()59 ~BindingOwner() { 60 bindable_->bound_pipeline_ = nullptr; 61 } 62 Get()63 B *Get() { 64 return bindable_; 65 } 66 67 private: 68 B *const bindable_; 69 }; 70 71 struct DrmDisplayPipeline { 72 static auto CreatePipeline(DrmConnector &connector) 73 -> std::unique_ptr<DrmDisplayPipeline>; 74 75 auto GetUsablePlanes() 76 -> std::vector<std::shared_ptr<BindingOwner<DrmPlane>>>; 77 78 DrmDevice *device; 79 80 std::shared_ptr<BindingOwner<DrmConnector>> connector; 81 std::shared_ptr<BindingOwner<DrmEncoder>> encoder; 82 std::shared_ptr<BindingOwner<DrmCrtc>> crtc; 83 std::shared_ptr<BindingOwner<DrmPlane>> primary_plane; 84 85 std::unique_ptr<DrmAtomicStateManager> atomic_state_manager; 86 }; 87 88 } // namespace android 89 90 #endif 91