2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "hwc-drm-connector"
19 #include "drmconnector.h"
20 #include "drmresources.h"
25 #include <cutils/log.h>
26 #include <xf86drmMode.h>
30 DrmConnector::DrmConnector(DrmResources *drm, drmModeConnectorPtr c,
31 DrmEncoder *current_encoder,
32 std::vector<DrmEncoder *> &possible_encoders)
35 encoder_(current_encoder),
37 type_(c->connector_type),
38 state_(c->connection),
39 mm_width_(c->mmWidth),
40 mm_height_(c->mmHeight),
41 possible_encoders_(possible_encoders) {
44 DrmConnector::~DrmConnector() {
47 int DrmConnector::Init() {
48 int ret = drm_->GetConnectorProperty(*this, "DPMS", &dpms_property_);
50 ALOGE("Could not get DPMS property\n");
53 ret = drm_->GetConnectorProperty(*this, "CRTC_ID", &crtc_id_property_);
55 ALOGE("Could not get CRTC_ID property\n");
61 uint32_t DrmConnector::id() const {
65 int DrmConnector::display() const {
69 void DrmConnector::set_display(int display) {
73 bool DrmConnector::built_in() const {
74 return type_ == DRM_MODE_CONNECTOR_LVDS || type_ == DRM_MODE_CONNECTOR_eDP ||
75 type_ == DRM_MODE_CONNECTOR_DSI;
78 int DrmConnector::UpdateModes() {
81 drmModeConnectorPtr c = drmModeGetConnector(fd, id_);
83 ALOGE("Failed to get connector %d", id_);
87 std::vector<DrmMode> new_modes;
88 for (int i = 0; i < c->count_modes; ++i) {
90 for (std::vector<DrmMode>::iterator iter = modes_.begin();
91 iter != modes_.end(); ++iter) {
92 if (*iter == c->modes[i]) {
93 new_modes.push_back(*iter);
101 DrmMode m(&c->modes[i]);
102 m.set_id(drm_->next_mode_id());
103 new_modes.push_back(m);
105 modes_.swap(new_modes);
109 const DrmMode &DrmConnector::active_mode() const {
113 void DrmConnector::set_active_mode(const DrmMode &mode) {
117 const DrmProperty &DrmConnector::dpms_property() const {
118 return dpms_property_;
121 const DrmProperty &DrmConnector::crtc_id_property() const {
122 return crtc_id_property_;
125 DrmConnector::ModeIter DrmConnector::begin_modes() const {
126 return modes_.begin();
129 DrmConnector::ModeIter DrmConnector::end_modes() const {
133 DrmEncoder *DrmConnector::encoder() const {
137 void DrmConnector::set_encoder(DrmEncoder *encoder) {
141 DrmConnector::EncoderIter DrmConnector::begin_possible_encoders() const {
142 return possible_encoders_.begin();
145 DrmConnector::EncoderIter DrmConnector::end_possible_encoders() const {
146 return possible_encoders_.end();
149 uint32_t DrmConnector::mm_width() const {
153 uint32_t DrmConnector::mm_height() const {