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 | |
| 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 DrmDisplayCompositor; |
| 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: |
| 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: |
| 58 | explicit BindingOwner(B *pb) : bindable_(pb){}; |
| 59 | ~BindingOwner() { |
| 60 | bindable_->bound_pipeline_ = nullptr; |
| 61 | } |
| 62 | |
| 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 | DrmDevice *device; |
| 76 | |
| 77 | std::shared_ptr<BindingOwner<DrmConnector>> connector; |
| 78 | std::shared_ptr<BindingOwner<DrmEncoder>> encoder; |
| 79 | std::shared_ptr<BindingOwner<DrmCrtc>> crtc; |
| 80 | std::shared_ptr<BindingOwner<DrmPlane>> primary_plane; |
| 81 | std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> overlay_planes; |
Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame^] | 82 | |
| 83 | std::unique_ptr<DrmDisplayCompositor> compositor; |
Roman Stratiienko | cad8e0c | 2022-01-31 16:40:16 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace android |
| 87 | |
| 88 | #endif |