blob: 44864b9de6ebc283b2081722dc25adc70d0bad92 [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#define LOG_TAG "hwc-drm-connector"
18
19#include "drmconnector.h"
20#include "drmresources.h"
21
22#include <errno.h>
23#include <stdint.h>
24
25#include <cutils/log.h>
26#include <xf86drmMode.h>
27
28namespace android {
29
30DrmConnector::DrmConnector(DrmResources *drm, drmModeConnectorPtr c,
31 DrmEncoder *current_encoder,
32 std::vector<DrmEncoder *> &possible_encoders)
33 : drm_(drm),
34 id_(c->connector_id),
35 encoder_(current_encoder),
36 display_(-1),
37 type_(c->connector_type),
38 state_(c->connection),
39 mm_width_(c->mmWidth),
40 mm_height_(c->mmHeight),
41 possible_encoders_(possible_encoders) {
42}
43
44DrmConnector::~DrmConnector() {
45}
46
47int DrmConnector::Init() {
48 int ret = drm_->GetConnectorProperty(*this, "DPMS", &dpms_property_);
49 if (ret) {
50 ALOGE("Could not get DPMS property\n");
51 return ret;
52 }
53 return 0;
54}
55
56uint32_t DrmConnector::id() const {
57 return id_;
58}
59
60int DrmConnector::display() const {
61 return display_;
62}
63
64void DrmConnector::set_display(int display) {
65 display_ = display;
66}
67
68bool DrmConnector::built_in() const {
69 return type_ == DRM_MODE_CONNECTOR_LVDS || type_ == DRM_MODE_CONNECTOR_eDP ||
70 type_ == DRM_MODE_CONNECTOR_DSI;
71}
72
73int DrmConnector::UpdateModes() {
74 int fd = drm_->fd();
75
76 drmModeConnectorPtr c = drmModeGetConnector(fd, id_);
77 if (!c) {
78 ALOGE("Failed to get connector %d", id_);
79 return -ENODEV;
80 }
81
82 std::vector<DrmMode> new_modes;
83 for (int i = 0; i < c->count_modes; ++i) {
84 bool exists = false;
85 for (std::vector<DrmMode>::iterator iter = modes_.begin();
86 iter != modes_.end(); ++iter) {
87 if (*iter == c->modes[i]) {
88 new_modes.push_back(*iter);
89 exists = true;
90 break;
91 }
92 }
93 if (exists)
94 continue;
95
96 DrmMode m(&c->modes[i]);
97 m.set_id(drm_->next_mode_id());
98 new_modes.push_back(m);
99 }
100 modes_.swap(new_modes);
101 return 0;
102}
103
104const DrmMode &DrmConnector::active_mode() const {
105 return active_mode_;
106}
107
108int DrmConnector::set_active_mode(uint32_t mode_id) {
109 for (std::vector<DrmMode>::const_iterator iter = modes_.begin();
110 iter != modes_.end(); ++iter) {
111 if (iter->id() == mode_id) {
112 active_mode_ = *iter;
113 return 0;
114 }
115 }
116 return -ENOENT;
117}
118
119const DrmProperty &DrmConnector::dpms_property() const {
120 return dpms_property_;
121}
122
123DrmConnector::ModeIter DrmConnector::begin_modes() const {
124 return modes_.begin();
125}
126
127DrmConnector::ModeIter DrmConnector::end_modes() const {
128 return modes_.end();
129}
130
131DrmEncoder *DrmConnector::encoder() const {
132 return encoder_;
133}
134
135void DrmConnector::set_encoder(DrmEncoder *encoder) {
136 encoder_ = encoder;
137}
138
139DrmConnector::EncoderIter DrmConnector::begin_possible_encoders() const {
140 return possible_encoders_.begin();
141}
142
143DrmConnector::EncoderIter DrmConnector::end_possible_encoders() const {
144 return possible_encoders_.end();
145}
146
147uint32_t DrmConnector::mm_width() const {
148 return mm_width_;
149}
150
151uint32_t DrmConnector::mm_height() const {
152 return mm_height_;
153}
154}