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