• 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 <stdint.h>
21 
22 #include <map>
23 #include <tuple>
24 
25 #include "DrmConnector.h"
26 #include "DrmCrtc.h"
27 #include "DrmEncoder.h"
28 #include "DrmEventListener.h"
29 #include "DrmPlane.h"
30 
31 namespace android {
32 
33 class DrmDevice {
34  public:
35   DrmDevice();
36   ~DrmDevice();
37 
38   std::tuple<int, int> Init(const char *path, int num_displays);
39 
fd()40   int fd() const {
41     return fd_.get();
42   }
43 
connectors()44   const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
45     return connectors_;
46   }
47 
planes()48   const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
49     return planes_;
50   }
51 
min_resolution()52   std::pair<uint32_t, uint32_t> min_resolution() const {
53     return min_resolution_;
54   }
55 
max_resolution()56   std::pair<uint32_t, uint32_t> max_resolution() const {
57     return max_resolution_;
58   }
59 
60   DrmConnector *GetConnectorForDisplay(int display) const;
61   DrmConnector *GetWritebackConnectorForDisplay(int display) const;
62   DrmConnector *AvailableWritebackConnector(int display) const;
63   DrmCrtc *GetCrtcForDisplay(int display) const;
64   DrmPlane *GetPlane(uint32_t id) const;
65   DrmEventListener *event_listener();
66 
67   int GetPlaneProperty(const DrmPlane &plane, const char *prop_name,
68                        DrmProperty *property);
69   int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
70                       DrmProperty *property);
71   int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
72                            DrmProperty *property);
73 
74   const std::string GetName() const;
75 
76   const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
77   uint32_t next_mode_id();
78 
79   int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id);
80   int DestroyPropertyBlob(uint32_t blob_id);
81   bool HandlesDisplay(int display) const;
RegisterHotplugHandler(DrmEventHandler * handler)82   void RegisterHotplugHandler(DrmEventHandler *handler) {
83     event_listener_.RegisterHotplugHandler(handler);
84   }
85 
86  private:
87   int TryEncoderForDisplay(int display, DrmEncoder *enc);
88   int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
89                   DrmProperty *property);
90 
91   int CreateDisplayPipe(DrmConnector *connector);
92   int AttachWriteback(DrmConnector *display_conn);
93 
94   UniqueFd fd_;
95   uint32_t mode_id_ = 0;
96 
97   std::vector<std::unique_ptr<DrmConnector>> connectors_;
98   std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
99   std::vector<std::unique_ptr<DrmEncoder>> encoders_;
100   std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
101   std::vector<std::unique_ptr<DrmPlane>> planes_;
102   DrmEventListener event_listener_;
103 
104   std::pair<uint32_t, uint32_t> min_resolution_;
105   std::pair<uint32_t, uint32_t> max_resolution_;
106   std::map<int, int> displays_;
107 };
108 }  // namespace android
109 
110 #endif  // ANDROID_DRM_H_
111