blob: 671cab6c621a3a1376d268cab7327f2b791fe343 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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"
Sean Paul047b9b22015-07-28 14:15:42 -040023#include "drmeventlistener.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040024#include "drmplane.h"
Alexandru Gheorghec5463582018-03-27 15:52:02 +010025#include "platform.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040026
27#include <stdint.h>
Alexandru Gheorghec5463582018-03-27 15:52:02 +010028#include <tuple>
Sean Paul6a55e9f2015-04-30 15:31:06 -040029
30namespace android {
31
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010032class DrmDevice {
Sean Paul6a55e9f2015-04-30 15:31:06 -040033 public:
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010034 DrmDevice();
35 ~DrmDevice();
Sean Paul6a55e9f2015-04-30 15:31:06 -040036
Alexandru Gheorghec5463582018-03-27 15:52:02 +010037 std::tuple<int, int> Init(const char *path, int num_displays);
Sean Paul6a55e9f2015-04-30 15:31:06 -040038
Zach Reiznerff30b522015-10-28 19:08:45 -070039 int fd() const {
40 return fd_.get();
41 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040042
Zach Reiznerff30b522015-10-28 19:08:45 -070043 const std::vector<std::unique_ptr<DrmConnector>> &connectors() const {
44 return connectors_;
45 }
46
47 const std::vector<std::unique_ptr<DrmPlane>> &planes() const {
48 return planes_;
49 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040050
Sean Paul406dbfc2016-02-10 15:35:17 -080051 std::pair<uint32_t, uint32_t> min_resolution() const {
52 return min_resolution_;
53 }
54
55 std::pair<uint32_t, uint32_t> max_resolution() const {
56 return max_resolution_;
57 }
58
Sean Paul6a55e9f2015-04-30 15:31:06 -040059 DrmConnector *GetConnectorForDisplay(int display) const;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000060 DrmConnector *GetWritebackConnectorForDisplay(int display) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040061 DrmCrtc *GetCrtcForDisplay(int display) const;
62 DrmPlane *GetPlane(uint32_t id) const;
Sean Paul047b9b22015-07-28 14:15:42 -040063 DrmEventListener *event_listener();
Sean Paul6a55e9f2015-04-30 15:31:06 -040064
65 int GetPlaneProperty(const DrmPlane &plane, const char *prop_name,
66 DrmProperty *property);
Sean Paul877be972015-06-03 14:08:27 -040067 int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
68 DrmProperty *property);
Sean Paul6a55e9f2015-04-30 15:31:06 -040069 int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
70 DrmProperty *property);
71
Robert Foss0690c1c2016-10-20 11:07:57 -040072 const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040073 uint32_t next_mode_id();
Sean Paul6a55e9f2015-04-30 15:31:06 -040074
Sean Paul57355412015-09-19 09:14:34 -040075 int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id);
76 int DestroyPropertyBlob(uint32_t blob_id);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010077 bool HandlesDisplay(int display) const;
Sean Paul57355412015-09-19 09:14:34 -040078
Sean Paul6a55e9f2015-04-30 15:31:06 -040079 private:
80 int TryEncoderForDisplay(int display, DrmEncoder *enc);
81 int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
82 DrmProperty *property);
83
Sean Paul877be972015-06-03 14:08:27 -040084 int CreateDisplayPipe(DrmConnector *connector);
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000085 int AttachWriteback(DrmConnector *display_conn);
Sean Paul877be972015-06-03 14:08:27 -040086
Zach Reiznerff30b522015-10-28 19:08:45 -070087 UniqueFd fd_;
88 uint32_t mode_id_ = 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -040089
Zach Reiznerff30b522015-10-28 19:08:45 -070090 std::vector<std::unique_ptr<DrmConnector>> connectors_;
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000091 std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_;
Zach Reiznerff30b522015-10-28 19:08:45 -070092 std::vector<std::unique_ptr<DrmEncoder>> encoders_;
93 std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
94 std::vector<std::unique_ptr<DrmPlane>> planes_;
Sean Paul047b9b22015-07-28 14:15:42 -040095 DrmEventListener event_listener_;
Sean Paul406dbfc2016-02-10 15:35:17 -080096
97 std::pair<uint32_t, uint32_t> min_resolution_;
98 std::pair<uint32_t, uint32_t> max_resolution_;
Alexandru Gheorghec5463582018-03-27 15:52:02 +010099 std::map<int, int> displays_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400100};
101}
102
103#endif // ANDROID_DRM_H_