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