xref: /aosp_15_r20/external/drm_hwcomposer/drm/DrmDisplayPipeline.h (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
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 #pragma once
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;
29 class DrmAtomicStateManager;
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:
GetPipeline()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:
BindingOwner(B * pb)57   explicit BindingOwner(B *pb) : bindable_(pb){};
~BindingOwner()58   ~BindingOwner() {
59     bindable_->bound_pipeline_ = nullptr;
60   }
61 
Get()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 
74   auto GetUsablePlanes()
75       -> std::vector<std::shared_ptr<BindingOwner<DrmPlane>>>;
76 
77   ~DrmDisplayPipeline();
78 
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;
85 
86   std::shared_ptr<DrmAtomicStateManager> atomic_state_manager;
87 };
88 
89 }  // namespace android
90