• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 using UsablePlanes = std::pair<
71     std::vector<std::shared_ptr<BindingOwner<DrmPlane>>>,
72     std::shared_ptr<BindingOwner<DrmPlane>>>;
73 
74 struct DrmDisplayPipeline {
75   static auto CreatePipeline(DrmConnector &connector)
76       -> std::unique_ptr<DrmDisplayPipeline>;
77 
78   auto GetUsablePlanes() -> UsablePlanes;
79 
80   ~DrmDisplayPipeline();
81 
82   DrmDevice *device;
83 
84   std::shared_ptr<BindingOwner<DrmConnector>> connector;
85   std::shared_ptr<BindingOwner<DrmEncoder>> encoder;
86   std::shared_ptr<BindingOwner<DrmCrtc>> crtc;
87   std::shared_ptr<BindingOwner<DrmPlane>> primary_plane;
88 
89   std::shared_ptr<DrmAtomicStateManager> atomic_state_manager;
90 };
91 
92 }  // namespace android
93