blob: a3e2dd91cd0f034d3cec92602cda8a0f76dc67f1 [file] [log] [blame]
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +02001/*
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
23namespace android {
24
25class DrmConnector;
26class DrmDevice;
27class DrmPlane;
28class DrmCrtc;
29class DrmEncoder;
30class DrmDisplayCompositor;
31
32struct DrmDisplayPipeline;
33
34template <class O>
35class BindingOwner;
36
37template <class O>
38class 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
55template <class B>
56class 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
71struct 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 Stratiienko19c162f2022-02-01 09:35:08 +020082
83 std::unique_ptr<DrmDisplayCompositor> compositor;
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020084};
85
86} // namespace android
87
88#endif