OSDN Git Service

drm_hwcomposer: Tidy-up DrmConnector class
[android-x86/external-drm_hwcomposer.git] / drm / DrmDevice.h
1 /*
2  * Copyright (C) 2015 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_DRM_H_
18 #define ANDROID_DRM_H_
19
20 #include <cstdint>
21 #include <map>
22 #include <tuple>
23
24 #include "DrmConnector.h"
25 #include "DrmCrtc.h"
26 #include "DrmEncoder.h"
27 #include "DrmFbImporter.h"
28 #include "utils/UniqueFd.h"
29
30 namespace android {
31
32 class DrmFbImporter;
33 class DrmPlane;
34
35 class DrmDevice {
36  public:
37   DrmDevice();
38   ~DrmDevice() = default;
39
40   std::tuple<int, int> Init(const char *path, int num_displays);
41
42   int fd() const {
43     return fd_.Get();
44   }
45
46   const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
47     return connectors_;
48   }
49
50   const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
51     return planes_;
52   }
53
54   std::pair<uint32_t, uint32_t> min_resolution() const {
55     return min_resolution_;
56   }
57
58   std::pair<uint32_t, uint32_t> max_resolution() const {
59     return max_resolution_;
60   }
61
62   DrmConnector *GetConnectorForDisplay(int display) const;
63   DrmCrtc *GetCrtcForDisplay(int display) const;
64
65   std::string GetName() const;
66
67   const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
68   uint32_t next_mode_id();
69
70   auto RegisterUserPropertyBlob(void *data, size_t length) const
71       -> DrmModeUserPropertyBlobUnique;
72
73   bool HandlesDisplay(int display) const;
74
75   bool HasAddFb2ModifiersSupport() const {
76     return HasAddFb2ModifiersSupport_;
77   }
78
79   DrmFbImporter &GetDrmFbImporter() {
80     return *mDrmFbImporter;
81   }
82
83   static auto IsKMSDev(const char *path) -> bool;
84
85   auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
86     for (const auto &crtc : crtcs_) {
87       if (crtc->GetId() == id) {
88         return crtc.get();
89       }
90     };
91
92     return nullptr;
93   }
94
95   auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
96     for (const auto &enc : encoders_) {
97       if (enc->GetId() == id) {
98         return enc.get();
99       }
100     };
101
102     return nullptr;
103   }
104
105   auto GetDisplayId(DrmConnector *conn) {
106     return connectors_to_display_id_.at(conn);
107   }
108
109   int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
110                   DrmProperty *property) const;
111
112  private:
113   int TryEncoderForDisplay(int display, DrmEncoder *enc);
114
115   int CreateDisplayPipe(DrmConnector *connector);
116
117   UniqueFd fd_;
118   uint32_t mode_id_ = 0;
119
120   std::vector<std::unique_ptr<DrmConnector>> connectors_;
121   std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
122   std::vector<std::unique_ptr<DrmEncoder>> encoders_;
123   std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
124   std::vector<std::unique_ptr<DrmPlane>> planes_;
125
126   std::pair<uint32_t, uint32_t> min_resolution_;
127   std::pair<uint32_t, uint32_t> max_resolution_;
128
129   std::map<int /*display*/, DrmCrtc *> bound_crtcs_;
130   std::map<int /*display*/, DrmConnector *> bound_connectors_;
131   std::map<DrmConnector *, int /*display*/> connectors_to_display_id_;
132   std::map<DrmEncoder *, int /*display*/> encoders_to_display_id_;
133   std::map<DrmCrtc *, DrmEncoder *> bound_encoders_;
134
135   bool HasAddFb2ModifiersSupport_{};
136
137   std::shared_ptr<DrmDevice> self;
138
139   std::unique_ptr<DrmFbImporter> mDrmFbImporter;
140 };
141 }  // namespace android
142
143 #endif  // ANDROID_DRM_H_