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