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