• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   auto Init(const char *path) -> int;
41 
GetFd()42   auto GetFd() const {
43     return fd_.Get();
44   }
45 
46   auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &;
47   auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
48   auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
49   auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &;
50 
GetMinResolution()51   auto GetMinResolution() const {
52     return min_resolution_;
53   }
54 
GetMaxResolution()55   auto GetMaxResolution() const {
56     return max_resolution_;
57   }
58 
59   std::string GetName() const;
60 
61   auto RegisterUserPropertyBlob(void *data, size_t length) const
62       -> DrmModeUserPropertyBlobUnique;
63 
HasAddFb2ModifiersSupport()64   auto HasAddFb2ModifiersSupport() const {
65     return HasAddFb2ModifiersSupport_;
66   }
67 
GetDrmFbImporter()68   auto &GetDrmFbImporter() {
69     return *drm_fb_importer_;
70   }
71 
72   static auto IsKMSDev(const char *path) -> bool;
73 
74   auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
75     for (const auto &crtc : crtcs_) {
76       if (crtc->GetId() == id) {
77         return crtc.get();
78       }
79     };
80 
81     return nullptr;
82   }
83 
84   auto FindEncoderById(uint32_t id) const -> DrmEncoder * {
85     for (const auto &enc : encoders_) {
86       if (enc->GetId() == id) {
87         return enc.get();
88       }
89     };
90 
91     return nullptr;
92   }
93 
94   int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
95                   DrmProperty *property) const;
96 
97  private:
98   UniqueFd fd_;
99 
100   std::vector<std::unique_ptr<DrmConnector>> connectors_;
101   std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
102   std::vector<std::unique_ptr<DrmEncoder>> encoders_;
103   std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
104   std::vector<std::unique_ptr<DrmPlane>> planes_;
105 
106   std::pair<uint32_t, uint32_t> min_resolution_;
107   std::pair<uint32_t, uint32_t> max_resolution_;
108 
109   bool HasAddFb2ModifiersSupport_{};
110 
111   std::unique_ptr<DrmFbImporter> drm_fb_importer_;
112 };
113 }  // namespace android
114 
115 #endif  // ANDROID_DRM_H_
116